KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > templates > Stylesheet


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 /*
17  * $Id: Stylesheet.java,v 1.30 2004/02/16 20:32:32 minchau Exp $
18  */

19 package org.apache.xalan.templates;
20
21 import java.io.IOException JavaDoc;
22 import java.io.ObjectInputStream JavaDoc;
23 import java.io.ObjectOutputStream JavaDoc;
24 import java.util.Hashtable JavaDoc;
25 import java.util.Stack JavaDoc;
26 import java.util.Vector JavaDoc;
27
28 import javax.xml.transform.SourceLocator JavaDoc;
29 import javax.xml.transform.TransformerException JavaDoc;
30
31 import org.apache.xml.dtm.DTM;
32 import org.apache.xml.utils.QName;
33 import org.apache.xml.utils.StringVector;
34 import org.apache.xml.utils.SystemIDResolver;
35
36 /**
37  * Represents a stylesheet element.
38  * <p>All properties in this class have a fixed form of bean-style property
39  * accessors for all properties that represent XSL attributes or elements.
40  * These properties have setter method names accessed generically by the
41  * processor, and so these names must be fixed according to the system
42  * defined in the <a HREF="XSLTAttributeDef#getSetterMethodName">getSetterMethodName</a>
43  * function.</p>
44  * <p><pre>
45  * <!ENTITY % top-level "
46  * (xsl:import*,
47  * (xsl:include
48  * | xsl:strip-space
49  * | xsl:preserve-space
50  * | xsl:output
51  * | xsl:key
52  * | xsl:decimal-format
53  * | xsl:attribute-set
54  * | xsl:variable
55  * | xsl:param
56  * | xsl:template
57  * | xsl:namespace-alias
58  * %non-xsl-top-level;)*)
59  * ">
60  *
61  * <!ENTITY % top-level-atts '
62  * extension-element-prefixes CDATA #IMPLIED
63  * exclude-result-prefixes CDATA #IMPLIED
64  * id ID #IMPLIED
65  * version NMTOKEN #REQUIRED
66  * xmlns:xsl CDATA #FIXED "http://www.w3.org/1999/XSL/Transform"
67  * %space-att;
68  * '>
69  *
70  * <!ELEMENT xsl:stylesheet %top-level;>
71  * <!ATTLIST xsl:stylesheet %top-level-atts;>
72  *
73  * <!ELEMENT xsl:transform %top-level;>
74  * <!ATTLIST xsl:transform %top-level-atts;>
75  *
76  * </p></pre>
77  * @see <a HREF="http://www.w3.org/TR/xslt#section-Stylesheet-Structure">section-Stylesheet-Structure in XSLT Specification</a>
78  */

79 public class Stylesheet extends ElemTemplateElement
80         implements java.io.Serializable JavaDoc /* , Document */
81 {
82
83   /**
84    * Constructor for a Stylesheet.
85    * @param parent The including or importing stylesheet.
86    */

87   public Stylesheet(Stylesheet parent)
88   {
89
90     if (null != parent)
91     {
92       m_stylesheetParent = parent;
93       m_stylesheetRoot = parent.getStylesheetRoot();
94     }
95   }
96
97   /**
98    * Get the owning stylesheet. This looks up the
99    * inheritance chain until it calls getStylesheet
100    * on a Stylesheet object, which will return itself.
101    *
102    * @return The owning stylesheet, itself.
103    */

104   public Stylesheet getStylesheet()
105   {
106     return this;
107   }
108
109   /**
110    * Tell if this can be cast to a StylesheetComposed, meaning, you
111    * can ask questions from getXXXComposed functions.
112    *
113    * @return False if this is not a StylesheetComposed
114    */

115   public boolean isAggregatedType()
116   {
117     return false;
118   }
119
120   /**
121    * Tell if this is the root of the stylesheet tree.
122    *
123    * @return False is this is not the root of the stylesheet tree.
124    */

125   public boolean isRoot()
126   {
127     return false;
128   }
129
130   /**
131    * Extension to be used when serializing to disk.
132    */

133   public static final String JavaDoc STYLESHEET_EXT = ".lxc";
134
135   /**
136    * Read the stylesheet from a serialization stream.
137    *
138    * @param stream Input stream to read from
139    *
140    * @throws IOException
141    * @throws TransformerException
142    */

143   private void readObject(ObjectInputStream JavaDoc stream)
144           throws IOException JavaDoc, TransformerException JavaDoc
145   {
146
147     // System.out.println("Reading Stylesheet");
148
try
149     {
150       stream.defaultReadObject();
151     }
152     catch (ClassNotFoundException JavaDoc cnfe)
153     {
154       throw new TransformerException JavaDoc(cnfe);
155     }
156
157     // System.out.println("Done reading Stylesheet");
158
}
159
160   /**
161    * Write out the given output stream
162    *
163    *
164    * @param stream The output stream to write out
165    *
166    * @throws IOException
167    */

168   private void writeObject(ObjectOutputStream JavaDoc stream) throws IOException JavaDoc
169   {
170
171     // System.out.println("Writing Stylesheet");
172
stream.defaultWriteObject();
173
174     // System.out.println("Done writing Stylesheet");
175
}
176
177   //============== XSLT Properties =================
178

179   /**
180    * The "xmlns:xsl" property.
181    * @serial
182    */

183   private String JavaDoc m_XmlnsXsl;
184
185   /**
186    * Set the "xmlns:xsl" property.
187    * @see <a HREF="http://www.w3.org/TR/xslt#xslt-namespace">xslt-namespace in XSLT Specification</a>
188    *
189    * @param v The value to be set for the "xmlns:xsl" property.
190    */

191   public void setXmlnsXsl(String JavaDoc v)
192   {
193     m_XmlnsXsl = v;
194   }
195
196   /**
197    * Get the "xmlns:xsl" property.
198    * @see <a HREF="http://www.w3.org/TR/xslt#xslt-namespace">xslt-namespace in XSLT Specification</a>
199    *
200    * @return The value of the "xmlns:xsl" property.
201    */

202   public String JavaDoc getXmlnsXsl()
203   {
204     return m_XmlnsXsl;
205   }
206
207   /**
208    * The "extension-element-prefixes" property, actually contains URIs.
209    * @serial
210    */

211   private StringVector m_ExtensionElementURIs;
212
213   /**
214    * Set the "extension-element-prefixes" property.
215    * @see <a HREF="http://www.w3.org/TR/xslt#extension-element">extension-element in XSLT Specification</a>
216    *
217    * @param v The value to be set for the "extension-element-prefixes"
218    * property: a vector of extension element URIs.
219    */

220   public void setExtensionElementPrefixes(StringVector v)
221   {
222     m_ExtensionElementURIs = v;
223   }
224
225   /**
226    * Get and "extension-element-prefix" property.
227    * @see <a HREF="http://www.w3.org/TR/xslt#extension-element">extension-element in XSLT Specification</a>
228    *
229    * @param i Index of extension element URI in list
230    *
231    * @return The extension element URI at the given index
232    *
233    * @throws ArrayIndexOutOfBoundsException
234    */

235   public String JavaDoc getExtensionElementPrefix(int i)
236           throws ArrayIndexOutOfBoundsException JavaDoc
237   {
238
239     if (null == m_ExtensionElementURIs)
240       throw new ArrayIndexOutOfBoundsException JavaDoc();
241
242     return m_ExtensionElementURIs.elementAt(i);
243   }
244
245   /**
246    * Get the number of "extension-element-prefixes" Strings.
247    * @see <a HREF="http://www.w3.org/TR/xslt#extension-element">extension-element in XSLT Specification</a>
248    *
249    * @return Number of URIs in the list
250    */

251   public int getExtensionElementPrefixCount()
252   {
253     return (null != m_ExtensionElementURIs)
254            ? m_ExtensionElementURIs.size() : 0;
255   }
256
257   /**
258    * Find out if this contains a given "extension-element-prefix" property.
259    * @see <a HREF="http://www.w3.org/TR/xslt#extension-element">extension-element in XSLT Specification</a>
260    *
261    * @param uri URI of extension element to look for
262    *
263    * @return True if the given URI was found in the list
264    */

265   public boolean containsExtensionElementURI(String JavaDoc uri)
266   {
267
268     if (null == m_ExtensionElementURIs)
269       return false;
270
271     return m_ExtensionElementURIs.contains(uri);
272   }
273
274   /**
275    * The "exclude-result-prefixes" property.
276    * @serial
277    */

278   private StringVector m_ExcludeResultPrefixs;
279
280   /**
281    * Set the "exclude-result-prefixes" property.
282    * The designation of a namespace as an excluded namespace is
283    * effective within the subtree of the stylesheet rooted at
284    * the element bearing the exclude-result-prefixes or
285    * xsl:exclude-result-prefixes attribute; a subtree rooted
286    * at an xsl:stylesheet element does not include any stylesheets
287    * imported or included by children of that xsl:stylesheet element.
288    * @see <a HREF="http://www.w3.org/TR/xslt#literal-result-element">literal-result-element in XSLT Specification</a>
289    *
290    * @param v A StringVector of prefixes to exclude
291    */

292   public void setExcludeResultPrefixes(StringVector v)
293   {
294     m_ExcludeResultPrefixs = v;
295   }
296
297   /**
298    * Get an "exclude-result-prefix" property.
299    * The designation of a namespace as an excluded namespace is
300    * effective within the subtree of the stylesheet rooted at
301    * the element bearing the exclude-result-prefixes or
302    * xsl:exclude-result-prefixes attribute; a subtree rooted
303    * at an xsl:stylesheet element does not include any stylesheets
304    * imported or included by children of that xsl:stylesheet element.
305    * @see <a HREF="http://www.w3.org/TR/xslt#literal-result-element">literal-result-element in XSLT Specification</a>
306    *
307    * @param i Index of prefix to get in list
308    *
309    * @return Prefix to be excluded at the given index
310    *
311    * @throws ArrayIndexOutOfBoundsException
312    */

313   public String JavaDoc getExcludeResultPrefix(int i)
314           throws ArrayIndexOutOfBoundsException JavaDoc
315   {
316
317     if (null == m_ExcludeResultPrefixs)
318       throw new ArrayIndexOutOfBoundsException JavaDoc();
319
320     return m_ExcludeResultPrefixs.elementAt(i);
321   }
322
323   /**
324    * Get the number of "exclude-result-prefixes" Strings.
325    * @see <a HREF="http://www.w3.org/TR/xslt#literal-result-element">literal-result-element in XSLT Specification</a>
326    *
327    * @return The number of prefix strings to be excluded.
328    */

329   public int getExcludeResultPrefixCount()
330   {
331     return (null != m_ExcludeResultPrefixs)
332            ? m_ExcludeResultPrefixs.size() : 0;
333   }
334
335   /**
336    * Get whether or not the passed prefix is contained flagged by
337    * the "exclude-result-prefixes" property.
338    * @see <a HREF="http://www.w3.org/TR/xslt#literal-result-element">literal-result-element in XSLT Specification</a>
339    *
340    * @param prefix non-null reference to prefix that might be excluded.
341    * @param uri reference to namespace that prefix maps to
342    *
343    * @return true if the prefix should normally be excluded.>
344    */

345   public boolean containsExcludeResultPrefix(String JavaDoc prefix, String JavaDoc uri)
346   {
347
348     if (null == m_ExcludeResultPrefixs || uri == null )
349       return false;
350     
351     // This loop is ok here because this code only runs during
352
// stylesheet compile time.
353
for (int i =0; i< m_ExcludeResultPrefixs.size(); i++)
354     {
355       if (uri.equals(getNamespaceForPrefix(m_ExcludeResultPrefixs.elementAt(i))))
356         return true;
357     }
358     
359     return false;
360
361   /* if (prefix.length() == 0)
362       prefix = Constants.ATTRVAL_DEFAULT_PREFIX;
363
364     return m_ExcludeResultPrefixs.contains(prefix); */

365   }
366
367   /**
368    * The "id" property.
369    * @serial
370    */

371   private String JavaDoc m_Id;
372
373   /**
374    * Set the "id" property.
375    * @see <a HREF="http://www.w3.org/TR/xslt#section-Embedding-Stylesheets">section-Embedding-Stylesheets in XSLT Specification</a>
376    *
377    * @param v Value for the "id" property.
378    */

379   public void setId(String JavaDoc v)
380   {
381     m_Id = v;
382   }
383
384   /**
385    * Get the "id" property.
386    * @see <a HREF="http://www.w3.org/TR/xslt#section-Embedding-Stylesheets">section-Embedding-Stylesheets in XSLT Specification</a>
387    *
388    * @return The value of the "id" property.
389    */

390   public String JavaDoc getId()
391   {
392     return m_Id;
393   }
394
395   /**
396    * The "version" property.
397    * @serial
398    */

399   private String JavaDoc m_Version;
400   
401   /**
402    * Whether or not the stylesheet is in "Forward Compatibility Mode"
403    * @serial
404    */

405   private boolean m_isCompatibleMode = false;
406
407   /**
408    * Set the "version" property.
409    * @see <a HREF="http://www.w3.org/TR/xslt#forwards">forwards in XSLT Specification</a>
410    *
411    * @param v Value for the "version" property.
412    */

413   public void setVersion(String JavaDoc v)
414   {
415     m_Version = v;
416     m_isCompatibleMode = (Double.valueOf(v).doubleValue() > Constants.XSLTVERSUPPORTED);
417   }
418
419   /**
420    * Get whether or not the stylesheet is in "Forward Compatibility Mode"
421    *
422    * @return true if in forward compatible mode, false otherwise
423    */

424   public boolean getCompatibleMode()
425   {
426     return m_isCompatibleMode;
427   }
428
429   /**
430    * Get the "version" property.
431    * @see <a HREF="http://www.w3.org/TR/xslt#forwards">forwards in XSLT Specification</a>
432    *
433    * @return The value of the "version" property.
434    */

435   public String JavaDoc getVersion()
436   {
437     return m_Version;
438   }
439
440   /**
441    * The "xsl:import" list.
442    * @serial
443    */

444   private Vector JavaDoc m_imports;
445
446   /**
447    * Add a stylesheet to the "import" list.
448    * @see <a HREF="http://www.w3.org/TR/xslt#import">import in XSLT Specification</a>
449    *
450    * @param v Stylesheet to add to the import list
451    */

452   public void setImport(StylesheetComposed v)
453   {
454
455     if (null == m_imports)
456       m_imports = new Vector JavaDoc();
457
458     // I'm going to insert the elements in backwards order,
459
// so I can walk them 0 to n.
460
m_imports.addElement(v);
461   }
462
463   /**
464    * Get a stylesheet from the "import" list.
465    * @see <a HREF="http://www.w3.org/TR/xslt#import">import in XSLT Specification</a>
466    *
467    * @param i Index of the stylesheet to get
468    *
469    * @return The stylesheet at the given index
470    *
471    * @throws ArrayIndexOutOfBoundsException
472    */

473   public StylesheetComposed getImport(int i)
474           throws ArrayIndexOutOfBoundsException JavaDoc
475   {
476
477     if (null == m_imports)
478       throw new ArrayIndexOutOfBoundsException JavaDoc();
479
480     return (StylesheetComposed) m_imports.elementAt(i);
481   }
482
483   /**
484    * Get the number of imported stylesheets.
485    * @see <a HREF="http://www.w3.org/TR/xslt#import">import in XSLT Specification</a>
486    *
487    * @return the number of imported stylesheets.
488    */

489   public int getImportCount()
490   {
491     return (null != m_imports) ? m_imports.size() : 0;
492   }
493
494   /**
495    * The "xsl:include" properties.
496    * @serial
497    */

498   private Vector JavaDoc m_includes;
499
500   /**
501    * Add a stylesheet to the "include" list.
502    * @see <a HREF="http://www.w3.org/TR/xslt#include">include in XSLT Specification</a>
503    *
504    * @param v Stylesheet to add to the "include" list
505    */

506   public void setInclude(Stylesheet v)
507   {
508
509     if (null == m_includes)
510       m_includes = new Vector JavaDoc();
511
512     m_includes.addElement(v);
513   }
514
515   /**
516    * Get the stylesheet at the given in index in "include" list
517    * @see <a HREF="http://www.w3.org/TR/xslt#include">include in XSLT Specification</a>
518    *
519    * @param i Index of stylesheet to get
520    *
521    * @return Stylesheet at the given index
522    *
523    * @throws ArrayIndexOutOfBoundsException
524    */

525   public Stylesheet getInclude(int i) throws ArrayIndexOutOfBoundsException JavaDoc
526   {
527
528     if (null == m_includes)
529       throw new ArrayIndexOutOfBoundsException JavaDoc();
530
531     return (Stylesheet) m_includes.elementAt(i);
532   }
533
534   /**
535    * Get the number of included stylesheets.
536    * @see <a HREF="http://www.w3.org/TR/xslt#import">import in XSLT Specification</a>
537    *
538    * @return the number of included stylesheets.
539    */

540   public int getIncludeCount()
541   {
542     return (null != m_includes) ? m_includes.size() : 0;
543   }
544
545   /**
546    * Table of tables of element decimal-format.
547    * @see DecimalFormatProperties
548    * @serial
549    */

550   Stack JavaDoc m_DecimalFormatDeclarations;
551
552   /**
553    * Process the xsl:decimal-format element.
554    *
555    * @param edf Decimal-format element to push into stack
556    */

557   public void setDecimalFormat(DecimalFormatProperties edf)
558   {
559
560     if (null == m_DecimalFormatDeclarations)
561       m_DecimalFormatDeclarations = new Stack JavaDoc();
562
563     // Elements are pushed in by order of importance
564
// so that when recomposed, they get overiden properly.
565
m_DecimalFormatDeclarations.push(edf);
566   }
567
568   /**
569    * Get an "xsl:decimal-format" property.
570    *
571    * @see DecimalFormatProperties
572    * @see <a HREF="http://www.w3.org/TR/xslt#format-number">format-number in XSLT Specification</a>
573    *
574    * @param name The qualified name of the decimal format property.
575    * @return null if not found, otherwise a DecimalFormatProperties
576    * object, from which you can get a DecimalFormatSymbols object.
577    */

578   public DecimalFormatProperties getDecimalFormat(QName name)
579   {
580
581     if (null == m_DecimalFormatDeclarations)
582       return null;
583
584     int n = getDecimalFormatCount();
585
586     for (int i = (n - 1); i >= 0; i++)
587     {
588       DecimalFormatProperties dfp = getDecimalFormat(i);
589
590       if (dfp.getName().equals(name))
591         return dfp;
592     }
593
594     return null;
595   }
596
597   /**
598    * Get an "xsl:decimal-format" property.
599    * @see <a HREF="http://www.w3.org/TR/xslt#format-number">format-number in XSLT Specification</a>
600    * @see DecimalFormatProperties
601    *
602    * @param i Index of decimal-format property in stack
603    *
604    * @return The decimal-format property at the given index
605    *
606    * @throws ArrayIndexOutOfBoundsException
607    */

608   public DecimalFormatProperties getDecimalFormat(int i)
609           throws ArrayIndexOutOfBoundsException JavaDoc
610   {
611
612     if (null == m_DecimalFormatDeclarations)
613       throw new ArrayIndexOutOfBoundsException JavaDoc();
614
615     return (DecimalFormatProperties) m_DecimalFormatDeclarations.elementAt(i);
616   }
617
618   /**
619    * Get the number of xsl:decimal-format declarations.
620    * @see DecimalFormatProperties
621    *
622    * @return the number of xsl:decimal-format declarations.
623    */

624   public int getDecimalFormatCount()
625   {
626     return (null != m_DecimalFormatDeclarations)
627            ? m_DecimalFormatDeclarations.size() : 0;
628   }
629
630   /**
631    * The "xsl:strip-space" properties,
632    * A lookup table of all space stripping elements.
633    * @serial
634    */

635   private Vector JavaDoc m_whitespaceStrippingElements;
636
637   /**
638    * Set the "xsl:strip-space" properties.
639    * @see <a HREF="http://www.w3.org/TR/xslt#strip">strip in XSLT Specification</a>
640    *
641    * @param wsi WhiteSpaceInfo element to add to list
642    */

643   public void setStripSpaces(WhiteSpaceInfo wsi)
644   {
645
646     if (null == m_whitespaceStrippingElements)
647     {
648       m_whitespaceStrippingElements = new Vector JavaDoc();
649     }
650
651     m_whitespaceStrippingElements.addElement(wsi);
652   }
653
654   /**
655    * Get an "xsl:strip-space" property.
656    * @see <a HREF="http://www.w3.org/TR/xslt#strip">strip in XSLT Specification</a>
657    *
658    * @param i Index of WhiteSpaceInfo to get
659    *
660    * @return WhiteSpaceInfo at given index
661    *
662    * @throws ArrayIndexOutOfBoundsException
663    */

664   public WhiteSpaceInfo getStripSpace(int i) throws ArrayIndexOutOfBoundsException JavaDoc
665   {
666
667     if (null == m_whitespaceStrippingElements)
668       throw new ArrayIndexOutOfBoundsException JavaDoc();
669
670     return (WhiteSpaceInfo) m_whitespaceStrippingElements.elementAt(i);
671   }
672
673   /**
674    * Get the number of "xsl:strip-space" properties.
675    * @see <a HREF="http://www.w3.org/TR/xslt#strip">strip in XSLT Specification</a>
676    *
677    * @return the number of "xsl:strip-space" properties.
678    */

679   public int getStripSpaceCount()
680   {
681     return (null != m_whitespaceStrippingElements)
682            ? m_whitespaceStrippingElements.size() : 0;
683   }
684
685   /**
686    * The "xsl:preserve-space" property,
687    * A lookup table of all space preserving elements.
688    * @serial
689    */

690   private Vector JavaDoc m_whitespacePreservingElements;
691
692   /**
693    * Set the "xsl:preserve-space" property.
694    * @see <a HREF="http://www.w3.org/TR/xslt#strip">strip in XSLT Specification</a>
695    *
696    * @param wsi WhiteSpaceInfo element to add to list
697    */

698   public void setPreserveSpaces(WhiteSpaceInfo wsi)
699   {
700
701     if (null == m_whitespacePreservingElements)
702     {
703       m_whitespacePreservingElements = new Vector JavaDoc();
704     }
705
706     m_whitespacePreservingElements.addElement(wsi);
707   }
708
709   /**
710    * Get a "xsl:preserve-space" property.
711    * @see <a HREF="http://www.w3.org/TR/xslt#strip">strip in XSLT Specification</a>
712    *
713    * @param i Index of WhiteSpaceInfo to get
714    *
715    * @return WhiteSpaceInfo at the given index
716    *
717    * @throws ArrayIndexOutOfBoundsException
718    */

719   public WhiteSpaceInfo getPreserveSpace(int i) throws ArrayIndexOutOfBoundsException JavaDoc
720   {
721
722     if (null == m_whitespacePreservingElements)
723       throw new ArrayIndexOutOfBoundsException JavaDoc();
724
725     return (WhiteSpaceInfo) m_whitespacePreservingElements.elementAt(i);
726   }
727
728   /**
729    * Get the number of "xsl:preserve-space" properties.
730    * @see <a HREF="http://www.w3.org/TR/xslt#strip">strip in XSLT Specification</a>
731    *
732    * @return the number of "xsl:preserve-space" properties.
733    */

734   public int getPreserveSpaceCount()
735   {
736     return (null != m_whitespacePreservingElements)
737            ? m_whitespacePreservingElements.size() : 0;
738   }
739
740   /**
741    * The "xsl:output" properties. This is a vector of OutputProperties objects.
742    * @serial
743    */

744   private Vector JavaDoc m_output;
745
746   /**
747    * Set the "xsl:output" property.
748    * @see <a HREF="http://www.w3.org/TR/xslt#output">output in XSLT Specification</a>
749    *
750    * @param v non-null reference to the OutputProperties object to be
751    * added to the collection.
752    */

753   public void setOutput(OutputProperties v)
754   {
755     if (null == m_output)
756     {
757       m_output = new Vector JavaDoc();
758     }
759
760     m_output.addElement(v);
761   }
762
763   /**
764    * Get an "xsl:output" property.
765    * @see <a HREF="http://www.w3.org/TR/xslt#output">output in XSLT Specification</a>
766    *
767    * @param i Index of OutputFormatExtended to get
768    *
769    * @return non-null reference to an OutputProperties object.
770    *
771    * @throws ArrayIndexOutOfBoundsException
772    */

773   public OutputProperties getOutput(int i) throws ArrayIndexOutOfBoundsException JavaDoc
774   {
775
776     if (null == m_output)
777       throw new ArrayIndexOutOfBoundsException JavaDoc();
778
779     return (OutputProperties) m_output.elementAt(i);
780   }
781
782   /**
783    * Get the number of "xsl:output" properties.
784    * @see <a HREF="http://www.w3.org/TR/xslt#output">output in XSLT Specification</a>
785    *
786    * @return The number of OutputProperties objects contained in this stylesheet.
787    */

788   public int getOutputCount()
789   {
790     return (null != m_output)
791            ? m_output.size() : 0;
792   }
793
794   /**
795    * The "xsl:key" property.
796    * @serial
797    */

798   private Vector JavaDoc m_keyDeclarations;
799
800   /**
801    * Set the "xsl:key" property.
802    * @see <a HREF="http://www.w3.org/TR/xslt#key">key in XSLT Specification</a>
803    *
804    * @param v KeyDeclaration element to add to the list of key declarations
805    */

806   public void setKey(KeyDeclaration v)
807   {
808
809     if (null == m_keyDeclarations)
810       m_keyDeclarations = new Vector JavaDoc();
811
812     m_keyDeclarations.addElement(v);
813   }
814
815   /**
816    * Get an "xsl:key" property.
817    * @see <a HREF="http://www.w3.org/TR/xslt#key">key in XSLT Specification</a>
818    *
819    * @param i Index of KeyDeclaration element to get
820    *
821    * @return KeyDeclaration element at given index in list
822    *
823    * @throws ArrayIndexOutOfBoundsException
824    */

825   public KeyDeclaration getKey(int i) throws ArrayIndexOutOfBoundsException JavaDoc
826   {
827
828     if (null == m_keyDeclarations)
829       throw new ArrayIndexOutOfBoundsException JavaDoc();
830
831     return (KeyDeclaration) m_keyDeclarations.elementAt(i);
832   }
833
834   /**
835    * Get the number of "xsl:key" properties.
836    * @see <a HREF="http://www.w3.org/TR/xslt#key">key in XSLT Specification</a>
837    *
838    * @return the number of "xsl:key" properties.
839    */

840   public int getKeyCount()
841   {
842     return (null != m_keyDeclarations) ? m_keyDeclarations.size() : 0;
843   }
844
845   /**
846    * The "xsl:attribute-set" property.
847    * @serial
848    */

849   private Vector JavaDoc m_attributeSets;
850
851   /**
852    * Set the "xsl:attribute-set" property.
853    * @see <a HREF="http://www.w3.org/TR/xslt#attribute-sets">attribute-sets in XSLT Specification</a>
854    *
855    * @param attrSet ElemAttributeSet to add to the list of attribute sets
856    */

857   public void setAttributeSet(ElemAttributeSet attrSet)
858   {
859
860     if (null == m_attributeSets)
861     {
862       m_attributeSets = new Vector JavaDoc();
863     }
864
865     m_attributeSets.addElement(attrSet);
866   }
867
868   /**
869    * Get an "xsl:attribute-set" property.
870    * @see <a HREF="http://www.w3.org/TR/xslt#attribute-sets">attribute-sets in XSLT Specification</a>
871    *
872    * @param i Index of ElemAttributeSet to get in list
873    *
874    * @return ElemAttributeSet at the given index
875    *
876    * @throws ArrayIndexOutOfBoundsException
877    */

878   public ElemAttributeSet getAttributeSet(int i)
879           throws ArrayIndexOutOfBoundsException JavaDoc
880   {
881
882     if (null == m_attributeSets)
883       throw new ArrayIndexOutOfBoundsException JavaDoc();
884
885     return (ElemAttributeSet) m_attributeSets.elementAt(i);
886   }
887
888   /**
889    * Get the number of "xsl:attribute-set" properties.
890    * @see <a HREF="http://www.w3.org/TR/xslt#attribute-sets">attribute-sets in XSLT Specification</a>
891    *
892    * @return the number of "xsl:attribute-set" properties.
893    */

894   public int getAttributeSetCount()
895   {
896     return (null != m_attributeSets) ? m_attributeSets.size() : 0;
897   }
898
899   /**
900    * The "xsl:variable" and "xsl:param" properties.
901    * @serial
902    */

903   private Vector JavaDoc m_topLevelVariables;
904
905   /**
906    * Set the "xsl:variable" property.
907    * @see <a HREF="http://www.w3.org/TR/xslt#top-level-variables">top-level-variables in XSLT Specification</a>
908    *
909    * @param v ElemVariable object to add to list of top level variables
910    */

911   public void setVariable(ElemVariable v)
912   {
913
914     if (null == m_topLevelVariables)
915       m_topLevelVariables = new Vector JavaDoc();
916
917     m_topLevelVariables.addElement(v);
918   }
919   
920   /**
921    * Get an "xsl:variable" or "xsl:param" property.
922    * @see <a HREF="http://www.w3.org/TR/xslt#top-level-variables">top-level-variables in XSLT Specification</a>
923    *
924    * @param qname non-null reference to the qualified name of the variable.
925    *
926    * @return The ElemVariable with the given name in the list or null
927    */

928   public ElemVariable getVariableOrParam(QName qname)
929   {
930
931     if (null != m_topLevelVariables)
932     {
933       int n = getVariableOrParamCount();
934
935       for (int i = 0; i < n; i++)
936       {
937         ElemVariable var = (ElemVariable) getVariableOrParam(i);
938
939         if (var.getName().equals(qname))
940           return var;
941       }
942     }
943
944     return null;
945   }
946
947
948   /**
949    * Get an "xsl:variable" property.
950    * @see <a HREF="http://www.w3.org/TR/xslt#top-level-variables">top-level-variables in XSLT Specification</a>
951    *
952    * @param qname Qualified name of the xsl:variable to get
953    *
954    * @return reference to the variable named by qname, or null if not found.
955    */

956   public ElemVariable getVariable(QName qname)
957   {
958
959     if (null != m_topLevelVariables)
960     {
961       int n = getVariableOrParamCount();
962
963       for (int i = 0; i < n; i++)
964       {
965         ElemVariable var = getVariableOrParam(i);
966         if((var.getXSLToken() == Constants.ELEMNAME_VARIABLE) &&
967            (var.getName().equals(qname)))
968           return var;
969       }
970     }
971
972     return null;
973   }
974
975   /**
976    * Get an "xsl:variable" property.
977    * @see <a HREF="http://www.w3.org/TR/xslt#top-level-variables">top-level-variables in XSLT Specification</a>
978    *
979    * @param i Index of variable to get in the list
980    *
981    * @return ElemVariable at the given index in the list
982    *
983    * @throws ArrayIndexOutOfBoundsException
984    */

985   public ElemVariable getVariableOrParam(int i) throws ArrayIndexOutOfBoundsException JavaDoc
986   {
987
988     if (null == m_topLevelVariables)
989       throw new ArrayIndexOutOfBoundsException JavaDoc();
990
991     return (ElemVariable) m_topLevelVariables.elementAt(i);
992   }
993
994   /**
995    * Get the number of "xsl:variable" properties.
996    * @see <a HREF="http://www.w3.org/TR/xslt#top-level-variables">top-level-variables in XSLT Specification</a>
997    *
998    * @return the number of "xsl:variable" properties.
999    */

1000  public int getVariableOrParamCount()
1001  {
1002    return (null != m_topLevelVariables) ? m_topLevelVariables.size() : 0;
1003  }
1004
1005  /**
1006   * Set an "xsl:param" property.
1007   * @see <a HREF="http://www.w3.org/TR/xslt#top-level-variables">top-level-variables in XSLT Specification</a>
1008   *
1009   * @param v A non-null ElemParam reference.
1010   */

1011  public void setParam(ElemParam v)
1012  {
1013    setVariable(v);
1014  }
1015
1016  /**
1017   * Get an "xsl:param" property.
1018   * @see <a HREF="http://www.w3.org/TR/xslt#top-level-variables">top-level-variables in XSLT Specification</a>
1019   *
1020   * @param qname non-null reference to qualified name of the parameter.
1021   *
1022   * @return ElemParam with the given name in the list or null
1023   */

1024  public ElemParam getParam(QName qname)
1025  {
1026
1027    if (null != m_topLevelVariables)
1028    {
1029      int n = getVariableOrParamCount();
1030
1031      for (int i = 0; i < n; i++)
1032      {
1033        ElemVariable var = getVariableOrParam(i);
1034        if((var.getXSLToken() == Constants.ELEMNAME_PARAMVARIABLE) &&
1035           (var.getName().equals(qname)))
1036          return (ElemParam)var;
1037      }
1038    }
1039
1040    return null;
1041  }
1042
1043  /**
1044   * The "xsl:template" properties.
1045   * @serial
1046   */

1047  private Vector JavaDoc m_templates;
1048
1049  /**
1050   * Set an "xsl:template" property.
1051   * @see <a HREF="http://www.w3.org/TR/xslt#section-Defining-Template-Rules">section-Defining-Template-Rules in XSLT Specification</a>
1052   *
1053   * @param v ElemTemplate to add to list of templates
1054   */

1055  public void setTemplate(ElemTemplate v)
1056  {
1057
1058    if (null == m_templates)
1059      m_templates = new Vector JavaDoc();
1060
1061    m_templates.addElement(v);
1062    v.setStylesheet(this);
1063  }
1064
1065  /**
1066   * Get an "xsl:template" property.
1067   * @see <a HREF="http://www.w3.org/TR/xslt#section-Defining-Template-Rules">section-Defining-Template-Rules in XSLT Specification</a>
1068   *
1069   * @param i Index of ElemTemplate in the list to get
1070   *
1071   * @return ElemTemplate at the given index in the list
1072   *
1073   * @throws TransformerException
1074   */

1075  public ElemTemplate getTemplate(int i) throws TransformerException JavaDoc
1076  {
1077
1078    if (null == m_templates)
1079      throw new ArrayIndexOutOfBoundsException JavaDoc();
1080
1081    return (ElemTemplate) m_templates.elementAt(i);
1082  }
1083
1084  /**
1085   * Get the number of "xsl:template" properties.
1086   * @see <a HREF="http://www.w3.org/TR/xslt#section-Defining-Template-Rules">section-Defining-Template-Rules in XSLT Specification</a>
1087   *
1088   * @return the number of "xsl:template" properties.
1089   */

1090  public int getTemplateCount()
1091  {
1092    return (null != m_templates) ? m_templates.size() : 0;
1093  }
1094
1095  /**
1096   * The "xsl:namespace-alias" properties.
1097   * @serial
1098   */

1099  private Vector JavaDoc m_prefix_aliases;
1100
1101  /**
1102   * Set the "xsl:namespace-alias" property.
1103   * @see <a HREF="http://www.w3.org/TR/xslt#literal-result-element">literal-result-element in XSLT Specification</a>
1104   *
1105   * @param na NamespaceAlias elemeent to add to the list
1106   */

1107  public void setNamespaceAlias(NamespaceAlias na)
1108  {
1109
1110    if (m_prefix_aliases == null)
1111      m_prefix_aliases = new Vector JavaDoc();
1112
1113    m_prefix_aliases.addElement(na);
1114  }
1115
1116  /**
1117   * Get an "xsl:namespace-alias" property.
1118   * @see <a HREF="http://www.w3.org/TR/xslt#literal-result-element">literal-result-element in XSLT Specification</a>
1119   *
1120   * @param i Index of NamespaceAlias element to get from the list
1121   *
1122   * @return NamespaceAlias element at the given index in the list
1123   *
1124   * @throws ArrayIndexOutOfBoundsException
1125   */

1126  public NamespaceAlias getNamespaceAlias(int i)
1127          throws ArrayIndexOutOfBoundsException JavaDoc
1128  {
1129
1130    if (null == m_prefix_aliases)
1131      throw new ArrayIndexOutOfBoundsException JavaDoc();
1132
1133    return (NamespaceAlias) m_prefix_aliases.elementAt(i);
1134  }
1135
1136  /**
1137   * Get the number of "xsl:namespace-alias" properties.
1138   * @see <a HREF="http://www.w3.org/TR/xslt#top-level-variables">top-level-variables in XSLT Specification</a>
1139   *
1140   * @return the number of "xsl:namespace-alias" properties.
1141   */

1142  public int getNamespaceAliasCount()
1143  {
1144    return (null != m_prefix_aliases) ? m_prefix_aliases.size() : 0;
1145  }
1146
1147  /**
1148   * The "non-xsl-top-level" properties.
1149   * @serial
1150   */

1151  private Hashtable JavaDoc m_NonXslTopLevel;
1152
1153  /**
1154   * Set found a non-xslt element.
1155   * @see <a HREF="http://www.w3.org/TR/xslt#stylesheet-element">stylesheet-element in XSLT Specification</a>
1156   *
1157   * @param name Qualified name of the element
1158   * @param obj The element object
1159   */

1160  public void setNonXslTopLevel(QName name, Object JavaDoc obj)
1161  {
1162
1163    if (null == m_NonXslTopLevel)
1164      m_NonXslTopLevel = new Hashtable JavaDoc();
1165
1166    m_NonXslTopLevel.put(name, obj);
1167  }
1168
1169  /**
1170   * Get a non-xslt element.
1171   * @see <a HREF="http://www.w3.org/TR/xslt#stylesheet-element">stylesheet-element in XSLT Specification</a>
1172   *
1173   * @param name Qualified name of the element to get
1174   *
1175   * @return The object associate with the given name
1176   */

1177  public Object JavaDoc getNonXslTopLevel(QName name)
1178  {
1179    return (null != m_NonXslTopLevel) ? m_NonXslTopLevel.get(name) : null;
1180  }
1181
1182  // =========== End top-level XSLT properties ===========
1183

1184  /**
1185   * The base URL of the XSL document.
1186   * @serial
1187   */

1188  private String JavaDoc m_href = null;
1189
1190  /** The doctype-public element.
1191   * @serial */

1192  private String JavaDoc m_publicId;
1193
1194  /** The doctype-system element.
1195   * @serial */

1196  private String JavaDoc m_systemId;
1197
1198  /**
1199   * Get the base identifier with which this stylesheet is associated.
1200   *
1201   * @return the base identifier with which this stylesheet is associated.
1202   */

1203  public String JavaDoc getHref()
1204  {
1205    return m_href;
1206  }
1207
1208  /**
1209   * Set the base identifier with which this stylesheet is associated.
1210   *
1211   * @param baseIdent the base identifier with which this stylesheet is associated.
1212   */

1213  public void setHref(String JavaDoc baseIdent)
1214  {
1215    m_href = baseIdent;
1216  }
1217
1218  /**
1219   * Set the location information for this element.
1220   *
1221   * @param locator SourceLocator object with location information
1222   */

1223  public void setLocaterInfo(SourceLocator JavaDoc locator)
1224  {
1225
1226    if (null != locator)
1227    {
1228      m_publicId = locator.getPublicId();
1229      m_systemId = locator.getSystemId();
1230
1231      if (null != m_systemId)
1232      {
1233        try
1234        {
1235          m_href = SystemIDResolver.getAbsoluteURI(m_systemId, null);
1236        }
1237        catch (TransformerException JavaDoc se)
1238        {
1239
1240          // Ignore this for right now
1241
}
1242      }
1243
1244      super.setLocaterInfo(locator);
1245    }
1246  }
1247
1248  /**
1249   * The root of the stylesheet, where all the tables common
1250   * to all stylesheets are kept.
1251   * @serial
1252   */

1253  private StylesheetRoot m_stylesheetRoot;
1254
1255  /**
1256   * Get the root of the stylesheet, where all the tables common
1257   * to all stylesheets are kept.
1258   *
1259   * @return the root of the stylesheet
1260   */

1261  public StylesheetRoot getStylesheetRoot()
1262  {
1263    return m_stylesheetRoot;
1264  }
1265
1266  /**
1267   * Set the root of the stylesheet, where all the tables common
1268   * to all stylesheets are kept.
1269   *
1270   * @param v the root of the stylesheet
1271   */

1272  public void setStylesheetRoot(StylesheetRoot v)
1273  {
1274    m_stylesheetRoot = v;
1275  }
1276
1277  /**
1278   * The parent of the stylesheet. This will be null if this
1279   * is the root stylesheet.
1280   * @serial
1281   */

1282  private Stylesheet m_stylesheetParent;
1283
1284  /**
1285   * Get the parent of the stylesheet. This will be null if this
1286   * is the root stylesheet.
1287   *
1288   * @return the parent of the stylesheet.
1289   */

1290  public Stylesheet getStylesheetParent()
1291  {
1292    return m_stylesheetParent;
1293  }
1294
1295  /**
1296   * Set the parent of the stylesheet. This should be null if this
1297   * is the root stylesheet.
1298   *
1299   * @param v the parent of the stylesheet.
1300   */

1301  public void setStylesheetParent(Stylesheet v)
1302  {
1303    m_stylesheetParent = v;
1304  }
1305
1306  /**
1307   * Get the owning aggregated stylesheet, or this
1308   * stylesheet if it is aggregated.
1309   *
1310   * @return the owning aggregated stylesheet or itself
1311   */

1312  public StylesheetComposed getStylesheetComposed()
1313  {
1314
1315    Stylesheet sheet = this;
1316
1317    while (!sheet.isAggregatedType())
1318    {
1319      sheet = sheet.getStylesheetParent();
1320    }
1321
1322    return (StylesheetComposed) sheet;
1323  }
1324
1325  /**
1326   * Get the type of the node. We'll pretend we're a Document.
1327   *
1328   * @return the type of the node: document node.
1329   */

1330  public short getNodeType()
1331  {
1332    return DTM.DOCUMENT_NODE;
1333  }
1334
1335  /**
1336   * Get an integer representation of the element type.
1337   *
1338   * @return An integer representation of the element, defined in the
1339   * Constants class.
1340   * @see org.apache.xalan.templates.Constants
1341   */

1342  public int getXSLToken()
1343  {
1344    return Constants.ELEMNAME_STYLESHEET;
1345  }
1346
1347  /**
1348   * Return the node name.
1349   *
1350   * @return The node name
1351   */

1352  public String JavaDoc getNodeName()
1353  {
1354    return Constants.ELEMNAME_STYLESHEET_STRING;
1355  }
1356
1357  /**
1358   * Replace an "xsl:template" property.
1359   * This is a hook for CompilingStylesheetHandler, to allow
1360   * us to access a template, compile it, instantiate it,
1361   * and replace the original with the compiled instance.
1362   * ADDED 9/5/2000 to support compilation experiment
1363   *
1364   * @param v Compiled template to replace with
1365   * @param i Index of template to be replaced
1366   *
1367   * @throws TransformerException
1368   */

1369  public void replaceTemplate(ElemTemplate v, int i) throws TransformerException JavaDoc
1370  {
1371
1372    if (null == m_templates)
1373      throw new ArrayIndexOutOfBoundsException JavaDoc();
1374
1375    replaceChild(v, (ElemTemplateElement)m_templates.elementAt(i));
1376    m_templates.setElementAt(v, i);
1377    v.setStylesheet(this);
1378  }
1379  
1380    /**
1381     * Call the children visitors.
1382     * @param visitor The visitor whose appropriate method will be called.
1383     */

1384    protected void callChildVisitors(XSLTVisitor visitor, boolean callAttrs)
1385    {
1386      int s = getImportCount();
1387      for (int j = 0; j < s; j++)
1388      {
1389        getImport(j).callVisitors(visitor);
1390      }
1391   
1392      s = getIncludeCount();
1393      for (int j = 0; j < s; j++)
1394      {
1395        getInclude(j).callVisitors(visitor);
1396      }
1397
1398      s = getOutputCount();
1399      for (int j = 0; j < s; j++)
1400      {
1401        visitor.visitTopLevelInstruction(getOutput(j));
1402      }
1403
1404      // Next, add in the attribute-set elements
1405

1406      s = getAttributeSetCount();
1407      for (int j = 0; j < s; j++)
1408      {
1409        ElemAttributeSet attrSet = getAttributeSet(j);
1410        if (visitor.visitTopLevelInstruction(attrSet))
1411        {
1412          attrSet.callChildVisitors(visitor);
1413        }
1414      }
1415      // Now the decimal-formats
1416

1417      s = getDecimalFormatCount();
1418      for (int j = 0; j < s; j++)
1419      {
1420        visitor.visitTopLevelInstruction(getDecimalFormat(j));
1421      }
1422
1423      // Now the keys
1424

1425      s = getKeyCount();
1426      for (int j = 0; j < s; j++)
1427      {
1428        visitor.visitTopLevelInstruction(getKey(j));
1429      }
1430
1431      // And the namespace aliases
1432

1433      s = getNamespaceAliasCount();
1434      for (int j = 0; j < s; j++)
1435      {
1436        visitor.visitTopLevelInstruction(getNamespaceAlias(j));
1437      }
1438
1439      // Next comes the templates
1440

1441      s = getTemplateCount();
1442      for (int j = 0; j < s; j++)
1443      {
1444        try
1445        {
1446          ElemTemplate template = getTemplate(j);
1447          if (visitor.visitTopLevelInstruction(template))
1448          {
1449            template.callChildVisitors(visitor);
1450          }
1451        }
1452        catch (TransformerException JavaDoc te)
1453        {
1454          throw new org.apache.xml.utils.WrappedRuntimeException(te);
1455        }
1456      }
1457
1458      // Then, the variables
1459

1460      s = getVariableOrParamCount();
1461      for (int j = 0; j < s; j++)
1462      {
1463        ElemVariable var = getVariableOrParam(j);
1464        if (visitor.visitTopLevelVariableOrParamDecl(var))
1465        {
1466          var.callChildVisitors(visitor);
1467        }
1468      }
1469
1470      // And lastly the whitespace preserving and stripping elements
1471

1472      s = getStripSpaceCount();
1473      for (int j = 0; j < s; j++)
1474      {
1475        visitor.visitTopLevelInstruction(getStripSpace(j));
1476      }
1477
1478      s = getPreserveSpaceCount();
1479      for (int j = 0; j < s; j++)
1480      {
1481        visitor.visitTopLevelInstruction(getPreserveSpace(j));
1482      }
1483      
1484      if(null != m_NonXslTopLevel)
1485      {
1486        java.util.Enumeration JavaDoc elements = m_NonXslTopLevel.elements();
1487        while(elements.hasMoreElements())
1488        {
1489          ElemTemplateElement elem = (ElemTemplateElement)elements.nextElement();
1490          if (visitor.visitTopLevelInstruction(elem))
1491          {
1492            elem.callChildVisitors(visitor);
1493          }
1494            
1495        }
1496      }
1497    }
1498        
1499          
1500  /**
1501   * Accept a visitor and call the appropriate method
1502   * for this class.
1503   *
1504   * @param visitor The visitor whose appropriate method will be called.
1505   * @return true if the children of the object should be visited.
1506   */

1507  protected boolean accept(XSLTVisitor visitor)
1508  {
1509    return visitor.visitStylesheet(this);
1510  }
1511
1512  
1513}
1514
Popular Tags