01: /*
02: * argun 1.0
03: * Web 2.0 delivery framework
04: * Copyright (C) 2007 Hammurapi Group
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2 of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: *
20: * URL: http://www.hammurapi.biz
21: * e-Mail: support@hammurapi.biz
22: */
23: package biz.hammurapi.web.xslt;
24:
25: import java.io.InputStream;
26:
27: import javax.xml.transform.Source;
28: import javax.xml.transform.TransformerFactory;
29: import javax.xml.transform.stream.StreamSource;
30:
31: import org.apache.log4j.Logger;
32: import org.apache.xalan.xsltc.trax.TransformerFactoryImpl;
33:
34: import biz.hammurapi.web.HammurapiWebException;
35:
36: /**
37: * @author Pavel Vlasov
38: * @version $Revision: 1.1 $
39: */
40: public class XsltcTransformerBase extends AbstractXsltTransformer {
41: private static Logger logger = Logger
42: .getLogger(XsltcTransformerBase.class);
43:
44: private String transletName;
45: private String transletPackage;
46:
47: public void setTransletName(String transletName) {
48: if (transletName == null) {
49: this .transletName = null;
50: this .transletPackage = null;
51: logger.debug(this .getClass().getName()
52: + ": transletName -> null");
53: } else {
54: int idx = transletName.lastIndexOf('.');
55: if (idx == -1) {
56: this .transletName = transletName;
57: } else {
58: this .transletName = transletName.substring(idx + 1);
59: this .transletPackage = transletName.substring(0, idx);
60: }
61: logger.debug(this .getClass().getName()
62: + ": transletName -> " + this .transletName);
63: logger.debug(this .getClass().getName()
64: + ": transletPackage -> " + this .transletPackage);
65: }
66: }
67:
68: protected Source getSource() throws HammurapiWebException {
69: if (transletName == null) {
70: InputStream is = getStyleSheetAsStream();
71: if (is != null) {
72: throw new UnsupportedOperationException(
73: "Runtime compilation is not supported");
74: // XSLTC xsltc = new XSLTC();
75: // xsltc.init();
76: // if (xsltc.compile(is, getClass().getName().replace('.','_')+"_Translet_"+String.valueOf(counter++))) {
77: // transletName=xsltc.getClassName();
78: // } else {
79: // throw new HammurapiWebException("Stylesheet compilation failed");
80: // }
81: }
82: }
83:
84: return transletName == null ? null : new StreamSource(
85: transletName);
86: }
87:
88: protected TransformerFactory createTransformerFactory() {
89: // On one hand it is bad to instantiate TransformerFactory
90: // in this way, on the other hand I hate to modify
91: // system-wide properties even temporarily.
92: TransformerFactory tf = new TransformerFactoryImpl();
93: tf.setAttribute("use-classpath", Boolean.TRUE);
94: if (transletPackage != null) {
95: tf.setAttribute("package-name", transletPackage);
96: }
97: return tf;
98: }
99: }
|