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 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 MicroscopyXmlReader method getPrimaryROIs.
/**
* This method is only called by DataSymbolsPanel to get the primary ROIs
*/
public ROI[] getPrimaryROIs(Element param, /*root, frapstudy element*/
ClientTaskStatusSupport progressListener) throws XmlParseException {
// get frapData element
Element frapDataElement = param.getChild(MicroscopyXMLTags.FRAPDataTag);
Namespace ns = param.getNamespace();
List<Element> roiList = frapDataElement.getChildren(MicroscopyXMLTags.ROITag);
ROI[] rois = null;
int numROIs = 3;
if (numROIs > 0) {
rois = new ROI[numROIs];
Iterator<Element> roiIter = roiList.iterator();
int index = 0;
while (roiIter.hasNext()) {
Element roiElement = roiIter.next();
if (roiElement.getAttributeValue(MicroscopyXMLTags.ROITypeAttrTag).equals(AnnotatedImageDataset.VFRAP_ROI_ENUM.ROI_BLEACHED.name()) || roiElement.getAttributeValue(MicroscopyXMLTags.ROITypeAttrTag).equals(AnnotatedImageDataset.VFRAP_ROI_ENUM.ROI_BACKGROUND.name()) || roiElement.getAttributeValue(MicroscopyXMLTags.ROITypeAttrTag).equals(AnnotatedImageDataset.VFRAP_ROI_ENUM.ROI_CELL.name())) {
rois[index++] = getROI(roiElement);
if (index == 3) {
break;
}
}
}
}
// reorder ROIs according to the order of FRAPData.VFRAP_ROI_ENUM
ROI[] reorderedROIs = AnnotatedImageDataset.reorderROIs(rois);
return reorderedROIs;
}
use of org.jdom.Namespace in project vcell by virtualcell.
the class XMLDict method getMatchingElement.
private static Element getMatchingElement(Element root, String reName, String attName, String attValue) {
String path;
// accomodate math models.
if (!root.getName().equals(XMLTags.MathModelTag)) {
path = (String) reHashBio.get(reName);
} else {
path = (String) reHashMath.get(reName);
}
if (path == null) {
System.err.println("The xpath of the element to resolve is not available: " + reName);
return getMatchingElementGeneric(root, reName, attName, attValue);
}
java.util.StringTokenizer tokenizer = new java.util.StringTokenizer(path, XMLDict.XPATH_SEP);
// System.out.println(root.getName() + " " + reName + " " + attName + " " + attValue + " " + path + " " + tokenizer.countTokens());
if (tokenizer.countTokens() < 2) {
// the element to resolve is the root. Should not happen.
System.err.println("No tokens found for element: " + reName);
return null;
}
while (tokenizer.hasMoreTokens()) {
// start at the parent of interest, which can be a shorter path than the one saved.
String curToken = tokenizer.nextToken();
if (root.getName().equals(curToken)) {
break;
}
}
Namespace ns = root.getNamespace();
for (int i = 0; i < tokenizer.countTokens() - 1; i++) {
// break when reaching the direct parent.
String elementName = tokenizer.nextToken();
// System.out.println("Current Token: " + elementName);
root = root.getChild(elementName, ns);
}
String resElementName = tokenizer.nextToken();
// System.out.println(resElementName);
@SuppressWarnings("unchecked") Iterator<Element> // last 2 tokens (direct parent, and element to resolve)
iterator = root.getChildren(resElementName, ns).iterator();
Element temp = null;
while (iterator.hasNext()) {
temp = iterator.next();
if (attValue.equals(temp.getAttributeValue(attName))) {
break;
} else {
temp = null;
}
}
return temp;
}
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;
}
Aggregations