Java Code Examples for org.apache.jackrabbit.webdav.xml.DomUtil#matches()
The following examples show how to use
org.apache.jackrabbit.webdav.xml.DomUtil#matches() .
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: 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 2
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 3
Source File: PrincipalPropertySearchReport.java From cosmo with Apache License 2.0 | 5 votes |
public static SearchSpec createFromXml(Element root) throws CosmoDavException { if (! DomUtil.matches(root, "property-search", NAMESPACE)) { throw new IllegalArgumentException("Expected root element DAV:property-search"); } Element p = DomUtil.getChildElement(root, "prop", NAMESPACE); if (p == null) { throw new BadRequestException("Expected DAV:prop child of DAV:property-search"); } ElementIterator pi = DomUtil.getChildren(p); if (! pi.hasNext()) { throw new BadRequestException("Expected at least one child of DAV:prop"); } HashSet<DavPropertyName> properties = new HashSet<DavPropertyName>(); while (pi.hasNext()) { DavPropertyName name = DavPropertyName.createFromXml(pi.nextElement()); properties.add(name); } Element m = DomUtil.getChildElement(root, "match", NAMESPACE); if (m == null) { throw new BadRequestException("Expected DAV:match child of DAV:property-search"); } String match = DomUtil.getText(m); return new SearchSpec(properties, match); }
Example 4
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; }
Example 5
Source File: MultiStatus.java From cosmo with Apache License 2.0 | 5 votes |
/** * Finds Prop. * @param name The name. * @param ns The namespace. * @return The element. */ public Element findProp(String name, Namespace ns) { for (Element prop : props) { if (DomUtil.matches(prop, name, ns)) { return prop; } } return null; }
Example 6
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 7
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 8
Source File: ExceptionConverter.java From commons-vfs with Apache License 2.0 | 5 votes |
public static FileSystemException generate(final DavException davExc) throws FileSystemException { String msg = davExc.getMessage(); if (davExc.hasErrorCondition()) { try { final Element error = davExc.toXml(DomUtil.createDocument()); 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 9
Source File: StandardDavRequest.java From cosmo with Apache License 2.0 | 4 votes |
/** * * @throws CosmoDavException */ private void parsePropPatchRequest() throws CosmoDavException { Document requestDocument = getSafeRequestDocument(); if (requestDocument == null) { throw new BadRequestException("PROPPATCH requires entity body"); } Element root = requestDocument.getDocumentElement(); if (!DomUtil.matches(root, XML_PROPERTYUPDATE, NAMESPACE)) { throw new BadRequestException("Expected " + QN_PROPERTYUPDATE + " root element"); } ElementIterator sets = DomUtil.getChildren(root, XML_SET, NAMESPACE); ElementIterator removes = DomUtil.getChildren(root, XML_REMOVE, NAMESPACE); if (!(sets.hasNext() || removes.hasNext())) { throw new BadRequestException("Expected at least one of " + QN_REMOVE + " and " + QN_SET + " as a child of " + QN_PROPERTYUPDATE); } Element prop = null; ElementIterator i = null; proppatchSet = new DavPropertySet(); while (sets.hasNext()) { Element set = sets.nextElement(); prop = DomUtil.getChildElement(set, XML_PROP, NAMESPACE); if (prop == null) { throw new BadRequestException("Expected " + QN_PROP + " child of " + QN_SET); } i = DomUtil.getChildren(prop); while (i.hasNext()) { StandardDavProperty p = StandardDavProperty.createFromXml(i .nextElement()); proppatchSet.add(p); } } proppatchRemove = new DavPropertyNameSet(); while (removes.hasNext()) { Element remove = removes.nextElement(); prop = DomUtil.getChildElement(remove, XML_PROP, NAMESPACE); if (prop == null) { throw new BadRequestException("Expected " + QN_PROP + " child of " + QN_REMOVE); } i = DomUtil.getChildren(prop); while (i.hasNext()){ proppatchRemove.add(DavPropertyName.createFromXml(i .nextElement())); } } }
Example 10
Source File: StandardDavRequest.java From cosmo with Apache License 2.0 | 4 votes |
/** * * @return Ticket * @throws CosmoDavException */ private Ticket parseTicketRequest() throws CosmoDavException { Document requestDocument = getSafeRequestDocument(); if (requestDocument == null) { throw new BadRequestException("MKTICKET requires entity body"); } Element root = requestDocument.getDocumentElement(); if (!DomUtil.matches(root, ELEMENT_TICKET_TICKETINFO, NAMESPACE_TICKET)) { throw new BadRequestException("Expected " + QN_TICKET_TICKETINFO + " root element"); } if (DomUtil.hasChildElement(root, ELEMENT_TICKET_ID, NAMESPACE_TICKET)) { throw new BadRequestException(QN_TICKET_TICKETINFO + " may not contain child " + QN_TICKET_ID); } if (DomUtil.hasChildElement(root, XML_OWNER, NAMESPACE)) { throw new BadRequestException(QN_TICKET_TICKETINFO + " may not contain child " + QN_OWNER); } String timeout = DomUtil.getChildTextTrim(root, ELEMENT_TICKET_TIMEOUT, NAMESPACE_TICKET); if (timeout != null && !timeout.equals(TIMEOUT_INFINITE)) { try { int seconds = Integer.parseInt(timeout.substring(7)); if (LOG.isTraceEnabled()) { LOG.trace("Timeout seconds: " + seconds); } } catch (NumberFormatException e) { throw new BadRequestException("Malformed " + QN_TICKET_TIMEOUT + " value " + timeout); } } else { timeout = TIMEOUT_INFINITE; } // visit limits are not supported Element pe = DomUtil.getChildElement(root, XML_PRIVILEGE, NAMESPACE); if (pe == null) { throw new BadRequestException("Expected " + QN_PRIVILEGE + " child of " + QN_TICKET_TICKETINFO); } DavPrivilegeSet privileges = DavPrivilegeSet.createFromXml(pe); if (!privileges.containsAny(DavPrivilege.READ, DavPrivilege.WRITE, DavPrivilege.READ_FREE_BUSY)) { throw new BadRequestException("Empty or invalid " + QN_PRIVILEGE); } Ticket ticket = entityFactory.creatTicket(); ticket.setTimeout(timeout); privileges.setTicketPrivileges(ticket); return ticket; }