Search in sources :

Example 1 with XMLWriter

use of org.hl7.fhir.utilities.xml.XMLWriter in project kindling by HL7.

the class SvgGenerator method drawClass.

private ClassItem drawClass(XMLWriter xml, ElementDefn e, boolean isRoot, ResourceDefn resource, boolean link, String path, DefinedCode primitive, StandardsStatus status) throws Exception {
    ClassItem item = classes.get(e);
    String tn = e.getName();
    if (!definitions.hasPrimitiveType(tn) && !tn.equals("xhtml")) {
        tn = Utilities.capitalize(tn);
    }
    ResourceDefn r = definitions.hasResource(tn) ? definitions.getResourceByName(tn) : null;
    if (r == null) {
        r = definitions.getBaseResources().get(tn);
    }
    xml.attribute("id", "n" + (++nc));
    xml.enter("g");
    xml.attribute("x", Double.toString(item.left));
    xml.attribute("y", Double.toString(item.top));
    xml.attribute("rx", "4");
    xml.attribute("ry", "4");
    xml.attribute("width", Double.toString(item.width));
    xml.attribute("height", Double.toString(item.height));
    xml.attribute("filter", "url(#shadow" + id + ")");
    if (r != null) {
        xml.attribute("style", "fill:" + r.getStatus().getColorSvg() + ";stroke:black;stroke-width:1");
        status = r.getStatus();
    } else if (e == null || e.getStandardsStatus() == null)
        xml.attribute("style", "fill:" + (status == null ? "#ffffff" : status.getColorSvg()) + ";stroke:black;stroke-width:1");
    else {
        xml.attribute("style", "fill:" + e.getStandardsStatus().getColorSvg() + ";stroke:black;stroke-width:1");
        status = e.getStandardsStatus();
    }
    if (!makeTargets)
        xml.attribute("id", "n" + (++nc));
    else
        xml.attribute("id", item.getId());
    xml.element("rect", null);
    xml.attribute("x1", Double.toString(item.left));
    xml.attribute("y1", Double.toString(item.top + HEADER_HEIGHT + GAP_HEIGHT * 2));
    xml.attribute("x2", Double.toString(item.left + item.width));
    xml.attribute("y2", Double.toString(item.top + HEADER_HEIGHT + GAP_HEIGHT * 2));
    xml.attribute("style", "stroke:dimgrey;stroke-width:1");
    xml.attribute("id", "n" + (++nc));
    xml.element("line", null);
    xml.attribute("x", Double.toString(item.left + item.width / 2));
    xml.attribute("y", Double.toString(item.top + HEADER_HEIGHT));
    xml.attribute("fill", "black");
    if (isRoot)
        xml.attribute("class", "diagram-class-title  diagram-class-resource");
    else
        xml.attribute("class", "diagram-class-title");
    if (link) {
        xml.attribute("id", "n" + (++nc));
        if (e.isAbstractType()) {
            xml.attribute("style", "font-style: italic");
        }
        xml.enter("text");
        xml.attribute("xlink:href", makeRel(definitions.getSrcFile(tn) + ".html#" + tn));
        xml.attribute("id", "n" + (++nc));
        xml.enter("a");
        xml.text(tn);
        xml.exit("a");
        if (definitions.getBaseResources().containsKey(e.getName()) && definitions.getBaseResources().get(e.getName()).isInterface()) {
            xml.text(" ");
            xml.attribute("xlink:href", makeRel("uml.html#interface"));
            xml.enter("a");
            xml.text("«Interface»");
            xml.exit("a");
        }
        xml.exit("text");
    } else if (isRoot) {
        xml.attribute("id", "n" + (++nc));
        if (e.isAbstractType()) {
            xml.attribute("style", "font-style: italic");
        }
        xml.enter("text");
        xml.text(tn);
        if (Utilities.noString(e.typeCode())) {
            xml.text(" \u00ABResource\u00BB");
        } else {
            xml.attribute("class", "diagram-class-title-link");
            xml.enter("tspan");
            xml.text(" (");
            if ("Logical".equals(e.typeCode()))
                xml.attribute("xlink:href", prefix + definitions.getBaseLink());
            else
                xml.attribute("xlink:href", prefix + definitions.getSrcFile(e.typeCode()) + ".html#" + e.typeCode());
            xml.attribute("class", "diagram-class-reference");
            xml.attribute("id", "n" + (++nc));
            xml.attribute("style", "font-style: italic");
            if ("Logical".equals(e.typeCode())) {
                xml.element("a", "Base");
            } else {
                xml.element("a", e.typeCode());
            }
            xml.text(")");
            xml.exit("tspan");
        }
        if ("Logical".equals(e.typeCode())) {
            xml.text(" ");
            xml.attribute("xlink:href", makeRel("uml.html#pattern"));
            xml.enter("a");
            xml.text("«Pattern»");
            xml.exit("a");
        }
        if (definitions.getBaseResources().containsKey(e.getName()) && definitions.getBaseResources().get(e.getName()).isInterface()) {
            xml.text(" ");
            xml.attribute("xlink:href", makeRel("uml.html#interface"));
            xml.enter("a");
            xml.text("«Interface»");
            xml.exit("a");
        }
        xml.exit("text");
    } else if (e.hasStatedType()) {
        xml.attribute("id", "n" + (++nc));
        xml.element("text", e.getStatedType());
    } else {
        xml.attribute("id", "n" + (++nc));
        xml.element("text", tn);
    }
    if (attributes) {
        if (primitive != null) {
            if (primitive instanceof PrimitiveType)
                addValueAttribute(xml, item.left, item.top + HEADER_HEIGHT + GAP_HEIGHT * 2 + LINE_HEIGHT, getXsi(primitive).split("\\|"));
        } else {
            int i = 0;
            for (ElementDefn c : e.getElements()) {
                if (isAttribute(c)) {
                    i++;
                    addAttribute(xml, item.left, item.top + HEADER_HEIGHT + GAP_HEIGHT * 2 + LINE_HEIGHT * i, c, path, LINE_HEIGHT, item.width);
                    String[] texts = textForAttribute(c);
                    i = i + texts.length - 1;
                }
            }
        }
    }
    xml.exit("g");
    if (attributes) {
        for (ElementDefn c : e.getElements()) {
            if (!isAttribute(c)) {
                if (Utilities.noString(c.typeCode()) || !c.typeCode().startsWith("@")) {
                    links.add(new Link(item, drawClass(xml, c, false, resource, false, path + "." + c.getName(), null, status), LinkType.COMPOSITION, c.getName(), c.describeCardinality(), PointKind.unknown, baseUrl(path) + path + "." + c.getName(), c.getEnhancedDefinition()));
                } else {
                    ClassItem target = getItemForPath(resource, c.typeCode().substring(1));
                    links.add(new Link(item, target, LinkType.COMPOSITION, c.getName(), c.describeCardinality(), PointKind.unknown, baseUrl(path) + path + "." + c.getName(), c.getEnhancedDefinition()));
                }
            }
        }
    }
    return item;
}
Also used : ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) PrimitiveType(org.hl7.fhir.definitions.model.PrimitiveType) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn)

Example 2 with XMLWriter

use of org.hl7.fhir.utilities.xml.XMLWriter in project kindling by HL7.

the class SvgGenerator method drawElement.

private ClassItem drawElement(XMLWriter xml, String[] classNames) throws Exception {
    // classNames.length == 1 && classNames[0].equals("Base");
    boolean onlyElement = false;
    if (classNames != null) {
        for (String cn : classNames) {
            if (definitions.getPrimitives().containsKey(cn)) {
                DefinedCode cd = definitions.getPrimitives().get(cn);
                ElementDefn fake = fakes.get(cn);
                if (cd instanceof DefinedStringPattern) {
                    links.add(new Link(classes.get(fakes.get(((DefinedStringPattern) cd).getBase())), drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE), LinkType.SPECIALIZATION, null, null, PointKind.unknown, null, null));
                } else {
                    ClassItem parent = classes.get(definitions.getElementDefn(version.isR4B() ? "Element" : "PrimitiveType"));
                    if (parent == null) {
                        drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE);
                    } else {
                        links.add(new Link(parent, drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE), LinkType.SPECIALIZATION, null, null, PointKind.unknown, null, null));
                    }
                }
            } else if ("xhtml".equals(cn)) {
                DefinedCode cd = new DefinedCode("xhtml", "XHTML for resource narrative", null);
                ElementDefn fake = fakes.get(cn);
                ClassItem parent = classes.get(definitions.getElementDefn(version.isR4B() ? "Element" : "DataType"));
                if (parent == null) {
                    drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE);
                } else {
                    links.add(new Link(parent, drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE), LinkType.SPECIALIZATION, null, null, PointKind.unknown, null, null));
                }
            } else if (definitions.getConstraints().containsKey(cn)) {
                ProfiledType cd = definitions.getConstraints().get(cn);
                ElementDefn fake = fakes.get(cn);
                ClassItem parent = classes.get(definitions.getElementDefn(cd.getBaseType()));
                links.add(new Link(parent, drawClass(xml, fake, false, null, true, null, null, StandardsStatus.NORMATIVE), LinkType.CONSTRAINT, null, null, PointKind.unknown, null, null));
            } else if (definitions.getPrimitives().containsKey(cn)) {
                DefinedCode cd = new DefinedCode("xhtml", "XHTML for resource narrative", null);
                ElementDefn fake = fakes.get(cn);
                // links.add(new Link(item,
                // , LinkType.SPECIALIZATION, null, null, PointKind.unknown, null, null));
                drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE);
            } else if (!onlyElement) {
                ElementDefn e = definitions.getElementDefn(cn);
                ClassItem parent = Utilities.noString(e.typeCode()) ? null : classes.get(definitions.getElementDefn(e.typeCode()));
                if (parent == null) {
                    drawClass(xml, e, false, null, true, cn, null, e.getStandardsStatus());
                } else {
                    links.add(new Link(parent, drawClass(xml, e, false, null, true, cn, null, e.getStandardsStatus()), LinkType.SPECIALIZATION, null, null, PointKind.unknown, null, null));
                }
            }
        }
    }
    return null;
}
Also used : DefinedStringPattern(org.hl7.fhir.definitions.model.DefinedStringPattern) ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 3 with XMLWriter

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

the class XmlParserBase method compose.

/**
 * Compose a resource to a stream, possibly using pretty presentation for a human reader, and maybe a different choice in the xhtml narrative (used in the spec in one place, but should not be used in production)
 * @
 */
public void compose(OutputStream stream, Resource resource, boolean htmlPretty) throws IOException {
    XMLWriter writer = new XMLWriter(stream, "UTF-8");
    writer.setPretty(style == OutputStyle.PRETTY);
    writer.start();
    compose(writer, resource, htmlPretty);
    writer.end();
}
Also used : IXMLWriter(org.hl7.fhir.utilities.xml.IXMLWriter) XMLWriter(org.hl7.fhir.utilities.xml.XMLWriter)

Example 4 with XMLWriter

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

the class XmlParserBase method compose.

/**
 * Compose a type to a stream (used in the spec, for example, but not normally in production)
 * @
 */
public void compose(OutputStream stream, String rootName, Type type) throws IOException {
    xml = new XMLWriter(stream, "UTF-8");
    xml.setPretty(style == OutputStyle.PRETTY);
    xml.start();
    xml.setDefaultNamespace(FHIR_NS);
    composeType(Utilities.noString(rootName) ? "value" : rootName, type);
    xml.end();
}
Also used : IXMLWriter(org.hl7.fhir.utilities.xml.IXMLWriter) XMLWriter(org.hl7.fhir.utilities.xml.XMLWriter)

Example 5 with XMLWriter

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

the class XmlParserBase method compose.

/**
 * Compose a resource to a stream, possibly using pretty presentation for a human reader (used in the spec, for example, but not normally in production)
 * @
 */
@Override
public void compose(OutputStream stream, Resource resource) throws IOException {
    XMLWriter writer = new XMLWriter(stream, "UTF-8");
    writer.setPretty(style == OutputStyle.PRETTY);
    writer.start();
    compose(writer, resource, writer.isPretty());
    writer.end();
}
Also used : IXMLWriter(org.hl7.fhir.utilities.xml.IXMLWriter) XMLWriter(org.hl7.fhir.utilities.xml.XMLWriter)

Aggregations

XMLWriter (org.hl7.fhir.utilities.xml.XMLWriter)28 IXMLWriter (org.hl7.fhir.utilities.xml.IXMLWriter)22 FileOutputStream (java.io.FileOutputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ArrayList (java.util.ArrayList)2 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)2 BindingSpecification (org.hl7.fhir.definitions.model.BindingSpecification)1 DefinedCode (org.hl7.fhir.definitions.model.DefinedCode)1 DefinedStringPattern (org.hl7.fhir.definitions.model.DefinedStringPattern)1 PrimitiveType (org.hl7.fhir.definitions.model.PrimitiveType)1 ProfiledType (org.hl7.fhir.definitions.model.ProfiledType)1 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)1 TypeRef (org.hl7.fhir.definitions.model.TypeRef)1 SpecialElement (org.hl7.fhir.dstu2016may.metamodel.Element.SpecialElement)1 IniFile (org.hl7.fhir.utilities.IniFile)1