Last active
December 31, 2015 15:28
-
-
Save migue/8006714 to your computer and use it in GitHub Desktop.
Sample extension mechanism for Liferay using the OSGi capabilities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TemplateTracker implements BundleTrackerCustomizer { | |
@Override | |
public Object addingBundle(Bundle bundle, BundleEvent event) { | |
// lets track all the bundles publishing the _TEMPLATES_LOCATION header | |
String templatesLocation = bundle.getHeaders().get(_TEMPLATES_LOCATION); | |
if (templatesLocation == null) { | |
System.out.println("No templates provided"); | |
return bundle; | |
} | |
Enumeration<URL> templates = bundle.findEntries( | |
templatesLocation, "*.ftl", true); | |
String context = bundle.getHeaders().get("Web-ContextPath"); | |
while (templates.hasMoreElements()) { | |
URL template = templates.nextElement(); | |
String path = context + "_SERVLET_CONTEXT_" + template.getFile(); | |
System.out.println("Registered template " + path); | |
_registeredTemplates.add(path); | |
} | |
return bundle; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment