Search in sources :

Example 1 with CompactNodeTypeDefWriter

use of org.apache.jackrabbit.spi.commons.nodetype.compact.CompactNodeTypeDefWriter in project jackrabbit by apache.

the class AbstractRecord method writeNodeTypeDef.

/**
     * {@inheritDoc}
     */
public void writeNodeTypeDef(QNodeTypeDefinition ntd) throws JournalException {
    try {
        StringWriter sw = new StringWriter();
        CompactNodeTypeDefWriter writer = new CompactNodeTypeDefWriter(sw, nsResolver, resolver);
        writer.write(ntd);
        writer.close();
        writeString(sw.toString());
    } catch (IOException e) {
        String msg = "I/O error while writing node type definition.";
        throw new JournalException(msg, e);
    }
}
Also used : StringWriter(java.io.StringWriter) IOException(java.io.IOException) CompactNodeTypeDefWriter(org.apache.jackrabbit.spi.commons.nodetype.compact.CompactNodeTypeDefWriter)

Example 2 with CompactNodeTypeDefWriter

use of org.apache.jackrabbit.spi.commons.nodetype.compact.CompactNodeTypeDefWriter 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)

Aggregations

StringWriter (java.io.StringWriter)2 CompactNodeTypeDefWriter (org.apache.jackrabbit.spi.commons.nodetype.compact.CompactNodeTypeDefWriter)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 DefaultDavProperty (org.apache.jackrabbit.webdav.property.DefaultDavProperty)1 XmlSerializable (org.apache.jackrabbit.webdav.xml.XmlSerializable)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1