Search in sources :

Example 6 with Xml

use of ezvcard.property.Xml in project ez-vcard by mangstadt.

the class XmlScribe method _parseXml.

@Override
protected Xml _parseXml(XCardElement element, VCardParameters parameters, ParseContext context) {
    Xml xml = new Xml(element.element());
    // remove the <parameters> element
    Element root = xml.getValue().getDocumentElement();
    for (Element child : XmlUtils.toElementList(root.getChildNodes())) {
        if ("parameters".equals(child.getLocalName()) && VCardVersion.V4_0.getXmlNamespace().equals(child.getNamespaceURI())) {
            root.removeChild(child);
        }
    }
    return xml;
}
Also used : Xml(ezvcard.property.Xml) XCardElement(ezvcard.io.xml.XCardElement) Element(org.w3c.dom.Element)

Example 7 with Xml

use of ezvcard.property.Xml in project ez-vcard by mangstadt.

the class XCardWriter method write.

@SuppressWarnings({ "rawtypes", "unchecked" })
private void write(VCardProperty property, VCard vcard) throws SAXException {
    VCardPropertyScribe scribe = index.getPropertyScribe(property);
    VCardParameters parameters = scribe.prepareParameters(property, targetVersion, vcard);
    // get the property element to write
    Element propertyElement;
    if (property instanceof Xml) {
        Xml xml = (Xml) property;
        Document value = xml.getValue();
        if (value == null) {
            return;
        }
        propertyElement = value.getDocumentElement();
    } else {
        QName qname = scribe.getQName();
        propertyElement = DOC.createElementNS(qname.getNamespaceURI(), qname.getLocalPart());
        try {
            scribe.writeXml(property, propertyElement);
        } catch (SkipMeException e) {
            return;
        } catch (EmbeddedVCardException e) {
            return;
        }
    }
    start(propertyElement);
    write(parameters);
    write(propertyElement);
    end(propertyElement);
}
Also used : VCardPropertyScribe(ezvcard.io.scribe.VCardPropertyScribe) VCardParameters(ezvcard.parameter.VCardParameters) EmbeddedVCardException(ezvcard.io.EmbeddedVCardException) Xml(ezvcard.property.Xml) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) SkipMeException(ezvcard.io.SkipMeException) Document(org.w3c.dom.Document)

Aggregations

Xml (ezvcard.property.Xml)7 VCard (ezvcard.VCard)5 Test (org.junit.Test)5 Document (org.w3c.dom.Document)4 XCardDocumentStreamWriter (ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter)2 Element (org.w3c.dom.Element)2 AgeProperty (ezvcard.io.AgeProperty)1 AgeScribe (ezvcard.io.AgeProperty.AgeScribe)1 EmbeddedVCardException (ezvcard.io.EmbeddedVCardException)1 LuckyNumProperty (ezvcard.io.LuckyNumProperty)1 LuckyNumScribe (ezvcard.io.LuckyNumProperty.LuckyNumScribe)1 MyFormattedNameProperty (ezvcard.io.MyFormattedNameProperty)1 MyFormattedNameScribe (ezvcard.io.MyFormattedNameProperty.MyFormattedNameScribe)1 SalaryProperty (ezvcard.io.SalaryProperty)1 SalaryScribe (ezvcard.io.SalaryProperty.SalaryScribe)1 SkipMeException (ezvcard.io.SkipMeException)1 VCardPropertyScribe (ezvcard.io.scribe.VCardPropertyScribe)1 XCardElement (ezvcard.io.xml.XCardElement)1 VCardParameters (ezvcard.parameter.VCardParameters)1 RawProperty (ezvcard.property.RawProperty)1