xsltattributedef.java

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

JAVA
1,654
字号
    }    return strings;  }  /**   * Process an attribute string of type T_URLLIST into   * a vector of prefixes that may be resolved to URLs.   *   * @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 list of whitespace delimited prefixes.   *   * @return A vector of strings that may be resolved to URLs.   *   * @throws org.xml.sax.SAXException if one of the prefixes can not be resolved.   */  StringVector processPREFIX_URLLIST(          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 nStrings = tokenizer.countTokens();    StringVector strings = new StringVector(nStrings);    for (int i = 0; i < nStrings; i++)    {      String prefix = tokenizer.nextToken();      String url = handler.getNamespaceForPrefix(prefix);      if (url != null)        strings.addElement(url);      else        throw new org.xml.sax.SAXException(XSLMessages.createMessage(XSLTErrorResources.ER_CANT_RESOLVE_NSPREFIX, new Object[] {prefix}));        }    return strings;  }  /**   * Process an attribute string of type T_URL into   * a URL 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 non-null string that conforms to the URL syntax.   *   * @return The non-absolutized URL argument, in other words, the value argument.  If this    *         attribute supports AVT, an AVT is returned.   *   * @throws org.xml.sax.SAXException if the URL does not conform to the URL syntax.   */  Object processURL(          StylesheetHandler handler, String uri, String name, String rawName, String value, ElemTemplateElement owner)            throws org.xml.sax.SAXException  {    if (getSupportsAVT()) {	    try	    {	      AVT avt = new AVT(handler, uri, name, rawName, value, owner);			  // If an AVT wasn't used, validate the value		 // if (avt.getSimpleString() != null) {			   // TODO: syntax check URL value.			    // return SystemIDResolver.getAbsoluteURI(value, 			    //                                         handler.getBaseIdentifier());		  //}		      return avt;	    }	    catch (TransformerException te)	    {	      throw new org.xml.sax.SAXException(te);	    }  		     } else {    // TODO: syntax check URL value.    // return SystemIDResolver.getAbsoluteURI(value,     //                                         handler.getBaseIdentifier());     		    return value;    }  }  /**   * Process an attribute string of type T_YESNO into   * a Boolean 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 should be "yes" or "no".   *   * @return Boolean object representation of the value.   *   * @throws org.xml.sax.SAXException   */  private Boolean processYESNO(          StylesheetHandler handler, String uri, String name, String rawName, String value)            throws org.xml.sax.SAXException  {    // Is this already checked somewhere else?  -sb    if (!(value.equals("yes") || value.equals("no")))    {      handleError(handler, XSLTErrorResources.INVALID_BOOLEAN, new Object[] {name,value}, null);      return null;   }      return new Boolean(value.equals("yes") ? true : false);  }  /**   * Process an attribute 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 The unprocessed string value of the attribute.   *   * @return The processed Object representation of the attribute.   *   * @throws org.xml.sax.SAXException if the attribute value can not be processed.   */  Object processValue(          StylesheetHandler handler, String uri, String name, String rawName, String value,          ElemTemplateElement owner)            throws org.xml.sax.SAXException  {    int type = getType();    Object processedValue = null;    switch (type)    {    case T_AVT :      processedValue = processAVT(handler, uri, name, rawName, value, owner);      break;    case T_CDATA :      processedValue = processCDATA(handler, uri, name, rawName, value, owner);      break;    case T_CHAR :      processedValue = processCHAR(handler, uri, name, rawName, value, owner);      break;    case T_ENUM :      processedValue = processENUM(handler, uri, name, rawName, value, owner);      break;    case T_EXPR :      processedValue = processEXPR(handler, uri, name, rawName, value, owner);      break;    case T_NMTOKEN :      processedValue = processNMTOKEN(handler, uri, name, rawName, value, owner);      break;    case T_PATTERN :      processedValue = processPATTERN(handler, uri, name, rawName, value, owner);      break;    case T_NUMBER :      processedValue = processNUMBER(handler, uri, name, rawName, value, owner);      break;    case T_QNAME :      processedValue = processQNAME(handler, uri, name, rawName, value, owner);      break;    case T_QNAMES :      processedValue = processQNAMES(handler, uri, name, rawName, value);      break;	case T_QNAMES_RESOLVE_NULL:      processedValue = processQNAMESRNU(handler, uri, name, rawName, value);      break;    case T_SIMPLEPATTERNLIST :      processedValue = processSIMPLEPATTERNLIST(handler, uri, name, rawName,                                                value, owner);      break;    case T_URL :      processedValue = processURL(handler, uri, name, rawName, value, owner);      break;    case T_YESNO :      processedValue = processYESNO(handler, uri, name, rawName, value);      break;    case T_STRINGLIST :      processedValue = processSTRINGLIST(handler, uri, name, rawName, value);      break;    case T_PREFIX_URLLIST :      processedValue = processPREFIX_URLLIST(handler, uri, name, rawName,                                             value);      break;    case T_ENUM_OR_PQNAME :    	processedValue = processENUM_OR_PQNAME(handler, uri, name, rawName, value, owner);    	break;    case T_NCNAME :        processedValue = processNCNAME(handler, uri, name, rawName, value, owner);        break;    case T_AVT_QNAME :        processedValue = processAVT_QNAME(handler, uri, name, rawName, value, owner);        break;    default :    }    return processedValue;  }  /**   * Set the default value of an attribute.   *   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.   * @param elem The object on which the property will be set.   *   * @throws org.xml.sax.SAXException wraps an invocation exception if the   * setter method can not be invoked on the object.   */  void setDefAttrValue(StylesheetHandler handler, ElemTemplateElement elem)          throws org.xml.sax.SAXException  {    setAttrValue(handler, this.getNamespace(), this.getName(),                 this.getName(), this.getDefault(), elem);  }  /**   * Get the primative type for the class, if there   * is one.  If the class is a Double, for instance,   * this will return double.class.  If the class is not one   * of the 9 primative types, it will return the same   * class that was passed in.   *   * @param obj The object which will be resolved to a primative class object if possible.   *   * @return The most primative class representation possible for the object, never null.   */  private Class getPrimativeClass(Object obj)  {    if (obj instanceof XPath)      return XPath.class;    Class cl = obj.getClass();    if (cl == Double.class)    {      cl = double.class;    }    if (cl == Float.class)    {      cl = float.class;    }    else if (cl == Boolean.class)    {      cl = boolean.class;    }    else if (cl == Byte.class)    {      cl = byte.class;    }    else if (cl == Character.class)    {      cl = char.class;    }    else if (cl == Short.class)    {      cl = short.class;    }    else if (cl == Integer.class)    {      cl = int.class;    }    else if (cl == Long.class)    {      cl = long.class;    }    return cl;  }    /**   * StringBuffer containing comma delimited list of valid values for ENUM type.   * Used to build error message.   */  private StringBuffer getListOfEnums()   {     StringBuffer enumNamesList = new StringBuffer();                 String [] enumValues = this.getEnumNames();     for (int i = 0; i < enumValues.length; i++)     {        if (i > 0)        {           enumNamesList.append(' ');        }        enumNamesList.append(enumValues[i]);    }            return enumNamesList;  }  /**   * Set a value on an attribute.   *   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.   * @param attrUri The Namespace URI of the attribute, or an empty string.   * @param attrLocalName The local name (without prefix), or empty string if not namespace processing.   * @param attrRawName The raw name of the attribute, including possible prefix.   * @param attrValue The attribute's value.   * @param elem The object that should contain a property that represents the attribute.   *   * @throws org.xml.sax.SAXException   */  boolean setAttrValue(          StylesheetHandler handler, String attrUri, String attrLocalName,           String attrRawName, String attrValue, ElemTemplateElement elem)            throws org.xml.sax.SAXException  {    if(attrRawName.equals("xmlns") || attrRawName.startsWith("xmlns:"))      return true;          String setterString = getSetterMethodName();    // If this is null, then it is a foreign namespace and we     // do not process it.    if (null != setterString)    {      try      {        Method meth;        Object[] args;        if(setterString.equals(S_FOREIGNATTR_SETTER))        {          // workaround for possible crimson bug          if( attrUri==null) attrUri="";          // First try to match with the primative value.          Class sclass = attrUri.getClass();          Class[] argTypes = new Class[]{ sclass, sclass,                                      sclass, sclass };            meth = elem.getClass().getMethod(setterString, argTypes);            args = new Object[]{ attrUri, attrLocalName,                                      attrRawName, attrValue };        }        else        {          Object value = processValue(handler, attrUri, attrLocalName,                                      attrRawName, attrValue, elem);          // If a warning was issued because the value for this attribute was          // invalid, then the value will be null.  Just return          if (null == value) return false;                                                // First try to match with the primative value.          Class[] argTypes = new Class[]{ getPrimativeClass(value) };            try          {            meth = elem.getClass().getMethod(setterString, argTypes);          }          catch (NoSuchMethodException nsme)          {            Class cl = ((Object) value).getClass();              // If this doesn't work, try it with the non-primative value;            argTypes[0] = cl;            meth = elem.getClass().getMethod(setterString, argTypes);          }            args = new Object[]{ value };        }        meth.invoke(elem, args);      }      catch (NoSuchMethodException nsme)      {        if (!setterString.equals(S_FOREIGNATTR_SETTER))         {          handler.error(XSLTErrorResources.ER_FAILED_CALLING_METHOD, new Object[]{setterString}, nsme);//"Failed calling " + setterString + " method!", nsme);          return false;        }      }      catch (IllegalAccessException iae)      {        handler.error(XSLTErrorResources.ER_FAILED_CALLING_METHOD, new Object[]{setterString}, iae);//"Failed calling " + setterString + " method!", iae);        return false;      }      catch (InvocationTargetException nsme)      {        handleError(handler, XSLTErrorResources.WG_ILLEGAL_ATTRIBUTE_VALUE,            new Object[]{ Constants.ATTRNAME_NAME, getName()}, nsme);        return false;      }    }        return true;  }    private void handleError(StylesheetHandler handler, String msg, Object [] args, Exception exc) throws org.xml.sax.SAXException  {    switch (getErrorType())     {        case (FATAL):        case (ERROR):                handler.error(msg, args, exc);                          break;        case (WARNING):                handler.warn(msg, args);               default: break;    }  }}

⌨️ 快捷键说明

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