1 package com.atlassian.plugins.rest.module.template;
2
3 import com.atlassian.templaterenderer.velocity.one.six.VelocityTemplateRenderer;
4 import com.sun.jersey.spi.template.TemplateProcessor;
5 import org.osgi.framework.Bundle;
6 import org.osgi.framework.ServiceFactory;
7 import org.osgi.framework.ServiceRegistration;
8 import org.osgi.util.tracker.ServiceTracker;
9
10 import java.io.IOException;
11 import java.io.OutputStream;
12
13
14
15
16
17
18
19
20 public class VelocityTemplateProcessorServiceFactory implements ServiceFactory, TemplateProcessor {
21 public Object getService(Bundle bundle, ServiceRegistration serviceRegistration) {
22
23
24 ServiceTracker serviceTracker = new ServiceTracker(bundle.getBundleContext(), VelocityTemplateRenderer.class.getName(), null);
25 serviceTracker.open();
26 return new VelocityTemplateProcessor(serviceTracker);
27 }
28
29 public void ungetService(Bundle bundle, ServiceRegistration serviceRegistration, Object service) {
30 ((VelocityTemplateProcessor) service).closeTemplateRendererServiceTracker();
31 }
32
33 public String resolve(String s) {
34 throw new UnsupportedOperationException();
35 }
36
37 public void writeTo(String s, Object o, OutputStream outputStream) throws IOException {
38 throw new UnsupportedOperationException();
39 }
40 }