View Javadoc

1   package net.sf.tomp.xtcl.filter;
2   
3   import org.apache.commons.logging.Log;
4   import org.apache.commons.logging.LogFactory;
5   import org.xml.sax.SAXException;
6   
7   import javax.xml.transform.Transformer;
8   import javax.xml.transform.sax.TransformerHandler;
9   
10  import java.util.Properties;
11  
12  /***
13   * DOCUMENT ME!
14   * 
15   * @author tomp
16   */
17  public class TransformerFilterImpl extends XSLTFilter implements
18          HasOutputProperties {
19  
20  	private static final Log log = LogFactory.getLog(TransformerFilterImpl.class);
21  
22      /*** DOCUMENT ME! */
23      protected Transformer transformer;
24  
25      /*** DOCUMENT ME! */
26      protected TransformerHandler handler;
27  
28      /*** DOCUMENT ME! */
29      protected HasOutputProperties outputPropertiesListener = null;
30  
31      /***
32       * Creates a new TransformerFilterImpl object.
33       * 
34       * @param handler DOCUMENT ME!
35       */
36      protected TransformerFilterImpl(TransformerHandler handler) {
37          super(handler);
38          this.handler = handler;
39          transformer = handler.getTransformer();
40      }
41  
42      /***
43       * DOCUMENT ME!
44       * 
45       * @return DOCUMENT ME!
46       */
47      public Transformer getTransformer() {
48          return transformer;
49      }
50  
51      /***
52       * DOCUMENT ME!
53       * 
54       * @return DOCUMENT ME!
55       */
56      public Properties getOutputProperties() {
57          Properties p = transformer.getOutputProperties();
58  
59          //System.out.println(this+" ********************** "+p);
60          return p;
61      }
62  
63      /***
64       * DOCUMENT ME!
65       * 
66       * @param p DOCUMENT ME!
67       */
68      public void setOutputProperties(Properties p) {
69          transformer.setOutputProperties(p);
70      }
71  
72      /***
73       * DOCUMENT ME!
74       * 
75       * @param l DOCUMENT ME!
76       */
77      public void setOutputPropertiesListener(HasOutputProperties l) {
78          outputPropertiesListener = l;
79      }
80  
81      /***
82       * DOCUMENT ME!
83       * 
84       * @param k DOCUMENT ME!
85       * @param v DOCUMENT ME!
86       */
87      public void setParameter(String k, Object v) {
88  //    	System.out.println("TransfFilter Setting param "+k+"="+v);
89          transformer.setParameter(k, v);
90  
91          //System.out.println("Setting param to " + this + ": "+k+"="+v);
92      }
93  
94      ////////////////////////////////////////////////////////////////////
95      // Implementation of the LexicalHandler.
96      ////////////////////////////////////////////////////////////////////
97  
98      /***
99       * Callback interface for SAX (part of LexicalHandler interface): not for
100      * application use
101      * 
102      * @param ch DOCUMENT ME!
103      * @param start DOCUMENT ME!
104      * @param length DOCUMENT ME!
105      * @throws SAXException DOCUMENT ME!
106      */
107 
108     /*
109      * public void startDocument() throws SAXException { super.startDocument();
110      * System.out.println("%%%%% TransformerFilterImpl.startDocument sent"); }
111      * public void endDocument() throws SAXException { System.out.println("%%%%%
112      * TransformerFilterImpl.endDocument trying..."); super.endDocument();
113      * System.out.println("%%%%% TransformerFilterImpl.endDocument sent"); }
114      * public void startElement (String uri, String localName, String qName,
115      * Attributes atts) throws SAXException { super.startElement(uri, localName,
116      * qName, atts); System.out.println("%%%%%
117      * TransformerFilterImpl.startElement="+localName); } public void endElement
118      * (String uri, String localName, String qName) throws SAXException {
119      * super.endElement(uri, localName, qName); System.out.println("%%%%%
120      * TransformerFilterImpl.endElement="+localName); }
121      */
122     public void comment(char[] ch, int start, int length) throws SAXException {
123         handler.comment(ch, start, length);
124 
125         //System.out.println("%%%%% TransformerFilterImpl.comment");
126     }
127 
128     // No-op methods to satisfy lexical handler interface
129 
130     /***
131      * Register the start of the DTD. Comments in the DTD are skipped because
132      * they are not part of the XPath data model
133      * 
134      * @param name DOCUMENT ME!
135      * @param publicId DOCUMENT ME!
136      * @param systemId DOCUMENT ME!
137      * @throws SAXException DOCUMENT ME!
138      */
139     public void startDTD(String name, String publicId, String systemId)
140             throws SAXException {
141         handler.startDTD(name, publicId, systemId);
142     }
143 
144     /***
145      * Register the end of the DTD. Comments in the DTD are skipped because they
146      * are not part of the XPath data model
147      * 
148      * @throws SAXException DOCUMENT ME!
149      */
150     public void endDTD() throws SAXException {
151         handler.endDTD();
152     }
153 
154     /***
155      * DOCUMENT ME!
156      * 
157      * @param name DOCUMENT ME!
158      * @throws SAXException DOCUMENT ME!
159      */
160     public void startEntity(String name) throws SAXException {
161         handler.startEntity(name);
162     }
163 
164     /***
165      * DOCUMENT ME!
166      * 
167      * @param name DOCUMENT ME!
168      * @throws SAXException DOCUMENT ME!
169      */
170     public void endEntity(String name) throws SAXException {
171         handler.endEntity(name);
172     }
173 
174     /***
175      * DOCUMENT ME!
176      * 
177      * @throws SAXException DOCUMENT ME!
178      */
179     public void startCDATA() throws SAXException {
180         handler.startCDATA();
181     }
182 
183     /***
184      * DOCUMENT ME!
185      * 
186      * @throws SAXException DOCUMENT ME!
187      */
188     public void endCDATA() throws SAXException {
189         handler.endCDATA();
190     }
191 }
192 
193 /*
194  * The contents of this file are subject to the Mozilla Public License Version
195  * 1.1 (the "License"); you may not use this file except in compliance with the
196  * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
197  * Software distributed under the License is distributed on an "AS IS" basis,
198  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
199  * the specific language governing rights and limitations under the License. The
200  * Original Code is: all this file. The Initial Developer of the Original Code
201  * is: Tomas Pitner, Masaryk University in Brno, Czech Republic. Contributor(s):
202  */