/** * Returns a {@link org.apache.jackrabbit.webdav.observation.EventDiscovery} object listing all events that were * recorded since the last call to this method and clears the list of event * bundles. * * @param timeout time in milliseconds to wait at most for events if none * are present currently. * @return object listing all events that were recorded. * @see #onEvent(EventIterator) */ synchronized EventDiscovery discoverEvents(long timeout) { EventDiscovery ed = new EventDiscovery(); if (eventBundles.isEmpty() && timeout > 0) { try { wait(timeout); } catch (InterruptedException e) { // continue and possibly return empty event discovery } } for (EventBundle eb : eventBundles) { ed.addEventBundle(eb); } // clear list eventBundles.clear(); return ed; }
/** * Return response body as {@link EventDiscovery} object. * @throws IllegalStateException when response does not represent a {@link EventDiscovery} * @throws DavException for failures in obtaining/parsing the response body */ public EventDiscovery getResponseBodyAsEventDiscovery(HttpResponse response) throws DavException { try { Document doc = getResponseBodyAsDocument(response.getEntity()); if (doc == null) { throw new DavException(response.getStatusLine().getStatusCode(), "no response body"); } return EventDiscovery.createFromXml(doc.getDocumentElement()); } catch (IOException ex) { throw new DavException(response.getStatusLine().getStatusCode(), ex); } }
/** * Returns the Xml representation of this <code>EventDiscovery</code> as * being present in the POLL response body. * * @return Xml representation * @see org.apache.jackrabbit.webdav.xml.XmlSerializable#toXml(Document) * @param document */ public Element toXml(Document document) { Element ed = DomUtil.createElement(document, XML_EVENTDISCOVERY, NAMESPACE); Iterator it = getEventBundles(); while (it.hasNext()) { EventBundle bundle = (EventBundle)it.next(); ed.appendChild(bundle.toXml(document)); } return ed; } }
/** * 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; } }
/** * Return response body as {@link EventDiscovery} object. * @throws IllegalStateException when response does not represent a {@link EventDiscovery} * @throws DavException for failures in obtaining/parsing the response body */ public EventDiscovery getResponseBodyAsEventDiscovery(HttpResponse response) throws DavException { try { Document doc = getResponseBodyAsDocument(response.getEntity()); if (doc == null) { throw new DavException(response.getStatusLine().getStatusCode(), "no response body"); } return EventDiscovery.createFromXml(doc.getDocumentElement()); } catch (IOException ex) { throw new DavException(response.getStatusLine().getStatusCode(), ex); } }
/** * 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; } }