From fff805e5b73731394f22697f30625b07425618bc Mon Sep 17 00:00:00 2001 From: Lloyd McKenzie Date: Tue, 10 Sep 2024 08:07:01 -0600 Subject: [PATCH] Made changes as recommended by Grahame and Elliot --- .../org/hl7/fhir/r5/elementmodel/Element.java | 14 +++--- .../hl7/fhir/r5/elementmodel/JsonParser.java | 32 ++++++------- .../hl7/fhir/r5/elementmodel/XmlParser.java | 46 +++++++++---------- .../org/hl7/fhir/r5/formats/JsonCreator.java | 3 +- .../fhir/r5/formats/JsonCreatorCanonical.java | 5 +- .../fhir/r5/formats/JsonCreatorDirect.java | 5 +- .../hl7/fhir/r5/formats/JsonCreatorGson.java | 5 +- .../hl7/fhir/utilities/xml/IXMLWriter.java | 5 +- .../org/hl7/fhir/utilities/xml/XMLWriter.java | 7 ++- 9 files changed, 68 insertions(+), 54 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Element.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Element.java index 1aaecc1c9..71643ba9e 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Element.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Element.java @@ -162,7 +162,7 @@ public class Element extends Base implements NamedItem { private FhirFormat format; private Object nativeObject; private List sliceDefinitions; - private boolean ellipsed; + private boolean ellided; public Element(String name) { super(); @@ -1430,8 +1430,8 @@ public class Element extends Base implements NamedItem { public Base copy() { Element element = new Element(this); this.copyValues(element); - if (this.isEllipsed()) - element.setEllipsed(true); + if (this.isEllided()) + element.setEllided(true); return element; } @@ -1641,11 +1641,11 @@ public class Element extends Base implements NamedItem { return FhirPublication.fromCode(property.getStructure().getVersion()); } - public void setEllipsed(boolean ellipsed) { - this.ellipsed = ellipsed; + public void setEllided(boolean ellided) { + this.ellided = ellided; } - public boolean isEllipsed() { - return this.ellipsed; + public boolean isEllided() { + return this.ellided; } } \ No newline at end of file diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java index f8f77e387..20b27c8cd 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java @@ -86,8 +86,8 @@ public class JsonParser extends ParserBase { private JsonCreator json; private boolean allowComments; - private boolean ellipseElements; - private boolean suppressResourceType; + private boolean ellideElements; +// private boolean suppressResourceType; private Element baseElement; private boolean markedXhtml; @@ -785,7 +785,7 @@ public class JsonParser extends ParserBase { } checkComposeComments(e); json.beginObject(); - if (!isSuppressResourceType()) +// if (!isSuppressResourceType()) prop("resourceType", e.getType(), null); Set done = new HashSet(); for (Element child : e.getChildren()) { @@ -811,7 +811,7 @@ public class JsonParser extends ParserBase { checkComposeComments(e); json.beginObject(); - if (!isSuppressResourceType()) +// if (!isSuppressResourceType()) prop("resourceType", e.getType(), linkResolver == null ? null : linkResolver.resolveProperty(e.getProperty())); Set done = new HashSet(); for (Element child : e.getChildren()) { @@ -826,8 +826,8 @@ public class JsonParser extends ParserBase { if (wantCompose(path, child)) { boolean isList = child.hasElementProperty() ? child.getElementProperty().isList() : child.getProperty().isList(); if (!isList) {// for specials, ignore the cardinality of the stated type - if (child.isEllipsed() && ellipseElements) - json.ellipse(); + if (child.isEllided() && isEllideElements() && json.canEllide()) + json.ellide(); else compose(path, child); } else if (!done.contains(child.getName())) { @@ -887,8 +887,8 @@ public class JsonParser extends ParserBase { if (prim) { openArray(name, linkResolver == null ? null : linkResolver.resolveProperty(list.get(0).getProperty())); for (Element item : list) { - if (item.isEllipsed()) - json.ellipse(); + if (item.isEllided() && json.canEllide()) + json.ellide(); else if (item.hasValue()) { if (linkResolver != null && item.getProperty().isReference()) { String ref = linkResolver.resolveReference(getReferenceForElement(item)); @@ -908,8 +908,8 @@ public class JsonParser extends ParserBase { openArray(name, linkResolver == null ? null : linkResolver.resolveProperty(list.get(0).getProperty())); int i = 0; for (Element item : list) { - if (item.isEllipsed()) - json.ellipse(); + if (item.isEllided() && json.canEllide()) + json.ellide(); else if (item.hasChildren()) { open(null,null); if (item.getProperty().isResource()) { @@ -996,15 +996,15 @@ public class JsonParser extends ParserBase { return this; } - public boolean isEllipseElements() { - return ellipseElements; + public boolean isEllideElements() { + return ellideElements; } - public JsonParser setEllipseElements(boolean ellipseElements) { - this.ellipseElements = ellipseElements; + public JsonParser setEllideElements(boolean ellideElements) { + this.ellideElements = ellideElements; return this; } - +/* public boolean isSuppressResourceType() { return suppressResourceType; } @@ -1013,6 +1013,6 @@ public class JsonParser extends ParserBase { this.suppressResourceType = suppressResourceType; return this; } - +*/ } \ No newline at end of file diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java index ce65e2a0c..e2ef427be 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java @@ -94,7 +94,7 @@ import org.xml.sax.XMLReader; public class XmlParser extends ParserBase { private boolean allowXsiLocation; private String version; - private boolean ellipseElements; + private boolean ellideElements; public XmlParser(IWorkerContext context) { super(context); @@ -806,7 +806,7 @@ public class XmlParser extends ParserBase { } private void composeElement(IXMLWriter xml, Element element, String elementName, boolean root) throws IOException, FHIRException { - if (!(isEllipseElements() && element.isEllipsed())) { + if (!(isEllideElements() && element.isEllided())) { if (showDecorations) { @SuppressWarnings("unchecked") List decorations = (List) element.getUserData("fhir.decorations"); @@ -819,8 +819,8 @@ public class XmlParser extends ParserBase { } } if (isText(element.getProperty())) { - if (isEllipseElements() && element.isEllipsed()) - xml.ellipse(); + if (isEllideElements() && element.isEllided() && xml.canEllide()) + xml.ellide(); else { if (linkResolver != null) xml.link(linkResolver.resolveProperty(element.getProperty())); @@ -835,8 +835,8 @@ public class XmlParser extends ParserBase { xml.exit(element.getProperty().getXmlNamespace(),elementName); } } else if (!element.hasChildren() && !element.hasValue()) { - if (isEllipseElements() && element.isEllipsed()) - xml.ellipse(); + if (isEllideElements() && element.isEllided() && xml.canEllide()) + xml.ellide(); else { if (element.getExplicitType() != null) xml.attribute("xsi:type", element.getExplicitType()); @@ -844,8 +844,8 @@ public class XmlParser extends ParserBase { } } else if (element.isPrimitive() || (element.hasType() && isPrimitive(element.getType()))) { if (element.getType().equals("xhtml")) { - if (isEllipseElements() && element.isEllipsed()) - xml.ellipse(); + if (isEllideElements() && element.isEllided() && xml.canEllide()) + xml.ellide(); else { String rawXhtml = element.getValue(); if (isCdaText(element.getProperty())) { @@ -859,16 +859,16 @@ public class XmlParser extends ParserBase { } } } else if (isText(element.getProperty())) { - if (isEllipseElements() && element.isEllipsed()) - xml.ellipse(); + if (isEllideElements() && element.isEllided() && xml.canEllide()) + xml.ellide(); else { if (linkResolver != null) xml.link(linkResolver.resolveProperty(element.getProperty())); xml.text(element.getValue()); } } else { - if (isEllipseElements() && element.isEllipsed()) - xml.attributeEllipse(); + if (isEllideElements() && element.isEllided()) + xml.attributeEllide(); else { setXsiTypeIfIsTypeAttr(xml, element); if (element.hasValue()) { @@ -894,22 +894,22 @@ public class XmlParser extends ParserBase { } } } else { - if (isEllipseElements() && element.isEllipsed()) - xml.ellipse(); + if (isEllideElements() && element.isEllided() && xml.canEllide()) + xml.ellide(); else { setXsiTypeIfIsTypeAttr(xml, element); Set handled = new HashSet<>(); for (Element child : element.getChildren()) { if (!handled.contains(child.getName()) && isAttr(child.getProperty()) && wantCompose(element.getPath(), child)) { handled.add(child.getName()); - if (isEllipseElements() && child.isEllipsed()) - xml.attributeEllipse(); + if (isEllideElements() && child.isEllided()) + xml.attributeEllide(); else { String av = child.getValue(); if (child.getProperty().isList()) { for (Element c2 : element.getChildren()) { if (c2 != child && c2.getName().equals(child.getName())) { - if (c2.isEllipsed()) + if (c2.isEllided()) av = av + " ..."; else av = av + " " + c2.getValue(); @@ -948,8 +948,8 @@ public class XmlParser extends ParserBase { } for (Element child : element.getChildren()) { if (wantCompose(element.getPath(), child)) { - if (isEllipseElements() && child.isEllipsed()) - xml.ellipse(); + if (isEllideElements() && child.isEllided() && xml.canEllide()) + xml.ellide(); else { if (isText(child.getProperty())) { if (linkResolver != null) @@ -1073,12 +1073,12 @@ public class XmlParser extends ParserBase { } } - public boolean isEllipseElements() { - return ellipseElements; + public boolean isEllideElements() { + return ellideElements; } - public void setEllipseElements(boolean ellipseElements) { - this.ellipseElements = ellipseElements; + public void setEllideElements(boolean ellideElements) { + this.ellideElements = ellideElements; } } \ No newline at end of file diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/formats/JsonCreator.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/formats/JsonCreator.java index 58f44d505..c5edc1180 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/formats/JsonCreator.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/formats/JsonCreator.java @@ -71,5 +71,6 @@ public interface JsonCreator { void link(String href); void anchor(String string); void externalLink(String string); - void ellipse(); + void ellide(); + boolean canEllide(); } \ No newline at end of file diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/formats/JsonCreatorCanonical.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/formats/JsonCreatorCanonical.java index badb9a4a0..43b16362b 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/formats/JsonCreatorCanonical.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/formats/JsonCreatorCanonical.java @@ -281,7 +281,10 @@ public class JsonCreatorCanonical implements JsonCreator { } @Override - public void ellipse() { + public boolean canEllide() { return false; } + + @Override + public void ellide() { // not used } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/formats/JsonCreatorDirect.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/formats/JsonCreatorDirect.java index 5132099f3..9148d8636 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/formats/JsonCreatorDirect.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/formats/JsonCreatorDirect.java @@ -245,7 +245,10 @@ public class JsonCreatorDirect implements JsonCreator { } @Override - public void ellipse() { + public boolean canEllide() { return false; } + + @Override + public void ellide() { // not used } } \ No newline at end of file diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/formats/JsonCreatorGson.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/formats/JsonCreatorGson.java index ded1fcac7..7d7a701ae 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/formats/JsonCreatorGson.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/formats/JsonCreatorGson.java @@ -128,8 +128,11 @@ public class JsonCreatorGson implements JsonCreator { } @Override - public void ellipse() { + public void ellide() { // not used } + @Override + public boolean canEllide() { return false;} + } \ No newline at end of file diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/IXMLWriter.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/IXMLWriter.java index 0a2a61ec3..cb0276f9d 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/IXMLWriter.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/IXMLWriter.java @@ -106,6 +106,7 @@ public interface IXMLWriter { public abstract void externalLink(String ref) throws IOException; // this is only implemented by an implementation that is producing an xhtml representation and handles ellipsing elements - public abstract void ellipse() throws IOException; - public abstract void attributeEllipse(); + public abstract boolean canEllide(); + public abstract void ellide() throws IOException; + public abstract void attributeEllide(); } \ No newline at end of file diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/XMLWriter.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/XMLWriter.java index 777083e99..aa70a26dd 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/XMLWriter.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/XMLWriter.java @@ -913,12 +913,15 @@ public class XMLWriter extends OutputStreamWriter implements IXMLWriter { } @Override - public void attributeEllipse() { + public boolean canEllide() { return false; } + + @Override + public void attributeEllide() { // ignore this } @Override - public void ellipse() throws IOException { + public void ellide() throws IOException { // ignore this }