Search in sources :

Example 41 with NodeType

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

the class FnIDREF method processAttributes.

private static ResultBuffer processAttributes(Node node, List idrefs, ResultBuffer rs, EvaluationContext ec) {
    if (!node.hasAttributes()) {
        return rs;
    }
    NamedNodeMap attributeList = node.getAttributes();
    for (int atsub = 0; atsub < attributeList.getLength(); atsub++) {
        Attr atNode = (Attr) attributeList.item(atsub);
        NodeType atType = new AttrType(atNode, ec.getStaticContext().getTypeModel());
        if (atType.isID()) {
            if (hasID(idrefs, atNode)) {
                if (!isDuplicate(node, rs)) {
                    ElementType element = new ElementType((Element) node, ec.getStaticContext().getTypeModel());
                    rs.add(element);
                }
            }
        }
    }
    return rs;
}
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 42 with NodeType

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

the class FnNamespaceUri method namespace_uri.

/**
 * Namespace-Uri operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:namespace-uri operation.
 */
public static ResultSequence namespace_uri(Collection args, EvaluationContext context) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultSequence arg1 = null;
    if (cargs.isEmpty()) {
        if (context.getContextItem() == null) {
            throw DynamicError.contextUndefined();
        }
        arg1 = (AnyType) context.getContextItem();
    } else {
        // get arg
        arg1 = (ResultSequence) cargs.iterator().next();
    }
    if (arg1.empty()) {
        return new XSAnyURI("");
    }
    NodeType an = (NodeType) arg1.first();
    QName name = an.node_name();
    String sname = "";
    if (name != null)
        sname = name.namespace();
    return new XSAnyURI(sname);
}
Also used : XSAnyURI(org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI) 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)

Example 43 with NodeType

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

the class commaOpTest method test_op_concatenate_mix_args_019.

// Use an external variable with op:concatenate.
public void test_op_concatenate_mix_args_019() throws Exception {
    String inputFile = "/TestSources/bib.xml";
    String xqFile = "/Queries/XQuery/Expressions/Operators/SeqOp/SeqConcat/op-concatenate-mix-args-019.xq";
    String resultFile = "/ExpectedTestResults/Expressions/Operators/SeqOp/SeqConcat/op-concatenate-mix-args-019.txt";
    String expectedResult = getExpectedResult(resultFile);
    URL fileURL = bundle.getEntry(inputFile);
    loadDOMDocument(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = getGrammar();
    setupDynamicContext(schema);
    String xpath = extractXPathExpression(xqFile, inputFile);
    String actual = null;
    try {
        compileXPath(xpath);
        ResultSequence rs = evaluate(domDoc);
        actual = buildXMLResultString(rs);
    // Iterator<NodeType> iterator = rs.iterator();
    // while (iterator.hasNext()) {
    // AnyType aat = iterator.next();
    // if (!(aat instanceof NodeType)) {
    // actual += aat.string_value();
    // }
    // }
    } catch (XPathParserException ex) {
        actual = ex.code();
    } catch (StaticError ex) {
        actual = ex.code();
    } catch (DynamicError ex) {
        actual = ex.code();
    }
    assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual);
}
Also used : XPathParserException(org.eclipse.wst.xml.xpath2.processor.XPathParserException) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) XSModel(org.apache.xerces.xs.XSModel) StaticError(org.eclipse.wst.xml.xpath2.processor.StaticError) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) URL(java.net.URL)

Example 44 with NodeType

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

the class TestWTPDOMXPath2 method buildXMLResultString.

protected String buildXMLResultString(ResultSequence rs) throws Exception {
    Iterator iterator = rs.iterator();
    StringBuffer buffer = new StringBuffer();
    while (iterator.hasNext()) {
        AnyType aat = (AnyType) iterator.next();
        if (aat instanceof NodeType) {
            NodeType nodeType = (NodeType) aat;
            IDOMNode node = (IDOMNode) nodeType.node_value();
            buffer = buffer.append(node.getSource());
        } else {
            buffer = buffer.append(aat.string_value());
        }
    }
    return buffer.toString();
}
Also used : IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Iterator(java.util.Iterator) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 45 with NodeType

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

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