use of org.apache.jackrabbit.webdav.property.DavPropertyName in project jackrabbit by apache.
the class DefaultHandler method setJcrProperty.
/**
* @param property dav property
* @param contentNode the content node
* @throws RepositoryException if an error during repository access occurs.
*/
private void setJcrProperty(DavProperty<?> property, Node contentNode) throws RepositoryException {
// Retrieve the property value. Note, that a 'null' value is replaced
// by empty string, since setting a jcr property value to 'null'
// would be equivalent to its removal.
String value = "";
if (property.getValue() != null) {
value = property.getValue().toString();
}
DavPropertyName davName = property.getName();
if (DavPropertyName.GETCONTENTTYPE.equals(davName)) {
String mimeType = IOUtil.getMimeType(value);
String encoding = IOUtil.getEncoding(value);
contentNode.setProperty(JcrConstants.JCR_MIMETYPE, mimeType);
contentNode.setProperty(JcrConstants.JCR_ENCODING, encoding);
} else {
contentNode.setProperty(getJcrName(davName, contentNode.getSession()), value);
}
}
use of org.apache.jackrabbit.webdav.property.DavPropertyName in project jackrabbit by apache.
the class DefaultHandler method exportProperties.
public boolean exportProperties(PropertyExportContext exportContext, boolean isCollection) throws RepositoryException {
if (!canExport(exportContext, isCollection)) {
throw new RepositoryException("PropertyHandler " + getName() + " failed to export properties.");
}
Node cn = getContentNode(exportContext, isCollection);
try {
// export the properties common with normal I/O handling
exportProperties(exportContext, isCollection, cn);
// export all other properties as well
PropertyIterator it = cn.getProperties();
while (it.hasNext()) {
Property p = it.nextProperty();
String name = p.getName();
PropertyDefinition def = p.getDefinition();
if (def.isMultiple() || isDefinedByFilteredNodeType(def)) {
log.debug("Skip property '" + name + "': not added to webdav property set.");
continue;
}
if (JcrConstants.JCR_DATA.equals(name) || JcrConstants.JCR_MIMETYPE.equals(name) || JcrConstants.JCR_ENCODING.equals(name) || JcrConstants.JCR_LASTMODIFIED.equals(name)) {
continue;
}
DavPropertyName davName = getDavName(name, p.getSession());
exportContext.setProperty(davName, p.getValue().getString());
}
return true;
} catch (IOException e) {
// should not occur (log output see 'exportProperties')
return false;
}
}
use of org.apache.jackrabbit.webdav.property.DavPropertyName in project jackrabbit by apache.
the class ExpandPropertyReport method getResponse.
/**
* Builds a <code>MultiStatusResponse</code> for the given resource respecting
* the properties specified. Any property that represents a {@link HrefProperty}
* is expanded: It's name equals the name of a valid {@link HrefProperty}.
* However the value of that given property (consisting of one or multiple DAV:href elements)
* is replaced by the Xml representation of a separate
* {@link MultiStatusResponse multistatus responses} for the
* resource referenced by the given DAV:href elements. The responses may
* themselves have properties, which are defined by the separate list.
*
* @param res
* @param propertyElements
* @return <code>MultiStatusResponse</code> for the given resource.
* @see ExpandProperty
*/
private MultiStatusResponse getResponse(DavResource res, Iterator<Element> propertyElements) {
MultiStatusResponse resp = new MultiStatusResponse(res.getHref(), null);
while (propertyElements.hasNext()) {
Element propertyElem = propertyElements.next();
// retrieve the localName present in the "name" attribute
String nameAttr = propertyElem.getAttribute(ATTR_NAME);
if (nameAttr == null || "".equals(nameAttr)) {
// NOTE: this is not valid according to the DTD
continue;
}
// retrieve the namespace present in the "namespace" attribute
// NOTE: if this attribute is missing the DAV: namespace represents the default.
String namespaceAttr = propertyElem.getAttribute(ATTR_NAMESPACE);
Namespace namespace = (namespaceAttr != null) ? Namespace.getNamespace(namespaceAttr) : NAMESPACE;
DavPropertyName propName = DavPropertyName.create(nameAttr, namespace);
DavProperty<?> p = res.getProperty(propName);
if (p != null) {
if (p instanceof HrefProperty && res instanceof DeltaVResource) {
ElementIterator it = DomUtil.getChildren(propertyElem, XML_PROPERTY, NAMESPACE);
resp.add(new ExpandProperty((DeltaVResource) res, (HrefProperty) p, it));
} else {
resp.add(p);
}
} else {
resp.add(propName, DavServletResponse.SC_NOT_FOUND);
}
}
return resp;
}
use of org.apache.jackrabbit.webdav.property.DavPropertyName in project jackrabbit by apache.
the class RepositoryServiceImpl method internalGetPrivilegeDefinitions.
private PrivilegeDefinition[] internalGetPrivilegeDefinitions(SessionInfo sessionInfo, String uri) throws RepositoryException {
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(SecurityConstants.SUPPORTED_PRIVILEGE_SET);
HttpPropfind request = null;
try {
request = new HttpPropfind(uri, nameSet, DEPTH_0);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
if (mresponses.length < 1) {
throw new PathNotFoundException("Unable to retrieve privileges definitions.");
}
DavPropertyName displayName = SecurityConstants.SUPPORTED_PRIVILEGE_SET;
DavProperty<?> p = mresponses[0].getProperties(DavServletResponse.SC_OK).get(displayName);
if (p == null) {
return new PrivilegeDefinition[0];
} else {
// build PrivilegeDefinition(s) from the supported-privileges dav property
Map<Name, SupportedPrivilege> spMap = new HashMap<Name, SupportedPrivilege>();
fillSupportedPrivilegeMap(new SupportedPrivilegeSetProperty(p).getValue(), spMap, getNameFactory());
List<PrivilegeDefinition> pDefs = new ArrayList<PrivilegeDefinition>();
for (Name privilegeName : spMap.keySet()) {
SupportedPrivilege sp = spMap.get(privilegeName);
Set<Name> aggrnames = null;
SupportedPrivilege[] aggregates = sp.getSupportedPrivileges();
if (aggregates != null && aggregates.length > 0) {
aggrnames = new HashSet<Name>();
for (SupportedPrivilege aggregate : aggregates) {
Name aggregateName = nameFactory.create(aggregate.getPrivilege().getNamespace().getURI(), aggregate.getPrivilege().getName());
aggrnames.add(aggregateName);
}
}
PrivilegeDefinition def = new PrivilegeDefinitionImpl(privilegeName, sp.isAbstract(), aggrnames);
pDefs.add(def);
}
return pDefs.toArray(new PrivilegeDefinition[pDefs.size()]);
}
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
use of org.apache.jackrabbit.webdav.property.DavPropertyName in project jackrabbit by apache.
the class DefaultItemCollection method alterProperties.
/**
* Loops over the given <code>List</code>s and alters the properties accordingly.
* Changes are persisted at the end according to the rules defined with
* the {@link AbstractItemResource#complete()} method.<p>
* Please note: since there is only a single property
* ({@link ItemResourceConstants#JCR_MIXINNODETYPES}
* that can be set or removed with PROPPATCH, this method either succeeds
* or throws an exception, even if this violates RFC 2518. Thus no property
* specific multistatus will be created in case of an error.
*
* @param changeList
* @return
* @throws DavException
*/
@Override
public MultiStatusResponse alterProperties(List<? extends PropEntry> changeList) throws DavException {
for (PropEntry propEntry : changeList) {
if (propEntry instanceof DavPropertyName) {
// use the internal remove method in order to prevent premature 'save'
DavPropertyName propName = (DavPropertyName) propEntry;
internalRemoveProperty(propName);
} else if (propEntry instanceof DavProperty) {
// use the internal set method in order to prevent premature 'save'
DavProperty<?> prop = (DavProperty<?>) propEntry;
internalSetProperty(prop);
} else {
throw new IllegalArgumentException("unknown object in change list: " + propEntry.getClass().getName());
}
}
// TODO: missing undo of successful set/remove if subsequent operation fails
// NOTE, that this is relevant with transactions only.
// success: save all changes together if no error occurred
complete();
return new MultiStatusResponse(getHref(), DavServletResponse.SC_OK);
}
Aggregations