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