Package org.exist.dom

Examples of org.exist.dom.NodeImpl


    try {
      final StoredNode[] ql = selectAndLock(transaction);
      final IndexListener listener = new IndexListener(ql);
      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);
View Full Code Here


        if (children.getLength() == 0) {return 0;}
        try {
            final StoredNode[] ql = selectAndLock(transaction);
            final IndexListener listener = new IndexListener(ql);
            final NotificationService notifier = broker.getBrokerPool().getNotificationService();      
            NodeImpl parent;            
            final int len = children.getLength();
            if (LOG.isDebugEnabled())
                {LOG.debug("found " + len + " nodes to insert");}
            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("permission to update document denied");
                }
                parent = (NodeImpl) node.getParentNode();
                switch (mode) {
                    case INSERT_BEFORE:
                        parent.insertBefore(transaction, children, node);
                        break;
                    case INSERT_AFTER:
                        parent.insertAfter(transaction, children, node);
                        break;
                }
                doc.getMetadata().clearIndexListener();
                doc.getMetadata().setLastModified(System.currentTimeMillis());
                modifiedDocuments.add(doc);
View Full Code Here

        final NodeList children = content;
        if (children.getLength() == 0) {return 0;}
        int modificationCount = 0;
        try {
            final StoredNode[] ql = selectAndLock(transaction);
            NodeImpl parent;
            final IndexListener listener = new IndexListener(ql);
            final NotificationService notifier = broker.getBrokerPool().getNotificationService();
            final String newName = children.item(0).getNodeValue();
            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();
                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);
                        newAttr.setNodeName(new QName(newName, "", null));
                        parent.updateChild(transaction, node, newAttr);
                        modificationCount++;
                        break;
                    default:
                        throw new EXistException("unsupported node-type");
                }
View Full Code Here

     * Make sure the NodePool doesn't grow beyond its bounds.
     */
    @Test
    public void testPool() {
        NodePool pool = NodePool.getInstance();
        NodeImpl nodes[] = new NodeImpl[100];

        for (int i = 0; i < 100; i++) {
            nodes[i] = pool.borrowNode(Node.ELEMENT_NODE);
        }
        for (int i = 99; i > -1; i--) {
View Full Code Here

            final Txn transaction = getTransaction();
        try {
          final NotificationService notifier = context.getBroker().getBrokerPool().getNotificationService();
                final StoredNode[] ql = selectAndLock(transaction, inSeq);
                final IndexListener listener = new IndexListener(ql);
                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(context.getUser(), Permission.WRITE)) {
                        //transact.abort(transaction);   
                        throw new PermissionDeniedException("User '" + context.getSubject().getName() + "' does not have permission to write to the document '" + doc.getDocumentURI() + "'!");
                    }
                    doc.getMetadata().setIndexListener(listener);
                   
                    //update the document
                    parent = (NodeImpl) node.getParentNode();
                    if (parent==null) {
                        LOG.debug("Cannot remove the document element (no parent node)");
                        throw new XPathException(this,
                                "It is not possible to remove the document element.");

                    } else if (parent.getNodeType() != Node.ELEMENT_NODE) {
                        LOG.debug("parent = " + parent.getNodeType() + "; " + parent.getNodeName());
                        //transact.abort(transaction);
                        throw new XPathException(this,
                                "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);
View Full Code Here

                   
                    //update the document
            if (mode == INSERT_APPEND) {
              node.appendChildren(transaction, contentList, -1);
            } else {
              final NodeImpl parent = (NodeImpl) node.getParentNode();
                      switch (mode) {
                          case INSERT_BEFORE:
                              parent.insertBefore(transaction, contentList, node);
                              break;
                          case INSERT_AFTER:
                              parent.insertAfter(transaction, contentList, node);
                              break;
                      }
            }
                    doc.getMetadata().clearIndexListener();
                    doc.getMetadata().setLastModified(System.currentTimeMillis());
View Full Code Here

            //start a transaction
            final Txn transaction = getTransaction();
        try {
                final StoredNode[] ql = selectAndLock(transaction, inSeq);
                NodeImpl parent;
                final IndexListener listener = new IndexListener(ql);
                final NotificationService notifier = context.getBroker().getBrokerPool().getNotificationService();
                for (int i = 0; i < ql.length; i++) {
                    final StoredNode node = ql[i];
                    final DocumentImpl doc = (DocumentImpl)node.getOwnerDocument();
                    if (!doc.getPermissions().validate(context.getUser(), Permission.WRITE)) {
                            throw new PermissionDeniedException("User '" + context.getSubject().getName() + "' does not have permission to write to the document '" + doc.getDocumentURI() + "'!");
                    }
                    doc.getMetadata().setIndexListener(listener);
                   
                    //update the document
                    parent = (NodeImpl) node.getParentNode();
                    switch (node.getNodeType()) {
                        case Node.ELEMENT_NODE:
                            final ElementImpl newElem = new ElementImpl((ElementImpl) node);
                            newElem.setNodeName(newQName, context.getBroker().getBrokerPool().getSymbols());
                            parent.updateChild(transaction, node, newElem);
                            break;
                        case Node.ATTRIBUTE_NODE:
                            final AttrImpl newAttr = new AttrImpl((AttrImpl) node);
                            newAttr.setNodeName(newQName, context.getBroker().getBrokerPool().getSymbols());
                            parent.updateChild(transaction, node, newAttr);
                            break;
                        default:
                            throw new XPathException(this, "unsupported node-type");
                    }
   
View Full Code Here

TOP

Related Classes of org.exist.dom.NodeImpl

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.