Skip to content

Commit

Permalink
enabling mzid1.2 import
Browse files Browse the repository at this point in the history
  • Loading branch information
julianu committed Jul 5, 2024
1 parent 5c6a2ec commit b19e2bb
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/main/java/de/mpc/pia/intermediate/compiler/PIACompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
Expand All @@ -21,6 +22,7 @@
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLOutputFactory;
Expand Down Expand Up @@ -135,13 +137,13 @@ public abstract class PIACompiler {
private static String nsjPiaXML = "http://www.medizinisches-proteom-center.de/PIA/piaintermediate";

/** prefixdeclaration for jPiaXML */
private static String prefixjPiaXML = "ns3";
private static String prefixjPiaXML = "pia";

/** namespace declaration for mzIdentML */
private static String nsMzIdentML = "http://psidev.info/psi/pi/mzIdentML/1.1";

/** prefix declaration for mzIdentML */
private static String prefixMzIdentML = "ns2";
private static String prefixMzIdentML = "mzid";

/** encoding specification */
private static String encoding = "UTF-8";
Expand Down Expand Up @@ -933,6 +935,26 @@ public final void writeOutXML(OutputStream outputStream) {
XMLOutputFactory xmlof = XMLOutputFactory.newInstance();
XMLStreamWriter xmlOut = new IndentingXMLStreamWriter(xmlof.createXMLStreamWriter(out));

// take care of the namespace in the PIA XML files -> basically set them fixed to PIA and mzid 1.1
xmlOut.setNamespaceContext(new NamespaceContext() {
public Iterator<String> getPrefixes(String namespaceURI) {
return null;
}

public String getPrefix(String namespaceURI) {
if (namespaceURI.equals(nsjPiaXML)) {
return prefixjPiaXML;
} else if (namespaceURI.contains("mzIdentML")) {
return prefixMzIdentML;
}
return "";
}

public String getNamespaceURI(String prefix) {
return "";
}
});

// xml header
xmlOut.writeStartDocument(encoding, "1.0");

Expand Down

0 comments on commit b19e2bb

Please sign in to comment.