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