Loading histream-export/src/main/java/de/sekmi/histream/export/NoOpStreamWriter.java 0 → 100644 +139 −0 Original line number Original line Diff line number Diff line package de.sekmi.histream.export; import javax.xml.namespace.NamespaceContext; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; public class NoOpStreamWriter implements XMLStreamWriter { public static NoOpStreamWriter INSTANCE = new NoOpStreamWriter(); @Override public void writeStartElement(String localName) throws XMLStreamException {} @Override public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {} @Override public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException { } @Override public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException { } @Override public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException { } @Override public void writeEmptyElement(String localName) throws XMLStreamException { } @Override public void writeEndElement() throws XMLStreamException { } @Override public void writeEndDocument() throws XMLStreamException { } @Override public void close() throws XMLStreamException { } @Override public void flush() throws XMLStreamException { } @Override public void writeAttribute(String localName, String value) throws XMLStreamException { } @Override public void writeAttribute(String prefix, String namespaceURI, String localName, String value) throws XMLStreamException { } @Override public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException { } @Override public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException { } @Override public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException { } @Override public void writeComment(String data) throws XMLStreamException { } @Override public void writeProcessingInstruction(String target) throws XMLStreamException { } @Override public void writeProcessingInstruction(String target, String data) throws XMLStreamException { } @Override public void writeCData(String data) throws XMLStreamException { } @Override public void writeDTD(String dtd) throws XMLStreamException { } @Override public void writeEntityRef(String name) throws XMLStreamException { } @Override public void writeStartDocument() throws XMLStreamException { } @Override public void writeStartDocument(String version) throws XMLStreamException { } @Override public void writeStartDocument(String encoding, String version) throws XMLStreamException { } @Override public void writeCharacters(String text) throws XMLStreamException { } @Override public void writeCharacters(char[] text, int start, int len) throws XMLStreamException { } @Override public String getPrefix(String uri) throws XMLStreamException { return null; } @Override public void setPrefix(String prefix, String uri) throws XMLStreamException { } @Override public void setDefaultNamespace(String uri) throws XMLStreamException { } @Override public void setNamespaceContext(NamespaceContext context) throws XMLStreamException { } @Override public NamespaceContext getNamespaceContext() { return null; } @Override public Object getProperty(String name) throws IllegalArgumentException { return null; } } histream-export/src/main/java/de/sekmi/histream/export/VisitFragmentParser.java +18 −4 Original line number Original line Diff line number Diff line package de.sekmi.histream.export; package de.sekmi.histream.export; import java.util.Objects; import java.util.Objects; import java.util.logging.Logger; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory; Loading @@ -21,6 +22,7 @@ import de.sekmi.histream.ext.Visit; import de.sekmi.histream.io.GroupedXMLWriter; import de.sekmi.histream.io.GroupedXMLWriter; abstract class VisitFragmentParser extends GroupedXMLWriter { abstract class VisitFragmentParser extends GroupedXMLWriter { // private static final Logger log = Logger.getLogger(VisitFragmentParser.class.getName()); private XMLOutputFactory factory; private XMLOutputFactory factory; private Document doc; private Document doc; private DocumentFragment currentPatient; private DocumentFragment currentPatient; Loading @@ -28,15 +30,16 @@ abstract class VisitFragmentParser extends GroupedXMLWriter { private boolean firstVisit; private boolean firstVisit; protected VisitFragmentParser() throws XMLStreamException, ParserConfigurationException { protected VisitFragmentParser() throws XMLStreamException, ParserConfigurationException { super(); this(XMLOutputFactory.newInstance()); } protected VisitFragmentParser(XMLOutputFactory factory) throws XMLStreamException, ParserConfigurationException{ setFormatted(false); setFormatted(false); factory = XMLOutputFactory.newFactory(); this.factory = factory; factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE); factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE); createDocument(); createDocument(); // write meta data to document node // write meta data to document node setDOMWriter(doc); setDOMWriter(doc); } } private void fixNamespaces(DocumentFragment fragment){ private void fixNamespaces(DocumentFragment fragment){ //fragment.setPrefix(null); //fragment.setPrefix(null); // cannot do this // cannot do this Loading @@ -59,6 +62,7 @@ abstract class VisitFragmentParser extends GroupedXMLWriter { f.setIgnoringElementContentWhitespace(true); f.setIgnoringElementContentWhitespace(true); f.setNamespaceAware(true); f.setNamespaceAware(true); DocumentBuilder builder = f.newDocumentBuilder(); DocumentBuilder builder = f.newDocumentBuilder(); // log.info("Using document builder "+builder.getClass().getName()+", version="+builder.getClass().getPackage().getImplementationVersion()); doc = builder.newDocument(); doc = builder.newDocument(); doc.getDomConfig().setParameter("namespaces", true); doc.getDomConfig().setParameter("namespaces", true); doc.getDomConfig().setParameter("namespace-declarations", true); doc.getDomConfig().setParameter("namespace-declarations", true); Loading @@ -68,6 +72,9 @@ abstract class VisitFragmentParser extends GroupedXMLWriter { @Override @Override protected void endPatient(Patient patient) throws ObservationException { protected void endPatient(Patient patient) throws ObservationException { // super class will close the patient element, which we already closed // use a dummy stream writer, which does nothing this.writer=NoOpStreamWriter.INSTANCE; super.endPatient(patient); super.endPatient(patient); if( firstVisit == true ){ if( firstVisit == true ){ // patient fragment already processed // patient fragment already processed Loading Loading @@ -95,8 +102,15 @@ abstract class VisitFragmentParser extends GroupedXMLWriter { @Override @Override protected void beginEncounter(Visit visit) throws ObservationException { protected void beginEncounter(Visit visit) throws ObservationException { if( firstVisit == false ){ if( firstVisit == false ){ // this is the first encounter of a patient // patient fragment was parsed // patient fragment was parsed fixNamespaces(currentPatient); fixNamespaces(currentPatient); // close patient element try { writer.writeEndElement(); } catch (XMLStreamException e) { throw new ObservationException(e); } patientFragment((Element)currentPatient.getFirstChild()); patientFragment((Element)currentPatient.getFirstChild()); firstVisit = true; firstVisit = true; } } Loading Loading
histream-export/src/main/java/de/sekmi/histream/export/NoOpStreamWriter.java 0 → 100644 +139 −0 Original line number Original line Diff line number Diff line package de.sekmi.histream.export; import javax.xml.namespace.NamespaceContext; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; public class NoOpStreamWriter implements XMLStreamWriter { public static NoOpStreamWriter INSTANCE = new NoOpStreamWriter(); @Override public void writeStartElement(String localName) throws XMLStreamException {} @Override public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {} @Override public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException { } @Override public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException { } @Override public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException { } @Override public void writeEmptyElement(String localName) throws XMLStreamException { } @Override public void writeEndElement() throws XMLStreamException { } @Override public void writeEndDocument() throws XMLStreamException { } @Override public void close() throws XMLStreamException { } @Override public void flush() throws XMLStreamException { } @Override public void writeAttribute(String localName, String value) throws XMLStreamException { } @Override public void writeAttribute(String prefix, String namespaceURI, String localName, String value) throws XMLStreamException { } @Override public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException { } @Override public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException { } @Override public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException { } @Override public void writeComment(String data) throws XMLStreamException { } @Override public void writeProcessingInstruction(String target) throws XMLStreamException { } @Override public void writeProcessingInstruction(String target, String data) throws XMLStreamException { } @Override public void writeCData(String data) throws XMLStreamException { } @Override public void writeDTD(String dtd) throws XMLStreamException { } @Override public void writeEntityRef(String name) throws XMLStreamException { } @Override public void writeStartDocument() throws XMLStreamException { } @Override public void writeStartDocument(String version) throws XMLStreamException { } @Override public void writeStartDocument(String encoding, String version) throws XMLStreamException { } @Override public void writeCharacters(String text) throws XMLStreamException { } @Override public void writeCharacters(char[] text, int start, int len) throws XMLStreamException { } @Override public String getPrefix(String uri) throws XMLStreamException { return null; } @Override public void setPrefix(String prefix, String uri) throws XMLStreamException { } @Override public void setDefaultNamespace(String uri) throws XMLStreamException { } @Override public void setNamespaceContext(NamespaceContext context) throws XMLStreamException { } @Override public NamespaceContext getNamespaceContext() { return null; } @Override public Object getProperty(String name) throws IllegalArgumentException { return null; } }
histream-export/src/main/java/de/sekmi/histream/export/VisitFragmentParser.java +18 −4 Original line number Original line Diff line number Diff line package de.sekmi.histream.export; package de.sekmi.histream.export; import java.util.Objects; import java.util.Objects; import java.util.logging.Logger; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory; Loading @@ -21,6 +22,7 @@ import de.sekmi.histream.ext.Visit; import de.sekmi.histream.io.GroupedXMLWriter; import de.sekmi.histream.io.GroupedXMLWriter; abstract class VisitFragmentParser extends GroupedXMLWriter { abstract class VisitFragmentParser extends GroupedXMLWriter { // private static final Logger log = Logger.getLogger(VisitFragmentParser.class.getName()); private XMLOutputFactory factory; private XMLOutputFactory factory; private Document doc; private Document doc; private DocumentFragment currentPatient; private DocumentFragment currentPatient; Loading @@ -28,15 +30,16 @@ abstract class VisitFragmentParser extends GroupedXMLWriter { private boolean firstVisit; private boolean firstVisit; protected VisitFragmentParser() throws XMLStreamException, ParserConfigurationException { protected VisitFragmentParser() throws XMLStreamException, ParserConfigurationException { super(); this(XMLOutputFactory.newInstance()); } protected VisitFragmentParser(XMLOutputFactory factory) throws XMLStreamException, ParserConfigurationException{ setFormatted(false); setFormatted(false); factory = XMLOutputFactory.newFactory(); this.factory = factory; factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE); factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE); createDocument(); createDocument(); // write meta data to document node // write meta data to document node setDOMWriter(doc); setDOMWriter(doc); } } private void fixNamespaces(DocumentFragment fragment){ private void fixNamespaces(DocumentFragment fragment){ //fragment.setPrefix(null); //fragment.setPrefix(null); // cannot do this // cannot do this Loading @@ -59,6 +62,7 @@ abstract class VisitFragmentParser extends GroupedXMLWriter { f.setIgnoringElementContentWhitespace(true); f.setIgnoringElementContentWhitespace(true); f.setNamespaceAware(true); f.setNamespaceAware(true); DocumentBuilder builder = f.newDocumentBuilder(); DocumentBuilder builder = f.newDocumentBuilder(); // log.info("Using document builder "+builder.getClass().getName()+", version="+builder.getClass().getPackage().getImplementationVersion()); doc = builder.newDocument(); doc = builder.newDocument(); doc.getDomConfig().setParameter("namespaces", true); doc.getDomConfig().setParameter("namespaces", true); doc.getDomConfig().setParameter("namespace-declarations", true); doc.getDomConfig().setParameter("namespace-declarations", true); Loading @@ -68,6 +72,9 @@ abstract class VisitFragmentParser extends GroupedXMLWriter { @Override @Override protected void endPatient(Patient patient) throws ObservationException { protected void endPatient(Patient patient) throws ObservationException { // super class will close the patient element, which we already closed // use a dummy stream writer, which does nothing this.writer=NoOpStreamWriter.INSTANCE; super.endPatient(patient); super.endPatient(patient); if( firstVisit == true ){ if( firstVisit == true ){ // patient fragment already processed // patient fragment already processed Loading Loading @@ -95,8 +102,15 @@ abstract class VisitFragmentParser extends GroupedXMLWriter { @Override @Override protected void beginEncounter(Visit visit) throws ObservationException { protected void beginEncounter(Visit visit) throws ObservationException { if( firstVisit == false ){ if( firstVisit == false ){ // this is the first encounter of a patient // patient fragment was parsed // patient fragment was parsed fixNamespaces(currentPatient); fixNamespaces(currentPatient); // close patient element try { writer.writeEndElement(); } catch (XMLStreamException e) { throw new ObservationException(e); } patientFragment((Element)currentPatient.getFirstChild()); patientFragment((Element)currentPatient.getFirstChild()); firstVisit = true; firstVisit = true; } } Loading