use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.
the class MergeInfo method getSourceHrefs.
/**
* Returns the URL specified with the DAV:source element or <code>null</code>
* if no such child element is present in the DAV:merge element.
*
* @return href present in the DAV:source child element or <code>null</code>.
*/
public String[] getSourceHrefs() {
List<String> sourceHrefs = new ArrayList<String>();
Element srcElem = DomUtil.getChildElement(mergeElement, DavConstants.XML_SOURCE, DavConstants.NAMESPACE);
if (srcElem != null) {
ElementIterator it = DomUtil.getChildren(srcElem, DavConstants.XML_HREF, DavConstants.NAMESPACE);
while (it.hasNext()) {
String href = DomUtil.getTextTrim(it.nextElement());
if (href != null) {
sourceHrefs.add(href);
}
}
}
return sourceHrefs.toArray(new String[sourceHrefs.size()]);
}
use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.
the class ProtectedRemoveConfig method parse.
void parse(InputStream inputStream) throws IOException {
Element config;
ProtectedItemRemoveHandler instance = null;
try {
config = DomUtil.parseDocument(inputStream).getDocumentElement();
if (config == null) {
log.warn("Missing mandatory config element");
return;
}
ElementIterator handlers = DomUtil.getChildren(config, ELEMENT_HANDLER, null);
while (handlers.hasNext()) {
Element handler = handlers.nextElement();
instance = createHandler(handler);
manager.addHandler(instance);
}
} catch (ParserConfigurationException e) {
log.error(e.getMessage(), e);
} catch (SAXException e) {
log.error(e.getMessage(), e);
}
}
use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.
the class RepositoryServiceImpl method getEvents.
@Override
public EventBundle getEvents(SessionInfo sessionInfo, EventFilter filter, long after) throws RepositoryException {
// TODO: use filters remotely (JCR-3179)
HttpGet request = null;
String rootUri = uriResolver.getWorkspaceUri(sessionInfo.getWorkspaceName());
// TODO should have a way to discover URI template
rootUri += "?type=journal";
try {
request = new HttpGet(rootUri);
// TODO
request.addHeader("If-None-Match", "\"" + Long.toHexString(after) + "\"");
initMethod(request, sessionInfo);
HttpResponse response = executeRequest(sessionInfo, request);
int status = response.getStatusLine().getStatusCode();
if (status != 200) {
throw new RepositoryException("getEvents to " + rootUri + " failed with " + response.getStatusLine());
}
HttpEntity entity = response.getEntity();
InputStream in = entity.getContent();
Document doc = null;
if (in != null) {
// read response and try to build a xml document
try {
doc = DomUtil.parseDocument(in);
} catch (ParserConfigurationException e) {
throw new IOException("XML parser configuration error", e);
} catch (SAXException e) {
throw new IOException("XML parsing error", e);
} finally {
in.close();
}
}
List<Event> events = new ArrayList<Event>();
ElementIterator entries = DomUtil.getChildren(doc.getDocumentElement(), AtomFeedConstants.N_ENTRY);
while (entries.hasNext()) {
Element entryElem = entries.next();
Element contentElem = DomUtil.getChildElement(entryElem, AtomFeedConstants.N_CONTENT);
if (contentElem != null && "application/vnd.apache.jackrabbit.event+xml".equals(contentElem.getAttribute("type"))) {
List<Event> el = buildEventList(contentElem, (SessionInfoImpl) sessionInfo, rootUri);
for (Event e : el) {
if (e.getDate() > after && (filter == null || filter.accept(e, false))) {
events.add(e);
}
}
}
}
return new EventBundleImpl(events, false);
} catch (Exception ex) {
log.error("extracting events from journal feed", ex);
throw new RepositoryException("extracting events from journal feed: " + ex.getMessage(), ex);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.
the class RepositoryServiceImpl method buildEventList.
private List<Event> buildEventList(Element bundleElement, SessionInfoImpl sessionInfo, String baseUri) throws RepositoryException {
List<Event> events = new ArrayList<Event>();
ElementIterator eventElementIterator = DomUtil.getChildren(bundleElement, ObservationConstants.N_EVENT);
String userId = null;
// get user id from enclosing Atom entry element in case this was a feed
if (DomUtil.matches(bundleElement, AtomFeedConstants.N_ENTRY)) {
Element authorEl = DomUtil.getChildElement(bundleElement, AtomFeedConstants.N_AUTHOR);
Element nameEl = authorEl != null ? DomUtil.getChildElement(authorEl, AtomFeedConstants.N_NAME) : null;
if (nameEl != null) {
userId = DomUtil.getTextTrim(nameEl);
}
}
while (eventElementIterator.hasNext()) {
Element evElem = eventElementIterator.nextElement();
Element typeEl = DomUtil.getChildElement(evElem, ObservationConstants.N_EVENTTYPE);
EventType[] et = DefaultEventType.createFromXml(typeEl);
if (et.length == 0 || et.length > 1) {
// should not occur.
log.error("Ambiguous event type definition: expected one single event type.");
continue;
}
String href = DomUtil.getChildTextTrim(evElem, XML_HREF, NAMESPACE);
int type = EventUtil.getJcrEventType(et[0].getName());
Path eventPath = null;
ItemId eventId = null;
NodeId parentId = null;
if (href != null) {
href = resolve(baseUri, href);
try {
eventPath = uriResolver.getQPath(href, sessionInfo);
} catch (RepositoryException e) {
// should not occur
log.error("Internal error while building Event: ()", e.getMessage());
continue;
}
boolean isForNode = (type == Event.NODE_ADDED || type == Event.NODE_REMOVED || type == Event.NODE_MOVED);
try {
if (isForNode) {
eventId = uriResolver.getNodeIdAfterEvent(href, sessionInfo, type == Event.NODE_REMOVED);
} else {
eventId = uriResolver.getPropertyId(href, sessionInfo);
}
} catch (RepositoryException e) {
if (isForNode) {
eventId = idFactory.createNodeId((String) null, eventPath);
} else {
try {
eventId = idFactory.createPropertyId(idFactory.createNodeId((String) null, eventPath.getAncestor(1)), eventPath.getName());
} catch (RepositoryException e1) {
log.warn("Unable to build event itemId: {}", e.getMessage());
}
}
}
String parentHref = Text.getRelativeParent(href, 1, true);
try {
parentId = uriResolver.getNodeId(parentHref, sessionInfo);
} catch (RepositoryException e) {
log.warn("Unable to build event parentId: {}", e.getMessage());
}
}
if (userId == null) {
// user id not retrieved from container
userId = DomUtil.getChildTextTrim(evElem, ObservationConstants.N_EVENTUSERID);
}
events.add(new EventImpl(eventId, eventPath, parentId, type, userId, evElem, getNamePathResolver(sessionInfo), getQValueFactory()));
}
return events;
}
use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.
the class RepositoryServiceImpl method poll.
private EventBundle[] poll(String uri, String subscriptionId, long timeout, SessionInfoImpl sessionInfo) throws RepositoryException {
HttpPoll request = null;
try {
request = new HttpPoll(uri, subscriptionId, timeout);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
EventDiscovery disc = request.getResponseBodyAsEventDiscovery(response);
EventBundle[] events;
if (disc.isEmpty()) {
events = new EventBundle[0];
} else {
Element discEl = disc.toXml(DomUtil.createDocument());
ElementIterator it = DomUtil.getChildren(discEl, ObservationConstants.N_EVENTBUNDLE);
List<EventBundle> bundles = new ArrayList<EventBundle>();
while (it.hasNext()) {
Element bundleElement = it.nextElement();
String value = DomUtil.getAttribute(bundleElement, ObservationConstants.XML_EVENT_LOCAL, null);
// check if it matches a batch id recently submitted
boolean isLocal = false;
if (value != null) {
isLocal = Boolean.parseBoolean(value);
}
bundles.add(new EventBundleImpl(buildEventList(bundleElement, sessionInfo, uri), isLocal));
}
events = bundles.toArray(new EventBundle[bundles.size()]);
}
return events;
} catch (IOException e) {
throw new RepositoryException(e);
} catch (ParserConfigurationException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
Aggregations