use of org.jdom.Namespace in project vcell by virtualcell.
the class XmlHelper method XMLToDocument.
/**
* Insert the method's description here.
* Creation date: (2/7/2006 4:45:26 PM)
* @return cbit.vcell.document.VCDocument
* @param xmlString java.lang.String
*/
public static VCDocument XMLToDocument(VCLogger vcLogger, String xmlString) throws Exception {
VCDocument doc = null;
XMLSource xmlSource = new XMLSource(xmlString);
// some overhead.
org.jdom.Element rootElement = xmlSource.getXmlDoc().getRootElement();
String xmlType = rootElement.getName();
if (xmlType.equals(XMLTags.VcmlRootNodeTag)) {
// For now, assuming that <vcml> element has only one child (biomodel, mathmodel or geometry).
// Will deal with multiple children of <vcml> Element when we get to model composition.
java.util.List<?> childElementList = rootElement.getChildren();
// assuming first child is the biomodel, mathmodel or geometry.
Element modelElement = (Element) childElementList.get(0);
xmlType = modelElement.getName();
}
if (xmlType.equals(XMLTags.BioModelTag)) {
doc = XmlHelper.XMLToBioModel(xmlSource);
} else if (xmlType.equals(XMLTags.MathModelTag)) {
doc = XmlHelper.XMLToMathModel(xmlSource);
} else if (xmlType.equals(XMLTags.GeometryTag)) {
doc = XmlHelper.XMLToGeometry(xmlSource);
} else if (xmlType.equals(XMLTags.SbmlRootNodeTag)) {
Namespace namespace = rootElement.getNamespace(XMLTags.SBML_SPATIAL_NS_PREFIX);
boolean bIsSpatial = (namespace == null) ? false : true;
doc = XmlHelper.importSBML(vcLogger, xmlSource, bIsSpatial);
} else if (xmlType.equals(XMLTags.CellmlRootNodeTag)) {
doc = XmlHelper.importMathCellML(vcLogger, xmlSource);
} else {
// unknown XML format
throw new RuntimeException("unsupported XML format, first element tag is <" + rootElement.getName() + ">");
}
return doc;
}
use of org.jdom.Namespace in project vcell by virtualcell.
the class XmlHelper method XMLToImage.
static VCImage XMLToImage(String xmlString, boolean printKeys) throws XmlParseException {
Namespace ns = Namespace.getNamespace(XMLTags.VCML_NS);
if (xmlString == null || xmlString.length() == 0) {
throw new XmlParseException("Invalid xml for Image: " + xmlString);
}
// default parser and no validation
Element root = (XmlUtil.stringToXML(xmlString, null)).getRootElement();
Element extentElement = root.getChild(XMLTags.ExtentTag, ns);
Element imageElement = root.getChild(XMLTags.ImageTag, ns);
// Element extentElement = root.getChild(XMLTags.ExtentTag);
// Element imageElement = root.getChild(XMLTags.ImageTag);
XmlReader reader = new XmlReader(printKeys, ns);
Extent extent = reader.getExtent(extentElement);
VCImage vcImage = reader.getVCImage(imageElement, extent);
vcImage.refreshDependencies();
return vcImage;
}
use of org.jdom.Namespace in project vcell by virtualcell.
the class XmlHelper method XMLToSimTask.
public static SimulationTask XMLToSimTask(String xmlString) throws XmlParseException, ExpressionException {
Namespace ns = Namespace.getNamespace(XMLTags.VCML_NS);
try {
if (xmlString == null || xmlString.length() == 0) {
throw new XmlParseException("Invalid xml for Simulation: " + xmlString);
}
// default parser and no validation
Element root = (XmlUtil.stringToXML(xmlString, null)).getRootElement();
if (!root.getName().equals(SimulationTask_tag)) {
throw new RuntimeException("expecting top level element to be " + SimulationTask_tag);
}
int taskId = Integer.parseInt(root.getAttributeValue(TaskId_attr));
int jobIndex = Integer.parseInt(root.getAttributeValue(JobIndex_attr));
boolean isPowerUser = false;
if (root.getAttributeValue(powerUser_attr) != null) {
isPowerUser = Boolean.parseBoolean(root.getAttributeValue(powerUser_attr));
}
String computeResource = root.getChildTextTrim(ComputeResource_tag, ns);
List<?> children = root.getChildren(FieldFunctionIdentifierSpec_tag, ns);
ArrayList<FieldDataIdentifierSpec> fdisArrayList = new ArrayList<FieldDataIdentifierSpec>();
for (Object child : children) {
if (child instanceof Element) {
String fdisText = ((Element) child).getTextTrim();
FieldDataIdentifierSpec fdis = FieldDataIdentifierSpec.fromCSVString(fdisText);
fdisArrayList.add(fdis);
}
}
FieldDataIdentifierSpec[] fdisArray = fdisArrayList.toArray(new FieldDataIdentifierSpec[0]);
Element simElement = root.getChild(XMLTags.SimulationTag, ns);
Element mdElement = root.getChild(XMLTags.MathDescriptionTag, ns);
Element geomElement = root.getChild(XMLTags.GeometryTag, ns);
XmlReader reader = new XmlReader(true, ns);
Geometry geom = null;
if (geomElement != null) {
geom = reader.getGeometry(geomElement);
}
MathDescription md = reader.getMathDescription(mdElement, geom);
Simulation sim = reader.getSimulation(simElement, md);
sim.refreshDependencies();
SimulationJob simJob = new SimulationJob(sim, jobIndex, fdisArray);
SimulationTask simTask = new SimulationTask(simJob, taskId, computeResource, isPowerUser);
return simTask;
} catch (Exception pve) {
pve.printStackTrace();
throw new XmlParseException("Unable to parse simulation string.", pve);
}
}
use of org.jdom.Namespace in project vcell by virtualcell.
the class SEDMLExporter method getSEDMLFile.
public String getSEDMLFile(String sPath, String sBaseFileName, boolean bForceVCML, boolean bHasDataOnly, boolean bFromOmex) {
// Create an SEDMLDocument and create the SEDMLModel from the document, so that other details can be added to it in translateBioModel()
SEDMLDocument sedmlDocument = new SEDMLDocument(this.sedmlLevel, this.sedmlVersion);
// sedmlDocument.getSedMLModel().setAdditionalNamespaces(Arrays.asList(new Namespace[] {
// Namespace.getNamespace(SEDMLTags.SBML_NS_PREFIX, SEDMLTags.SBML_NS_L2V4)
// }));
final String SBML_NS = "http://www.sbml.org/sbml/level3/version1/core";
final String SBML_NS_PREFIX = "sbml";
final String VCML_NS = "http://sourceforge.net/projects/vcell/vcml";
final String VCML_NS_PREFIX = "vcml";
List<Namespace> nsList = new ArrayList<>();
Namespace ns = Namespace.getNamespace(SEDMLTags.MATHML_NS_PREFIX, SEDMLTags.MATHML_NS);
nsList.add(ns);
ns = Namespace.getNamespace(SBML_NS_PREFIX, SBML_NS);
nsList.add(ns);
ns = Namespace.getNamespace(VCML_NS_PREFIX, VCML_NS);
nsList.add(ns);
sedmlModel = sedmlDocument.getSedMLModel();
sedmlModel.setAdditionalNamespaces(nsList);
translateBioModelToSedML(sPath, sBaseFileName, bForceVCML, bHasDataOnly, bFromOmex);
// write SEDML document into SEDML writer, so that the SEDML str can be retrieved
return sedmlDocument.writeDocumentToString();
}
use of org.jdom.Namespace in project vcell by virtualcell.
the class SEDMLReader method getSedDocument.
/*
* returns a SedML model given an Element of xml for a complete model non -
* api method
*/
public SedML getSedDocument(Element sedRoot) throws XMLException {
SedML sedDoc = null;
SymbolRegistry.getInstance().addSymbolFactory(new SedMLSymbolFactory());
try {
Namespace sedNS = sedRoot.getNamespace();
String verStr = sedRoot.getAttributeValue(SEDMLTags.VERSION_TAG);
String lvlStr = sedRoot.getAttributeValue(SEDMLTags.LEVEL_TAG);
if (verStr != null && lvlStr != null) {
int sedVersion = Integer.parseInt(verStr);
int sedLevel = Integer.parseInt(lvlStr);
sedDoc = new SedML(sedLevel, sedVersion, sedNS);
} else {
sedDoc = new SedML(sedNS);
}
// Get additional namespaces if mentioned : mathml, sbml, etc.
List additionalNamespaces = sedRoot.getAdditionalNamespaces();
sedDoc.setAdditionalNamespaces(additionalNamespaces);
// notes and annotations
addNotesAndAnnotation(sedDoc, sedRoot);
Iterator<Element> elementsIter = null;
// models
Element el = sedRoot.getChild(SEDMLTags.MODELS, sedNS);
if (el != null) {
List elementsList = el.getChildren();
elementsIter = elementsList.iterator();
while (elementsIter.hasNext()) {
Element modelElement = elementsIter.next();
if (modelElement.getName().equals(SEDMLTags.MODEL_TAG)) {
sedDoc.addModel(getModel(modelElement));
}
}
}
// simulations
el = sedRoot.getChild(SEDMLTags.SIMS, sedNS);
if (el != null) {
List elementsList = el.getChildren();
elementsIter = elementsList.iterator();
while (elementsIter.hasNext()) {
Element simElement = elementsIter.next();
sedDoc.addSimulation(getSimulation(simElement));
}
}
el = sedRoot.getChild(SEDMLTags.TASKS, sedNS);
if (el != null) {
List elementsList = el.getChildren();
elementsIter = elementsList.iterator();
while (elementsIter.hasNext()) {
Element taskElement = elementsIter.next();
if (taskElement.getName().equals(SEDMLTags.TASK_TAG)) {
sedDoc.addTask(getTask(taskElement));
} else if (taskElement.getName().equals(SEDMLTags.REPEATED_TASK_TAG)) {
sedDoc.addTask(getRepeatedTask(taskElement));
}
}
}
el = sedRoot.getChild(SEDMLTags.DATAGENERATORS, sedNS);
if (el != null) {
List elementsList = el.getChildren();
elementsIter = elementsList.iterator();
while (elementsIter.hasNext()) {
Element dataGenElement = elementsIter.next();
if (dataGenElement.getName().equals(SEDMLTags.DATAGENERATOR_TAG)) {
sedDoc.addDataGenerator(getDataGenerator(dataGenElement));
}
}
}
el = sedRoot.getChild(SEDMLTags.OUTPUTS, sedNS);
if (el != null) {
List elementsList = el.getChildren();
elementsIter = elementsList.iterator();
while (elementsIter.hasNext()) {
Element outputElement = elementsIter.next();
if (outputElement.getName().equals(SEDMLTags.OUTPUT_P2D) || outputElement.getName().equals(SEDMLTags.OUTPUT_P3D) || outputElement.getName().equals(SEDMLTags.OUTPUT_REPORT)) {
sedDoc.addOutput(getOutput(outputElement));
}
}
}
} catch (Exception e) {
e.printStackTrace(System.out);
throw new XMLException("Error loading sed-ml document : " + e.getMessage());
// return sedDoc;
}
return sedDoc;
}
Aggregations