use of io.milton.resource.PropFindableResource in project lobcder by skoulouzis.
the class PropFindHandler method processExistingResource.
@Override
public void processExistingResource(HttpManager manager, Request request, Response response, Resource resource) throws NotAuthorizedException, BadRequestException, ConflictException {
log.trace("processExistingResource");
PropFindableResource pfr = (PropFindableResource) resource;
int depth = request.getDepthHeader();
response.setStatus(Response.Status.SC_MULTI_STATUS);
response.setContentTypeHeader(Response.XML);
PropertiesRequest parseResult;
try {
parseResult = requestFieldParser.getRequestedFields(request.getInputStream());
} catch (IOException ex) {
throw new RuntimeException(ex);
}
String url = request.getAbsoluteUrl();
// Check that the current user has permission to write requested fields
Set<QName> allFields = getAllFields(parseResult, pfr);
Set<PropertyAuthoriser.CheckResult> errorFields = permissionService.checkPermissions(request, request.getMethod(), PropertyAuthoriser.PropertyPermission.READ, allFields, resource);
if (errorFields != null && errorFields.size() > 0) {
if (log.isTraceEnabled()) {
log.trace("permissionService denied access: " + permissionService.getClass().getCanonicalName());
}
responseHandler.respondUnauthorised(resource, response, request);
} else {
List<PropFindResponse> propFindResponses;
try {
propFindResponses = propertyBuilder.buildProperties(pfr, depth, parseResult, url);
} catch (URISyntaxException ex) {
log.error("Exception parsing url. request class: " + request.getClass() + ". Please check the client application is usign percentage encoding (see http://en.wikipedia.org/wiki/Percent-encoding)");
throw new RuntimeException("Exception parsing url, indicating the requested URL is not correctly encoded. Please check the client application. Requested url is: " + url, ex);
}
if (log.isTraceEnabled()) {
log.trace("responses: " + propFindResponses.size());
}
responseHandler.respondPropFind(propFindResponses, response, request, pfr);
}
}
use of io.milton.resource.PropFindableResource in project lobcder by skoulouzis.
the class DefaultPropFindPropertyBuilder method processResource.
@Override
public void processResource(List<PropFindResponse> responses, PropFindableResource resource, PropertiesRequest parseResult, String href, int requestedDepth, int currentDepth, String collectionHref) throws NotAuthorizedException, BadRequestException {
final LinkedHashMap<QName, ValueAndType> knownProperties = new LinkedHashMap<QName, ValueAndType>();
final ArrayList<NameAndError> unknownProperties = new ArrayList<NameAndError>();
if (resource instanceof CollectionResource) {
if (!href.endsWith("/")) {
href = href + "/";
}
}
Set<QName> requestedFields;
if (parseResult.isAllProp()) {
requestedFields = findAllProps(resource);
} else {
requestedFields = parseResult.getNames();
}
Iterator<QName> it = requestedFields.iterator();
while (it.hasNext()) {
QName field = it.next();
LogUtils.trace(log, "processResoource: find property:", field);
if (field.getLocalPart().equals("href")) {
knownProperties.put(field, new ValueAndType(href, String.class));
} else {
boolean found = false;
for (PropertySource source : propertySources) {
LogUtils.trace(log, "look for field", field, " in property source", source.getClass());
PropertyMetaData meta = source.getPropertyMetaData(field, resource);
if (meta != null && !meta.isUnknown()) {
Object val;
try {
val = source.getProperty(field, resource);
LogUtils.trace(log, "processResource: got value", val, "from source", source.getClass());
if (val == null) {
// null, but we still need type information to write it so use meta
knownProperties.put(field, new ValueAndType(val, meta.getValueType()));
} else {
// non-null, so use more robust class info
knownProperties.put(field, new ValueAndType(val, val.getClass()));
}
} catch (NotAuthorizedException ex) {
unknownProperties.add(new NameAndError(field, "Not authorised"));
}
found = true;
break;
}
}
if (!found) {
if (log.isDebugEnabled()) {
log.debug("property not found in any property source: " + field.toString());
}
unknownProperties.add(new NameAndError(field, null));
}
}
}
if (log.isDebugEnabled()) {
if (unknownProperties.size() > 0) {
log.debug("some properties could not be resolved. Listing property sources:");
for (PropertySource ps : propertySources) {
log.debug(" - " + ps.getClass().getCanonicalName());
}
}
}
// Map<Status, List<NameAndError>> errorProperties = new HashMap<Status, List<NameAndError>>();
Map<Status, List<NameAndError>> errorProperties = new EnumMap<Status, List<NameAndError>>(Status.class);
errorProperties.put(Status.SC_NOT_FOUND, unknownProperties);
PropFindResponse r = new PropFindResponse(href, knownProperties, errorProperties);
responses.add(r);
if (requestedDepth > currentDepth && resource instanceof CollectionResource) {
CollectionResource col = (CollectionResource) resource;
List<? extends Resource> list = col.getChildren();
list = new ArrayList<Resource>(list);
for (Resource child : list) {
if (child instanceof PropFindableResource) {
String childName = child.getName();
if (childName == null) {
log.warn("null name for resource of type: " + child.getClass() + " in folder: " + href + " WILL NOT be returned in PROPFIND response!!");
} else {
String childHref = href + Utils.percentEncode(childName);
// Note that the new collection href, is just the current href
processResource(responses, (PropFindableResource) child, parseResult, childHref, requestedDepth, currentDepth + 1, href);
}
}
}
}
}
Aggregations