use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.
the class RepositoryServiceImpl method getRepositoryDescriptors.
@Override
public Map<String, QValue[]> getRepositoryDescriptors() throws RepositoryException {
if (descriptors.isEmpty()) {
ReportInfo info = new ReportInfo(JcrRemotingConstants.REPORT_REPOSITORY_DESCRIPTORS, ItemResourceConstants.NAMESPACE);
HttpReport request = null;
try {
request = new HttpReport(uriResolver.getRepositoryUri(), info);
HttpResponse response = executeRequest(null, request);
int sc = response.getStatusLine().getStatusCode();
if (sc == HttpStatus.SC_UNAUTHORIZED || sc == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) {
// JCR-3076: Mandatory authentication prevents us from
// accessing the descriptors on the server, so instead
// of failing with an exception we simply return an empty
// set of descriptors
log.warn("Authentication required to access repository descriptors");
return descriptors;
}
request.checkSuccess(response);
Document doc = request.getResponseBodyAsDocument(response.getEntity());
if (doc != null) {
Element rootElement = doc.getDocumentElement();
ElementIterator nsElems = DomUtil.getChildren(rootElement, JcrRemotingConstants.XML_DESCRIPTOR, ItemResourceConstants.NAMESPACE);
while (nsElems.hasNext()) {
Element elem = nsElems.nextElement();
String key = DomUtil.getChildText(elem, JcrRemotingConstants.XML_DESCRIPTORKEY, ItemResourceConstants.NAMESPACE);
ElementIterator it = DomUtil.getChildren(elem, JcrRemotingConstants.XML_DESCRIPTORVALUE, ItemResourceConstants.NAMESPACE);
List<QValue> vs = new ArrayList<QValue>();
while (it.hasNext()) {
Element dv = it.nextElement();
String descriptor = DomUtil.getText(dv);
if (key != null && descriptor != null) {
String typeStr = (DomUtil.getAttribute(dv, JcrRemotingConstants.ATTR_VALUE_TYPE, null));
int type = (typeStr == null) ? PropertyType.STRING : PropertyType.valueFromName(typeStr);
vs.add(getQValueFactory().create(descriptor, type));
} else {
log.error("Invalid descriptor key / value pair: " + key + " -> " + descriptor);
}
}
descriptors.put(key, vs.toArray(new QValue[vs.size()]));
}
}
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
return descriptors;
}
use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.
the class SubscriptionDiscovery method createFromXml.
// -----------------------------------------------------< static Factory >---
public static SubscriptionDiscovery createFromXml(Element sDiscoveryElement) {
if (!DomUtil.matches(sDiscoveryElement, ObservationConstants.SUBSCRIPTIONDISCOVERY.getName(), ObservationConstants.SUBSCRIPTIONDISCOVERY.getNamespace())) {
throw new IllegalArgumentException("'subscriptiondiscovery' element expected.");
}
List<Subscription> subscriptions = new ArrayList<Subscription>();
ElementIterator it = DomUtil.getChildren(sDiscoveryElement, ObservationConstants.XML_SUBSCRIPTION, ObservationConstants.NAMESPACE);
while (it.hasNext()) {
final Element sb = it.nextElement();
// anonymous inner class: Subscription interface
Subscription s = new Subscription() {
/**
* @see Subscription#getSubscriptionId()
*/
public String getSubscriptionId() {
Element ltEl = DomUtil.getChildElement(sb, ObservationConstants.XML_SUBSCRIPTIONID, ObservationConstants.NAMESPACE);
if (ltEl != null) {
return DomUtil.getChildText(sb, DavConstants.XML_HREF, DavConstants.NAMESPACE);
}
return null;
}
public boolean eventsProvideNodeTypeInformation() {
String t = DomUtil.getChildText(sb, ObservationConstants.XML_EVENTSWITHTYPES, ObservationConstants.NAMESPACE);
return t == null ? false : Boolean.parseBoolean(t);
}
public boolean eventsProvideNoLocalFlag() {
String t = DomUtil.getChildText(sb, ObservationConstants.XML_EVENTSWITHLOCALFLAG, ObservationConstants.NAMESPACE);
return t == null ? false : Boolean.parseBoolean(t);
}
/**
* @see XmlSerializable#toXml(Document)
*/
public Element toXml(Document document) {
return (Element) document.importNode(sb, true);
}
};
subscriptions.add(s);
}
return new SubscriptionDiscovery(subscriptions.toArray(new Subscription[subscriptions.size()]));
}
use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.
the class DefaultEventType method createFromXml.
/**
* Retrieves one or multiple <code>EventType</code>s from the 'eventtype'
* Xml element. While a subscription may register multiple types (thus
* the 'eventtype' contains multiple child elements), a single event may only
* refer to one single type.
*
* @param eventType
* @return
*/
public static EventType[] createFromXml(Element eventType) {
if (!DomUtil.matches(eventType, ObservationConstants.XML_EVENTTYPE, ObservationConstants.NAMESPACE)) {
throw new IllegalArgumentException("'eventtype' element expected which contains a least a single child element.");
}
List<EventType> etypes = new ArrayList<EventType>();
ElementIterator it = DomUtil.getChildren(eventType);
while (it.hasNext()) {
Element el = it.nextElement();
etypes.add(create(el.getLocalName(), DomUtil.getNamespace(el)));
}
return etypes.toArray(new EventType[etypes.size()]);
}
use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.
the class EventDiscovery method createFromXml.
/**
* Build a <code>EventDiscovery</code> from the specified xml element.
*
* @param eventDiscoveryElement
* @return new <code>EventDiscovery</code> instance.
* @throws IllegalArgumentException if the given document is <code>null</code>
* or does not provide the required element.
*/
public static EventDiscovery createFromXml(Element eventDiscoveryElement) {
if (!DomUtil.matches(eventDiscoveryElement, XML_EVENTDISCOVERY, ObservationConstants.NAMESPACE)) {
throw new IllegalArgumentException("{" + ObservationConstants.NAMESPACE + "}" + XML_EVENTDISCOVERY + " element expected, but got: {" + eventDiscoveryElement.getNamespaceURI() + "}" + eventDiscoveryElement.getLocalName());
}
EventDiscovery eventDiscovery = new EventDiscovery();
ElementIterator it = DomUtil.getChildren(eventDiscoveryElement, XML_EVENTBUNDLE, ObservationConstants.NAMESPACE);
while (it.hasNext()) {
final Element ebElement = it.nextElement();
EventBundle eb = new EventBundle() {
public Element toXml(Document document) {
return (Element) document.importNode(ebElement, true);
}
};
eventDiscovery.addEventBundle(eb);
}
return eventDiscovery;
}
use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.
the class Position method createFromXml.
// -----------------------------------------------------< static methods >---
/**
* Create a new <code>Position</code> object from the specified position
* element. The element must fulfill the following structure:<br>
* <pre>
* <!ELEMENT position (first | last | before | after) >
* <!ELEMENT segment (#PCDATA) >
* <!ELEMENT first EMPTY >
* <!ELEMENT last EMPTY >
* <!ELEMENT before segment >
* <!ELEMENT after segment >
* </pre>
*
* @param positionElement Xml element defining the position.
* @throws IllegalArgumentException if the given Xml element is not valid.
*/
public static Position createFromXml(Element positionElement) {
if (!DomUtil.matches(positionElement, XML_POSITION, NAMESPACE)) {
throw new IllegalArgumentException("The 'DAV:position' element required.");
}
ElementIterator it = DomUtil.getChildren(positionElement);
if (it.hasNext()) {
Element el = it.nextElement();
String type = el.getLocalName();
// read the text of DAV:segment child element inside the type
String segmentText = DomUtil.getChildText(el, XML_SEGMENT, NAMESPACE);
// stop after the first iteration
return new Position(type, segmentText);
} else {
throw new IllegalArgumentException("The 'DAV:position' element required with exact one child indicating the type.");
}
}
Aggregations