Skip to content

Instantly share code, notes, and snippets.

@migue
Last active December 31, 2015 15:28
Show Gist options
  • Save migue/8006714 to your computer and use it in GitHub Desktop.
Save migue/8006714 to your computer and use it in GitHub Desktop.
Sample extension mechanism for Liferay using the OSGi capabilities
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