use of org.apache.jackrabbit.webdav.property.DavPropertyName 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.property.DavPropertyName in project jackrabbit by apache.
the class VersionControlledItemCollection method resolveMergeConflict.
/**
* Resolve one or multiple merge conflicts present on this resource. Please
* note that the 'setProperties' or 'removeProperties' set my contain additional
* resource properties, that need to be changed. Those properties are left
* untouched, whereas the {@link #AUTO_MERGE_SET DAV:auto-merge-set}, is
* removed from the list upon successful resolution of a merge conflict.<br>
* If the removeProperties or setProperties set do not contain the mentioned
* merge conflict resource properties or if the value of those properties do
* not allow for a resolution of an existing merge conflict, this method
* returns silently.
*
* @param changeList
* @throws org.apache.jackrabbit.webdav.DavException
* @see Node#doneMerge(Version)
* @see Node#cancelMerge(Version)
*/
private void resolveMergeConflict(List<? extends PropEntry> changeList) throws DavException {
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
try {
Node n = (Node) item;
VersionManager vMgr = getVersionManager();
String path = item.getPath();
DavProperty<?> autoMergeSet = null;
DavProperty<?> predecessorSet = null;
/* find DAV:auto-merge-set entries. If none exists no attempt is made
to resolve merge conflict > return silently */
for (int i = 0; i < changeList.size(); i++) {
PropEntry propEntry = changeList.get(i);
// conflicts are resolved with 'cancel'
if (propEntry instanceof DavPropertyName && AUTO_MERGE_SET.equals(propEntry)) {
// retrieve the current jcr:mergeFailed property values
if (!n.hasProperty(JcrConstants.JCR_MERGEFAILED)) {
throw new DavException(DavServletResponse.SC_CONFLICT, "Attempt to resolve non-existing merge conflicts.");
}
Value[] mergeFailed = n.getProperty(JcrConstants.JCR_MERGEFAILED).getValues();
for (Value value : mergeFailed) {
vMgr.cancelMerge(path, (Version) getRepositorySession().getNodeByIdentifier(value.getString()));
}
// remove this entry from the changeList
changeList.remove(propEntry);
} else if (propEntry instanceof DavProperty) {
if (AUTO_MERGE_SET.equals(((DavProperty<?>) propEntry).getName())) {
autoMergeSet = (DavProperty<?>) propEntry;
} else if (PREDECESSOR_SET.equals(((DavProperty<?>) propEntry).getName())) {
predecessorSet = (DavProperty<?>) propEntry;
}
}
}
// resolved individually according to the DAV:predecessor-set property.
if (autoMergeSet != null) {
// retrieve the current jcr:mergeFailed property values
if (!n.hasProperty(JcrConstants.JCR_MERGEFAILED)) {
throw new DavException(DavServletResponse.SC_CONFLICT, "Attempt to resolve non-existing merge conflicts.");
}
List<String> mergeset = new HrefProperty(autoMergeSet).getHrefs();
List<String> predecL;
if (predecessorSet == null) {
predecL = Collections.emptyList();
} else {
predecL = new HrefProperty(predecessorSet).getHrefs();
}
Session session = getRepositorySession();
// loop over the mergeFailed values (versions) and test whether they are
// removed from the DAV:auto-merge-set thus indicating resolution.
Value[] mergeFailed = n.getProperty(JcrConstants.JCR_MERGEFAILED).getValues();
for (Value value : mergeFailed) {
// build version-href from each entry in the jcr:mergeFailed property
// in order to be able to compare to the entries in the HrefProperty.
Version version = (Version) session.getNodeByIdentifier(value.getString());
String href = getLocatorFromItem(version).getHref(true);
// thus indicating that this merge conflict needs to be resolved.
if (!mergeset.contains(href)) {
// must be called.
if (predecL.contains(href)) {
vMgr.doneMerge(path, version);
} else {
vMgr.cancelMerge(path, version);
}
}
}
// after successful resolution of merge-conflicts according to
// DAV:auto-merge-set and DAV:predecessor-set remove these entries
// from the changeList.
changeList.remove(autoMergeSet);
if (predecessorSet != null) {
changeList.remove(predecessorSet);
}
}
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
use of org.apache.jackrabbit.webdav.property.DavPropertyName in project jackrabbit by apache.
the class DefaultHandler method importProperties.
public Map<? extends PropEntry, ?> importProperties(PropertyImportContext importContext, boolean isCollection) throws RepositoryException {
if (!canImport(importContext, isCollection)) {
throw new RepositoryException("PropertyHandler " + getName() + " failed import properties");
}
// loop over List and remember all properties and propertyNames
// that failed to be imported (set or remove).
Map<PropEntry, RepositoryException> failures = new HashMap<PropEntry, RepositoryException>();
List<? extends PropEntry> changeList = importContext.getChangeList();
// for collections the import-root is the target node where properties
// are altered. in contrast 'non-collections' are with the handler
// represented by 'file' nodes, that must have a jcr:content child
// node, which holds all properties except jcr:created.
// -> see canImport for the corresponding assertions
Node cn = (Node) importContext.getImportRoot();
if (!isCollection && cn.hasNode(JcrConstants.JCR_CONTENT)) {
cn = cn.getNode(JcrConstants.JCR_CONTENT);
}
if (changeList != null) {
for (PropEntry propEntry : changeList) {
try {
if (propEntry instanceof DavPropertyName) {
// remove
DavPropertyName propName = (DavPropertyName) propEntry;
removeJcrProperty(propName, cn);
} else if (propEntry instanceof DavProperty) {
// add or modify property
DavProperty<?> prop = (DavProperty<?>) propEntry;
setJcrProperty(prop, cn);
} else {
// ignore any other entry in the change list
log.error("unknown object in change list: " + propEntry.getClass().getName());
}
} catch (RepositoryException e) {
failures.put(propEntry, e);
}
}
}
if (failures.isEmpty()) {
setLastModified(cn, IOUtil.UNDEFINED_LENGTH);
}
return failures;
}
use of org.apache.jackrabbit.webdav.property.DavPropertyName in project jackrabbit by apache.
the class DefaultHandler method getDavName.
//------------------------------------------------------------< private >---
/**
* Builds a webdav property name from the given jcrName. In case the jcrName
* contains a namespace prefix that would conflict with any of the predefined
* webdav namespaces a new prefix is assigned.<br>
* Please note, that the local part of the jcrName is checked for XML
* compatibility by calling {@link ISO9075#encode(String)}
*
* @param jcrName name of the jcr property
* @param session session
* @return a <code>DavPropertyName</code> for the given jcr name.
* @throws RepositoryException if an error during repository access occurs.
*/
private DavPropertyName getDavName(String jcrName, Session session) throws RepositoryException {
// make sure the local name is xml compliant
String localName = ISO9075.encode(Text.getLocalName(jcrName));
String prefix = Text.getNamespacePrefix(jcrName);
String uri = session.getNamespaceURI(prefix);
Namespace namespace = Namespace.getNamespace(prefix, uri);
DavPropertyName name = DavPropertyName.create(localName, namespace);
return name;
}
use of org.apache.jackrabbit.webdav.property.DavPropertyName in project jackrabbit by apache.
the class RepositoryServiceImpl method getPrivilegeNames.
@Override
public Name[] getPrivilegeNames(SessionInfo sessionInfo, NodeId nodeId) throws RepositoryException {
String uri = (nodeId == null) ? uriResolver.getWorkspaceUri(sessionInfo.getWorkspaceName()) : getItemUri(nodeId, sessionInfo);
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(SecurityConstants.CURRENT_USER_PRIVILEGE_SET);
HttpPropfind propfindRequest = null;
try {
propfindRequest = new HttpPropfind(uri, nameSet, DEPTH_0);
HttpResponse response = execute(propfindRequest, sessionInfo);
propfindRequest.checkSuccess(response);
MultiStatusResponse[] mresponses = propfindRequest.getResponseBodyAsMultiStatus(response).getResponses();
if (mresponses.length < 1) {
throw new PathNotFoundException("Unable to retrieve privileges definitions.");
}
DavPropertyName displayName = SecurityConstants.CURRENT_USER_PRIVILEGE_SET;
DavProperty<?> p = mresponses[0].getProperties(DavServletResponse.SC_OK).get(displayName);
if (p == null) {
return new Name[0];
} else {
Collection<Privilege> privs = new CurrentUserPrivilegeSetProperty(p).getValue();
Set<Name> privNames = new HashSet<Name>(privs.size());
for (Privilege priv : privs) {
privNames.add(nameFactory.create(priv.getNamespace().getURI(), priv.getName()));
}
return privNames.toArray(new Name[privNames.size()]);
}
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (propfindRequest != null) {
propfindRequest.releaseConnection();
}
}
}
Aggregations