use of org.jdom.Namespace in project vcell by virtualcell.
the class XMLUtils method getNamespacesWithPrefixes.
public Map<Namespace, String> getNamespacesWithPrefixes(Document doc) {
Map<Namespace, Element> n2El = getElementNamespaces(doc);
Map<Namespace, String> rc = new HashMap<Namespace, String>();
for (Namespace ns : n2El.keySet()) {
String s = null;
// ideally we use the existing prefix in the model element
if (ns.getPrefix().length() > 0) {
rc.put(ns, ns.getPrefix());
// else we use the namespace to generate a prefix
} else if ((s = getNCNameFromNSURL(ns)) != null) {
rc.put(ns, s);
// else a last resort we sjust use the element name as a prefix
// and
// hope this will get matched to a namespace in the model.
} else {
rc.put(ns, n2El.get(ns).getName());
}
}
return rc;
}
use of org.jdom.Namespace in project vcell by virtualcell.
the class AnatomicalStructure method getCompartmentGoTerms.
public static HashMap<String, AnatomicalStructure> getCompartmentGoTerms(String sbmlText) {
HashMap<String, AnatomicalStructure> compartmentAnatomyMap = new HashMap<String, AnatomicalStructure>();
Namespace sbmlNamespace = Namespace.getNamespace("http://www.sbml.org/sbml/level2");
Namespace rdfNamespace = Namespace.getNamespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#");
Namespace bioqualifierNamespace = Namespace.getNamespace("http://biomodels.net/biology-qualifiers/");
Element rootSBML = (XmlUtil.stringToXML(sbmlText, null)).getRootElement();
Element sbmlModelElement = rootSBML.getChild("model", sbmlNamespace);
Element listOfCompartments = sbmlModelElement.getChild("listOfCompartments", sbmlNamespace);
List<Element> compartmentElementList = listOfCompartments.getChildren("compartment", sbmlNamespace);
for (Element compartmentElement : compartmentElementList) {
AnatomicalStructure anatomicalStructure = null;
String compartmentID = compartmentElement.getAttributeValue("id");
String goPrefix = "http://www.geneontology.org/#GO:";
String compartmentOutside = compartmentElement.getAttributeValue("outside");
Element annotationElement = compartmentElement.getChild("annotation", sbmlNamespace);
if (annotationElement != null) {
Element rdfElement = annotationElement.getChild("RDF", rdfNamespace);
Element descriptionElement = rdfElement.getChild("Description", rdfNamespace);
Element isElement = descriptionElement.getChild("is", bioqualifierNamespace);
if (isElement == null) {
isElement = descriptionElement.getChild("isVersionOf", bioqualifierNamespace);
}
if (isElement != null) {
Element bagElement = isElement.getChild("Bag", rdfNamespace);
Element liElement = bagElement.getChild("li", rdfNamespace);
String compartmentRdfResource = liElement.getAttributeValue("resource", rdfNamespace);
if (compartmentRdfResource.startsWith(goPrefix)) {
String GoTerm = compartmentRdfResource.substring(goPrefix.length(), compartmentRdfResource.length());
anatomicalStructure = AnatomicalStructure.fromGOTerm(GoTerm);
}
if (compartmentOutside != null) {
System.out.println(compartmentOutside + "," + compartmentID);
}
}
compartmentAnatomyMap.put(compartmentID, anatomicalStructure);
}
}
return compartmentAnatomyMap;
}
use of org.jdom.Namespace in project vcell by virtualcell.
the class XmlHelper method XMLToGeometry.
static Geometry XMLToGeometry(XMLSource xmlSource, boolean printkeys) throws XmlParseException {
Geometry geometry = null;
if (xmlSource == null) {
throw new XmlParseException("Invalid xml for Geometry.");
}
Document xmlDoc = xmlSource.getXmlDoc();
// NOTES:
// * The root element can be <Biomodel> (old-style vcml) OR <vcml> (new-style vcml)
// * With the old-style vcml, the namespace was " "
// * With the new-style vcml, there is an intermediate stage where the namespace for <vcml> root
// was set to "http://sourceforge.net/projects/VCell/version0.4" for some models and
// "http://sourceforge.net/projects/vcell/vcml" for some models; and the namespace for child element
// <biomdel>, etc. was " "
// * The final new-style vcml has (should have) the namespace "http://sourceforge.net/projects/vcell/vcml"
// for <vcml> and all children elements.
// The code below attempts to take care of this situation.
Element root = xmlDoc.getRootElement();
Namespace ns = null;
if (root.getName().equals(XMLTags.VcmlRootNodeTag)) {
// NEW WAY - with xml string containing xml declaration, vcml element, namespace, etc ...
ns = root.getNamespace();
Element geoRoot = root.getChild(XMLTags.GeometryTag, ns);
if (geoRoot == null) {
geoRoot = root.getChild(XMLTags.GeometryTag);
// geoRoot was null, so obtained the <Geometry> element with namespace " ";
// Re-set the namespace so that the correct XMLReader constructor is invoked.
ns = null;
}
root = geoRoot;
}
// else - root is assumed to be old-style vcml with <Geometry> as root.
// common for both new-style (with xml declaration, vcml element, etc) and old-style (geometry is root)
// If namespace is null, xml is the old-style xml with geometry as root, so invoke XMLReader without namespace argument.
XmlReader reader = null;
if (ns == null) {
reader = new XmlReader(printkeys);
} else {
reader = new XmlReader(printkeys, ns);
}
geometry = reader.getGeometry(root);
geometry.refreshDependencies();
return geometry;
}
use of org.jdom.Namespace in project vcell by virtualcell.
the class XmlHelper method XMLToMathModel.
static MathModel XMLToMathModel(XMLSource xmlSource, boolean printkeys) throws XmlParseException {
MathModel mathModel = null;
if (xmlSource == null) {
throw new XmlParseException("Invalid xml for Geometry.");
}
Document xmlDoc = xmlSource.getXmlDoc();
// NOTES:
// * The root element can be <Biomodel> (old-style vcml) OR <vcml> (new-style vcml)
// * With the old-style vcml, the namespace was " "
// * With the new-style vcml, there is an intermediate stage where the namespace for <vcml> root
// was set to "http://sourceforge.net/projects/VCell/version0.4" for some models and
// "http://sourceforge.net/projects/vcell/vcml" for some models; and the namespace for child element
// <biomdel>, etc. was " "
// * The final new-style vcml has (should have) the namespace "http://sourceforge.net/projects/vcell/vcml"
// for <vcml> and all children elements.
// The code below attempts to take care of this situation.
Element root = xmlDoc.getRootElement();
Namespace ns = null;
if (root.getName().equals(XMLTags.VcmlRootNodeTag)) {
// NEW WAY - with xml string containing xml declaration, vcml element, namespace, etc ...
ns = root.getNamespace();
Element mathRoot = root.getChild(XMLTags.MathModelTag, ns);
if (mathRoot == null) {
mathRoot = root.getChild(XMLTags.MathModelTag);
// mathRoot was null, so obtained the <Mathmodel> element with namespace " ";
// Re-set the namespace so that the correct XMLReader constructor is invoked.
ns = null;
}
root = mathRoot;
}
// else - root is assumed to be old-style vcml with <Mathmodel> as root.
// common for both new-style (with xml declaration, vcml element, etc) and old-style (mathmodel is root)
// If namespace is null, xml is the old-style xml with mathmodel as root, so invoke XMLReader without namespace argument.
XmlReader reader = null;
if (ns == null) {
reader = new XmlReader(printkeys);
} else {
reader = new XmlReader(printkeys, ns);
}
mathModel = reader.getMathModel(root);
mathModel.refreshDependencies();
return mathModel;
}
use of org.jdom.Namespace in project vcell by virtualcell.
the class XmlHelper method XMLToBioModel.
public static BioModel XMLToBioModel(XMLSource xmlSource, boolean printkeys, ModelUnitSystem forcedModelUnitSystem) throws XmlParseException {
// long l0 = System.currentTimeMillis();
BioModel bioModel = null;
if (xmlSource == null) {
throw new XmlParseException("Invalid xml for Biomodel.");
}
Document xmlDoc = xmlSource.getXmlDoc();
// NOTES:
// * The root element can be <Biomodel> (old-style vcml) OR <vcml> (new-style vcml)
// * With the old-style vcml, the namespace was " "
// * With the new-style vcml, there is an intermediate stage where the namespace for <vcml> root
// was set to "http://sourceforge.net/projects/VCell/version0.4" for some models and
// "http://sourceforge.net/projects/vcell/vcml" for some models; and the namespace for child element
// <biomdel>, etc. was " "
// * The final new-style vcml has (should have) the namespace "http://sourceforge.net/projects/vcell/vcml"
// for <vcml> and all children elements.
// The code below attempts to take care of this situation.
Element root = xmlDoc.getRootElement();
Namespace ns = null;
if (root.getName().equals(XMLTags.VcmlRootNodeTag)) {
// NEW WAY - with xml string containing xml declaration, vcml element, namespace, etc ...
ns = root.getNamespace();
Element bioRoot = root.getChild(XMLTags.BioModelTag, ns);
if (bioRoot == null) {
bioRoot = root.getChild(XMLTags.BioModelTag);
// bioRoot was null, so obtained the <Biomodel> element with namespace " ";
// Re-set the namespace so that the correct XMLReader constructor is invoked.
ns = null;
}
root = bioRoot;
}
// else - root is assumed to be old-style vcml with <Biomodel> as root.
// common for both new way (with xml declaration, vcml element, etc) and existing way (biomodel is root)
// If namespace is null, xml is the old-style xml with biomodel as root, so invoke XMLReader without namespace argument.
XmlReader reader = null;
VCellSoftwareVersion vCellSoftwareVersion = null;
if (ns == null) {
reader = new XmlReader(printkeys);
} else {
reader = new XmlReader(printkeys, ns);
vCellSoftwareVersion = VCellSoftwareVersion.fromString(root.getAttributeValue(XMLTags.SoftwareVersionAttrTag, ns));
}
if (forcedModelUnitSystem != null) {
reader.setForcedModelUnitSystem(forcedModelUnitSystem);
}
bioModel = reader.getBioModel(root, vCellSoftwareVersion);
// long l1 = System.currentTimeMillis();
bioModel.refreshDependencies();
return bioModel;
}
Aggregations