RDF XML Parser
This commit is contained in:
parent
a15c90be6d
commit
fc27325dbc
|
@ -66,8 +66,10 @@
|
|||
|
||||
<!-- General -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<groupId>org.apache.jena</groupId>
|
||||
<artifactId>apache-jena-libs</artifactId>
|
||||
<type>pom</type>
|
||||
<version>3.11.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
|
|
|
@ -111,7 +111,7 @@ public class FhirContext {
|
|||
* of this method, e.g. {@link #forDstu2()} or {@link #forDstu3()} or {@link #forR4()}
|
||||
*/
|
||||
@Deprecated
|
||||
public FhirContext(Class<? extends IBaseResource> theResourceType) {
|
||||
public FhirContext(final Class<? extends IBaseResource> theResourceType) {
|
||||
this(toCollection(theResourceType));
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ public class FhirContext {
|
|||
* of this method, e.g. {@link #forDstu2()} or {@link #forDstu3()} or {@link #forR4()}
|
||||
*/
|
||||
@Deprecated
|
||||
public FhirContext(Class<?>... theResourceTypes) {
|
||||
public FhirContext(final Class<?>... theResourceTypes) {
|
||||
this(toCollection(theResourceTypes));
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ public class FhirContext {
|
|||
* of this method, e.g. {@link #forDstu2()} or {@link #forDstu3()} or {@link #forR4()}
|
||||
*/
|
||||
@Deprecated
|
||||
public FhirContext(Collection<Class<? extends IBaseResource>> theResourceTypes) {
|
||||
public FhirContext(final Collection<Class<? extends IBaseResource>> theResourceTypes) {
|
||||
this(null, theResourceTypes);
|
||||
}
|
||||
|
||||
|
@ -138,11 +138,11 @@ public class FhirContext {
|
|||
* of this method, e.g. {@link #forDstu2()} or {@link #forDstu3()} or {@link #forR4()}, but
|
||||
* this method can also be used if you wish to supply the version programmatically.
|
||||
*/
|
||||
public FhirContext(FhirVersionEnum theVersion) {
|
||||
public FhirContext(final FhirVersionEnum theVersion) {
|
||||
this(theVersion, null);
|
||||
}
|
||||
|
||||
private FhirContext(FhirVersionEnum theVersion, Collection<Class<? extends IBaseResource>> theResourceTypes) {
|
||||
private FhirContext(final FhirVersionEnum theVersion, final Collection<Class<? extends IBaseResource>> theResourceTypes) {
|
||||
VersionUtil.getVersion();
|
||||
|
||||
if (theVersion != null) {
|
||||
|
@ -191,7 +191,7 @@ public class FhirContext {
|
|||
|
||||
}
|
||||
|
||||
private String createUnknownResourceNameError(String theResourceName, FhirVersionEnum theVersion) {
|
||||
private String createUnknownResourceNameError(final String theResourceName, final FhirVersionEnum theVersion) {
|
||||
return getLocalizer().getMessage(FhirContext.class, "unknownResourceName", theResourceName, theVersion);
|
||||
}
|
||||
|
||||
|
@ -232,7 +232,7 @@ public class FhirContext {
|
|||
*
|
||||
* @param theAddProfileTagWhenEncoding The add profile mode (must not be <code>null</code>)
|
||||
*/
|
||||
public void setAddProfileTagWhenEncoding(AddProfileTagEnum theAddProfileTagWhenEncoding) {
|
||||
public void setAddProfileTagWhenEncoding(final AddProfileTagEnum theAddProfileTagWhenEncoding) {
|
||||
Validate.notNull(theAddProfileTagWhenEncoding, "theAddProfileTagWhenEncoding must not be null");
|
||||
myAddProfileTagWhenEncoding = theAddProfileTagWhenEncoding;
|
||||
}
|
||||
|
@ -247,7 +247,7 @@ public class FhirContext {
|
|||
*
|
||||
* @see #setDefaultTypeForProfile(String, Class)
|
||||
*/
|
||||
public Class<? extends IBaseResource> getDefaultTypeForProfile(String theProfile) {
|
||||
public Class<? extends IBaseResource> getDefaultTypeForProfile(final String theProfile) {
|
||||
validateInitialized();
|
||||
return myDefaultTypeForProfile.get(theProfile);
|
||||
}
|
||||
|
@ -257,7 +257,7 @@ public class FhirContext {
|
|||
* for extending the core library.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public BaseRuntimeElementDefinition<?> getElementDefinition(Class<? extends IBase> theElementType) {
|
||||
public BaseRuntimeElementDefinition<?> getElementDefinition(final Class<? extends IBase> theElementType) {
|
||||
validateInitialized();
|
||||
BaseRuntimeElementDefinition<?> retVal = myClassToElementDefinition.get(theElementType);
|
||||
if (retVal == null) {
|
||||
|
@ -273,7 +273,7 @@ public class FhirContext {
|
|||
* Note that this method is case insensitive!
|
||||
* </p>
|
||||
*/
|
||||
public BaseRuntimeElementDefinition<?> getElementDefinition(String theElementName) {
|
||||
public BaseRuntimeElementDefinition<?> getElementDefinition(final String theElementName) {
|
||||
validateInitialized();
|
||||
return myNameToElementDefinition.get(theElementName.toLowerCase());
|
||||
}
|
||||
|
@ -309,7 +309,7 @@ public class FhirContext {
|
|||
* This feature is not yet in its final state and should be considered an internal part of HAPI for now - use with
|
||||
* caution
|
||||
*/
|
||||
public void setLocalizer(HapiLocalizer theMessages) {
|
||||
public void setLocalizer(final HapiLocalizer theMessages) {
|
||||
myLocalizer = theMessages;
|
||||
}
|
||||
|
||||
|
@ -317,7 +317,7 @@ public class FhirContext {
|
|||
return myNarrativeGenerator;
|
||||
}
|
||||
|
||||
public void setNarrativeGenerator(INarrativeGenerator theNarrativeGenerator) {
|
||||
public void setNarrativeGenerator(final INarrativeGenerator theNarrativeGenerator) {
|
||||
myNarrativeGenerator = theNarrativeGenerator;
|
||||
}
|
||||
|
||||
|
@ -337,7 +337,7 @@ public class FhirContext {
|
|||
*
|
||||
* @param theParserOptions The parser options object - Must not be <code>null</code>
|
||||
*/
|
||||
public void setParserOptions(ParserOptions theParserOptions) {
|
||||
public void setParserOptions(final ParserOptions theParserOptions) {
|
||||
Validate.notNull(theParserOptions, "theParserOptions must not be null");
|
||||
myParserOptions = theParserOptions;
|
||||
}
|
||||
|
@ -368,7 +368,7 @@ public class FhirContext {
|
|||
*
|
||||
* @see PerformanceOptionsEnum for a list of available options
|
||||
*/
|
||||
public void setPerformanceOptions(Collection<PerformanceOptionsEnum> theOptions) {
|
||||
public void setPerformanceOptions(final Collection<PerformanceOptionsEnum> theOptions) {
|
||||
myPerformanceOptions.clear();
|
||||
if (theOptions != null) {
|
||||
myPerformanceOptions.addAll(theOptions);
|
||||
|
@ -379,7 +379,7 @@ public class FhirContext {
|
|||
* Returns the scanned runtime model for the given type. This is an advanced feature which is generally only needed
|
||||
* for extending the core library.
|
||||
*/
|
||||
public RuntimeResourceDefinition getResourceDefinition(Class<? extends IBaseResource> theResourceType) {
|
||||
public RuntimeResourceDefinition getResourceDefinition(final Class<? extends IBaseResource> theResourceType) {
|
||||
validateInitialized();
|
||||
if (theResourceType == null) {
|
||||
throw new NullPointerException("theResourceType can not be null");
|
||||
|
@ -395,7 +395,7 @@ public class FhirContext {
|
|||
return retVal;
|
||||
}
|
||||
|
||||
public RuntimeResourceDefinition getResourceDefinition(FhirVersionEnum theVersion, String theResourceName) {
|
||||
public RuntimeResourceDefinition getResourceDefinition(final FhirVersionEnum theVersion, final String theResourceName) {
|
||||
Validate.notNull(theVersion, "theVersion can not be null");
|
||||
validateInitialized();
|
||||
|
||||
|
@ -427,7 +427,7 @@ public class FhirContext {
|
|||
* Returns the scanned runtime model for the given type. This is an advanced feature which is generally only needed
|
||||
* for extending the core library.
|
||||
*/
|
||||
public RuntimeResourceDefinition getResourceDefinition(IBaseResource theResource) {
|
||||
public RuntimeResourceDefinition getResourceDefinition(final IBaseResource theResource) {
|
||||
validateInitialized();
|
||||
Validate.notNull(theResource, "theResource must not be null");
|
||||
return getResourceDefinition(theResource.getClass());
|
||||
|
@ -442,7 +442,7 @@ public class FhirContext {
|
|||
*
|
||||
* @throws DataFormatException If the resource name is not known
|
||||
*/
|
||||
public RuntimeResourceDefinition getResourceDefinition(String theResourceName) throws DataFormatException {
|
||||
public RuntimeResourceDefinition getResourceDefinition(final String theResourceName) throws DataFormatException {
|
||||
validateInitialized();
|
||||
Validate.notBlank(theResourceName, "theResourceName must not be blank");
|
||||
|
||||
|
@ -470,7 +470,7 @@ public class FhirContext {
|
|||
* Returns the scanned runtime model for the given type. This is an advanced feature which is generally only needed
|
||||
* for extending the core library.
|
||||
*/
|
||||
public RuntimeResourceDefinition getResourceDefinitionById(String theId) {
|
||||
public RuntimeResourceDefinition getResourceDefinitionById(final String theId) {
|
||||
validateInitialized();
|
||||
return myIdToResourceDefinition.get(theId);
|
||||
}
|
||||
|
@ -536,7 +536,7 @@ public class FhirContext {
|
|||
*
|
||||
* @param theRestfulClientFactory
|
||||
*/
|
||||
public void setRestfulClientFactory(IRestfulClientFactory theRestfulClientFactory) {
|
||||
public void setRestfulClientFactory(final IRestfulClientFactory theRestfulClientFactory) {
|
||||
Validate.notNull(theRestfulClientFactory, "theRestfulClientFactory must not be null");
|
||||
this.myRestfulClientFactory = theRestfulClientFactory;
|
||||
}
|
||||
|
@ -662,7 +662,7 @@ public class FhirContext {
|
|||
* @return A newly created client
|
||||
* @throws ConfigurationException If the interface type is not an interface
|
||||
*/
|
||||
public <T extends IRestfulClient> T newRestfulClient(Class<T> theClientType, String theServerBase) {
|
||||
public <T extends IRestfulClient> T newRestfulClient(final Class<T> theClientType, final String theServerBase) {
|
||||
return getRestfulClientFactory().newClient(theClientType, theServerBase);
|
||||
}
|
||||
|
||||
|
@ -678,7 +678,7 @@ public class FhirContext {
|
|||
*
|
||||
* @param theServerBase The URL of the base for the restful FHIR server to connect to
|
||||
*/
|
||||
public IGenericClient newRestfulGenericClient(String theServerBase) {
|
||||
public IGenericClient newRestfulGenericClient(final String theServerBase) {
|
||||
return getRestfulClientFactory().newGenericClient(theServerBase);
|
||||
}
|
||||
|
||||
|
@ -729,7 +729,7 @@ public class FhirContext {
|
|||
*
|
||||
* @param theType The custom type to add (must not be <code>null</code>)
|
||||
*/
|
||||
public void registerCustomType(Class<? extends IBase> theType) {
|
||||
public void registerCustomType(final Class<? extends IBase> theType) {
|
||||
Validate.notNull(theType, "theType must not be null");
|
||||
|
||||
ensureCustomTypeList();
|
||||
|
@ -748,7 +748,7 @@ public class FhirContext {
|
|||
*
|
||||
* @param theTypes The custom types to add (must not be <code>null</code> or contain null elements in the collection)
|
||||
*/
|
||||
public void registerCustomTypes(Collection<Class<? extends IBase>> theTypes) {
|
||||
public void registerCustomTypes(final Collection<Class<? extends IBase>> theTypes) {
|
||||
Validate.notNull(theTypes, "theTypes must not be null");
|
||||
Validate.noNullElements(theTypes.toArray(), "theTypes must not contain any null elements");
|
||||
|
||||
|
@ -757,21 +757,21 @@ public class FhirContext {
|
|||
myCustomTypes.addAll(theTypes);
|
||||
}
|
||||
|
||||
private BaseRuntimeElementDefinition<?> scanDatatype(Class<? extends IElement> theResourceType) {
|
||||
private BaseRuntimeElementDefinition<?> scanDatatype(final Class<? extends IElement> theResourceType) {
|
||||
ArrayList<Class<? extends IElement>> resourceTypes = new ArrayList<Class<? extends IElement>>();
|
||||
resourceTypes.add(theResourceType);
|
||||
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> defs = scanResourceTypes(resourceTypes);
|
||||
return defs.get(theResourceType);
|
||||
}
|
||||
|
||||
private RuntimeResourceDefinition scanResourceType(Class<? extends IBaseResource> theResourceType) {
|
||||
private RuntimeResourceDefinition scanResourceType(final Class<? extends IBaseResource> theResourceType) {
|
||||
ArrayList<Class<? extends IElement>> resourceTypes = new ArrayList<Class<? extends IElement>>();
|
||||
resourceTypes.add(theResourceType);
|
||||
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> defs = scanResourceTypes(resourceTypes);
|
||||
return (RuntimeResourceDefinition) defs.get(theResourceType);
|
||||
}
|
||||
|
||||
private synchronized Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> scanResourceTypes(Collection<Class<? extends IElement>> theResourceTypes) {
|
||||
private synchronized Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> scanResourceTypes(final Collection<Class<? extends IElement>> theResourceTypes) {
|
||||
List<Class<? extends IBase>> typesToScan = new ArrayList<Class<? extends IBase>>();
|
||||
if (theResourceTypes != null) {
|
||||
typesToScan.addAll(theResourceTypes);
|
||||
|
@ -844,7 +844,7 @@ public class FhirContext {
|
|||
* <code>null</code> or empty.
|
||||
* @param theClass The resource type, or <code>null</code> to clear any existing type
|
||||
*/
|
||||
public void setDefaultTypeForProfile(String theProfile, Class<? extends IBaseResource> theClass) {
|
||||
public void setDefaultTypeForProfile(final String theProfile, final Class<? extends IBaseResource> theClass) {
|
||||
Validate.notBlank(theProfile, "theProfile must not be null or empty");
|
||||
if (theClass == null) {
|
||||
myDefaultTypeForProfile.remove(theProfile);
|
||||
|
@ -858,7 +858,7 @@ public class FhirContext {
|
|||
*
|
||||
* @param theParserErrorHandler The error handler
|
||||
*/
|
||||
public void setParserErrorHandler(IParserErrorHandler theParserErrorHandler) {
|
||||
public void setParserErrorHandler(final IParserErrorHandler theParserErrorHandler) {
|
||||
Validate.notNull(theParserErrorHandler, "theParserErrorHandler must not be null");
|
||||
myParserErrorHandler = theParserErrorHandler;
|
||||
}
|
||||
|
@ -868,7 +868,7 @@ public class FhirContext {
|
|||
*
|
||||
* @see PerformanceOptionsEnum for a list of available options
|
||||
*/
|
||||
public void setPerformanceOptions(PerformanceOptionsEnum... thePerformanceOptions) {
|
||||
public void setPerformanceOptions(final PerformanceOptionsEnum... thePerformanceOptions) {
|
||||
Collection<PerformanceOptionsEnum> asList = null;
|
||||
if (thePerformanceOptions != null) {
|
||||
asList = Arrays.asList(thePerformanceOptions);
|
||||
|
@ -877,7 +877,7 @@ public class FhirContext {
|
|||
}
|
||||
|
||||
@SuppressWarnings({"cast"})
|
||||
private List<Class<? extends IElement>> toElementList(Collection<Class<? extends IBaseResource>> theResourceTypes) {
|
||||
private List<Class<? extends IElement>> toElementList(final Collection<Class<? extends IBaseResource>> theResourceTypes) {
|
||||
if (theResourceTypes == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -947,7 +947,7 @@ public class FhirContext {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static List<Class<? extends IBaseResource>> toCollection(Class<?>[] theResourceTypes) {
|
||||
private static List<Class<? extends IBaseResource>> toCollection(final Class<?>[] theResourceTypes) {
|
||||
ArrayList<Class<? extends IBaseResource>> retVal = new ArrayList<Class<? extends IBaseResource>>(1);
|
||||
for (Class<?> clazz : theResourceTypes) {
|
||||
if (!IResource.class.isAssignableFrom(clazz)) {
|
||||
|
|
|
@ -53,7 +53,7 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
|||
* This class is the FHIR RDF parser/encoder. Users should not interact with this class directly, but should use
|
||||
* {@link FhirContext#newRDFParser()} to get an instance.
|
||||
*/
|
||||
public class RDFParser extends BaseParser /* implements IParser */ {
|
||||
public class RDFParser extends BaseParser {
|
||||
|
||||
private static final String FHIR_NS = "http://hl7.org/fhir";
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(RDFParser.class);
|
||||
|
@ -68,12 +68,12 @@ public class RDFParser extends BaseParser /* implements IParser */ {
|
|||
*
|
||||
* @param theParserErrorHandler the Parser Error Handler
|
||||
*/
|
||||
public RDFParser(FhirContext theContext, IParserErrorHandler theParserErrorHandler) {
|
||||
public RDFParser(final FhirContext theContext, final IParserErrorHandler theParserErrorHandler) {
|
||||
super(theContext, theParserErrorHandler);
|
||||
myContext = theContext;
|
||||
}
|
||||
|
||||
private XMLEventReader createStreamReader(Reader theReader) {
|
||||
private XMLEventReader createStreamReader(final Reader theReader) {
|
||||
try {
|
||||
return RDFUtil.createXmlReader(theReader);
|
||||
} catch (FactoryConfigurationError e1) {
|
||||
|
@ -83,14 +83,14 @@ public class RDFParser extends BaseParser /* implements IParser */ {
|
|||
}
|
||||
}
|
||||
|
||||
private XMLStreamWriter createRDFWriter(Writer theWriter) throws XMLStreamException {
|
||||
private XMLStreamWriter createRDFWriter(final Writer theWriter) throws XMLStreamException {
|
||||
XMLStreamWriter eventWriter;
|
||||
eventWriter = RDFUtil.createXmlStreamWriter(theWriter);
|
||||
eventWriter = decorateStreamWriter(eventWriter);
|
||||
return eventWriter;
|
||||
}
|
||||
|
||||
private XMLStreamWriter decorateStreamWriter(XMLStreamWriter eventWriter) {
|
||||
private XMLStreamWriter decorateStreamWriter(final XMLStreamWriter eventWriter) {
|
||||
if (myPrettyPrint) {
|
||||
return new PrettyPrintWriterWrapper(eventWriter);
|
||||
}
|
||||
|
@ -98,7 +98,9 @@ public class RDFParser extends BaseParser /* implements IParser */ {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doEncodeResourceToWriter(IBaseResource theResource, Writer theWriter, EncodeContext theEncodeContext) throws DataFormatException {
|
||||
public void doEncodeResourceToWriter(final IBaseResource theResource,
|
||||
final Writer theWriter,
|
||||
final EncodeContext theEncodeContext) throws DataFormatException {
|
||||
XMLStreamWriter eventWriter;
|
||||
try {
|
||||
eventWriter = createRDFWriter(theWriter);
|
||||
|
@ -111,12 +113,12 @@ public class RDFParser extends BaseParser /* implements IParser */ {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T extends IBaseResource> T doParseResource(Class<T> theResourceType, Reader theReader) {
|
||||
public <T extends IBaseResource> T doParseResource(final Class<T> theResourceType, final Reader theReader) {
|
||||
XMLEventReader streamReader = createStreamReader(theReader);
|
||||
return parseResource(theResourceType, streamReader);
|
||||
}
|
||||
|
||||
private <T> T doRDFLoop(XMLEventReader streamReader, ParserState<T> parserState) {
|
||||
private <T> T doRDFLoop(final XMLEventReader streamReader, final ParserState<T> parserState) {
|
||||
ourLog.trace("Entering RDF parsing loop with state: {}", parserState);
|
||||
|
||||
try {
|
||||
|
@ -209,8 +211,17 @@ public class RDFParser extends BaseParser /* implements IParser */ {
|
|||
}
|
||||
}
|
||||
|
||||
private void encodeChildElementToStreamWriter(IBaseResource theResource, XMLStreamWriter theEventWriter, BaseRuntimeChildDefinition theChildDefinition, IBase theElement, String theChildName, BaseRuntimeElementDefinition<?> childDef,
|
||||
String theExtensionUrl, boolean theIncludedResource, CompositeChildElement theParent, EncodeContext theEncodeContext) throws XMLStreamException, DataFormatException {
|
||||
private void encodeChildElementToStreamWriter(final IBaseResource theResource,
|
||||
final XMLStreamWriter theEventWriter,
|
||||
final BaseRuntimeChildDefinition theChildDefinition,
|
||||
final IBase theElement,
|
||||
final String theChildName,
|
||||
final BaseRuntimeElementDefinition<?> childDef,
|
||||
final String theExtensionUrl,
|
||||
final boolean theIncludedResource,
|
||||
final CompositeChildElement theParent,
|
||||
final EncodeContext theEncodeContext)
|
||||
throws XMLStreamException, DataFormatException {
|
||||
|
||||
/*
|
||||
* Often the two values below will be the same thing. There are cases though
|
||||
|
@ -336,7 +347,12 @@ public class RDFParser extends BaseParser /* implements IParser */ {
|
|||
|
||||
}
|
||||
|
||||
private void encodeCompositeElementToStreamWriter(IBaseResource theResource, IBase theElement, XMLStreamWriter theEventWriter, boolean theContainedResource, CompositeChildElement theParent, EncodeContext theEncodeContext)
|
||||
private void encodeCompositeElementToStreamWriter(final IBaseResource theResource,
|
||||
final IBase theElement,
|
||||
final XMLStreamWriter theEventWriter,
|
||||
final boolean theContainedResource,
|
||||
final CompositeChildElement theParent,
|
||||
final EncodeContext theEncodeContext)
|
||||
throws XMLStreamException, DataFormatException {
|
||||
|
||||
for (CompositeChildElement nextChildElem : super.compositeChildIterator(theElement, theContainedResource, theParent, theEncodeContext)) {
|
||||
|
@ -369,13 +385,18 @@ public class RDFParser extends BaseParser /* implements IParser */ {
|
|||
RuntimeChildNarrativeDefinition child = (RuntimeChildNarrativeDefinition) nextChild;
|
||||
String childName = nextChild.getChildNameByDatatype(child.getDatatype());
|
||||
BaseRuntimeElementDefinition<?> type = child.getChildByName(childName);
|
||||
encodeChildElementToStreamWriter(theResource, theEventWriter, nextChild, narr, childName, type, null, theContainedResource, nextChildElem, theEncodeContext);
|
||||
encodeChildElementToStreamWriter(theResource,
|
||||
theEventWriter, nextChild, narr, childName, type, null,
|
||||
theContainedResource, nextChildElem, theEncodeContext);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (nextChild instanceof RuntimeChildContainedResources) {
|
||||
encodeChildElementToStreamWriter(theResource, theEventWriter, nextChild, null, nextChild.getChildNameByDatatype(null), nextChild.getChildElementDefinitionByDatatype(null), null, theContainedResource, nextChildElem, theEncodeContext);
|
||||
encodeChildElementToStreamWriter(theResource, theEventWriter, nextChild, null,
|
||||
nextChild.getChildNameByDatatype(null),
|
||||
nextChild.getChildElementDefinitionByDatatype(null), null,
|
||||
theContainedResource, nextChildElem, theEncodeContext);
|
||||
} else {
|
||||
|
||||
List<? extends IBase> values = nextChild.getAccessor().getValues(theElement);
|
||||
|
@ -399,7 +420,8 @@ public class RDFParser extends BaseParser /* implements IParser */ {
|
|||
String extensionUrl = getExtensionUrl(nextChild.getExtensionUrl());
|
||||
|
||||
if (extensionUrl != null && !childName.equals("extension")) {
|
||||
encodeExtension(theResource, theEventWriter, theContainedResource, nextChildElem, nextChild, nextValue, childName, extensionUrl, childDef, theEncodeContext);
|
||||
encodeExtension(theResource, theEventWriter, theContainedResource, nextChildElem, nextChild,
|
||||
nextValue, childName, extensionUrl, childDef, theEncodeContext);
|
||||
} else if (nextChild instanceof RuntimeChildExtension) {
|
||||
IBaseExtension<?, ?> extension = (IBaseExtension<?, ?>) nextValue;
|
||||
if ((extension.getValue() == null || extension.getValue().isEmpty())) {
|
||||
|
@ -407,16 +429,28 @@ public class RDFParser extends BaseParser /* implements IParser */ {
|
|||
continue;
|
||||
}
|
||||
}
|
||||
encodeChildElementToStreamWriter(theResource, theEventWriter, nextChild, nextValue, childName, childDef, getExtensionUrl(extension.getUrl()), theContainedResource, nextChildElem, theEncodeContext);
|
||||
encodeChildElementToStreamWriter(theResource, theEventWriter, nextChild, nextValue,
|
||||
childName, childDef, getExtensionUrl(extension.getUrl()),
|
||||
theContainedResource, nextChildElem, theEncodeContext);
|
||||
} else if (!(nextChild instanceof RuntimeChildNarrativeDefinition) || !theContainedResource) {
|
||||
encodeChildElementToStreamWriter(theResource, theEventWriter, nextChild, nextValue, childName, childDef, extensionUrl, theContainedResource, nextChildElem, theEncodeContext);
|
||||
encodeChildElementToStreamWriter(theResource, theEventWriter, nextChild, nextValue,
|
||||
childName, childDef, extensionUrl, theContainedResource, nextChildElem, theEncodeContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void encodeExtension(IBaseResource theResource, XMLStreamWriter theEventWriter, boolean theContainedResource, CompositeChildElement nextChildElem, BaseRuntimeChildDefinition nextChild, IBase nextValue, String childName, String extensionUrl, BaseRuntimeElementDefinition<?> childDef, EncodeContext theEncodeContext)
|
||||
private void encodeExtension(final IBaseResource theResource,
|
||||
final XMLStreamWriter theEventWriter,
|
||||
final boolean theContainedResource,
|
||||
final CompositeChildElement nextChildElem,
|
||||
final BaseRuntimeChildDefinition nextChild,
|
||||
final IBase nextValue,
|
||||
final String childName,
|
||||
final String extensionUrl,
|
||||
final BaseRuntimeElementDefinition<?> childDef,
|
||||
final EncodeContext theEncodeContext)
|
||||
throws XMLStreamException {
|
||||
BaseRuntimeDeclaredChildDefinition extDef = (BaseRuntimeDeclaredChildDefinition) nextChild;
|
||||
if (extDef.isModifier()) {
|
||||
|
@ -431,11 +465,17 @@ public class RDFParser extends BaseParser /* implements IParser */ {
|
|||
}
|
||||
|
||||
theEventWriter.writeAttribute("url", extensionUrl);
|
||||
encodeChildElementToStreamWriter(theResource, theEventWriter, nextChild, nextValue, childName, childDef, null, theContainedResource, nextChildElem, theEncodeContext);
|
||||
encodeChildElementToStreamWriter(theResource, theEventWriter, nextChild, nextValue, childName,
|
||||
childDef, null, theContainedResource, nextChildElem, theEncodeContext);
|
||||
theEventWriter.writeEndElement();
|
||||
}
|
||||
|
||||
private void encodeExtensionsIfPresent(IBaseResource theResource, XMLStreamWriter theWriter, IBase theElement, boolean theIncludedResource, EncodeContext theEncodeContext) throws XMLStreamException, DataFormatException {
|
||||
private void encodeExtensionsIfPresent(final IBaseResource theResource,
|
||||
final XMLStreamWriter theWriter,
|
||||
final IBase theElement,
|
||||
final boolean theIncludedResource,
|
||||
final EncodeContext theEncodeContext)
|
||||
throws XMLStreamException, DataFormatException {
|
||||
if (theElement instanceof ISupportsUndeclaredExtensions) {
|
||||
ISupportsUndeclaredExtensions res = (ISupportsUndeclaredExtensions) theElement;
|
||||
encodeUndeclaredExtensions(theResource, theWriter, toBaseExtensionList(res.getUndeclaredExtensions()), "extension", theIncludedResource, theEncodeContext);
|
||||
|
@ -451,7 +491,11 @@ public class RDFParser extends BaseParser /* implements IParser */ {
|
|||
}
|
||||
}
|
||||
|
||||
private void encodeResourceToRDFStreamWriter(IBaseResource theResource, XMLStreamWriter theEventWriter, boolean theIncludedResource, EncodeContext theEncodeContext) throws XMLStreamException, DataFormatException {
|
||||
private void encodeResourceToRDFStreamWriter(final IBaseResource theResource,
|
||||
final XMLStreamWriter theEventWriter,
|
||||
final boolean theIncludedResource,
|
||||
final EncodeContext theEncodeContext)
|
||||
throws XMLStreamException, DataFormatException {
|
||||
IIdType resourceId = null;
|
||||
|
||||
if (StringUtils.isNotBlank(theResource.getIdElement().getIdPart())) {
|
||||
|
@ -472,7 +516,11 @@ public class RDFParser extends BaseParser /* implements IParser */ {
|
|||
encodeResourceToRDFStreamWriter(theResource, theEventWriter, theIncludedResource, resourceId, theEncodeContext);
|
||||
}
|
||||
|
||||
private void encodeResourceToRDFStreamWriter(IBaseResource theResource, XMLStreamWriter theEventWriter, boolean theContainedResource, IIdType theResourceId, EncodeContext theEncodeContext) throws XMLStreamException {
|
||||
private void encodeResourceToRDFStreamWriter(final IBaseResource theResource,
|
||||
final XMLStreamWriter theEventWriter,
|
||||
final boolean theContainedResource,
|
||||
final IIdType theResourceId,
|
||||
final EncodeContext theEncodeContext) throws XMLStreamException {
|
||||
RuntimeResourceDefinition resDef = myContext.getResourceDefinition(theResource);
|
||||
if (resDef == null) {
|
||||
throw new ConfigurationException("Unknown resource type: " + theResource.getClass());
|
||||
|
@ -575,7 +623,12 @@ public class RDFParser extends BaseParser /* implements IParser */ {
|
|||
theEventWriter.writeEndElement();
|
||||
}
|
||||
|
||||
private void encodeUndeclaredExtensions(IBaseResource theResource, XMLStreamWriter theEventWriter, List<? extends IBaseExtension<?, ?>> theExtensions, String tagName, boolean theIncludedResource, EncodeContext theEncodeContext)
|
||||
private void encodeUndeclaredExtensions(final IBaseResource theResource,
|
||||
final XMLStreamWriter theEventWriter,
|
||||
final List<? extends IBaseExtension<?, ?>> theExtensions,
|
||||
final String tagName,
|
||||
final boolean theIncludedResource,
|
||||
final EncodeContext theEncodeContext)
|
||||
throws XMLStreamException, DataFormatException {
|
||||
for (IBaseExtension<?, ?> next : theExtensions) {
|
||||
if (next == null || (ElementUtil.isEmpty(next.getValue()) && next.getExtension().isEmpty())) {
|
||||
|
@ -611,7 +664,8 @@ public class RDFParser extends BaseParser /* implements IParser */ {
|
|||
throw new ConfigurationException("Unable to encode extension, unrecognized child element type: " + value.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
encodeChildElementToStreamWriter(theResource, theEventWriter, extDef, value, childName, childDef, null, theIncludedResource, null, theEncodeContext);
|
||||
encodeChildElementToStreamWriter(theResource, theEventWriter, extDef, value, childName,
|
||||
childDef, null, theIncludedResource, null, theEncodeContext);
|
||||
}
|
||||
|
||||
// child extensions
|
||||
|
@ -624,7 +678,7 @@ public class RDFParser extends BaseParser /* implements IParser */ {
|
|||
}
|
||||
}
|
||||
|
||||
private void encodeXhtml(XhtmlDt theDt, XMLStreamWriter theEventWriter) throws XMLStreamException {
|
||||
private void encodeXhtml(final XhtmlDt theDt, final XMLStreamWriter theEventWriter) throws XMLStreamException {
|
||||
if (theDt == null || theDt.getValue() == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -721,16 +775,18 @@ public class RDFParser extends BaseParser /* implements IParser */ {
|
|||
|
||||
@Override
|
||||
public EncodingEnum getEncoding() {
|
||||
return EncodingEnum.XML;
|
||||
return EncodingEnum.RDF;
|
||||
}
|
||||
|
||||
private <T extends IBaseResource> T parseResource(Class<T> theResourceType, XMLEventReader theStreamReader) {
|
||||
ParserState<T> parserState = ParserState.getPreResourceInstance(this, theResourceType, myContext, false, getErrorHandler());
|
||||
private <T extends IBaseResource> T parseResource(final Class<T> theResourceType,
|
||||
final XMLEventReader theStreamReader) {
|
||||
ParserState<T> parserState = ParserState.getPreResourceInstance(this, theResourceType,
|
||||
myContext, false, getErrorHandler());
|
||||
return doRDFLoop(theStreamReader, parserState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IParser setPrettyPrint(boolean thePrettyPrint) {
|
||||
public IParser setPrettyPrint(final boolean thePrettyPrint) {
|
||||
myPrettyPrint = thePrettyPrint;
|
||||
return this;
|
||||
}
|
||||
|
@ -746,7 +802,7 @@ public class RDFParser extends BaseParser /* implements IParser */ {
|
|||
return retVal;
|
||||
}
|
||||
|
||||
private void writeCommentsPost(XMLStreamWriter theEventWriter, IBase theElement) throws XMLStreamException {
|
||||
private void writeCommentsPost(final XMLStreamWriter theEventWriter, final IBase theElement) throws XMLStreamException {
|
||||
if (theElement != null && theElement.hasFormatComment()) {
|
||||
for (String next : theElement.getFormatCommentsPost()) {
|
||||
if (isNotBlank(next)) {
|
||||
|
@ -756,7 +812,7 @@ public class RDFParser extends BaseParser /* implements IParser */ {
|
|||
}
|
||||
}
|
||||
|
||||
private void writeCommentsPre(XMLStreamWriter theEventWriter, IBase theElement) throws XMLStreamException {
|
||||
private void writeCommentsPre(final XMLStreamWriter theEventWriter, final IBase theElement) throws XMLStreamException {
|
||||
if (theElement != null && theElement.hasFormatComment()) {
|
||||
for (String next : theElement.getFormatCommentsPre()) {
|
||||
if (isNotBlank(next)) {
|
||||
|
@ -766,7 +822,8 @@ public class RDFParser extends BaseParser /* implements IParser */ {
|
|||
}
|
||||
}
|
||||
|
||||
private void writeOptionalTagWithValue(XMLStreamWriter theEventWriter, String theName, String theValue) throws XMLStreamException {
|
||||
private void writeOptionalTagWithValue(final XMLStreamWriter theEventWriter, final String theName, final String theValue)
|
||||
throws XMLStreamException {
|
||||
if (StringUtils.isNotBlank(theValue)) {
|
||||
theEventWriter.writeStartElement(theName);
|
||||
theEventWriter.writeAttribute("value", theValue);
|
||||
|
|
|
@ -42,6 +42,7 @@ public class Constants {
|
|||
*/
|
||||
public static final Set<String> CORS_ALLWED_METHODS;
|
||||
public static final String CT_FHIR_JSON = "application/json+fhir";
|
||||
public static final String CT_FHIR_RDF = "application/x-turtle";
|
||||
/**
|
||||
* The FHIR MimeType for JSON encoding in FHIR DSTU3+
|
||||
*/
|
||||
|
@ -70,6 +71,9 @@ public class Constants {
|
|||
public static final String FORMAT_HTML = "html";
|
||||
public static final String FORMAT_JSON = "json";
|
||||
public static final String FORMAT_XML = "xml";
|
||||
public static final String FORMAT_RDF = "text/turtle";
|
||||
|
||||
|
||||
/**
|
||||
* "text/html" and "html"
|
||||
*/
|
||||
|
|
|
@ -42,16 +42,31 @@ public enum EncodingEnum {
|
|||
public IParser newParser(FhirContext theContext) {
|
||||
return theContext.newXmlParser();
|
||||
}
|
||||
},
|
||||
|
||||
RDF(Constants.CT_FHIR_RDF, Constants.CT_FHIR_RDF, Constants.FORMAT_RDF) {
|
||||
@Override
|
||||
public IParser newParser(FhirContext theContext) {
|
||||
return theContext.newRDFParser();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* "json"
|
||||
*/
|
||||
public static final String JSON_PLAIN_STRING = "json";
|
||||
|
||||
/**
|
||||
* "xml"
|
||||
*/
|
||||
public static final String XML_PLAIN_STRING = "xml";
|
||||
|
||||
/**
|
||||
* "ttl"
|
||||
*/
|
||||
public static final String TTL_PLAIN_STRING = "ttl";
|
||||
|
||||
|
||||
private static Map<String, EncodingEnum> ourContentTypeToEncoding;
|
||||
private static Map<String, EncodingEnum> ourContentTypeToEncodingLegacy;
|
||||
private static Map<String, EncodingEnum> ourContentTypeToEncodingStrict;
|
||||
|
@ -127,9 +142,9 @@ public enum EncodingEnum {
|
|||
return myResourceContentTypeNonLegacy;
|
||||
}
|
||||
|
||||
public abstract IParser newParser(FhirContext theContext);
|
||||
public abstract IParser newParser(final FhirContext theContext);
|
||||
|
||||
public static EncodingEnum detectEncoding(String theBody) {
|
||||
public static EncodingEnum detectEncoding(final String theBody) {
|
||||
EncodingEnum retVal = detectEncodingNoDefault(theBody);
|
||||
retVal = ObjectUtils.defaultIfNull(retVal, EncodingEnum.XML);
|
||||
return retVal;
|
||||
|
@ -158,7 +173,7 @@ public enum EncodingEnum {
|
|||
* even if the "+fhir" part is missing from the expected content type.
|
||||
* </p>
|
||||
*/
|
||||
public static EncodingEnum forContentType(String theContentType) {
|
||||
public static EncodingEnum forContentType(final String theContentType) {
|
||||
String contentTypeSplitted = getTypeWithoutCharset(theContentType);
|
||||
if (contentTypeSplitted == null) {
|
||||
return null;
|
||||
|
@ -177,7 +192,7 @@ public enum EncodingEnum {
|
|||
*
|
||||
* @see #forContentType(String)
|
||||
*/
|
||||
public static EncodingEnum forContentTypeStrict(String theContentType) {
|
||||
public static EncodingEnum forContentTypeStrict(final String theContentType) {
|
||||
String contentTypeSplitted = getTypeWithoutCharset(theContentType);
|
||||
if (contentTypeSplitted == null) {
|
||||
return null;
|
||||
|
@ -186,7 +201,7 @@ public enum EncodingEnum {
|
|||
}
|
||||
}
|
||||
|
||||
private static String getTypeWithoutCharset(String theContentType) {
|
||||
private static String getTypeWithoutCharset(final String theContentType) {
|
||||
if (theContentType == null) {
|
||||
return null;
|
||||
} else {
|
||||
|
@ -198,7 +213,7 @@ public enum EncodingEnum {
|
|||
/**
|
||||
* Is the given type a FHIR legacy (pre-DSTU3) content type?
|
||||
*/
|
||||
public static boolean isLegacy(String theContentType) {
|
||||
public static boolean isLegacy(final String theContentType) {
|
||||
String contentTypeSplitted = getTypeWithoutCharset(theContentType);
|
||||
if (contentTypeSplitted == null) {
|
||||
return false;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue