Search in sources :

Example 36 with NodeType

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

the class ParentAxis method iterate.

/**
 * returns parent accessors of the context node
 *
 * @param node
 *            is the node type.
 * @throws dc
 *             is the Dynamic context.
 */
public void iterate(NodeType node, ResultBuffer copyInto, Node limitNode) {
    Node n = node.node_value();
    if (limitNode != null && limitNode.isSameNode(n)) {
        // no further, we have reached the limit node
        return;
    }
    Node parent = findParent(n);
    // if a parent exists... add it
    if (parent != null) {
        NodeType nodeType = NodeType.dom_to_xpath(parent, node.getTypeModel());
        if (nodeType != null) {
            copyInto.add(nodeType);
        }
    }
}
Also used : Node(org.w3c.dom.Node) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)

Example 37 with NodeType

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

the class AbstractPsychoPathTest method buildXMLResultString.

protected String buildXMLResultString(ResultSequence rs) throws Exception {
    DOMImplementationLS domLS = (DOMImplementationLS) domDoc.getImplementation().getFeature("LS", "3.0");
    LSOutput outputText = domLS.createLSOutput();
    LSSerializer serializer = null;
    ClassLoader originalLoader = Thread.currentThread().getContextClassLoader();
    DelegatingLoader newContext = new DelegatingLoader(originalLoader);
    Thread.currentThread().setContextClassLoader(newContext);
    try {
        serializer = domLS.createLSSerializer();
    } finally {
        Thread.currentThread().setContextClassLoader(originalLoader);
    }
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    outputText.setByteStream(outputStream);
    String actual = new String();
    Iterator iterator = rs.iterator();
    boolean queueSpace = false;
    while (iterator.hasNext()) {
        AnyType aat = (AnyType) iterator.next();
        if (aat instanceof NodeType) {
            NodeType nodeType = (NodeType) aat;
            Node node = nodeType.node_value();
            serializer.write(node, outputText);
            queueSpace = false;
        } else {
            if (queueSpace)
                outputText.getByteStream().write(32);
            outputText.getByteStream().write(aat.getStringValue().getBytes("UTF-8"));
            queueSpace = true;
        }
    }
    actual = outputStream.toString("UTF-8");
    actual = actual.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "");
    actual = actual.replace("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>", "");
    outputStream.close();
    return actual.trim();
}
Also used : DOMImplementationLS(org.w3c.dom.ls.DOMImplementationLS) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Node(org.w3c.dom.Node) Iterator(java.util.Iterator) LSSerializer(org.w3c.dom.ls.LSSerializer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LSOutput(org.w3c.dom.ls.LSOutput) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 38 with NodeType

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

the class FnLocalName method local_name.

/**
 * Local-Name operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:local-name operation.
 */
public static ResultSequence local_name(Collection args, EvaluationContext context) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    // get arg
    ResultSequence arg1 = null;
    if (cargs.isEmpty()) {
        if (context.getContextItem() == null)
            throw DynamicError.contextUndefined();
        else {
            arg1 = (AnyType) context.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.local();
    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 39 with NodeType

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

the class FnDocumentUri method document_uri.

/**
 * Document-Uri operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:document-uri operation.
 */
public static ResultSequence document_uri(Collection args) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
    if (arg1.empty())
        return ResultBuffer.EMPTY;
    NodeType nt = (NodeType) arg1.first();
    if (!(nt instanceof DocType))
        return ResultBuffer.EMPTY;
    DocType dt = (DocType) nt;
    String documentURI = dt.value().getDocumentURI();
    if (documentURI != null) {
        XSAnyURI docUri = new XSAnyURI(documentURI);
        return docUri;
    }
    return ResultBuffer.EMPTY;
}
Also used : XSAnyURI(org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Collection(java.util.Collection) DocType(org.eclipse.wst.xml.xpath2.processor.internal.types.DocType)

Example 40 with NodeType

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

the class FnIDREF method idref.

/**
 * Insert-Before operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param dc
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:insert-before operation.
 */
public static ResultSequence idref(Collection args, EvaluationContext ec) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultBuffer rs = new ResultBuffer();
    Iterator argIt = cargs.iterator();
    ResultSequence idrefRS = (ResultSequence) argIt.next();
    String[] idst = idrefRS.first().getStringValue().split(" ");
    ArrayList ids = createIDs(idst);
    ResultSequence nodeArg = null;
    NodeType nodeType = null;
    if (argIt.hasNext()) {
        nodeArg = (ResultSequence) argIt.next();
        nodeType = (NodeType) nodeArg.first();
    } else {
        if (ec.getContextItem() == null) {
            throw DynamicError.contextUndefined();
        }
        if (!(ec.getContextItem() instanceof NodeType)) {
            throw new DynamicError(TypeError.invalid_type(null));
        }
        nodeType = (NodeType) ec.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 here
        throw DynamicError.contextUndefined();
    // throw DynamicError.noContextDoc();
    }
    if (hasID(ids, node)) {
        ElementType element = new ElementType((Element) node, ec.getStaticContext().getTypeModel());
        rs.add(element);
    }
    rs = processAttributes(node, ids, rs, ec);
    rs = processChildNodes(node, ids, rs, ec);
    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