org.apache.jackrabbit.webdav.property.DavProperty Java Examples

The following examples show how to use org.apache.jackrabbit.webdav.property.DavProperty. 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: AppointmentManager.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if the resourcetype Property has a Calendar Element under it.
 *
 * @param resourcetype ResourceType Property
 * @return True if, resource is Calendar, else false.
 */
private static boolean checkCalendarResourceType(DavProperty<?> resourcetype) {
	boolean isCalendar = false;

	if (resourcetype != null) {
		DavPropertyName calProp = DavPropertyName.create("calendar", CalDAVConstants.NAMESPACE_CALDAV);

		for (Object o : (Collection<?>) resourcetype.getValue()) {
			if (o instanceof Element) {
				Element e = (Element) o;
				if (e.getLocalName().equals(calProp.getName())) {
					isCalendar = true;
				}
			}
		}
	}
	return isCalendar;
}
 
Example #2
Source File: TestDavExchangeSessionOther.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Search in non ipm subtree
 *
 * @throws IOException on error
 */
public void testNonIpmSubtree() throws IOException {
    Set<String> attributes = new HashSet<>();
    attributes.add("messageclass");
    attributes.add("permanenturl");
    attributes.add("roamingxmlstream");
    attributes.add("roamingdictionary");
    attributes.add("displayname");

    MultiStatusResponse[] responses = davSession.searchItems("/users/" + davSession.getEmail() + "/non_ipm_subtree", attributes, davSession.and(davSession.isTrue("ishidden")), HC4DavExchangeSession.FolderQueryTraversal.Deep, 0);
    for (MultiStatusResponse response : responses) {
        System.out.println(response.getHref() + ' ' + response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("messageclass")).getValue() + ": "
                + response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("displayname")).getValue());

        DavProperty<?> roamingxmlstreamProperty = response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("roamingxmlstream"));
        if (roamingxmlstreamProperty != null) {
            System.out.println("roamingxmlstream: " + new String(Base64.decodeBase64(((String) roamingxmlstreamProperty.getValue()).getBytes()), StandardCharsets.UTF_8));
        }

        DavProperty<?> roamingdictionaryProperty = response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("roamingdictionary"));
        if (roamingdictionaryProperty != null) {
            System.out.println("roamingdictionary: " + new String(Base64.decodeBase64(((String) roamingdictionaryProperty.getValue()).getBytes()), StandardCharsets.UTF_8));
        }
    }
}
 
Example #3
Source File: TestDavExchangeSessionOther.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Retrieve all hidden items
 *
 * @throws IOException on error
 */
public void testAllHidden() throws IOException {
    Set<String> attributes = new HashSet<>();
    attributes.add("messageclass");
    attributes.add("permanenturl");
    attributes.add("roamingxmlstream");
    attributes.add("displayname");

    MultiStatusResponse[] responses = davSession.searchItems("/users/" + davSession.getEmail() + '/', attributes, davSession.and(davSession.isTrue("ishidden")), HC4DavExchangeSession.FolderQueryTraversal.Deep, 0);
    for (MultiStatusResponse response : responses) {
        System.out.println(response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("messageclass")).getValue() + ": "
                + response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("displayname")).getValue());

        DavProperty<?> roamingxmlstreamProperty = response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("roamingxmlstream"));
        if (roamingxmlstreamProperty != null) {
            System.out.println(new String(Base64.decodeBase64(((String) roamingxmlstreamProperty.getValue()).getBytes()), StandardCharsets.UTF_8));
        }

    }
}
 
Example #4
Source File: DeltaVResourceImpl.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
public DavResource[] getReferenceResources(DavPropertyName hrefPropertyName) throws DavException {
	DavProperty prop = getProperty(hrefPropertyName);
	List resources = new ArrayList();
	if (prop != null && prop instanceof HrefProperty) {
		HrefProperty hp = (HrefProperty) prop;
		// process list of hrefs
		List hrefs = hp.getHrefs();
		for (Iterator iter = hrefs.iterator(); iter.hasNext();) {
			String href = (String) iter.next();
			DavResourceLocator locator = getLocator().getFactory().createResourceLocator(getLocator().getPrefix(),
					href);
			resources.add(createResourceFromLocator(locator));
		}
	} else {
		throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
	}
	return (DavResource[]) resources.toArray(new DavResource[0]);
}
 
Example #5
Source File: Webdav4FileContentInfoFactory.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
@Override
public FileContentInfo create(final FileContent fileContent) throws FileSystemException {
    final Webdav4FileObject file = (Webdav4FileObject) FileObjectUtils.getAbstractFileObject(fileContent.getFile());

    String contentType = null;
    String contentEncoding = null;

    final DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(DavPropertyName.GETCONTENTTYPE);
    final DavPropertySet propertySet = file.getProperties((GenericURLFileName) file.getName(), nameSet, true);

    DavProperty property = propertySet.get(DavPropertyName.GETCONTENTTYPE);
    if (property != null) {
        contentType = (String) property.getValue();
    }
    property = propertySet.get(Webdav4FileObject.RESPONSE_CHARSET);
    if (property != null) {
        contentEncoding = (String) property.getValue();
    }

    return new DefaultFileContentInfo(contentType, contentEncoding);
}
 
Example #6
Source File: WebdavFileContentInfoFactory.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
@Override
public FileContentInfo create(final FileContent fileContent) throws FileSystemException {
    final WebdavFileObject file = (WebdavFileObject) FileObjectUtils.getAbstractFileObject(fileContent.getFile());

    String contentType = null;
    String contentEncoding = null;

    final DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(DavPropertyName.GETCONTENTTYPE);
    final DavPropertySet propertySet = file.getProperties((URLFileName) file.getName(), nameSet, true);

    DavProperty property = propertySet.get(DavPropertyName.GETCONTENTTYPE);
    if (property != null) {
        contentType = (String) property.getValue();
    }
    property = propertySet.get(WebdavFileObject.RESPONSE_CHARSET);
    if (property != null) {
        contentEncoding = (String) property.getValue();
    }

    return new DefaultFileContentInfo(contentType, contentEncoding);
}
 
Example #7
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 #8
Source File: WebdavFileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Sets an attribute of this file. Is only called if {@link #doGetType} does not return {@link FileType#IMAGINARY}.
 */
@Override
protected void doSetAttribute(final String attrName, final Object value) throws Exception {
    try {
        final URLFileName fileName = (URLFileName) getName();
        final String urlStr = toUrlString(fileName);
        final DavPropertySet properties = new DavPropertySet();
        final DavPropertyNameSet propertyNameSet = new DavPropertyNameSet();
        final DavProperty property = new DefaultDavProperty(attrName, value, Namespace.EMPTY_NAMESPACE);
        if (value != null) {
            properties.add(property);
        } else {
            propertyNameSet.add(property.getName()); // remove property
        }

        final PropPatchMethod method = new PropPatchMethod(urlStr, properties, propertyNameSet);
        setupMethod(method);
        execute(method);
        if (!method.succeeded()) {
            throw new FileSystemException("Property '" + attrName + "' could not be set.");
        }
    } catch (final FileSystemException fse) {
        throw fse;
    } catch (final Exception e) {
        throw new FileSystemException("vfs.provider.webdav/set-attributes", e, getName(), attrName);
    }
}
 
Example #9
Source File: DavCollectionBaseTest.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Tests get include freeBusy rollup property.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testGetIncludeFreeBusyRollupProperty() throws Exception {
    testHelper.getHomeCollection().setExcludeFreeBusyRollup(false);
    DavCollectionBase dc = (DavCollectionBase) testHelper.initializeHomeResource();

    @SuppressWarnings("rawtypes")
    DavProperty efbr = dc.getProperty(EXCLUDEFREEBUSYROLLUP);
    Assert.assertNotNull("exclude-free-busy-rollup property not found", efbr);

    boolean flag = ((Boolean) efbr.getValue()).booleanValue();
    Assert.assertTrue("exclude-free-busy-rollup property not false", ! flag);
}
 
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: 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 #12
Source File: DavCollectionBaseTest.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Tests get exclude free busy rollup porperty.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testGetExcludeFreeBusyRollupProperty() throws Exception {
    testHelper.getHomeCollection().setExcludeFreeBusyRollup(true);
    DavCollectionBase dc = (DavCollectionBase) testHelper.initializeHomeResource();

    @SuppressWarnings("rawtypes")
    DavProperty efbr = dc.getProperty(EXCLUDEFREEBUSYROLLUP);
    Assert.assertNotNull("exclude-free-busy-rollup property not found", efbr);

    boolean flag = ((Boolean) efbr.getValue()).booleanValue();
    Assert.assertTrue("exclude-free-busy-rollup property not true", flag);
}
 
Example #13
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 #14
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 #15
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 #16
Source File: Webdav4FileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Sets an attribute of this file. Is only called if {@link #doGetType} does not return {@link FileType#IMAGINARY}.
 */
@Override
protected void doSetAttribute(final String attrName, final Object value) throws Exception {
    try {
        final GenericURLFileName fileName = (GenericURLFileName) getName();
        final String urlStr = toUrlString(fileName);
        final DavPropertySet properties = new DavPropertySet();
        final DavPropertyNameSet propertyNameSet = new DavPropertyNameSet();
        final DavProperty property = new DefaultDavProperty(attrName, value, Namespace.EMPTY_NAMESPACE);
        if (value != null) {
            properties.add(property);
        } else {
            propertyNameSet.add(property.getName()); // remove property
        }

        final HttpProppatch request = new HttpProppatch(urlStr, properties, propertyNameSet);
        setupRequest(request);
        final HttpResponse response = executeRequest(request);
        if (!request.succeeded(response)) {
            throw new FileSystemException("Property '" + attrName + "' could not be set.");
        }
    } catch (final FileSystemException fse) {
        throw fse;
    } catch (final Exception e) {
        throw new FileSystemException("vfs.provider.webdav/set-attributes", e, getName(), attrName);
    }
}
 
Example #17
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 #18
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 #19
Source File: HC4DavExchangeSession.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
protected long getLongPropertyIfExists(DavPropertySet properties, @SuppressWarnings("SameParameterValue") String alias) {
    DavProperty property = properties.get(Field.getPropertyName(alias));
    if (property == null) {
        return 0;
    } else {
        return Long.parseLong((String) property.getValue());
    }
}
 
Example #20
Source File: DavResourceImpl.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @see DavResource#getProperty(org.apache.jackrabbit.webdav.property.DavPropertyName)
 */
public DavProperty getProperty(DavPropertyName name) {
	initProperties();

	log.debug("getProperty(..) " + name);

	return properties.get(name);
}
 
Example #21
Source File: HC4DavExchangeSession.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
protected String getURIPropertyIfExists(DavPropertySet properties, String alias) throws IOException {
    DavProperty property = properties.get(Field.getPropertyName(alias));
    if (property == null) {
        return null;
    } else {
        return URIUtil.decode((String) property.getValue());
    }
}
 
Example #22
Source File: HC4DavExchangeSession.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
protected String getPropertyIfExists(DavPropertySet properties, String alias) {
    DavProperty property = properties.get(Field.getResponsePropertyName(alias));
    if (property == null) {
        return null;
    } else {
        Object value = property.getValue();
        if (value instanceof Node) {
            return ((Node) value).getTextContent();
        } else if (value instanceof List) {
            StringBuilder buffer = new StringBuilder();
            for (Object node : (List) value) {
                if (buffer.length() > 0) {
                    buffer.append(',');
                }
                if (node instanceof Node) {
                    // jackrabbit
                    buffer.append(((Node) node).getTextContent());
                } else {
                    // ExchangeDavMethod
                    buffer.append(node);
                }
            }
            return buffer.toString();
        } else {
            return (String) value;
        }
    }
}
 
Example #23
Source File: HC4DavExchangeSession.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
protected int getIntPropertyIfExists(DavPropertySet properties, String alias) {
    DavProperty property = properties.get(Field.getPropertyName(alias));
    if (property == null) {
        return 0;
    } else {
        return Integer.parseInt((String) property.getValue());
    }
}
 
Example #24
Source File: AppointmentManager.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
private static String getTextValuefromProperty(DavProperty<?> property) {
	String value = null;

	if (property != null) {
		for (Object o : (Collection<?>) property.getValue()) {
			if (o instanceof Element) {
				Element e = (Element) o;
				value = DomUtil.getTextTrim(e);
				break;
			}
		}
	}
	return value;
}
 
Example #25
Source File: HC4DavExchangeSession.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
protected double getDoublePropertyIfExists(DavPropertySet properties, @SuppressWarnings("SameParameterValue") String alias) {
    DavProperty property = properties.get(Field.getResponsePropertyName(alias));
    if (property == null) {
        return 0;
    } else {
        return Double.parseDouble((String) property.getValue());
    }
}
 
Example #26
Source File: DavExchangeSession.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
protected String getURIPropertyIfExists(DavPropertySet properties, String alias) throws IOException {
    DavProperty property = properties.get(Field.getPropertyName(alias));
    if (property == null) {
        return null;
    } else {
        return URIUtil.decode((String) property.getValue());
    }
}
 
Example #27
Source File: DavExchangeSession.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
protected String getPropertyIfExists(DavPropertySet properties, String alias) {
    DavProperty property = properties.get(Field.getResponsePropertyName(alias));
    if (property == null) {
        return null;
    } else {
        Object value = property.getValue();
        if (value instanceof Node) {
            return ((Node) value).getTextContent();
        } else if (value instanceof List) {
            StringBuilder buffer = new StringBuilder();
            for (Object node : (List) value) {
                if (buffer.length() > 0) {
                    buffer.append(',');
                }
                if (node instanceof Node) {
                    // jackrabbit
                    buffer.append(((Node) node).getTextContent());
                } else {
                    // ExchangeDavMethod
                    buffer.append(node);
                }
            }
            return buffer.toString();
        } else {
            return (String) value;
        }
    }
}
 
Example #28
Source File: DavExchangeSession.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
protected int getIntPropertyIfExists(DavPropertySet properties, String alias) {
    DavProperty property = properties.get(Field.getPropertyName(alias));
    if (property == null) {
        return 0;
    } else {
        return Integer.parseInt((String) property.getValue());
    }
}
 
Example #29
Source File: DavExchangeSession.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
protected long getLongPropertyIfExists(DavPropertySet properties, @SuppressWarnings("SameParameterValue") String alias) {
    DavProperty property = properties.get(Field.getPropertyName(alias));
    if (property == null) {
        return 0;
    } else {
        return Long.parseLong((String) property.getValue());
    }
}
 
Example #30
Source File: DavExchangeSession.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
protected double getDoublePropertyIfExists(DavPropertySet properties, @SuppressWarnings("SameParameterValue") String alias) {
    DavProperty property = properties.get(Field.getResponsePropertyName(alias));
    if (property == null) {
        return 0;
    } else {
        return Double.parseDouble((String) property.getValue());
    }
}