1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.coreservice.impl.style;
17
18 import org.apache.log4j.Logger;
19 import org.kuali.rice.coreservice.api.style.Style;
20 import org.kuali.rice.coreservice.api.style.StyleRepositoryService;
21 import org.kuali.rice.coreservice.api.style.StyleService;
22 import org.kuali.rice.coreservice.framework.CoreFrameworkServiceLocator;
23 import org.kuali.rice.kew.api.KewApiConstants;
24 import org.kuali.rice.krad.util.KRADConstants;
25
26 import javax.xml.transform.Templates;
27 import javax.xml.transform.TransformerConfigurationException;
28 import javax.xml.transform.TransformerFactory;
29 import javax.xml.transform.stream.StreamSource;
30 import java.io.StringReader;
31 import java.util.List;
32 import java.util.Properties;
33
34
35
36
37
38
39 public class StyleServiceImpl implements StyleService {
40
41 private static final Logger LOG = Logger.getLogger(StyleServiceImpl.class);
42
43 private StyleRepositoryService styleRepositoryService;
44
45 public void setStyleRepositoryService(StyleRepositoryService styleRepositoryService) {
46 this.styleRepositoryService = styleRepositoryService;
47 }
48
49
50
51
52
53
54 @Override
55 public Style getStyle(String styleName) {
56 return styleRepositoryService.getStyle(styleName);
57 }
58
59 @Override
60 public Templates getStyleAsTranslet(String name) throws TransformerConfigurationException {
61 if (name == null) {
62 return null;
63 }
64
65 Style style = getStyle(name);
66 if (style == null) {
67 return null;
68 }
69
70 boolean useXSLTC = CoreFrameworkServiceLocator.getParameterService().getParameterValueAsBoolean(KewApiConstants.KEW_NAMESPACE, KRADConstants.DetailTypes.EDOC_LITE_DETAIL_TYPE, KewApiConstants.EDL_USE_XSLTC_IND);
71 if (useXSLTC) {
72 LOG.info("using xsltc to compile stylesheet");
73 String key = "javax.xml.transform.TransformerFactory";
74 String value = "org.apache.xalan.xsltc.trax.TransformerFactoryImpl";
75 Properties props = System.getProperties();
76 props.put(key, value);
77 System.setProperties(props);
78 }
79
80 TransformerFactory factory = TransformerFactory.newInstance();
81 factory.setURIResolver(new StyleUriResolver(this));
82
83 if (useXSLTC) {
84 factory.setAttribute("translet-name",name);
85 factory.setAttribute("generate-translet",Boolean.TRUE);
86 String debugTransform = CoreFrameworkServiceLocator.getParameterService().getParameterValueAsString(KewApiConstants.KEW_NAMESPACE, KRADConstants.DetailTypes.EDOC_LITE_DETAIL_TYPE, KewApiConstants.EDL_DEBUG_TRANSFORM_IND);
87 if (debugTransform.trim().equals("Y")) {
88 factory.setAttribute("debug", Boolean.TRUE);
89 }
90 }
91
92 return factory.newTemplates(new StreamSource(new StringReader(style.getXmlContent())));
93 }
94
95 @Override
96 public void saveStyle(Style style) {
97 styleRepositoryService.saveStyle(style);
98 }
99
100 @Override
101 public List<String> getAllStyleNames() {
102 return styleRepositoryService.getAllStyleNames();
103 }
104 }