Package org.exist.dom

Examples of org.exist.dom.DocumentImpl


      out().println("Collection lock:");
      collection.getLock().debug(out());
     
      if (commandData.length == 0) return;
     
      DocumentImpl doc = collection.getDocument(broker, XmldbURI.create(commandData[0]) );
     
      if (doc == null) {
        err().println("Resource '"+commandData[0]+"' not found.");
        return;
      }
     
      out().println("Locked by "+doc.getUserLock());
      out().println("Lock token: "+doc.getMetadata().getLockToken());
     
      out().println("Update lock: ");
      doc.getUpdateLock().debug(out());

    } catch (Exception e) {
      throw new CommandException(e);
    } finally {
      if (db != null)
View Full Code Here


            // Remove all collections below the /db root, except /db/system
            Collection root = broker.getOrCreateCollection(transaction, XmldbURI.ROOT_COLLECTION_URI);
            assertNotNull(root);
            for (Iterator<DocumentImpl> i = root.iterator(broker); i.hasNext(); ) {
                DocumentImpl doc = i.next();
                root.removeXMLResource(transaction, broker, doc.getURI().lastSegment());
            }
            broker.saveCollection(transaction, root);
            for (Iterator<XmldbURI> i = root.collectionIterator(broker); i.hasNext(); ) {
                XmldbURI childName = i.next();
                if (childName.equals("system"))
View Full Code Here

       
        for(final String dependant : dependants) {
           
            try {
               
                final DocumentImpl dependantModule = broker.getResource(XmldbURI.create(dependant), Permission.READ);
               
                /**
                 * This null check is needed, as a dependency module may have been renamed,
                 * and so is no longer accessible under its old URI.
                 *
 
View Full Code Here

               
        Sequence result = Sequence.EMPTY_SEQUENCE;
               
        try {
            if(isCalledAs(qnRegisterModule.getLocalName())) {
                final DocumentImpl module = getContext().getBroker().getResource(moduleUri, Permission.READ);
                if(xqueryRegistry.isXquery(module)) {
                    try {
                        final List<RestXqService> resourceFunctions = xqueryRegistry.findServices(getContext().getBroker(), module);
                        xqueryRegistry.registerServices(getContext().getBroker(), resourceFunctions);
                        result = (NodeValue)org.exist.extensions.exquery.restxq.impl.xquery.RegistryFunctions.serializeRestXqServices(context.getDocumentBuilder(), resourceFunctions).getDocumentElement();
                    } catch(final ExQueryException exqe) {
                        LOG.warn(exqe.getMessage(), exqe);
                        result = Sequence.EMPTY_SEQUENCE;
                    }
                } else {
                   result = Sequence.EMPTY_SEQUENCE;
                }
            } else if(isCalledAs(qnDeregisterModule.getLocalName())) {
                final DocumentImpl module = getContext().getBroker().getResource(moduleUri, Permission.READ);
                if(xqueryRegistry.isXquery(module)) {               
                    final List<RestXqService> deregisteringServices = new ArrayList<RestXqService>();
                    for(final RestXqService service : registry) {
                        if(XmldbURI.create(service.getResourceFunction().getXQueryLocation()).equals(moduleUri)) {
                            deregisteringServices.add(service);
                        }
                    }
                    xqueryRegistry.deregisterServices(getContext().getBroker(), moduleUri);
                    result = (NodeValue)org.exist.extensions.exquery.restxq.impl.xquery.RegistryFunctions.serializeRestXqServices(context.getDocumentBuilder(), deregisteringServices).getDocumentElement();
                } else {
                   result = Sequence.EMPTY_SEQUENCE;
                }
            } else if(isCalledAs(qnFindResourceFunctions.getLocalName())) {
               final DocumentImpl module = getContext().getBroker().getResource(moduleUri, Permission.READ);
               if(xqueryRegistry.isXquery(module)) {               
                    try {
                        final List<RestXqService> resourceFunctions = xqueryRegistry.findServices(getContext().getBroker(), module);
                        xqueryRegistry.deregisterServices(getContext().getBroker(), moduleUri);
                        result = (NodeValue)org.exist.extensions.exquery.restxq.impl.xquery.RegistryFunctions.serializeRestXqServices(context.getDocumentBuilder(), resourceFunctions).getDocumentElement();
                    } catch(final ExQueryException exqe) {
                        LOG.warn(exqe.getMessage(), exqe);
                        result = Sequence.EMPTY_SEQUENCE;
                    }
                } else {
                   result = Sequence.EMPTY_SEQUENCE;
                }
            } else if(isCalledAs(qnRegisterResourceFunction.getLocalName())) {
               final String resourceFunctionIdentifier = args[1].getStringValue();
               final DocumentImpl module = getContext().getBroker().getResource(moduleUri, Permission.READ);
               if(xqueryRegistry.isXquery(module)) {
                   final SignatureDetail signatureDetail = extractSignatureDetail(resourceFunctionIdentifier);
                   if(signatureDetail != null) {
                       try {
                         final RestXqService serviceToRegister = findService(xqueryRegistry.findServices(getContext().getBroker(), module).iterator(), signatureDetail);
View Full Code Here

               
                if (docbits.contains(docId)) {
                    return;
                }

                DocumentImpl storedDocument = docs.getDoc(docId);
                if (storedDocument == null)
                    return;
               
                docbits.add(storedDocument);
View Full Code Here

     */
    private ResourceType getResourceType(BrokerPool brokerPool, XmldbURI xmldbUri) {

        DBBroker broker = null;
        Collection collection = null;
        DocumentImpl document = null;
        ResourceType type = ResourceType.NOT_EXISTING;
       
        // MacOsX finder specific files
        String documentSeqment = xmldbUri.lastSegment().toString();
        if(documentSeqment.startsWith("._") || documentSeqment.equals(".DS_Store")){
            //LOG.debug(String.format("Ignoring MacOSX file '%s'", xmldbUri.lastSegment().toString()));
            //return ResourceType.IGNORABLE;
        }
       
        // Documents that start with a dot
        if(documentSeqment.startsWith(".")){
            //LOG.debug(String.format("Ignoring '.' file '%s'", xmldbUri.lastSegment().toString()));
            //return ResourceType.IGNORABLE;
        }

        try {
            if(LOG.isDebugEnabled()) {
                LOG.debug(String.format("Path: %s", xmldbUri.toString()));
            }
           
            // Try to read as system user. Note that the actual user is not know
            // yet. In MiltonResource the actual authentication and authorization
            // is performed.
            broker = brokerPool.get(brokerPool.getSecurityManager().getSystemSubject());

           
            // First check if resource is a collection
            collection = broker.openCollection(xmldbUri, Lock.READ_LOCK);
            if (collection != null) {
                type = ResourceType.COLLECTION;
                collection.release(Lock.READ_LOCK);
                collection = null;

            } else {
                // If it is not a collection, check if it is a document
                document = broker.getXMLResource(xmldbUri, Lock.READ_LOCK);

                if (document != null) {
                    // Document is found
                    type = ResourceType.DOCUMENT;
                    document.getUpdateLock().release(Lock.READ_LOCK);
                    document = null;

                } else {
                    // No document and no collection.
                    type = ResourceType.NOT_EXISTING;
                }
            }
          

        } catch (Exception ex) {
            LOG.error(String.format("Error determining nature of resource %s", xmldbUri.toString()), ex);
            type = ResourceType.NOT_EXISTING;

        } finally {

            // Clean-up, just in case
            if (collection != null) {
                collection.release(Lock.READ_LOCK);
            }

            // Clean-up, just in case
            if (document != null) {
                document.getUpdateLock().release(Lock.READ_LOCK);
            }

            // Return broker to pool
            if(broker != null) {
                brokerPool.release(broker);
View Full Code Here

            }
        }

        private BinaryDocument getDoc() throws PermissionDeniedException {

            DocumentImpl doc = context.getBroker().getXMLResource(uri, Lock.READ_LOCK);
            if(doc == null || doc.getResourceType() != DocumentImpl.BINARY_FILE) {
                return null;
            }

            return (BinaryDocument)doc;
        }
View Full Code Here

       
        BrokerPool pool = null;
        DBBroker broker = null;

        try {
            DocumentImpl resource = null;
            Source source = null;

            pool = BrokerPool.getInstance();

            broker = pool.get(principal);
View Full Code Here

                    LOG.debug(String.format("Inserting XML document '%s'", mime.getName()));

                // Stream into database
                VirtualTempFileInputSource vtfis = new VirtualTempFileInputSource(vtf);
                IndexInfo info = collection.validateXMLResource(txn, broker, newNameUri, vtfis);
                DocumentImpl doc = info.getDocument();
                doc.getMetadata().setMimeType(mime.getName());
                collection.store(txn, broker, info, vtfis, false);

            } else {

                if(LOG.isDebugEnabled())
View Full Code Here

        String docConstraint = "";
        boolean refine_query_on_doc = false;
        if (contextSet != null) {
            if(contextSet.getDocumentSet().getDocumentCount() <= index.getMaxDocsInContextToRefineQuery()) {
                refine_query_on_doc = true;
                DocumentImpl doc;
                Iterator<DocumentImpl> it = contextSet.getDocumentSet().getDocumentIterator();
                doc  = it.next();
                docConstraint = "(DOCUMENT_URI = '" + doc.getURI().toString() + "')";
                while(it.hasNext()) {
                    doc  = it.next();
                    docConstraint = docConstraint + " OR (DOCUMENT_URI = '" + doc.getURI().toString() + "')";
                }
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Refine query on documents is enabled.");
                }
            } else {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Refine query on documents is disabled.");
                }
            }
        }

        switch (spatialOp) {
        //BBoxes are equal
        case SpatialOperator.EQUALS:
            bboxConstraint = "(EPSG4326_MINX = ? AND EPSG4326_MAXX = ?)" +
                " AND (EPSG4326_MINY = ? AND EPSG4326_MAXY = ?)";
            break;
        //Nothing much we can do with the BBox at this stage
        case SpatialOperator.DISJOINT:
            //Retrieve the BBox though...
            extraSelection = ", EPSG4326_MINX, EPSG4326_MAXX, EPSG4326_MINY, EPSG4326_MAXY";
            break;
        //BBoxes intersect themselves
        case SpatialOperator.INTERSECTS:
        case SpatialOperator.TOUCHES:
        case SpatialOperator.CROSSES:
        case SpatialOperator.OVERLAPS:
            bboxConstraint = "(EPSG4326_MAXX >= ? AND EPSG4326_MINX <= ?)" +
            " AND (EPSG4326_MAXY >= ? AND EPSG4326_MINY <= ?)";
            break;
        //BBox is fully within
        case SpatialOperator.WITHIN:
            bboxConstraint = "(EPSG4326_MINX >= ? AND EPSG4326_MAXX <= ?)" +
            " AND (EPSG4326_MINY >= ? AND EPSG4326_MAXY <= ?)";
            break;
        //BBox fully contains
        case SpatialOperator.CONTAINS:
            bboxConstraint = "(EPSG4326_MINX <= ? AND EPSG4326_MAXX >= ?)" +
            " AND (EPSG4326_MINY <= ? AND EPSG4326_MAXY >= ?)";
            break;
        default:
            throw new IllegalArgumentException("Unsupported spatial operator:" + spatialOp);
        }
        PreparedStatement ps = conn.prepareStatement(
            "SELECT EPSG4326_WKB, DOCUMENT_URI, NODE_ID_UNITS, NODE_ID" + (extraSelection == null ? "" : extraSelection) +
            " FROM " + GMLHSQLIndex.TABLE_NAME +
            (bboxConstraint == null ?
                (refine_query_on_doc ? " WHERE " + docConstraint : "") :
                " WHERE " (refine_query_on_doc ? "(" + docConstraint + ") AND " "") + bboxConstraint) + ";"
        );
        if (bboxConstraint != null) {
            ps.setDouble(1, EPSG4326_geometry.getEnvelopeInternal().getMinX());
            ps.setDouble(2, EPSG4326_geometry.getEnvelopeInternal().getMaxX());
            ps.setDouble(3, EPSG4326_geometry.getEnvelopeInternal().getMinY());
            ps.setDouble(4, EPSG4326_geometry.getEnvelopeInternal().getMaxY());
        }
        ResultSet rs = null;
        NodeSet result = null;
        try {
            int disjointPostFiltered = 0;
            rs = ps.executeQuery();
            result = new ExtArrayNodeSet(); //new ExtArrayNodeSet(docs.getLength(), 250)
            while (rs.next()) {
                DocumentImpl doc = null;
                try {
                    doc = (DocumentImpl)broker.getXMLResource(XmldbURI.create(rs.getString("DOCUMENT_URI")));             
                } catch (PermissionDeniedException e) {
                    LOG.debug(e);
                    //Ignore since the broker has no right on the document
                    continue;
                }
                //contextSet == null should be used to scan the whole index
                if (contextSet == null || refine_query_on_doc || contextSet.getDocumentSet().contains(doc.getDocId())) {
                    NodeId nodeId = new DLN(rs.getInt("NODE_ID_UNITS"), rs.getBytes("NODE_ID"), 0);
                    NodeProxy p = new NodeProxy(doc, nodeId);
                    //Node is in the context : check if it is accurate
                    //contextSet.contains(p) would have made more sense but there is a problem with
                    //VirtualNodeSet when on the DESCENDANT_OR_SELF axis
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.