xsltattributedef.java

来自「java jdk 1.4的源码」· Java 代码 · 共 1,654 行 · 第 1/4 页

JAVA
1,654
字号
	      AVT avt = new AVT(handler, uri, name, rawName, value, owner);			  // If an AVT wasn't used, validate the value		  if ((avt.isSimple()) && (!XMLChar.isValidNmtoken(value))) {            handleError(handler,XSLTErrorResources.INVALID_NMTOKEN, new Object[] {name,value},null);            return null;		  }		      return avt;	    }	    catch (TransformerException te)	    {	      throw new org.xml.sax.SAXException(te);	    }  		  	} else {  		if (!XMLChar.isValidNmtoken(value)) {            handleError(handler,XSLTErrorResources.INVALID_NMTOKEN, new Object[] {name,value},null);            return null;  		}  	}	  			    return value;  }  /**   * Process an attribute string of type T_PATTERN into   * an XPath match pattern value.   *   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.   * @param uri The Namespace URI, or an empty string.   * @param name The local name (without prefix), or empty string if not namespace processing.   * @param rawName The qualified name (with prefix).   * @param value A match pattern string.   *   * @return An XPath pattern that may be used to evaluate the XPath.   *   * @throws org.xml.sax.SAXException that wraps a   * {@link javax.xml.transform.TransformerException} if the match pattern   * string contains a syntax error.   */  Object processPATTERN(          StylesheetHandler handler, String uri, String name, String rawName, String value,          ElemTemplateElement owner)            throws org.xml.sax.SAXException  {    try    {      XPath pattern = handler.createMatchPatternXPath(value, owner);      return pattern;    }    catch (TransformerException te)    {      throw new org.xml.sax.SAXException(te);    }  }  /**   * Process an attribute string of type T_NUMBER into   * a double value.   *   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.   * @param uri The Namespace URI, or an empty string.   * @param name The local name (without prefix), or empty string if not namespace processing.   * @param rawName The qualified name (with prefix).   * @param value A string that can be parsed into a double value.   * @param number   *   * @return A Double object.   *   * @throws org.xml.sax.SAXException that wraps a   * {@link javax.xml.transform.TransformerException}   * if the string does not contain a parsable number.   */  Object processNUMBER(          StylesheetHandler handler, String uri, String name, String rawName, String value, ElemTemplateElement owner)            throws org.xml.sax.SAXException  {	if (getSupportsAVT()) 	{		Double val;		AVT avt = null;	    try	    {	      avt = new AVT(handler, uri, name, rawName, value, owner);	      	      // If this attribute used an avt, then we can't validate at this time.	      if (avt.isSimple()) 	      {	      	val = Double.valueOf(value);	      }	    }	    catch (TransformerException te)	    {	      throw new org.xml.sax.SAXException(te);	    } 	    catch (NumberFormatException nfe)	    {	     	handleError(handler,XSLTErrorResources.INVALID_NUMBER, new Object[] {name, value}, nfe);            return null;	    }	    return avt;		} 	else    {	    try	    {	      return Double.valueOf(value);	    }	    catch (NumberFormatException nfe)	    {            handleError(handler,XSLTErrorResources.INVALID_NUMBER, new Object[] {name, value}, nfe);            return null;	    }    }      }  /**   * Process an attribute string of type T_QNAME into a QName value.   *   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.   * @param uri The Namespace URI, or an empty string.   * @param name The local name (without prefix), or empty string if not namespace processing.   * @param rawName The qualified name (with prefix).   * @param value A string that represents a potentially prefix qualified name.   * @param owner   *   * @return A QName object if this attribute does not support AVT's.  Otherwise, an AVT   *         is returned.   *   * @throws org.xml.sax.SAXException if the string contains a prefix that can not be   * resolved, or the string contains syntax that is invalid for a qualified name.   */  Object processQNAME(          StylesheetHandler handler, String uri, String name, String rawName, String value, ElemTemplateElement owner)            throws org.xml.sax.SAXException  {     try         {	   	      QName qname = new QName(value, handler, true);          return qname;        }        catch (IllegalArgumentException ie)        {            // thrown by QName constructor            handleError(handler,XSLTErrorResources.INVALID_QNAME, new Object[] {name, value},ie);            return null;        }        catch (RuntimeException re) {            // thrown by QName constructor            handleError(handler,XSLTErrorResources.INVALID_QNAME, new Object[] {name, value},re);            return null;        }  	}   /**   * Process an attribute string of type T_QNAME into a QName value.   *   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.   * @param uri The Namespace URI, or an empty string.   * @param name The local name (without prefix), or empty string if not namespace processing.   * @param rawName The qualified name (with prefix).   * @param value A string that represents a potentially prefix qualified name.   * @param owner   *   * @return An AVT is returned.   *   * @throws org.xml.sax.SAXException if the string contains a prefix that can not be   * resolved, or the string contains syntax that is invalid for a qualified name.   */  Object processAVT_QNAME(          StylesheetHandler handler, String uri, String name, String rawName, String value, ElemTemplateElement owner)            throws org.xml.sax.SAXException  {       AVT avt = null;       try       {          avt = new AVT(handler, uri, name, rawName, value, owner);              // If an AVT wasn't used, validate the value          if (avt.isSimple())          {             int indexOfNSSep = value.indexOf(':');             if (indexOfNSSep >= 0)              {                     String prefix = value.substring(0, indexOfNSSep);                  if (!XMLChar.isValidNCName(prefix))                  {                     handleError(handler,XSLTErrorResources.INVALID_QNAME,new Object[]{name,value },null);                     return null;                  }             }                              String localName =  (indexOfNSSep < 0)                 ? value : value.substring(indexOfNSSep + 1);                           if ((localName == null) || (localName.length() == 0) ||                 (!XMLChar.isValidNCName(localName)))             {                         handleError(handler,XSLTErrorResources.INVALID_QNAME,new Object[]{name,value },null );                     return null;             }          }          }        catch (TransformerException te)        {           // thrown by AVT constructor          throw new org.xml.sax.SAXException(te);        }         return avt; }  /**   * Process an attribute string of type NCName into a String   *   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.   * @param uri The Namespace URI, or an empty string.   * @param name The local name (without prefix), or empty string if not namespace processing.   * @param rawName The qualified name (with prefix).   * @param value A string that represents a potentially prefix qualified name.   * @param owner   *   * @return A String object if this attribute does not support AVT's.  Otherwise, an AVT   *         is returned.   *   * @throws org.xml.sax.SAXException if the string contains a prefix that can not be   * resolved, or the string contains syntax that is invalid for a NCName.   */  Object processNCNAME(          StylesheetHandler handler, String uri, String name, String rawName, String value, ElemTemplateElement owner)            throws org.xml.sax.SAXException  {        if (getSupportsAVT())     {        AVT avt = null;        try        {          avt = new AVT(handler, uri, name, rawName, value, owner);              // If an AVT wasn't used, validate the value          if ((avt.isSimple()) &&  (!XMLChar.isValidNCName(value)))           {             handleError(handler,XSLTErrorResources.INVALID_NCNAME,new Object[] {name,value},null);             return null;          }                return avt;        }        catch (TransformerException te)        {           // thrown by AVT constructor          throw new org.xml.sax.SAXException(te);        }             } else {        if (!XMLChar.isValidNCName(value))         {            handleError(handler,XSLTErrorResources.INVALID_NCNAME,new Object[] {name,value},null);            return null;        }        return value;    } }  /**   * Process an attribute string of type T_QNAMES into a vector of QNames where   * the specification requires that non-prefixed elements not be placed in a   * namespace.  (See section 2.4 of XSLT 1.0.)   *   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.   * @param uri The Namespace URI, or an empty string.   * @param name The local name (without prefix), or empty string if not namespace processing.   * @param rawName The qualified name (with prefix).   * @param value A whitespace delimited list of qualified names.   *   * @return a Vector of QName objects.   *   * @throws org.xml.sax.SAXException if the one of the qualified name strings   * contains a prefix that can not be   * resolved, or a qualified name contains syntax that is invalid for a qualified name.   */  Vector processQNAMES(          StylesheetHandler handler, String uri, String name, String rawName, String value)            throws org.xml.sax.SAXException  {    StringTokenizer tokenizer = new StringTokenizer(value, " \t\n\r\f");    int nQNames = tokenizer.countTokens();    Vector qnames = new Vector(nQNames);    for (int i = 0; i < nQNames; i++)    {      // Fix from Alexander Rudnev      qnames.addElement(new QName(tokenizer.nextToken(), handler));    }    return qnames;  } /**   * Process an attribute string of type T_QNAMES_RESOLVE_NULL into a vector   * of QNames where the specification requires non-prefixed elements to be   * placed in the default namespace.  (See section 16 of XSLT 1.0; the   * <em>only</em> time that this will get called is for the   * <code>cdata-section-elements</code> attribute on <code>xsl:output</code>.   *   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.   * @param uri The Namespace URI, or an empty string.   * @param name The local name (without prefix), or empty string if not namespace processing.   * @param rawName The qualified name (with prefix).   * @param value A whitespace delimited list of qualified names.   *   * @return a Vector of QName objects.   *   * @throws org.xml.sax.SAXException if the one of the qualified name strings   * contains a prefix that can not be resolved, or a qualified name contains   * syntax that is invalid for a qualified name.   */  final Vector processQNAMESRNU(StylesheetHandler handler, String uri,    String name, String rawName, String value)    throws org.xml.sax.SAXException  {    StringTokenizer tokenizer = new StringTokenizer(value, " \t\n\r\f");    int nQNames = tokenizer.countTokens();    Vector qnames = new Vector(nQNames);    String defaultURI = handler.getNamespaceForPrefix("");    for (int i = 0; i < nQNames; i++)    {      String tok = tokenizer.nextToken();      if (tok.indexOf(':') == -1) {        qnames.addElement(new QName(defaultURI,tok));      } else {        qnames.addElement(new QName(tok, handler));      }    }    return qnames;  }  /**   * Process an attribute string of type T_SIMPLEPATTERNLIST into   * a vector of XPath match patterns.   *   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.   * @param uri The Namespace URI, or an empty string.   * @param name The local name (without prefix), or empty string if not namespace processing.   * @param rawName The qualified name (with prefix).   * @param value A whitespace delimited list of simple match patterns.   *   * @return A Vector of XPath objects.   *   * @throws org.xml.sax.SAXException that wraps a   * {@link javax.xml.transform.TransformerException} if one of the match pattern   * strings contains a syntax error.   */  Vector processSIMPLEPATTERNLIST(          StylesheetHandler handler, String uri, String name, String rawName, String value,          ElemTemplateElement owner)            throws org.xml.sax.SAXException  {    try    {      StringTokenizer tokenizer = new StringTokenizer(value, " \t\n\r\f");      int nPatterns = tokenizer.countTokens();      Vector patterns = new Vector(nPatterns);      for (int i = 0; i < nPatterns; i++)      {        XPath pattern =          handler.createMatchPatternXPath(tokenizer.nextToken(), owner);        patterns.addElement(pattern);      }      return patterns;    }    catch (TransformerException te)    {      throw new org.xml.sax.SAXException(te);    }  }  /**   * Process an attribute string of type T_STRINGLIST into   * a vector of XPath match patterns.   *   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.   * @param uri The Namespace URI, or an empty string.   * @param name The local name (without prefix), or empty string if not namespace processing.   * @param rawName The qualified name (with prefix).   * @param value a whitespace delimited list of string values.   *   * @return A StringVector of the tokenized strings.   */  StringVector processSTRINGLIST(StylesheetHandler handler, String uri,                                 String name, String rawName, String value)  {    StringTokenizer tokenizer = new StringTokenizer(value, " \t\n\r\f");    int nStrings = tokenizer.countTokens();    StringVector strings = new StringVector(nStrings);    for (int i = 0; i < nStrings; i++)    {      strings.addElement(tokenizer.nextToken());

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?