use of io.milton.resource.CollectionResource 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);
}
}
}
}
}
use of io.milton.resource.CollectionResource in project lobcder by skoulouzis.
the class CopyJsonResource method processForm.
public String processForm(Map<String, String> parameters, Map<String, FileItem> files) throws BadRequestException, NotAuthorizedException {
String dest = parameters.get("destination");
Path pDest = Path.path(dest);
Resource rDestParent = resourceFactory.getResource(host, pDest.getParent().toString());
if (rDestParent == null)
throw new BadRequestException(wrapped, "The destination parent does not exist");
if (rDestParent instanceof CollectionResource) {
CollectionResource colDestParent = (CollectionResource) rDestParent;
if (colDestParent.child(pDest.getName()) == null) {
try {
wrapped.copyTo(colDestParent, pDest.getName());
} catch (ConflictException ex) {
log.warn("Exception copying to: " + pDest.getName(), ex);
throw new BadRequestException(rDestParent, "conflict: " + ex.getMessage());
}
return null;
} else {
log.warn("destination already exists: " + pDest.getName());
throw new BadRequestException(rDestParent, "File already exists");
}
} else {
throw new BadRequestException(wrapped, "The destination parent is not a collection resource");
}
}
use of io.milton.resource.CollectionResource in project lobcder by skoulouzis.
the class PutHelper method findNearestParent.
public CollectionResource findNearestParent(HttpManager manager, String host, Path path) throws NotAuthorizedException, ConflictException, BadRequestException {
if (path == null) {
return null;
}
Resource thisResource = manager.getResourceFactory().getResource(host, path.toString());
if (thisResource != null) {
if (thisResource instanceof CollectionResource) {
return (CollectionResource) thisResource;
} else {
log.warn("parent is not a collection: " + path);
return null;
}
}
CollectionResource parent = findNearestParent(manager, host, path.getParent());
return parent;
}
use of io.milton.resource.CollectionResource in project lobcder by skoulouzis.
the class FckFileManagerResource method find.
private Resource find(CollectionResource wrappedResource, Path p) throws NotAuthorizedException, BadRequestException {
Resource r = wrappedResource;
for (String s : p.getParts()) {
if (r instanceof CollectionResource) {
CollectionResource col = (CollectionResource) r;
r = col.child(s);
if (r == null) {
log.trace("not found: " + s + " in path: " + p);
return null;
}
} else {
log.trace("not a collection: " + r.getName() + " in path: " + p);
return null;
}
}
return r;
}
Aggregations