Search in sources :

Example 1 with NodeTypeProperty

use of org.apache.jackrabbit.webdav.jcr.nodetype.NodeTypeProperty in project jackrabbit by apache.

the class DefaultItemCollection method internalSetProperty.

/**
     * Internal method used to set or add the given property
     *
     * @param property
     * @throws DavException
     * @see #setProperty(DavProperty)
     */
private void internalSetProperty(DavProperty<?> property) throws DavException {
    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) {
            throw new JcrDavException(e);
        }
    } else {
        // all props except for mixin node types and primaryType are read-only
        throw new DavException(DavServletResponse.SC_CONFLICT);
    }
}
Also used : JcrDavPropertyNameSet(org.apache.jackrabbit.webdav.jcr.property.JcrDavPropertyNameSet) Set(java.util.Set) NodeTypeProperty(org.apache.jackrabbit.webdav.jcr.nodetype.NodeTypeProperty) DavException(org.apache.jackrabbit.webdav.DavException) Node(javax.jcr.Node) NodeType(javax.jcr.nodetype.NodeType) RepositoryException(javax.jcr.RepositoryException) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName)

Example 2 with NodeTypeProperty

use of org.apache.jackrabbit.webdav.jcr.nodetype.NodeTypeProperty in project jackrabbit by apache.

the class DefaultItemCollection method initProperties.

/**
     * Fill the property set for this resource.
     */
@Override
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;
        // add node-specific resource properties
        try {
            properties.add(new NodeTypeProperty(JCR_PRIMARYNODETYPE, n.getPrimaryNodeType(), false));
            properties.add(new NodeTypeProperty(JCR_MIXINNODETYPES, n.getMixinNodeTypes(), false));
        } catch (RepositoryException e) {
            log.error("Failed to retrieve node-specific property: " + e);
        }
    }
}
Also used : NodeTypeProperty(org.apache.jackrabbit.webdav.jcr.nodetype.NodeTypeProperty) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException)

Aggregations

Node (javax.jcr.Node)2 RepositoryException (javax.jcr.RepositoryException)2 NodeTypeProperty (org.apache.jackrabbit.webdav.jcr.nodetype.NodeTypeProperty)2 Set (java.util.Set)1 NodeType (javax.jcr.nodetype.NodeType)1 DavException (org.apache.jackrabbit.webdav.DavException)1 JcrDavPropertyNameSet (org.apache.jackrabbit.webdav.jcr.property.JcrDavPropertyNameSet)1 DavPropertyName (org.apache.jackrabbit.webdav.property.DavPropertyName)1