Package org.w3c.dom

Examples of org.w3c.dom.Node


  /// @return next sibling or <code>null</code> if there is no such node.
  ///    Next sibling is child of this node's parent that is immediately
  ///    next to this node.
  public Any m_getNextSibling()
  {
    Node sibling = _node.getNextSibling();
    return (sibling != null) ? new AnyNode(sibling) : NULL;
  }
View Full Code Here


  /// @return next sibling or <code>null</code> if there is no such node.
  ///    Previous sibling is child of this node's parent that is immediately
  ///    next to this node.
  public Any m_getPreviousSibling()
  {
    Node sibling = _node.getPreviousSibling();
    return (sibling != null) ? new AnyNode(sibling) : NULL;
  }
View Full Code Here

  /// Gets the root element.
  /// @synopsis Node getRootNode()
  /// @return the root node of document where this node belongs to
  public Any m_getRootNode()
  {
    Node root = null;
    if (_type == Node.DOCUMENT_NODE) {
      root = ((Document)_node).getDocumentElement();
    } else {
      Document doc = _node.getOwnerDocument();
      if (doc != null) {
View Full Code Here

    if (_type == Node.DOCUMENT_TYPE_NODE) {
      NamedNodeMap map = ((DocumentType)_node).getEntities();
      int length = map.getLength();
      Array entities = new Array(length);
      for(int i=0; i<length; i++) {
        Node entity = map.item(i);
        if (entity.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
          entities.append(((DocumentType)entity).getName(), new AnyNode(entity));
        }
      }
      return entities;
    } else {
View Full Code Here

    if (_type == Node.DOCUMENT_TYPE_NODE) {
      NamedNodeMap map = ((DocumentType)_node).getNotations();
      int length = map.getLength();
      Array notations = new Array(length);
      for(int i=0; i<length; i++) {
        Node entity = map.item(i);
        if (entity.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
          notations.append(((DocumentType)entity).getName(), new AnyNode(entity));
        }
      }
      return notations;
    } else {
View Full Code Here

        service.appendChild(textnode(doc, "Fees", "none"));
        service.appendChild(textnode(doc, "AccessConstraints", "none"));
        root.appendChild(service);

        Node capability = doc.createElement("Capability");
        Element request = doc.createElement("Request");

        request.appendChild(requestcap(doc, WMTConstants.GETCAPABILITIES, formatsList[FMT_GETCAPS], "Get",
                onlineResourcesList[FMT_GETCAPS]));
        request.appendChild(requestcap(doc, WMTConstants.GETMAP, formatsList[FMT_GETMAP], "Get",
                onlineResourcesList[FMT_GETMAP]));
        request.appendChild(requestcap(doc, WMTConstants.GETFEATUREINFO, formatsList[FMT_GETFEATUREINFO],
                "Get", onlineResourcesList[FMT_GETFEATUREINFO]));
        capability.appendChild(request);

        Element exceptionElement = doc.createElement("Exception");
        for (int i = 0; i < formatsList[FMT_EXCEPTIONS].size(); i++) {
            exceptionElement.appendChild(textnode(doc, "Format", (String) formatsList[FMT_EXCEPTIONS].get(i)));
        }
        capability.appendChild(exceptionElement);

        capability.appendChild(createLayersElement(doc));
        root.appendChild(capability);

        return doc;
    }
View Full Code Here

    private Node textnode(Document doc, String Name, String text) {
        Element e1 = doc.createElement(Name);
        if (text == null) {
            text = "";
        }
        Node n = doc.createTextNode(text);
        e1.appendChild(n);
        return e1;
    }
View Full Code Here

            collectionID = null;
            primaryDir = null;
            extendedDirs = new LinkedList();
            currentDir = null;

            Node node = nodeList.item(i);
            collectionID = node.getAttributes().getNamedItem(COLLECTION_ID).getNodeValue();
            primaryDir = node.getAttributes().getNamedItem(PRIMARY_DIRECTORY).getNodeValue();
            currentDir = node.getAttributes().getNamedItem(CURRENT_DIRECTORY).getNodeValue();
            childNodes = node.getChildNodes();

            for (int j = 0; j < childNodes.getLength(); j++) {

                Node childNode = childNodes.item(j);
                if (childNode.getNodeType() == Node.ELEMENT_NODE) {
                    extendedPath = childNode.getAttributes().getNamedItem(EXTENDED_PATH).getNodeValue();
                    extendedDirs.addLast(extendedPath);
                }
            }
            colStorage = new CollectionStorage(primaryDir, extendedDirs, currentDir);
            colStorageMap.put(new Integer(collectionID), colStorage);
View Full Code Here

            }
           
            Document document = getDocument(s);
               
            XPath xpath = XPathFactory.newInstance().newXPath();
            Node node = (Node) xpath.evaluate("/html/body", document, XPathConstants.NODE);

            String text = node.getTextContent();
           
            while (text.length() > 1 && (text.startsWith("\r") || text.startsWith("\n")))
                text = text.substring(1);

            while (text.length() > 1 && (text.endsWith("\r") || text.endsWith("\n")))
View Full Code Here

                    println("\n------------------------------------------------");
                }
                final StaticContext statEnv = new StaticContext();
                statEnv.setConstructionModeStrip(true);

                Node testCase = rs.item(i);
                final String testName = xpath.evaluate("./@name", testCase);
                final String testFilePath = xpath.evaluate("./@FilePath", testCase);
                final String queryFileName = xpath.evaluate("./*[local-name()='query']/@name", testCase);
                File queryFile = new File(xqtsQueryPath, testFilePath + queryFileName + ".xq");
                final URI baseUri = new File(xqtsQueryPath, testFilePath).toURI();

                XQueryModule xqmod = new XQueryModule();

                {// ((//*:test-group)//*:test-case)/*:module
                    NodeList moduleNodes = (NodeList) xpath.evaluate("./*[local-name()='module']", testCase, XPathConstants.NODESET);
                    final int modcount = moduleNodes.getLength();
                    if(modcount > 0) {
                        ModuleManager moduleManager = statEnv.getModuleManager();
                        SimpleModuleResolver modResolver = new SimpleModuleResolver();
                        moduleManager.setModuleResolver(modResolver);
                        for(int j = 0; j < modcount; j++) {
                            Node moduleNode = moduleNodes.item(j);
                            String moduleId = moduleNode.getTextContent();
                            String moduleFileStr = xpath.evaluate("/*[local-name()='test-suite']/*[local-name()='sources']/*[local-name()='module']/@FileName[../@ID='"
                                    + moduleId + "']", catalog);
                            File moduleFile = new File(xqtsDir, moduleFileStr + ".xq");
                            String physical = moduleFile.toURI().toString();
                            String logical = xpath.evaluate("./@namespace", moduleNode);
                            modResolver.addMappingRule(logical, physical);
                        }
                    }
                }
                {// ((//*:test-group)//*:test-case)/*:input-file
                    NodeList vars1 = (NodeList) xpath.evaluate("./*[local-name()='input-file']/@variable", testCase, XPathConstants.NODESET);
                    loadVariables(vars1, testCase, xqmod, statEnv, xpath, catalog, false);
                }
                { // ((//*:test-group)//*:test-case)/*:input-URI
                    NodeList vars2 = (NodeList) xpath.evaluate("./*[local-name()='input-URI']/@variable", testCase, XPathConstants.NODESET);
                    loadVariables(vars2, testCase, xqmod, statEnv, xpath, catalog, true);
                }
                {// ((//*:test-group)//*:test-case)/*:defaultCollection
                    String colId = xpath.evaluate("./*[local-name()='defaultCollection']/text()", testCase);
                    if(colId != null) {
                        NodeList list = (NodeList) xpath.evaluate("/*[local-name()='test-suite']/*[local-name()='sources']/*[local-name()='collection'][@ID='"
                                + colId + "']/*[local-name()='input-document']/text()", catalog, XPathConstants.NODESET);
                        final int listlen = list.getLength();
                        if(listlen > 0) {
                            final Map<String, DTMDocument> defaultCollectionMap = new HashMap<String, DTMDocument>(listlen);
                            for(int j = 0; j < listlen; j++) {
                                String name = list.item(j).getTextContent();
                                String docName = name + ".xml";
                                DTMDocument testDataDoc = _docCache.get(name);
                                if(testDataDoc == null) {
                                    File testDataFile = new File(xqtsDir, docName);
                                    DocumentTableModel dtm = new DocumentTableModel(false);
                                    dtm.loadDocument(new FileInputStream(testDataFile));
                                    testDataDoc = dtm.documentNode();
                                    _docCache.put(name, testDataDoc);
                                }
                                defaultCollectionMap.put(docName, testDataDoc);
                                // import namespace decl
                                Map<String, String> nsmap = testDataDoc.documentTable().getDeclaredNamespaces();
                                NamespaceBinder nsResolver = statEnv.getStaticalyKnownNamespaces();
                                nsResolver.declarePrefixs(nsmap);
                            }
                            statEnv.setDefaultCollection(defaultCollectionMap);
                        }
                    }
                }
                Sequence<? extends Item> contextItem = null;
                {// ((//*:test-group)//*:test-case)/*:contextItem
                    String contextItemRef = xpath.evaluate("./*[local-name()='contextItem']/text()", testCase);
                    if(contextItemRef != null && contextItemRef.length() > 0) {
                        String contextItemFileRef = xpath.evaluate("/*[local-name()='test-suite']/*[local-name()='sources']/*[local-name()='source']/@FileName[../@ID='"
                                + contextItemRef + "']", catalog);
                        DTMDocument contextItemDoc = _docCache.get(contextItemRef);
                        if(contextItemDoc == null) {
                            File contextItemFile = new File(xqtsDir, contextItemFileRef);
                            DocumentTableModel dtm = new DocumentTableModel(false);
                            dtm.loadDocument(new FileInputStream(contextItemFile));
                            contextItemDoc = dtm.documentNode();
                            _docCache.put(contextItemRef, contextItemDoc);
                        }
                        contextItem = contextItemDoc;
                    }
                }
                {// ((//*:test-group)//*:test-case)/*:input-query
                    String inputVarName = xpath.evaluate("./*[local-name()='input-query']/@variable", testCase);
                    if(inputVarName != null && inputVarName.length() > 0) {
                        String dateData = xpath.evaluate("./*[local-name()='input-query']/@date", testCase);
                        assert (dateData != null) : dateData;
                        QualifiedName varName = QNameTable.instantiate(XMLConstants.DEFAULT_NS_PREFIX, inputVarName);
                        Variable var = new Variable.GlobalVariable(varName, null);
                        var.setResult(new DateTimeValue(dateData, DateType.DATE));
                        xqmod.putVariable(varName, var);
                    }
                }

                // -----------------------------------------------------------
                // #1 execute
                final String resString;
                {
                    final String query = IOUtils.toString(new FileInputStream(queryFile), "UTF-8");
                    if(doPrint) {
                        println("Query: ");
                        println(query);
                    }
                    final NodeList expectedErrors = (NodeList) xpath.evaluate("./*[local-name()='expected-error']", testCase, XPathConstants.NODESET);
                    {
                        XQueryProcessor proc = new XQueryProcessor(xqmod);
                        proc.setStaticContext(statEnv);
                        if(contextItem != null) {
                            proc.setContextItem(contextItem);
                        }
                        final StringWriter res_sw = new StringWriter();
                        try {
                            XQueryModule mod = proc.parse(query, baseUri);
                            Sequence result = proc.execute(mod);
                            SAXWriter saxwriter = new SAXWriter(res_sw, SAXWriter.DEFAULT_ENCODING);
                            saxwriter.setXMLDeclaration(false);
                            Serializer ser = new SAXSerializer(saxwriter, res_sw);
                            ser.emit(result);
                        } catch (Throwable ex) {
                            final int errors = expectedErrors.getLength();
                            if(errors == 0) {
                                final Node expectedOutputs = (Node) xpath.evaluate("./*[local-name()='output-file'][last()]", testCase, XPathConstants.NODE);
                                assert (expectedOutputs != null);
                                final Element output = (Element) expectedOutputs;
                                final String expFileName = output.getTextContent();
                                final File testFileDir = new File(xqtsResultPath, testFilePath);
                                String expectedResult = _expectedResultStrCache.get(expFileName);
                                if(expectedResult == null) {
                                    File expected = new File(testFileDir, expFileName);
                                    expectedResult = IOUtils.toString(new FileInputStream(expected));
                                    _expectedResultStrCache.put(expFileName, expectedResult);
                                }
                                if(doPrint) {
                                    println("Expected Result: ");
                                    println(expectedResult);
                                }
                                final String compareForm = output.getAttribute("compare");
                                final String errmsg;
                                if("Ignore".equals(compareForm)) {
                                    errmsg = "Unexpected exception: \n" + PrintUtils.getMessage(ex);
                                    String smallerrmsg = "Unexpected exception: "
                                            + PrintUtils.prettyPrintStackTrace(ex);
                                    reportTestResult(testName, "fail", smallerrmsg);
                                } else if("Inspect".equals(compareForm)) {
                                    errmsg = "Inspectection is required, got exception: \n"
                                            + PrintUtils.prettyPrintStackTrace(ex);
                                    String smallerrmsg = "Inspectection is required, got exception: "
                                            + PrintUtils.getOneLineMessage(ex);
                                    reportTestResult(testName, "not tested", smallerrmsg);
                                } else {
                                    errmsg = (expectedResult == null) ? "No result"
                                            : ('\'' + expectedResult + '\'')
                                                    + " is expected, but caused following exception: \n"
                                                    + PrintUtils.prettyPrintStackTrace(ex);
                                    String smallerrmsg = (expectedResult == null) ? "No result"
                                            : ('\'' + expectedResult + '\'')
                                                    + " is expected, but caused following exception: "
                                                    + PrintUtils.getOneLineMessage(ex);
                                    reportTestResult(testName, "fail", smallerrmsg);
                                }
                                Assert.fail(errmsg);
                            } else {
                                String errMsg = ex.getMessage();
                                if(errMsg == null) {
                                    errMsg = PrintUtils.getOneLineMessage(ex);
                                }
                                final int lastei = errors - 1;
                                for(int ei = 0; ei < errors; ei++) {
                                    final String expectedError = expectedErrors.item(ei).getTextContent();
                                    final boolean contain = (errMsg == null) ? false
                                            : errMsg.contains(expectedError);
                                    if(contain) {
                                        reportTestResult(testName, "pass", null);
                                        break;
                                    } else {
                                        final String msg = "Expected-error: " + expectedError
                                                + ", Actual Error: " + errMsg;
                                        if(!(ex instanceof XQueryException || ex instanceof XQRTException)) {
                                            reportTestResult(testName, "fail", msg);
                                            ex.printStackTrace();
                                            Assert.fail(msg);
                                        } else {
                                            if(ei == lastei) {
                                                final String passmsg = "Expected-error: "
                                                        + expectedError + ", Actual Error: "
                                                        + getErrCode(ex);
                                                reportTestResult(testName, "fail", passmsg);
                                                ex.printStackTrace();
                                                Assert.fail(msg);
                                            }
                                        }
                                    }
                                }
                                return;
                            }
                        }
                        resString = res_sw.toString();
                        if(doPrint) {
                            println("\nActual Result: ");
                            println(resString);
                        }
                    }
                    final int errors = expectedErrors.getLength();
                    if(errors > 0) {
                        final StringBuilder buf = new StringBuilder(256);
                        for(int ei = 0; ei < errors; ei++) {
                            if(ei != 0) {
                                buf.append(" or ");
                            }
                            final String expectedError = expectedErrors.item(ei).getTextContent();
                            buf.append(expectedError);
                        }
                        buf.append(" is expected, but was ..\n");
                        buf.append(resString);
                        Assert.fail(buf.toString());
                    }
                }

                // -----------------------------------------------------------
                // #2 probe
                {
                    NodeList expectedOutputs = (NodeList) xpath.evaluate("./*[local-name()='output-file']", testCase, XPathConstants.NODESET);
                    final int expectedOuts = expectedOutputs.getLength();
                    if(expectedOuts == 0) {
                        Assert.fail("Expected condition is not found in '" + testName + '\'');
                    }
                    final File testFileDir = new File(xqtsResultPath, testFilePath);
                    final int lastoi = expectedOuts - 1;
                    for(int oi = 0; oi <= lastoi; oi++) {
                        final Element output = (Element) expectedOutputs.item(oi);
                        final String expFileName = output.getTextContent();
                        String expectedStr = _expectedResultStrCache.get(expFileName);
                        if(expectedStr == null) {
                            File expected = new File(testFileDir, expFileName);
                            expectedStr = IOUtils.toString(new FileInputStream(expected), "UTF-8");
View Full Code Here

TOP

Related Classes of org.w3c.dom.Node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.