Example usage for org.apache.commons.vfs FileContent setAttribute

List of usage examples for org.apache.commons.vfs FileContent setAttribute

Introduction

In this page you can find the example usage for org.apache.commons.vfs FileContent setAttribute.

Prototype

void setAttribute(String attrName, Object value) throws FileSystemException;

Source Link

Document

Sets the value of an attribute of the file's content.

Usage

From source file:com.thinkberg.webdav.data.DavResource.java

protected boolean setPropertyValue(Element root, Element propertyEl) {
    LogFactory.getLog(getClass()).debug(String.format("[%s].set('%s')", object.getName(), propertyEl.asXML()));

    if (!ALL_PROPERTIES.contains(propertyEl.getName())) {
        final String nameSpace = propertyEl.getNamespaceURI();
        final String attributeName = getFQName(nameSpace, propertyEl.getName());
        try {/*from   w w w.  j a va 2 s .c  o  m*/
            FileContent objectContent = object.getContent();
            final String command = propertyEl.getParent().getParent().getName();
            if (TAG_PROP_SET.equals(command)) {
                StringWriter propertyValueWriter = new StringWriter();
                propertyEl.write(propertyValueWriter);
                propertyValueWriter.close();
                objectContent.setAttribute(attributeName, propertyValueWriter.getBuffer().toString());
            } else if (TAG_PROP_REMOVE.equals(command)) {
                objectContent.setAttribute(attributeName, null);
            }
            root.addElement(propertyEl.getQName());
            return true;
        } catch (IOException e) {
            LogFactory.getLog(getClass()).error(String.format("can't store attribute property '%s' = '%s'",
                    attributeName, propertyEl.asXML()), e);
        }
    }
    return false;
}

From source file:org.efaps.webdav4vfs.data.DavResource.java

@Override()
protected boolean setPropertyValue(Element root, Element propertyEl) {
    LogFactory.getLog(getClass()).debug(String.format("[%s].set('%s')", object.getName(), propertyEl.asXML()));

    if (!ALL_PROPERTIES.contains(propertyEl.getName())) {
        final String nameSpace = propertyEl.getNamespaceURI();
        final String attributeName = getFQName(nameSpace, propertyEl.getName());
        try {//from   ww w.j a v a 2s .c  o m
            FileContent objectContent = object.getContent();
            final String command = propertyEl.getParent().getParent().getName();
            if (TAG_PROP_SET.equals(command)) {
                StringWriter propertyValueWriter = new StringWriter();
                propertyEl.write(propertyValueWriter);
                propertyValueWriter.close();
                objectContent.setAttribute(attributeName, propertyValueWriter.getBuffer().toString());
            } else if (TAG_PROP_REMOVE.equals(command)) {
                objectContent.setAttribute(attributeName, null);
            }
            root.addElement(propertyEl.getQName());
            return true;
        } catch (IOException e) {
            LogFactory.getLog(getClass()).error(String.format("can't store attribute property '%s' = '%s'",
                    attributeName, propertyEl.asXML()), e);
        }
    }
    return false;
}