/*
* Copyright (c) 2005 Thomas Weise
*
* E-Mail : tweise@gmx.de
* Creation Date : 2005-08-20 19:19:03
* Original Filename: org.sfc.xml.formats.MathMLWriter.java
* Version : 1.0.2
* Last modification: 2006-03-07
* by: Thomas Weise
*
* License : GNU LESSER GENERAL PUBLIC LICENSE
* Version 2.1, February 1999
* You should have received a copy of this license along
* with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307, USA or download the license under
* http://www.gnu.org/copyleft/lesser.html.
*
* Warranty : This software is provided "as is" without any
* warranty; without even the implied warranty of
* merchantability or fitness for a particular purpose.
* See the Gnu Lesser General Public License for more
* details.
*/
package org.sfc.xml.formats;
import org.xml.sax.SAXException;
import org.sfc.xml.formats.meta.MathMLTag;
import org.sfc.xml.sax.SAXWriter;
/**
* This class may be used to dynamically create MathMLWriter content.
*
* @author Thomas Weise
*/
public final class MathMLWriter extends XMLPropagate
{
/**
* The math ml namespace.
*/
private static final String MATH_ML_NS =
"http://www.w3.org/1998/Math/MathML";
/**
* Create a new math ml processor.
* @param p_dest Any given source object that can be converted to a
* Writer
by the IO
class.
* @throws SAXException If something goes wrong.
*/
public MathMLWriter (final Object p_dest) throws SAXException
{
this(p_dest, true);
}
/**
* Create a new math ml processor.
* @param p_dest Any given source object that can be converted to a
* Writer
by the IO
class.
* @param p_is_owner true
if this sax propagate is the sole
* owner of the sax writer, meaning that when the
* propagate starts a document, the sax writer starts a
* document too (and the same goes for ending a
* document).
* @throws SAXException If something goes wrong.
*/
MathMLWriter (final Object p_dest,
final boolean p_is_owner) throws SAXException
{
super(p_dest, p_is_owner);
}
/**
* Start a new xml document.
* @throws SAXException If something goes wrong.
*/
@Override
public final void start_document () throws SAXException
{
super.start_document();
this.start_element(MATH_ML_NS, "math");
}
/**
* This method must be called to shutdoen the xml production.
* @throws SAXException If something goes sax-like wrong.
*/
@Override
public final void end_document () throws SAXException
{
this.end_element();
super.end_document();
}
/**
* This method will be invoked to begin mathml tags.
* @param p_tag The tag to begin.
* @throws SAXException If something at sax-level fails.
* @throws MathMLException If mathml creation failed.
*/
public final void tag(final MathMLTag p_tag) throws SAXException
{
this.start_element(p_tag.toString());
}
/**
* Begin a new maction-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void maction () throws SAXException
{
this.tag(MathMLTag.MACTION);
}
/**
* Begin a new maligngroup-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void maligngroup () throws SAXException
{
this.tag(MathMLTag.MALIGNGROUP);
}
/**
* Begin a new malignmark-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void malignmark () throws SAXException
{
this.tag(MathMLTag.MALIGNMARK);
}
/**
* Begin a new merror-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void merror () throws SAXException
{
this.tag(MathMLTag.MERROR);
}
/**
* Begin a new mfenced-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void mfenced () throws SAXException
{
this.tag(MathMLTag.MFENCED);
}
/**
* Begin a new mfrac-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void mfrac () throws SAXException
{
this.tag(MathMLTag.MFRAC);
}
/**
* Begin a new mglyph-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void mglyph () throws SAXException
{
this.tag(MathMLTag.MGLYPH);
}
/**
* Begin a new mi-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void mi () throws SAXException
{
this.tag(MathMLTag.MI);
}
/**
* Begin a new mlabeledtr-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void mlabeledtr () throws SAXException
{
this.tag(MathMLTag.MLABELEDTR);
}
/**
* Begin a new mmultiscripts-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void mmultiscripts () throws SAXException
{
this.tag(MathMLTag.MMULTISCRIPTS);
}
/**
* Begin a new mn-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void mn() throws SAXException
{
this.tag(MathMLTag.MN);
}
/**
* Begin a new mo-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void mo () throws SAXException
{
this.tag(MathMLTag.MO);
}
/**
* Begin a new mover-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void mover () throws SAXException
{
this.tag(MathMLTag.MOVER);
}
/**
* Begin a new mpadded-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void mpadded () throws SAXException
{
this.tag(MathMLTag.MPADDED);
}
/**
* Begin a new mphantom-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void mphantom() throws SAXException
{
this.tag(MathMLTag.MPHANTOM);
}
/**
* Begin a new mroot-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void mroot() throws SAXException
{
this.tag(MathMLTag.MROOT);
}
/**
* Begin a new mrow-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void mrow() throws SAXException
{
this.tag(MathMLTag.MROW);
}
/**
* Begin a new ms-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void ms() throws SAXException
{
this.tag(MathMLTag.MS);
}
/**
* Begin a new mspace-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void mspace() throws SAXException
{
this.tag(MathMLTag.MSPACE);
}
/**
* Begin a new msqrt-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void msqrt () throws SAXException
{
this.tag(MathMLTag.MSQRT);
}
/**
* Begin a new mstyle-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void mstyle () throws SAXException
{
this.tag(MathMLTag.MSTYLE);
}
/**
* Begin a new msub-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void msub() throws SAXException
{
this.tag(MathMLTag.MSUB);
}
/**
* Begin a new msubsup-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void msubsup() throws SAXException
{
this.tag(MathMLTag.MSUBSUP);
}
/**
* Begin a new msup-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void msup() throws SAXException
{
this.tag(MathMLTag.MSUP);
}
/**
* Begin a new mtable-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void mtable() throws SAXException
{
this.tag(MathMLTag.MTABLE);
}
/**
* Begin a new td-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void mtd() throws SAXException
{
this.tag(MathMLTag.MTD);
}
/**
* Begin a new mtext-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void mtext() throws SAXException
{
this.tag(MathMLTag.MTEXT);
}
/**
* Begin a new mtr-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void mtr() throws SAXException
{
this.tag(MathMLTag.MTR);
}
/**
* Begin a new munder-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void munder () throws SAXException
{
this.tag(MathMLTag.MUNDER);
}
/**
* Begin a new munderover-tag.
* You must call end_element()
to close this tag.
* @throws SAXException If something went wrong.
* @throws MathMLException If mathml creation failed.
* @see SAXWriter#end_element()
*/
public final void munderover () throws SAXException
{
this.tag(MathMLTag.MUNDEROVER);
}
}