use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.
the class OrderPatch method createFromXml.
// ------------------------------------------------------< static method >---
/**
* Create a new <code>OrderPath</code> object.
*
* @param orderPatchElement
* @throws IllegalArgumentException if the specified Xml element was not valid.
*/
public static OrderPatch createFromXml(Element orderPatchElement) throws DavException {
if (!DomUtil.matches(orderPatchElement, XML_ORDERPATCH, NAMESPACE)) {
log.warn("ORDERPATH request body must start with an 'orderpatch' element.");
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
// retrieve the href of the orderingtype element
String orderingType;
Element otype = DomUtil.getChildElement(orderPatchElement, XML_ORDERING_TYPE, NAMESPACE);
if (otype != null) {
orderingType = DomUtil.getChildText(otype, DavConstants.XML_HREF, DavConstants.NAMESPACE);
} else {
log.warn("ORDERPATH request body must contain an 'ordering-type' child element.");
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
// set build the list of ordering instructions
List<Member> tmpList = new ArrayList<Member>();
ElementIterator it = DomUtil.getChildren(orderPatchElement, XML_ORDER_MEMBER, NAMESPACE);
while (it.hasNext()) {
Element el = it.nextElement();
try {
// retrieve text 'DAV:segment' child of this DAV:order-member element
String segment = DomUtil.getChildText(el, XML_SEGMENT, NAMESPACE);
// retrieve the 'DAV:position' child element
Position pos = Position.createFromXml(DomUtil.getChildElement(el, XML_POSITION, NAMESPACE));
Member om = new Member(segment, pos);
tmpList.add(om);
} catch (IllegalArgumentException e) {
log.warn("Invalid element in 'orderpatch' request body: " + e.getMessage());
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
}
Member[] instructions = tmpList.toArray(new Member[tmpList.size()]);
return new OrderPatch(orderingType, instructions);
}
use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.
the class WebdavRequestImpl method parsePropPatchRequest.
/**
* Parse the PROPPATCH request body.
*/
private void parsePropPatchRequest() throws DavException {
proppatchSet = new DavPropertySet();
proppatchList = new ArrayList<PropEntry>();
Document requestDocument = getRequestDocument();
if (requestDocument == null) {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid request body.");
}
Element root = requestDocument.getDocumentElement();
if (!DomUtil.matches(root, XML_PROPERTYUPDATE, NAMESPACE)) {
log.warn("PropPatch-Request has no <DAV:propertyupdate> tag.");
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "PropPatch-Request has no <propertyupdate> tag.");
}
ElementIterator it = DomUtil.getChildren(root);
while (it.hasNext()) {
Element el = it.nextElement();
if (DomUtil.matches(el, XML_SET, NAMESPACE)) {
Element propEl = DomUtil.getChildElement(el, XML_PROP, NAMESPACE);
if (propEl != null) {
ElementIterator properties = DomUtil.getChildren(propEl);
while (properties.hasNext()) {
DavProperty<?> davProp = DefaultDavProperty.createFromXml(properties.nextElement());
proppatchSet.add(davProp);
proppatchList.add(davProp);
}
}
} else if (DomUtil.matches(el, XML_REMOVE, NAMESPACE)) {
Element propEl = DomUtil.getChildElement(el, XML_PROP, NAMESPACE);
if (propEl != null) {
ElementIterator properties = DomUtil.getChildren(propEl);
while (properties.hasNext()) {
DavProperty<?> davProp = DefaultDavProperty.createFromXml(properties.nextElement());
proppatchSet.add(davProp);
proppatchList.add(davProp.getName());
}
}
} else {
log.debug("Unknown element in DAV:propertyupdate: " + el.getNodeName());
// unknown child elements are ignored
}
}
}
use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.
the class MultiStatus method createFromXml.
/**
* Build a <code>MultiStatus</code> from the specified xml element.
*
* @param multistatusElement
* @return new <code>MultiStatus</code> instance.
* @throws IllegalArgumentException if the given document is <code>null</code>
* or does not provide the required element.
*/
public static MultiStatus createFromXml(Element multistatusElement) {
if (!DomUtil.matches(multistatusElement, XML_MULTISTATUS, NAMESPACE)) {
throw new IllegalArgumentException("DAV:multistatus element expected.");
}
MultiStatus multistatus = new MultiStatus();
ElementIterator it = DomUtil.getChildren(multistatusElement, XML_RESPONSE, NAMESPACE);
while (it.hasNext()) {
Element respElem = it.nextElement();
MultiStatusResponse response = MultiStatusResponse.createFromXml(respElem);
multistatus.addResponse(response);
}
// optional response description on the multistatus element
multistatus.setResponseDescription(DomUtil.getChildText(multistatusElement, XML_RESPONSEDESCRIPTION, NAMESPACE));
return multistatus;
}
use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.
the class ParentElement method createFromXml.
/**
* Build an <code>ParentElement</code> object from an XML element DAV:parent
*
* @param root the DAV:parent element
* @return a ParentElement object
* @throws org.apache.jackrabbit.webdav.DavException if the DAV:parent element is malformed
*/
public static ParentElement createFromXml(Element root) throws DavException {
if (!DomUtil.matches(root, BindConstants.XML_PARENT, BindConstants.NAMESPACE)) {
log.warn("DAV:paret element expected");
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
String href = null;
String segment = null;
ElementIterator it = DomUtil.getChildren(root);
while (it.hasNext()) {
Element elt = it.nextElement();
if (DomUtil.matches(elt, BindConstants.XML_SEGMENT, BindConstants.NAMESPACE)) {
if (segment == null) {
segment = DomUtil.getText(elt);
} else {
log.warn("unexpected multiple occurrence of DAV:segment element");
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
} else if (DomUtil.matches(elt, BindConstants.XML_HREF, BindConstants.NAMESPACE)) {
if (href == null) {
href = DomUtil.getText(elt);
} else {
log.warn("unexpected multiple occurrence of DAV:href element");
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
} else {
log.warn("unexpected element " + elt.getLocalName());
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
}
if (href == null) {
log.warn("DAV:href element expected");
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
if (segment == null) {
log.warn("DAV:segment element expected");
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
return new ParentElement(href, segment);
}
use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.
the class ResourceConfig method setParameters.
/**
* Retrieve 'param' elements for the specified <code>xmlElement</code> and
* use the public setter methods of the given <code>instance</code> to set
* the corresponding instance fields.
*
* @param instance
* @param xmlElement
*/
private static void setParameters(Object instance, Element xmlElement) {
ElementIterator paramElems = DomUtil.getChildren(xmlElement, ELEMENT_PARAM, Namespace.EMPTY_NAMESPACE);
if (paramElems.hasNext()) {
Map<String, Method> setters = getSetters(instance.getClass());
if (!setters.isEmpty()) {
while (paramElems.hasNext()) {
Element parameter = paramElems.next();
String name = DomUtil.getAttribute(parameter, ATTR_NAME, null);
String value = DomUtil.getAttribute(parameter, ATTR_VALUE, null);
if (name == null || value == null) {
log.error("Parameter name or value missing -> ignore.");
continue;
}
Method setter = setters.get(name);
if (setter != null) {
Class<?> type = setter.getParameterTypes()[0];
try {
if (type.isAssignableFrom(String.class) || type.isAssignableFrom(Object.class)) {
setter.invoke(instance, value);
} else if (type.isAssignableFrom(Boolean.TYPE) || type.isAssignableFrom(Boolean.class)) {
setter.invoke(instance, Boolean.valueOf(value));
} else if (type.isAssignableFrom(Integer.TYPE) || type.isAssignableFrom(Integer.class)) {
setter.invoke(instance, Integer.valueOf(value));
} else if (type.isAssignableFrom(Long.TYPE) || type.isAssignableFrom(Long.class)) {
setter.invoke(instance, Long.valueOf(value));
} else if (type.isAssignableFrom(Double.TYPE) || type.isAssignableFrom(Double.class)) {
setter.invoke(instance, Double.valueOf(value));
} else {
log.error("Cannot set configuration property " + name);
}
} catch (Exception e) {
log.error("Invalid format (" + value + ") for property " + name + " of class " + instance.getClass().getName(), e);
}
}
}
}
}
}
Aggregations