Package org.exist.dom

Examples of org.exist.dom.DocumentImpl


           
            Collection test = broker.getCollection(TEST_COLLECTION_URI.append("test2"));
            assertNotNull(test);
            System.out.println("Contents of collection " + test.getURI() + ":");
            for (Iterator<DocumentImpl> i = test.iterator(broker); i.hasNext(); ) {
                DocumentImpl next = i.next();
                System.out.println("- " + next.getURI());
            }
        } catch (Exception e) {           
            fail(e.getMessage());             
        } finally {
            pool.release(broker);
View Full Code Here


      final NotificationService notifier = broker.getBrokerPool()
          .getNotificationService();
      NodeImpl parent;
      for (int i = 0; i < ql.length; i++) {
        final StoredNode node = ql[i];
                final DocumentImpl doc = (DocumentImpl)node.getOwnerDocument();
        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() + "'!");
                                }
        doc.getMetadata().setIndexListener(listener);
        parent = (NodeImpl) node.getParentNode();
                if (parent == null || parent.getNodeType() != Node.ELEMENT_NODE) {
          throw new EXistException(
              "you cannot remove the document element. Use update "
                  + "instead");
        } else
          {parent.removeChild(transaction, node);}
        doc.getMetadata().clearIndexListener();
        doc.getMetadata().setLastModified(System.currentTimeMillis());
        modifiedDocuments.add(doc);
        broker.storeXMLResource(transaction, doc);
        notifier.notifyUpdate(doc, UpdateListener.UPDATE);
            }
      checkFragmentation(transaction, modifiedDocuments);
View Full Code Here

          final StoredNode ql[] = selectAndLock(transaction);
      final IndexListener listener = new IndexListener(ql);
      final NotificationService notifier = broker.getBrokerPool().getNotificationService();
      for(int i = 0; i < ql.length; i++) {
        final StoredNode node = ql[i];
        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() + "'!");
                                }
                node.appendChildren(transaction, children, child);
                doc.getMetadata().clearIndexListener();
                doc.getMetadata().setLastModified(System.currentTimeMillis());
                modifiedDocuments.add(doc);
                broker.storeXMLResource(transaction, doc);
                notifier.notifyUpdate(doc, UpdateListener.UPDATE);
      }
      checkFragmentation(transaction, modifiedDocuments);
View Full Code Here

          assertNotNull(pool);
            broker = pool.get(pool.getSecurityManager().getSystemSubject());
            Serializer serializer = broker.getSerializer();
            serializer.reset();
           
            DocumentImpl doc = broker.getXMLResource(XmldbURI.ROOT_COLLECTION_URI.append("test/test2/hamlet.xml"), Lock.READ_LOCK);
            assertNotNull("Document '" + XmldbURI.ROOT_COLLECTION + "/test/test2/hamlet.xml' should not be null", doc);
            String data = serializer.serialize(doc);
            assertNotNull(data);
            //System.out.println(data);
            doc.getUpdateLock().release(Lock.READ_LOCK);
           
            doc = broker.getXMLResource(XmldbURI.ROOT_COLLECTION_URI.append("test/test2/test_string.xml"), Lock.READ_LOCK);
            assertNotNull("Document '" + XmldbURI.ROOT_COLLECTION + "/test/test2/test_string.xml' should not be null", doc);
            data = serializer.serialize(doc);
            assertNotNull(data);
            //System.out.println(data);
            doc.getUpdateLock().release(Lock.READ_LOCK);
           
            File files[] = dir.listFiles();
            assertNotNull(files);
           
            doc = broker.getXMLResource(TestConstants.TEST_COLLECTION_URI2.append(files[files.length - 1].getName()), Lock.READ_LOCK);
View Full Code Here

          broker = pool.get(pool.getSecurityManager().getSystemSubject());
          assertNotNull(broker);
          Serializer serializer = broker.getSerializer();
          serializer.reset();

          DocumentImpl doc = broker.getXMLResource(XmldbURI.ROOT_COLLECTION_URI.append("test/new_test.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);

            transact = pool.getTransactionManager();
            assertNotNull(transact);
            transaction = transact.beginTransaction();
            assertNotNull(transaction);
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("new_test2.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);

            transact = pool.getTransactionManager();
            assertNotNull(transact);
            transaction = transact.beginTransaction();
            assertNotNull(transaction);
View Full Code Here

          pool = startDB();
            broker = pool.get(pool.getSecurityManager().getSystemSubject());
            Serializer serializer = broker.getSerializer();
            serializer.reset();
           
            DocumentImpl doc;
            String data;
           
            doc = broker.getXMLResource(TEST_COLLECTION_URI.append("test2/test.xml"), Lock.READ_LOCK);
            assertNotNull("Document '"+ TEST_COLLECTION_URI.append("test2/test.xml")+"' should not be null", doc);
            data = serializer.serialize(doc);
            System.out.println(data);
            doc.getUpdateLock().release(Lock.READ_LOCK);
           
            XQuery xquery = broker.getXQueryService();
            Sequence seq = xquery.execute("/products/product[last()]", null, AccessContext.TEST);
            System.out.println("Found: " + seq.getItemCount());
            for (SequenceIterator i = seq.iterate(); i.hasNext(); ) {
View Full Code Here

                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();
                doc.getMetadata().setLastModified(System.currentTimeMillis());
                modifiedDocuments.add(doc);
                broker.storeXMLResource(transaction, doc);
                notifier.notifyUpdate(doc, UpdateListener.UPDATE);
            }
            checkFragmentation(transaction, modifiedDocuments);
View Full Code Here

        final XmldbURI newName = XmldbURI.create("dest");

        final Collection srcCollection = EasyMock.createStrictMock(Collection.class);
        final Permission srcPermissions = EasyMock.createStrictMock(Permission.class);

        final DocumentImpl srcSubDocument = EasyMock.createStrictMock(DocumentImpl.class);
        final Permission srcSubDocumentPermissions = EasyMock.createStrictMock(Permission.class);

        final Collection destCollection = EasyMock.createStrictMock(Collection.class);
        final Permission destPermissions = EasyMock.createStrictMock(Permission.class);

        final Collection newDestCollection = null;


        final NativeBroker broker = EasyMock.createMockBuilder(NativeBroker.class)
                .addMockedMethod("getCollection")
                .addMockedMethod("getSubject")
                .createStrictMock();

        final Subject subject = EasyMock.createStrictMock(Subject.class);

        //grant EXECUTE and READ permissions on the src
        expect(srcCollection.getPermissionsNoLock()).andReturn(srcPermissions);
        expect(broker.getSubject()).andReturn(subject);
        expect(srcPermissions.validate(subject, Permission.EXECUTE | Permission.READ)).andReturn(true);

        //grant EXECUTE and WRITE permission on the dest
        expect(broker.getCollection(dest)).andReturn(destCollection);
        final Capture<XmldbURI> newDestURICapture = new Capture<XmldbURI>();
        expect(broker.getCollection(capture(newDestURICapture))).andReturn(newDestCollection);
        expect(destCollection.getPermissionsNoLock()).andReturn(destPermissions);
        expect(broker.getSubject()).andReturn(subject);
        expect(destPermissions.validate(subject, Permission.EXECUTE | Permission.WRITE)).andReturn(true);

        //one sub-document with READ permission
        expect(srcCollection.iterator(broker)).andReturn(new ArrayIterator<DocumentImpl>(srcSubDocument));
        expect(srcSubDocument.getPermissions()).andReturn(srcSubDocumentPermissions);
        expect(broker.getSubject()).andReturn(subject);
        expect(srcSubDocumentPermissions.validate(subject, Permission.READ)).andReturn(true);

        //no sub-collections
        expect(srcCollection.collectionIterator(broker)).andReturn(new EmptyIterator<XmldbURI>());
View Full Code Here

        final XmldbURI newName = XmldbURI.create("dest");

        final Collection srcCollection = EasyMock.createStrictMock(Collection.class);
        final Permission srcPermissions = EasyMock.createStrictMock(Permission.class);

        final DocumentImpl srcSubDocument = EasyMock.createStrictMock(DocumentImpl.class);
        final Permission srcSubDocumentPermissions = EasyMock.createStrictMock(Permission.class);
        final XmldbURI srcSubCollectionName = XmldbURI.create("sub-collection");
        final XmldbURI srcSubCollectionUri = src.append(srcSubCollectionName);
        final Collection srcSubCollection = EasyMock.createStrictMock(Collection.class);
        final Permission srcSubCollectionPermissions = EasyMock.createStrictMock(Permission.class);

        final Collection destCollection = EasyMock.createStrictMock(Collection.class);
        final Permission destPermissions = EasyMock.createStrictMock(Permission.class);

        final Collection newDestCollection = null;

        final NativeBroker broker = EasyMock.createMockBuilder(NativeBroker.class)
                .addMockedMethod("getCollection")
                .addMockedMethod("getSubject")
                .createStrictMock();

        final Subject subject = EasyMock.createStrictMock(Subject.class);

        //grant EXECUTE and READ permissions on the src
        expect(srcCollection.getPermissionsNoLock()).andReturn(srcPermissions);
        expect(broker.getSubject()).andReturn(subject);
        expect(srcPermissions.validate(subject, Permission.EXECUTE | Permission.READ)).andReturn(true);

        //grant EXECUTE and WRITE permission on the dest
        expect(broker.getCollection(dest)).andReturn(destCollection);
        final Capture<XmldbURI> newDestURICapture = new Capture<XmldbURI>();
        expect(broker.getCollection(capture(newDestURICapture))).andReturn(newDestCollection);
        expect(destCollection.getPermissionsNoLock()).andReturn(destPermissions);
        expect(broker.getSubject()).andReturn(subject);
        expect(destPermissions.validate(subject, Permission.EXECUTE | Permission.WRITE)).andReturn(true);

        //one sub-document with READ permission
        expect(srcCollection.iterator(broker)).andReturn(new ArrayIterator<DocumentImpl>(srcSubDocument));
        expect(srcSubDocument.getPermissions()).andReturn(srcSubDocumentPermissions);
        expect(broker.getSubject()).andReturn(subject);
        expect(srcSubDocumentPermissions.validate(subject, Permission.READ)).andReturn(true);

        //one sub-collection with READ and EXECUTE permission
        expect(srcCollection.collectionIterator(broker)).andReturn(new ArrayIterator<XmldbURI>(srcSubCollectionName));
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.