From: <nik...@us...> - 2016-01-21 17:13:22
|
Revision: 2471 http://sourceforge.net/p/jsbml/code/2471 Author: niko-rodrigue Date: 2016-01-21 17:13:20 +0000 (Thu, 21 Jan 2016) Log Message: ----------- implemented a new method on MathMLXMLStreamCompiler in order to be able to write the ASTNodePlugins. Writing only attributes for ci element for now Modified Paths: -------------- trunk/core/src/org/sbml/jsbml/util/compilers/MathMLXMLStreamCompiler.java Modified: trunk/core/src/org/sbml/jsbml/util/compilers/MathMLXMLStreamCompiler.java =================================================================== --- trunk/core/src/org/sbml/jsbml/util/compilers/MathMLXMLStreamCompiler.java 2016-01-21 16:34:35 UTC (rev 2470) +++ trunk/core/src/org/sbml/jsbml/util/compilers/MathMLXMLStreamCompiler.java 2016-01-21 17:13:20 UTC (rev 2471) @@ -27,6 +27,7 @@ import java.text.MessageFormat; import java.util.List; import java.util.Locale; +import java.util.Map; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; @@ -38,6 +39,7 @@ import org.sbml.jsbml.SBMLDocument; import org.sbml.jsbml.SBMLException; import org.sbml.jsbml.SBase; +import org.sbml.jsbml.ext.ASTNodePlugin; import org.sbml.jsbml.util.StringTools; import org.sbml.jsbml.xml.XMLNode; import org.sbml.jsbml.xml.parsers.XMLNodeWriter; @@ -648,6 +650,12 @@ try { writer.writeCharacters(indent); writer.writeStartElement(ASTNode.URI_MATHML_DEFINITION, "ci"); + + // check if there are any plugins on the ASTNode + if (astNode.getExtensionCount() > 0) { + writePlugins(astNode); + } + writer.writeCharacters(" "); writer.writeCharacters(astNode.getName()); writer.writeCharacters(" "); @@ -662,8 +670,34 @@ } /** + * Writes the attributes of the {@link ASTNodePlugin}s present on the ASTNode. + * * @param astNode */ + private void writePlugins(ASTNode astNode) { + + // TODO - for now only writing the attributes, we will need to revisit if + // one package add elements to mathML elements. + + ASTNodePlugin plugin = astNode.getPlugin("multi"); + Map<String, String> attributes = plugin.writeXMLAttributes(); + + if (attributes.size() > 0) { + for (String attributeKey : attributes.keySet()) { + String attributeValue = attributes.get(attributeKey); + + try { + writer.writeAttribute(attributeKey, attributeValue); + } catch (XMLStreamException e) { + e.printStackTrace(); + } + } + } + } + + /** + * @param astNode + */ private void compileElement(ASTNode astNode) { compileElement(astNode.getType().toString().toLowerCase(), astNode); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |