xsltattributedef.java
来自「java jdk 1.4的源码」· Java 代码 · 共 1,654 行 · 第 1/4 页
JAVA
1,654 行
{ m_default = def; } /** * If true, this is a required attribute. */ private boolean m_required; /** * Get whether or not this is a required attribute. * * @return true if this is a required attribute. */ boolean getRequired() { return m_required; } /** * If true, this is attribute supports AVT's. */ private boolean m_supportsAVT; /** * Get whether or not this attribute supports AVT's. * * @return true if this attribute supports AVT's. */ boolean getSupportsAVT() { return m_supportsAVT; } int m_errorType = this.WARNING; /** * Get the type of error message to use if the attribute value is invalid. * * @return one of XSLAttributeDef.FATAL, XSLAttributeDef.ERROR, XSLAttributeDef.WARNING */ int getErrorType() { return m_errorType; } /** * String that should represent the setter method which which * may be used on objects to set a value that represents this attribute */ String m_setterString = null; /** * Return a string that should represent the setter method. * The setter method name will be created algorithmically the * first time this method is accessed, and then cached for return * by subsequent invocations of this method. * * @return String that should represent the setter method which which * may be used on objects to set a value that represents this attribute, * of null if no setter method should be called. */ public String getSetterMethodName() { if (null == m_setterString) { if (m_foreignAttr == this) { return S_FOREIGNATTR_SETTER; } else if (m_name.equals("*")) { m_setterString = "addLiteralResultAttribute"; return m_setterString; } StringBuffer outBuf = new StringBuffer(); outBuf.append("set"); if ((m_namespace != null) && m_namespace.equals(Constants.S_XMLNAMESPACEURI)) { outBuf.append("Xml"); } int n = m_name.length(); for (int i = 0; i < n; i++) { char c = m_name.charAt(i); if ('-' == c) { i++; c = m_name.charAt(i); c = Character.toUpperCase(c); } else if (0 == i) { c = Character.toUpperCase(c); } outBuf.append(c); } m_setterString = outBuf.toString(); } return m_setterString; } /** * Process an attribute string of type T_AVT into * a AVT 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 Should be an Attribute Value Template string. * * @return An AVT object that may be used to evaluate the Attribute Value Template. * * @throws org.xml.sax.SAXException which will wrap a * {@link javax.xml.transform.TransformerException}, if there is a syntax error * in the attribute value template string. */ AVT processAVT( StylesheetHandler handler, String uri, String name, String rawName, String value, ElemTemplateElement owner) throws org.xml.sax.SAXException { try { AVT avt = new AVT(handler, uri, name, rawName, value, owner); return avt; } catch (TransformerException te) { throw new org.xml.sax.SAXException(te); } } /** * Process an attribute string of type T_CDATA into * a String 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 reference. * * @return The value argument. * * @throws org.xml.sax.SAXException. */ Object processCDATA(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); return avt; } catch (TransformerException te) { throw new org.xml.sax.SAXException(te); } } else { return value; } } /** * Process an attribute string of type T_CHAR into * a Character 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 Should be a string with a length of 1. * * @return Character object. * * @throws org.xml.sax.SAXException if the string is not a length of 1. */ Object processCHAR( 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.isSimple()) && (value.length() != 1)) { handleError(handler, XSLTErrorResources.INVALID_TCHAR, new Object[] {name, value},null); return null; } return avt; } catch (TransformerException te) { throw new org.xml.sax.SAXException(te); } } else { if (value.length() != 1) { handleError(handler, XSLTErrorResources.INVALID_TCHAR, new Object[] {name, value},null); return null; } return new Character(value.charAt(0)); } } /** * Process an attribute string of type T_ENUM into a int 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 represents an enumerated value that is * valid for this element. * @param owner * * @return An Integer representation of the enumerated value if this attribute does not support * AVT. Otherwise, and AVT is returned. */ Object processENUM(StylesheetHandler handler, String uri, String name, String rawName, String value, ElemTemplateElement owner) throws org.xml.sax.SAXException { AVT avt = null; if (getSupportsAVT()) { 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()) return avt; } catch (TransformerException te) { throw new org.xml.sax.SAXException(te); } } int retVal = this.getEnum(value); if (retVal == StringToIntTable.INVALID_KEY) { StringBuffer enumNamesList = getListOfEnums(); handleError(handler, XSLTErrorResources.INVALID_ENUM,new Object[]{name, value, enumNamesList.toString() },null); return null; } if (getSupportsAVT()) return avt; else return new Integer(retVal); } /** * Process an attribute string of that is either an enumerated value or a qname-but-not-ncname. * Returns an AVT, if this attribute support AVT; otherwise returns int or qname. * * @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 represents an enumerated value that is * valid for this element. * @param owner * * @return AVT if attribute supports AVT. An Integer representation of the enumerated value if * attribute does not support AVT and an enumerated value was used. Otherwise a qname * is returned. */ Object processENUM_OR_PQNAME(StylesheetHandler handler, String uri, String name, String rawName, String value, ElemTemplateElement owner) throws org.xml.sax.SAXException { Object objToReturn = null; if (getSupportsAVT()) { try { AVT avt = new AVT(handler, uri, name, rawName, value, owner); if (!avt.isSimple()) return avt; else objToReturn = avt; } catch (TransformerException te) { throw new org.xml.sax.SAXException(te); } } // An avt wasn't used. int enum = this.getEnum(value); if (enum != StringToIntTable.INVALID_KEY) { if (objToReturn == null) objToReturn = new Integer(enum); } // enum not used. Validate qname-but-not-ncname. else { try { QName qname = new QName(value, handler, true); if (objToReturn == null) objToReturn = qname; if (qname.getPrefix() == null) { StringBuffer enumNamesList = getListOfEnums(); enumNamesList.append(" <qname-but-not-ncname>"); handleError(handler,XSLTErrorResources.INVALID_ENUM,new Object[]{name, value, enumNamesList.toString() },null); return null; } } catch (IllegalArgumentException ie) { StringBuffer enumNamesList = getListOfEnums(); enumNamesList.append(" <qname-but-not-ncname>"); handleError(handler,XSLTErrorResources.INVALID_ENUM,new Object[]{name, value, enumNamesList.toString() },ie); return null; } catch (RuntimeException re) { StringBuffer enumNamesList = getListOfEnums(); enumNamesList.append(" <qname-but-not-ncname>"); handleError(handler,XSLTErrorResources.INVALID_ENUM,new Object[]{name, value, enumNamesList.toString() },re); return null; } } return objToReturn; } /** * Process an attribute string of type T_EXPR into * an XPath 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 An XSLT expression string. * * @return an XPath object that may be used for evaluation. * * @throws org.xml.sax.SAXException that wraps a * {@link javax.xml.transform.TransformerException} if the expression * string contains a syntax error. */ Object processEXPR( StylesheetHandler handler, String uri, String name, String rawName, String value, ElemTemplateElement owner) throws org.xml.sax.SAXException { try { XPath expr = handler.createXPath(value, owner); return expr; } catch (TransformerException te) { org.xml.sax.SAXException se = new org.xml.sax.SAXException(te); throw new org.xml.sax.SAXException(te); } } /** * Process an attribute string of type T_NMTOKEN into * a String 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 NMTOKEN string. * * @return the value argument or an AVT if this attribute supports AVTs. * * @throws org.xml.sax.SAXException if the value is not a valid nmtoken */ Object processNMTOKEN(StylesheetHandler handler, String uri, String name, String rawName, String value, ElemTemplateElement owner) throws org.xml.sax.SAXException { if (getSupportsAVT()) { try {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?