/** * Modify the {@link SubscriptionInfo} for this subscription. * * @param info */ void setInfo(SubscriptionInfo info) { this.info = info; // validate the timeout and adjust value, if it is invalid or missing long timeout = info.getTimeOut(); if (timeout <= 0) { timeout = DEFAULT_TIMEOUT; } expirationTime = System.currentTimeMillis() + timeout; }
/** * @return true if this subscription is intended to be deep. */ boolean isDeep() { return info.isDeep(); }
/** * @return JCR compliant integer representation of the event types defined * for this {@link SubscriptionInfo}. */ int getJcrEventTypes() throws DavException { EventType[] eventTypes = info.getEventTypes(); int events = 0; for (EventType eventType : eventTypes) { events |= getJcrEventType(eventType); } return events; }
public HttpSubscribe(URI uri, SubscriptionInfo info, String subscriptionId) throws IOException { super(uri); if (info == null) { throw new IllegalArgumentException("SubscriptionInfo must not be null."); } // optional subscriptionId (only required to modify an existing // subscription) if (subscriptionId != null) { CodedUrlHeader h = new CodedUrlHeader(ObservationConstants.HEADER_SUBSCRIPTIONID, subscriptionId); super.setHeader(h.getHeaderName(), h.getHeaderValue()); } // optional timeout header long to = info.getTimeOut(); if (to != DavConstants.UNDEFINED_TIMEOUT) { TimeoutHeader h = new TimeoutHeader(info.getTimeOut()); super.setHeader(h.getHeaderName(), h.getHeaderValue()); } // always set depth header since value is boolean flag DepthHeader dh = new DepthHeader(info.isDeep()); super.setHeader(dh.getHeaderName(), dh.getHeaderValue()); super.setEntity(XmlEntity.create(info)); }
/** * Return the Xml representation of this <code>Subscription</code> as required * for the {@link org.apache.jackrabbit.webdav.observation.SubscriptionDiscovery} * webdav property that in included in the response body of a successful SUBSCRIBE * request or as part of a PROPFIND response. * * @return Xml representation * @see org.apache.jackrabbit.webdav.xml.XmlSerializable#toXml(Document) * @param document */ public Element toXml(Document document) { Element subscr = DomUtil.createElement(document, XML_SUBSCRIPTION, NAMESPACE); subscr.appendChild(info.toXml(document)); subscr.appendChild(DomUtil.depthToXml(info.isDeep(), document)); subscr.appendChild(DomUtil.timeoutToXml(info.getTimeOut(), document)); if (getSubscriptionId() != null) { Element id = DomUtil.addChildElement(subscr, XML_SUBSCRIPTIONID, NAMESPACE); id.appendChild(DomUtil.hrefToXml(getSubscriptionId(), document)); } DomUtil.addChildElement(subscr, XML_EVENTSWITHTYPES, NAMESPACE, Boolean.toString(eventsProvideNodeTypeInformation())); DomUtil.addChildElement(subscr, XML_EVENTSWITHLOCALFLAG, NAMESPACE, Boolean.toString(eventsProvideNoLocalFlag())); return subscr; }
/** * @see org.apache.jackrabbit.webdav.observation.ObservationDavServletRequest#getSubscriptionInfo() */ public SubscriptionInfo getSubscriptionInfo() throws DavException { Document requestDocument = getRequestDocument(); if (requestDocument != null) { Element root = requestDocument.getDocumentElement(); if (ObservationConstants.XML_SUBSCRIPTIONINFO.equals(root.getLocalName())) { int depth = getDepth(DEPTH_0); return new SubscriptionInfo(root, getTimeout(), depth == DEPTH_INFINITY); } } return null; }
/** * * @return true if a {@link ObservationConstants#XML_NOLOCAL} element * is present in the {@link SubscriptionInfo}. */ boolean isNoLocal() { return info.isNoLocal(); }
private String[] getFilterValues(String filterLocalName) { List<String> values = new ArrayList<String>(); for (Filter filter : info.getFilters(filterLocalName, NAMESPACE)) { String val = filter.getValue(); if (val != null) { values.add(val); } } return (values.size() > 0) ? values.toArray(new String[values.size()]) : null; }
public HttpSubscribe(URI uri, SubscriptionInfo info, String subscriptionId) throws IOException { super(uri); if (info == null) { throw new IllegalArgumentException("SubscriptionInfo must not be null."); } // optional subscriptionId (only required to modify an existing // subscription) if (subscriptionId != null) { CodedUrlHeader h = new CodedUrlHeader(ObservationConstants.HEADER_SUBSCRIPTIONID, subscriptionId); super.setHeader(h.getHeaderName(), h.getHeaderValue()); } // optional timeout header long to = info.getTimeOut(); if (to != DavConstants.UNDEFINED_TIMEOUT) { TimeoutHeader h = new TimeoutHeader(info.getTimeOut()); super.setHeader(h.getHeaderName(), h.getHeaderValue()); } // always set depth header since value is boolean flag DepthHeader dh = new DepthHeader(info.isDeep()); super.setHeader(dh.getHeaderName(), dh.getHeaderValue()); super.setEntity(XmlEntity.create(info)); }
/** * @see org.apache.jackrabbit.webdav.observation.ObservationDavServletRequest#getSubscriptionInfo() */ public SubscriptionInfo getSubscriptionInfo() throws DavException { Document requestDocument = getRequestDocument(); if (requestDocument != null) { Element root = requestDocument.getDocumentElement(); if (ObservationConstants.XML_SUBSCRIPTIONINFO.equals(root.getLocalName())) { int depth = getDepth(DEPTH_0); return new SubscriptionInfo(root, getTimeout(), depth == DEPTH_INFINITY); } } return null; }
/** * Creates a new transaction listener for the scope of a transaction * commit (save call). * @return a transaction listener for this subscription. */ TransactionListener createTransactionListener() { if (info.isNoLocal()) { // a subscription which is not interested in local changes does // not need the transaction id return new TransactionEvent() { @Override public void onEvent(EventIterator events) { // ignore } @Override public void beforeCommit(TransactionResource resource, String lockToken) { // ignore } @Override public void afterCommit(TransactionResource resource, String lockToken, boolean success) { // ignore } }; } else { return new TransactionEvent(); } }
/** * @see org.apache.jackrabbit.webdav.observation.ObservationDavServletRequest#getSubscriptionInfo() */ public SubscriptionInfo getSubscriptionInfo() throws DavException { Document requestDocument = getRequestDocument(); if (requestDocument != null) { Element root = requestDocument.getDocumentElement(); if (ObservationConstants.XML_SUBSCRIPTIONINFO.equals(root.getLocalName())) { int depth = getDepth(DEPTH_0); return new SubscriptionInfo(root, getTimeout(), depth == DEPTH_INFINITY); } } return null; }