Search in sources :

Example 1 with ElemSort

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

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)

Example 2 with ElemSort

use of org.apache.xalan.templates.ElemSort 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

Vector (java.util.Vector)2 AVT (org.apache.xalan.templates.AVT)2 ElemSort (org.apache.xalan.templates.ElemSort)2 NodeVector (org.apache.xml.utils.NodeVector)2 XPathContext (org.apache.xpath.XPathContext)2 XObject (org.apache.xpath.objects.XObject)2