Search in sources :

Example 1 with Item

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

the class FnBaseUri method base_uri.

/**
 * Base-Uri operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param d_context
 * 			  Dynamic context
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:base-uri operation.
 */
public static ResultSequence base_uri(Collection args, EvaluationContext ec) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultSequence rs = null;
    if (cargs.size() == 0) {
        // support for arity 0
        // get base-uri from the context item.
        Item contextItem = ec.getContextItem();
        if (contextItem != null) {
            rs = getBaseUri(contextItem);
        } else {
            throw DynamicError.contextUndefined();
        }
    } else if (cargs.size() == 1) {
        // support for arity 1
        ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
        Item att = arg1.empty() ? null : arg1.first();
        rs = getBaseUri(att);
    } else {
        // arity other than 0 or 1 is not allowed
        throw DynamicError.throw_type_error();
    }
    return rs;
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Collection(java.util.Collection)

Example 2 with Item

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

the class FnBaseUri method getBaseUri.

/*
	 * Helper function for base-uri support
	 */
public static ResultSequence getBaseUri(Item att) {
    ResultBuffer rs = new ResultBuffer();
    XSAnyURI baseUri = null;
    if (att instanceof NodeType) {
        NodeType node = (NodeType) att;
        Node domNode = node.node_value();
        String buri = domNode.getBaseURI();
        if (buri != null) {
            baseUri = new XSAnyURI(buri);
        } else {
            baseUri = new XSAnyURI("null");
        }
    }
    if (baseUri != null) {
        rs.add(baseUri);
    }
    return rs.getSequence();
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) XSAnyURI(org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Node(org.w3c.dom.Node)

Example 3 with Item

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

the class FnInScopePrefixes method inScopePrefixes.

/**
 * Prefix-from-QName operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:prefix-from-QName operation.
 */
public static ResultSequence inScopePrefixes(Collection args, DynamicContext dc) throws DynamicError {
    // Collection cargs = Function.convert_arguments(args, expected_args());
    Collection cargs = args;
    ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
    if (arg1.empty())
        return ResultBuffer.EMPTY;
    ResultBuffer rs = new ResultBuffer();
    Item anytype = arg1.item(0);
    if (!(anytype instanceof ElementType)) {
        throw new DynamicError(TypeError.invalid_type(null));
    }
    ElementType element = (ElementType) anytype;
    List prefixList = lookupPrefixes(element);
    createPrefixResultSet(rs, prefixList);
    return rs.getSequence();
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ElementType(org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError)

Example 4 with Item

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

the class FnInsertBefore method insert_before.

/**
 * Insert-Before operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:insert-before operation.
 */
public static ResultSequence insert_before(Collection args) throws DynamicError {
    assert args.size() == 3;
    ResultBuffer rs = new ResultBuffer();
    // get args
    Iterator citer = args.iterator();
    ResultSequence target = (ResultSequence) citer.next();
    ResultSequence arg2 = (ResultSequence) citer.next();
    ResultSequence inserts = (ResultSequence) citer.next();
    // sanity chex
    if (arg2.size() != 1)
        DynamicError.throw_type_error();
    Item at = arg2.first();
    if (!(at instanceof XSInteger))
        DynamicError.throw_type_error();
    // XXX cloning!
    if (target.empty())
        return inserts;
    if (inserts.empty())
        return target;
    int position = ((XSInteger) at).int_value().intValue();
    if (position < 1)
        position = 1;
    int target_size = target.size();
    if (position > target_size)
        position = target_size + 1;
    int curpos = 1;
    for (Iterator i = target.iterator(); i.hasNext(); ) {
        at = (AnyType) i.next();
        if (curpos == position)
            rs.concat(inserts);
        rs.add(at);
        curpos++;
    }
    if (curpos == position)
        rs.concat(inserts);
    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) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Iterator(java.util.Iterator)

Example 5 with Item

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

the class FsPlus method fs_plus_unary.

/**
 * Unary operation on the arguments.
 *
 * @param args
 *            input arguments.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of the operation.
 */
public static ResultSequence fs_plus_unary(Collection args) throws DynamicError {
    // make sure we got only one arg
    if (args.size() != 1)
        DynamicError.throw_type_error();
    ResultSequence arg = (ResultSequence) args.iterator().next();
    // make sure we got only one numeric atom
    if (arg.size() != 1)
        DynamicError.throw_type_error();
    Item at = arg.first();
    if (!(at instanceof NumericType))
        DynamicError.throw_type_error();
    // no-op
    return arg;
}
Also used : NumericType(org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType) Item(org.eclipse.wst.xml.xpath2.api.Item) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence)

Aggregations

DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)71 Item (org.eclipse.wst.xml.xpath2.api.Item)69 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)66 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)65 URL (java.net.URL)64 XSModel (org.apache.xerces.xs.XSModel)64 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)64 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)46 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)34 Iterator (java.util.Iterator)26 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)14 BigInteger (java.math.BigInteger)13 Collection (java.util.Collection)13 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)11 ListIterator (java.util.ListIterator)8 NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)8 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)6 NumericType (org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType)5 ArrayList (java.util.ArrayList)4 GregorianCalendar (java.util.GregorianCalendar)4