Package org.exist.dom

Examples of org.exist.dom.DocumentImpl


  }

  @Override
  public Sequence eval(Sequence[] args, Sequence contextSequence)
      throws XPathException {
    DocumentImpl doc = null;
        try {
            // Get first parameter, this is the document
            String path = args[0].itemAt(0).getStringValue();

            // Retrieve document from database
            doc = context.getBroker().getXMLResource(XmldbURI.xmldbUriFor(path), Lock.READ_LOCK);

            // Verify the document actually exists
            if (doc == null) {
                throw new XPathException("Document " + path + " does not exist.");
            }

            // Retrieve Lucene
            LuceneIndexWorker index = (LuceneIndexWorker) context.getBroker()
                    .getIndexController().getWorkerByIndexId(LuceneIndex.ID);

            // Note: code order is important here,
            index.setDocument(doc, StreamListener.REMOVE_BINARY);

            index.flush();

        } catch (Exception ex) { // PermissionDeniedException
            throw new XPathException(ex);

        } finally {
            if (doc != null) {
                doc.getUpdateLock().release(Lock.READ_LOCK);
            }
        }

        // Return nothing [status would be nice]
        return Sequence.EMPTY_SEQUENCE;
View Full Code Here


      throws XPathException {
    String path = args[0].itemAt(0).getStringValue();
   
        try {
      // Retrieve document from database
      DocumentImpl doc = context.getBroker().getXMLResource(XmldbURI.xmldbUriFor(path), Lock.READ_LOCK);

      // Verify the document actually exists
      if (doc == null) {
          throw new XPathException("Document " + path + " does not exist.");
      }
     
      LuceneIndexWorker index = (LuceneIndexWorker)
        context.getBroker().getIndexController().getWorkerByIndexId(LuceneIndex.ID);
      return new BooleanValue(index.hasIndex(doc.getDocId()));
    } catch (PermissionDeniedException e) {
      throw new XPathException(this, LuceneModule.EXXQDYFT0001, e.getMessage());
    } catch (URISyntaxException e) {
      throw new XPathException(this, LuceneModule.EXXQDYFT0003, e.getMessage());
    } catch (IOException e) {
View Full Code Here

    }

    @Override
    public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {

        DocumentImpl doc = null;
        try {
          // Retrieve Lucene
            LuceneIndexWorker index = (LuceneIndexWorker) context.getBroker()
                    .getIndexController().getWorkerByIndexId(LuceneIndex.ID);
           
          if (isCalledAs("index")) {
              // Get first parameter, this is the document
              String path = args[0].itemAt(0).getStringValue();
 
              // Retrieve document from database
              doc = context.getBroker().getXMLResource(XmldbURI.xmldbUriFor(path), Lock.READ_LOCK);
 
              // Verify the document actually exists
              if (doc == null) {
                  throw new XPathException("Document " + path + " does not exist.");
              }
 
              boolean flush = args.length == 2 || args[2].effectiveBooleanValue();
 
              // Note: code order is important here,
              index.setDocument(doc, StreamListener.STORE);
              index.setMode(StreamListener.STORE);
 
              // Get 'solr' node from second parameter
              NodeValue descriptor = (NodeValue) args[1].itemAt(0);
             
              // Pas document and index instructions to indexer
              index.indexNonXML(descriptor);
             
              if (flush) {
                // Make sure things are written
                index.writeNonXML();
              }
          } else {
            // "close"
            index.writeNonXML();
          }

        } catch (Exception ex) { // PermissionDeniedException
            logger.error(ex.getMessage(), ex);
            throw new XPathException(ex);

        } finally {
            if (doc != null) {
                doc.getUpdateLock().release(Lock.READ_LOCK);
            }
        }

        // Return nothing [status would be nice]
        return Sequence.EMPTY_SEQUENCE;
View Full Code Here

        public void collect(int doc) {
            try {
                float score = scorer.score();
                int docId = (int) this.docIdValues.get(doc);
               
                DocumentImpl storedDocument = docs.getDoc(docId);
                if (storedDocument == null)
                    return;
               
                if (!docbits.contains(docId)) {
                    docbits.add(storedDocument);
View Full Code Here

    public void startElement(QName qname, AttrList attribs) throws SAXException {
        if (elementStack == 0) {
            StoredNode node = getCurrentNode();
            if (node != null) {
                DocumentImpl doc = node.getDocument();
                XmldbURI uri = doc.getURI();
                if (!uri.startsWith(XmldbURI.SYSTEM_COLLECTION_URI)) {
                   
                    if (doc.getCollection().getConfiguration(getBroker()).triggerRegistered(VersioningTrigger.class)) {
                        try {
                            long rev = VersioningHelper.getCurrentRevision(getBroker(), doc.getURI());
                            long time = System.currentTimeMillis();
                            String key = Long.toHexString(time) + Long.toHexString(rev);
                            attribs.addAttribute(ATTR_REVISION, rev == 0 ? "0" : Long.toString(rev));
                            attribs.addAttribute(ATTR_KEY, key);
                            attribs.addAttribute(ATTR_PATH, doc.getURI().toString());
                        } catch (XPathException e) {
                            LOG.error("Exception while retrieving versioning info: " + e.getMessage(), e);
                        } catch (IOException e) {
                            LOG.error("Exception while retrieving versioning info: " + e.getMessage(), e);
                        } catch (PermissionDeniedException e) {
View Full Code Here

        NodeValue nv1 = (NodeValue) args[0].itemAt(0);
        NodeValue nv2 = (NodeValue) args[1].itemAt(0);
        if (nv1.getImplementationType() != NodeValue.PERSISTENT_NODE ||
                nv2.getImplementationType() != NodeValue.PERSISTENT_NODE)
            throw new XPathException(this, "diff function only works on persistent documents stored in the db");
        DocumentImpl doc1 = ((NodeProxy)nv1).getDocument();
        DocumentImpl doc2 = ((NodeProxy)nv2).getDocument();

        context.pushDocumentContext();
        try {
            MemTreeBuilder builder = context.getDocumentBuilder();
            DocumentBuilderReceiver receiver = new DocumentBuilderReceiver(builder);
View Full Code Here

            nv = (NodeValue) args[1].itemAt(0);
            if (nv.getImplementationType() == NodeValue.IN_MEMORY_NODE)
                throw new XPathException("patch cannot be applied to in-memory documents");
            NodeProxy diffProxy = (NodeProxy) nv;
            DocumentImpl diff = diffProxy.getDocument();
       
            MemTreeBuilder builder = context.getDocumentBuilder();
            DocumentBuilderReceiver receiver = new DocumentBuilderReceiver(builder);
            Patch patch = new Patch(context.getBroker(), diff);
            if (isCalledAs("annotate"))
View Full Code Here

            System.out.println("Transaction commited ...");
           
            Serializer serializer = broker.getSerializer();
            serializer.reset();
           
            DocumentImpl doc = broker.getXMLResource(TestConstants.TEST_COLLECTION_URI2.append(TestConstants.TEST_XML_URI), Lock.READ_LOCK);
            assertNotNull("Document '" + XmldbURI.ROOT_COLLECTION + "/test/test2/test.xml' should not be null", doc);
            String data = serializer.serialize(doc);
            System.out.println(data);
            doc.getUpdateLock().release(Lock.READ_LOCK);
           
            // the following transaction will not be committed and thus undone during recovery
            transaction = mgr.beginTransaction();
            System.out.println("Transaction started ...");
           
View Full Code Here

             assertNotNull(broker);
            Serializer serializer = broker.getSerializer();
            assertNotNull(serializer);
            serializer.reset();
           
            DocumentImpl doc = broker.getXMLResource(TestConstants.TEST_COLLECTION_URI2.append(TestConstants.TEST_XML_URI), Lock.READ_LOCK);
            assertNotNull("Document '" + XmldbURI.ROOT_COLLECTION + "/test/test2/test.xml' should not be null", doc);
            String data = serializer.serialize(doc);
            assertNotNull(data);
            System.out.println(data);
            doc.getUpdateLock().release(Lock.READ_LOCK);
        } catch (Exception e) {           
          fail(e.getMessage());                   
        } finally {
          if (pool!= null) pool.release(broker);
        }
View Full Code Here

            broker = pool.get(pool.getSecurityManager().getSystemSubject());
            assertNotNull(broker);
            Serializer serializer = broker.getSerializer();
            serializer.reset();
           
            DocumentImpl doc = broker.getXMLResource(TestConstants.TEST_COLLECTION_URI2.append("terms-eng.xml"), Lock.READ_LOCK);
            assertNotNull("Document should not be null", doc);
            String data = serializer.serialize(doc);
            assertNotNull(data);
            System.out.println(data);
            doc.getUpdateLock().release(Lock.READ_LOCK);
      } catch (Exception e) {           
          fail(e.getMessage());
      } finally {
        if (pool != null) pool.release(broker);
        }   
View Full Code Here

TOP

Related Classes of org.exist.dom.DocumentImpl

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.