use of org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefWriter in project jackrabbit by apache.
the class WorkspaceResourceImpl method getProperty.
@Override
public DavProperty<?> getProperty(DavPropertyName name) {
DavProperty prop = super.getProperty(name);
if (prop == null) {
StringWriter writer = null;
try {
if (ItemResourceConstants.JCR_NODETYPES_CND.equals(name)) {
writer = new StringWriter();
Session s = getRepositorySession();
CompactNodeTypeDefWriter cndWriter = new CompactNodeTypeDefWriter(writer, s, true);
NodeTypeIterator ntIterator = s.getWorkspace().getNodeTypeManager().getAllNodeTypes();
while (ntIterator.hasNext()) {
cndWriter.write(ntIterator.nextNodeType());
}
cndWriter.close();
/*
NOTE: avoid having JCR_NODETYPES_CND exposed upon allprop
PROPFIND request since it needs to be calculated.
nevertheless, this property can be altered using
PROPPATCH, which is not consistent with the specification
*/
prop = new DefaultDavProperty<String>(ItemResourceConstants.JCR_NODETYPES_CND, writer.toString(), true);
} else if (SecurityConstants.SUPPORTED_PRIVILEGE_SET.equals(name)) {
prop = new JcrSupportedPrivilegesProperty(getRepositorySession(), null).asDavProperty();
} else if (SecurityConstants.CURRENT_USER_PRIVILEGE_SET.equals(name)) {
prop = new JcrUserPrivilegesProperty(getRepositorySession(), null).asDavProperty();
}
} catch (RepositoryException e) {
log.error("Failed to access NodeTypeManager: " + e.getMessage());
} catch (IOException e) {
log.error("Failed to write compact node definition: " + e.getMessage());
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
log.error(e.getMessage());
}
}
}
}
return prop;
}
use of org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefWriter in project jackrabbit-oak by apache.
the class NodeTypeImpl method getCnd.
/**
* Returns the namespace neutral CND of the given node type definition.
* @param def the node type definition
* @return the CND
*/
private static String getCnd(NodeTypeDefinition def) {
StringWriter out = new StringWriter();
CompactNodeTypeDefWriter cndWriter = new CompactNodeTypeDefWriter(out, new CompactNodeTypeDefWriter.NamespaceMapping() {
@Override
public String getNamespaceURI(String s) {
return s;
}
}, false);
try {
cndWriter.write(def);
} catch (IOException e) {
// should never occur
log.error("Error generating CND of " + def, e);
throw new IllegalStateException(e);
}
return out.toString();
}
Aggregations