Package xbird.util.xml

Examples of xbird.util.xml.NamespaceBinder


    public BXQStaticContext(StaticContext statEnv) {
        this.statEnv_ = statEnv;
    }

    public void declareNamespace(String prefix, String uri) throws XQException {
        final NamespaceBinder nsmap = statEnv_.getStaticalyKnownNamespaces();
        nsmap.declarePrefix(prefix, uri);
    }
View Full Code Here


    public int getHoldability() {
        return _holdability;
    }

    public String[] getNamespacePrefixes() {
        final NamespaceBinder nsmap = statEnv_.getStaticalyKnownNamespaces();
        return nsmap.getAllPrefixesAsArray();
    }
View Full Code Here

        final NamespaceBinder nsmap = statEnv_.getStaticalyKnownNamespaces();
        return nsmap.getAllPrefixesAsArray();
    }

    public String getNamespaceURI(String prefix) throws XQException {
        final NamespaceBinder nsmap = statEnv_.getStaticalyKnownNamespaces();
        return nsmap.getNamespaceURI(prefix);
    }
View Full Code Here

            xqdoc.setDocumentUri(unescaped);
            _sharedCache.put(docurl, xqdoc);
        }
        // import namespace decl
        Map<String, String> nsmap = xqdoc.documentTable().getDeclaredNamespaces();
        NamespaceBinder nsResolver = dynEnv.getStaticContext().getStaticalyKnownNamespaces();
        nsResolver.declarePrefixs(nsmap);
        return xqdoc;
    }
View Full Code Here

        match("//aaa/*", "/bbb/aaa/ccc/cccc", false);
    }
   
    private void match(String ptnStr1, String ptnStr2, boolean expected) {
        StaticContext statEnv = new StaticContext();
        NamespaceBinder namespaces = statEnv.getStaticalyKnownNamespaces();
        XMLPathPattern ptn1 = new XMLPathPattern(ptnStr1, namespaces);
        XMLPathPattern ptn2 = new XMLPathPattern(ptnStr2, namespaces);
        Assert.assertSame(ptn1 + " <-> " + ptn2, expected, ptn1.match(ptn2));
    }
View Full Code Here

                + xqtsVersion + ", target version: " + targetXQTSVersion;
    }

    protected static int countTests(final String testPath) throws XPathExpressionException {
        final XPath xpath = XPathFactory.newInstance().newXPath();
        NamespaceBinder resolver = new NamespaceBinder();
        resolver.declarePrefix(CATALONG_URI_PREFIX, CATALONG_URI);
        xpath.setNamespaceContext(resolver);
        final String count = "count(" + testPath + ")";
        XPathExpression expr = xpath.compile(count);
        final Document catalog = catalogPool.borrowObject();
        final Double d = (Double) expr.evaluate(catalog, XPathConstants.NUMBER);
View Full Code Here

        return d.intValue();
    }

    public void invokeTest(final String testPath) throws Exception {
        XPath xpath = XPathFactory.newInstance().newXPath();
        NamespaceBinder resolver = new NamespaceBinder();
        resolver.declarePrefix(CATALONG_URI_PREFIX, CATALONG_URI);
        xpath.setNamespaceContext(resolver);

        final Document catalog = catalogPool.borrowObject();
        try {
            NodeList rs = (NodeList) xpath.evaluate(testPath, catalog, XPathConstants.NODESET);
            final int rslen = rs.getLength();
            for(int i = 0; i < rslen; i++) {
                if(doPrint) {
                    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);
                        }
                    }
                }
View Full Code Here

                            testDataDoc = dtm.documentNode();
                            _docCache.put(testDataId, testDataDoc);
                        }
                        // import namespace decl
                        Map<String, String> nsmap = testDataDoc.documentTable().getDeclaredNamespaces();
                        NamespaceBinder nsResolver = statEnv.getStaticalyKnownNamespaces();
                        nsResolver.declarePrefixs(nsmap);
                        // reserve variable
                        QualifiedName varName = QNameTable.instantiate(XMLConstants.DEFAULT_NS_PREFIX, varNameStr);
                        Variable var = new Variable.GlobalVariable(varName, null);
                        var.setResult(testDataDoc);
                        xqmod.putVariable(varName, var);
                    }
                } else {
                    NodeList list = (NodeList) xpath.evaluate("/*[local-name()='test-suite']/*[local-name()='sources']/*[local-name()='collection'][@ID='"
                            + testDataId + "']/*[local-name()='input-document']/text()", catalog, XPathConstants.NODESET);
                    final int listlen = list.getLength();
                    if(listlen > 0) {
                        final NodeSequence<DTMDocument> ret = new NodeSequence<DTMDocument>(new DynamicContext(statEnv));
                        for(int i = 0; i < listlen; i++) {
                            String name = list.item(i).getTextContent();
                            DTMDocument testDataDoc = _docCache.get(name);
                            if(testDataDoc == null) {
                                File testDataFile = new File(xqtsDir, name + ".xml");
                                DocumentTableModel dtm = new DocumentTableModel(false);
                                dtm.loadDocument(new FileInputStream(testDataFile));
                                testDataDoc = dtm.documentNode();
                                _docCache.put(testDataId, testDataDoc);
                            }
                            // import namespace decl
                            Map<String, String> nsmap = testDataDoc.documentTable().getDeclaredNamespaces();
                            NamespaceBinder nsResolver = statEnv.getStaticalyKnownNamespaces();
                            nsResolver.declarePrefixs(nsmap);
                            ret.addItem(testDataDoc);
                        }
                        // reserve variable
                        QualifiedName varName = QNameTable.instantiate(XMLConstants.DEFAULT_NS_PREFIX, varNameStr);
                        Variable var = new Variable.GlobalVariable(varName, null);
View Full Code Here

        if(instName == null) {
            instName = processNameExpr(contextSeq, dynEnv);
        }
        DMElement dmelem = XQueryDataModel.createElement(instName);
        boolean hasNamespaceDecl = false;
        NamespaceBinder knownNamespaces = dynEnv.getStaticContext().getStaticalyKnownNamespaces();
        // process attribute/namespace
        for(AttributeConstructorBase att : attributes) {
            if(att instanceof NamespaceConstructor) {
                if(!hasNamespaceDecl) {
                    knownNamespaces.pushContext(); // TODO REVIEWME performance
                    hasNamespaceDecl = true;
                }
                NamespaceConstructor nc = ((NamespaceConstructor) att);
                DMNamespace dmns = nc.eval(contextSeq, dynEnv);
                dmelem.addNamespace(dmns);
                String nsprefix = nc.getPrefix();
                String nsuri = nc.getValue();
                knownNamespaces.declarePrefix(nsprefix, nsuri);
            } else if(att instanceof AttributeConstructor) {
                AttributeConstructor ac = (AttributeConstructor) att;
                DMAttribute dmatt = ac.eval(contextSeq, dynEnv);
                dmelem.addAttribute(dmatt);
            } else {
                throw new IllegalStateException("Expected to be NamespaceConstructor or AttributeConstructor instance, but was.. "
                        + att.getClass().getCanonicalName());
            }
        }
        // process children
        for(XQExpression content : contents) {
            Sequence childs = content.eval(contextSeq, dynEnv);
            if(childs != ValueSequence.EMPTY_SEQUENCE) {
                CloneNodesSequence clonedseq = new CloneNodesSequence(childs, dynEnv);           
                dmelem.addContents(clonedseq, dynEnv);
            }
        }
        if(hasNamespaceDecl) {
            knownNamespaces.popContext();
        }
        return dmelem;
    }
View Full Code Here

        if(instName == null) {
            instName = processNameExpr(contextSeq, dynEnv);
        }
        handler.evStartElement(instName);
        boolean hasNamespaceDecl = false;
        NamespaceBinder knownNamespaces = dynEnv.getStaticContext().getStaticalyKnownNamespaces();

        final int attlen = _attslen;
        for(int i = 0; i < attlen; i++) {
            AttributeConstructorBase att = attributes.get(i);
            if(att instanceof NamespaceConstructor) {
                if(!hasNamespaceDecl) {
                    knownNamespaces.pushContext(); // TODO REVIEWME performance
                    hasNamespaceDecl = true;
                }
                NamespaceConstructor nc = ((NamespaceConstructor) att);
                String nsprefix = nc.getPrefix();
                String nsuri = nc.getValue();
                knownNamespaces.declarePrefix(nsprefix, nsuri);
                handler.evNamespace(nsprefix, nsuri);
            } else {
                att.evalAsEvents(handler, contextSeq, dynEnv);
            }
        }
        final boolean old = handler.setBlankRequired(false);
        final int contentlen = contents.size();
        for(int i = 0; i < contentlen; i++) {
            XQExpression content = contents.get(i);
            content.evalAsEvents(handler, contextSeq, dynEnv);
            handler.setBlankRequired(true);
        }
        handler.setBlankRequired(old);

        if(hasNamespaceDecl) {
            knownNamespaces.popContext();
        }
        handler.evEndElement(instName);
    }
View Full Code Here

TOP

Related Classes of xbird.util.xml.NamespaceBinder

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.