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());
}
}
}
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;
}
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;
}
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);
}
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);
}
Aggregations