Search in sources :

Example 6 with AVT

use of org.apache.xalan.templates.AVT in project j2objc by google.

the class XSLTAttributeDef method processAVT_QNAME.

/**
   * 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 (!XML11Char.isXML11ValidNCName(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) || (!XML11Char.isXML11ValidNCName(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;
}
Also used : TransformerException(javax.xml.transform.TransformerException) AVT(org.apache.xalan.templates.AVT)

Example 7 with AVT

use of org.apache.xalan.templates.AVT in project j2objc by google.

the class XSLTAttributeDef method processENUM_OR_PQNAME.

/**
   * 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 key = this.getEnum(value);
    if (key != StringToIntTable.INVALID_KEY) {
        if (objToReturn == null)
            objToReturn = new Integer(key);
    } else // enum not used.  Validate qname-but-not-ncname.
    {
        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;
}
Also used : QName(org.apache.xml.utils.QName) TransformerException(javax.xml.transform.TransformerException) AVT(org.apache.xalan.templates.AVT)

Example 8 with AVT

use of org.apache.xalan.templates.AVT in project j2objc by google.

the class XSLTAttributeDef method processNUMBER.

/**
   * 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;
        }
    }
}
Also used : TransformerException(javax.xml.transform.TransformerException) AVT(org.apache.xalan.templates.AVT)

Example 9 with AVT

use of org.apache.xalan.templates.AVT in project robovm by robovm.

the class XSLTAttributeDef method processAVT_QNAME.

/**
   * 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 (!XML11Char.isXML11ValidNCName(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) || (!XML11Char.isXML11ValidNCName(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;
}
Also used : TransformerException(javax.xml.transform.TransformerException) AVT(org.apache.xalan.templates.AVT)

Example 10 with AVT

use of org.apache.xalan.templates.AVT in project robovm by robovm.

the class TransformerImpl method processSortKeys.

/**
   * Get the keys for the xsl:sort elements.
   * Note: Should this go into ElemForEach?
   *
   * @param foreach Valid ElemForEach element, not null.
   * @param sourceNodeContext The current node context in the source tree,
   * needed to evaluate the Attribute Value Templates.
   *
   * @return A Vector of NodeSortKeys, or null.
   *
   * @throws TransformerException
   * @xsl.usage advanced
   */
public Vector processSortKeys(ElemForEach foreach, int sourceNodeContext) throws TransformerException {
    Vector keys = null;
    XPathContext xctxt = m_xcontext;
    int nElems = foreach.getSortElemCount();
    if (nElems > 0)
        keys = new Vector();
    // March backwards, collecting the sort keys.
    for (int i = 0; i < nElems; i++) {
        ElemSort sort = foreach.getSortElem(i);
        String langString = (null != sort.getLang()) ? sort.getLang().evaluate(xctxt, sourceNodeContext, foreach) : null;
        String dataTypeString = sort.getDataType().evaluate(xctxt, sourceNodeContext, foreach);
        if (dataTypeString.indexOf(":") >= 0)
            System.out.println("TODO: Need to write the hooks for QNAME sort data type");
        else if (!(dataTypeString.equalsIgnoreCase(Constants.ATTRVAL_DATATYPE_TEXT)) && !(dataTypeString.equalsIgnoreCase(Constants.ATTRVAL_DATATYPE_NUMBER)))
            foreach.error(XSLTErrorResources.ER_ILLEGAL_ATTRIBUTE_VALUE, new Object[] { Constants.ATTRNAME_DATATYPE, dataTypeString });
        boolean treatAsNumbers = ((null != dataTypeString) && dataTypeString.equals(Constants.ATTRVAL_DATATYPE_NUMBER)) ? true : false;
        String orderString = sort.getOrder().evaluate(xctxt, sourceNodeContext, foreach);
        if (!(orderString.equalsIgnoreCase(Constants.ATTRVAL_ORDER_ASCENDING)) && !(orderString.equalsIgnoreCase(Constants.ATTRVAL_ORDER_DESCENDING)))
            foreach.error(XSLTErrorResources.ER_ILLEGAL_ATTRIBUTE_VALUE, new Object[] { Constants.ATTRNAME_ORDER, orderString });
        boolean descending = ((null != orderString) && orderString.equals(Constants.ATTRVAL_ORDER_DESCENDING)) ? true : false;
        AVT caseOrder = sort.getCaseOrder();
        boolean caseOrderUpper;
        if (null != caseOrder) {
            String caseOrderString = caseOrder.evaluate(xctxt, sourceNodeContext, foreach);
            if (!(caseOrderString.equalsIgnoreCase(Constants.ATTRVAL_CASEORDER_UPPER)) && !(caseOrderString.equalsIgnoreCase(Constants.ATTRVAL_CASEORDER_LOWER)))
                foreach.error(XSLTErrorResources.ER_ILLEGAL_ATTRIBUTE_VALUE, new Object[] { Constants.ATTRNAME_CASEORDER, caseOrderString });
            caseOrderUpper = ((null != caseOrderString) && caseOrderString.equals(Constants.ATTRVAL_CASEORDER_UPPER)) ? true : false;
        } else {
            caseOrderUpper = false;
        }
        keys.addElement(new NodeSortKey(this, sort.getSelect(), treatAsNumbers, descending, langString, caseOrderUpper, foreach));
    }
    return keys;
}
Also used : XPathContext(org.apache.xpath.XPathContext) XObject(org.apache.xpath.objects.XObject) Vector(java.util.Vector) NodeVector(org.apache.xml.utils.NodeVector) ElemSort(org.apache.xalan.templates.ElemSort) AVT(org.apache.xalan.templates.AVT)

Aggregations

AVT (org.apache.xalan.templates.AVT)10 TransformerException (javax.xml.transform.TransformerException)8 Vector (java.util.Vector)2 ElemSort (org.apache.xalan.templates.ElemSort)2 NodeVector (org.apache.xml.utils.NodeVector)2 QName (org.apache.xml.utils.QName)2 XPathContext (org.apache.xpath.XPathContext)2 XObject (org.apache.xpath.objects.XObject)2