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 {
22 public Object getService(Bundle bundle, ServiceRegistration serviceRegistration)
23 {
24
25
26 ServiceTracker serviceTracker = new ServiceTracker(bundle.getBundleContext(), VelocityTemplateRenderer.class.getName(), null);
27 serviceTracker.open();
28 return new VelocityTemplateProcessor(serviceTracker);
29 }
30
31 public void ungetService(Bundle bundle, ServiceRegistration serviceRegistration, Object service)
32 {
33 ((VelocityTemplateProcessor) service).closeTemplateRendererServiceTracker();
34 }
35
36 public String resolve(String s)
37 {
38 throw new UnsupportedOperationException();
39 }
40
41 public void writeTo(String s, Object o, OutputStream outputStream) throws IOException
42 {
43 throw new UnsupportedOperationException();
44 }
45 }