Search in sources :

Example 6 with DefaultDavProperty

use of org.apache.jackrabbit.webdav.property.DefaultDavProperty in project jackrabbit by apache.

the class DefaultItemResource method initProperties.

/**
     * Add resource specific properties.
     */
@Override
protected void initProperties() {
    super.initProperties();
    if (exists()) {
        try {
            Property prop = (Property) item;
            int type = prop.getType();
            // set the content type
            String contentType;
            if (isMultiple()) {
                contentType = IOUtil.buildContentType("text/xml", "utf-8");
            } else {
                contentType = IOUtil.buildContentType(JcrValueType.contentTypeFromType(type), "utf-8");
            }
            properties.add(new DefaultDavProperty<String>(DavPropertyName.GETCONTENTTYPE, contentType));
            // add jcr-specific resource properties
            properties.add(new DefaultDavProperty<String>(JCR_TYPE, PropertyType.nameFromValue(type)));
            if (isMultiple()) {
                properties.add(new ValuesProperty(prop.getValues()));
            } else {
                properties.add(new ValuesProperty(prop.getValue()));
            }
        } catch (RepositoryException e) {
            log.error("Failed to retrieve resource properties: " + e.getMessage());
        }
    }
}
Also used : ValuesProperty(org.apache.jackrabbit.webdav.jcr.property.ValuesProperty) RepositoryException(javax.jcr.RepositoryException) LengthsProperty(org.apache.jackrabbit.webdav.jcr.property.LengthsProperty) Property(javax.jcr.Property) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) ValuesProperty(org.apache.jackrabbit.webdav.jcr.property.ValuesProperty)

Example 7 with DefaultDavProperty

use of org.apache.jackrabbit.webdav.property.DefaultDavProperty in project jackrabbit by apache.

the class DefaultItemResource method getProperty.

@Override
public DavProperty<?> getProperty(DavPropertyName name) {
    DavProperty prop = super.getProperty(name);
    if (prop == null && exists()) {
        try {
            Property p = (Property) item;
            if (isMultiple()) {
                if (JCR_LENGTHS.equals(name)) {
                    prop = new LengthsProperty(p.getLengths());
                }
            } else {
                if (JCR_LENGTH.equals(name)) {
                    long length = p.getLength();
                    prop = new DefaultDavProperty<String>(JCR_LENGTH, String.valueOf(length), true);
                } else if (JCR_GET_STRING.equals(name) && p.getType() != PropertyType.BINARY) {
                    // getstring property is only created for single value
                    // non-binary jcr properties
                    prop = new DefaultDavProperty<String>(JCR_GET_STRING, p.getString(), true);
                }
            }
        } catch (RepositoryException e) {
            log.error("Failed to retrieve resource properties: " + e.getMessage());
        }
    }
    return prop;
}
Also used : DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) LengthsProperty(org.apache.jackrabbit.webdav.jcr.property.LengthsProperty) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) RepositoryException(javax.jcr.RepositoryException) LengthsProperty(org.apache.jackrabbit.webdav.jcr.property.LengthsProperty) Property(javax.jcr.Property) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) ValuesProperty(org.apache.jackrabbit.webdav.jcr.property.ValuesProperty)

Example 8 with DefaultDavProperty

use of org.apache.jackrabbit.webdav.property.DefaultDavProperty in project jackrabbit by apache.

the class AbstractItemResource method getProperty.

@Override
public DavProperty<?> getProperty(DavPropertyName name) {
    DavProperty prop = super.getProperty(name);
    if (prop == null) {
        if (JCR_DEFINITION.equals(name)) {
            if (exists()) {
                try {
                    // protected 'definition' property revealing the item definition
                    ItemDefinitionImpl val;
                    if (item.isNode()) {
                        val = NodeDefinitionImpl.create(((Node) item).getDefinition());
                    } else {
                        val = PropertyDefinitionImpl.create(((Property) item).getDefinition());
                    }
                    prop = new DefaultDavProperty<ItemDefinitionImpl>(JCR_DEFINITION, val, true);
                } catch (RepositoryException e) {
                    // should not get here
                    log.error("Error while accessing item definition: " + e.getMessage());
                }
            }
        } else if (JCR_ISNEW.equals(name)) {
            // transaction resource additional protected properties
            if (exists() && item.isNew()) {
                prop = new DefaultDavProperty<String>(JCR_ISNEW, null, true);
            }
        } else if (JCR_ISMODIFIED.equals(name)) {
            // transaction resource additional protected properties
            if (exists() && item.isModified()) {
                prop = new DefaultDavProperty<String>(JCR_ISMODIFIED, null, true);
            }
        } else if (ObservationConstants.SUBSCRIPTIONDISCOVERY.equals(name)) {
            // observation resource
            prop = subsMgr.getSubscriptionDiscovery(this);
        }
    }
    return prop;
}
Also used : DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) Node(javax.jcr.Node) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) ItemDefinitionImpl(org.apache.jackrabbit.webdav.jcr.nodetype.ItemDefinitionImpl) RepositoryException(javax.jcr.RepositoryException) Property(javax.jcr.Property) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty)

Example 9 with DefaultDavProperty

use of org.apache.jackrabbit.webdav.property.DefaultDavProperty in project jackrabbit by apache.

the class RepositoryServiceImpl method createRegisterNodeTypesProperty.

private DavProperty<List<XmlSerializable>> createRegisterNodeTypesProperty(SessionInfo sessionInfo, QNodeTypeDefinition[] nodeTypeDefinitions, final boolean allowUpdate) throws IOException {
    // create xml elements for both cnd and allow update value.
    List<XmlSerializable> val = new ArrayList<XmlSerializable>();
    StringWriter sw = new StringWriter();
    CompactNodeTypeDefWriter writer = new CompactNodeTypeDefWriter(sw, new NamespaceResolverImpl(sessionInfo), true);
    writer.write(Arrays.asList(nodeTypeDefinitions));
    writer.close();
    final String cnd = sw.toString();
    val.add(new XmlSerializable() {

        public Element toXml(Document document) {
            Element cndElem = document.createElementNS(JcrRemotingConstants.NS_URI, JcrRemotingConstants.NS_PREFIX + ":" + JcrRemotingConstants.XML_CND);
            DomUtil.setText(cndElem, cnd);
            return cndElem;
        }
    });
    val.add(new XmlSerializable() {

        public Element toXml(Document document) {
            Element allowElem = document.createElementNS(JcrRemotingConstants.NS_URI, JcrRemotingConstants.NS_PREFIX + ":" + JcrRemotingConstants.XML_ALLOWUPDATE);
            DomUtil.setText(allowElem, Boolean.toString(allowUpdate));
            return allowElem;
        }
    });
    return new DefaultDavProperty<List<XmlSerializable>>(JcrRemotingConstants.JCR_NODETYPES_CND_LN, val, ItemResourceConstants.NAMESPACE, false);
}
Also used : DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) StringWriter(java.io.StringWriter) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) XmlSerializable(org.apache.jackrabbit.webdav.xml.XmlSerializable) Document(org.w3c.dom.Document) CompactNodeTypeDefWriter(org.apache.jackrabbit.spi.commons.nodetype.compact.CompactNodeTypeDefWriter)

Example 10 with DefaultDavProperty

use of org.apache.jackrabbit.webdav.property.DefaultDavProperty in project jackrabbit by apache.

the class RepositoryServiceImpl method createUnRegisterNodeTypesProperty.

private DavProperty<List<XmlSerializable>> createUnRegisterNodeTypesProperty(SessionInfo sessionInfo, Name[] nodeTypeNames) throws IOException, RepositoryException {
    NamePathResolver resolver = getNamePathResolver(sessionInfo);
    List<XmlSerializable> val = new ArrayList<XmlSerializable>();
    for (Name ntName : nodeTypeNames) {
        final String jcrName = resolver.getJCRName(ntName);
        val.add(new XmlSerializable() {

            public Element toXml(Document document) {
                Element ntNameElem = document.createElementNS(JcrRemotingConstants.NS_URI, JcrRemotingConstants.NS_PREFIX + ":" + JcrRemotingConstants.XML_NODETYPENAME);
                org.w3c.dom.Text txt = document.createTextNode(jcrName);
                ntNameElem.appendChild(txt);
                return ntNameElem;
            }
        });
    }
    return new DefaultDavProperty<List<XmlSerializable>>(JcrRemotingConstants.JCR_NODETYPES_CND_LN, val, ItemResourceConstants.NAMESPACE, false);
}
Also used : NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) XmlSerializable(org.apache.jackrabbit.webdav.xml.XmlSerializable) Text(org.apache.jackrabbit.util.Text) Document(org.w3c.dom.Document) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName) Name(org.apache.jackrabbit.spi.Name)

Aggregations

DefaultDavProperty (org.apache.jackrabbit.webdav.property.DefaultDavProperty)10 RepositoryException (javax.jcr.RepositoryException)8 DavProperty (org.apache.jackrabbit.webdav.property.DavProperty)7 Node (javax.jcr.Node)5 Property (javax.jcr.Property)5 ArrayList (java.util.ArrayList)4 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)4 StringWriter (java.io.StringWriter)2 PropertyIterator (javax.jcr.PropertyIterator)2 Version (javax.jcr.version.Version)2 LengthsProperty (org.apache.jackrabbit.webdav.jcr.property.LengthsProperty)2 ValuesProperty (org.apache.jackrabbit.webdav.jcr.property.ValuesProperty)2 JcrSupportedPrivilegesProperty (org.apache.jackrabbit.webdav.jcr.security.JcrSupportedPrivilegesProperty)2 JcrUserPrivilegesProperty (org.apache.jackrabbit.webdav.jcr.security.JcrUserPrivilegesProperty)2 LabelSetProperty (org.apache.jackrabbit.webdav.version.LabelSetProperty)2 XmlSerializable (org.apache.jackrabbit.webdav.xml.XmlSerializable)2 Document (org.w3c.dom.Document)2 Element (org.w3c.dom.Element)2 IOException (java.io.IOException)1 List (java.util.List)1