org.apache.jackrabbit.webdav.xml.DomUtil Java Examples
The following examples show how to use
org.apache.jackrabbit.webdav.xml.DomUtil.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScheduleResponse.java From cosmo with Apache License 2.0 | 6 votes |
/** * @param document The document. * @return The element created. */ public Element toXml(Document document) { Element response = DomUtil.createElement(document, ELEMENT_CALDAV_RESPONSE, NAMESPACE_CALDAV); response.appendChild(recipient.toXml(document)); Element statusElem = DomUtil.createElement(document, ELEMENT_CALDAV_REQUEST_STATUS, NAMESPACE_CALDAV, getStatus() .getValue()); response.appendChild(statusElem); if (calendarData != null) { response.appendChild(calendarData.toXml(document)); } if (description != null) { Element respDesc = DomUtil.createElement(document, XML_RESPONSEDESCRIPTION, NAMESPACE, description); response.appendChild(respDesc); } return response; }
Example #2
Source File: TimeRangeFilter.java From cosmo with Apache License 2.0 | 6 votes |
/** * Construct a TimeRangeFilter object from a DOM Element * @param element The DOM Element. * @throws ParseException - if something is wrong this exception is thrown. */ public TimeRangeFilter(Element element, VTimeZone timezone) throws ParseException { // Get start (must be present) String start = DomUtil.getAttribute(element, ATTR_CALDAV_START, null); if (start == null) { throw new ParseException("CALDAV:comp-filter time-range requires a start time", -1); } DateTime trstart = new DateTime(start); if (! trstart.isUtc()) { throw new ParseException("CALDAV:param-filter timerange start must be UTC", -1); } // Get end (must be present) String end = DomUtil.getAttribute(element, ATTR_CALDAV_END, null); DateTime trend = end != null ? new DateTime(end) : getDefaultEndDate(trstart); if (! trend.isUtc()) { throw new ParseException("CALDAV:param-filter timerange end must be UTC", -1); } setPeriod(new Period(trstart, trend)); setTimezone(timezone); }
Example #3
Source File: ComponentFilter.java From cosmo with Apache License 2.0 | 6 votes |
/** * Construct a ComponentFilter object from a DOM Element. * @param element The element. * @param timezone The timezone. * @throws ParseException - if something is wrong this exception is thrown. */ public ComponentFilter(Element element, VTimeZone timezone) throws ParseException { // Name must be present validateName(element); final ElementIterator i = DomUtil.getChildren(element); int childCount = 0; while (i.hasNext()) { final Element child = i.nextElement(); childCount++; // if is-not-defined is present, then nothing else can be present validateNotDefinedState(childCount); Initializers.getInitializer(child.getLocalName()).initialize(child, timezone, this, childCount); } }
Example #4
Source File: ComponentFilter.java From cosmo with Apache License 2.0 | 6 votes |
private void validateName(Element element) throws ParseException { name = DomUtil.getAttribute(element, ATTR_CALDAV_NAME, null); if (name == null) { throw new ParseException( "CALDAV:comp-filter a calendar component name (e.g., \"VEVENT\") is required", -1); } if (!(name.equals(Calendar.VCALENDAR) || CalendarUtils.isSupportedComponent(name) || name.equals(Component.VALARM) || name.equals(Component.VTIMEZONE))) { throw new ParseException(name + " is not a supported iCalendar component", -1); } }
Example #5
Source File: TextMatchFilter.java From cosmo with Apache License 2.0 | 6 votes |
/** * Construct a TextMatchFilter object from a DOM Element * @param element The dom element. * @throws ParseException - if something is wrong this exception is thrown. */ public TextMatchFilter(Element element) throws ParseException { // Element data is string to match // TODO: do we need to do this replacing?? value = DomUtil.getTextTrim(element).replaceAll("'", "''"); // Check attribute for collation collation = DomUtil.getAttribute(element, ATTR_CALDAV_COLLATION,null); String negateCondition = DomUtil.getAttribute(element, ATTR_CALDAV_NEGATE_CONDITION,null); if((negateCondition == null) || !VALUE_YES.equals(negateCondition)) { isNegateCondition = false; } else { isNegateCondition = true; } }
Example #6
Source File: SyncMethod.java From openmeetings with Apache License 2.0 | 6 votes |
/** * Process the sync-token, from the response. */ protected void processResponseBody(HttpResponse response) { if (!processedResponse && succeeded(response)) { try { Document document = getResponseBodyAsDocument(response.getEntity()); if (document != null) { synctoken = DomUtil.getChildText(document.getDocumentElement(), SyncReportInfo.XML_SYNC_TOKEN, DavConstants.NAMESPACE); log.info("Sync-Token for REPORT: {}", synctoken); multiStatus = MultiStatus.createFromXml(document.getDocumentElement()); } } catch (IOException e) { log.error("Error while parsing sync-token.", e); } processedResponse = true; } }
Example #7
Source File: CalendarFilter.java From cosmo with Apache License 2.0 | 6 votes |
/** * Construct a CalendarFilter object from a DOM Element. * @param element The element. * @param timezone The timezone. * @throws ParseException - if something is wrong this exception is thrown. */ public CalendarFilter(Element element, VTimeZone timezone) throws ParseException { // Can only have a single comp-filter element final ElementIterator i = DomUtil.getChildren(element, ELEMENT_CALDAV_COMP_FILTER, NAMESPACE_CALDAV); if (!i.hasNext()) { throw new ParseException( "CALDAV:filter must contain a comp-filter", -1); } final Element child = i.nextElement(); if (i.hasNext()) { throw new ParseException( "CALDAV:filter can contain only one comp-filter", -1); } // Create new component filter and have it parse the element filter = new ComponentFilter(child, timezone); }
Example #8
Source File: SyncReportInfo.java From openmeetings with Apache License 2.0 | 6 votes |
/** * @see XmlSerializable#toXml(Document) * @param document - document to create report info from * @return report info as {@link Element} */ @Override public Element toXml(Document document) { Element syncCollection = DomUtil.createElement(document, XML_SYNC_COLLECTION, NAMESPACE); DomUtil.addChildElement(syncCollection, XML_SYNC_TOKEN, NAMESPACE, syncToken); if (limit > 0) { Element xlimit = DomUtil.addChildElement(syncCollection, XML_LIMIT, NAMESPACE); DomUtil.addChildElement(xlimit, XML_NRESULTS, NAMESPACE, Integer.toString(this.limit)); } DomUtil.addChildElement(syncCollection, XML_SYNC_LEVEL, NAMESPACE, (syncLevel == SYNC_LEVEL_INF) ? "infinity" : "1"); if (properties != null && !properties.isEmpty()) { syncCollection.appendChild(properties.toXml(document)); } return syncCollection; }
Example #9
Source File: MultiStatus.java From cosmo with Apache License 2.0 | 6 votes |
/** * Creates from xml. * @param doc The document. * @return Multi status. */ public static MultiStatus createFromXml(Document doc) { if (doc == null) { throw new IllegalArgumentException("null document"); } Element mse = doc.getDocumentElement(); if (! DomUtil.matches(mse, "multistatus", NS)) { throw new IllegalArgumentException("root element not DAV:multistatus"); } MultiStatus ms = new MultiStatus(); ElementIterator i = DomUtil.getChildren(mse, "response", NS); while (i.hasNext()) { ms.getResponses(). add(MultiStatusResponse.createFromXml(i.nextElement())); } String msrd = DomUtil.getChildTextTrim(mse, "responsedescription", NS); ms.setResponseDescription(msrd); return ms; }
Example #10
Source File: QueryReport.java From cosmo with Apache License 2.0 | 6 votes |
private static VTimeZone findTimeZone(ReportInfo info) throws CosmoDavException { Element propdata = DomUtil.getChildElement(getReportElementFrom(info), XML_PROP, NAMESPACE); if (propdata == null) { return null; } Element tzdata = DomUtil.getChildElement(propdata, ELEMENT_CALDAV_TIMEZONE, NAMESPACE_CALDAV); if (tzdata == null) { return null; } String icaltz = DomUtil.getTextTrim(tzdata); if (icaltz == null) { throw new UnprocessableEntityException("Expected text content for " + QN_CALDAV_TIMEZONE); } return TimeZoneExtractor.extract(icaltz); }
Example #11
Source File: DavPrivilegeSet.java From cosmo with Apache License 2.0 | 6 votes |
public static final DavPrivilegeSet createFromXml(Element root) { if (! DomUtil.matches(root, "privilege", NAMESPACE)) { throw new IllegalArgumentException("Expected DAV:privilege element"); } DavPrivilegeSet privileges = new DavPrivilegeSet(); if (DomUtil.hasChildElement(root, "read", NAMESPACE)) { privileges.add(DavPrivilege.READ); } if (DomUtil.hasChildElement(root, "write", NAMESPACE)) { privileges.add(DavPrivilege.WRITE); } if (DomUtil.hasChildElement(root, "read-free-busy", NAMESPACE_CALDAV)) { privileges.add(DavPrivilege.READ_FREE_BUSY); } return privileges; }
Example #12
Source File: StandardDavProperty.java From cosmo with Apache License 2.0 | 6 votes |
/** * <p> * If the property value is an <code>Element</code>, the text and character * data content of the element and every child element are concatenated. * </p> * <p> * If the property is a <code>Set</code>, the set is sorted and joined. * </p> * <p> * If the property value is otherwise not null, {@link Object.toString()} is * called upon it, and the result is returned. * </p> */ public String getValueText() { if (value == null) { return null; } if (value instanceof Element) { String text = DomUtil.getText((Element) value); if (text != null) { return text; } } if (value instanceof Set) { TreeSet<Object> sorted = new TreeSet<Object>((Set)value); return StringUtils.join(sorted, ", "); } return value.toString(); }
Example #13
Source File: PrincipalSearchPropertySetReport.java From cosmo with Apache License 2.0 | 6 votes |
public Element toXml(Document document) { Element root = DomUtil. createElement(document, "principal-search-property-set", NAMESPACE); Element psp = DomUtil. createElement(document, "principal-search-property", NAMESPACE); root.appendChild(psp); Element prop = DomUtil.createElement(document, "prop", NAMESPACE); psp.appendChild(prop); prop.appendChild(DavPropertyName.DISPLAYNAME.toXml(document)); // XXX I18N Element desc = DomUtil.createElement(document, "description", NAMESPACE); DomUtil.setAttribute(desc, "lang", NAMESPACE_XML, "en_US"); DomUtil.setText(desc, "Display name"); psp.appendChild(desc); return root; }
Example #14
Source File: PrincipalSearchPropertySetReport.java From cosmo with Apache License 2.0 | 6 votes |
/** * Validates the report info. */ protected void parseReport(ReportInfo info) throws CosmoDavException { if (! getType().isRequestedReportType(info)) { throw new CosmoDavException("Report not of type " + getType().getReportName()); } if (! getResource().isCollection()) { throw new BadRequestException(getType() + " report must target a collection"); } if (info.getDepth() != DEPTH_0) { throw new BadRequestException(getType() + " report must be made with depth 0"); } if (DomUtil.hasContent(getReportElementFrom(info))) { throw new BadRequestException("DAV:principal-search-property-set must be empty"); } }
Example #15
Source File: SupportedCalendarData.java From cosmo with Apache License 2.0 | 6 votes |
/** * * {@inheritDoc} */ public Element toXml(Document document) { Element name = getName().toXml(document); Element element = DomUtil.createElement(document, ELEMENT_CALDAV_CALENDAR_DATA, NAMESPACE_CALDAV); DomUtil.setAttribute(element, ATTR_CALDAV_CONTENT_TYPE, NAMESPACE_CALDAV, ICALENDAR_MEDIA_TYPE); DomUtil.setAttribute(element, ATTR_CALDAV_VERSION, NAMESPACE_CALDAV, ICALENDAR_VERSION); name.appendChild(element); return name; }
Example #16
Source File: PrincipalPropertySearchReport.java From cosmo with Apache License 2.0 | 6 votes |
private static Set<SearchSpec> findSearchSpecs(ReportInfo info) throws CosmoDavException { HashSet<SearchSpec> specs = new HashSet<SearchSpec>(); ElementIterator psi = DomUtil.getChildren(getReportElementFrom(info), "property-search", NAMESPACE); if (! psi.hasNext()) { throw new BadRequestException("Expected at least one DAV:property-search child of DAV:principal-property-search"); } while (psi.hasNext()) { specs.add(SearchSpec.createFromXml(psi.nextElement())); } return specs; }
Example #17
Source File: CaldavMultiStatusReport.java From cosmo with Apache License 2.0 | 6 votes |
/** * Parses an output filter out of the given report info. */ protected static OutputFilter findOutputFilter(ReportInfo info) throws CosmoDavException { Element propdata = DomUtil.getChildElement(getReportElementFrom(info), XML_PROP, NAMESPACE); if (propdata == null) { return null; } Element cdata = DomUtil.getChildElement(propdata, ELEMENT_CALDAV_CALENDAR_DATA, NAMESPACE_CALDAV); if (cdata == null) { return null; } return CaldavOutputFilter.createFromXml(cdata); }
Example #18
Source File: PropFindContent.java From cosmo with Apache License 2.0 | 6 votes |
/** * toXML. * {@inheritDoc} * @param doc - The document. * @return The element. */ public Element toXml(Document doc) { Element propfind = DomUtil.createElement(doc, XML_PROPFIND, NAMESPACE); if (propertyNames.isEmpty()) { // allprop Element allprop = DomUtil.createElement(doc, XML_ALLPROP, NAMESPACE); propfind.appendChild(allprop); } else { for (DavPropertyName propname: propertyNames) { Element name = DomUtil.createElement(doc, propname.getName(), propname.getNamespace()); Element prop = DomUtil.createElement(doc, XML_PROP, NAMESPACE); prop.appendChild(name); propfind.appendChild(prop); } } return propfind; }
Example #19
Source File: ScheduleInboxURL.java From cosmo with Apache License 2.0 | 5 votes |
public Element toXml(Document document) { Element name = getName().toXml(document); Element e = DomUtil.createElement(document, XML_HREF, NAMESPACE); DomUtil.setText(e, getHref()); name.appendChild(e); return name; }
Example #20
Source File: ScheduleOutboxURL.java From cosmo with Apache License 2.0 | 5 votes |
public Element toXml(Document document) { Element name = getName().toXml(document); Element e = DomUtil.createElement(document, XML_HREF, NAMESPACE); DomUtil.setText(e, getHref()); name.appendChild(e); return name; }
Example #21
Source File: Field.java From davmail with GNU General Public License v2.0 | 5 votes |
/** * Create DavProperty object for field alias and value. * * @param alias DavMail field alias * @param value field value * @return DavProperty with value or DavPropertyName for null values */ public static PropEntry createDavProperty(String alias, String value) { Field field = Field.get(alias); if (value == null) { // return DavPropertyName to remove property return field.updatePropertyName; } else if (field.isMultivalued) { // multivalued field, split values separated by \n List<XmlSerializable> valueList = new ArrayList<>(); String[] values = value.split(","); for (final String singleValue : values) { valueList.add(document -> DomUtil.createElement(document, "v", XML, singleValue)); } return new DefaultDavProperty<>(field.updatePropertyName, valueList); } else if (field.isBooleanValue && !"haspicture".equals(alias)) { if ("true".equals(value)) { return new DefaultDavProperty<>(field.updatePropertyName, "1"); } else if ("false".equals(value)) { return new DefaultDavProperty<>(field.updatePropertyName, "0"); } else { throw new RuntimeException("Invalid value for " + field.alias + ": " + value); } } else { return new DefaultDavProperty<>(field.updatePropertyName, value); } }
Example #22
Source File: Recipient.java From cosmo with Apache License 2.0 | 5 votes |
public Element toXml(Document document) { Element name = getName().toXml(document); Element e = DomUtil.createElement(document, XML_HREF, NAMESPACE); DomUtil.setText(e, getHref()); name.appendChild(e); return name; }
Example #23
Source File: CalendarHomeSet.java From cosmo with Apache License 2.0 | 5 votes |
/** * * {@inheritDoc} */ public Element toXml(Document document) { Element name = getName().toXml(document); Element e = DomUtil.createElement(document, XML_HREF, NAMESPACE); DomUtil.setText(e, getHref()); name.appendChild(e); return name; }
Example #24
Source File: SupportedCalendarComponentSet.java From cosmo with Apache License 2.0 | 5 votes |
/** * * {@inheritDoc} */ public Element toXml(Document document) { Element name = getName().toXml(document); for (String type : getComponentTypes()) { Element e = DomUtil.createElement(document, ELEMENT_CALDAV_COMP, NAMESPACE_CALDAV); DomUtil.setAttribute(e, ATTR_CALDAV_NAME, Namespace.EMPTY_NAMESPACE, type); name.appendChild(e); } return name; }
Example #25
Source File: ExceptionConverter.java From commons-vfs with Apache License 2.0 | 5 votes |
public static FileSystemException generate(final DavException davExc, final DavMethod method) throws FileSystemException { String msg = davExc.getMessage(); if (davExc.hasErrorCondition()) { try { final Element error = davExc.toXml(DomUtil.BUILDER_FACTORY.newDocumentBuilder().newDocument()); if (DomUtil.matches(error, DavException.XML_ERROR, DavConstants.NAMESPACE)) { if (DomUtil.hasChildElement(error, "exception", null)) { final Element exc = DomUtil.getChildElement(error, "exception", null); if (DomUtil.hasChildElement(exc, "message", null)) { msg = DomUtil.getChildText(exc, "message", null); } if (DomUtil.hasChildElement(exc, "class", null)) { final Class<?> cl = Class.forName(DomUtil.getChildText(exc, "class", null)); final Constructor<?> excConstr = cl.getConstructor(new Class[] { String.class }); if (excConstr != null) { final Object o = excConstr.newInstance(new Object[] { msg }); if (o instanceof FileSystemException) { return (FileSystemException) o; } else if (o instanceof Exception) { return new FileSystemException(msg, (Exception) o); } } } } } } catch (final Exception e) { throw new FileSystemException(e); } } return new FileSystemException(msg); }
Example #26
Source File: CalendarUserAddressSet.java From cosmo with Apache License 2.0 | 5 votes |
public Element toXml(Document document) { Element calendarUserAddressSetNode = getName().toXml(document); for(String emailAddress : userEmails){ Element e = DomUtil.createElement(document, XML_HREF, NAMESPACE); DomUtil.setText(e, href(emailAddress)); calendarUserAddressSetNode.appendChild(e); } return calendarUserAddressSetNode; }
Example #27
Source File: MultiStatus.java From cosmo with Apache License 2.0 | 5 votes |
/** * Creates from xml. * @param e The element. * @return The multi status response. */ public static MultiStatusResponse createFromXml(Element e) { if (e == null) { throw new IllegalArgumentException("null DAV:response element"); } MultiStatusResponse msr = new MultiStatusResponse(); Element he = DomUtil.getChildElement(e, "href", NS); if (he == null) { throw new IllegalArgumentException("expected DAV:href child for DAV:response element"); } msr.setHref(DomUtil.getTextTrim(he)); String statusLine = DomUtil.getChildTextTrim(e, "status", NS); if (statusLine != null) { msr.setStatus(Status.createFromStatusLine(statusLine)); } ElementIterator i = DomUtil.getChildren(e, "propstat", NS); while (i.hasNext()) { msr.getPropStats().add(PropStat.createFromXml(i.nextElement())); } String msrrd = DomUtil.getChildTextTrim(e, "responsedescription", NS); msr.setResponseDescription(msrrd); return msr; }
Example #28
Source File: StandardDavResponse.java From cosmo with Apache License 2.0 | 5 votes |
public Element toXml(Document document) { Element prop = DomUtil.createElement(document, XML_PROP, NAMESPACE); if (td != null) { prop.appendChild(td.toXml(document)); } return prop; }
Example #29
Source File: TicketContent.java From cosmo with Apache License 2.0 | 5 votes |
/** * Returns a <code>TicketContent> populated with information from * the given XML fragment which is assumed to be response content * (containing an owner href rather than a <code>User</code>). * * The root element of the fragment must be a * <code>ticket:ticketinfo</code> element. * @param root The element. * @return The ticket content. * @throws Exception - if something is wrong this exception is thrown. */ public static TicketContent createFromXml(Element root) throws Exception { if (! DomUtil.matches(root, ELEMENT_TICKET_TICKETINFO, NAMESPACE_TICKET)) { throw new Exception("root element not ticketinfo"); } Ticket ticket = new HibTicket(); String id = DomUtil.getChildTextTrim(root, ELEMENT_TICKET_ID, NAMESPACE_TICKET); ticket.setKey(id); String timeout = DomUtil.getChildTextTrim(root, ELEMENT_TICKET_TIMEOUT, NAMESPACE_TICKET); ticket.setTimeout(timeout); Element pe = DomUtil.getChildElement(root, XML_PRIVILEGE, NAMESPACE); DavPrivilegeSet privileges = DavPrivilegeSet.createFromXml(pe); privileges.setTicketPrivileges(ticket); Element owner = DomUtil.getChildElement(root, XML_OWNER, NAMESPACE); String ownerHref = DomUtil.getChildTextTrim(owner, XML_HREF, NAMESPACE); return new TicketContent(ticket, ownerHref); }
Example #30
Source File: StandardDavRequest.java From cosmo with Apache License 2.0 | 5 votes |
/** * * @return DavPropertySet * @throws CosmoDavException */ private DavPropertySet parseMkCalendarRequest() throws CosmoDavException { DavPropertySet propertySet = new DavPropertySet(); Document requestDocument = getSafeRequestDocument(false); if (requestDocument == null) { return propertySet; } Element root = requestDocument.getDocumentElement(); if (!DomUtil.matches(root, ELEMENT_CALDAV_MKCALENDAR, NAMESPACE_CALDAV)) { throw new BadRequestException("Expected " + QN_MKCALENDAR + " root element"); } Element set = DomUtil.getChildElement(root, XML_SET, NAMESPACE); if (set == null) { throw new BadRequestException("Expected " + QN_SET + " child of " + QN_MKCALENDAR); } Element prop = DomUtil.getChildElement(set, XML_PROP, NAMESPACE); if (prop == null) { throw new BadRequestException("Expected " + QN_PROP + " child of " + QN_SET); } ElementIterator i = DomUtil.getChildren(prop); while (i.hasNext()){ propertySet.add(StandardDavProperty.createFromXml(i.nextElement())); } return propertySet; }