Search in sources :

Example 1 with IXMLWriter

use of org.hl7.fhir.utilities.xml.IXMLWriter in project org.hl7.fhir.core by hapifhir.

the class XmlParser method composeElement.

private void composeElement(IXMLWriter xml, Element element, String elementName) throws IOException {
    for (String s : element.getComments()) {
        xml.comment(s, true);
    }
    if (isText(element.getProperty())) {
        if (linkResolver != null)
            xml.link(linkResolver.resolveProperty(element.getProperty()));
        xml.enter(elementName);
        xml.text(element.getValue());
        xml.exit(elementName);
    } else if (element.isPrimitive() || (element.hasType() && isPrimitive(element.getType()))) {
        if (element.getType().equals("xhtml")) {
            xml.escapedText(element.getValue());
        } else if (isText(element.getProperty())) {
            if (linkResolver != null)
                xml.link(linkResolver.resolveProperty(element.getProperty()));
            xml.text(element.getValue());
        } else {
            if (element.hasValue()) {
                if (linkResolver != null)
                    xml.link(linkResolver.resolveType(element.getType()));
                xml.attribute("value", element.getValue());
            }
            if (linkResolver != null)
                xml.link(linkResolver.resolveProperty(element.getProperty()));
            if (element.hasChildren()) {
                xml.enter(elementName);
                for (Element child : element.getChildren()) composeElement(xml, child, child.getName());
                xml.exit(elementName);
            } else
                xml.element(elementName);
        }
    } else {
        for (Element child : element.getChildren()) {
            if (isAttr(child.getProperty())) {
                if (linkResolver != null)
                    xml.link(linkResolver.resolveType(child.getType()));
                xml.attribute(child.getName(), child.getValue());
            }
        }
        if (linkResolver != null)
            xml.link(linkResolver.resolveProperty(element.getProperty()));
        xml.enter(elementName);
        if (element.getSpecial() != null) {
            if (linkResolver != null)
                xml.link(linkResolver.resolveProperty(element.getProperty()));
            xml.enter(element.getType());
        }
        for (Element child : element.getChildren()) {
            if (isText(child.getProperty())) {
                if (linkResolver != null)
                    xml.link(linkResolver.resolveProperty(element.getProperty()));
                xml.text(child.getValue());
            } else if (!isAttr(child.getProperty()))
                composeElement(xml, child, child.getName());
        }
        if (element.getSpecial() != null)
            xml.exit(element.getType());
        xml.exit(elementName);
    }
}
Also used : SpecialElement(org.hl7.fhir.dstu3.elementmodel.Element.SpecialElement)

Example 2 with IXMLWriter

use of org.hl7.fhir.utilities.xml.IXMLWriter in project org.hl7.fhir.core by hapifhir.

the class XmlParser method composeElement.

private void composeElement(IXMLWriter xml, Element element, String elementName, boolean root) throws IOException, FHIRException {
    if (showDecorations) {
        @SuppressWarnings("unchecked") List<ElementDecoration> decorations = (List<ElementDecoration>) element.getUserData("fhir.decorations");
        if (decorations != null)
            for (ElementDecoration d : decorations) xml.decorate(d);
    }
    for (String s : element.getComments()) {
        xml.comment(s, true);
    }
    if (isText(element.getProperty())) {
        if (linkResolver != null)
            xml.link(linkResolver.resolveProperty(element.getProperty()));
        xml.enter(element.getProperty().getXmlNamespace(), elementName);
        xml.text(element.getValue());
        xml.exit(element.getProperty().getXmlNamespace(), elementName);
    } else if (!element.hasChildren() && !element.hasValue()) {
        if (element.getExplicitType() != null)
            xml.attribute("xsi:type", element.getExplicitType());
        xml.element(elementName);
    } else if (element.isPrimitive() || (element.hasType() && isPrimitive(element.getType()))) {
        if (element.getType().equals("xhtml")) {
            String rawXhtml = element.getValue();
            if (isCdaText(element.getProperty())) {
                new CDANarrativeFormat().convert(xml, new XhtmlParser().parseFragment(rawXhtml));
            } else {
                xml.escapedText(rawXhtml);
                xml.anchor("end-xhtml");
            }
        } else if (isText(element.getProperty())) {
            if (linkResolver != null)
                xml.link(linkResolver.resolveProperty(element.getProperty()));
            xml.text(element.getValue());
        } else {
            setXsiTypeIfIsTypeAttr(xml, element);
            if (element.hasValue()) {
                if (linkResolver != null)
                    xml.link(linkResolver.resolveType(element.getType()));
                xml.attribute("value", element.getValue());
            }
            if (linkResolver != null)
                xml.link(linkResolver.resolveProperty(element.getProperty()));
            if (element.hasChildren()) {
                xml.enter(element.getProperty().getXmlNamespace(), elementName);
                for (Element child : element.getChildren()) composeElement(xml, child, child.getName(), false);
                xml.exit(element.getProperty().getXmlNamespace(), elementName);
            } else
                xml.element(elementName);
        }
    } else {
        setXsiTypeIfIsTypeAttr(xml, element);
        for (Element child : element.getChildren()) {
            if (isAttr(child.getProperty())) {
                if (linkResolver != null)
                    xml.link(linkResolver.resolveType(child.getType()));
                String av = child.getValue();
                if (ToolingExtensions.hasExtension(child.getProperty().getDefinition(), "http://www.healthintersections.com.au/fhir/StructureDefinition/elementdefinition-dateformat"))
                    av = convertForDateFormatToExternal(ToolingExtensions.readStringExtension(child.getProperty().getDefinition(), "http://www.healthintersections.com.au/fhir/StructureDefinition/elementdefinition-dateformat"), av);
                xml.attribute(child.getProperty().getXmlNamespace(), child.getProperty().getXmlName(), av);
            }
        }
        if (linkResolver != null)
            xml.link(linkResolver.resolveProperty(element.getProperty()));
        xml.enter(element.getProperty().getXmlNamespace(), elementName);
        if (!root && element.getSpecial() != null) {
            if (linkResolver != null)
                xml.link(linkResolver.resolveProperty(element.getProperty()));
            xml.enter(element.getProperty().getXmlNamespace(), element.getType());
        }
        for (Element child : element.getChildren()) {
            if (isText(child.getProperty())) {
                if (linkResolver != null)
                    xml.link(linkResolver.resolveProperty(element.getProperty()));
                xml.text(child.getValue());
            } else if (!isAttr(child.getProperty()))
                composeElement(xml, child, child.getName(), false);
        }
        if (!root && element.getSpecial() != null)
            xml.exit(element.getProperty().getXmlNamespace(), element.getType());
        xml.exit(element.getProperty().getXmlNamespace(), elementName);
    }
}
Also used : XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) ElementDecoration(org.hl7.fhir.utilities.ElementDecoration) NamedElement(org.hl7.fhir.r4b.elementmodel.ParserBase.NamedElement) SpecialElement(org.hl7.fhir.r4b.elementmodel.Element.SpecialElement) ArrayList(java.util.ArrayList) List(java.util.List) CDANarrativeFormat(org.hl7.fhir.utilities.xhtml.CDANarrativeFormat)

Example 3 with IXMLWriter

use of org.hl7.fhir.utilities.xml.IXMLWriter in project org.hl7.fhir.core by hapifhir.

the class XmlParser method composeElement.

private void composeElement(IXMLWriter xml, Element element, String elementName, boolean root) throws IOException, FHIRException {
    if (showDecorations) {
        @SuppressWarnings("unchecked") List<ElementDecoration> decorations = (List<ElementDecoration>) element.getUserData("fhir.decorations");
        if (decorations != null)
            for (ElementDecoration d : decorations) xml.decorate(d);
    }
    for (String s : element.getComments()) {
        xml.comment(s, true);
    }
    if (isText(element.getProperty())) {
        if (linkResolver != null)
            xml.link(linkResolver.resolveProperty(element.getProperty()));
        xml.enter(elementName);
        xml.text(element.getValue());
        xml.exit(elementName);
    } else if (!element.hasChildren() && !element.hasValue()) {
        if (element.getExplicitType() != null)
            xml.attribute("xsi:type", element.getExplicitType());
        xml.element(elementName);
    } else if (element.isPrimitive() || (element.hasType() && isPrimitive(element.getType()))) {
        if (element.getType().equals("xhtml")) {
            String rawXhtml = element.getValue();
            if (isCdaText(element.getProperty())) {
                new CDANarrativeFormat().convert(xml, element.getXhtml());
            } else
                xml.escapedText(rawXhtml);
        } else if (isText(element.getProperty())) {
            if (linkResolver != null)
                xml.link(linkResolver.resolveProperty(element.getProperty()));
            xml.text(element.getValue());
        } else {
            if (isTypeAttr(element.getProperty()) && !Utilities.noString(element.getType())) {
                xml.attribute("xsi:type", element.getType());
            }
            if (element.hasValue()) {
                if (linkResolver != null)
                    xml.link(linkResolver.resolveType(element.getType()));
                xml.attribute("value", element.getValue());
            }
            if (linkResolver != null)
                xml.link(linkResolver.resolveProperty(element.getProperty()));
            if (element.hasChildren()) {
                xml.enter(elementName);
                for (Element child : element.getChildren()) composeElement(xml, child, child.getName(), false);
                xml.exit(elementName);
            } else
                xml.element(elementName);
        }
    } else {
        if (isTypeAttr(element.getProperty()) && !Utilities.noString(element.getType())) {
            xml.attribute("xsi:type", element.getType());
        }
        for (Element child : element.getChildren()) {
            if (isAttr(child.getProperty())) {
                if (linkResolver != null)
                    xml.link(linkResolver.resolveType(child.getType()));
                String av = child.getValue();
                if (ToolingExtensions.hasExtension(child.getProperty().getDefinition(), "http://www.healthintersections.com.au/fhir/StructureDefinition/elementdefinition-dateformat"))
                    av = convertForDateFormatToExternal(ToolingExtensions.readStringExtension(child.getProperty().getDefinition(), "http://www.healthintersections.com.au/fhir/StructureDefinition/elementdefinition-dateformat"), av);
                xml.attribute(child.getName(), av);
            }
        }
        if (linkResolver != null)
            xml.link(linkResolver.resolveProperty(element.getProperty()));
        xml.enter(elementName);
        if (!root && element.getSpecial() != null) {
            if (linkResolver != null)
                xml.link(linkResolver.resolveProperty(element.getProperty()));
            xml.enter(element.getType());
        }
        for (Element child : element.getChildren()) {
            if (isText(child.getProperty())) {
                if (linkResolver != null)
                    xml.link(linkResolver.resolveProperty(element.getProperty()));
                xml.text(child.getValue());
            } else if (!isAttr(child.getProperty()))
                composeElement(xml, child, child.getName(), false);
        }
        if (!root && element.getSpecial() != null)
            xml.exit(element.getType());
        xml.exit(elementName);
    }
}
Also used : ElementDecoration(org.hl7.fhir.utilities.ElementDecoration) SpecialElement(org.hl7.fhir.r4.elementmodel.Element.SpecialElement) ArrayList(java.util.ArrayList) List(java.util.List) CDANarrativeFormat(org.hl7.fhir.utilities.xhtml.CDANarrativeFormat)

Example 4 with IXMLWriter

use of org.hl7.fhir.utilities.xml.IXMLWriter in project org.hl7.fhir.core by hapifhir.

the class XmlParser method composeElement.

private void composeElement(IXMLWriter xml, Element element, String elementName, boolean root) throws IOException, FHIRException {
    if (showDecorations) {
        @SuppressWarnings("unchecked") List<ElementDecoration> decorations = (List<ElementDecoration>) element.getUserData("fhir.decorations");
        if (decorations != null)
            for (ElementDecoration d : decorations) xml.decorate(d);
    }
    for (String s : element.getComments()) {
        xml.comment(s, true);
    }
    if (isText(element.getProperty())) {
        if (linkResolver != null)
            xml.link(linkResolver.resolveProperty(element.getProperty()));
        xml.enter(element.getProperty().getXmlNamespace(), elementName);
        xml.text(element.getValue());
        xml.exit(element.getProperty().getXmlNamespace(), elementName);
    } else if (!element.hasChildren() && !element.hasValue()) {
        if (element.getExplicitType() != null)
            xml.attribute("xsi:type", element.getExplicitType());
        xml.element(elementName);
    } else if (element.isPrimitive() || (element.hasType() && isPrimitive(element.getType()))) {
        if (element.getType().equals("xhtml")) {
            String rawXhtml = element.getValue();
            if (isCdaText(element.getProperty())) {
                new CDANarrativeFormat().convert(xml, new XhtmlParser().parseFragment(rawXhtml));
            } else {
                xml.escapedText(rawXhtml);
                xml.anchor("end-xhtml");
            }
        } else if (isText(element.getProperty())) {
            if (linkResolver != null)
                xml.link(linkResolver.resolveProperty(element.getProperty()));
            xml.text(element.getValue());
        } else {
            setXsiTypeIfIsTypeAttr(xml, element);
            if (element.hasValue()) {
                if (linkResolver != null)
                    xml.link(linkResolver.resolveType(element.getType()));
                xml.attribute("value", element.getValue());
            }
            if (linkResolver != null)
                xml.link(linkResolver.resolveProperty(element.getProperty()));
            if (element.hasChildren()) {
                xml.enter(element.getProperty().getXmlNamespace(), elementName);
                for (Element child : element.getChildren()) composeElement(xml, child, child.getName(), false);
                xml.exit(element.getProperty().getXmlNamespace(), elementName);
            } else
                xml.element(elementName);
        }
    } else {
        setXsiTypeIfIsTypeAttr(xml, element);
        for (Element child : element.getChildren()) {
            if (isAttr(child.getProperty())) {
                if (linkResolver != null)
                    xml.link(linkResolver.resolveType(child.getType()));
                String av = child.getValue();
                if (ToolingExtensions.hasExtension(child.getProperty().getDefinition(), "http://www.healthintersections.com.au/fhir/StructureDefinition/elementdefinition-dateformat"))
                    av = convertForDateFormatToExternal(ToolingExtensions.readStringExtension(child.getProperty().getDefinition(), "http://www.healthintersections.com.au/fhir/StructureDefinition/elementdefinition-dateformat"), av);
                xml.attribute(child.getProperty().getXmlNamespace(), child.getProperty().getXmlName(), av);
            }
        }
        if (linkResolver != null)
            xml.link(linkResolver.resolveProperty(element.getProperty()));
        xml.enter(element.getProperty().getXmlNamespace(), elementName);
        if (!root && element.getSpecial() != null) {
            if (linkResolver != null)
                xml.link(linkResolver.resolveProperty(element.getProperty()));
            xml.enter(element.getProperty().getXmlNamespace(), element.getType());
        }
        for (Element child : element.getChildren()) {
            if (isText(child.getProperty())) {
                if (linkResolver != null)
                    xml.link(linkResolver.resolveProperty(element.getProperty()));
                xml.text(child.getValue());
            } else if (!isAttr(child.getProperty()))
                composeElement(xml, child, child.getName(), false);
        }
        if (!root && element.getSpecial() != null)
            xml.exit(element.getProperty().getXmlNamespace(), element.getType());
        xml.exit(element.getProperty().getXmlNamespace(), elementName);
    }
}
Also used : XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) ElementDecoration(org.hl7.fhir.utilities.ElementDecoration) SpecialElement(org.hl7.fhir.r5.elementmodel.Element.SpecialElement) NamedElement(org.hl7.fhir.r5.elementmodel.ParserBase.NamedElement) ArrayList(java.util.ArrayList) List(java.util.List) CDANarrativeFormat(org.hl7.fhir.utilities.xhtml.CDANarrativeFormat)

Aggregations

ArrayList (java.util.ArrayList)3 List (java.util.List)3 ElementDecoration (org.hl7.fhir.utilities.ElementDecoration)3 CDANarrativeFormat (org.hl7.fhir.utilities.xhtml.CDANarrativeFormat)3 XhtmlParser (org.hl7.fhir.utilities.xhtml.XhtmlParser)2 SpecialElement (org.hl7.fhir.dstu3.elementmodel.Element.SpecialElement)1 SpecialElement (org.hl7.fhir.r4.elementmodel.Element.SpecialElement)1 SpecialElement (org.hl7.fhir.r4b.elementmodel.Element.SpecialElement)1 NamedElement (org.hl7.fhir.r4b.elementmodel.ParserBase.NamedElement)1 SpecialElement (org.hl7.fhir.r5.elementmodel.Element.SpecialElement)1 NamedElement (org.hl7.fhir.r5.elementmodel.ParserBase.NamedElement)1