use of org.apache.jackrabbit.webdav.xml.XmlSerializable 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.xml.XmlSerializable 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);
}
use of org.apache.jackrabbit.webdav.xml.XmlSerializable in project jackrabbit by apache.
the class AbstractDavProperty method toXml.
/**
* Return a XML element representation of this property. The value of the
* property will be added as text or as child element.
* <pre>
* new DavProperty("displayname", "WebDAV Directory").toXml
* gives a element like:
* <D:displayname>WebDAV Directory</D:displayname>
*
* new DavProperty("resourcetype", new Element("collection")).toXml
* gives a element like:
* <D:resourcetype><D:collection/></D:resourcetype>
*
* Element[] customVals = { new Element("bla", customNamespace), new Element("bli", customNamespace) };
* new DavProperty("custom-property", customVals, customNamespace).toXml
* gives an element like
* <Z:custom-property>
* <Z:bla/>
* <Z:bli/>
* </Z:custom-property>
* </pre>
*
* @return a XML element of this property
* @see org.apache.jackrabbit.webdav.xml.XmlSerializable#toXml(Document)
* @param document
*/
public Element toXml(Document document) {
Element elem = getName().toXml(document);
T value = getValue();
// todo: improve....
if (value != null) {
if (value instanceof XmlSerializable) {
elem.appendChild(((XmlSerializable) value).toXml(document));
} else if (value instanceof Node) {
Node n = document.importNode((Node) value, true);
elem.appendChild(n);
} else if (value instanceof Node[]) {
for (int i = 0; i < ((Node[]) value).length; i++) {
Node n = document.importNode(((Node[]) value)[i], true);
elem.appendChild(n);
}
} else if (value instanceof Collection) {
for (Object entry : ((Collection<?>) value)) {
if (entry instanceof XmlSerializable) {
elem.appendChild(((XmlSerializable) entry).toXml(document));
} else if (entry instanceof Node) {
Node n = document.importNode((Node) entry, true);
elem.appendChild(n);
} else {
DomUtil.setText(elem, entry.toString());
}
}
} else {
DomUtil.setText(elem, value.toString());
}
}
return elem;
}
Aggregations