KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xalan > internal > xsltc > runtime > AbstractTranslet


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

17 /*
18  * $Id: AbstractTranslet.java,v 1.52 2004/02/16 22:55:55 minchau Exp $
19  */

20
21 package com.sun.org.apache.xalan.internal.xsltc.runtime;
22
23 import java.io.FileWriter JavaDoc;
24 import java.io.File JavaDoc;
25 import java.text.DecimalFormat JavaDoc;
26 import java.text.DecimalFormatSymbols JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.Enumeration JavaDoc;
29 import java.util.Vector JavaDoc;
30 import javax.xml.transform.Templates JavaDoc;
31 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
32 import org.w3c.dom.Document JavaDoc;
33 import org.w3c.dom.DOMImplementation JavaDoc;
34 import javax.xml.parsers.ParserConfigurationException JavaDoc;
35    
36
37 import com.sun.org.apache.xml.internal.dtm.DTM;
38
39 import com.sun.org.apache.xalan.internal.xsltc.DOM;
40 import com.sun.org.apache.xalan.internal.xsltc.DOMCache;
41 import com.sun.org.apache.xalan.internal.xsltc.DOMEnhancedForDTM;
42 import com.sun.org.apache.xalan.internal.xsltc.Translet;
43 import com.sun.org.apache.xalan.internal.xsltc.TransletException;
44 import com.sun.org.apache.xalan.internal.xsltc.dom.DOMAdapter;
45 import com.sun.org.apache.xalan.internal.xsltc.dom.KeyIndex;
46 import com.sun.org.apache.xalan.internal.xsltc.runtime.output.TransletOutputHandlerFactory;
47 import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
48 import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
49
50 /**
51  * @author Jacek Ambroziak
52  * @author Santiago Pericas-Geertsen
53  * @author Morten Jorgensen
54  * @author G. Todd Miller
55  * @author John Howard, JohnH@schemasoft.com
56  */

57 public abstract class AbstractTranslet implements Translet {
58
59     // These attributes are extracted from the xsl:output element. They also
60
// appear as fields (with the same type, only public) in Output.java
61
public String JavaDoc _version = "1.0";
62     public String JavaDoc _method = null;
63     public String JavaDoc _encoding = "UTF-8";
64     public boolean _omitHeader = false;
65     public String JavaDoc _standalone = null;
66     public String JavaDoc _doctypePublic = null;
67     public String JavaDoc _doctypeSystem = null;
68     public boolean _indent = false;
69     public String JavaDoc _mediaType = null;
70     public Vector JavaDoc _cdata = null;
71     public int _indentamount = -1;
72
73     public static final int FIRST_TRANSLET_VERSION = 100;
74     public static final int VER_SPLIT_NAMES_ARRAY = 101;
75     public static final int CURRENT_TRANSLET_VERSION = VER_SPLIT_NAMES_ARRAY;
76
77     // Initialize Translet version field to base value. A class that extends
78
// AbstractTranslet may override this value to a more recent translet
79
// version; if it doesn't override the value (because it was compiled
80
// before the notion of a translet version was introduced, it will get
81
// this default value).
82
protected int transletVersion = FIRST_TRANSLET_VERSION;
83
84     // DOM/translet handshaking - the arrays are set by the compiled translet
85
protected String JavaDoc[] namesArray;
86     protected String JavaDoc[] urisArray;
87     protected int[] typesArray;
88     protected String JavaDoc[] namespaceArray;
89     
90     // The Templates object that is used to create this Translet instance
91
protected Templates JavaDoc _templates = null;
92     
93     // Boolean flag to indicate whether this translet has id functions.
94
protected boolean _hasIdCall = false;
95
96     // TODO - these should only be instanciated when needed
97
protected StringValueHandler stringValueHandler = new StringValueHandler();
98
99     // Use one empty string instead of constantly instanciating String("");
100
private final static String JavaDoc EMPTYSTRING = "";
101
102     // This is the name of the index used for ID attributes
103
private final static String JavaDoc ID_INDEX_NAME = "##id";
104
105     
106     /************************************************************************
107      * Debugging
108      ************************************************************************/

109     public void printInternalState() {
110     System.out.println("-------------------------------------");
111     System.out.println("AbstractTranslet this = " + this);
112     System.out.println("pbase = " + pbase);
113     System.out.println("vframe = " + pframe);
114     System.out.println("paramsStack.size() = " + paramsStack.size());
115     System.out.println("namesArray.size = " + namesArray.length);
116     System.out.println("namespaceArray.size = " + namespaceArray.length);
117     System.out.println("");
118     System.out.println("Total memory = " + Runtime.getRuntime().totalMemory());
119     }
120
121     /**
122      * Wrap the initial input DOM in a dom adapter. This adapter is wrapped in
123      * a DOM multiplexer if the document() function is used (handled by compiled
124      * code in the translet - see compiler/Stylesheet.compileTransform()).
125      */

126     public final DOMAdapter makeDOMAdapter(DOM dom)
127     throws TransletException {
128     return new DOMAdapter(dom, namesArray, urisArray, typesArray, namespaceArray);
129     }
130
131     /************************************************************************
132      * Parameter handling
133      ************************************************************************/

134
135     // Parameter's stack: <tt>pbase</tt> and <tt>pframe</tt> are used
136
// to denote the current parameter frame.
137
protected int pbase = 0, pframe = 0;
138     protected ArrayList JavaDoc paramsStack = new ArrayList JavaDoc();
139
140     /**
141      * Push a new parameter frame.
142      */

143     public final void pushParamFrame() {
144     paramsStack.add(pframe, new Integer JavaDoc(pbase));
145     pbase = ++pframe;
146     }
147
148     /**
149      * Pop the topmost parameter frame.
150      */

151     public final void popParamFrame() {
152     if (pbase > 0) {
153         final int oldpbase = ((Integer JavaDoc)paramsStack.get(--pbase)).intValue();
154         for (int i = pframe - 1; i >= pbase; i--) {
155         paramsStack.remove(i);
156         }
157         pframe = pbase; pbase = oldpbase;
158     }
159     }
160
161     /**
162      * Add a new global parameter if not already in the current frame.
163      * To setParameters of the form {http://foo.bar}xyz
164      * This needs to get mapped to an instance variable in the class
165      * The mapping created so that
166      * the global variables in the generated class become
167      * http$colon$$flash$$flash$foo$dot$bar$colon$xyz
168      */

169     public final Object JavaDoc addParameter(String JavaDoc name, Object JavaDoc value) {
170         name = BasisLibrary.mapQNameToJavaName (name);
171     return addParameter(name, value, false);
172     }
173
174     /**
175      * Add a new global or local parameter if not already in the current frame.
176      * The 'isDefault' parameter is set to true if the value passed is the
177      * default value from the <xsl:parameter> element's select attribute or
178      * element body.
179      */

180     public final Object JavaDoc addParameter(String JavaDoc name, Object JavaDoc value,
181     boolean isDefault)
182     {
183     // Local parameters need to be re-evaluated for each iteration
184
for (int i = pframe - 1; i >= pbase; i--) {
185         final Parameter param = (Parameter) paramsStack.get(i);
186
187         if (param._name.equals(name)) {
188         // Only overwrite if current value is the default value and
189
// the new value is _NOT_ the default value.
190
if (param._isDefault || !isDefault) {
191             param._value = value;
192             param._isDefault = isDefault;
193             return value;
194         }
195         return param._value;
196         }
197     }
198
199     // Add new parameter to parameter stack
200
paramsStack.add(pframe++, new Parameter(name, value, isDefault));
201     return value;
202     }
203
204     /**
205      * Clears the parameter stack.
206      */

207     public void clearParameters() {
208     pbase = pframe = 0;
209     paramsStack.clear();
210     }
211
212     /**
213      * Get the value of a parameter from the current frame or
214      * <tt>null</tt> if undefined.
215      */

216     public final Object JavaDoc getParameter(String JavaDoc name) {
217
218         name = BasisLibrary.mapQNameToJavaName (name);
219
220     for (int i = pframe - 1; i >= pbase; i--) {
221         final Parameter param = (Parameter)paramsStack.get(i);
222         if (param._name.equals(name)) return param._value;
223     }
224     return null;
225     }
226
227     /************************************************************************
228      * Message handling - implementation of <xsl:message>
229      ************************************************************************/

230
231     // Holds the translet's message handler - used for <xsl:message>.
232
// The deault message handler dumps a string stdout, but anything can be
233
// used, such as a dialog box for applets, etc.
234
private MessageHandler _msgHandler = null;
235
236     /**
237      * Set the translet's message handler - must implement MessageHandler
238      */

239     public final void setMessageHandler(MessageHandler handler) {
240     _msgHandler = handler;
241     }
242
243     /**
244      * Pass a message to the message handler - used by Message class.
245      */

246     public final void displayMessage(String JavaDoc msg) {
247     if (_msgHandler == null) {
248             System.err.println(msg);
249     }
250     else {
251         _msgHandler.displayMessage(msg);
252     }
253     }
254
255     /************************************************************************
256      * Decimal number format symbol handling
257      ************************************************************************/

258
259     // Contains decimal number formatting symbols used by FormatNumberCall
260
public Hashtable _formatSymbols = null;
261
262     /**
263      * Adds a DecimalFormat object to the _formatSymbols hashtable.
264      * The entry is created with the input DecimalFormatSymbols.
265      */

266     public void addDecimalFormat(String JavaDoc name, DecimalFormatSymbols JavaDoc symbols) {
267     // Instanciate hashtable for formatting symbols if needed
268
if (_formatSymbols == null) _formatSymbols = new Hashtable();
269
270     // The name cannot be null - use empty string instead
271
if (name == null) name = EMPTYSTRING;
272
273     // Construct a DecimalFormat object containing the symbols we got
274
final DecimalFormat JavaDoc df = new DecimalFormat JavaDoc();
275     if (symbols != null) {
276         df.setDecimalFormatSymbols(symbols);
277     }
278     _formatSymbols.put(name, df);
279     }
280
281     /**
282      * Retrieves a named DecimalFormat object from _formatSymbols hashtable.
283      */

284     public final DecimalFormat JavaDoc getDecimalFormat(String JavaDoc name) {
285
286     if (_formatSymbols != null) {
287         // The name cannot be null - use empty string instead
288
if (name == null) name = EMPTYSTRING;
289
290         DecimalFormat JavaDoc df = (DecimalFormat JavaDoc)_formatSymbols.get(name);
291         if (df == null) df = (DecimalFormat JavaDoc)_formatSymbols.get(EMPTYSTRING);
292         return df;
293     }
294     return(null);
295     }
296
297     /**
298      * Give the translet an opportunity to perform a prepass on the document
299      * to extract any information that it can store in an optimized form.
300      *
301      * Currently, it only extracts information about attributes of type ID.
302      */

303     public final void prepassDocument(DOM document) {
304         setIndexSize(document.getSize());
305         buildIDIndex(document);
306     }
307
308     /**
309      * Leverages the Key Class to implement the XSLT id() function.
310      * buildIdIndex creates the index (##id) that Key Class uses.
311      * The index contains the element node index (int) and Id value (String).
312      */

313     private final void buildIDIndex(DOM document) {
314         
315         if (document instanceof DOMEnhancedForDTM) {
316             DOMEnhancedForDTM enhancedDOM = (DOMEnhancedForDTM)document;
317             
318             // If the input source is DOMSource, the KeyIndex table is not
319
// built at this time. It will be built later by the lookupId()
320
// and containsId() methods of the KeyIndex class.
321
if (enhancedDOM.hasDOMSource()) {
322                 buildKeyIndex(ID_INDEX_NAME, document);
323                 return;
324             }
325             else {
326                 final Hashtable elementsByID = enhancedDOM.getElementsWithIDs();
327
328                 if (elementsByID == null) {
329                     return;
330                 }
331
332                 // Given a Hashtable of DTM nodes indexed by ID attribute values,
333
// loop through the table copying information to a KeyIndex
334
// for the mapping from ID attribute value to DTM node
335
final Enumeration JavaDoc idValues = elementsByID.keys();
336                 boolean hasIDValues = false;
337
338                 while (idValues.hasMoreElements()) {
339                     final Object JavaDoc idValue = idValues.nextElement();
340                     final int element = ((Integer JavaDoc)elementsByID.get(idValue)).intValue();
341
342                     buildKeyIndex(ID_INDEX_NAME, element, idValue);
343                     hasIDValues = true;
344                 }
345
346                 if (hasIDValues) {
347                     setKeyIndexDom(ID_INDEX_NAME, document);
348                 }
349             }
350         }
351     }
352
353     /**
354      * After constructing the translet object, this method must be called to
355      * perform any version-specific post-initialization that's required.
356      */

357     public final void postInitialization() {
358         // If the version of the translet had just one namesArray, split
359
// it into multiple fields.
360
if (transletVersion < VER_SPLIT_NAMES_ARRAY) {
361             int arraySize = namesArray.length;
362             String JavaDoc[] newURIsArray = new String JavaDoc[arraySize];
363             String JavaDoc[] newNamesArray = new String JavaDoc[arraySize];
364             int[] newTypesArray = new int[arraySize];
365
366             for (int i = 0; i < arraySize; i++) {
367                 String JavaDoc name = namesArray[i];
368                 int colonIndex = name.lastIndexOf(':');
369                 int lNameStartIdx = colonIndex+1;
370
371                 if (colonIndex > -1) {
372                     newURIsArray[i] = name.substring(0, colonIndex);
373                 }
374
375                // Distinguish attribute and element names. Attribute has
376
// @ before local part of name.
377
if (name.charAt(lNameStartIdx) == '@') {
378                    lNameStartIdx++;
379                    newTypesArray[i] = DTM.ATTRIBUTE_NODE;
380                } else if (name.charAt(lNameStartIdx) == '?') {
381                    lNameStartIdx++;
382                    newTypesArray[i] = DTM.NAMESPACE_NODE;
383                } else {
384                    newTypesArray[i] = DTM.ELEMENT_NODE;
385                }
386                newNamesArray[i] =
387                           (lNameStartIdx == 0) ? name
388                                                : name.substring(lNameStartIdx);
389             }
390
391             namesArray = newNamesArray;
392             urisArray = newURIsArray;
393             typesArray = newTypesArray;
394         }
395
396         // Was translet compiled using a more recent version of the XSLTC
397
// compiler than is known by the AbstractTranslet class? If, so
398
// and we've made it this far (which is doubtful), we should give up.
399
if (transletVersion > CURRENT_TRANSLET_VERSION) {
400             BasisLibrary.runTimeError(BasisLibrary.UNKNOWN_TRANSLET_VERSION_ERR,
401                                       this.getClass().getName());
402         }
403     }
404
405     /************************************************************************
406      * Index(es) for <xsl:key> / key() / id()
407      ************************************************************************/

408
409     // Container for all indexes for xsl:key elements
410
private Hashtable _keyIndexes = null;
411     private KeyIndex _emptyKeyIndex = null;
412     private int _indexSize = 0;
413
414     /**
415      * This method is used to pass the largest DOM size to the translet.
416      * Needed to make sure that the translet can index the whole DOM.
417      */

418     public void setIndexSize(int size) {
419     if (size > _indexSize) _indexSize = size;
420     }
421
422     /**
423      * Creates a KeyIndex object of the desired size - don't want to resize!!!
424      */

425     public KeyIndex createKeyIndex() {
426     return(new KeyIndex(_indexSize));
427     }
428
429     /**
430      * Adds a value to a key/id index
431      * @name is the name of the index (the key or ##id)
432      * @node is the node id of the node to insert
433      * @value is the value that will look up the node in the given index
434      */

435     public void buildKeyIndex(String JavaDoc name, int node, Object JavaDoc value) {
436     if (_keyIndexes == null) _keyIndexes = new Hashtable();
437     
438     KeyIndex index = (KeyIndex)_keyIndexes.get(name);
439     if (index == null) {
440         _keyIndexes.put(name, index = new KeyIndex(_indexSize));
441     }
442     index.add(value, node);
443     }
444
445     /**
446      * Create an empty KeyIndex in the DOM case
447      * @name is the name of the index (the key or ##id)
448      * @node is the DOM
449      */

450     public void buildKeyIndex(String JavaDoc name, DOM dom) {
451     if (_keyIndexes == null) _keyIndexes = new Hashtable();
452     
453     KeyIndex index = (KeyIndex)_keyIndexes.get(name);
454     if (index == null) {
455         _keyIndexes.put(name, index = new KeyIndex(_indexSize));
456     }
457     index.setDom(dom);
458     }
459
460     /**
461      * Returns the index for a given key (or id).
462      * The index implements our internal iterator interface
463      */

464     public KeyIndex getKeyIndex(String JavaDoc name) {
465     // Return an empty key index iterator if none are defined
466
if (_keyIndexes == null) {
467         return (_emptyKeyIndex != null)
468             ? _emptyKeyIndex
469             : (_emptyKeyIndex = new KeyIndex(1));
470     }
471
472     // Look up the requested key index
473
final KeyIndex index = (KeyIndex)_keyIndexes.get(name);
474
475     // Return an empty key index iterator if the requested index not found
476
if (index == null) {
477         return (_emptyKeyIndex != null)
478             ? _emptyKeyIndex
479             : (_emptyKeyIndex = new KeyIndex(1));
480     }
481
482     return(index);
483     }
484
485     /**
486      * This method builds key indexes - it is overridden in the compiled
487      * translet in cases where the <xsl:key> element is used
488      */

489     public void buildKeys(DOM document, DTMAxisIterator iterator,
490               SerializationHandler handler,
491               int root) throws TransletException {
492                 
493     }
494     
495     /**
496      * This method builds key indexes - it is overridden in the compiled
497      * translet in cases where the <xsl:key> element is used
498      */

499     public void setKeyIndexDom(String JavaDoc name, DOM document) {
500         getKeyIndex(name).setDom(document);
501                 
502     }
503
504     /************************************************************************
505      * DOM cache handling
506      ************************************************************************/

507
508     // Hold the DOM cache (if any) used with this translet
509
private DOMCache _domCache = null;
510
511     /**
512      * Sets the DOM cache used for additional documents loaded using the
513      * document() function.
514      */

515     public void setDOMCache(DOMCache cache) {
516     _domCache = cache;
517     }
518
519     /**
520      * Returns the DOM cache used for this translet. Used by the LoadDocument
521      * class (if present) when the document() function is used.
522      */

523     public DOMCache getDOMCache() {
524     return(_domCache);
525     }
526
527     /************************************************************************
528      * Multiple output document extension.
529      * See compiler/TransletOutput for actual implementation.
530      ************************************************************************/

531
532     public SerializationHandler openOutputHandler(String JavaDoc filename, boolean append)
533     throws TransletException
534     {
535     try {
536         final TransletOutputHandlerFactory factory
537         = TransletOutputHandlerFactory.newInstance();
538
539             String JavaDoc dirStr = new File JavaDoc(filename).getParent();
540             if ((null != dirStr) && (dirStr.length() > 0)) {
541                File JavaDoc dir = new File JavaDoc(dirStr);
542                dir.mkdirs();
543             }
544
545         factory.setEncoding(_encoding);
546         factory.setOutputMethod(_method);
547         factory.setWriter(new FileWriter JavaDoc(filename, append));
548         factory.setOutputType(TransletOutputHandlerFactory.STREAM);
549
550         final SerializationHandler handler
551         = factory.getSerializationHandler();
552
553         transferOutputSettings(handler);
554         handler.startDocument();
555         return handler;
556     }
557     catch (Exception JavaDoc e) {
558         throw new TransletException(e);
559     }
560     }
561
562     public SerializationHandler openOutputHandler(String JavaDoc filename)
563        throws TransletException
564     {
565        return openOutputHandler(filename, false);
566     }
567
568     public void closeOutputHandler(SerializationHandler handler) {
569     try {
570         handler.endDocument();
571         handler.close();
572     }
573     catch (Exception JavaDoc e) {
574         // what can you do?
575
}
576     }
577
578     /************************************************************************
579      * Native API transformation methods - _NOT_ JAXP/TrAX
580      ************************************************************************/

581
582     /**
583      * Main transform() method - this is overridden by the compiled translet
584      */

585     public abstract void transform(DOM document, DTMAxisIterator iterator,
586                    SerializationHandler handler)
587     throws TransletException;
588
589     /**
590      * Calls transform() with a given output handler
591      */

592     public final void transform(DOM document, SerializationHandler handler)
593     throws TransletException {
594     transform(document, document.getIterator(), handler);
595     }
596     
597     /**
598      * Used by some compiled code as a shortcut for passing strings to the
599      * output handler
600      */

601     public final void characters(final String JavaDoc string,
602                  SerializationHandler handler)
603     throws TransletException {
604         if (string != null) {
605            //final int length = string.length();
606
try {
607                handler.characters(string);
608            } catch (Exception JavaDoc e) {
609                throw new TransletException(e);
610            }
611         }
612     }
613
614     /**
615      * Add's a name of an element whose text contents should be output as CDATA
616      */

617     public void addCdataElement(String JavaDoc name) {
618     if (_cdata == null) {
619             _cdata = new Vector JavaDoc();
620         }
621
622         int lastColon = name.lastIndexOf(':');
623
624         if (lastColon > 0) {
625             String JavaDoc uri = name.substring(0, lastColon);
626             String JavaDoc localName = name.substring(lastColon+1);
627         _cdata.addElement(uri);
628         _cdata.addElement(localName);
629         } else {
630         _cdata.addElement(null);
631         _cdata.addElement(name);
632         }
633     }
634
635     /**
636      * Transfer the output settings to the output post-processor
637      */

638     protected void transferOutputSettings(SerializationHandler handler) {
639     if (_method != null) {
640         if (_method.equals("xml")) {
641             if (_standalone != null) {
642             handler.setStandalone(_standalone);
643         }
644         if (_omitHeader) {
645             handler.setOmitXMLDeclaration(true);
646         }
647         handler.setCdataSectionElements(_cdata);
648         if (_version != null) {
649             handler.setVersion(_version);
650         }
651         handler.setIndent(_indent);
652         handler.setIndentAmount(_indentamount);
653         if (_doctypeSystem != null) {
654             handler.setDoctype(_doctypeSystem, _doctypePublic);
655         }
656         }
657         else if (_method.equals("html")) {
658         handler.setIndent(_indent);
659         handler.setDoctype(_doctypeSystem, _doctypePublic);
660         if (_mediaType != null) {
661             handler.setMediaType(_mediaType);
662         }
663         }
664     }
665     else {
666         handler.setCdataSectionElements(_cdata);
667         if (_version != null) {
668         handler.setVersion(_version);
669         }
670         if (_standalone != null) {
671         handler.setStandalone(_standalone);
672         }
673         if (_omitHeader) {
674         handler.setOmitXMLDeclaration(true);
675         }
676         handler.setIndent(_indent);
677         handler.setDoctype(_doctypeSystem, _doctypePublic);
678     }
679     }
680
681     private Hashtable _auxClasses = null;
682
683     public void addAuxiliaryClass(Class JavaDoc auxClass) {
684     if (_auxClasses == null) _auxClasses = new Hashtable();
685     _auxClasses.put(auxClass.getName(), auxClass);
686     }
687
688     public void setAuxiliaryClasses(Hashtable auxClasses) {
689         _auxClasses = auxClasses;
690     }
691     
692     public Class JavaDoc getAuxiliaryClass(String JavaDoc className) {
693     if (_auxClasses == null) return null;
694     return((Class JavaDoc)_auxClasses.get(className));
695     }
696
697     // GTM added (see pg 110)
698
public String JavaDoc[] getNamesArray() {
699     return namesArray;
700     }
701     
702     public String JavaDoc[] getUrisArray() {
703         return urisArray;
704     }
705     
706     public int[] getTypesArray() {
707         return typesArray;
708     }
709     
710     public String JavaDoc[] getNamespaceArray() {
711     return namespaceArray;
712     }
713     
714     public boolean hasIdCall() {
715         return _hasIdCall;
716     }
717     
718     public Templates JavaDoc getTemplates() {
719         return _templates;
720     }
721     
722     public void setTemplates(Templates JavaDoc templates) {
723         _templates = templates;
724     }
725       
726    /************************************************************************
727     * DOMImplementation caching for basis library
728     ************************************************************************/

729     protected DOMImplementation JavaDoc _domImplementation = null;
730     
731     public Document JavaDoc newDocument(String JavaDoc uri, String JavaDoc qname)
732           throws ParserConfigurationException JavaDoc
733     {
734         if (_domImplementation == null) {
735             _domImplementation = DocumentBuilderFactory.newInstance()
736                 .newDocumentBuilder().getDOMImplementation();
737         }
738         return _domImplementation.createDocument(uri, qname, null);
739     }
740 }
741
Popular Tags