Atom parsing now works!
This commit is contained in:
parent
14b795ad68
commit
42d8037a06
|
@ -140,6 +140,9 @@ public abstract class BaseRuntimeDeclaredChildDefinition extends BaseRuntimeChil
|
|||
private final Method myMutator;
|
||||
|
||||
private PlainMutator(Class<?> theTargetReturnType, Method theMutator) {
|
||||
assert theTargetReturnType != null;
|
||||
assert theMutator != null;
|
||||
|
||||
myTargetReturnType = theTargetReturnType;
|
||||
myMutator = theMutator;
|
||||
}
|
||||
|
|
|
@ -36,10 +36,10 @@ import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
|||
import ca.uhn.fhir.model.api.annotation.Extension;
|
||||
import ca.uhn.fhir.model.api.annotation.Narrative;
|
||||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||
import ca.uhn.fhir.model.dstu.composite.NarrativeDt;
|
||||
import ca.uhn.fhir.model.primitive.CodeDt;
|
||||
import ca.uhn.fhir.model.primitive.DateDt;
|
||||
import ca.uhn.fhir.model.primitive.ICodedDatatype;
|
||||
import ca.uhn.fhir.model.primitive.NarrativeDt;
|
||||
import ca.uhn.fhir.model.primitive.XhtmlDt;
|
||||
|
||||
class ModelScanner {
|
||||
|
|
|
@ -2,7 +2,7 @@ package ca.uhn.fhir.context;
|
|||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import ca.uhn.fhir.model.primitive.NarrativeDt;
|
||||
import ca.uhn.fhir.model.dstu.composite.NarrativeDt;
|
||||
|
||||
public class RuntimeChildNarrativeDefinition extends BaseRuntimeChildDatatypeDefinition {
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package ca.uhn.fhir.model.api;
|
||||
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
|
||||
public class BaseBundle {
|
||||
|
||||
private StringDt myAuthorName;
|
||||
private StringDt myAuthorUri;
|
||||
|
||||
public StringDt getAuthorName() {
|
||||
if (myAuthorName == null) {
|
||||
myAuthorName = new StringDt();
|
||||
}
|
||||
return myAuthorName;
|
||||
}
|
||||
|
||||
public StringDt getAuthorUri() {
|
||||
if (myAuthorUri == null) {
|
||||
myAuthorUri = new StringDt();
|
||||
}
|
||||
return myAuthorUri;
|
||||
}
|
||||
|
||||
}
|
|
@ -7,10 +7,8 @@ import ca.uhn.fhir.model.primitive.InstantDt;
|
|||
import ca.uhn.fhir.model.primitive.IntegerDt;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
|
||||
public class Bundle implements IElement {
|
||||
public class Bundle extends BaseBundle implements IElement {
|
||||
|
||||
private StringDt myAuthorUri;
|
||||
private StringDt myAuthorName;
|
||||
private List<BundleEntry> myEntries;
|
||||
private StringDt myId;
|
||||
private StringDt myLinkBase;
|
||||
|
@ -24,20 +22,6 @@ public class Bundle implements IElement {
|
|||
private IntegerDt myTotalResults;
|
||||
private InstantDt myUpdated;
|
||||
|
||||
public StringDt getAuthorUri() {
|
||||
if (myAuthorUri == null) {
|
||||
myAuthorUri = new StringDt();
|
||||
}
|
||||
return myAuthorUri;
|
||||
}
|
||||
|
||||
public StringDt getAuthorName() {
|
||||
if (myAuthorName == null) {
|
||||
myAuthorName = new StringDt();
|
||||
}
|
||||
return myAuthorName;
|
||||
}
|
||||
|
||||
public List<BundleEntry> getEntries() {
|
||||
if (myEntries == null) {
|
||||
myEntries = new ArrayList<BundleEntry>();
|
||||
|
|
|
@ -1,70 +1,73 @@
|
|||
package ca.uhn.fhir.model.api;
|
||||
|
||||
import java.util.Date;
|
||||
import ca.uhn.fhir.model.primitive.InstantDt;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.model.primitive.XhtmlDt;
|
||||
|
||||
public class BundleEntry {
|
||||
private String myTitle;
|
||||
private String myId;
|
||||
private Date myUpdated;
|
||||
private Date myPublished;
|
||||
private String myAuthorName;
|
||||
private String myAuthorUri;
|
||||
public class BundleEntry extends BaseBundle {
|
||||
private StringDt myId;
|
||||
private StringDt myLinkSelf;
|
||||
private InstantDt myPublished;
|
||||
private IResource myResource;
|
||||
private StringDt myTitle;
|
||||
private InstantDt myUpdated;
|
||||
private XhtmlDt mySummary;
|
||||
|
||||
public String getTitle() {
|
||||
return myTitle;
|
||||
}
|
||||
|
||||
public void setTitle(String theTitle) {
|
||||
myTitle = theTitle;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
public StringDt getId() {
|
||||
if (myId == null) {
|
||||
myId = new StringDt();
|
||||
}
|
||||
return myId;
|
||||
}
|
||||
|
||||
public void setId(String theId) {
|
||||
myId = theId;
|
||||
public StringDt getLinkSelf() {
|
||||
if (myLinkSelf == null) {
|
||||
myLinkSelf = new StringDt();
|
||||
}
|
||||
return myLinkSelf;
|
||||
}
|
||||
|
||||
public Date getUpdated() {
|
||||
return myUpdated;
|
||||
}
|
||||
|
||||
public void setUpdated(Date theUpdated) {
|
||||
myUpdated = theUpdated;
|
||||
}
|
||||
|
||||
public Date getPublished() {
|
||||
public InstantDt getPublished() {
|
||||
if (myPublished == null) {
|
||||
myPublished = new InstantDt();
|
||||
}
|
||||
return myPublished;
|
||||
}
|
||||
|
||||
public void setPublished(Date thePublished) {
|
||||
myPublished = thePublished;
|
||||
}
|
||||
|
||||
public String getAuthorName() {
|
||||
return myAuthorName;
|
||||
}
|
||||
|
||||
public void setAuthorName(String theAuthorName) {
|
||||
myAuthorName = theAuthorName;
|
||||
}
|
||||
|
||||
public String getAuthorUri() {
|
||||
return myAuthorUri;
|
||||
}
|
||||
|
||||
public void setAuthorUri(String theAuthorUri) {
|
||||
myAuthorUri = theAuthorUri;
|
||||
}
|
||||
|
||||
public IResource getResource() {
|
||||
return myResource;
|
||||
}
|
||||
|
||||
public StringDt getTitle() {
|
||||
if (myTitle == null) {
|
||||
myTitle = new StringDt();
|
||||
}
|
||||
return myTitle;
|
||||
}
|
||||
|
||||
public InstantDt getUpdated() {
|
||||
if (myUpdated == null) {
|
||||
myUpdated = new InstantDt();
|
||||
}
|
||||
return myUpdated;
|
||||
}
|
||||
|
||||
public void setLinkSelf(StringDt theLinkSelf) {
|
||||
if (myLinkSelf == null) {
|
||||
myLinkSelf = new StringDt();
|
||||
}
|
||||
myLinkSelf = theLinkSelf;
|
||||
}
|
||||
|
||||
public void setResource(IResource theResource) {
|
||||
myResource = theResource;
|
||||
}
|
||||
|
||||
public XhtmlDt getSummary() {
|
||||
if (mySummary == null) {
|
||||
mySummary = new XhtmlDt();
|
||||
}
|
||||
return mySummary;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -81,6 +81,21 @@ public class ValueSet implements IResource {
|
|||
@Child(name="expansion", order=13, min=0, max=1)
|
||||
private Expansion myExpansion;
|
||||
|
||||
@Child(name="text", order=14, min=0, max=1)
|
||||
private NarrativeDt myText;
|
||||
|
||||
|
||||
public NarrativeDt getText() {
|
||||
if(myText==null) {
|
||||
myText=new NarrativeDt();
|
||||
}
|
||||
return myText;
|
||||
}
|
||||
|
||||
public void setText(NarrativeDt theText) {
|
||||
myText = theText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value(s) for <b>identifier</b> (Logical id to reference this value set).
|
||||
* creating it if it does
|
||||
|
|
|
@ -1,93 +0,0 @@
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
package ca.uhn.fhir.model.primitive;
|
||||
|
||||
import java.util.*;
|
||||
import ca.uhn.fhir.model.api.*;
|
||||
import ca.uhn.fhir.model.api.annotation.*;
|
||||
import ca.uhn.fhir.model.primitive.*;
|
||||
|
||||
/**
|
||||
* HAPI/FHIR <b>Narrative</b> Datatype
|
||||
* (A human-readable formatted text, including images)
|
||||
*
|
||||
* <p>
|
||||
* <b>Definition:</b>
|
||||
* A human-readable formatted text, including images
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* <b>Requirements:</b>
|
||||
*
|
||||
* </p>
|
||||
*/
|
||||
@DatatypeDef(name="Narrative")
|
||||
public class NarrativeDt extends BaseCompositeDatatype {
|
||||
|
||||
@Child(name="status", type=CodeDt.class, order=0, min=1, max=1)
|
||||
private CodeDt myStatus;
|
||||
|
||||
@Child(name="div", type=XhtmlDt.class, order=1, min=1, max=1)
|
||||
private XhtmlDt myDiv;
|
||||
|
||||
/**
|
||||
* Gets the value(s) for status (generated | extensions | additional)
|
||||
*
|
||||
* <p>
|
||||
* <b>Definition:</b>
|
||||
* The status of the narrative - whether it's entirely generated (from just the defined data or the extensions too), or whether a human authored it and it may contain additional data
|
||||
* </p>
|
||||
*/
|
||||
public CodeDt getStatus() {
|
||||
return myStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value(s) for status (generated | extensions | additional)
|
||||
*
|
||||
* <p>
|
||||
* <b>Definition:</b>
|
||||
* The status of the narrative - whether it's entirely generated (from just the defined data or the extensions too), or whether a human authored it and it may contain additional data
|
||||
* </p>
|
||||
*/
|
||||
public void setStatus(CodeDt theValue) {
|
||||
myStatus = theValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value(s) for div (Limited xhtml content)
|
||||
*
|
||||
* <p>
|
||||
* <b>Definition:</b>
|
||||
* The actual narrative content, a stripped down version of XHTML
|
||||
* </p>
|
||||
*/
|
||||
public XhtmlDt getDiv() {
|
||||
return myDiv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value(s) for div (Limited xhtml content)
|
||||
*
|
||||
* <p>
|
||||
* <b>Definition:</b>
|
||||
* The actual narrative content, a stripped down version of XHTML
|
||||
* </p>
|
||||
*/
|
||||
public void setDiv(XhtmlDt theValue) {
|
||||
myDiv = theValue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -44,6 +44,14 @@ public class StringDt extends BasePrimitiveDatatype<String> {
|
|||
public void setValueAsString(String theValue) throws DataFormatException {
|
||||
myValue = theValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of this string, or <code>null</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return myValue;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -11,8 +11,6 @@ import javax.xml.stream.events.XMLEvent;
|
|||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.ctc.wstx.sw.BaseStreamWriter;
|
||||
|
||||
import ca.uhn.fhir.context.BaseRuntimeChildDefinition;
|
||||
import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition;
|
||||
import ca.uhn.fhir.context.BaseRuntimeElementDefinition;
|
||||
|
@ -23,7 +21,9 @@ import ca.uhn.fhir.context.RuntimePrimitiveDatatypeNarrativeDefinition;
|
|||
import ca.uhn.fhir.context.RuntimeResourceBlockDefinition;
|
||||
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||
import ca.uhn.fhir.context.RuntimeResourceReferenceDefinition;
|
||||
import ca.uhn.fhir.model.api.BaseBundle;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.api.BundleEntry;
|
||||
import ca.uhn.fhir.model.api.ICompositeDatatype;
|
||||
import ca.uhn.fhir.model.api.ICompositeElement;
|
||||
import ca.uhn.fhir.model.api.IElement;
|
||||
|
@ -33,49 +33,26 @@ import ca.uhn.fhir.model.api.IResourceBlock;
|
|||
import ca.uhn.fhir.model.api.ISupportsUndeclaredExtensions;
|
||||
import ca.uhn.fhir.model.api.ResourceReference;
|
||||
import ca.uhn.fhir.model.api.UndeclaredExtension;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.model.primitive.XhtmlDt;
|
||||
|
||||
class ParserState<T extends IElement> {
|
||||
|
||||
public class AtomAuthorState extends BaseState {
|
||||
private static final QName ATOM_LINK_HREF_ATTRIBUTE = new QName("href");
|
||||
|
||||
private Bundle myInstance;
|
||||
|
||||
public AtomAuthorState(Bundle theInstance) {
|
||||
myInstance = theInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endingElement(EndElement theElem) throws DataFormatException {
|
||||
pop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enteringNewElement(String theNamespaceURI, String theLocalPart) throws DataFormatException {
|
||||
if ("name".equals(theLocalPart)) {
|
||||
push(new AtomPrimitiveState(myInstance.getAuthorName()));
|
||||
} else if ("uri".equals(theLocalPart)) {
|
||||
push(new AtomPrimitiveState(myInstance.getAuthorUri()));
|
||||
} else {
|
||||
throw new DataFormatException("Unexpected element: " + theLocalPart);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private static final QName ATOM_LINK_REL_ATTRIBUTE = new QName("rel");
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ParserState.class);
|
||||
|
||||
private FhirContext myContext;
|
||||
private T myObject;
|
||||
|
||||
private BaseState myState;
|
||||
|
||||
private ParserState(FhirContext theContext) {
|
||||
myContext = theContext;
|
||||
}
|
||||
|
||||
public void attributeValue(Attribute theAttribute, String theValue) throws DataFormatException {
|
||||
myState.attributeValue(theAttribute, theValue);
|
||||
public void attributeValue(String theName, String theValue) throws DataFormatException {
|
||||
myState.attributeValue(theName, theValue);
|
||||
}
|
||||
|
||||
public void endingElement(EndElement theElem) throws DataFormatException {
|
||||
|
@ -98,6 +75,23 @@ class ParserState<T extends IElement> {
|
|||
return myObject != null;
|
||||
}
|
||||
|
||||
public void string(String theData) {
|
||||
myState.string(theData);
|
||||
}
|
||||
|
||||
public boolean verifyNamespace(String theExpect, String theActual) {
|
||||
return StringUtils.equals(theExpect, theActual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked after any new XML event is individually processed, containing a
|
||||
* copy of the XML event. This is basically intended for embedded XHTML
|
||||
* content
|
||||
*/
|
||||
public void xmlEvent(XMLEvent theNextEvent) {
|
||||
myState.xmlEvent(theNextEvent);
|
||||
}
|
||||
|
||||
private void pop() {
|
||||
myState = myState.myStack;
|
||||
myState.wereBack();
|
||||
|
@ -108,24 +102,145 @@ class ParserState<T extends IElement> {
|
|||
myState = theState;
|
||||
}
|
||||
|
||||
public static ParserState<IResource> getPreResourceInstance(FhirContext theContext) throws DataFormatException {
|
||||
ParserState<IResource> retVal = new ParserState<IResource>(theContext);
|
||||
retVal.push(retVal.new PreResourceState());
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public static ParserState<Bundle> getPreAtomInstance(FhirContext theContext) throws DataFormatException {
|
||||
ParserState<Bundle> retVal = new ParserState<Bundle>(theContext);
|
||||
retVal.push(retVal.new PreAtomState());
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public static ParserState<IResource> getPreResourceInstance(FhirContext theContext) throws DataFormatException {
|
||||
ParserState<IResource> retVal = new ParserState<IResource>(theContext);
|
||||
retVal.push(retVal.new PreResourceState());
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public class AtomAuthorState extends BaseState {
|
||||
|
||||
private BaseBundle myInstance;
|
||||
|
||||
public AtomAuthorState(BaseBundle theEntry) {
|
||||
myInstance = theEntry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endingElement(EndElement theElem) throws DataFormatException {
|
||||
pop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enteringNewElement(String theNamespaceURI, String theLocalPart) throws DataFormatException {
|
||||
if ("name".equals(theLocalPart)) {
|
||||
push(new AtomPrimitiveState(myInstance.getAuthorName()));
|
||||
} else if ("uri".equals(theLocalPart)) {
|
||||
push(new AtomPrimitiveState(myInstance.getAuthorUri()));
|
||||
} else {
|
||||
throw new DataFormatException("Unexpected element: " + theLocalPart);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class AtomEntryState extends BaseState {
|
||||
|
||||
private BundleEntry myEntry;
|
||||
|
||||
public AtomEntryState(Bundle theInstance) {
|
||||
myEntry = new BundleEntry();
|
||||
theInstance.getEntries().add(myEntry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endingElement(EndElement theElem) throws DataFormatException {
|
||||
pop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enteringNewElement(String theNamespaceURI, String theLocalPart) throws DataFormatException {
|
||||
if ("title".equals(theLocalPart)) {
|
||||
push(new AtomPrimitiveState(myEntry.getTitle()));
|
||||
} else if ("id".equals(theLocalPart)) {
|
||||
push(new AtomPrimitiveState(myEntry.getId()));
|
||||
} else if ("link".equals(theLocalPart)) {
|
||||
push(new AtomLinkState(myEntry));
|
||||
} else if ("updated".equals(theLocalPart)) {
|
||||
push(new AtomPrimitiveState(myEntry.getUpdated()));
|
||||
} else if ("published".equals(theLocalPart)) {
|
||||
push(new AtomPrimitiveState(myEntry.getPublished()));
|
||||
} else if ("author".equals(theLocalPart)) {
|
||||
push(new AtomAuthorState(myEntry));
|
||||
} else if ("content".equals(theLocalPart)) {
|
||||
push(new PreResourceState(myEntry));
|
||||
} else if ("summary".equals(theLocalPart)) {
|
||||
push(new XhtmlState(myEntry.getSummary(),false));
|
||||
} else {
|
||||
throw new DataFormatException("Unexpected element in entry: " + theLocalPart);
|
||||
}
|
||||
|
||||
// TODO: handle category
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class AtomLinkState extends BaseState {
|
||||
|
||||
private BundleEntry myEntry;
|
||||
private String myHref;
|
||||
private Bundle myInstance;
|
||||
private String myRel;
|
||||
|
||||
public AtomLinkState(Bundle theInstance) {
|
||||
myInstance = theInstance;
|
||||
}
|
||||
|
||||
public AtomLinkState(BundleEntry theEntry) {
|
||||
myEntry = theEntry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attributeValue(String theName, String theValue) throws DataFormatException {
|
||||
if ("rel".equals(theName)) {
|
||||
myRel = theValue;
|
||||
} else if ("href".equals(theName)) {
|
||||
myHref = theValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endingElement(EndElement theElem) throws DataFormatException {
|
||||
if (myInstance != null) {
|
||||
if ("self".equals(myRel)) {
|
||||
myInstance.getLinkSelf().setValueAsString(myHref);
|
||||
} else if ("first".equals(myRel)) {
|
||||
myInstance.getLinkFirst().setValueAsString(myHref);
|
||||
} else if ("previous".equals(myRel)) {
|
||||
myInstance.getLinkPrevious().setValueAsString(myHref);
|
||||
} else if ("next".equals(myRel)) {
|
||||
myInstance.getLinkNext().setValueAsString(myHref);
|
||||
} else if ("last".equals(myRel)) {
|
||||
myInstance.getLinkLast().setValueAsString(myHref);
|
||||
} else if ("fhir-base".equals(myRel)) {
|
||||
myInstance.getLinkBase().setValueAsString(myHref);
|
||||
}
|
||||
} else {
|
||||
myEntry.getLinkSelf().setValueAsString(myHref);
|
||||
}
|
||||
pop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enteringNewElement(String theNamespaceURI, String theLocalPart) throws DataFormatException {
|
||||
throw new DataFormatException("Found unexpected element content");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class AtomPrimitiveState extends BaseState {
|
||||
|
||||
private IPrimitiveDatatype<?> myPrimitive;
|
||||
private String myData;
|
||||
private IPrimitiveDatatype<?> myPrimitive;
|
||||
|
||||
public AtomPrimitiveState(IPrimitiveDatatype<?> thePrimitive) {
|
||||
assert thePrimitive != null;
|
||||
myPrimitive = thePrimitive;
|
||||
}
|
||||
|
||||
|
@ -137,12 +252,7 @@ class ParserState<T extends IElement> {
|
|||
|
||||
@Override
|
||||
public void enteringNewElement(String theNamespaceURI, String theLocalPart) throws DataFormatException {
|
||||
throw new DataFormatException("Unexpected nested element in atom tag ");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IElement getCurrentElement() {
|
||||
return null;
|
||||
throw new DataFormatException("Unexpected nested element in atom tag: " + theLocalPart);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -150,62 +260,19 @@ class ParserState<T extends IElement> {
|
|||
if (myData == null) {
|
||||
myData = theData;
|
||||
} else {
|
||||
// this shouldn't generally happen so it's ok that it's inefficient
|
||||
// this shouldn't generally happen so it's ok that it's
|
||||
// inefficient
|
||||
myData = myData + theData;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class AtomLinkState extends BaseState {
|
||||
|
||||
private String myRel;
|
||||
private String myHref;
|
||||
private Bundle myInstance;
|
||||
|
||||
public AtomLinkState(Bundle theInstance) {
|
||||
myInstance = theInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attributeValue(Attribute theAttribute, String theValue) throws DataFormatException {
|
||||
String name = theAttribute.getName().getLocalPart();
|
||||
if ("rel".equals(name)) {
|
||||
myRel = theValue;
|
||||
} else if ("href".equals(name)) {
|
||||
myHref = theValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endingElement(EndElement theElem) throws DataFormatException {
|
||||
if ("self".equals(myRel)) {
|
||||
myInstance.getLinkSelf().setValueAsString(myHref);
|
||||
} else if ("first".equals(myRel)) {
|
||||
myInstance.getLinkFirst().setValueAsString(myHref);
|
||||
} else if ("previous".equals(myRel)) {
|
||||
myInstance.getLinkPrevious().setValueAsString(myHref);
|
||||
} else if ("next".equals(myRel)) {
|
||||
myInstance.getLinkNext().setValueAsString(myHref);
|
||||
} else if ("last".equals(myRel)) {
|
||||
myInstance.getLinkLast().setValueAsString(myHref);
|
||||
} else if ("fhir-base".equals(myRel)) {
|
||||
myInstance.getLinkBase().setValueAsString(myHref);
|
||||
}
|
||||
|
||||
pop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enteringNewElement(String theNamespaceURI, String theLocalPart) throws DataFormatException {
|
||||
throw new DataFormatException("Found unexpected element content");
|
||||
protected IElement getCurrentElement() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final QName ATOM_LINK_REL_ATTRIBUTE = new QName("rel");
|
||||
private static final QName ATOM_LINK_HREF_ATTRIBUTE = new QName("href");
|
||||
|
||||
private class AtomState extends BaseState {
|
||||
|
||||
private Bundle myInstance;
|
||||
|
@ -214,11 +281,7 @@ class ParserState<T extends IElement> {
|
|||
myInstance = theInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attributeValue(Attribute theAttribute, String theValue) throws DataFormatException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void endingElement(EndElement theElem) throws DataFormatException {
|
||||
|
@ -228,7 +291,7 @@ class ParserState<T extends IElement> {
|
|||
@Override
|
||||
public void enteringNewElement(String theNamespaceURI, String theLocalPart) throws DataFormatException {
|
||||
if ("entry".equals(theLocalPart) && verifyNamespace(XmlParser.ATOM_NS, theNamespaceURI)) {
|
||||
|
||||
push(new AtomEntryState(myInstance));
|
||||
} else if (theLocalPart.equals("title")) {
|
||||
push(new AtomPrimitiveState(myInstance.getTitle()));
|
||||
} else if ("id".equals(theLocalPart)) {
|
||||
|
@ -241,6 +304,8 @@ class ParserState<T extends IElement> {
|
|||
push(new AtomPrimitiveState(myInstance.getUpdated()));
|
||||
} else if ("author".equals(theLocalPart)) {
|
||||
push(new AtomAuthorState(myInstance));
|
||||
} else {
|
||||
throw new DataFormatException("Unexpected element: "+ theLocalPart);
|
||||
}
|
||||
|
||||
// TODO: handle category and DSig
|
||||
|
@ -253,51 +318,12 @@ class ParserState<T extends IElement> {
|
|||
|
||||
}
|
||||
|
||||
private class PreAtomState extends BaseState {
|
||||
|
||||
private Bundle myInstance;
|
||||
|
||||
@Override
|
||||
public void attributeValue(Attribute theAttribute, String theValue) throws DataFormatException {
|
||||
// ignore
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endingElement(EndElement theElem) throws DataFormatException {
|
||||
// ignore
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enteringNewElement(String theNamespaceURI, String theLocalPart) throws DataFormatException {
|
||||
if (!"feed".equals(theLocalPart)) {
|
||||
throw new DataFormatException("Expecting outer element called 'feed', found: " + theLocalPart);
|
||||
}
|
||||
|
||||
myInstance = new Bundle();
|
||||
push(new AtomState(myInstance));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IElement getCurrentElement() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void wereBack() {
|
||||
myObject = (T) myInstance;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private abstract class BaseState {
|
||||
|
||||
private BaseState myStack;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void attributeValue(Attribute theAttribute, String theValue) throws DataFormatException {
|
||||
public void attributeValue(String theName, String theValue) throws DataFormatException {
|
||||
// ignore by default
|
||||
}
|
||||
|
||||
|
@ -325,26 +351,26 @@ class ParserState<T extends IElement> {
|
|||
}
|
||||
}
|
||||
|
||||
protected IElement getCurrentElement() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setStack(BaseState theState) {
|
||||
myStack = theState;
|
||||
}
|
||||
|
||||
public void wereBack() {
|
||||
// allow an implementor to override
|
||||
}
|
||||
|
||||
public void string(@SuppressWarnings("unused") String theData) {
|
||||
// ignore by default
|
||||
}
|
||||
|
||||
public void wereBack() {
|
||||
// allow an implementor to override
|
||||
}
|
||||
|
||||
public void xmlEvent(@SuppressWarnings("unused") XMLEvent theNextEvent) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
protected IElement getCurrentElement() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class DeclaredExtensionState extends BaseState {
|
||||
|
@ -358,10 +384,6 @@ class ParserState<T extends IElement> {
|
|||
myParentInstance = theParentInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attributeValue(Attribute theAttribute, String theValue) throws DataFormatException {
|
||||
throw new DataFormatException("'value' attribute is invalid in 'extension' element");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endingElement(EndElement theElem) throws DataFormatException {
|
||||
|
@ -442,11 +464,6 @@ class ParserState<T extends IElement> {
|
|||
myInstance = theInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attributeValue(Attribute theAttribute, String theValue) {
|
||||
ourLog.debug("Ignoring attribute value: {}", theValue);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void endingElement(EndElement theElem) {
|
||||
|
@ -501,7 +518,7 @@ class ParserState<T extends IElement> {
|
|||
RuntimePrimitiveDatatypeNarrativeDefinition xhtmlTarget = (RuntimePrimitiveDatatypeNarrativeDefinition) target;
|
||||
XhtmlDt newDt = xhtmlTarget.newInstance();
|
||||
child.getMutator().addValue(myInstance, newDt);
|
||||
XhtmlState state = new XhtmlState(newDt);
|
||||
XhtmlState state = new XhtmlState(newDt,true);
|
||||
push(state);
|
||||
return;
|
||||
}
|
||||
|
@ -541,10 +558,6 @@ class ParserState<T extends IElement> {
|
|||
myExtension = theExtension;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attributeValue(Attribute theAttribute, String theValue) throws DataFormatException {
|
||||
throw new DataFormatException("'value' attribute is invalid in 'extension' element");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endingElement(EndElement theElem) throws DataFormatException {
|
||||
|
@ -601,20 +614,60 @@ class ParserState<T extends IElement> {
|
|||
|
||||
}
|
||||
|
||||
private class PreResourceState extends BaseState {
|
||||
private class PreAtomState extends BaseState {
|
||||
|
||||
private ICompositeElement myInstance;
|
||||
private Bundle myInstance;
|
||||
|
||||
@Override
|
||||
public void attributeValue(Attribute theAttribute, String theValue) throws DataFormatException {
|
||||
// ignore
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endingElement(EndElement theElem) throws DataFormatException {
|
||||
// ignore
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enteringNewElement(String theNamespaceURI, String theLocalPart) throws DataFormatException {
|
||||
if (!"feed".equals(theLocalPart)) {
|
||||
throw new DataFormatException("Expecting outer element called 'feed', found: " + theLocalPart);
|
||||
}
|
||||
|
||||
myInstance = new Bundle();
|
||||
push(new AtomState(myInstance));
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void wereBack() {
|
||||
myObject = (T) myInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IElement getCurrentElement() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class PreResourceState extends BaseState {
|
||||
|
||||
private IResource myInstance;
|
||||
private BundleEntry myEntry;
|
||||
|
||||
public PreResourceState() {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public PreResourceState(BundleEntry theEntry) {
|
||||
myEntry = theEntry;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void endingElement(EndElement theElem) throws DataFormatException {
|
||||
pop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enteringNewElement(String theNamespaceURI, String theLocalPart) throws DataFormatException {
|
||||
BaseRuntimeElementDefinition<?> definition = myContext.getNameToResourceDefinition().get(theLocalPart);
|
||||
|
@ -624,19 +677,24 @@ class ParserState<T extends IElement> {
|
|||
|
||||
RuntimeResourceDefinition def = (RuntimeResourceDefinition) definition;
|
||||
myInstance = def.newInstance();
|
||||
if (myEntry != null) {
|
||||
myEntry.setResource(myInstance);
|
||||
}
|
||||
|
||||
push(new ElementCompositeState(def, myInstance));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IElement getCurrentElement() {
|
||||
return myInstance;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void wereBack() {
|
||||
myObject = (T) myInstance;
|
||||
if (myEntry == null) {
|
||||
myObject = (T) myInstance;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IElement getCurrentElement() {
|
||||
return myInstance;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -650,8 +708,10 @@ class ParserState<T extends IElement> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void attributeValue(Attribute theAttribute, String theValue) throws DataFormatException {
|
||||
myInstance.setValueAsString(theValue);
|
||||
public void attributeValue(String theName, String theValue) throws DataFormatException {
|
||||
if ("value".equals(theName)) {
|
||||
myInstance.setValueAsString(theValue);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -684,7 +744,11 @@ class ParserState<T extends IElement> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void attributeValue(Attribute theAttribute, String theValue) throws DataFormatException {
|
||||
public void attributeValue(String theName, String theValue) throws DataFormatException {
|
||||
if (!"value".equals(theName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (mySubState) {
|
||||
case DISPLAY:
|
||||
myInstance.setDisplay(theValue);
|
||||
|
@ -742,26 +806,29 @@ class ParserState<T extends IElement> {
|
|||
private int myDepth;
|
||||
private XhtmlDt myDt;
|
||||
private List<XMLEvent> myEvents = new ArrayList<XMLEvent>();
|
||||
private boolean myIncludeOuterEvent;
|
||||
|
||||
private XhtmlState(XhtmlDt theXhtmlDt) throws DataFormatException {
|
||||
myDepth = 1;
|
||||
private XhtmlState(XhtmlDt theXhtmlDt, boolean theIncludeOuterEvent) throws DataFormatException {
|
||||
myDepth = 0;
|
||||
myDt = theXhtmlDt;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IElement getCurrentElement() {
|
||||
return myDt;
|
||||
myIncludeOuterEvent = theIncludeOuterEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void xmlEvent(XMLEvent theEvent) {
|
||||
myEvents.add(theEvent);
|
||||
if (theEvent.isEndElement()) {
|
||||
myDepth--;
|
||||
}
|
||||
|
||||
if (myIncludeOuterEvent || myDepth > 0) {
|
||||
myEvents.add(theEvent);
|
||||
}
|
||||
|
||||
if (theEvent.isStartElement()) {
|
||||
myDepth++;
|
||||
}
|
||||
|
||||
if (theEvent.isEndElement()) {
|
||||
myDepth--;
|
||||
if (myDepth == 0) {
|
||||
myDt.setValue(myEvents);
|
||||
pop();
|
||||
|
@ -769,21 +836,11 @@ class ParserState<T extends IElement> {
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
protected IElement getCurrentElement() {
|
||||
return myDt;
|
||||
}
|
||||
|
||||
public void string(String theData) {
|
||||
myState.string(theData);
|
||||
}
|
||||
|
||||
public boolean verifyNamespace(String theExpect, String theActual) {
|
||||
return StringUtils.equals(theExpect, theActual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked after any new XML event is individually processed, containing a copy of the XML event. This is basically intended for embedded XHTML content
|
||||
*/
|
||||
public void xmlEvent(XMLEvent theNextEvent) {
|
||||
myState.xmlEvent(theNextEvent);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
package ca.uhn.fhir.parser;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
import static org.apache.commons.lang3.StringUtils.*;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.stream.FactoryConfigurationError;
|
||||
|
@ -425,26 +423,23 @@ public class XmlParser {
|
|||
for (@SuppressWarnings("unchecked")
|
||||
Iterator<Attribute> iter = elem.getAttributes(); iter.hasNext();) {
|
||||
Attribute next = iter.next();
|
||||
if (next.getName().getLocalPart().equals("value")) {
|
||||
parserState.attributeValue(next, next.getValue());
|
||||
}
|
||||
// if (next.getName().getLocalPart().equals("value")) {
|
||||
parserState.attributeValue(next.getName().getLocalPart(), next.getValue());
|
||||
// }
|
||||
}
|
||||
|
||||
} else if (nextEvent.isAttribute()) {
|
||||
Attribute elem = (Attribute) nextEvent;
|
||||
if (!FHIR_NS.equals(elem.getName().getNamespaceURI())) {
|
||||
continue;
|
||||
}
|
||||
if (!"value".equals(elem.getName().getLocalPart())) {
|
||||
continue;
|
||||
}
|
||||
parserState.attributeValue(elem, elem.getValue());
|
||||
String name = (elem.getName().getLocalPart());
|
||||
parserState.attributeValue(name, elem.getValue());
|
||||
} else if (nextEvent.isEndElement()) {
|
||||
EndElement elem = nextEvent.asEndElement();
|
||||
|
||||
String name = elem.getName().getLocalPart();
|
||||
String namespaceURI = elem.getName().getNamespaceURI();
|
||||
if (!FHIR_NS.equals(namespaceURI) && !XHTML_NS.equals(namespaceURI)) {
|
||||
continue;
|
||||
}
|
||||
// if (!FHIR_NS.equals(namespaceURI) && !XHTML_NS.equals(namespaceURI)) {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
parserState.endingElement(elem);
|
||||
if (parserState.isComplete()) {
|
||||
|
|
|
@ -16,6 +16,7 @@ import ca.uhn.fhir.context.ConfigurationException;
|
|||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.context.ResourceWithExtensionsA;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.api.BundleEntry;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.dstu.resource.Observation;
|
||||
import ca.uhn.fhir.model.dstu.resource.ValueSet;
|
||||
|
@ -26,6 +27,12 @@ public class XmlParserTest {
|
|||
public void testParseBundle() {
|
||||
|
||||
//@formatter:off
|
||||
String summaryText =
|
||||
"<div xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
|
||||
" <p>Value set \"LOINC Codes for Cholesterol\": This is an example value set that includes \n" +
|
||||
" all the LOINC codes for serum cholesterol from v2.36. \n" +
|
||||
" Developed by: FHIR project team (example)</p></div>";
|
||||
|
||||
String msg = "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n" +
|
||||
" <title>FHIR Core Valuesets</title>\n" +
|
||||
" <id>http://hl7.org/fhir/profile/valuesets</id>\n" +
|
||||
|
@ -70,10 +77,8 @@ public class XmlParserTest {
|
|||
" </compose>\n" +
|
||||
" </ValueSet>\n" +
|
||||
" </content>\n" +
|
||||
" <summary type=\"xhtml\"><div xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
|
||||
" <p>Value set "LOINC Codes for Cholesterol": This is an example value set that includes \n" +
|
||||
" all the LOINC codes for serum cholesterol from v2.36. \n" +
|
||||
" Developed by: FHIR project team (example)</p>\n" +
|
||||
" <summary type=\"xhtml\">"+
|
||||
summaryText +
|
||||
" </summary>\n" +
|
||||
" </entry>" +
|
||||
"</feed>";
|
||||
|
@ -83,7 +88,17 @@ public class XmlParserTest {
|
|||
Bundle bundle = p.parseBundle(msg);
|
||||
|
||||
assertEquals("FHIR Core Valuesets", bundle.getTitle().getValue());
|
||||
assertEquals("http://hl7.org/implement/standards/fhir/valuesets.xml", bundle.getLinkSelf().getValue());
|
||||
assertEquals("2014-02-10T04:11:24.435+00:00", bundle.getUpdated().getValueAsString());
|
||||
assertEquals(1, bundle.getEntries().size());
|
||||
|
||||
BundleEntry entry = bundle.getEntries().get(0);
|
||||
assertEquals("HL7, Inc (FHIR Project)", entry.getAuthorName().getValue());
|
||||
assertEquals("http://hl7.org/fhir/valueset/256a5231-a2bb-49bd-9fea-f349d428b70d", entry.getId().getValue());
|
||||
|
||||
ValueSet resource = (ValueSet) entry.getResource();
|
||||
assertEquals("LOINC Codes for Cholesterol", resource.getName().getValue());
|
||||
assertEquals(summaryText.trim(), entry.getSummary().getValueAsString().trim());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue