Java Code Examples for org.apache.jackrabbit.webdav.xml.DomUtil#hasChildElement()
The following examples show how to use
org.apache.jackrabbit.webdav.xml.DomUtil#hasChildElement() .
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: 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 3
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 4
Source File: PrincipalPropertySearchReport.java From cosmo with Apache License 2.0 | 4 votes |
private static boolean findSearchPrincipalCollections(ReportInfo info) throws CosmoDavException { return DomUtil.hasChildElement(getReportElementFrom(info), "apply-to-principal-collection-set", NAMESPACE); }
Example 5
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; }