org.apache.jackrabbit.webdav.DavConstants Java Examples

The following examples show how to use org.apache.jackrabbit.webdav.DavConstants. 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: WebdavFileObject.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
DavPropertySet getProperties(final URLFileName name, final int type, final DavPropertyNameSet nameSet,
        final boolean addEncoding) throws FileSystemException {
    try {
        final String urlStr = toUrlString(name);
        final PropFindMethod method = new PropFindMethod(urlStr, type, nameSet, DavConstants.DEPTH_0);
        setupMethod(method);
        execute(method);
        if (method.succeeded()) {
            final MultiStatus multiStatus = method.getResponseBodyAsMultiStatus();
            final MultiStatusResponse response = multiStatus.getResponses()[0];
            final DavPropertySet props = response.getProperties(HttpStatus.SC_OK);
            if (addEncoding) {
                final DavProperty prop = new DefaultDavProperty(RESPONSE_CHARSET, method.getResponseCharSet());
                props.add(prop);
            }
            return props;
        }
        return new DavPropertySet();
    } catch (final FileSystemException fse) {
        throw fse;
    } catch (final Exception e) {
        throw new FileSystemException("vfs.provider.webdav/get-property.error", e, getName(), name, type,
                nameSet.getContent(), addEncoding);
    }
}
 
Example #2
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * The OPTION method
 * 
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 */
protected void doOptions(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws IOException, DavException {
	log.debug("doOptions");

	response.addHeader(DavConstants.HEADER_DAV, resource.getComplianceClass());
	response.addHeader("Allow", resource.getSupportedMethods());
	response.addHeader("MS-Author-Via", DavConstants.HEADER_DAV);
	if (resource instanceof SearchResource) {
		String[] langs = ((SearchResource) resource).getQueryGrammerSet().getQueryLanguages();
		for (int i = 0; i < langs.length; i++) {
			response.addHeader(SearchConstants.HEADER_DASL, "<" + langs[i] + ">");
		}
	}
	// with DeltaV the OPTIONS request may contain a Xml body.
	OptionsResponse oR = null;
	OptionsInfo oInfo = request.getOptionsInfo();
	if (oInfo != null && resource instanceof DeltaVResource) {
		oR = ((DeltaVResource) resource).getOptionResponse(oInfo);
	}
	if (oR == null) {
		response.setStatus(DavServletResponse.SC_OK);
	} else {
		response.sendXmlResponse(oR, DavServletResponse.SC_OK);
	}
}
 
Example #3
Source File: SyncMethod.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #4
Source File: ExceptionConverter.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
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 #5
Source File: Webdav4FileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the size of the file content (in bytes).
 */
@Override
protected long doGetContentSize() throws Exception {
    final DavProperty property = getProperty((GenericURLFileName) getName(), DavConstants.PROPERTY_GETCONTENTLENGTH);
    if (property != null) {
        final String value = (String) property.getValue();
        return Long.parseLong(value);
    }
    return 0;
}
 
Example #6
Source File: ExceptionConverter.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
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 #7
Source File: WebdavFileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
private boolean isDirectory(final URLFileName name) throws IOException {
    try {
        final DavProperty property = getProperty(name, DavConstants.PROPERTY_RESOURCETYPE);
        Node node;
        if (property != null && (node = (Node) property.getValue()) != null) {
            return node.getLocalName().equals(DavConstants.XML_COLLECTION);
        }
        return false;
    } catch (final FileNotFoundException fse) {
        throw new FileNotFolderException(name);
    }
}
 
Example #8
Source File: Webdav4FileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the last modified time of this file. Is only called if {@link #doGetType} does not return
 * {@link FileType#IMAGINARY}.
 */
@Override
protected long doGetLastModifiedTime() throws Exception {
    final DavProperty property = getProperty((GenericURLFileName) getName(), DavConstants.PROPERTY_GETLASTMODIFIED);
    if (property != null) {
        final String value = (String) property.getValue();
        return DateUtils.parseDate(value).getTime();
    }
    return 0;
}
 
Example #9
Source File: WebdavFileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the last modified time of this file. Is only called if {@link #doGetType} does not return
 * {@link FileType#IMAGINARY}.
 */
@Override
protected long doGetLastModifiedTime() throws Exception {
    final DavProperty property = getProperty((URLFileName) getName(), DavConstants.PROPERTY_GETLASTMODIFIED);
    if (property != null) {
        final String value = (String) property.getValue();
        return DateUtil.parseDate(value).getTime();
    }
    return 0;
}
 
Example #10
Source File: WebdavFileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the size of the file content (in bytes).
 */
@Override
protected long doGetContentSize() throws Exception {
    final DavProperty property = getProperty((URLFileName) getName(), DavConstants.PROPERTY_GETCONTENTLENGTH);
    if (property != null) {
        final String value = (String) property.getValue();
        return Long.parseLong(value);
    }
    return 0;
}
 
Example #11
Source File: DavPrivilege.java    From cosmo with Apache License 2.0 5 votes vote down vote up
public Element toXml(Document document) {
    if (isAbstract) {
        return null;
    }
    Element privilege = DomUtil.createElement(document, 
            XML_PRIVILEGE, DavConstants.NAMESPACE); 
    privilege.appendChild(DomUtil.createElement(document, 
            qname.getLocalPart(), ns(qname)));
    return privilege;
}
 
Example #12
Source File: TestCaldavHttpClient4.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
public void testGetOtherUserCalendar() throws IOException {
    HttpPropfind method = new HttpPropfind("/principals/users/" + Settings.getProperty("davmail.usera"),
            DavConstants.PROPFIND_ALL_PROP, new DavPropertyNameSet(), DavConstants.DEPTH_INFINITY);
    try (CloseableHttpResponse response = httpClient.execute(method)) {
        assertEquals(HttpStatus.SC_MULTI_STATUS, response.getStatusLine().getStatusCode());
    }
}
 
Example #13
Source File: ExportContextImpl.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void setModificationTime(long modificationTime) {
	if (modificationTime <= IOUtil.UNDEFINED_TIME) {
		modificationTime = new Date().getTime();
	}
	String lastMod = IOUtil.getLastModified(modificationTime);
	properties.put(DavConstants.HEADER_LAST_MODIFIED, lastMod);
}
 
Example #14
Source File: Webdav4FileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
DavPropertySet getProperties(final GenericURLFileName name, final int type, final DavPropertyNameSet nameSet,
        final boolean addEncoding) throws FileSystemException {
    try {
        final String urlStr = toUrlString(name);
        final HttpPropfind request = new HttpPropfind(urlStr, type, nameSet, DavConstants.DEPTH_0);
        setupRequest(request);
        final HttpResponse res = executeRequest(request);
        if (request.succeeded(res)) {
            final MultiStatus multiStatus = request.getResponseBodyAsMultiStatus(res);
            final MultiStatusResponse response = multiStatus.getResponses()[0];
            final DavPropertySet props = response.getProperties(HttpStatus.SC_OK);
            if (addEncoding) {
                final ContentType resContentType = ContentType.getOrDefault(res.getEntity());
                final DavProperty prop = new DefaultDavProperty(RESPONSE_CHARSET,
                        resContentType.getCharset().name());
                props.add(prop);
            }
            return props;
        }
        return new DavPropertySet();
    } catch (final FileSystemException fse) {
        throw fse;
    } catch (final Exception e) {
        throw new FileSystemException("vfs.provider.webdav/get-property.error", e, getName(), name, type,
                nameSet.getContent(), addEncoding);
    }
}
 
Example #15
Source File: Webdav4FileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
private boolean isDirectory(final GenericURLFileName name) throws IOException {
    try {
        final DavProperty property = getProperty(name, DavConstants.PROPERTY_RESOURCETYPE);
        Node node;
        if (property != null && (node = (Node) property.getValue()) != null) {
            return node.getLocalName().equals(DavConstants.XML_COLLECTION);
        }
        return false;
    } catch (final FileNotFoundException fse) {
        throw new FileNotFolderException(name);
    }
}
 
Example #16
Source File: WebdavFileObject.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
DavPropertySet getProperties(final URLFileName name) throws FileSystemException {
    return getProperties(name, DavConstants.PROPFIND_ALL_PROP, new DavPropertyNameSet(), false);
}
 
Example #17
Source File: Webdav4FileObject.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
DavPropertySet getProperties(final GenericURLFileName name) throws FileSystemException {
    return getProperties(name, DavConstants.PROPFIND_ALL_PROP, new DavPropertyNameSet(), false);
}
 
Example #18
Source File: Webdav4FileObject.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
DavPropertySet getProperties(final GenericURLFileName name, final DavPropertyNameSet nameSet, final boolean addEncoding)
        throws FileSystemException {
    return getProperties(name, DavConstants.PROPFIND_BY_PROPERTY, nameSet, addEncoding);
}
 
Example #19
Source File: Webdav4FileObject.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
DavPropertySet getPropertyNames(final GenericURLFileName name) throws FileSystemException {
    return getProperties(name, DavConstants.PROPFIND_PROPERTY_NAMES, new DavPropertyNameSet(), false);
}
 
Example #20
Source File: WebdavFileObject.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
DavPropertySet getPropertyNames(final URLFileName name) throws FileSystemException {
    return getProperties(name, DavConstants.PROPFIND_PROPERTY_NAMES, new DavPropertyNameSet(), false);
}
 
Example #21
Source File: WebdavFileObject.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
DavPropertySet getProperties(final URLFileName name, final DavPropertyNameSet nameSet, final boolean addEncoding)
        throws FileSystemException {
    return getProperties(name, DavConstants.PROPFIND_BY_PROPERTY, nameSet, addEncoding);
}
 
Example #22
Source File: ExportContextImpl.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public void setETag(String etag) {
	properties.put(DavConstants.HEADER_ETAG, etag);
}
 
Example #23
Source File: ExportContextImpl.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public void setContentType(String mimeType, String encoding) {
	properties.put(DavConstants.HEADER_CONTENT_TYPE, IOUtil.buildContentType(mimeType, encoding));
}
 
Example #24
Source File: ExportContextImpl.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public void setContentLength(long contentLength) {
	properties.put(DavConstants.HEADER_CONTENT_LENGTH, contentLength + "");
}
 
Example #25
Source File: ExportContextImpl.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public void setContentLanguage(String contentLanguage) {
	properties.put(DavConstants.HEADER_CONTENT_LANGUAGE, contentLanguage);
}