Package org.exist.dom

Examples of org.exist.dom.ElementImpl$AttribVisitor


        final DOMFile domDb = ( (NativeBroker)broker ).getDOMFile();
        return (ErrorReport)new DOMTransaction( this, domDb, Lock.WRITE_LOCK, doc ) {
            public Object start() {
                EmbeddedXMLStreamReader reader = null;
                try {
                    final ElementImpl root = (ElementImpl)doc.getDocumentElement();
                    if (root == null) {
                        return new ErrorReport.ResourceError(ErrorReport.RESOURCE_ACCESS_FAILED, "Failed to access document data");
                    }
                } catch( final Exception e ) {
                    e.printStackTrace();
View Full Code Here


        final DOMFile domDb = ( (NativeBroker)broker ).getDOMFile();
        return( (ErrorReport)new DOMTransaction( this, domDb, Lock.WRITE_LOCK, doc ) {
                    public Object start() {
                        EmbeddedXMLStreamReader reader = null;
                        try {
                            final ElementImpl             root            = (ElementImpl)doc.getDocumentElement();
                            reader = broker.getXMLStreamReader( root, true );
                            NodeId                  nodeId;
                            boolean                 attribsAllowed  = false;
                            int                     expectedAttribs = 0;
                            int                     attributeCount  = 0;
View Full Code Here

    }
   
    private NodeImpl makeObject(short key) {
        switch (key) {
            case Node.ELEMENT_NODE:
                return new ElementImpl();
            case Node.TEXT_NODE:
                return new TextImpl();
            case Node.ATTRIBUTE_NODE:
                return new AttrImpl();
            case Node.CDATA_SECTION_NODE:
View Full Code Here

   
    if (element instanceof org.exist.memtree.ElementImpl) {
      ((org.exist.memtree.ElementImpl)element).getNamespaceMap(prefixes);
   
    } else {
      final ElementImpl elementImpl = (org.exist.dom.ElementImpl) element;
      if (elementImpl.declaresNamespacePrefixes()) {
        for (final Iterator<String> i = elementImpl.getPrefixes(); i.hasNext(); ) {
          final String prefix = i.next();
          prefixes.put(prefix, elementImpl.getNamespaceForPrefix(prefix));
        }
      }
    }
   
    if (namespaceURI == null && namespaceURI.isEmpty()) {
View Full Code Here

                if (node.getImplementationType() == NodeValue.PERSISTENT_NODE) {
                    NodeProxy proxy = (NodeProxy) node;
                    final NodeSet ancestors = proxy.getAncestors(contextId, true);
                    for (final Iterator<NodeProxy> i = ancestors.iterator(); i.hasNext();) {
                        proxy = i.next();
                        final ElementImpl e = (ElementImpl) proxy.getNode();
                        uri = findNamespaceURI(e, prefix);
                        if (uri != null) {
                            break;
                        }
                    }
View Full Code Here

            "return $XQTSCatalog//catalog:sources//catalog:source";

            Sequence results = xquery.execute(query, null, AccessContext.TEST);

            for (NodeProxy node : results.toNodeSet()) {
                ElementImpl source = (ElementImpl) node.getNode();
                sources.put(source.getAttribute("ID"), XQTS_folder + source.getAttribute("FileName"));
            }
        }
        if (moduleSources == null) {
            moduleSources = new HashMap<String, String>();

            String query = "declare namespace catalog=\"http://www.w3.org/2005/02/query-test-XQTSCatalog\";"+
                "let $XQTSCatalog := xmldb:document('/db/XQTS/XQTSCatalog.xml') "+
                "return $XQTSCatalog//catalog:sources//catalog:module";

            Sequence results = xquery.execute(query, null, AccessContext.TEST);

            for (NodeProxy node : results.toNodeSet()) {
                ElementImpl source = (ElementImpl) node.getNode();
                moduleSources.put(source.getAttribute("ID"), "test/external/XQTS_1_0_3/"+source.getAttribute("FileName")+".xq");
            }
        }
    }
View Full Code Here

            Sequence results = xquery.execute(query, null, AccessContext.TEST);
           
            Assert.assertFalse("", !results.hasOne());

            ElementImpl TC = (ElementImpl) results.toNodeSet().get(0).getNode();

            //collect test case information
            String folder = "";
            String scenario = "";
            String script = "";
            //DateTimeValue scriptDateTime = null;
            NodeListImpl inputFiles = new NodeListImpl();
            NodeListImpl outputFiles = new NodeListImpl();
            ElementImpl contextItem = null;
            NodeListImpl modules = new NodeListImpl();
            String expectedError = "";

            String name = null;

            NodeList childNodes = TC.getChildNodes();
            for (int i = 0; i < childNodes.getLength(); i++) {
                Node child = childNodes.item(i);
                switch (child.getNodeType()) {
                    case Node.ATTRIBUTE_NODE:
                        name = ((Attr)child).getName();
                        if (name.equals("FilePath"))
                            folder = ((Attr)child).getValue();
                        else if (name.equals("scenario"))
                            scenario = ((Attr)child).getValue();
                        break;
                    case Node.ELEMENT_NODE:
                        name = ((ElementImpl) child).getLocalName();
                        if (name.equals("query")) {
                            ElementImpl el = ((ElementImpl) child);
                            script = el.getAttribute("name");
                            //scriptDateTime = new DateTimeValue(el.getAttribute("date"));
                        }
                        else if (name.equals("input-file"))
                            inputFiles.add(child);
                        else if (name.equals("output-file"))
                            outputFiles.add(child);
                        else if (name.equals("contextItem"))
                            contextItem = (ElementImpl)child;
                        else if (name.equals("module"))
                            modules.add(child);
                        else if (name.equals("expected-error"))
                            expectedError = ((ElementImpl) child).getNodeValue();
                        break;
                    default :
                        ;
                }
            }

            Sequence result = null;

            //compile & evaluate
            File caseScript = new File(XQTS_folder+"Queries/XQuery/"+folder, script+".xq");
            try {
                XQueryContext context;

                context = xquery.newContext(AccessContext.TEST);

                //map modules' namespaces to location
                Map<String, String> moduleMap = (Map<String, String>)broker.getConfiguration().getProperty(XQueryContext.PROPERTY_STATIC_MODULE_MAP);
                for (int i = 0; i < modules.getLength(); i++) {
                    ElementImpl module = (ElementImpl)modules.item(i);
                    String id = module.getNodeValue();
                    moduleMap.put(module.getAttribute("namespace"), moduleSources.get(id));
                }
                broker.getConfiguration().setProperty(XQueryContext.PROPERTY_STATIC_MODULE_MAP, moduleMap);

                //declare variable
                for (int i = 0; i < inputFiles.getLength(); i++) {
                    ElementImpl inputFile = (ElementImpl)inputFiles.item(i);
                    String id = inputFile.getNodeValue();

                    //use DocUtils
                    //context.declareVariable(
                        //inputFile.getAttribute("variable"),
                        //DocUtils.getDocument(context, sources.get(id))
                    //);

                    //in-memory nodes
                    context.declareVariable(inputFile.getAttribute("variable"), loadVarFromURI(context, sources.get(id)));
                }

                Sequence contextSequence = null;
                //set context item
                if (contextItem != null) {
                    String id = contextItem.getNodeValue();
                    contextSequence = loadVarFromURI(context, sources.get(id));
                }

                fixBrokenTests(context, testGroup, testCase);

                //compare result with one provided by test case
                boolean ok = false;
               
              Exception error = null;
                if ("runtime-error".equals(scenario)) {
                  try {
                        //compile
                        CompiledXQuery compiled = xquery.compile(context, new FileSource(caseScript, "UTF8", true));

                        //execute
                        result = xquery.execute(compiled, contextSequence);
                       
                        if (outputFiles.getLength() != 0) {
                            //can be answered
                          for (int i = 0; i < outputFiles.getLength(); i++) {
                              ElementImpl outputFile = (ElementImpl)outputFiles.item(i);
         
                              String compare = outputFile.getAttribute("compare");
                              if (compare != null && compare.equalsIgnoreCase("IGNORE")) {
                                ok = true;
                                break;
                              }
         
                              if (compareResult(script, "XQTS_1_0_3/ExpectedTestResults/"+folder, outputFile, result)) {
                                  ok = true;
                                  break;
                              }
                          }
                        } else {
                          error = catchError(result);
                        }

                  } catch (Exception e) {
                    error = e;
          }
                 
                    if (!ok && error != null && expectedError != null) {// error.getMessage().contains(expectedError)) {
                      ok = true;
                    }
                } else {
                    //compile
                    CompiledXQuery compiled = xquery.compile(context, new FileSource(caseScript, "UTF8", true));

                    //execute
                    result = xquery.execute(compiled, contextSequence);

                    //check answer
                  for (int i = 0; i < outputFiles.getLength(); i++) {
                      ElementImpl outputFile = (ElementImpl)outputFiles.item(i);
 
                      String compare = outputFile.getAttribute("compare");
                      if (compare != null && compare.equalsIgnoreCase("IGNORE")) {
                        ok = true;
                        break;
                      }
 
                      if (compareResult(script, "XQTS_1_0_3/ExpectedTestResults/"+folder, outputFile, result)) {
                          ok = true;
                          break;
                      }
                  }
                }

                //collect information if result is wrong
                if (!ok) {
                    StringBuilder message = new StringBuilder();
                    StringBuffer exp = new StringBuffer();
                    try {
                        for (int i = 0; i < outputFiles.getLength(); i++) {
                            ElementImpl outputFile = (ElementImpl)outputFiles.item(i);
                            String compare = outputFile.getAttribute("compare");
                            if (compare != null && compare.equalsIgnoreCase("IGNORE"))
                              continue;
                           
                            File expectedResult = new File(XQTS_folder+"ExpectedTestResults/"+folder, outputFile.getNodeValue());
                            if (!expectedResult.canRead())
                                Assert.fail("can't read expected result");
                           
                            //avoid to big output
                            if (expectedResult.length() >= 1024) {
                              exp = new StringBuffer();
                              exp.append("{TOO BIG}");
                              break;
                            } else {
                              exp.append("{'");
                              Reader reader = new BufferedReader(new FileReader(expectedResult));
                              char ch;
                              try {
                                  while (reader.ready()) {
                                      ch = (char)reader.read();
                                      if (ch == '\r')
                                          ch = (char)reader.read();
                                      exp.append(String.valueOf(ch));
                                  }
                              } finally {
                                  reader.close();
                              }
                              exp.append("'}");
                            }
                        }
                    } catch (Exception e) {
                        exp.append(e.getMessage());
                    }
                   
                    String res = "{NOTHING}";
                    if (result != null)
                      res = sequenceToString(result);
                   
                    if (exp.length() == 0)
                        exp.append("error "+ expectedError);
                    StringBuilder data = new StringBuilder();
                    for (int i = 0; i < inputFiles.getLength(); i++) {
                        ElementImpl inputFile = (ElementImpl)inputFiles.item(i);
                        String id = inputFile.getNodeValue();
                        data.append(inputFile.getAttribute("variable"));
                        data.append(" = \n");
                        data.append(readFileAsString(new File(sources.get(id)), 1024));
                        data.append("\n");
                    }
                    message.append("\n");
View Full Code Here

                for (int i = 0; i < reader.getAttributeCount(); i++) {
                    // check if an attribute has to be inserted before the current attribute
                    NodeId nodeId = reader.getAttributeId(i);

                    // check if an attribute has to be inserted before the current attribute
                    ElementImpl insertedNode = insertedNodes.get(nodeId);
                    if (insertedNode != null) {
                        StoredNode child = (StoredNode) insertedNode.getFirstChild();
                        while (child != null) {
                            if (StandardDiff.NAMESPACE.equals(child.getNamespaceURI()) && "attribute".equals(child.getLocalName())) {
                                NamedNodeMap map = child.getAttributes();
                                for (int j = 0; j < map.getLength(); j++) {
                                    AttrImpl attr = (AttrImpl) map.item(j);
View Full Code Here

            final IndexListener listener = new IndexListener(ql);
            final NotificationService notifier = broker.getBrokerPool().getNotificationService();
            Node temp;
            TextImpl text;
            AttrImpl attribute;
            ElementImpl parent;
            for (int i = 0; i < ql.length; i++) {
                final StoredNode node = ql[i];
                if (node == null) {
                    LOG.warn("select " + selectStmt + " returned empty node set");
                    continue;
                }
                final DocumentImpl doc = (DocumentImpl)node.getOwnerDocument();
                doc.getMetadata().setIndexListener(listener);
                if (!doc.getPermissions().validate(broker.getSubject(), Permission.WRITE)) {
                        throw new PermissionDeniedException("User '" + broker.getSubject().getName() + "' does not have permission to write to the document '" + doc.getDocumentURI() + "'!");
                }
                parent = (ElementImpl) node.getParentStoredNode();
                if (parent == null)
                    {throw new EXistException("The root element of a document can not be replaced with 'xu:replace'. " +
                        "Please consider removing the document or use 'xu:update' to just replace the children of the root.");}
                switch (node.getNodeType()) {
                    case Node.ELEMENT_NODE:
                        if (modifications == 0) {modifications = 1;}
                        temp = children.item(0);
                        parent.replaceChild(transaction, temp, node);
                        break;
                    case Node.TEXT_NODE:
                        temp = children.item(0);
                        text = new TextImpl(temp.getNodeValue());
                        modifications = 1;
                        text.setOwnerDocument(doc);
                        parent.updateChild(transaction, node, text);
                        break;
                    case Node.ATTRIBUTE_NODE:
                        final AttrImpl attr = (AttrImpl) node;
                        temp = children.item(0);
                        attribute = new AttrImpl(attr.getQName(), temp.getNodeValue(), broker.getBrokerPool().getSymbols());
                        attribute.setOwnerDocument(doc);
                        parent.updateChild(transaction, node, attribute);
                        break;
                    default:
                        throw new EXistException("unsupported node-type");
                }
                doc.getMetadata().clearIndexListener();
View Full Code Here

                }
                doc.getMetadata().setIndexListener(listener);
                parent = (NodeImpl) node.getParentNode();
                switch (node.getNodeType()) {
                    case Node.ELEMENT_NODE:
                        final ElementImpl newElem = new ElementImpl((ElementImpl) node);
                        newElem.setNodeName(new QName(newName, "", null));
                        parent.updateChild(transaction, node, newElem);
                        modificationCount++;
                        break;
                    case Node.ATTRIBUTE_NODE:
                        final AttrImpl newAttr = new AttrImpl((AttrImpl) node);
View Full Code Here

TOP

Related Classes of org.exist.dom.ElementImpl$AttribVisitor

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.