01: /*
02: * Milin Radivoj
03: * rmilin@gmail.com
04: */
05: package org.enhydra.snapperPreviewer.business;
06:
07: import java.io.StringReader;
08: import java.io.StringWriter;
09:
10: import javax.xml.transform.Transformer;
11: import javax.xml.transform.TransformerFactory;
12: import javax.xml.transform.stream.StreamSource;
13:
14: import org.enhydra.snapperPreviewer.Previewer;
15:
16: /**
17: * @author Milin Radivoj
18: */
19:
20: public class TransformManager implements
21: org.enhydra.snapperPreviewer.spec.TransformManager {
22:
23: private int previewNumLimit = 0;
24:
25: public String transform(String content, String xslPath)
26: throws Exception {
27:
28: StringWriter stringWriter = null;
29:
30: try {
31: TransformerFactory tFactory = TransformerFactory
32: .newInstance();
33: //tFactory.setAttribute("ContainerPreviewNumberLimit", previewNumLimit);
34: Transformer transformer = tFactory
35: .newTransformer(new StreamSource(xslPath));
36:
37: stringWriter = new StringWriter();
38: transformer.transform(new StreamSource(new StringReader(
39: content)),
40: new javax.xml.transform.stream.StreamResult(
41: stringWriter));
42: String result = stringWriter.toString();
43: return result;
44: } catch (Exception e) {
45: Previewer.logError(" Problem in Transform manager : "
46: + e.getMessage());
47: return new String();
48: } finally {
49:
50: if (stringWriter != null) {
51: try {
52: stringWriter.close();
53: } catch (Exception e) {
54: }
55:
56: stringWriter = null;
57: }
58:
59: }
60: }
61:
62: public int getPreviewNumLimit() {
63: return previewNumLimit;
64: }
65:
66: public void setPreviewNumLimit(int previewNumLimit) {
67: this.previewNumLimit = previewNumLimit;
68: }
69: }
|