use of io.milton.http.webdav.PropFindResponse.NameAndError in project lobcder by skoulouzis.
the class PropPatchJsonResource method sendContent.
public void sendContent(OutputStream out, Range range, Map<String, String> params, String contentType) throws IOException, NotAuthorizedException {
log.debug("sendContent");
JsonConfig cfg = new JsonConfig();
cfg.setIgnoreTransientFields(true);
cfg.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
List<FieldError> errors = new ArrayList<FieldError>();
if (resp != null && resp.getErrorProperties() != null) {
log.debug("error props: " + resp.getErrorProperties().size());
for (Status stat : resp.getErrorProperties().keySet()) {
List<NameAndError> props = resp.getErrorProperties().get(stat);
for (NameAndError ne : props) {
errors.add(new FieldError(ne.getName().getLocalPart(), ne.getError(), stat.code));
}
}
}
log.debug("errors size: " + errors.size());
FieldError[] arr = new FieldError[errors.size()];
arr = errors.toArray(arr);
Writer writer = new PrintWriter(out);
JSON json = JSONSerializer.toJSON(arr, cfg);
json.write(writer);
writer.flush();
}
use of io.milton.http.webdav.PropFindResponse.NameAndError 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