added i18N handling to JsonParser, TurtleParser, XMLParser
This commit is contained in:
parent
9443b1c1c3
commit
14a0f7d687
|
@ -9,9 +9,9 @@ package org.hl7.fhir.r5.elementmodel;
|
|||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -91,20 +91,20 @@ public class JsonParser extends ParserBase {
|
|||
map = new IdentityHashMap<JsonElement, LocationData>();
|
||||
String source = TextFile.streamToString(stream);
|
||||
if (policy == ValidationPolicy.EVERYTHING) {
|
||||
JsonObject obj = null;
|
||||
JsonObject obj = null;
|
||||
try {
|
||||
obj = JsonTrackingParser.parse(source, map);
|
||||
} catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
logError(-1, -1, "(document)", IssueType.INVALID, context.formatMessage(I18nConstants.ERROR_PARSING_JSON_, e.getMessage()), IssueSeverity.FATAL);
|
||||
return null;
|
||||
}
|
||||
assert (map.containsKey(obj));
|
||||
return parse(obj);
|
||||
return parse(obj);
|
||||
} else {
|
||||
JsonObject obj = JsonTrackingParser.parse(source, null); // (JsonObject) new com.google.gson.JsonParser().parse(source);
|
||||
// assert (map.containsKey(obj));
|
||||
return parse(obj);
|
||||
}
|
||||
return parse(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public Element parse(JsonObject object, Map<JsonElement, LocationData> map) throws FHIRException {
|
||||
|
@ -233,10 +233,10 @@ public class JsonParser extends ParserBase {
|
|||
parseResource(npath, child, n, property);
|
||||
else
|
||||
parseChildren(npath, child, n, false);
|
||||
} else
|
||||
} else
|
||||
logError(line(e), col(e), npath, IssueType.INVALID, context.formatMessage(I18nConstants.THIS_PROPERTY_MUST_BE__NOT_, (property.isList() ? "an Array" : "an Object"), describe(e)), IssueSeverity.ERROR);
|
||||
}
|
||||
|
||||
|
||||
private String describe(JsonElement e) {
|
||||
if (e instanceof JsonArray) {
|
||||
return "an array";
|
||||
|
@ -251,7 +251,7 @@ public class JsonParser extends ParserBase {
|
|||
String npath = path+"."+property.getName();
|
||||
processed.add(name);
|
||||
processed.add("_"+name);
|
||||
JsonElement main = object.has(name) ? object.get(name) : null;
|
||||
JsonElement main = object.has(name) ? object.get(name) : null;
|
||||
JsonElement fork = object.has("_"+name) ? object.get("_"+name) : null;
|
||||
if (main != null || fork != null) {
|
||||
if (property.isList() && ((main == null) || (main instanceof JsonArray)) &&((fork == null) || (fork instanceof JsonArray)) ) {
|
||||
|
@ -329,7 +329,7 @@ public class JsonParser extends ParserBase {
|
|||
String name = rt.getAsString();
|
||||
StructureDefinition sd = context.fetchResource(StructureDefinition.class, ProfileUtilities.sdNs(name, context.getOverrideVersionNs()));
|
||||
if (sd == null)
|
||||
throw new FHIRFormatError("Contained resource does not appear to be a FHIR resource (unknown name '"+name+"')");
|
||||
throw new FHIRFormatError(context.formatMessage(I18nConstants.CONTAINED_RESOURCE_DOES_NOT_APPEAR_TO_BE_A_FHIR_RESOURCE_UNKNOWN_NAME_, name));
|
||||
parent.updateProperty(new Property(context, sd.getSnapshot().getElement().get(0), sd), SpecialElement.fromProperty(parent.getProperty()), elementProperty);
|
||||
parent.setType(name);
|
||||
parseChildren(npath, res, parent, true);
|
||||
|
@ -369,7 +369,7 @@ public class JsonParser extends ParserBase {
|
|||
|
||||
protected void open(String name, String link) throws IOException {
|
||||
json.link(link);
|
||||
if (name != null)
|
||||
if (name != null)
|
||||
json.name(name);
|
||||
json.beginObject();
|
||||
}
|
||||
|
@ -380,7 +380,7 @@ public class JsonParser extends ParserBase {
|
|||
|
||||
protected void openArray(String name, String link) throws IOException {
|
||||
json.link(link);
|
||||
if (name != null)
|
||||
if (name != null)
|
||||
json.name(name);
|
||||
json.beginArray();
|
||||
}
|
||||
|
@ -412,7 +412,7 @@ public class JsonParser extends ParserBase {
|
|||
public void compose(Element e, JsonCreator json) throws Exception {
|
||||
this.json = json;
|
||||
json.beginObject();
|
||||
|
||||
|
||||
prop("resourceType", e.getType(), linkResolver == null ? null : linkResolver.resolveProperty(e.getProperty()));
|
||||
Set<String> done = new HashSet<String>();
|
||||
for (Element child : e.getChildren()) {
|
||||
|
@ -440,7 +440,7 @@ public class JsonParser extends ParserBase {
|
|||
if (list.get(0).isPrimitive()) {
|
||||
boolean prim = false;
|
||||
complex = false;
|
||||
for (Element item : list) {
|
||||
for (Element item : list) {
|
||||
if (item.hasValue())
|
||||
prim = true;
|
||||
if (item.hasChildren())
|
||||
|
@ -448,19 +448,19 @@ public class JsonParser extends ParserBase {
|
|||
}
|
||||
if (prim) {
|
||||
openArray(name, linkResolver == null ? null : linkResolver.resolveProperty(list.get(0).getProperty()));
|
||||
for (Element item : list) {
|
||||
for (Element item : list) {
|
||||
if (item.hasValue())
|
||||
primitiveValue(null, item);
|
||||
else
|
||||
json.nullValue();
|
||||
}
|
||||
}
|
||||
closeArray();
|
||||
}
|
||||
name = "_"+name;
|
||||
}
|
||||
if (complex) {
|
||||
openArray(name, linkResolver == null ? null : linkResolver.resolveProperty(list.get(0).getProperty()));
|
||||
for (Element item : list) {
|
||||
for (Element item : list) {
|
||||
if (item.hasChildren()) {
|
||||
open(null,null);
|
||||
if (item.getProperty().isResource()) {
|
||||
|
@ -473,9 +473,9 @@ public class JsonParser extends ParserBase {
|
|||
close();
|
||||
} else
|
||||
json.nullValue();
|
||||
}
|
||||
}
|
||||
closeArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void primitiveValue(String name, Element item) throws IOException {
|
||||
|
@ -493,10 +493,10 @@ public class JsonParser extends ParserBase {
|
|||
try {
|
||||
json.value(new BigDecimal(item.getValue()));
|
||||
} catch (Exception e) {
|
||||
throw new NumberFormatException("error writing number '"+item.getValue()+"' to JSON");
|
||||
throw new NumberFormatException(context.formatMessage(I18nConstants.ERROR_WRITING_NUMBER__TO_JSON, item.getValue()));
|
||||
}
|
||||
else
|
||||
json.value(item.getValue());
|
||||
json.value(item.getValue());
|
||||
}
|
||||
|
||||
private void compose(String path, Element element) throws IOException {
|
||||
|
|
|
@ -46,6 +46,7 @@ import org.hl7.fhir.r5.utils.formats.Turtle.TTLList;
|
|||
import org.hl7.fhir.r5.utils.formats.Turtle.TTLLiteral;
|
||||
import org.hl7.fhir.r5.utils.formats.Turtle.TTLObject;
|
||||
import org.hl7.fhir.r5.utils.formats.Turtle.TTLURL;
|
||||
import org.hl7.fhir.utilities.I18nConstants;
|
||||
import org.hl7.fhir.utilities.TextFile;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity;
|
||||
|
@ -69,7 +70,7 @@ public class TurtleParser extends ParserBase {
|
|||
try {
|
||||
src.parse(TextFile.streamToString(input));
|
||||
} catch (Exception e) {
|
||||
logError(-1, -1, "(document)", IssueType.INVALID, "Error parsing Turtle: "+e.getMessage(), IssueSeverity.FATAL);
|
||||
logError(-1, -1, "(document)", IssueType.INVALID, context.formatMessage(I18nConstants.ERROR_PARSING_TURTLE_, e.getMessage()), IssueSeverity.FATAL);
|
||||
return null;
|
||||
}
|
||||
return parse(src);
|
||||
|
@ -101,7 +102,7 @@ public class TurtleParser extends ParserBase {
|
|||
private Element parse(Turtle src, TTLComplex cmp) throws FHIRException {
|
||||
TTLObject type = cmp.getPredicates().get("http://www.w3.org/2000/01/rdf-schema#type");
|
||||
if (type == null) {
|
||||
logError(cmp.getLine(), cmp.getCol(), "(document)", IssueType.INVALID, "Unknown resource type (missing rdfs:type)", IssueSeverity.FATAL);
|
||||
logError(cmp.getLine(), cmp.getCol(), "(document)", IssueType.INVALID, context.formatMessage(I18nConstants.UNKNOWN_RESOURCE_TYPE_MISSING_RDFSTYPE), IssueSeverity.FATAL);
|
||||
return null;
|
||||
}
|
||||
if (type instanceof TTLList) {
|
||||
|
@ -114,7 +115,7 @@ public class TurtleParser extends ParserBase {
|
|||
}
|
||||
}
|
||||
if (!(type instanceof TTLURL)) {
|
||||
logError(cmp.getLine(), cmp.getCol(), "(document)", IssueType.INVALID, "Unexpected datatype for rdfs:type)", IssueSeverity.FATAL);
|
||||
logError(cmp.getLine(), cmp.getCol(), "(document)", IssueType.INVALID, context.formatMessage(I18nConstants.UNEXPECTED_DATATYPE_FOR_RDFSTYPE), IssueSeverity.FATAL);
|
||||
return null;
|
||||
}
|
||||
String name = ((TTLURL) type).getUri();
|
||||
|
@ -134,9 +135,9 @@ public class TurtleParser extends ParserBase {
|
|||
return result;
|
||||
}
|
||||
|
||||
private void parseChildren(Turtle src, String path, TTLComplex object, Element context, boolean primitive) throws FHIRException {
|
||||
private void parseChildren(Turtle src, String path, TTLComplex object, Element element, boolean primitive) throws FHIRException {
|
||||
|
||||
List<Property> properties = context.getProperty().getChildProperties(context.getName(), null);
|
||||
List<Property> properties = element.getProperty().getChildProperties(element.getName(), null);
|
||||
Set<String> processed = new HashSet<String>();
|
||||
if (primitive)
|
||||
processed.add(FHIR_URI_BASE + "value");
|
||||
|
@ -147,10 +148,10 @@ public class TurtleParser extends ParserBase {
|
|||
if (property.isChoice()) {
|
||||
for (TypeRefComponent type : property.getDefinition().getType()) {
|
||||
String eName = property.getName().substring(0, property.getName().length()-3) + Utilities.capitalize(type.getCode());
|
||||
parseChild(src, object, context, processed, property, path, getFormalName(property, eName));
|
||||
parseChild(src, object, element, processed, property, path, getFormalName(property, eName));
|
||||
}
|
||||
} else {
|
||||
parseChild(src, object, context, processed, property, path, getFormalName(property));
|
||||
parseChild(src, object, element, processed, property, path, getFormalName(property));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -159,7 +160,7 @@ public class TurtleParser extends ParserBase {
|
|||
for (String u : object.getPredicates().keySet()) {
|
||||
if (!processed.contains(u)) {
|
||||
TTLObject n = object.getPredicates().get(u);
|
||||
logError(n.getLine(), n.getCol(), path, IssueType.STRUCTURE, "Unrecognised predicate '"+u+"'", IssueSeverity.ERROR);
|
||||
logError(n.getLine(), n.getCol(), path, IssueType.STRUCTURE, context.formatMessage(I18nConstants.UNRECOGNISED_PREDICATE_, u), IssueSeverity.ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -181,13 +182,13 @@ public class TurtleParser extends ParserBase {
|
|||
}
|
||||
}
|
||||
|
||||
private void parseChildInstance(Turtle src, String npath, TTLComplex object, Element context, Property property, String name, TTLObject e) throws FHIRException {
|
||||
private void parseChildInstance(Turtle src, String npath, TTLComplex object, Element element, Property property, String name, TTLObject e) throws FHIRException {
|
||||
if (property.isResource())
|
||||
parseResource(src, npath, object, context, property, name, e);
|
||||
parseResource(src, npath, object, element, property, name, e);
|
||||
else if (e instanceof TTLComplex) {
|
||||
TTLComplex child = (TTLComplex) e;
|
||||
Element n = new Element(tail(name), property).markLocation(e.getLine(), e.getCol());
|
||||
context.getChildren().add(n);
|
||||
element.getChildren().add(n);
|
||||
if (property.isPrimitive(property.getType(tail(name)))) {
|
||||
parseChildren(src, npath, child, n, true);
|
||||
TTLObject val = child.getPredicates().get(FHIR_URI_BASE + "value");
|
||||
|
@ -198,13 +199,13 @@ public class TurtleParser extends ParserBase {
|
|||
// todo: check type
|
||||
n.setValue(value);
|
||||
} else
|
||||
logError(object.getLine(), object.getCol(), npath, IssueType.INVALID, "This property must be a Literal, not a "+e.getClass().getName(), IssueSeverity.ERROR);
|
||||
logError(object.getLine(), object.getCol(), npath, IssueType.INVALID, context.formatMessage(I18nConstants.THIS_PROPERTY_MUST_BE_A_LITERAL_NOT_A_, e.getClass().getName()), IssueSeverity.ERROR);
|
||||
}
|
||||
} else
|
||||
parseChildren(src, npath, child, n, false);
|
||||
|
||||
} else
|
||||
logError(object.getLine(), object.getCol(), npath, IssueType.INVALID, "This property must be a URI or bnode, not a "+e.getClass().getName(), IssueSeverity.ERROR);
|
||||
logError(object.getLine(), object.getCol(), npath, IssueType.INVALID, context.formatMessage(I18nConstants.THIS_PROPERTY_MUST_BE_A_URI_OR_BNODE_NOT_A_, e.getClass().getName()), IssueSeverity.ERROR);
|
||||
}
|
||||
|
||||
|
||||
|
@ -212,7 +213,7 @@ public class TurtleParser extends ParserBase {
|
|||
return name.substring(name.lastIndexOf(".")+1);
|
||||
}
|
||||
|
||||
private void parseResource(Turtle src, String npath, TTLComplex object, Element context, Property property, String name, TTLObject e) throws FHIRException {
|
||||
private void parseResource(Turtle src, String npath, TTLComplex object, Element element, Property property, String name, TTLObject e) throws FHIRException {
|
||||
TTLComplex obj;
|
||||
if (e instanceof TTLComplex)
|
||||
obj = (TTLComplex) e;
|
||||
|
@ -220,15 +221,15 @@ public class TurtleParser extends ParserBase {
|
|||
String url = ((TTLURL) e).getUri();
|
||||
obj = src.getObject(url);
|
||||
if (obj == null) {
|
||||
logError(e.getLine(), e.getCol(), npath, IssueType.INVALID, "reference to "+url+" cannot be resolved", IssueSeverity.FATAL);
|
||||
logError(e.getLine(), e.getCol(), npath, IssueType.INVALID, context.formatMessage(I18nConstants.REFERENCE_TO__CANNOT_BE_RESOLVED, url), IssueSeverity.FATAL);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
throw new FHIRFormatError("Wrong type for resource");
|
||||
throw new FHIRFormatError(context.formatMessage(I18nConstants.WRONG_TYPE_FOR_RESOURCE));
|
||||
|
||||
TTLObject type = obj.getPredicates().get("http://www.w3.org/2000/01/rdf-schema#type");
|
||||
if (type == null) {
|
||||
logError(object.getLine(), object.getCol(), npath, IssueType.INVALID, "Unknown resource type (missing rdfs:type)", IssueSeverity.FATAL);
|
||||
logError(object.getLine(), object.getCol(), npath, IssueType.INVALID, context.formatMessage(I18nConstants.UNKNOWN_RESOURCE_TYPE_MISSING_RDFSTYPE), IssueSeverity.FATAL);
|
||||
return;
|
||||
}
|
||||
if (type instanceof TTLList) {
|
||||
|
@ -241,7 +242,7 @@ public class TurtleParser extends ParserBase {
|
|||
}
|
||||
}
|
||||
if (!(type instanceof TTLURL)) {
|
||||
logError(object.getLine(), object.getCol(), npath, IssueType.INVALID, "Unexpected datatype for rdfs:type)", IssueSeverity.FATAL);
|
||||
logError(object.getLine(), object.getCol(), npath, IssueType.INVALID, context.formatMessage(I18nConstants.UNEXPECTED_DATATYPE_FOR_RDFSTYPE), IssueSeverity.FATAL);
|
||||
return;
|
||||
}
|
||||
String rt = ((TTLURL) type).getUri();
|
||||
|
@ -253,7 +254,7 @@ public class TurtleParser extends ParserBase {
|
|||
return;
|
||||
|
||||
Element n = new Element(tail(name), property).markLocation(object.getLine(), object.getCol());
|
||||
context.getChildren().add(n);
|
||||
element.getChildren().add(n);
|
||||
n.updateProperty(new Property(this.context, sd.getSnapshot().getElement().get(0), sd), SpecialElement.fromProperty(n.getProperty()), property);
|
||||
n.setType(rt);
|
||||
parseChildren(src, npath, obj, n, false);
|
||||
|
@ -278,7 +279,7 @@ public class TurtleParser extends ParserBase {
|
|||
if (en == null)
|
||||
en = property.getDefinition().getPath();
|
||||
if (!en.endsWith("[x]"))
|
||||
throw new Error("Attempt to replace element name for a non-choice type");
|
||||
throw new Error(context.formatMessage(I18nConstants.ATTEMPT_TO_REPLACE_ELEMENT_NAME_FOR_A_NONCHOICE_TYPE));
|
||||
return en.substring(0, en.lastIndexOf(".")+1)+elementName;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,6 +54,7 @@ import org.hl7.fhir.r5.utils.ToolingExtensions;
|
|||
import org.hl7.fhir.r5.utils.formats.XmlLocationAnnotator;
|
||||
import org.hl7.fhir.r5.utils.formats.XmlLocationData;
|
||||
import org.hl7.fhir.utilities.ElementDecoration;
|
||||
import org.hl7.fhir.utilities.I18nConstants;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity;
|
||||
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType;
|
||||
|
@ -140,7 +141,8 @@ public class XmlParser extends ParserBase {
|
|||
Node node = document.getFirstChild();
|
||||
while (node != null) {
|
||||
if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE)
|
||||
logError(line(document), col(document), "(document)", IssueType.INVALID, "No processing instructions allowed in resources", IssueSeverity.ERROR);
|
||||
logError(line(document), col(document), "(document)", IssueType.INVALID, context.formatMessage(
|
||||
I18nConstants.NO_PROCESSING_INSTRUCTIONS_ALLOWED_IN_RESOURCES), IssueSeverity.ERROR);
|
||||
node = node.getNextSibling();
|
||||
}
|
||||
}
|
||||
|
@ -214,14 +216,14 @@ public class XmlParser extends ParserBase {
|
|||
private void checkElement(org.w3c.dom.Element element, String path, Property prop) throws FHIRFormatError {
|
||||
if (policy == ValidationPolicy.EVERYTHING) {
|
||||
if (empty(element) && FormatUtilities.FHIR_NS.equals(element.getNamespaceURI())) // this rule only applies to FHIR Content
|
||||
logError(line(element), col(element), path, IssueType.INVALID, "Element must have some content", IssueSeverity.ERROR);
|
||||
logError(line(element), col(element), path, IssueType.INVALID, context.formatMessage(I18nConstants.ELEMENT_MUST_HAVE_SOME_CONTENT), IssueSeverity.ERROR);
|
||||
String ns = FormatUtilities.FHIR_NS;
|
||||
if (ToolingExtensions.hasExtension(prop.getDefinition(), "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace"))
|
||||
ns = ToolingExtensions.readStringExtension(prop.getDefinition(), "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace");
|
||||
else if (ToolingExtensions.hasExtension(prop.getStructure(), "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace"))
|
||||
ns = ToolingExtensions.readStringExtension(prop.getStructure(), "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace");
|
||||
if (!element.getNamespaceURI().equals(ns))
|
||||
logError(line(element), col(element), path, IssueType.INVALID, "Wrong namespace - expected '"+ns+"'", IssueSeverity.ERROR);
|
||||
logError(line(element), col(element), path, IssueType.INVALID, context.formatMessage(I18nConstants.WRONG_NAMESPACE__EXPECTED_, ns), IssueSeverity.ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -236,10 +238,10 @@ public class XmlParser extends ParserBase {
|
|||
return result;
|
||||
}
|
||||
|
||||
private void parseChildren(String path, org.w3c.dom.Element node, Element context) throws FHIRFormatError, FHIRException, IOException, DefinitionException {
|
||||
private void parseChildren(String path, org.w3c.dom.Element node, Element element) throws FHIRFormatError, FHIRException, IOException, DefinitionException {
|
||||
// this parsing routine retains the original order in a the XML file, to support validation
|
||||
reapComments(node, context);
|
||||
List<Property> properties = context.getProperty().getChildProperties(context.getName(), XMLUtil.getXsiType(node));
|
||||
reapComments(node, element);
|
||||
List<Property> properties = element.getProperty().getChildProperties(element.getName(), XMLUtil.getXsiType(node));
|
||||
|
||||
String text = XMLUtil.getDirectText(node).trim();
|
||||
if (!Utilities.noString(text)) {
|
||||
|
@ -247,17 +249,17 @@ public class XmlParser extends ParserBase {
|
|||
if (property != null) {
|
||||
if ("ED.data[x]".equals(property.getDefinition().getId()) || (property.getDefinition()!=null && property.getDefinition().getBase()!=null && "ED.data[x]".equals(property.getDefinition().getBase().getPath()))) {
|
||||
if ("B64".equals(node.getAttribute("representation"))) {
|
||||
context.getChildren().add(new Element("dataBase64Binary", property, "base64Binary", text).markLocation(line(node), col(node)));
|
||||
element.getChildren().add(new Element("dataBase64Binary", property, "base64Binary", text).markLocation(line(node), col(node)));
|
||||
} else {
|
||||
context.getChildren().add(new Element("dataString", property, "string", text).markLocation(line(node), col(node)));
|
||||
element.getChildren().add(new Element("dataString", property, "string", text).markLocation(line(node), col(node)));
|
||||
}
|
||||
} else {
|
||||
context.getChildren().add(
|
||||
element.getChildren().add(
|
||||
new Element(property.getName(), property, property.getType(), text).markLocation(line(node), col(node)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
logError(line(node), col(node), path, IssueType.STRUCTURE, "Text should not be present", IssueSeverity.ERROR);
|
||||
logError(line(node), col(node), path, IssueType.STRUCTURE, context.formatMessage(I18nConstants.TEXT_SHOULD_NOT_BE_PRESENT), IssueSeverity.ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -269,10 +271,10 @@ public class XmlParser extends ParserBase {
|
|||
String av = attr.getNodeValue();
|
||||
if (ToolingExtensions.hasExtension(property.getDefinition(), "http://www.healthintersections.com.au/fhir/StructureDefinition/elementdefinition-dateformat"))
|
||||
av = convertForDateFormatFromExternal(ToolingExtensions.readStringExtension(property.getDefinition(), "http://www.healthintersections.com.au/fhir/StructureDefinition/elementdefinition-dateformat"), av);
|
||||
if (property.getName().equals("value") && context.isPrimitive())
|
||||
context.setValue(av);
|
||||
if (property.getName().equals("value") && element.isPrimitive())
|
||||
element.setValue(av);
|
||||
else
|
||||
context.getChildren().add(new Element(property.getName(), property, property.getType(), av).markLocation(line(node), col(node)));
|
||||
element.getChildren().add(new Element(property.getName(), property, property.getType(), av).markLocation(line(node), col(node)));
|
||||
} else {
|
||||
boolean ok = false;
|
||||
if (FormatUtilities.FHIR_NS.equals(node.getNamespaceURI())) {
|
||||
|
@ -281,9 +283,9 @@ public class XmlParser extends ParserBase {
|
|||
}
|
||||
} else
|
||||
ok = ok || (attr.getLocalName().equals("schemaLocation")); // xsi:schemalocation allowed for non FHIR content
|
||||
ok = ok || (hasTypeAttr(context) && attr.getLocalName().equals("type") && FormatUtilities.NS_XSI.equals(attr.getNamespaceURI())); // xsi:type allowed if element says so
|
||||
ok = ok || (hasTypeAttr(element) && attr.getLocalName().equals("type") && FormatUtilities.NS_XSI.equals(attr.getNamespaceURI())); // xsi:type allowed if element says so
|
||||
if (!ok)
|
||||
logError(line(node), col(node), path, IssueType.STRUCTURE, "Undefined attribute '@"+attr.getNodeName()+"' on "+node.getNodeName()+" for type "+context.fhirType()+" (properties = "+properties+")", IssueSeverity.ERROR);
|
||||
logError(line(node), col(node), path, IssueType.STRUCTURE, context.formatMessage(I18nConstants.UNDEFINED_ATTRIBUTE__ON__FOR_TYPE__PROPERTIES__, attr.getNodeName(), node.getNodeName(), element.fhirType(), properties), IssueSeverity.ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -295,11 +297,11 @@ public class XmlParser extends ParserBase {
|
|||
if (property != null) {
|
||||
if (!property.isChoice() && "xhtml".equals(property.getType())) {
|
||||
XhtmlNode xhtml;
|
||||
if (property.getDefinition().hasRepresentation(PropertyRepresentation.CDATEXT))
|
||||
if (property.getDefinition().hasRepresentation(PropertyRepresentation.CDATEXT))
|
||||
xhtml = new CDANarrativeFormat().convert((org.w3c.dom.Element) child);
|
||||
else
|
||||
xhtml = new XhtmlParser().setValidatorMode(true).parseHtmlNode((org.w3c.dom.Element) child);
|
||||
context.getChildren().add(new Element(property.getName(), property, "xhtml", new XhtmlComposer(XhtmlComposer.XML, false).compose(xhtml)).setXhtml(xhtml).markLocation(line(child), col(child)));
|
||||
element.getChildren().add(new Element(property.getName(), property, "xhtml", new XhtmlComposer(XhtmlComposer.XML, false).compose(xhtml)).setXhtml(xhtml).markLocation(line(child), col(child)));
|
||||
} else {
|
||||
String npath = path+"/"+pathPrefix(child.getNamespaceURI())+child.getLocalName();
|
||||
Element n = new Element(child.getLocalName(), property).markLocation(line(child), col(child));
|
||||
|
@ -313,7 +315,7 @@ public class XmlParser extends ParserBase {
|
|||
xsiType = ToolingExtensions.readStringExtension(property.getDefinition(), "http://hl7.org/fhir/StructureDefinition/elementdefinition-defaulttype");
|
||||
n.setType(xsiType);
|
||||
} else {
|
||||
logError(line(child), col(child), path, IssueType.STRUCTURE, "No type found on '"+child.getLocalName()+'"', IssueSeverity.ERROR);
|
||||
logError(line(child), col(child), path, IssueType.STRUCTURE, context.formatMessage(I18nConstants.NO_TYPE_FOUND_ON_, child.getLocalName()), IssueSeverity.ERROR);
|
||||
ok = false;
|
||||
}
|
||||
} else {
|
||||
|
@ -325,7 +327,7 @@ public class XmlParser extends ParserBase {
|
|||
} else
|
||||
n.setType(n.getType());
|
||||
}
|
||||
context.getChildren().add(n);
|
||||
element.getChildren().add(n);
|
||||
if (ok) {
|
||||
if (property.isResource())
|
||||
parseResource(npath, (org.w3c.dom.Element) child, n, property);
|
||||
|
@ -334,11 +336,11 @@ public class XmlParser extends ParserBase {
|
|||
}
|
||||
}
|
||||
} else
|
||||
logError(line(child), col(child), path, IssueType.STRUCTURE, "Undefined element '"+child.getLocalName()+"'", IssueSeverity.ERROR);
|
||||
logError(line(child), col(child), path, IssueType.STRUCTURE, context.formatMessage(I18nConstants.UNDEFINED_ELEMENT_, child.getLocalName()), IssueSeverity.ERROR);
|
||||
} else if (child.getNodeType() == Node.CDATA_SECTION_NODE){
|
||||
logError(line(child), col(child), path, IssueType.STRUCTURE, "CDATA is not allowed", IssueSeverity.ERROR);
|
||||
logError(line(child), col(child), path, IssueType.STRUCTURE, context.formatMessage(I18nConstants.CDATA_IS_NOT_ALLOWED), IssueSeverity.ERROR);
|
||||
} else if (!Utilities.existsInList(child.getNodeType(), 3, 8)) {
|
||||
logError(line(child), col(child), path, IssueType.STRUCTURE, "Node type "+Integer.toString(child.getNodeType())+" is not allowed", IssueSeverity.ERROR);
|
||||
logError(line(child), col(child), path, IssueType.STRUCTURE, context.formatMessage(I18nConstants.NODE_TYPE__IS_NOT_ALLOWED, Integer.toString(child.getNodeType())), IssueSeverity.ERROR);
|
||||
}
|
||||
child = child.getNextSibling();
|
||||
}
|
||||
|
@ -355,7 +357,8 @@ public class XmlParser extends ParserBase {
|
|||
}
|
||||
});
|
||||
for (Property p : propsSortedByLongestFirst)
|
||||
if (!p.getDefinition().hasRepresentation(PropertyRepresentation.XMLATTR) && !p.getDefinition().hasRepresentation(PropertyRepresentation.XMLTEXT)) {
|
||||
if (!p.getDefinition().hasRepresentation(PropertyRepresentation.XMLATTR) && !p.getDefinition().hasRepresentation(
|
||||
PropertyRepresentation.XMLTEXT)) {
|
||||
if (p.getName().equals(nodeName))
|
||||
return p;
|
||||
if (p.getName().endsWith("[x]") && nodeName.length() > p.getName().length()-3 && p.getName().substring(0, p.getName().length()-3).equals(nodeName.substring(0, p.getName().length()-3)))
|
||||
|
@ -366,7 +369,8 @@ public class XmlParser extends ParserBase {
|
|||
|
||||
private Property getAttrProp(List<Property> properties, String nodeName) {
|
||||
for (Property p : properties)
|
||||
if (p.getName().equals(nodeName) && p.getDefinition().hasRepresentation(PropertyRepresentation.XMLATTR))
|
||||
if (p.getName().equals(nodeName) && p.getDefinition().hasRepresentation(
|
||||
PropertyRepresentation.XMLATTR))
|
||||
return p;
|
||||
return null;
|
||||
}
|
||||
|
@ -383,7 +387,7 @@ public class XmlParser extends ParserBase {
|
|||
DateTimeType d = DateTimeType.parseV3(av);
|
||||
return d.asStringValue();
|
||||
} else
|
||||
throw new FHIRException("Unknown Data format '"+fmt+"'");
|
||||
throw new FHIRException(context.formatMessage(I18nConstants.UNKNOWN_DATA_FORMAT_, fmt));
|
||||
}
|
||||
|
||||
private String convertForDateFormatToExternal(String fmt, String av) throws FHIRException {
|
||||
|
@ -391,7 +395,7 @@ public class XmlParser extends ParserBase {
|
|||
DateTimeType d = new DateTimeType(av);
|
||||
return d.getAsV3();
|
||||
} else
|
||||
throw new FHIRException("Unknown Date format '"+fmt+"'");
|
||||
throw new FHIRException(context.formatMessage(I18nConstants.UNKNOWN_DATE_FORMAT_, fmt));
|
||||
}
|
||||
|
||||
private void parseResource(String string, org.w3c.dom.Element container, Element parent, Property elementProperty) throws FHIRFormatError, DefinitionException, FHIRException, IOException {
|
||||
|
@ -399,7 +403,7 @@ public class XmlParser extends ParserBase {
|
|||
String name = res.getLocalName();
|
||||
StructureDefinition sd = context.fetchResource(StructureDefinition.class, ProfileUtilities.sdNs(name, context.getOverrideVersionNs()));
|
||||
if (sd == null)
|
||||
throw new FHIRFormatError("Contained resource does not appear to be a FHIR resource (unknown name '"+res.getLocalName()+"')");
|
||||
throw new FHIRFormatError(context.formatMessage(I18nConstants.CONTAINED_RESOURCE_DOES_NOT_APPEAR_TO_BE_A_FHIR_RESOURCE_UNKNOWN_NAME_, res.getLocalName()));
|
||||
parent.updateProperty(new Property(context, sd.getSnapshot().getElement().get(0), sd), SpecialElement.fromProperty(parent.getProperty()), elementProperty);
|
||||
parent.setType(name);
|
||||
parseChildren(res.getLocalName(), res, parent);
|
||||
|
|
|
@ -364,5 +364,27 @@ public class I18nConstants {
|
|||
public final static String UNRECOGNISED_PROPERTY_ = "Unrecognised_property_";
|
||||
public final static String OBJECT_MUST_HAVE_SOME_CONTENT = "Object_must_have_some_content";
|
||||
public final static String ERROR_PARSING_JSON_ = "Error_parsing_JSON_";
|
||||
public final static String NODE_TYPE__IS_NOT_ALLOWED = "Node_type__is_not_allowed";
|
||||
public final static String CDATA_IS_NOT_ALLOWED = "CDATA_is_not_allowed";
|
||||
public final static String UNDEFINED_ELEMENT_ = "Undefined_element_";
|
||||
public final static String UNDEFINED_ATTRIBUTE__ON__FOR_TYPE__PROPERTIES__ = "Undefined_attribute__on__for_type__properties__";
|
||||
public final static String TEXT_SHOULD_NOT_BE_PRESENT = "Text_should_not_be_present";
|
||||
public final static String WRONG_NAMESPACE__EXPECTED_ = "Wrong_namespace__expected_";
|
||||
public final static String ELEMENT_MUST_HAVE_SOME_CONTENT = "Element_must_have_some_content";
|
||||
public final static String NO_PROCESSING_INSTRUCTIONS_ALLOWED_IN_RESOURCES = "No_processing_instructions_allowed_in_resources";
|
||||
public final static String UNKNOWN_RESOURCE_TYPE_MISSING_RDFSTYPE = "Unknown_resource_type_missing_rdfstype";
|
||||
public final static String REFERENCE_TO__CANNOT_BE_RESOLVED = "reference_to__cannot_be_resolved";
|
||||
public final static String THIS_PROPERTY_MUST_BE_A_URI_OR_BNODE_NOT_A_ = "This_property_must_be_a_URI_or_bnode_not_a_";
|
||||
public final static String THIS_PROPERTY_MUST_BE_A_LITERAL_NOT_A_ = "This_property_must_be_a_Literal_not_a_";
|
||||
public final static String UNRECOGNISED_PREDICATE_ = "Unrecognised_predicate_";
|
||||
public final static String ERROR_PARSING_TURTLE_ = "Error_parsing_Turtle_";
|
||||
public final static String UNEXPECTED_DATATYPE_FOR_RDFSTYPE = "Unexpected_datatype_for_rdfstype";
|
||||
public final static String ATTEMPT_TO_REPLACE_ELEMENT_NAME_FOR_A_NONCHOICE_TYPE = "Attempt_to_replace_element_name_for_a_nonchoice_type";
|
||||
public final static String WRONG_TYPE_FOR_RESOURCE = "Wrong_type_for_resource";
|
||||
public final static String CONTAINED_RESOURCE_DOES_NOT_APPEAR_TO_BE_A_FHIR_RESOURCE_UNKNOWN_NAME_ = "Contained_resource_does_not_appear_to_be_a_FHIR_resource_unknown_name_";
|
||||
public final static String UNKNOWN_DATE_FORMAT_ = "Unknown_Date_format_";
|
||||
public final static String UNKNOWN_DATA_FORMAT_ = "Unknown_Data_format_";
|
||||
public final static String NO_TYPE_FOUND_ON_ = "No_type_found_on_";
|
||||
public final static String ERROR_WRITING_NUMBER__TO_JSON = "error_writing_number__to_JSON";
|
||||
|
||||
}
|
||||
|
|
|
@ -361,3 +361,27 @@ This_property_must_be_an_Array_not_ = This property must be an Array, not {0}
|
|||
Unrecognised_property_ = Unrecognised property ''@{0}''
|
||||
Object_must_have_some_content = Object must have some content
|
||||
Error_parsing_JSON_ = Error parsing JSON: {0}
|
||||
Node_type__is_not_allowed = Node type {0} is not allowed
|
||||
CDATA_is_not_allowed = CDATA is not allowed
|
||||
Undefined_element_ = Undefined element ''{0}''
|
||||
Undefined_attribute__on__for_type__properties__ = Undefined attribute ''@{0}'' on {1} for type {2} (properties = {3})
|
||||
Text_should_not_be_present = Text should not be present
|
||||
Wrong_namespace__expected_ = Wrong namespace - expected ''{0}''
|
||||
Element_must_have_some_content = Element must have some content
|
||||
No_processing_instructions_allowed_in_resources = No processing instructions allowed in resources
|
||||
Unknown_resource_type_missing_rdfstype = Unknown resource type (missing rdfs:type)
|
||||
reference_to__cannot_be_resolved = reference to {0} cannot be resolved
|
||||
This_property_must_be_a_URI_or_bnode_not_a_ = This property must be a URI or bnode, not a {0}
|
||||
This_property_must_be_a_Literal_not_a_ = This property must be a Literal, not a {0}
|
||||
Unrecognised_predicate_ = Unrecognised predicate ''{0}''
|
||||
Error_parsing_Turtle_ = Error parsing Turtle: {0}
|
||||
Unexpected_datatype_for_rdfstype = Unexpected datatype for rdfs:type
|
||||
Attempt_to_replace_element_name_for_a_nonchoice_type = Attempt to replace element name for a non-choice type
|
||||
Wrong_type_for_resource = Wrong type for resource
|
||||
Contained_resource_does_not_appear_to_be_a_FHIR_resource_unknown_name_ = Contained resource does not appear to be a FHIR resource (unknown name ''{0}'')
|
||||
Unknown_Date_format_ = Unknown Date format ''{0}''
|
||||
Unknown_Data_format_ = Unknown Data format ''{0}''
|
||||
No_type_found_on_ = No type found on ''{0}''
|
||||
error_writing_number__to_JSON = error writing number ''{0}'' to JSON
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue