Search in sources :

Example 1 with XmlSerializable

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);
}
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 2 with XmlSerializable

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

Example 3 with XmlSerializable

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:
     * &lt;D:displayname&gt;WebDAV Directory&lt;/D:displayname&gt;
     *
     * new DavProperty("resourcetype", new Element("collection")).toXml
     * gives a element like:
     * &lt;D:resourcetype&gt;&lt;D:collection/&gt;&lt;/D:resourcetype&gt;
     *
     * Element[] customVals = { new Element("bla", customNamespace), new Element("bli", customNamespace) };
     * new DavProperty("custom-property", customVals, customNamespace).toXml
     * gives an element like
     * &lt;Z:custom-property&gt;
     *    &lt;Z:bla/&gt;
     *    &lt;Z:bli/&gt;
     * &lt;/Z:custom-property&gt;
     * </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;
}
Also used : Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) XmlSerializable(org.apache.jackrabbit.webdav.xml.XmlSerializable) Collection(java.util.Collection)

Aggregations

XmlSerializable (org.apache.jackrabbit.webdav.xml.XmlSerializable)3 Element (org.w3c.dom.Element)3 ArrayList (java.util.ArrayList)2 DefaultDavProperty (org.apache.jackrabbit.webdav.property.DefaultDavProperty)2 Document (org.w3c.dom.Document)2 StringWriter (java.io.StringWriter)1 Collection (java.util.Collection)1 Name (org.apache.jackrabbit.spi.Name)1 NamePathResolver (org.apache.jackrabbit.spi.commons.conversion.NamePathResolver)1 CompactNodeTypeDefWriter (org.apache.jackrabbit.spi.commons.nodetype.compact.CompactNodeTypeDefWriter)1 Text (org.apache.jackrabbit.util.Text)1 DavPropertyName (org.apache.jackrabbit.webdav.property.DavPropertyName)1 Node (org.w3c.dom.Node)1