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);
}
}
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);
}
}
}
Aggregations