use of org.hl7.fhir.utilities.xml.XMLWriter in project kindling by HL7.
the class SvgGenerator method generate.
public String generate(String filename, String id) throws Exception {
this.id = id;
ini = new IniFile(filename);
String[] classNames = ini.getStringProperty("diagram", "classes") == null ? null : ini.getStringProperty("diagram", "classes").split("\\,");
if ("false".equals(ini.getStringProperty("diagram", "attributes")))
attributes = false;
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
XMLWriter xml = new XMLWriter(bytes, "UTF-8");
minx = 0;
miny = 0;
Point size = determineMetrics(classNames);
adjustAllForMin(size);
xml.setPretty(false);
xml.start();
xml.setDefaultNamespace(NS_SVG);
xml.namespace(NS_XLINK, "xlink");
xml.attribute("id", "n" + (++nc));
xml.attribute("version", "1.1");
xml.attribute("width", Utilities.noString(ini.getStringProperty("size", "width")) ? Double.toString(size.x) : ini.getStringProperty("size", "width"));
xml.attribute("height", Utilities.noString(ini.getStringProperty("size", "height")) ? Double.toString(size.y) : ini.getStringProperty("size", "height"));
xml.enter("svg");
shadowFilter(xml);
drawElement(xml, classNames);
countDuplicateLinks();
for (Link l : links) {
drawLink(xml, l);
}
xml.exit("svg");
xml.end();
String s = new String(bytes.toByteArray());
return s.substring(s.indexOf(">") + 1);
}
use of org.hl7.fhir.utilities.xml.XMLWriter in project kindling by HL7.
the class SvgGenerator method addAttribute.
private void addAttribute(XMLWriter xml, double left, double top, ElementDefn e, String path, LineStatus ls, double height, double width) throws Exception {
if (e.getStandardsStatus() != null) {
xml.attribute("x", Double.toString(left + 1));
xml.attribute("y", Double.toString(top - height + GAP_HEIGHT));
xml.attribute("id", "n" + (++nc));
xml.attribute("width", Double.toString(width - 2));
xml.attribute("height", Double.toString(height));
xml.attribute("style", "fill:" + e.getStandardsStatus().getColorSvg() + ";stroke:black;stroke-width:0");
xml.element("rect", null);
}
xml.attribute("x", Double.toString(left + LEFT_MARGIN + (ls.line == 0 ? 0 : WRAP_INDENT)));
xml.attribute("y", Double.toString(top + LINE_HEIGHT * ls.line));
xml.attribute("fill", "black");
xml.attribute("class", "diagram-class-detail");
xml.attribute("id", "n" + (++nc));
xml.enter("text");
xml.attribute("xlink:href", baseUrl(path) + path + "." + e.getName().replace("[", "_").replace("]", "_"));
xml.attribute("id", "n" + (++nc));
xml.enter("a");
xml.element("title", e.getEnhancedDefinition());
xml.text(ls.see(e.getName()));
xml.exit("a");
xml.text(ls.see(" : "));
encodeType(xml, ls, getTypeCodeForElement(e.getTypes()));
xml.text(ls.see(" [" + e.describeCardinality() + "]"));
// now, the stereotypes
boolean hasTS = !((e.getTypes().isEmpty()) || (e.getTypes().size() == 1 && !isReference(e.getTypes().get(0).getName())));
boolean hasBinding = (e.hasBinding() && e.getBinding().getBinding() != BindingMethod.Unbound);
if (hasTS || hasBinding) {
xml.text(ls.see(" \u00AB "));
if (hasTS) {
if (isReference(e.getTypes().get(0).getName()) && e.getTypes().size() == 1) {
boolean first = true;
for (String p : e.getTypes().get(0).getParams()) {
if (first)
first = false;
else
xml.text(ls.see("|"));
ls.check(xml, left, top, p.length(), null);
encodeType(xml, ls, p);
}
} else {
boolean firstOuter = true;
for (TypeRef t : e.getTypes()) {
if (firstOuter)
firstOuter = false;
else
xml.text(ls.see("|"));
ls.check(xml, left, top, t.getName().length(), null);
encodeType(xml, ls, t.getName());
if (t.getParams().size() > 0) {
xml.text(ls.see("("));
boolean first = true;
for (String p : t.getParams()) {
if (first)
first = false;
else
xml.text(ls.see("|"));
ls.check(xml, left, top, p.length(), null);
encodeType(xml, ls, p);
}
xml.text(ls.see(")"));
}
}
}
}
if (hasTS && hasBinding) {
xml.text(ls.see("; "));
}
if (hasBinding) {
BindingSpecification b = e.getBinding();
String name = e.getBinding().getValueSet() != null ? e.getBinding().getValueSet().getName() : e.getBinding().getName();
if (name.toLowerCase().endsWith(" codes"))
name = name.substring(0, name.length() - 5);
if (name.length() > 30)
name = name.substring(0, 29) + "...";
String link = getBindingLink(prefix, e);
if (b.getStrength() == BindingStrength.EXAMPLE) {
if (link != null) {
xml.attribute("xlink:href", link);
xml.attribute("id", "n" + (++nc));
xml.enter("a");
xml.attribute("id", "n" + (++nc));
}
xml.element("title", b.getDefinition() + " (Strength=Example)");
for (String p : parts(name)) {
ls.check(xml, left, top, p.length(), link);
xml.text(ls.see(p));
}
if (link != null) {
xml.exit("a");
}
xml.text("??");
} else if (b.getStrength() == BindingStrength.PREFERRED) {
xml.attribute("xlink:href", link);
xml.attribute("id", "n" + (++nc));
xml.enter("a");
xml.element("title", b.getDefinition() + " (Strength=Preferred)");
for (String p : parts(name)) {
ls.check(xml, left, top, p.length(), link);
xml.text(ls.see(p));
}
xml.exit("a");
xml.text("?");
} else if (b.getStrength() == BindingStrength.EXTENSIBLE) {
// if (b.hasMax())
// what do in this case...
xml.attribute("xlink:href", link);
xml.attribute("id", "n" + (++nc));
xml.enter("a");
xml.attribute("id", "n" + (++nc));
xml.element("title", b.getDefinition() + " (Strength=Extensible)");
for (String p : parts(name)) {
ls.check(xml, left, top, p.length(), link);
xml.text(ls.see(p));
}
xml.exit("a");
xml.text("+");
} else if (b.getStrength() == BindingStrength.REQUIRED) {
xml.attribute("xlink:href", link);
xml.attribute("id", "n" + (++nc));
xml.enter("a");
xml.attribute("id", "n" + (++nc));
xml.element("title", b.getDefinition() + " (Strength=Required)");
// xml.open("b");
for (String p : parts(name)) {
ls.check(xml, left, top, p.length(), link);
xml.text(ls.see(p));
}
// xml.close("b");
xml.exit("a");
xml.text("!");
} else {
xml.attribute("id", "n" + (++nc));
xml.attribute("xlink:href", link);
xml.enter("a");
xml.attribute("id", "n" + (++nc));
xml.element("title", b.getDefinition() + " (??)");
for (String p : parts(name)) {
ls.check(xml, left, top, p.length(), link);
xml.text(ls.see(p));
}
xml.exit("a");
}
}
xml.text(ls.see(" \u00BB"));
}
xml.exit("text");
}
use of org.hl7.fhir.utilities.xml.XMLWriter in project org.hl7.fhir.core by hapifhir.
the class XmlParser method composeElement.
private void composeElement(XMLWriter xml, Element element, String elementName) throws IOException {
for (String s : element.getComments()) {
xml.comment(s, true);
}
if (isText(element.getProperty())) {
xml.enter(elementName);
xml.text(element.getValue());
xml.exit(elementName);
} else if (element.isPrimitive() || (element.hasType() && ParserBase.isPrimitive(element.getType()))) {
if (element.getType().equals("xhtml")) {
xml.escapedText(element.getValue());
} else if (isText(element.getProperty())) {
xml.text(element.getValue());
} else {
if (element.hasValue())
xml.attribute("value", element.getValue());
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()))
xml.attribute(child.getName(), child.getValue());
}
xml.enter(elementName);
if (element.getSpecial() != null)
xml.enter(element.getType());
for (Element child : element.getChildren()) {
if (isText(child.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);
}
}
use of org.hl7.fhir.utilities.xml.XMLWriter in project org.hl7.fhir.core by hapifhir.
the class XmlParser method compose.
@Override
public void compose(Element e, OutputStream stream, OutputStyle style, String base) throws Exception {
XMLWriter xml = new XMLWriter(stream, "UTF-8");
xml.setPretty(style == OutputStyle.PRETTY);
xml.start();
xml.setDefaultNamespace(e.getProperty().getNamespace());
composeElement(xml, e, e.getType());
xml.end();
}
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();
}
Aggregations