KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > xslt > TraxProcessor


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.components.xslt;
17
18 import java.io.File JavaDoc;
19 import java.io.IOException JavaDoc;
20 import java.io.InputStream JavaDoc;
21 import java.util.ArrayList JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import javax.xml.transform.Result JavaDoc;
27 import javax.xml.transform.Templates JavaDoc;
28 import javax.xml.transform.Transformer JavaDoc;
29 import javax.xml.transform.TransformerException JavaDoc;
30 import javax.xml.transform.TransformerFactory JavaDoc;
31 import javax.xml.transform.URIResolver JavaDoc;
32 import javax.xml.transform.sax.SAXTransformerFactory JavaDoc;
33 import javax.xml.transform.sax.TemplatesHandler JavaDoc;
34 import javax.xml.transform.sax.TransformerHandler JavaDoc;
35 import javax.xml.transform.stream.StreamSource JavaDoc;
36
37 import org.apache.avalon.excalibur.pool.Recyclable;
38 import org.apache.avalon.framework.activity.Disposable;
39 import org.apache.avalon.framework.activity.Initializable;
40 import org.apache.avalon.framework.logger.AbstractLogEnabled;
41 import org.apache.avalon.framework.parameters.ParameterException;
42 import org.apache.avalon.framework.parameters.Parameterizable;
43 import org.apache.avalon.framework.parameters.Parameters;
44 import org.apache.avalon.framework.service.ServiceException;
45 import org.apache.avalon.framework.service.ServiceManager;
46 import org.apache.avalon.framework.service.Serviceable;
47 import org.apache.excalibur.source.Source;
48 import org.apache.excalibur.source.SourceException;
49 import org.apache.excalibur.source.SourceResolver;
50 import org.apache.excalibur.source.SourceValidity;
51 import org.apache.excalibur.source.impl.validity.AggregatedValidity;
52 import org.apache.excalibur.store.Store;
53 import org.apache.excalibur.xml.sax.XMLizable;
54 import org.apache.excalibur.xml.xslt.XSLTProcessor;
55 import org.apache.excalibur.xml.xslt.XSLTProcessorException;
56 import org.apache.excalibur.xmlizer.XMLizer;
57 import org.xml.sax.ContentHandler JavaDoc;
58 import org.xml.sax.InputSource JavaDoc;
59 import org.xml.sax.SAXException JavaDoc;
60 import org.xml.sax.XMLFilter JavaDoc;
61
62 /**
63  * Adaptation of Excalibur's XSLTProcessor implementation to allow for better
64  * error reporting.
65  *
66  * @version $Id: TraxProcessor.java 332021 2005-11-09 11:22:09Z crossley $
67  * @since 2.1.8
68  */

69
70 public class TraxProcessor extends AbstractLogEnabled implements XSLTProcessor, Serviceable, Initializable, Disposable, Parameterizable,
71         Recyclable, URIResolver JavaDoc {
72     /** The store service instance */
73     protected Store m_store;
74
75     /** The configured transformer factory to use */
76     protected String JavaDoc m_transformerFactory;
77
78     /** The trax TransformerFactory this component uses */
79     protected SAXTransformerFactory JavaDoc m_factory;
80
81     /** The default TransformerFactory used by this component */
82     protected SAXTransformerFactory JavaDoc m_defaultFactory;
83
84     /** Is the store turned on? (default is off) */
85     protected boolean m_useStore;
86
87     /** Is incremental processing turned on? (default for Xalan: no) */
88     protected boolean m_incrementalProcessing;
89
90     /** Resolver used to resolve XSLT document() calls, imports and includes */
91     protected SourceResolver m_resolver;
92
93     /** Check included stylesheets */
94     protected boolean m_checkIncludes;
95
96     /** Map of pairs of System ID's / validities of the included stylesheets */
97     protected Map JavaDoc m_includesMap = new HashMap JavaDoc();
98
99     protected XMLizer m_xmlizer;
100
101     /** The ServiceManager */
102     protected ServiceManager m_manager;
103
104     /**
105      * Compose. Try to get the store
106      *
107      * @avalon.service interface="XMLizer"
108      * @avalon.service interface="SourceResolver"
109      * @avalon.service interface="Store/TransientStore" optional="true"
110      */

111     public void service(final ServiceManager manager) throws ServiceException {
112         m_manager = manager;
113         m_xmlizer = (XMLizer) m_manager.lookup(XMLizer.ROLE);
114         m_resolver = (SourceResolver) m_manager.lookup(SourceResolver.ROLE);
115
116         if (m_manager.hasService(Store.TRANSIENT_STORE)) {
117             m_store = (Store) m_manager.lookup(Store.TRANSIENT_STORE);
118         }
119     }
120
121     /**
122      * Initialize
123      */

124     public void initialize() throws Exception JavaDoc {
125         m_factory = getTransformerFactory(m_transformerFactory);
126         m_defaultFactory = m_factory;
127     }
128
129     /**
130      * Disposable
131      */

132     public void dispose() {
133         if (null != m_manager) {
134             m_manager.release(m_store);
135             m_manager.release(m_resolver);
136             m_manager.release(m_xmlizer);
137             m_manager = null;
138         }
139         m_xmlizer = null;
140         m_store = null;
141         m_resolver = null;
142     }
143
144     /**
145      * Configure the component
146      */

147     public void parameterize(final Parameters params) throws ParameterException {
148         m_useStore = params.getParameterAsBoolean("use-store", this.m_useStore);
149         m_incrementalProcessing = params.getParameterAsBoolean("incremental-processing", this.m_incrementalProcessing);
150         m_transformerFactory = params.getParameter("transformer-factory", null);
151         m_checkIncludes = params.getParameterAsBoolean("check-includes", true);
152         if (!m_useStore) {
153             // release the store, if we don't need it anymore
154
m_manager.release(m_store);
155             m_store = null;
156         } else if (null == m_store) {
157             final String JavaDoc message = "XSLTProcessor: use-store is set to true, " + "but unable to aquire the Store.";
158             throw new ParameterException(message);
159         }
160     }
161
162     /**
163      * Set the transformer factory used by this component
164      */

165     public void setTransformerFactory(final String JavaDoc classname) {
166         m_factory = getTransformerFactory(classname);
167     }
168
169     /**
170      * @see org.apache.excalibur.xml.xslt.XSLTProcessor#getTransformerHandler(org.apache.excalibur.source.Source)
171      */

172     public TransformerHandler JavaDoc getTransformerHandler(final Source JavaDoc stylesheet) throws XSLTProcessorException {
173         return getTransformerHandler(stylesheet, null);
174     }
175
176     /**
177      * @see org.apache.excalibur.xml.xslt.XSLTProcessor#getTransformerHandler(org.apache.excalibur.source.Source,
178      * org.xml.sax.XMLFilter)
179      */

180     public TransformerHandler JavaDoc getTransformerHandler(final Source JavaDoc stylesheet, final XMLFilter JavaDoc filter) throws XSLTProcessorException {
181         final XSLTProcessor.TransformerHandlerAndValidity validity = getTransformerHandlerAndValidity(stylesheet, filter);
182         return validity.getTransfomerHandler();
183     }
184
185     public TransformerHandlerAndValidity getTransformerHandlerAndValidity(final Source JavaDoc stylesheet) throws XSLTProcessorException {
186         return getTransformerHandlerAndValidity(stylesheet, null);
187     }
188
189     public TransformerHandlerAndValidity getTransformerHandlerAndValidity(Source JavaDoc stylesheet, XMLFilter JavaDoc filter) throws XSLTProcessorException {
190
191         final String JavaDoc id = stylesheet.getURI();
192         TransformerHandlerAndValidity handlerAndValidity;
193
194         try {
195             handlerAndValidity = getTemplates(stylesheet, id);
196             if (handlerAndValidity != null) {
197                 if (getLogger().isDebugEnabled()) {
198                     getLogger().debug("Reusing Templates for " + id);
199                 }
200                 return handlerAndValidity;
201             }
202         } catch(Exception JavaDoc e) {
203             throw new XSLTProcessorException("Error retrieving template", e);
204         }
205         
206         TraxErrorListener errorListener = new TraxErrorListener(getLogger(), stylesheet.getURI());
207         try{
208             if (getLogger().isDebugEnabled()) {
209                 getLogger().debug("Creating new Templates for " + id);
210             }
211
212             m_factory.setErrorListener(errorListener);
213
214             // Create a Templates ContentHandler to handle parsing of the
215
// stylesheet.
216
TemplatesHandler JavaDoc templatesHandler = m_factory.newTemplatesHandler();
217
218             // Set the system ID for the template handler since some
219
// TrAX implementations (XSLTC) rely on this in order to obtain
220
// a meaningful identifier for the Templates instances.
221
templatesHandler.setSystemId(id);
222             if (filter != null) {
223                 filter.setContentHandler(templatesHandler);
224             }
225
226             if (getLogger().isDebugEnabled()) {
227                 getLogger().debug("Source = " + stylesheet + ", templatesHandler = " + templatesHandler);
228             }
229
230             // Initialize List for included validities
231
SourceValidity validity = stylesheet.getValidity();
232             if (validity != null && m_checkIncludes) {
233                 m_includesMap.put(id, new ArrayList JavaDoc());
234             }
235
236             try {
237                 // Process the stylesheet.
238
sourceToSAX(stylesheet, filter != null ? (ContentHandler JavaDoc) filter : (ContentHandler JavaDoc) templatesHandler);
239
240                 // Get the Templates object (generated during the parsing of
241
// the stylesheet) from the TemplatesHandler.
242
final Templates JavaDoc template = templatesHandler.getTemplates();
243
244                 if (null == template) {
245                     throw new XSLTProcessorException("Unable to create templates for stylesheet: " + stylesheet.getURI());
246                 }
247
248                 putTemplates(template, stylesheet, id);
249
250                 // Create transformer handler
251
final TransformerHandler JavaDoc handler = m_factory.newTransformerHandler(template);
252                 handler.getTransformer().setErrorListener(new TraxErrorListener(getLogger(), stylesheet.getURI()));
253                 handler.getTransformer().setURIResolver(this);
254
255                 // Create aggregated validity
256
AggregatedValidity aggregated = null;
257                 if (validity != null && m_checkIncludes) {
258                     List JavaDoc includes = (List JavaDoc) m_includesMap.get(id);
259                     if (includes != null) {
260                         aggregated = new AggregatedValidity();
261                         aggregated.add(validity);
262                         for (int i = includes.size() - 1; i >= 0; i--) {
263                             aggregated.add((SourceValidity) ((Object JavaDoc[]) includes.get(i))[1]);
264                         }
265                         validity = aggregated;
266                     }
267                 }
268
269                 // Create result
270
handlerAndValidity = new MyTransformerHandlerAndValidity(handler, validity);
271             } finally {
272                 if (m_checkIncludes)
273                     m_includesMap.remove(id);
274             }
275
276             return handlerAndValidity;
277         } catch (Exception JavaDoc e) {
278             Throwable JavaDoc realEx = errorListener.getThrowable();
279             if (realEx == null) realEx = e;
280             
281             if (realEx instanceof RuntimeException JavaDoc) {
282                 throw (RuntimeException JavaDoc)realEx;
283             }
284             
285             if (realEx instanceof XSLTProcessorException) {
286                 throw (XSLTProcessorException)realEx;
287             }
288             
289             throw new XSLTProcessorException("Exception when creating Transformer from " + stylesheet.getURI(), realEx);
290         }
291     }
292
293     protected void sourceToSAX(Source JavaDoc source, ContentHandler JavaDoc handler) throws SAXException JavaDoc, IOException JavaDoc, SourceException {
294         if (source instanceof XMLizable) {
295             ((XMLizable) source).toSAX(handler);
296         } else {
297             final InputStream JavaDoc inputStream = source.getInputStream();
298             final String JavaDoc mimeType = source.getMimeType();
299             final String JavaDoc systemId = source.getURI();
300             m_xmlizer.toSAX(inputStream, mimeType, systemId, handler);
301         }
302     }
303
304     public void transform(final Source JavaDoc source, final Source JavaDoc stylesheet, final Parameters params, final Result JavaDoc result) throws XSLTProcessorException {
305         try {
306             if (getLogger().isDebugEnabled()) {
307                 getLogger().debug(
308                         "Transform source = " + source + ", stylesheet = " + stylesheet + ", parameters = " + params + ", result = " + result);
309             }
310             final TransformerHandler JavaDoc handler = getTransformerHandler(stylesheet);
311             if (params != null) {
312                 final Transformer JavaDoc transformer = handler.getTransformer();
313                 transformer.clearParameters();
314                 String JavaDoc[] names = params.getNames();
315                 for (int i = names.length - 1; i >= 0; i--) {
316                     transformer.setParameter(names[i], params.getParameter(names[i]));
317                 }
318             }
319
320             handler.setResult(result);
321             sourceToSAX(source, handler);
322             if (getLogger().isDebugEnabled()) {
323                 getLogger().debug("Transform done");
324             }
325         } catch (SAXException JavaDoc e) {
326             // Unwrapping the exception will "remove" the real cause with
327
// never Xalan versions and makes the exception message unusable
328
final String JavaDoc message = "Error in running Transformation";
329             throw new XSLTProcessorException(message, e);
330             /*
331              * if( e.getException() == null ) { final String message = "Error in
332              * running Transformation"; throw new XSLTProcessorException(
333              * message, e ); } else { final String message = "Got SAXException.
334              * Rethrowing cause exception."; getLogger().debug( message, e );
335              * throw new XSLTProcessorException( "Error in running
336              * Transformation", e.getException() ); }
337              */

338         } catch (Exception JavaDoc e) {
339             final String JavaDoc message = "Error in running Transformation";
340             throw new XSLTProcessorException(message, e);
341         }
342     }
343
344     /**
345      * Get the TransformerFactory associated with the given classname. If the
346      * class can't be found or the given class doesn't implement the required
347      * interface, the default factory is returned.
348      */

349     private SAXTransformerFactory JavaDoc getTransformerFactory(String JavaDoc factoryName) {
350         SAXTransformerFactory JavaDoc _factory;
351
352         if (null == factoryName) {
353             _factory = (SAXTransformerFactory JavaDoc) TransformerFactory.newInstance();
354         } else {
355             try {
356                 ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
357                 if (loader == null) {
358                     loader = getClass().getClassLoader();
359                 }
360                 _factory = (SAXTransformerFactory JavaDoc) loader.loadClass(factoryName).newInstance();
361             } catch (ClassNotFoundException JavaDoc cnfe) {
362                 getLogger().error("Cannot find the requested TrAX factory '" + factoryName + "'. Using default TrAX Transformer Factory instead.");
363                 if (m_factory != null)
364                     return m_factory;
365                 _factory = (SAXTransformerFactory JavaDoc) TransformerFactory.newInstance();
366             } catch (ClassCastException JavaDoc cce) {
367                 getLogger().error(
368                         "The indicated class '" + factoryName
369                                 + "' is not a TrAX Transformer Factory. Using default TrAX Transformer Factory instead.");
370                 if (m_factory != null)
371                     return m_factory;
372                 _factory = (SAXTransformerFactory JavaDoc) TransformerFactory.newInstance();
373             } catch (Exception JavaDoc e) {
374                 getLogger().error(
375                         "Error found loading the requested TrAX Transformer Factory '" + factoryName
376                                 + "'. Using default TrAX Transformer Factory instead.");
377                 if (m_factory != null)
378                     return m_factory;
379                 _factory = (SAXTransformerFactory JavaDoc) TransformerFactory.newInstance();
380             }
381         }
382
383         _factory.setErrorListener(new TraxErrorListener(getLogger(), null));
384         _factory.setURIResolver(this);
385
386         // FIXME (SM): implementation-specific parameter passing should be
387
// made more extensible.
388
if (_factory.getClass().getName().equals("org.apache.xalan.processor.TransformerFactoryImpl")) {
389             _factory.setAttribute("http://xml.apache.org/xalan/features/incremental", new Boolean JavaDoc(m_incrementalProcessing));
390         }
391
392         return _factory;
393     }
394
395     private TransformerHandlerAndValidity getTemplates(Source JavaDoc stylesheet, String JavaDoc id) throws IOException JavaDoc, TransformerException JavaDoc {
396         if (!m_useStore) {
397             return null;
398         }
399
400         // we must augment the template ID with the factory classname since one
401
// transformer implementation cannot handle the instances of a
402
// template created by another one.
403
String JavaDoc key = "XSLTTemplate: " + id + '(' + m_factory.getClass().getName() + ')';
404
405         if (getLogger().isDebugEnabled()) {
406             getLogger().debug("getTemplates: stylesheet " + id);
407         }
408
409         SourceValidity newValidity = stylesheet.getValidity();
410
411         // Only stylesheets with validity are stored
412
if (newValidity == null) {
413             // Remove an old template
414
m_store.remove(key);
415             return null;
416         }
417
418         // Stored is an array of the templates and the caching time and list of
419
// includes
420
Object JavaDoc[] templateAndValidityAndIncludes = (Object JavaDoc[]) m_store.get(key);
421         if (templateAndValidityAndIncludes == null) {
422             // Templates not found in cache
423
return null;
424         }
425
426         // Check template modification time
427
SourceValidity storedValidity = (SourceValidity) templateAndValidityAndIncludes[1];
428         int valid = storedValidity.isValid();
429         boolean isValid;
430         if (valid == 0) {
431             valid = storedValidity.isValid(newValidity);
432             isValid = (valid == 1);
433         } else {
434             isValid = (valid == 1);
435         }
436         if (!isValid) {
437             m_store.remove(key);
438             return null;
439         }
440
441         // Check includes
442
if (m_checkIncludes) {
443             AggregatedValidity aggregated = null;
444             List JavaDoc includes = (List JavaDoc) templateAndValidityAndIncludes[2];
445             if (includes != null) {
446                 aggregated = new AggregatedValidity();
447                 aggregated.add(storedValidity);
448
449                 for (int i = includes.size() - 1; i >= 0; i--) {
450                     // Every include stored as pair of source ID and validity
451
Object JavaDoc[] pair = (Object JavaDoc[]) includes.get(i);
452                     storedValidity = (SourceValidity) pair[1];
453                     aggregated.add(storedValidity);
454
455                     valid = storedValidity.isValid();
456                     isValid = false;
457                     if (valid == 0) {
458                         Source JavaDoc includedSource = null;
459                         try {
460                             includedSource = m_resolver.resolveURI((String JavaDoc) pair[0]);
461                             SourceValidity included = includedSource.getValidity();
462                             if (included != null) {
463                                 valid = storedValidity.isValid(included);
464                                 isValid = (valid == 1);
465                             }
466                         } finally {
467                             m_resolver.release(includedSource);
468                         }
469                     } else {
470                         isValid = (valid == 1);
471                     }
472                     if (!isValid) {
473                         m_store.remove(key);
474                         return null;
475                     }
476                 }
477                 storedValidity = aggregated;
478             }
479         }
480
481         TransformerHandler JavaDoc handler = m_factory.newTransformerHandler((Templates JavaDoc) templateAndValidityAndIncludes[0]);
482         handler.getTransformer().setErrorListener(new TraxErrorListener(getLogger(), stylesheet.getURI()));
483         handler.getTransformer().setURIResolver(this);
484         return new MyTransformerHandlerAndValidity(handler, storedValidity);
485     }
486
487     private void putTemplates(Templates JavaDoc templates, Source JavaDoc stylesheet, String JavaDoc id) throws IOException JavaDoc {
488         if (!m_useStore)
489             return;
490
491         // we must augment the template ID with the factory classname since one
492
// transformer implementation cannot handle the instances of a
493
// template created by another one.
494
String JavaDoc key = "XSLTTemplate: " + id + '(' + m_factory.getClass().getName() + ')';
495
496         // only stylesheets with a last modification date are stored
497
SourceValidity validity = stylesheet.getValidity();
498         if (null != validity) {
499             // Stored is an array of the template and the current time
500
Object JavaDoc[] templateAndValidityAndIncludes = new Object JavaDoc[3];
501             templateAndValidityAndIncludes[0] = templates;
502             templateAndValidityAndIncludes[1] = validity;
503             if (m_checkIncludes) {
504                 templateAndValidityAndIncludes[2] = m_includesMap.get(id);
505             }
506             m_store.store(key, templateAndValidityAndIncludes);
507         }
508     }
509
510     /**
511      * Called by the processor when it encounters an xsl:include, xsl:import, or
512      * document() function.
513      *
514      * @param href
515      * An href attribute, which may be relative or absolute.
516      * @param base
517      * The base URI in effect when the href attribute was
518      * encountered.
519      *
520      * @return A Source object, or null if the href cannot be resolved, and the
521      * processor should try to resolve the URI itself.
522      *
523      * @throws TransformerException
524      * if an error occurs when trying to resolve the URI.
525      */

526     public javax.xml.transform.Source JavaDoc resolve(String JavaDoc href, String JavaDoc base) throws TransformerException JavaDoc {
527         if (getLogger().isDebugEnabled()) {
528             getLogger().debug("resolve(href = " + href + ", base = " + base + "); resolver = " + m_resolver);
529         }
530
531         Source JavaDoc xslSource = null;
532         try {
533             if (base == null || href.indexOf(":") > 1) {
534                 // Null base - href must be an absolute URL
535
xslSource = m_resolver.resolveURI(href);
536             } else if (href.length() == 0) {
537                 // Empty href resolves to base
538
xslSource = m_resolver.resolveURI(base);
539             } else {
540                 // is the base a file or a real m_url
541
if (!base.startsWith("file:")) {
542                     int lastPathElementPos = base.lastIndexOf('/');
543                     if (lastPathElementPos == -1) {
544                         // this should never occur as the base should
545
// always be protocol:/....
546
return null; // we can't resolve this
547
} else {
548                         xslSource = m_resolver.resolveURI(base.substring(0, lastPathElementPos) + "/" + href);
549                     }
550                 } else {
551                     File JavaDoc parent = new File JavaDoc(base.substring(5));
552                     File JavaDoc parent2 = new File JavaDoc(parent.getParentFile(), href);
553                     xslSource = m_resolver.resolveURI(parent2.toURL().toExternalForm());
554                 }
555             }
556
557             InputSource JavaDoc is = getInputSource(xslSource);
558
559             if (getLogger().isDebugEnabled()) {
560                 getLogger().debug("xslSource = " + xslSource + ", system id = " + xslSource.getURI());
561             }
562
563             if (m_checkIncludes) {
564                 // Populate included validities
565
List JavaDoc includes = (List JavaDoc) m_includesMap.get(base);
566                 if (includes != null) {
567                     SourceValidity included = xslSource.getValidity();
568                     if (included != null) {
569                         includes.add(new Object JavaDoc[] { xslSource.getURI(), xslSource.getValidity() });
570                     } else {
571                         // One of the included stylesheets is not cacheable
572
m_includesMap.remove(base);
573                     }
574                 }
575             }
576
577             return new StreamSource JavaDoc(is.getByteStream(), is.getSystemId());
578         } catch (SourceException e) {
579             if (getLogger().isDebugEnabled()) {
580                 getLogger().debug("Failed to resolve " + href + "(base = " + base + "), return null", e);
581             }
582
583             // CZ: To obtain the same behaviour as when the resource is
584
// transformed by the XSLT Transformer we should return null here.
585
return null;
586         } catch (java.net.MalformedURLException JavaDoc mue) {
587             if (getLogger().isDebugEnabled()) {
588                 getLogger().debug("Failed to resolve " + href + "(base = " + base + "), return null", mue);
589             }
590
591             return null;
592         } catch (IOException JavaDoc ioe) {
593             if (getLogger().isDebugEnabled()) {
594                 getLogger().debug("Failed to resolve " + href + "(base = " + base + "), return null", ioe);
595             }
596
597             return null;
598         } finally {
599             m_resolver.release(xslSource);
600         }
601     }
602
603     /**
604      * Return a new <code>InputSource</code> object that uses the
605      * <code>InputStream</code> and the system ID of the <code>Source</code>
606      * object.
607      *
608      * @throws IOException
609      * if I/O error occured.
610      */

611     protected InputSource JavaDoc getInputSource(final Source JavaDoc source) throws IOException JavaDoc, SourceException {
612         final InputSource JavaDoc newObject = new InputSource JavaDoc(source.getInputStream());
613         newObject.setSystemId(source.getURI());
614         return newObject;
615     }
616
617     /**
618      * Recycle the component
619      */

620     public void recycle() {
621         m_includesMap.clear();
622         // restore default factory
623
if (m_factory != m_defaultFactory) {
624             m_factory = m_defaultFactory;
625         }
626     }
627
628     /**
629      * Subclass to allow for instanciation, as for some unknown reason the
630      * constructor is protected....
631      */

632     public static class MyTransformerHandlerAndValidity extends TransformerHandlerAndValidity {
633
634         protected MyTransformerHandlerAndValidity(TransformerHandler JavaDoc handler, SourceValidity validity) {
635             super(handler, validity);
636         }
637     }
638 }
639
Popular Tags