View Javadoc

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