Search in sources :

Example 1 with NodeType

use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType 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 2 with NodeType

use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType in project webtools.sourceediting by eclipse.

the class FnLang method lang.

/**
 * Language operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:lang operation.
 */
public static ResultSequence lang(Collection args, EvaluationContext ec) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    // get arg
    Iterator citer = cargs.iterator();
    ResultSequence arg1 = (ResultSequence) citer.next();
    ResultSequence arg2 = null;
    if (cargs.size() == 1) {
        if (ec.getContextItem() == null) {
            throw DynamicError.contextUndefined();
        }
        arg2 = (AnyType) ec.getContextItem();
    } else {
        arg2 = (ResultSequence) citer.next();
    }
    String lang = "";
    if (!arg1.empty()) {
        lang = ((XSString) arg1.first()).value();
    }
    if (!(arg2.first() instanceof NodeType)) {
        throw DynamicError.invalidType();
    }
    NodeType an = (NodeType) arg2.first();
    return new XSBoolean(test_lang(an.node_value(), lang));
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Iterator(java.util.Iterator) Collection(java.util.Collection) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 3 with NodeType

use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType in project webtools.sourceediting by eclipse.

the class FnName method name.

/**
 * Name operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param context
 *            Dynamic context.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:name operation.
 */
public static ResultSequence name(Collection args, EvaluationContext ec) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    // get arg
    ResultSequence arg1 = null;
    if (cargs.isEmpty()) {
        if (ec.getContextItem() == null)
            throw DynamicError.contextUndefined();
        else {
            arg1 = ResultBuffer.wrap(ec.getContextItem());
        }
    } else {
        arg1 = (ResultSequence) cargs.iterator().next();
    }
    if (arg1.empty()) {
        return new XSString("");
    }
    NodeType an = (NodeType) arg1.first();
    QName name = an.node_name();
    String sname = "";
    if (name != null)
        sname = name.getStringValue();
    return new XSString(sname);
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Collection(java.util.Collection) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 4 with NodeType

use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType in project webtools.sourceediting by eclipse.

the class FnNilled method nilled.

/**
 * Nilled operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:nilled operation.
 */
public static ResultSequence nilled(Collection args) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
    if (arg1.empty()) {
        return arg1;
    }
    NodeType nt = (NodeType) arg1.first();
    return nt.nilled();
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Collection(java.util.Collection)

Example 5 with NodeType

use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType in project webtools.sourceediting by eclipse.

the class FnID method id.

/**
 * Insert-Before operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:insert-before operation.
 */
public static ResultSequence id(Collection args, EvaluationContext context) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultBuffer rs = new ResultBuffer();
    Iterator argIt = cargs.iterator();
    ResultSequence idrefRS = (ResultSequence) argIt.next();
    String[] idrefst = idrefRS.first().getStringValue().split(" ");
    ArrayList idrefs = createIDRefs(idrefst);
    ResultSequence nodeArg = null;
    NodeType nodeType = null;
    if (argIt.hasNext()) {
        nodeArg = (ResultSequence) argIt.next();
        nodeType = (NodeType) nodeArg.first();
    } else {
        if (context.getContextItem() == null) {
            throw DynamicError.contextUndefined();
        }
        if (!(context.getContextItem() instanceof NodeType)) {
            throw new DynamicError(TypeError.invalid_type(null));
        }
        nodeType = (NodeType) context.getContextItem();
        if (nodeType.node_value().getOwnerDocument() == null) {
            throw DynamicError.contextUndefined();
        }
    }
    Node node = nodeType.node_value();
    if (node.getOwnerDocument() == null) {
        // W3C Test suite seems to want XPDY0002
        throw DynamicError.contextUndefined();
    // throw DynamicError.noContextDoc();
    }
    if (hasIDREF(idrefs, node)) {
        ElementType element = new ElementType((Element) node, context.getStaticContext().getTypeModel());
        rs.add(element);
    }
    processAttributes(node, idrefs, rs, context);
    processChildNodes(node, idrefs, rs, context);
    return rs.getSequence();
}
Also used : 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) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Node(org.w3c.dom.Node) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) Collection(java.util.Collection) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError)

Aggregations

NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)39 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)23 Iterator (java.util.Iterator)21 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)15 Collection (java.util.Collection)12 Node (org.w3c.dom.Node)12 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)11 ListIterator (java.util.ListIterator)10 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)9 ElementType (org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType)9 VarExprPair (org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)7 TypeDefinition (org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)6 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)5 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)5 ArrayList (java.util.ArrayList)4 Attr (org.w3c.dom.Attr)4 ForwardAxis (org.eclipse.wst.xml.xpath2.processor.internal.ForwardAxis)3 ParentAxis (org.eclipse.wst.xml.xpath2.processor.internal.ParentAxis)3 ReverseAxis (org.eclipse.wst.xml.xpath2.processor.internal.ReverseAxis)3 AttrType (org.eclipse.wst.xml.xpath2.processor.internal.types.AttrType)3