Package javax.jcr

Examples of javax.jcr.Node


        if (!exists()) {
            throw new DavException(DavServletResponse.SC_NOT_FOUND);
        }
        DavPropertyName propName = property.getName();
        if (JCR_MIXINNODETYPES.equals(propName)) {
            Node n = (Node) item;
            try {
                NodeTypeProperty mix = new NodeTypeProperty(property);
                Set<String> mixins = mix.getNodeTypeNames();

                for (NodeType existingMixin : n.getMixinNodeTypes()) {
                    String name = existingMixin.getName();
                    if (mixins.contains(name)){
                        // do not add existing mixins
                        mixins.remove(name);
                    } else {
                        // remove mixin that are not contained in the new list
                        n.removeMixin(name);
                    }
                }

                // add the remaining mixing types that are not yet set
                for (String mixin : mixins) {
                    n.addMixin(mixin);
                }
            } catch (RepositoryException e) {
                throw new JcrDavException(e);
            }
        } else if (JCR_PRIMARYNODETYPE.equals(propName)) {
            Node n = (Node) item;
            try {
                NodeTypeProperty ntProp = new NodeTypeProperty(property);
                Set<String> names = ntProp.getNodeTypeNames();
                if (names.size() == 1) {
                    String ntName = names.iterator().next();
                    n.setPrimaryType(ntName);
                } else {
                    // only a single node type can be primary node type.
                    throw new DavException(DavServletResponse.SC_BAD_REQUEST);
                }
            } catch (RepositoryException e) {
View Full Code Here


            throw new DavException(DavServletResponse.SC_NOT_FOUND);
        }
        if (JCR_MIXINNODETYPES.equals(propertyName)) {
            // remove all mixin nodetypes
            try {
                Node n = (Node)item;
                for (NodeType mixin : n.getMixinNodeTypes()) {
                    n.removeMixin(mixin.getName());
                }
            } catch (RepositoryException e) {
                // NoSuchNodeTypeException, ConstraintViolationException should never occur...
                throw new JcrDavException(e);
            }
View Full Code Here

            throw new DavException(DavServletResponse.SC_CONFLICT);
        }

        File tmpFile = null;
        try {
            Node n = (Node) item;
            InputStream in = (inputContext != null) ? inputContext.getInputStream() : null;
            String itemPath = getLocator().getRepositoryPath();
            String memberName = getItemName(resource.getLocator().getRepositoryPath());
            if (resource.isCollection()) {
                if (in == null) {
                    // MKCOL without a request body, try if a default-primary-type is defined.
                    n.addNode(memberName);
                } else {
                    // MKCOL, which is not allowed for existing resources
                    int uuidBehavior = ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW;
                    String str = inputContext.getProperty(IMPORT_UUID_BEHAVIOR);
                    if (str != null) {
                        try {
                            uuidBehavior = Integer.parseInt(str);
                        } catch (NumberFormatException e) {
                            throw new DavException(DavServletResponse.SC_BAD_REQUEST);
                        }
                    }
                    if (getTransactionId() == null) {
                        // if not part of a transaction directly import on workspace
                        // since changes would be explicitly saved in the
                        // complete-call.
                        getRepositorySession().getWorkspace().importXML(itemPath, in, uuidBehavior);
                    } else {
                        // changes will not be persisted unless the tx is completed.
                        getRepositorySession().importXML(itemPath, in, uuidBehavior);
                    }
                }
            } else {
                if (in == null) {
                    // PUT: not possible without request body
                    throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Cannot create a new non-collection resource without request body.");
                }
                // PUT : create new or overwrite existing property.
                String ct = inputContext.getContentType();
                int type = JcrValueType.typeFromContentType(ct);
                if (type != PropertyType.UNDEFINED) {
                    // no need to create value/values property. instead
                    // prop-value can be retrieved directly:
                    int pos = ct.indexOf(';');
                    String charSet = (pos > -1) ? ct.substring(pos) : "UTF-8";
                    if (type == PropertyType.BINARY) {
                        n.setProperty(memberName, inputContext.getInputStream());
                    } else {
                        BufferedReader r = new BufferedReader(new InputStreamReader(inputContext.getInputStream(), charSet));
                        String line;
                        StringBuffer value = new StringBuffer();
                        while ((line = r.readLine()) != null) {
                            value.append(line);
                        }
                        n.setProperty(memberName, value.toString(), type);
                    }
                } else {
                    // try to parse the request body into a 'values' property.
                    tmpFile = File.createTempFile(TMP_PREFIX + Text.escape(memberName), null, null);
                    FileOutputStream out = new FileOutputStream(tmpFile);
                    IOUtil.spool(in, out);
                    out.close();
                    // try to parse the request body into a 'values' property.
                    ValuesProperty vp = buildValuesProperty(new FileInputStream(tmpFile));
                    if (vp != null) {
                        if (JCR_VALUE.equals(vp.getName())) {
                            n.setProperty(memberName, vp.getJcrValue());
                        } else {
                            n.setProperty(memberName, vp.getJcrValues());
                        }
                    } else {
                        // request body cannot be parsed into a 'values' property.
                        // fallback: try to import as single value from stream.
                        n.setProperty(memberName, new FileInputStream(tmpFile));
                    }
                }
            }
            if (resource.exists() && resource instanceof AbstractItemResource) {
                // PUT may modify value of existing jcr property. thus, this
View Full Code Here

     */
    public DavResourceIterator getMembers() {
        ArrayList<DavResource> memberList = new ArrayList<DavResource>();
        if (exists()) {
            try {
                Node n = (Node)item;
                // add all node members
                NodeIterator it = n.getNodes();
                while (it.hasNext()) {
                    Node node = it.nextNode();
                    DavResourceLocator loc = getLocatorFromItem(node);
                    memberList.add(createResourceFromLocator(loc));
                }
                // add all property members
                PropertyIterator propIt = n.getProperties();
View Full Code Here

        // only custom ordering is allowed
        if (!OrderingConstants.ORDERING_TYPE_CUSTOM.equalsIgnoreCase(orderPatch.getOrderingType())) {
            throw new DavException(DavServletResponse.SC_UNPROCESSABLE_ENTITY, "Only DAV:custom ordering type supported.");
        }

        Node n = (Node)item;
        try {
            for (OrderPatch.Member instruction : orderPatch.getOrderInstructions()) {
                String srcRelPath = Text.unescape(instruction.getMemberHandle());
                Position pos = instruction.getPosition();
                String destRelPath = getRelDestinationPath(pos, n.getNodes());
                // preform the reordering
                n.orderBefore(srcRelPath, destRelPath);
            }
            complete();
        } catch (RepositoryException e) {
            // UnsupportedRepositoryException should not occur
            throw new JcrDavException(e);
View Full Code Here

            throws RepositoryException {

        String destRelPath = null;
        if (OrderingConstants.XML_FIRST.equals(position.getType())) {
            if (childNodes.hasNext()) {
                Node firstChild = childNodes.nextNode();
                // use last segment of node-path instead of name.
                destRelPath = Text.getName(firstChild.getPath());
            }
            // no child nodes available > reordering to 'first' position fails.
            if (destRelPath == null) {
                throw new ItemNotFoundException("No 'first' item found for reordering.");
            }
View Full Code Here

    protected void initProperties() {
        super.initProperties();
        if (exists()) {
            // resource is serialized as system-view (xml)
            properties.add(new DefaultDavProperty<String>(DavPropertyName.GETCONTENTTYPE, "text/xml"));
            Node n = (Node)item;
            // overwrite the default creation date and creator-displayname if possible
            try {
                if (n.hasProperty(JcrConstants.JCR_CREATED)) {
                    long creationTime = n.getProperty(JcrConstants.JCR_CREATED).getValue().getLong();
                    properties.add(new DefaultDavProperty<String>(DavPropertyName.CREATIONDATE,
                        HttpDateFormat.creationDateFormat().format(new Date(creationTime))));
                }
                // DAV:creator-displayname -> use jcr:createBy if present.
                if (n.hasProperty(Property.JCR_CREATED_BY)) {
                    String createdBy = n.getProperty(Property.JCR_CREATED_BY).getString();
                    properties.add(new DefaultDavProperty<String>(DeltaVConstants.CREATOR_DISPLAYNAME, createdBy, true));
                }
            } catch (RepositoryException e) {
                log.warn("Error while accessing jcr:created or jcr:createdBy property");
            }

            // add node-specific resource properties
            try {
                properties.add(new NodeTypeProperty(JCR_PRIMARYNODETYPE, n.getPrimaryNodeType(), false));
                properties.add(new NodeTypeProperty(JCR_MIXINNODETYPES, n.getMixinNodeTypes(), false));
                properties.add(new DefaultDavProperty<Integer>(JCR_INDEX, n.getIndex(), true));
                addHrefProperty(JCR_REFERENCES, n.getReferences(), true);
                addHrefProperty(JCR_WEAK_REFERENCES, n.getWeakReferences(), true);
                if (n.isNodeType(JcrConstants.MIX_REFERENCEABLE)) {
                    properties.add(new DefaultDavProperty<String>(JCR_UUID, n.getUUID(), true));
                }
            } catch (RepositoryException e) {
                log.error("Failed to retrieve node-specific property: " + e);
            }
            try {
                Item primaryItem = n.getPrimaryItem();
                addHrefProperty(JCR_PRIMARYITEM, new Item[] {primaryItem}, true);
            } catch (ItemNotFoundException e) {
                log.debug("No primary item present on this node '" + getResourcePath() + "'");
            } catch (RepositoryException e) {
                log.error("Error while retrieving primary item: " + e.getMessage());
View Full Code Here

        // immediately build the final multistatus element
        try {
            Element hrefElem = info.getContentElement(DavConstants.XML_HREF, DavConstants.NAMESPACE);
            String uuid = DomUtil.getTextTrim(hrefElem);
            DavResourceLocator resourceLoc = resource.getLocator();
            Node n = getRepositorySession().getNodeByUUID(uuid);
            DavResourceLocator loc = resourceLoc.getFactory().createResourceLocator(resourceLoc.getPrefix(), resourceLoc.getWorkspacePath(), n.getPath(), false);
            DavResource locatedResource = resource.getFactory().createResource(loc, resource.getSession());
            ms = new MultiStatus();
            ms.addResourceProperties(locatedResource, info.getPropertyNameSet(), info.getDepth());
        } catch (RepositoryException e) {
            throw new JcrDavException(e);
View Full Code Here

            String jcrPath = toJCRPath(itemInfo.getPath());
            Item item = session.getItem(jcrPath);
            assertEquals(jcrPath, item.getPath());

            if (item.getDepth() > 0) {
                Node parent = item.getParent();
                if (item.isNode()) {
                    assertTrue(item.isSame(parent.getNode(item.getName())));
                }
                else {
                    assertTrue(item.isSame(parent.getProperty(item.getName())));
                }
            }

        }
    }
View Full Code Here

        if (ranking.size() <= maxChildren) {
            return;
        }

        try {
            Node grandParent;
            if (isRoot(node)) {
                grandParent = node;
            }
            else {
                grandParent = node.getParent();

                // leave first minChildren items where they are
                ranking.take(minChildren);
            }

            // move remaining items to new parents
            for (int k = ranking.size() / minChildren; k > 0; k--) {
                T item = ranking.take(1).next();
                String key = item.getName();

                Node newParent;
                if (grandParent.getPrimaryNodeType().hasOrderableChildNodes()) {
                    Node dest = itemSequence.getSuccessor(grandParent, key);
                    newParent = createIntermediateNode(grandParent, key);
                    grandParent.orderBefore(key, dest == null ? null : dest.getName());
                }
                else {
                    newParent = createIntermediateNode(grandParent, key);
                }
View Full Code Here

TOP

Related Classes of javax.jcr.Node

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.