About to try removing namespaces from parser

This commit is contained in:
jamesagnew 2014-02-27 10:20:25 -05:00
parent 00411b64f6
commit 193b181b63
1 changed files with 75 additions and 20 deletions

View File

@ -3,11 +3,14 @@ package ca.uhn.fhir.parser;
import java.util.ArrayList;
import java.util.List;
import javax.xml.namespace.QName;
import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
import com.ctc.wstx.sw.BaseStreamWriter;
import ca.uhn.fhir.context.BaseRuntimeChildDefinition;
import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition;
import ca.uhn.fhir.context.BaseRuntimeElementDefinition;
@ -138,6 +141,38 @@ class ParserState<T extends IElement> {
}
private class ExpectEndElementState extends BaseState {
@Override
public void attributeValue(Attribute theAttribute, String theValue) throws DataFormatException {
throw new DataFormatException("Found unexpected element content");
}
@Override
public void endingElement(EndElement theElem) throws DataFormatException {
pop();
}
@Override
public void enteringNewElement(StartElement theElement, String theLocalPart) throws DataFormatException {
throw new DataFormatException("Found unexpected element content");
}
@Override
protected IElement getCurrentElement() {
return null;
}
@Override
public void otherEvent(XMLEvent theEvent) throws DataFormatException {
throw new DataFormatException("Found unexpected element content");
}
}
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;
@ -164,20 +199,40 @@ class ParserState<T extends IElement> {
} else if ("id".equals(theLocalPart)) {
push(new AtomPrimitiveState(myInstance.getId()));
} else if ("link".equals(theLocalPart)) {
Attribute rel = theElement.getAttributeByName(ATOM_LINK_REL_ATTRIBUTE);
Attribute href = theElement.getAttributeByName(ATOM_LINK_HREF_ATTRIBUTE);
if (rel != null && href != null) {
if ("self".equals(rel.getValue())) {
myInstance.getLinkSelf().setValueAsString(href.getValue());
push(new ExpectEndElementState());
} else if ("first".equals(rel.getValue())) {
myInstance.getLinkFirst().setValueAsString(href.getValue());
push(new ExpectEndElementState());
} else if ("previous".equals(rel.getValue())) {
myInstance.getLinkPrevious().setValueAsString(href.getValue());
push(new ExpectEndElementState());
} else if ("next".equals(rel.getValue())) {
myInstance.getLinkNext().setValueAsString(href.getValue());
push(new ExpectEndElementState());
} else if ("last".equals(rel.getValue())) {
myInstance.getLinkLast().setValueAsString(href.getValue());
push(new ExpectEndElementState());
} else if ("fhir-base".equals(rel.getValue())) {
myInstance.getLinkBase().setValueAsString(href.getValue());
push(new ExpectEndElementState());
}
}
}
}
@Override
protected IElement getCurrentElement() {
// TODO Auto-generated method stub
return null;
return myInstance;
}
@Override
public void otherEvent(XMLEvent theEvent) throws DataFormatException {
// TODO Auto-generated method stub
// ignore
}
}