Search in sources :

Example 96 with DOCUMENT

use of org.hl7.fhir.r4.model.Bundle.BundleType.DOCUMENT in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeLibrary.

protected void composeLibrary(Complex parent, String parentType, String name, Library element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeDomainResource(t, "Library", name, element, index);
    if (element.hasModuleMetadata())
        composeModuleMetadata(t, "Library", "moduleMetadata", element.getModuleMetadata(), -1);
    for (int i = 0; i < element.getModel().size(); i++) composeLibraryLibraryModelComponent(t, "Library", "model", element.getModel().get(i), i);
    for (int i = 0; i < element.getLibrary().size(); i++) composeLibraryLibraryLibraryComponent(t, "Library", "library", element.getLibrary().get(i), i);
    for (int i = 0; i < element.getCodeSystem().size(); i++) composeLibraryLibraryCodeSystemComponent(t, "Library", "codeSystem", element.getCodeSystem().get(i), i);
    for (int i = 0; i < element.getValueSet().size(); i++) composeLibraryLibraryValueSetComponent(t, "Library", "valueSet", element.getValueSet().get(i), i);
    for (int i = 0; i < element.getParameter().size(); i++) composeParameterDefinition(t, "Library", "parameter", element.getParameter().get(i), i);
    for (int i = 0; i < element.getDataRequirement().size(); i++) composeDataRequirement(t, "Library", "dataRequirement", element.getDataRequirement().get(i), i);
    if (element.hasDocument())
        composeAttachment(t, "Library", "document", element.getDocument(), -1);
}
Also used : Complex(org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)

Example 97 with DOCUMENT

use of org.hl7.fhir.r4.model.Bundle.BundleType.DOCUMENT in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeModuleDefinitionModuleDefinitionLibraryComponent.

protected void composeModuleDefinitionModuleDefinitionLibraryComponent(Complex parent, String parentType, String name, ModuleDefinition.ModuleDefinitionLibraryComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "library", name, element, index);
    if (element.hasNameElement())
        composeString(t, "ModuleDefinition", "name", element.getNameElement(), -1);
    if (element.hasIdentifierElement())
        composeString(t, "ModuleDefinition", "identifier", element.getIdentifierElement(), -1);
    if (element.hasVersionElement())
        composeString(t, "ModuleDefinition", "version", element.getVersionElement(), -1);
    if (element.hasDocument())
        composeType(t, "ModuleDefinition", "document", element.getDocument(), -1);
}
Also used : Complex(org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)

Example 98 with DOCUMENT

use of org.hl7.fhir.r4.model.Bundle.BundleType.DOCUMENT in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeRelatedArtifact.

protected void composeRelatedArtifact(Complex parent, String parentType, String name, RelatedArtifact element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeElement(t, "RelatedArtifact", name, element, index);
    if (element.hasTypeElement())
        composeEnum(t, "RelatedArtifact", "type", element.getTypeElement(), -1);
    if (element.hasDisplayElement())
        composeString(t, "RelatedArtifact", "display", element.getDisplayElement(), -1);
    if (element.hasCitationElement())
        composeString(t, "RelatedArtifact", "citation", element.getCitationElement(), -1);
    if (element.hasUrlElement())
        composeUri(t, "RelatedArtifact", "url", element.getUrlElement(), -1);
    if (element.hasDocument())
        composeAttachment(t, "RelatedArtifact", "document", element.getDocument(), -1);
    if (element.hasResource())
        composeReference(t, "RelatedArtifact", "resource", element.getResource(), -1);
}
Also used : Complex(org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)

Example 99 with DOCUMENT

use of org.hl7.fhir.r4.model.Bundle.BundleType.DOCUMENT in project org.hl7.fhir.core by hapifhir.

the class XmlParser method parse.

public Element parse(InputStream stream) throws FHIRFormatError, DefinitionException, FHIRException, IOException {
    Document doc = null;
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        // xxe protection
        factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
        factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
        factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
        factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
        factory.setXIncludeAware(false);
        factory.setExpandEntityReferences(false);
        factory.setNamespaceAware(true);
        if (policy == ValidationPolicy.EVERYTHING) {
            // use a slower parser that keeps location data
            TransformerFactory transformerFactory = TransformerFactory.newInstance();
            Transformer nullTransformer = transformerFactory.newTransformer();
            DocumentBuilder docBuilder = factory.newDocumentBuilder();
            doc = docBuilder.newDocument();
            DOMResult domResult = new DOMResult(doc);
            SAXParserFactory spf = SAXParserFactory.newInstance();
            spf.setNamespaceAware(true);
            spf.setValidating(false);
            // xxe protection
            spf.setFeature("http://xml.org/sax/features/external-general-entities", false);
            spf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
            SAXParser saxParser = spf.newSAXParser();
            XMLReader xmlReader = saxParser.getXMLReader();
            // xxe protection
            xmlReader.setFeature("http://xml.org/sax/features/external-general-entities", false);
            xmlReader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
            XmlLocationAnnotator locationAnnotator = new XmlLocationAnnotator(xmlReader, doc);
            InputSource inputSource = new InputSource(stream);
            SAXSource saxSource = new SAXSource(locationAnnotator, inputSource);
            nullTransformer.transform(saxSource, domResult);
        } else {
            DocumentBuilder builder = factory.newDocumentBuilder();
            doc = builder.parse(stream);
        }
    } catch (Exception e) {
        logError(0, 0, "(syntax)", IssueType.INVALID, e.getMessage(), IssueSeverity.FATAL);
        doc = null;
    }
    if (doc == null)
        return null;
    else
        return parse(doc);
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) DOMResult(javax.xml.transform.dom.DOMResult) Document(org.w3c.dom.Document) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) SAXSource(javax.xml.transform.sax.SAXSource) DocumentBuilder(javax.xml.parsers.DocumentBuilder) XmlLocationAnnotator(org.hl7.fhir.r4.utils.formats.XmlLocationAnnotator) SAXParser(javax.xml.parsers.SAXParser) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 100 with DOCUMENT

use of org.hl7.fhir.r4.model.Bundle.BundleType.DOCUMENT in project org.hl7.fhir.core by hapifhir.

the class JsonParser method parse.

@Override
public Element parse(InputStream stream) throws IOException, FHIRException {
    // if we're parsing at this point, then we're going to use the custom parser
    map = new IdentityHashMap<JsonElement, LocationData>();
    String source = TextFile.streamToString(stream);
    if (policy == ValidationPolicy.EVERYTHING) {
        JsonObject obj = null;
        try {
            obj = JsonTrackingParser.parse(source, map);
        } catch (Exception e) {
            logError(-1, -1, "(document)", IssueType.INVALID, "Error parsing JSON: " + e.getMessage(), IssueSeverity.FATAL);
            return null;
        }
        assert (map.containsKey(obj));
        return parse(obj);
    } else {
        // (JsonObject) new com.google.gson.JsonParser().parse(source);
        JsonObject obj = JsonTrackingParser.parse(source, null);
        // assert (map.containsKey(obj));
        return parse(obj);
    }
}
Also used : LocationData(org.hl7.fhir.utilities.json.JsonTrackingParser.LocationData) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Aggregations

Document (org.w3c.dom.Document)48 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)37 DocumentBuilder (javax.xml.parsers.DocumentBuilder)36 IOException (java.io.IOException)33 FHIRException (org.hl7.fhir.exceptions.FHIRException)33 ArrayList (java.util.ArrayList)28 Element (org.w3c.dom.Element)20 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)16 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)15 HashMap (java.util.HashMap)14 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)13 FileNotFoundException (java.io.FileNotFoundException)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 List (java.util.List)11 CSFile (org.hl7.fhir.utilities.CSFile)11 File (java.io.File)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 XmlGenerator (org.hl7.fhir.utilities.xml.XmlGenerator)9 Identifier (org.hl7.fhir.r4.model.Identifier)8 TextFile (org.hl7.fhir.utilities.TextFile)8