org.apache.jackrabbit.webdav.xml.XmlSerializable Java Examples

The following examples show how to use org.apache.jackrabbit.webdav.xml.XmlSerializable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlSerializer.java    From cosmo with Apache License 2.0 6 votes vote down vote up
public static String serialize(XmlSerializable serializable)
    throws IOException {
    StringWriter out = new StringWriter();
    try {
        Document doc = BUILDER_FACTORY.newDocumentBuilder().newDocument();
        doc.appendChild(serializable.toXml(doc));
        
        OutputFormat format = new OutputFormat("xml", "UTF-8", true);
        XMLSerializer serializer =
            new XMLSerializer(out, format);
        serializer.setNamespaces(true);
        serializer.asDOMSerializer().serialize(doc);

        return out.toString();
    } catch (ParserConfigurationException e) {
        throw new CosmoParseException(e);
    }
}
 
Example #2
Source File: Field.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create DavProperty object for field alias and value.
 *
 * @param alias DavMail field alias
 * @param value field value
 * @return DavProperty with value or DavPropertyName for null values
 */
public static PropEntry createDavProperty(String alias, String value) {
    Field field = Field.get(alias);
    if (value == null) {
        // return DavPropertyName to remove property
        return field.updatePropertyName;
    } else if (field.isMultivalued) {
        // multivalued field, split values separated by \n
        List<XmlSerializable> valueList = new ArrayList<>();
        String[] values = value.split(",");
        for (final String singleValue : values) {
            valueList.add(document -> DomUtil.createElement(document, "v", XML, singleValue));
        }

        return new DefaultDavProperty<>(field.updatePropertyName, valueList);
    } else if (field.isBooleanValue && !"haspicture".equals(alias)) {
        if ("true".equals(value)) {
            return new DefaultDavProperty<>(field.updatePropertyName, "1");
        } else if ("false".equals(value)) {
            return new DefaultDavProperty<>(field.updatePropertyName, "0");
        } else {
            throw new RuntimeException("Invalid value for " + field.alias + ": " + value);
        }
    } else {
        return new DefaultDavProperty<>(field.updatePropertyName, value);
    }
}
 
Example #3
Source File: StandardDavResponse.java    From cosmo with Apache License 2.0 5 votes vote down vote up
@Override
public void sendXmlResponse(XmlSerializable serializable, int status) throws IOException {
    super.sendXmlResponse(serializable, status);
    if (serializable != null && LOG.isTraceEnabled()) {
        StringBuilder sb = new StringBuilder("\n------------------------ Dump of response -------------------\n");
        sb.append("Status: ").append(status).append("\n");
        sb.append(XmlSerializer.serialize(serializable));
        sb.append("\n------------------------ End dump of response -------------------");
        LOG.trace(sb.toString());
    }
}