KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > processor > XSLTAttributeDef


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: XSLTAttributeDef.java,v 1.32 2004/02/11 18:15:50 minchau Exp $
18  */

19 package org.apache.xalan.processor;
20
21 import java.lang.reflect.InvocationTargetException JavaDoc;
22 import java.lang.reflect.Method JavaDoc;
23 import java.util.StringTokenizer JavaDoc;
24 import java.util.Vector JavaDoc;
25
26 import javax.xml.transform.TransformerException JavaDoc;
27
28 import org.apache.xalan.res.XSLMessages;
29 import org.apache.xalan.res.XSLTErrorResources;
30 import org.apache.xalan.templates.AVT;
31 import org.apache.xalan.templates.Constants;
32 import org.apache.xalan.templates.ElemTemplateElement;
33 import org.apache.xml.utils.QName;
34 import org.apache.xml.utils.StringToIntTable;
35 import org.apache.xml.utils.StringVector;
36 import org.apache.xml.utils.XMLChar;
37 import org.apache.xpath.XPath;
38
39  
40 /**
41  * This class defines an attribute for an element in a XSLT stylesheet,
42  * is meant to reflect the structure defined in http://www.w3.org/TR/xslt#dtd, and the
43  * mapping between Xalan classes and the markup attributes in the element.
44  */

45 public class XSLTAttributeDef
46 {
47    // How to handle invalid values for this attribute
48
static final int FATAL = 0;
49    static final int ERROR = 1;
50    static final int WARNING = 2;
51    
52    
53   /**
54    * Construct an instance of XSLTAttributeDef.
55    *
56    * @param namespace The Namespace URI, or an empty string.
57    * @param name The local name (without prefix), or empty string if not namespace processing.
58    * @param type One of T_CDATA, T_URL, T_AVT, T_PATTERN, T_EXPR, T_CHAR,
59    * T_NUMBER, T_YESNO, T_QNAME, T_QNAMES, T_ENUM, T_SIMPLEPATTERNLIST,
60    * T_NMTOKEN, T_STRINGLIST, T_PREFIX_URLLIST, T_ENUM_OR_PQNAME, T_NCNAME.
61    * @param required true if this is attribute is required by the XSLT specification.
62    * @param supportsAVT true if this attribute supports AVT's.
63    * @param errorType the type of error to issue if validation fails. One of FATAL, ERROR, WARNING.
64    */

65   XSLTAttributeDef(String JavaDoc namespace, String JavaDoc name, int type, boolean required, boolean supportsAVT, int errorType)
66   {
67     this.m_namespace = namespace;
68     this.m_name = name;
69     this.m_type = type;
70     this.m_required = required;
71     this.m_supportsAVT = supportsAVT;
72     this.m_errorType = errorType;
73   }
74
75   /**
76    * Construct an instance of XSLTAttributeDef.
77    *
78    * @param namespace The Namespace URI, or an empty string.
79    * @param name The local name (without prefix), or empty string if not namespace processing.
80    * @param type One of T_CDATA, T_URL, T_AVT, T_PATTERN, T_EXPR,
81    * T_CHAR, T_NUMBER, T_YESNO, T_QNAME, T_QNAMES, T_ENUM,
82    * T_SIMPLEPATTERNLIST, T_NMTOKEN, T_STRINGLIST, T_PREFIX_URLLIST,
83    * T_ENUM_OR_PQNAME, T_NCNAME.
84    * @param supportsAVT true if this attribute supports AVT's.
85    * @param errorType the type of error to issue if validation fails. One of FATAL, ERROR, WARNING.
86    * @param defaultVal The default value for this attribute.
87    */

88   XSLTAttributeDef(String JavaDoc namespace, String JavaDoc name, int type, boolean supportsAVT, int errorType, String JavaDoc defaultVal)
89   {
90
91     this.m_namespace = namespace;
92     this.m_name = name;
93     this.m_type = type;
94     this.m_required = false;
95     this.m_supportsAVT = supportsAVT;
96     this.m_errorType = errorType;
97     this.m_default = defaultVal;
98    }
99
100   /**
101    * Construct an instance of XSLTAttributeDef that uses two
102    * enumerated values.
103    *
104    * @param namespace The Namespace URI, or an empty string.
105    * @param name The local name (without prefix), or empty string if not namespace processing.
106    * @param required true if this attribute is required by the XSLT specification.
107    * @param supportsAVT true if this attribute supports AVT's.
108    * @param prefixedQNameValAllowed If true, the type is T_ENUM_OR_PQNAME
109    * @param errorType the type of error to issue if validation fails. One of FATAL, ERROR, WARNING.
110    * @param k1 The XSLT name of the enumerated value.
111    * @param v1 An integer representation of k1.
112    * @param k2 The XSLT name of the enumerated value.
113    * @param v2 An integer representation of k2.
114     */

115   XSLTAttributeDef(String JavaDoc namespace, String JavaDoc name, boolean required, boolean supportsAVT,
116                     boolean prefixedQNameValAllowed, int errorType, String JavaDoc k1, int v1, String JavaDoc k2, int v2)
117   {
118
119     this.m_namespace = namespace;
120     this.m_name = name;
121     this.m_type = prefixedQNameValAllowed ? this.T_ENUM_OR_PQNAME : this.T_ENUM;
122     this.m_required = required;
123     this.m_supportsAVT = supportsAVT;
124     this.m_errorType = errorType;
125     m_enums = new StringToIntTable(2);
126
127     m_enums.put(k1, v1);
128     m_enums.put(k2, v2);
129   }
130
131   /**
132    * Construct an instance of XSLTAttributeDef that uses three
133    * enumerated values.
134    *
135    * @param namespace The Namespace URI, or an empty string.
136    * @param name The local name (without prefix), or empty string if not namespace processing.
137    * @param required true if this attribute is required by the XSLT specification.
138    * @param supportsAVT true if this attribute supports AVT's.
139    * @param prefixedQNameValAllowed If true, the type is T_ENUM_OR_PQNAME
140    * @param errorType the type of error to issue if validation fails. One of FATAL, ERROR, WARNING. *
141    * @param k1 The XSLT name of the enumerated value.
142    * @param v1 An integer representation of k1.
143    * @param k2 The XSLT name of the enumerated value.
144    * @param v2 An integer representation of k2.
145    * @param k3 The XSLT name of the enumerated value.
146    * @param v3 An integer representation of k3.
147    */

148   XSLTAttributeDef(String JavaDoc namespace, String JavaDoc name, boolean required, boolean supportsAVT,
149                     boolean prefixedQNameValAllowed, int errorType, String JavaDoc k1, int v1, String JavaDoc k2, int v2, String JavaDoc k3, int v3)
150   {
151
152     this.m_namespace = namespace;
153     this.m_name = name;
154     this.m_type = prefixedQNameValAllowed ? this.T_ENUM_OR_PQNAME : this.T_ENUM;
155     this.m_required = required;
156     this.m_supportsAVT = supportsAVT;
157     this.m_errorType = errorType;
158     m_enums = new StringToIntTable(3);
159
160     m_enums.put(k1, v1);
161     m_enums.put(k2, v2);
162     m_enums.put(k3, v3);
163   }
164
165   /**
166    * Construct an instance of XSLTAttributeDef that uses three
167    * enumerated values.
168    *
169    * @param namespace The Namespace URI, or an empty string.
170    * @param name The local name (without prefix), or empty string if not namespace processing.
171    * @param required true if this attribute is required by the XSLT specification.
172    * @param supportsAVT true if this attribute supports AVT's.
173    * @param prefixedQNameValAllowed If true, the type is T_ENUM_OR_PQNAME
174    * @param errorType the type of error to issue if validation fails. One of FATAL, ERROR, WARNING. * @param k1 The XSLT name of the enumerated value.
175    * @param v1 An integer representation of k1.
176    * @param k2 The XSLT name of the enumerated value.
177    * @param v2 An integer representation of k2.
178    * @param k3 The XSLT name of the enumerated value.
179    * @param v3 An integer representation of k3.
180    * @param k4 The XSLT name of the enumerated value.
181    * @param v4 An integer representation of k4.
182    */

183   XSLTAttributeDef(String JavaDoc namespace, String JavaDoc name, boolean required, boolean supportsAVT,
184                    boolean prefixedQNameValAllowed, int errorType, String JavaDoc k1, int v1, String JavaDoc k2, int v2,
185                    String JavaDoc k3, int v3, String JavaDoc k4, int v4)
186   {
187
188     this.m_namespace = namespace;
189     this.m_name = name;
190     this.m_type = prefixedQNameValAllowed ? this.T_ENUM_OR_PQNAME : this.T_ENUM;
191     this.m_required = required;
192     this.m_supportsAVT = supportsAVT;
193     this.m_errorType = errorType;
194     m_enums = new StringToIntTable(4);
195
196     m_enums.put(k1, v1);
197     m_enums.put(k2, v2);
198     m_enums.put(k3, v3);
199     m_enums.put(k4, v4);
200   }
201
202   /** Type values that represent XSLT attribute types. */
203   static final int T_CDATA = 1,
204
205   // <!-- Used for the type of an attribute value that is a URI reference.-->
206
T_URL = 2,
207
208   // <!-- Used for the type of an attribute value that is an
209
// attribute value template.-->
210
T_AVT = 3, // Attribute Value Template
211

212   // <!-- Used for the type of an attribute value that is a pattern.-->
213
T_PATTERN = 4,
214
215   // <!-- Used for the type of an attribute value that is an expression.-->
216
T_EXPR = 5,
217
218   // <!-- Used for the type of an attribute value that consists
219
// of a single character.-->
220
T_CHAR = 6,
221
222   // <!-- Used for the type of an attribute value that is a number. -->
223
T_NUMBER = 7,
224
225   // Used for boolean values
226
T_YESNO = 8,
227
228   // <!-- Used for the type of an attribute value that is a QName; the prefix
229
// gets expanded by the XSLT processor. -->
230
T_QNAME = 9,
231
232   // <!--Used for a whitespace-separated list of QNames where the non-prefixed
233
// entries are not to be placed in the default namespace. -->
234
T_QNAMES = 10,
235
236   // <!-- Used for enumerated values -->
237
T_ENUM = 11,
238
239   // Used for simple match patterns, i.e. xsl:strip-space spec.
240
T_SIMPLEPATTERNLIST = 12,
241
242   // Used for a known token.
243
T_NMTOKEN = 13,
244
245   // Used for a list of white-space delimited strings.
246
T_STRINGLIST = 14,
247
248   // Used for a list of white-space delimited strings.
249
// Prefixes are checked to make sure they refer to
250
// valid namespaces, and are resolved when processed
251
T_PREFIX_URLLIST = 15,
252   
253   // Used for enumerated values, one of which could be a qname-but-not-ncname
254
T_ENUM_OR_PQNAME = 16,
255
256   // Used for the type of an attribute value that is a NCName
257
T_NCNAME = 17,
258   
259   // Used for QName attributes that are always AVT. Prefix isn't resolved.
260
T_AVT_QNAME = 18,
261   
262   // Used for a list of QNames where non-prefixed items are to be resolved
263
// using the default namespace (This is only true for cdata-section-elements)
264
T_QNAMES_RESOLVE_NULL = 19,
265   
266   // Used for a list of white-space delimited strings.
267
// strings are checked to make sure they are valid
268
// prefixes, and are not expanded when processed.
269
T_PREFIXLIST = 20;
270
271   /** Representation for an attribute in a foreign namespace. */
272   static XSLTAttributeDef m_foreignAttr = new XSLTAttributeDef("*", "*",
273                                             XSLTAttributeDef.T_CDATA,false, false, WARNING);
274
275   /** Method name that objects may implement if they wish to have forein attributes set. */
276   static String JavaDoc S_FOREIGNATTR_SETTER = "setForeignAttr";
277
278   /**
279    * The allowed namespace for this element.
280    */

281   private String JavaDoc m_namespace;
282
283   /**
284    * Get the allowed namespace for this attribute.
285    *
286    * @return The allowed namespace for this attribute, which may be null, or may be "*".
287    */

288   String JavaDoc getNamespace()
289   {
290     return m_namespace;
291   }
292
293   /**
294    * The name of this element.
295    */

296   private String JavaDoc m_name;
297
298   /**
299    * Get the name of this attribute.
300    *
301    * @return non-null reference to the name of this attribute, which may be "*".
302    */

303   String JavaDoc getName()
304   {
305     return m_name;
306   }
307
308   /**
309    * The type of this attribute value.
310    */

311   private int m_type;
312
313   /**
314    * Get the type of this attribute value.
315    *
316    * @return One of T_CDATA, T_URL, T_AVT, T_PATTERN, T_EXPR, T_CHAR,
317    * T_NUMBER, T_YESNO, T_QNAME, T_QNAMES, T_ENUM, T_SIMPLEPATTERNLIST,
318    * T_NMTOKEN, T_STRINGLIST, T_PREFIX_URLLIST, T_ENUM_OR_PQNAME.
319    */

320   int getType()
321   {
322     return m_type;
323   }
324
325   /**
326    * If this element is of type T_ENUM, this will contain
327    * a map from the attribute string to the Xalan integer
328    * value.
329    */

330   private StringToIntTable m_enums;
331
332   /**
333    * If this element is of type T_ENUM, this will return
334    * a map from the attribute string to the Xalan integer
335    * value.
336    * @param key The XSLT attribute value.
337    *
338    * @return The integer representation of the enumerated value for this attribute.
339    * @throws Throws NullPointerException if m_enums is null.
340    */

341   private int getEnum(String JavaDoc key)
342   {
343     return m_enums.get(key);
344   }
345
346  /**
347    * If this element is of type T_ENUM, this will return
348    * an array of strings - the values in the enumeration
349    *
350    * @return An array of the enumerated values permitted for this attribute.
351    *
352    * @throws Throws NullPointerException if m_enums is null.
353    */

354   private String JavaDoc[] getEnumNames()
355   {
356     return m_enums.keys();
357   }
358
359   /**
360    * The default value for this attribute.
361    */

362   private String JavaDoc m_default;
363
364   /**
365    * Get the default value for this attribute.
366    *
367    * @return The default value for this attribute, or null.
368    */

369   String JavaDoc getDefault()
370   {
371     return m_default;
372   }
373
374   /**
375    * Set the default value for this attribute.
376    *
377    * @param def String representation of the default value for this attribute.
378    */

379   void setDefault(String JavaDoc def)
380   {
381     m_default = def;
382   }
383
384   /**
385    * If true, this is a required attribute.
386    */

387   private boolean m_required;
388
389   /**
390    * Get whether or not this is a required attribute.
391    *
392    * @return true if this is a required attribute.
393    */

394   boolean getRequired()
395   {
396     return m_required;
397   }
398
399   /**
400    * If true, this is attribute supports AVT's.
401    */

402   private boolean m_supportsAVT;
403
404   /**
405    * Get whether or not this attribute supports AVT's.
406    *
407    * @return true if this attribute supports AVT's.
408    */

409   boolean getSupportsAVT()
410   {
411     return m_supportsAVT;
412   }
413   
414   int m_errorType = this.WARNING;
415   
416   /**
417    * Get the type of error message to use if the attribute value is invalid.
418    *
419    * @return one of XSLAttributeDef.FATAL, XSLAttributeDef.ERROR, XSLAttributeDef.WARNING
420    */

421   int getErrorType()
422   {
423     return m_errorType;
424   }
425   /**
426    * String that should represent the setter method which which
427    * may be used on objects to set a value that represents this attribute
428    */

429   String JavaDoc m_setterString = null;
430
431   /**
432    * Return a string that should represent the setter method.
433    * The setter method name will be created algorithmically the
434    * first time this method is accessed, and then cached for return
435    * by subsequent invocations of this method.
436    *
437    * @return String that should represent the setter method which which
438    * may be used on objects to set a value that represents this attribute,
439    * of null if no setter method should be called.
440    */

441   public String JavaDoc getSetterMethodName()
442   {
443
444     if (null == m_setterString)
445     {
446       if (m_foreignAttr == this)
447       {
448         return S_FOREIGNATTR_SETTER;
449       }
450       else if (m_name.equals("*"))
451       {
452         m_setterString = "addLiteralResultAttribute";
453
454         return m_setterString;
455       }
456
457       StringBuffer JavaDoc outBuf = new StringBuffer JavaDoc();
458
459       outBuf.append("set");
460
461       if ((m_namespace != null)
462               && m_namespace.equals(Constants.S_XMLNAMESPACEURI))
463       {
464         outBuf.append("Xml");
465       }
466
467       int n = m_name.length();
468
469       for (int i = 0; i < n; i++)
470       {
471         char c = m_name.charAt(i);
472
473         if ('-' == c)
474         {
475           i++;
476
477           c = m_name.charAt(i);
478           c = Character.toUpperCase(c);
479         }
480         else if (0 == i)
481         {
482           c = Character.toUpperCase(c);
483         }
484
485         outBuf.append(c);
486       }
487
488       m_setterString = outBuf.toString();
489     }
490
491     return m_setterString;
492   }
493
494   /**
495    * Process an attribute string of type T_AVT into
496    * a AVT value.
497    *
498    * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
499    * @param uri The Namespace URI, or an empty string.
500    * @param name The local name (without prefix), or empty string if not namespace processing.
501    * @param rawName The qualified name (with prefix).
502    * @param value Should be an Attribute Value Template string.
503    *
504    * @return An AVT object that may be used to evaluate the Attribute Value Template.
505    *
506    * @throws org.xml.sax.SAXException which will wrap a
507    * {@link javax.xml.transform.TransformerException}, if there is a syntax error
508    * in the attribute value template string.
509    */

510   AVT processAVT(
511           StylesheetHandler handler, String JavaDoc uri, String JavaDoc name, String JavaDoc rawName, String JavaDoc value,
512           ElemTemplateElement owner)
513             throws org.xml.sax.SAXException JavaDoc
514   {
515
516     try
517     {
518       AVT avt = new AVT(handler, uri, name, rawName, value, owner);
519
520       return avt;
521     }
522     catch (TransformerException JavaDoc te)
523     {
524       throw new org.xml.sax.SAXException JavaDoc(te);
525     }
526   }
527
528   /**
529    * Process an attribute string of type T_CDATA into
530    * a String value.
531    *
532    * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
533    * @param uri The Namespace URI, or an empty string.
534    * @param name The local name (without prefix), or empty string if not namespace processing.
535    * @param rawName The qualified name (with prefix).
536    * @param value non-null string reference.
537    *
538    * @return The value argument.
539    *
540    * @throws org.xml.sax.SAXException.
541    */

542   Object JavaDoc processCDATA(StylesheetHandler handler, String JavaDoc uri, String JavaDoc name,
543                       String JavaDoc rawName, String JavaDoc value, ElemTemplateElement owner)
544                       throws org.xml.sax.SAXException JavaDoc
545   {
546     if (getSupportsAVT()) {
547         try
548         {
549           AVT avt = new AVT(handler, uri, name, rawName, value, owner);
550           return avt;
551         }
552         catch (TransformerException JavaDoc te)
553         {
554           throw new org.xml.sax.SAXException JavaDoc(te);
555         }
556     } else {
557         return value;
558     }
559   }
560
561   /**
562    * Process an attribute string of type T_CHAR into
563    * a Character value.
564    *
565    * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
566    * @param uri The Namespace URI, or an empty string.
567    * @param name The local name (without prefix), or empty string if not namespace processing.
568    * @param rawName The qualified name (with prefix).
569    * @param value Should be a string with a length of 1.
570    *
571    * @return Character object.
572    *
573    * @throws org.xml.sax.SAXException if the string is not a length of 1.
574    */

575   Object JavaDoc processCHAR(
576           StylesheetHandler handler, String JavaDoc uri, String JavaDoc name, String JavaDoc rawName, String JavaDoc value, ElemTemplateElement owner)
577             throws org.xml.sax.SAXException JavaDoc
578   {
579     if (getSupportsAVT()) {
580         try
581         {
582           AVT avt = new AVT(handler, uri, name, rawName, value, owner);
583     
584           // If an AVT wasn't used, validate the value
585
if ((avt.isSimple()) && (value.length() != 1)) {
586             handleError(handler, XSLTErrorResources.INVALID_TCHAR, new Object JavaDoc[] {name, value},null);
587             return null;
588           }
589           return avt;
590         }
591         catch (TransformerException JavaDoc te)
592         {
593           throw new org.xml.sax.SAXException JavaDoc(te);
594         }
595     } else {
596         if (value.length() != 1)
597         {
598             handleError(handler, XSLTErrorResources.INVALID_TCHAR, new Object JavaDoc[] {name, value},null);
599             return null;
600         }
601
602         return new Character JavaDoc(value.charAt(0));
603     }
604   }
605
606   /**
607    * Process an attribute string of type T_ENUM into a int value.
608    *
609    * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
610    * @param uri The Namespace URI, or an empty string.
611    * @param name The local name (without prefix), or empty string if not namespace processing.
612    * @param rawName The qualified name (with prefix).
613    * @param value non-null string that represents an enumerated value that is
614    * valid for this element.
615    * @param owner
616    *
617    * @return An Integer representation of the enumerated value if this attribute does not support
618    * AVT. Otherwise, and AVT is returned.
619    */

620   Object JavaDoc processENUM(StylesheetHandler handler, String JavaDoc uri, String JavaDoc name,
621                      String JavaDoc rawName, String JavaDoc value, ElemTemplateElement owner)
622                      throws org.xml.sax.SAXException JavaDoc
623   {
624
625     AVT avt = null;
626     if (getSupportsAVT()) {
627         try
628         {
629           avt = new AVT(handler, uri, name, rawName, value, owner);
630           
631           // If this attribute used an avt, then we can't validate at this time.
632
if (!avt.isSimple()) return avt;
633         }
634         catch (TransformerException JavaDoc te)
635         {
636           throw new org.xml.sax.SAXException JavaDoc(te);
637         }
638     }
639     
640     int retVal = this.getEnum(value);
641     
642     if (retVal == StringToIntTable.INVALID_KEY)
643     {
644        StringBuffer JavaDoc enumNamesList = getListOfEnums();
645        handleError(handler, XSLTErrorResources.INVALID_ENUM,new Object JavaDoc[]{name, value, enumNamesList.toString() },null);
646        return null;
647     }
648
649     if (getSupportsAVT()) return avt;
650     else return new Integer JavaDoc(retVal);
651
652   }
653
654   /**
655    * Process an attribute string of that is either an enumerated value or a qname-but-not-ncname.
656    * Returns an AVT, if this attribute support AVT; otherwise returns int or qname.
657    *
658    * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
659    * @param uri The Namespace URI, or an empty string.
660    * @param name The local name (without prefix), or empty string if not namespace processing.
661    * @param rawName The qualified name (with prefix).
662    * @param value non-null string that represents an enumerated value that is
663    * valid for this element.
664    * @param owner
665    *
666    * @return AVT if attribute supports AVT. An Integer representation of the enumerated value if
667    * attribute does not support AVT and an enumerated value was used. Otherwise a qname
668    * is returned.
669    */

670   Object JavaDoc processENUM_OR_PQNAME(StylesheetHandler handler, String JavaDoc uri, String JavaDoc name,
671                      String JavaDoc rawName, String JavaDoc value, ElemTemplateElement owner)
672                      throws org.xml.sax.SAXException JavaDoc
673   {
674
675     Object JavaDoc objToReturn = null;
676     
677     if (getSupportsAVT()) {
678         try
679         {
680           AVT avt = new AVT(handler, uri, name, rawName, value, owner);
681           if (!avt.isSimple()) return avt;
682           else objToReturn = avt;
683         }
684         catch (TransformerException JavaDoc te)
685         {
686           throw new org.xml.sax.SAXException JavaDoc(te);
687         }
688     }
689     
690     // An avt wasn't used.
691
int key = this.getEnum(value);
692     
693     if (key != StringToIntTable.INVALID_KEY)
694     {
695         if (objToReturn == null) objToReturn = new Integer JavaDoc(key);
696     }
697
698     // enum not used. Validate qname-but-not-ncname.
699
else
700     {
701         try
702         {
703             QName qname = new QName(value, handler, true);
704             if (objToReturn == null) objToReturn = qname;
705             
706             if (qname.getPrefix() == null) {
707                StringBuffer JavaDoc enumNamesList = getListOfEnums();
708
709                enumNamesList.append(" <qname-but-not-ncname>");
710                handleError(handler,XSLTErrorResources.INVALID_ENUM,new Object JavaDoc[]{name, value, enumNamesList.toString() },null);
711                return null;
712         
713             }
714         }
715         catch (IllegalArgumentException JavaDoc ie)
716         {
717            StringBuffer JavaDoc enumNamesList = getListOfEnums();
718            enumNamesList.append(" <qname-but-not-ncname>");
719            
720            handleError(handler,XSLTErrorResources.INVALID_ENUM,new Object JavaDoc[]{name, value, enumNamesList.toString() },ie);
721            return null;
722
723         }
724         catch (RuntimeException JavaDoc re)
725         {
726            StringBuffer JavaDoc enumNamesList = getListOfEnums();
727            enumNamesList.append(" <qname-but-not-ncname>");
728
729            handleError(handler,XSLTErrorResources.INVALID_ENUM,new Object JavaDoc[]{name, value, enumNamesList.toString() },re);
730            return null;
731         }
732     }
733     
734     return objToReturn;
735   }
736
737   /**
738    * Process an attribute string of type T_EXPR into
739    * an XPath value.
740    *
741    * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
742    * @param uri The Namespace URI, or an empty string.
743    * @param name The local name (without prefix), or empty string if not namespace processing.
744    * @param rawName The qualified name (with prefix).
745    * @param value An XSLT expression string.
746    *
747    * @return an XPath object that may be used for evaluation.
748    *
749    * @throws org.xml.sax.SAXException that wraps a
750    * {@link javax.xml.transform.TransformerException} if the expression
751    * string contains a syntax error.
752    */

753   Object JavaDoc processEXPR(
754           StylesheetHandler handler, String JavaDoc uri, String JavaDoc name, String JavaDoc rawName, String JavaDoc value,
755           ElemTemplateElement owner)
756             throws org.xml.sax.SAXException JavaDoc
757   {
758
759     try
760     {
761       XPath expr = handler.createXPath(value, owner);
762
763       return expr;
764     }
765     catch (TransformerException JavaDoc te)
766     {
767       org.xml.sax.SAXException JavaDoc se = new org.xml.sax.SAXException JavaDoc(te);
768       throw new org.xml.sax.SAXException JavaDoc(te);
769     }
770   }
771
772   /**
773    * Process an attribute string of type T_NMTOKEN into
774    * a String value.
775    *
776    * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
777    * @param uri The Namespace URI, or an empty string.
778    * @param name The local name (without prefix), or empty string if not namespace processing.
779    * @param rawName The qualified name (with prefix).
780    * @param value A NMTOKEN string.
781    *
782    * @return the value argument or an AVT if this attribute supports AVTs.
783    *
784    * @throws org.xml.sax.SAXException if the value is not a valid nmtoken
785    */

786   Object JavaDoc processNMTOKEN(StylesheetHandler handler, String JavaDoc uri, String JavaDoc name,
787                         String JavaDoc rawName, String JavaDoc value, ElemTemplateElement owner)
788              throws org.xml.sax.SAXException JavaDoc
789   {
790     
791     if (getSupportsAVT()) {
792         try
793         {
794           AVT avt = new AVT(handler, uri, name, rawName, value, owner);
795     
796           // If an AVT wasn't used, validate the value
797
if ((avt.isSimple()) && (!XMLChar.isValidNmtoken(value))) {
798             handleError(handler,XSLTErrorResources.INVALID_NMTOKEN, new Object JavaDoc[] {name,value},null);
799             return null;
800           }
801           return avt;
802         }
803         catch (TransformerException JavaDoc te)
804         {
805           throw new org.xml.sax.SAXException JavaDoc(te);
806         }
807     } else {
808         if (!XMLChar.isValidNmtoken(value)) {
809             handleError(handler,XSLTErrorResources.INVALID_NMTOKEN, new Object JavaDoc[] {name,value},null);
810             return null;
811         }
812     }
813     return value;
814   }
815
816   /**
817    * Process an attribute string of type T_PATTERN into
818    * an XPath match pattern value.
819    *
820    * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
821    * @param uri The Namespace URI, or an empty string.
822    * @param name The local name (without prefix), or empty string if not namespace processing.
823    * @param rawName The qualified name (with prefix).
824    * @param value A match pattern string.
825    *
826    * @return An XPath pattern that may be used to evaluate the XPath.
827    *
828    * @throws org.xml.sax.SAXException that wraps a
829    * {@link javax.xml.transform.TransformerException} if the match pattern
830    * string contains a syntax error.
831    */

832   Object JavaDoc processPATTERN(
833           StylesheetHandler handler, String JavaDoc uri, String JavaDoc name, String JavaDoc rawName, String JavaDoc value,
834           ElemTemplateElement owner)
835             throws org.xml.sax.SAXException JavaDoc
836   {
837
838     try
839     {
840       XPath pattern = handler.createMatchPatternXPath(value, owner);
841
842       return pattern;
843     }
844     catch (TransformerException JavaDoc te)
845     {
846       throw new org.xml.sax.SAXException JavaDoc(te);
847     }
848   }
849
850   /**
851    * Process an attribute string of type T_NUMBER into
852    * a double value.
853    *
854    * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
855    * @param uri The Namespace URI, or an empty string.
856    * @param name The local name (without prefix), or empty string if not namespace processing.
857    * @param rawName The qualified name (with prefix).
858    * @param value A string that can be parsed into a double value.
859    * @param number
860    *
861    * @return A Double object.
862    *
863    * @throws org.xml.sax.SAXException that wraps a
864    * {@link javax.xml.transform.TransformerException}
865    * if the string does not contain a parsable number.
866    */

867   Object JavaDoc processNUMBER(
868           StylesheetHandler handler, String JavaDoc uri, String JavaDoc name, String JavaDoc rawName, String JavaDoc value, ElemTemplateElement owner)
869             throws org.xml.sax.SAXException JavaDoc
870   {
871
872
873     if (getSupportsAVT())
874     {
875         Double JavaDoc val;
876         AVT avt = null;
877         try
878         {
879           avt = new AVT(handler, uri, name, rawName, value, owner);
880           
881           // If this attribute used an avt, then we can't validate at this time.
882
if (avt.isSimple())
883           {
884             val = Double.valueOf(value);
885           }
886         }
887         catch (TransformerException JavaDoc te)
888         {
889           throw new org.xml.sax.SAXException JavaDoc(te);
890         }
891         catch (NumberFormatException JavaDoc nfe)
892         {
893             handleError(handler,XSLTErrorResources.INVALID_NUMBER, new Object JavaDoc[] {name, value}, nfe);
894             return null;
895         }
896         return avt;
897     
898     }
899     else
900     {
901         try
902         {
903           return Double.valueOf(value);
904         }
905         catch (NumberFormatException JavaDoc nfe)
906         {
907             handleError(handler,XSLTErrorResources.INVALID_NUMBER, new Object JavaDoc[] {name, value}, nfe);
908             return null;
909         }
910     }
911   }
912
913   /**
914    * Process an attribute string of type T_QNAME into a QName value.
915    *
916    * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
917    * @param uri The Namespace URI, or an empty string.
918    * @param name The local name (without prefix), or empty string if not namespace processing.
919    * @param rawName The qualified name (with prefix).
920    * @param value A string that represents a potentially prefix qualified name.
921    * @param owner
922    *
923    * @return A QName object if this attribute does not support AVT's. Otherwise, an AVT
924    * is returned.
925    *
926    * @throws org.xml.sax.SAXException if the string contains a prefix that can not be
927    * resolved, or the string contains syntax that is invalid for a qualified name.
928    */

929   Object JavaDoc processQNAME(
930           StylesheetHandler handler, String JavaDoc uri, String JavaDoc name, String JavaDoc rawName, String JavaDoc value, ElemTemplateElement owner)
931             throws org.xml.sax.SAXException JavaDoc
932   {
933
934      try
935         {
936           QName qname = new QName(value, handler, true);
937           return qname;
938         }
939         catch (IllegalArgumentException JavaDoc ie)
940         {
941             // thrown by QName constructor
942
handleError(handler,XSLTErrorResources.INVALID_QNAME, new Object JavaDoc[] {name, value},ie);
943             return null;
944         }
945         catch (RuntimeException JavaDoc re) {
946             // thrown by QName constructor
947
handleError(handler,XSLTErrorResources.INVALID_QNAME, new Object JavaDoc[] {name, value},re);
948             return null;
949         }
950     }
951  
952
953   /**
954    * Process an attribute string of type T_QNAME into a QName value.
955    *
956    * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
957    * @param uri The Namespace URI, or an empty string.
958    * @param name The local name (without prefix), or empty string if not namespace processing.
959    * @param rawName The qualified name (with prefix).
960    * @param value A string that represents a potentially prefix qualified name.
961    * @param owner
962    *
963    * @return An AVT is returned.
964    *
965    * @throws org.xml.sax.SAXException if the string contains a prefix that can not be
966    * resolved, or the string contains syntax that is invalid for a qualified name.
967    */

968   Object JavaDoc processAVT_QNAME(
969           StylesheetHandler handler, String JavaDoc uri, String JavaDoc name, String JavaDoc rawName, String JavaDoc value, ElemTemplateElement owner)
970             throws org.xml.sax.SAXException JavaDoc
971   {
972
973        AVT avt = null;
974        try
975        {
976           avt = new AVT(handler, uri, name, rawName, value, owner);
977     
978           // If an AVT wasn't used, validate the value
979
if (avt.isSimple())
980           {
981              int indexOfNSSep = value.indexOf(':');
982
983              if (indexOfNSSep >= 0)
984              {
985                   String JavaDoc prefix = value.substring(0, indexOfNSSep);
986                   if (!XMLChar.isValidNCName(prefix))
987                   {
988                      handleError(handler,XSLTErrorResources.INVALID_QNAME,new Object JavaDoc[]{name,value },null);
989                      return null;
990                   }
991              }
992                  
993              String JavaDoc localName = (indexOfNSSep < 0)
994                  ? value : value.substring(indexOfNSSep + 1);
995              
996              if ((localName == null) || (localName.length() == 0) ||
997                  (!XMLChar.isValidNCName(localName)))
998              {
999                      handleError(handler,XSLTErrorResources.INVALID_QNAME,new Object JavaDoc[]{name,value },null );
1000                     return null;
1001             }
1002          }
1003        }
1004        catch (TransformerException JavaDoc te)
1005        {
1006           // thrown by AVT constructor
1007
throw new org.xml.sax.SAXException JavaDoc(te);
1008        }
1009    
1010    return avt;
1011 }
1012
1013  /**
1014   * Process an attribute string of type NCName into a String
1015   *
1016   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
1017   * @param uri The Namespace URI, or an empty string.
1018   * @param name The local name (without prefix), or empty string if not namespace processing.
1019   * @param rawName The qualified name (with prefix).
1020   * @param value A string that represents a potentially prefix qualified name.
1021   * @param owner
1022   *
1023   * @return A String object if this attribute does not support AVT's. Otherwise, an AVT
1024   * is returned.
1025   *
1026   * @throws org.xml.sax.SAXException if the string contains a prefix that can not be
1027   * resolved, or the string contains syntax that is invalid for a NCName.
1028   */

1029  Object JavaDoc processNCNAME(
1030          StylesheetHandler handler, String JavaDoc uri, String JavaDoc name, String JavaDoc rawName, String JavaDoc value, ElemTemplateElement owner)
1031            throws org.xml.sax.SAXException JavaDoc
1032  {
1033    
1034    if (getSupportsAVT())
1035    {
1036        AVT avt = null;
1037        try
1038        {
1039          avt = new AVT(handler, uri, name, rawName, value, owner);
1040    
1041          // If an AVT wasn't used, validate the value
1042
if ((avt.isSimple()) && (!XMLChar.isValidNCName(value)))
1043          {
1044             handleError(handler,XSLTErrorResources.INVALID_NCNAME,new Object JavaDoc[] {name,value},null);
1045             return null;
1046          }
1047          return avt;
1048        }
1049        catch (TransformerException JavaDoc te)
1050        {
1051           // thrown by AVT constructor
1052
throw new org.xml.sax.SAXException JavaDoc(te);
1053        }
1054        
1055    } else {
1056        if (!XMLChar.isValidNCName(value))
1057        {
1058            handleError(handler,XSLTErrorResources.INVALID_NCNAME,new Object JavaDoc[] {name,value},null);
1059            return null;
1060        }
1061        return value;
1062    }
1063 }
1064
1065  /**
1066   * Process an attribute string of type T_QNAMES into a vector of QNames where
1067   * the specification requires that non-prefixed elements not be placed in a
1068   * namespace. (See section 2.4 of XSLT 1.0.)
1069   *
1070   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
1071   * @param uri The Namespace URI, or an empty string.
1072   * @param name The local name (without prefix), or empty string if not namespace processing.
1073   * @param rawName The qualified name (with prefix).
1074   * @param value A whitespace delimited list of qualified names.
1075   *
1076   * @return a Vector of QName objects.
1077   *
1078   * @throws org.xml.sax.SAXException if the one of the qualified name strings
1079   * contains a prefix that can not be
1080   * resolved, or a qualified name contains syntax that is invalid for a qualified name.
1081   */

1082  Vector JavaDoc processQNAMES(
1083          StylesheetHandler handler, String JavaDoc uri, String JavaDoc name, String JavaDoc rawName, String JavaDoc value)
1084            throws org.xml.sax.SAXException JavaDoc
1085  {
1086
1087    StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(value, " \t\n\r\f");
1088    int nQNames = tokenizer.countTokens();
1089    Vector JavaDoc qnames = new Vector JavaDoc(nQNames);
1090
1091    for (int i = 0; i < nQNames; i++)
1092    {
1093      // Fix from Alexander Rudnev
1094
qnames.addElement(new QName(tokenizer.nextToken(), handler));
1095    }
1096
1097    return qnames;
1098  }
1099
1100 /**
1101   * Process an attribute string of type T_QNAMES_RESOLVE_NULL into a vector
1102   * of QNames where the specification requires non-prefixed elements to be
1103   * placed in the default namespace. (See section 16 of XSLT 1.0; the
1104   * <em>only</em> time that this will get called is for the
1105   * <code>cdata-section-elements</code> attribute on <code>xsl:output</code>.
1106   *
1107   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
1108   * @param uri The Namespace URI, or an empty string.
1109   * @param name The local name (without prefix), or empty string if not namespace processing.
1110   * @param rawName The qualified name (with prefix).
1111   * @param value A whitespace delimited list of qualified names.
1112   *
1113   * @return a Vector of QName objects.
1114   *
1115   * @throws org.xml.sax.SAXException if the one of the qualified name strings
1116   * contains a prefix that can not be resolved, or a qualified name contains
1117   * syntax that is invalid for a qualified name.
1118   */

1119  final Vector JavaDoc processQNAMESRNU(StylesheetHandler handler, String JavaDoc uri,
1120    String JavaDoc name, String JavaDoc rawName, String JavaDoc value)
1121    throws org.xml.sax.SAXException JavaDoc
1122  {
1123
1124    StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(value, " \t\n\r\f");
1125    int nQNames = tokenizer.countTokens();
1126    Vector JavaDoc qnames = new Vector JavaDoc(nQNames);
1127
1128    String JavaDoc defaultURI = handler.getNamespaceForPrefix("");
1129    for (int i = 0; i < nQNames; i++)
1130    {
1131      String JavaDoc tok = tokenizer.nextToken();
1132      if (tok.indexOf(':') == -1) {
1133        qnames.addElement(new QName(defaultURI,tok));
1134      } else {
1135        qnames.addElement(new QName(tok, handler));
1136      }
1137    }
1138    return qnames;
1139  }
1140
1141  /**
1142   * Process an attribute string of type T_SIMPLEPATTERNLIST into
1143   * a vector of XPath match patterns.
1144   *
1145   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
1146   * @param uri The Namespace URI, or an empty string.
1147   * @param name The local name (without prefix), or empty string if not namespace processing.
1148   * @param rawName The qualified name (with prefix).
1149   * @param value A whitespace delimited list of simple match patterns.
1150   *
1151   * @return A Vector of XPath objects.
1152   *
1153   * @throws org.xml.sax.SAXException that wraps a
1154   * {@link javax.xml.transform.TransformerException} if one of the match pattern
1155   * strings contains a syntax error.
1156   */

1157  Vector JavaDoc processSIMPLEPATTERNLIST(
1158          StylesheetHandler handler, String JavaDoc uri, String JavaDoc name, String JavaDoc rawName, String JavaDoc value,
1159          ElemTemplateElement owner)
1160            throws org.xml.sax.SAXException JavaDoc
1161  {
1162
1163    try
1164    {
1165      StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(value, " \t\n\r\f");
1166      int nPatterns = tokenizer.countTokens();
1167      Vector JavaDoc patterns = new Vector JavaDoc(nPatterns);
1168
1169      for (int i = 0; i < nPatterns; i++)
1170      {
1171        XPath pattern =
1172          handler.createMatchPatternXPath(tokenizer.nextToken(), owner);
1173
1174        patterns.addElement(pattern);
1175      }
1176
1177      return patterns;
1178    }
1179    catch (TransformerException JavaDoc te)
1180    {
1181      throw new org.xml.sax.SAXException JavaDoc(te);
1182    }
1183  }
1184
1185  /**
1186   * Process an attribute string of type T_STRINGLIST into
1187   * a vector of XPath match patterns.
1188   *
1189   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
1190   * @param uri The Namespace URI, or an empty string.
1191   * @param name The local name (without prefix), or empty string if not namespace processing.
1192   * @param rawName The qualified name (with prefix).
1193   * @param value a whitespace delimited list of string values.
1194   *
1195   * @return A StringVector of the tokenized strings.
1196   */

1197  StringVector processSTRINGLIST(StylesheetHandler handler, String JavaDoc uri,
1198                                 String JavaDoc name, String JavaDoc rawName, String JavaDoc value)
1199  {
1200
1201    StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(value, " \t\n\r\f");
1202    int nStrings = tokenizer.countTokens();
1203    StringVector strings = new StringVector(nStrings);
1204
1205    for (int i = 0; i < nStrings; i++)
1206    {
1207      strings.addElement(tokenizer.nextToken());
1208    }
1209
1210    return strings;
1211  }
1212
1213  /**
1214   * Process an attribute string of type T_URLLIST into
1215   * a vector of prefixes that may be resolved to URLs.
1216   *
1217   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
1218   * @param uri The Namespace URI, or an empty string.
1219   * @param name The local name (without prefix), or empty string if not namespace processing.
1220   * @param rawName The qualified name (with prefix).
1221   * @param value A list of whitespace delimited prefixes.
1222   *
1223   * @return A vector of strings that may be resolved to URLs.
1224   *
1225   * @throws org.xml.sax.SAXException if one of the prefixes can not be resolved.
1226   */

1227  StringVector processPREFIX_URLLIST(
1228          StylesheetHandler handler, String JavaDoc uri, String JavaDoc name, String JavaDoc rawName, String JavaDoc value)
1229            throws org.xml.sax.SAXException JavaDoc
1230  {
1231
1232    StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(value, " \t\n\r\f");
1233    int nStrings = tokenizer.countTokens();
1234    StringVector strings = new StringVector(nStrings);
1235
1236    for (int i = 0; i < nStrings; i++)
1237    {
1238      String JavaDoc prefix = tokenizer.nextToken();
1239      String JavaDoc url = handler.getNamespaceForPrefix(prefix);
1240
1241      if (url != null)
1242        strings.addElement(url);
1243      else
1244        throw new org.xml.sax.SAXException JavaDoc(XSLMessages.createMessage(XSLTErrorResources.ER_CANT_RESOLVE_NSPREFIX, new Object JavaDoc[] {prefix}));
1245    
1246    }
1247
1248    return strings;
1249  }
1250
1251  /**
1252    * Process an attribute string of type T_PREFIXLIST into
1253    * a vector of prefixes that may be resolved to URLs.
1254    *
1255    * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
1256    * @param uri The Namespace URI, or an empty string.
1257    * @param name The local name (without prefix), or empty string if not namespace processing.
1258    * @param rawName The qualified name (with prefix).
1259    * @param value A list of whitespace delimited prefixes.
1260    *
1261    * @return A vector of strings that may be resolved to URLs.
1262    *
1263    * @throws org.xml.sax.SAXException if one of the prefixes can not be resolved.
1264    */

1265   StringVector processPREFIX_LIST(
1266           StylesheetHandler handler, String JavaDoc uri, String JavaDoc name,
1267           String JavaDoc rawName, String JavaDoc value) throws org.xml.sax.SAXException JavaDoc
1268   {
1269    
1270     StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(value, " \t\n\r\f");
1271     int nStrings = tokenizer.countTokens();
1272     StringVector strings = new StringVector(nStrings);
1273
1274     for (int i = 0; i < nStrings; i++)
1275     {
1276       String JavaDoc prefix = tokenizer.nextToken();
1277       String JavaDoc url = handler.getNamespaceForPrefix(prefix);
1278       if (prefix.equals(Constants.ATTRVAL_DEFAULT_PREFIX) || url != null)
1279         strings.addElement(prefix);
1280       else
1281         throw new org.xml.sax.SAXException JavaDoc(
1282              XSLMessages.createMessage(
1283                   XSLTErrorResources.ER_CANT_RESOLVE_NSPREFIX,
1284                   new Object JavaDoc[] {prefix}));
1285    
1286     }
1287
1288     return strings;
1289   }
1290
1291
1292  /**
1293   * Process an attribute string of type T_URL into
1294   * a URL value.
1295   *
1296   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
1297   * @param uri The Namespace URI, or an empty string.
1298   * @param name The local name (without prefix), or empty string if not namespace processing.
1299   * @param rawName The qualified name (with prefix).
1300   * @param value non-null string that conforms to the URL syntax.
1301   *
1302   * @return The non-absolutized URL argument, in other words, the value argument. If this
1303   * attribute supports AVT, an AVT is returned.
1304   *
1305   * @throws org.xml.sax.SAXException if the URL does not conform to the URL syntax.
1306   */

1307  Object JavaDoc processURL(
1308          StylesheetHandler handler, String JavaDoc uri, String JavaDoc name, String JavaDoc rawName, String JavaDoc value, ElemTemplateElement owner)
1309            throws org.xml.sax.SAXException JavaDoc
1310  {
1311
1312    if (getSupportsAVT()) {
1313        try
1314        {
1315          AVT avt = new AVT(handler, uri, name, rawName, value, owner);
1316    
1317          // If an AVT wasn't used, validate the value
1318
// if (avt.getSimpleString() != null) {
1319
// TODO: syntax check URL value.
1320
// return SystemIDResolver.getAbsoluteURI(value,
1321
// handler.getBaseIdentifier());
1322
//}
1323
return avt;
1324        }
1325        catch (TransformerException JavaDoc te)
1326        {
1327          throw new org.xml.sax.SAXException JavaDoc(te);
1328        }
1329     } else {
1330    // TODO: syntax check URL value.
1331
// return SystemIDResolver.getAbsoluteURI(value,
1332
// handler.getBaseIdentifier());
1333

1334        return value;
1335    }
1336  }
1337
1338  /**
1339   * Process an attribute string of type T_YESNO into
1340   * a Boolean value.
1341   *
1342   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
1343   * @param uri The Namespace URI, or an empty string.
1344   * @param name The local name (without prefix), or empty string if not namespace processing.
1345   * @param rawName The qualified name (with prefix).
1346   * @param value A string that should be "yes" or "no".
1347   *
1348   * @return Boolean object representation of the value.
1349   *
1350   * @throws org.xml.sax.SAXException
1351   */

1352  private Boolean JavaDoc processYESNO(
1353          StylesheetHandler handler, String JavaDoc uri, String JavaDoc name, String JavaDoc rawName, String JavaDoc value)
1354            throws org.xml.sax.SAXException JavaDoc
1355  {
1356
1357    // Is this already checked somewhere else? -sb
1358
if (!(value.equals("yes") || value.equals("no")))
1359    {
1360      handleError(handler, XSLTErrorResources.INVALID_BOOLEAN, new Object JavaDoc[] {name,value}, null);
1361      return null;
1362   }
1363 
1364     return new Boolean JavaDoc(value.equals("yes") ? true : false);
1365  }
1366
1367  /**
1368   * Process an attribute value.
1369   *
1370   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
1371   * @param uri The Namespace URI, or an empty string.
1372   * @param name The local name (without prefix), or empty string if not namespace processing.
1373   * @param rawName The qualified name (with prefix).
1374   * @param value The unprocessed string value of the attribute.
1375   *
1376   * @return The processed Object representation of the attribute.
1377   *
1378   * @throws org.xml.sax.SAXException if the attribute value can not be processed.
1379   */

1380  Object JavaDoc processValue(
1381          StylesheetHandler handler, String JavaDoc uri, String JavaDoc name, String JavaDoc rawName, String JavaDoc value,
1382          ElemTemplateElement owner)
1383            throws org.xml.sax.SAXException JavaDoc
1384  {
1385
1386    int type = getType();
1387    Object JavaDoc processedValue = null;
1388
1389    switch (type)
1390    {
1391    case T_AVT :
1392      processedValue = processAVT(handler, uri, name, rawName, value, owner);
1393      break;
1394    case T_CDATA :
1395      processedValue = processCDATA(handler, uri, name, rawName, value, owner);
1396      break;
1397    case T_CHAR :
1398      processedValue = processCHAR(handler, uri, name, rawName, value, owner);
1399      break;
1400    case T_ENUM :
1401      processedValue = processENUM(handler, uri, name, rawName, value, owner);
1402      break;
1403    case T_EXPR :
1404      processedValue = processEXPR(handler, uri, name, rawName, value, owner);
1405      break;
1406    case T_NMTOKEN :
1407      processedValue = processNMTOKEN(handler, uri, name, rawName, value, owner);
1408      break;
1409    case T_PATTERN :
1410      processedValue = processPATTERN(handler, uri, name, rawName, value, owner);
1411      break;
1412    case T_NUMBER :
1413      processedValue = processNUMBER(handler, uri, name, rawName, value, owner);
1414      break;
1415    case T_QNAME :
1416      processedValue = processQNAME(handler, uri, name, rawName, value, owner);
1417      break;
1418    case T_QNAMES :
1419      processedValue = processQNAMES(handler, uri, name, rawName, value);
1420      break;
1421    case T_QNAMES_RESOLVE_NULL:
1422      processedValue = processQNAMESRNU(handler, uri, name, rawName, value);
1423      break;
1424    case T_SIMPLEPATTERNLIST :
1425      processedValue = processSIMPLEPATTERNLIST(handler, uri, name, rawName,
1426                                                value, owner);
1427      break;
1428    case T_URL :
1429      processedValue = processURL(handler, uri, name, rawName, value, owner);
1430      break;
1431    case T_YESNO :
1432      processedValue = processYESNO(handler, uri, name, rawName, value);
1433      break;
1434    case T_STRINGLIST :
1435      processedValue = processSTRINGLIST(handler, uri, name, rawName, value);
1436      break;
1437    case T_PREFIX_URLLIST :
1438      processedValue = processPREFIX_URLLIST(handler, uri, name, rawName,
1439                                             value);
1440      break;
1441    case T_ENUM_OR_PQNAME :
1442        processedValue = processENUM_OR_PQNAME(handler, uri, name, rawName, value, owner);
1443        break;
1444    case T_NCNAME :
1445        processedValue = processNCNAME(handler, uri, name, rawName, value, owner);
1446        break;
1447    case T_AVT_QNAME :
1448        processedValue = processAVT_QNAME(handler, uri, name, rawName, value, owner);
1449        break;
1450    case T_PREFIXLIST :
1451      processedValue = processPREFIX_LIST(handler, uri, name, rawName,
1452                                             value);
1453      break;
1454
1455    default :
1456    }
1457
1458    return processedValue;
1459  }
1460
1461  /**
1462   * Set the default value of an attribute.
1463   *
1464   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
1465   * @param elem The object on which the property will be set.
1466   *
1467   * @throws org.xml.sax.SAXException wraps an invocation exception if the
1468   * setter method can not be invoked on the object.
1469   */

1470  void setDefAttrValue(StylesheetHandler handler, ElemTemplateElement elem)
1471          throws org.xml.sax.SAXException JavaDoc
1472  {
1473    setAttrValue(handler, this.getNamespace(), this.getName(),
1474                 this.getName(), this.getDefault(), elem);
1475  }
1476
1477  /**
1478   * Get the primative type for the class, if there
1479   * is one. If the class is a Double, for instance,
1480   * this will return double.class. If the class is not one
1481   * of the 9 primative types, it will return the same
1482   * class that was passed in.
1483   *
1484   * @param obj The object which will be resolved to a primative class object if possible.
1485   *
1486   * @return The most primative class representation possible for the object, never null.
1487   */

1488  private Class JavaDoc getPrimativeClass(Object JavaDoc obj)
1489  {
1490
1491    if (obj instanceof XPath)
1492      return XPath.class;
1493
1494    Class JavaDoc cl = obj.getClass();
1495
1496    if (cl == Double JavaDoc.class)
1497    {
1498      cl = double.class;
1499    }
1500
1501    if (cl == Float JavaDoc.class)
1502    {
1503      cl = float.class;
1504    }
1505    else if (cl == Boolean JavaDoc.class)
1506    {
1507      cl = boolean.class;
1508    }
1509    else if (cl == Byte JavaDoc.class)
1510    {
1511      cl = byte.class;
1512    }
1513    else if (cl == Character JavaDoc.class)
1514    {
1515      cl = char.class;
1516    }
1517    else if (cl == Short JavaDoc.class)
1518    {
1519      cl = short.class;
1520    }
1521    else if (cl == Integer JavaDoc.class)
1522    {
1523      cl = int.class;
1524    }
1525    else if (cl == Long JavaDoc.class)
1526    {
1527      cl = long.class;
1528    }
1529
1530    return cl;
1531  }
1532  
1533  /**
1534   * StringBuffer containing comma delimited list of valid values for ENUM type.
1535   * Used to build error message.
1536   */

1537  private StringBuffer JavaDoc getListOfEnums()
1538  {
1539     StringBuffer JavaDoc enumNamesList = new StringBuffer JavaDoc();
1540     String JavaDoc [] enumValues = this.getEnumNames();
1541
1542     for (int i = 0; i < enumValues.length; i++)
1543     {
1544        if (i > 0)
1545        {
1546           enumNamesList.append(' ');
1547        }
1548        enumNamesList.append(enumValues[i]);
1549    }
1550    return enumNamesList;
1551  }
1552
1553  /**
1554   * Set a value on an attribute.
1555   *
1556   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
1557   * @param attrUri The Namespace URI of the attribute, or an empty string.
1558   * @param attrLocalName The local name (without prefix), or empty string if not namespace processing.
1559   * @param attrRawName The raw name of the attribute, including possible prefix.
1560   * @param attrValue The attribute's value.
1561   * @param elem The object that should contain a property that represents the attribute.
1562   *
1563   * @throws org.xml.sax.SAXException
1564   */

1565  boolean setAttrValue(
1566          StylesheetHandler handler, String JavaDoc attrUri, String JavaDoc attrLocalName,
1567          String JavaDoc attrRawName, String JavaDoc attrValue, ElemTemplateElement elem)
1568            throws org.xml.sax.SAXException JavaDoc
1569  {
1570    if(attrRawName.equals("xmlns") || attrRawName.startsWith("xmlns:"))
1571      return true;
1572      
1573    String JavaDoc setterString = getSetterMethodName();
1574
1575    // If this is null, then it is a foreign namespace and we
1576
// do not process it.
1577
if (null != setterString)
1578    {
1579      try
1580      {
1581        Method JavaDoc meth;
1582        Object JavaDoc[] args;
1583
1584        if(setterString.equals(S_FOREIGNATTR_SETTER))
1585        {
1586          // workaround for possible crimson bug
1587
if( attrUri==null) attrUri="";
1588          // First try to match with the primative value.
1589
Class JavaDoc sclass = attrUri.getClass();
1590          Class JavaDoc[] argTypes = new Class JavaDoc[]{ sclass, sclass,
1591                                      sclass, sclass };
1592  
1593          meth = elem.getClass().getMethod(setterString, argTypes);
1594  
1595          args = new Object JavaDoc[]{ attrUri, attrLocalName,
1596                                      attrRawName, attrValue };
1597        }
1598        else
1599        {
1600          Object JavaDoc value = processValue(handler, attrUri, attrLocalName,
1601                                      attrRawName, attrValue, elem);
1602          // If a warning was issued because the value for this attribute was
1603
// invalid, then the value will be null. Just return
1604
if (null == value) return false;
1605                                      
1606          // First try to match with the primative value.
1607
Class JavaDoc[] argTypes = new Class JavaDoc[]{ getPrimativeClass(value) };
1608  
1609          try
1610          {
1611            meth = elem.getClass().getMethod(setterString, argTypes);
1612          }
1613          catch (NoSuchMethodException JavaDoc nsme)
1614          {
1615            Class JavaDoc cl = ((Object JavaDoc) value).getClass();
1616  
1617            // If this doesn't work, try it with the non-primative value;
1618
argTypes[0] = cl;
1619            meth = elem.getClass().getMethod(setterString, argTypes);
1620          }
1621  
1622          args = new Object JavaDoc[]{ value };
1623        }
1624
1625        meth.invoke(elem, args);
1626      }
1627      catch (NoSuchMethodException JavaDoc nsme)
1628      {
1629        if (!setterString.equals(S_FOREIGNATTR_SETTER))
1630        {
1631          handler.error(XSLTErrorResources.ER_FAILED_CALLING_METHOD, new Object JavaDoc[]{setterString}, nsme);//"Failed calling " + setterString + " method!", nsme);
1632
return false;
1633        }
1634      }
1635      catch (IllegalAccessException JavaDoc iae)
1636      {
1637        handler.error(XSLTErrorResources.ER_FAILED_CALLING_METHOD, new Object JavaDoc[]{setterString}, iae);//"Failed calling " + setterString + " method!", iae);
1638
return false;
1639      }
1640      catch (InvocationTargetException JavaDoc nsme)
1641      {
1642        handleError(handler, XSLTErrorResources.WG_ILLEGAL_ATTRIBUTE_VALUE,
1643            new Object JavaDoc[]{ Constants.ATTRNAME_NAME, getName()}, nsme);
1644        return false;
1645      }
1646    }
1647    
1648    return true;
1649  }
1650  
1651  private void handleError(StylesheetHandler handler, String JavaDoc msg, Object JavaDoc [] args, Exception JavaDoc exc) throws org.xml.sax.SAXException JavaDoc
1652  {
1653    switch (getErrorType())
1654    {
1655        case (FATAL):
1656        case (ERROR):
1657                handler.error(msg, args, exc);
1658                break;
1659        case (WARNING):
1660                handler.warn(msg, args);
1661        default: break;
1662    }
1663  }
1664}
1665
Popular Tags