Package org.exist.dom

Examples of org.exist.dom.QName


        try {
            broker = pool.get(pool.getSecurityManager().getSystemSubject());
            transact = pool.getTransactionManager();
            transaction = transact.beginTransaction();

            Occurrences occur[] = checkIndex(docs, broker, new QName[] { new QName("description", "") }, "chair", 1);
            assertEquals("chair", occur[0].getTerm());
            checkIndex(docs, broker, new QName[] { new QName("item", "") }, null, 5);

            XQuery xquery = broker.getXQueryService();
            assertNotNull(xquery);
            Sequence seq = xquery.execute("//item[ft:query(description, 'chair')]", null, AccessContext.TEST);
            assertNotNull(seq);
            assertEquals(1, seq.getItemCount());

            // Update element content
            XUpdateProcessor proc = new XUpdateProcessor(broker, docs, AccessContext.TEST);
            assertNotNull(proc);
            proc.setBroker(broker);
            proc.setDocumentSet(docs);
            String xupdate =
                    XUPDATE_START +
                    "   <xu:update select=\"//item[@id = '1']/description\">wardrobe</xu:update>" +
                    XUPDATE_END;
            Modification[] modifications = proc.parse(new InputSource(new StringReader(xupdate)));
            assertNotNull(modifications);
            modifications[0].process(transaction);
            proc.reset();

            checkIndex(docs, broker, new QName[] { new QName("description", "") }, null, 3);
            checkIndex(docs, broker, new QName[] { new QName("item", "") }, null, 5);
            checkIndex(docs, broker, new QName[] { new QName("description", "") }, "chair", 0);
            checkIndex(docs, broker, new QName[] { new QName("item", "") }, "chair", 0);
            Occurrences o[] = checkIndex(docs, broker, new QName[] { new QName("description", "") }, "wardrobe", 1);
            assertEquals("wardrobe", o[0].getTerm());

            // Update text node
            proc.setBroker(broker);
            proc.setDocumentSet(docs);
            xupdate =
                    XUPDATE_START +
                    "   <xu:update select=\"//item[@id = '1']/description/text()\">Wheelchair</xu:update>" +
                    XUPDATE_END;
            modifications = proc.parse(new InputSource(new StringReader(xupdate)));
            assertNotNull(modifications);
            modifications[0].process(transaction);
            proc.reset();

            checkIndex(docs, broker, new QName[] { new QName("description", "") }, null, 3);
            checkIndex(docs, broker, new QName[] { new QName("item", "") }, null, 5);
            checkIndex(docs, broker, new QName[] { new QName("description", "") }, "wardrobe", 0);
            checkIndex(docs, broker, new QName[] { new QName("item", "") }, "wardrobe", 0);
            o = checkIndex(docs, broker, new QName[] { new QName("description", "") }, "wheelchair", 1);
            assertEquals("wheelchair", o[0].getTerm());

            // Update attribute value
            proc.setBroker(broker);
            proc.setDocumentSet(docs);
            xupdate =
                    XUPDATE_START +
                    "   <xu:update select=\"//item[@id = '1']/@attr\">abc</xu:update>" +
                    XUPDATE_END;
            modifications = proc.parse(new InputSource(new StringReader(xupdate)));
            assertNotNull(modifications);
            modifications[0].process(transaction);
            proc.reset();

            QName qnattr[] = { new QName("attr", "", "") };
            qnattr[0].setNameType(ElementValue.ATTRIBUTE);
            o = checkIndex(docs, broker, qnattr, null, 1);
            assertEquals("abc", o[0].getTerm());
            checkIndex(docs, broker, qnattr, "attribute", 0);
View Full Code Here


        try {
            broker = pool.get(pool.getSecurityManager().getSystemSubject());
            transact = pool.getTransactionManager();
            transaction = transact.beginTransaction();

            Occurrences occur[] = checkIndex(docs, broker, new QName[] { new QName("description", "") }, "chair", 1);
            assertEquals("chair", occur[0].getTerm());
            checkIndex(docs, broker, new QName[] { new QName("item", "") }, null, 5);

            XQuery xquery = broker.getXQueryService();
            assertNotNull(xquery);
            Sequence seq = xquery.execute("//item[ft:query(description, 'chair')]", null, AccessContext.TEST);
            assertNotNull(seq);
            assertEquals(1, seq.getItemCount());

            XUpdateProcessor proc = new XUpdateProcessor(broker, docs, AccessContext.TEST);
            assertNotNull(proc);
            proc.setBroker(broker);
            proc.setDocumentSet(docs);
            String xupdate =
                    XUPDATE_START +
                    "<xu:replace select=\"//item[@id = '1']\">" +
                    "<item id='4'><description>Wheelchair</description> <condition>poor</condition></item>" +
                    "</xu:replace>" +
                    XUPDATE_END;
            Modification[] modifications = proc.parse(new InputSource(new StringReader(xupdate)));
            assertNotNull(modifications);
            modifications[0].process(transaction);
            proc.reset();

            checkIndex(docs, broker, new QName[] { new QName("description", "") }, null, 3);
            checkIndex(docs, broker, new QName[] { new QName("condition", "") }, null, 3);
            checkIndex(docs, broker, new QName[] { new QName("item", "") }, null, 6);
            checkIndex(docs, broker, new QName[] { new QName("description", "") }, "chair", 0);
            checkIndex(docs, broker, new QName[] { new QName("item", "") }, "chair", 0);
            Occurrences o[] = checkIndex(docs, broker, new QName[] { new QName("description", "") }, "wheelchair", 1);
            assertEquals("wheelchair", o[0].getTerm());
            o = checkIndex(docs, broker, new QName[] { new QName("condition", "") }, "poor", 1);
            assertEquals("poor", o[0].getTerm());
            o = checkIndex(docs, broker, new QName[] { new QName("item", "") }, "wheelchair", 1);
            assertEquals("wheelchair", o[0].getTerm());
            o = checkIndex(docs, broker, new QName[] { new QName("item", "") }, "poor", 1);
            assertEquals("poor", o[0].getTerm());

            proc.setBroker(broker);
            proc.setDocumentSet(docs);
            xupdate =
                    XUPDATE_START +
                    "<xu:replace select=\"//item[@id = '4']/description\">" +
                    "<description>Armchair</description>" +
                    "</xu:replace>" +
                    XUPDATE_END;
            modifications = proc.parse(new InputSource(new StringReader(xupdate)));
            assertNotNull(modifications);
            modifications[0].process(transaction);
            proc.reset();

            checkIndex(docs, broker, new QName[] { new QName("description", "") }, null, 3);
            checkIndex(docs, broker, new QName[] { new QName("item", "") }, null, 6);
            checkIndex(docs, broker, new QName[] { new QName("description", "") }, "wheelchair", 0);
            checkIndex(docs, broker, new QName[] { new QName("item", "") }, "wheelchair", 0);
            o = checkIndex(docs, broker, new QName[] { new QName("description", "") }, "armchair", 1);
            assertEquals("armchair", o[0].getTerm());
            o = checkIndex(docs, broker, new QName[] { new QName("item", "") }, "armchair", 1);
            assertEquals("armchair", o[0].getTerm());

            transact.commit(transaction);
         } catch (Exception e) {
             if (transact != null)
View Full Code Here

            org.w3c.dom.Document document = (org.w3c.dom.Document) item;
            item = document.getDocumentElement();
          }
         
          if (item instanceof org.w3c.dom.Element) {
            QName qn;
                  if (item instanceof QNameValue) {
                      qn = ((QNameValue)item).getQName();
                  } else {
                      qn = ((QNameable)item).getQName();
                      if (qn.getPrefix() == null && context.getInScopeNamespace("") != null) {
                           qn.setNamespaceURI(context.getInScopeNamespace(""));
                      }
                  }
            int nodeNr = builder.startElement(qn, null);
           
            if (use_attribute_sets != null)
View Full Code Here

     * @param functionSignature The Function Signature to use to match a Function
     *
     * @return The Function from the XQuery matching the Function Signature
     */
    private UserDefinedFunction findFunction(final CompiledXQuery xquery, final FunctionSignature functionSignature) throws XPathException {
        final QName fnName = QName.fromJavaQName(functionSignature.getName());
        final int arity = functionSignature.getArgumentCount();     
        return xquery.getContext().resolveFunction(fnName, arity);
    }
View Full Code Here

                                }
                                break;
                            }
                            case INLINE_ELEMENT: {
                                Element elem = (Element) node;
                                QName qname = LuceneIndexConfig.parseQName(elem, namespaces);
                                if (inlineNodes == null) {
                                    inlineNodes = new TreeSet<>();
                                }
                                inlineNodes.add(qname);
                                break;
                            }
                            case IGNORE_ELEMENT: {
                                Element elem = (Element) node;
                                QName qname = LuceneIndexConfig.parseQName(elem, namespaces);
                                if (ignoreNodes == null) {
                                    ignoreNodes = new TreeSet<>();
                                }
                                ignoreNodes.add(qname);
                                break;
View Full Code Here

                Expression outerExpr = contextInfo.getContextStep();
                if (outerExpr != null && outerExpr instanceof LocationStep) {
                    LocationStep outerStep = (LocationStep) outerExpr;
                    NodeTest test = outerStep.getTest();
                    if (test.getName() == null)
                        contextQName = new QName(null, null, null);
                    else if (test.isWildcardTest())
                        contextQName = test.getName();
                    else
                        contextQName = new QName(test.getName());
                    if (outerStep.getAxis() == Constants.ATTRIBUTE_AXIS || outerStep.getAxis() == Constants.DESCENDANT_ATTRIBUTE_AXIS)
                        contextQName.setNameType(ElementValue.ATTRIBUTE);
                    contextStep = firstStep;
                    axis = outerStep.getAxis();
                    optimizeSelf = true;
                }
            } else if (lastStep != null && firstStep != null) {
                NodeTest test = lastStep.getTest();
                if (test.getName() == null)
                    contextQName = new QName(null, null, null);
                else if (test.isWildcardTest())
                    contextQName = test.getName();
                else
                    contextQName = new QName(test.getName());
                if (lastStep.getAxis() == Constants.ATTRIBUTE_AXIS || lastStep.getAxis() == Constants.DESCENDANT_ATTRIBUTE_AXIS)
                    contextQName.setNameType(ElementValue.ATTRIBUTE);
                axis = firstStep.getAxis();
                optimizeChild = steps.size() == 1 &&
                        (axis == Constants.CHILD_AXIS || axis == Constants.ATTRIBUTE_AXIS);
View Full Code Here

    private FieldType type = null;
   
    public LuceneIndexConfig(Element config, Map<String, String> namespaces, AnalyzerConfig analyzers,
          Map<String, FieldType> fieldTypes) throws DatabaseConfigurationException {
        if (config.hasAttribute(QNAME_ATTR)) {
            QName qname = parseQName(config, namespaces);
            path = new NodePath(qname);
            isQNameIndex = true;
        } else {
            String matchPath = config.getAttribute(MATCH_ATTR);
            try {
View Full Code Here

                if(namespaceURI == null) {
                    throw new DatabaseConfigurationException("No namespace defined for prefix: " + prefix +
                            " in index definition");
                }
            }
            QName qname = new QName(localName, namespaceURI, prefix);
            if (isAttribute)
                qname.setNameType(ElementValue.ATTRIBUTE);
            return qname;
        } catch (IllegalArgumentException e) {
            throw new DatabaseConfigurationException("Lucene index configuration error: " + e.getMessage(), e);
        }
    }
View Full Code Here

        }
    }

    public boolean match(NodePath other) {
        if (isQNameIndex) {
            final QName qn1 = path.getLastComponent();
            final QName qn2 = other.getLastComponent();
            return qn1.getNameType() == qn2.getNameType() && qn2.equalsSimple(qn1);
        }
        return path.match(other);
    }
View Full Code Here

        Sequence xmlResponse = null;
        MemTreeBuilder builder = context.getDocumentBuilder();

        builder.startDocument();
        builder.startElement( new QName( "file", ZipModule.NAMESPACE_URI, ZipModule.PREFIX ), null );
        builder.addAttribute( new QName( "href", null, null ), uri.toString() );

        try {
            zis = zipFileSource.getStream();
            ZipEntry zipEntry;
            while ((zipEntry = zis.getNextEntry()) != null) {

                if (zipEntry.isDirectory()) {
                    builder.startElement(new QName("dir",ZipModule.NAMESPACE_URI,ZipModule.PREFIX),null);
                    builder.addAttribute(new QName("name",null,null), zipEntry.toString());
                    builder.endElement();
                } else {
                    logger.debug("file: " + zipEntry.getName());
                    builder.startElement(new QName("entry",ZipModule.NAMESPACE_URI,ZipModule.PREFIX),null);
                    builder.addAttribute(new QName("name",null,null), zipEntry.toString());
                    builder.endElement();
                }
            }
        }catch(PermissionDeniedException pde) {
            logger.error(pde.getMessage(), pde);
View Full Code Here

TOP

Related Classes of org.exist.dom.QName

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.