Search in sources :

Example 46 with ResultBuffer

use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.

the class FnCodepointEqual method codepoint_equals.

/**
 * Compare the arguments as codepoints
 *
 * @param args
 *            are compared.
 * @param dynamicContext
 *            The current dynamic context
 * @throws DynamicError
 *             Dynamic error.
 * @return The result of the comparison of the arguments.
 */
public static ResultSequence codepoint_equals(Collection args, DynamicContext dynamicContext) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultBuffer rs = new ResultBuffer();
    Iterator argiter = cargs.iterator();
    ResultSequence arg1 = (ResultSequence) argiter.next();
    XSString xstr1 = arg1.empty() ? null : (XSString) arg1.first();
    ResultSequence arg2 = (ResultSequence) argiter.next();
    XSString xstr2 = arg2.empty() ? null : (XSString) arg2.first();
    // This delegates to FnCompare
    BigInteger result = FnCompare.compare_string(CollationProvider.CODEPOINT_COLLATION, xstr1, xstr2, dynamicContext);
    if (result != null)
        rs.add(new XSBoolean(BigInteger.ZERO.equals(result)));
    return rs.getSequence();
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean) Iterator(java.util.Iterator) Collection(java.util.Collection) BigInteger(java.math.BigInteger) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 47 with ResultBuffer

use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.

the class FnConcat method concat.

/**
 * Concatenate the arguments.
 *
 * @param args
 *            are concatenated.
 * @throws DynamicError
 *             Dynamic error.
 * @return The result of the concatenation of the arguments.
 */
public static ResultSequence concat(Collection args) throws DynamicError {
    // sanity check
    if (args.size() < 2)
        DynamicError.throw_type_error();
    ResultBuffer rs = new ResultBuffer();
    String result = "";
    // go through args
    StringBuffer buf = new StringBuffer();
    for (Iterator argi = args.iterator(); argi.hasNext(); ) {
        ResultSequence arg = (ResultSequence) argi.next();
        int size = arg.size();
        // sanity check
        if (size > 1)
            DynamicError.throw_type_error();
        if (size == 0) {
            continue;
        }
        Item at = arg.first();
        buf.append(at.getStringValue());
    }
    result = buf.toString();
    rs.add(new XSString(result));
    return rs.getSequence();
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 48 with ResultBuffer

use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.

the class FnID method processAttributes.

private static void processAttributes(Node node, List idrefs, ResultBuffer rs, EvaluationContext context) {
    if (!node.hasAttributes()) {
        return;
    }
    NamedNodeMap attributeList = node.getAttributes();
    for (int atsub = 0; atsub < attributeList.getLength(); atsub++) {
        Attr atNode = (Attr) attributeList.item(atsub);
        NodeType atType = new AttrType(atNode, context.getStaticContext().getTypeModel());
        if (atType.isID()) {
            if (hasIDREF(idrefs, atNode)) {
                if (!isDuplicate(node, rs)) {
                    ElementType element = new ElementType((Element) node, context.getStaticContext().getTypeModel());
                    rs.add(element);
                }
            }
        }
    }
}
Also used : ElementType(org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType) NamedNodeMap(org.w3c.dom.NamedNodeMap) AttrType(org.eclipse.wst.xml.xpath2.processor.internal.types.AttrType) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Attr(org.w3c.dom.Attr)

Example 49 with ResultBuffer

use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.

the class NodeType method addAtomicListItemsToResultSet.

// getTypedValueForSimpleContent
/*
	 * If the variety of simpleType was 'list', add the typed "list item" values to the parent result set. 
	 */
private void addAtomicListItemsToResultSet(SimpleTypeDefinition simpType, List itemValueTypes, ResultBuffer rs) {
    // tokenize the string value by a 'longest sequence' of white-spaces. this gives us the list items as string values.
    String[] listItemsStrValues = getStringValue().split("\\s+");
    SimpleTypeDefinition itemType = (SimpleTypeDefinition) simpType.getItemType();
    if (itemType.getVariety() == SimpleTypeDefinition.VARIETY_ATOMIC) {
        for (int listItemIdx = 0; listItemIdx < listItemsStrValues.length; listItemIdx++) {
            // add an atomic typed value (whose type is the "item  type" of the list, and "string value" is the "string
            // value of the list item") to the "result sequence".
            rs.add(SchemaTypeValueFactory.newSchemaTypeValue(PsychoPathTypeHelper.getXSDTypeShortCode(itemType), listItemsStrValues[listItemIdx]));
        }
    } else if (itemType.getVariety() == SimpleTypeDefinition.VARIETY_UNION) {
        // here the list items may have different atomic types
        for (int listItemIdx = 0; listItemIdx < listItemsStrValues.length; listItemIdx++) {
            String listItem = listItemsStrValues[listItemIdx];
            rs.add(SchemaTypeValueFactory.newSchemaTypeValue(((Short) itemValueTypes.get(listItemIdx)).shortValue(), listItem));
        }
    }
}
Also used : SimpleTypeDefinition(org.eclipse.wst.xml.xpath2.api.typesystem.SimpleTypeDefinition)

Example 50 with ResultBuffer

use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.

the class NodeType method linarize.

public static ResultBuffer linarize(ResultBuffer rs) {
    TreeSet all = new TreeSet(NODE_COMPARATOR);
    all.addAll(rs.getCollection());
    return new ResultBuffer().concat(all);
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) TreeSet(java.util.TreeSet)

Aggregations

ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)40 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)31 Iterator (java.util.Iterator)26 NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)20 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)12 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)11 ElementType (org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType)10 ArrayList (java.util.ArrayList)9 Collection (java.util.Collection)9 Item (org.eclipse.wst.xml.xpath2.api.Item)8 Node (org.w3c.dom.Node)8 ListIterator (java.util.ListIterator)7 VarExprPair (org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)6 AnyAtomicType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)5 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)5 NodeList (org.w3c.dom.NodeList)5 List (java.util.List)4 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)4 NumericType (org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType)4 XSInteger (org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger)4