org.activemath.presentation
Class Formatter

java.lang.Object
  extended by org.activemath.presentation.Formatter

public class Formatter
extends Object

External call point for the presentation process. Any access to the presentation process must be done here. It encapsulates two basic features:

Formats currently supported: Glossary:


Field Summary
protected static boolean DEBUG
           
protected static Logger log
           
 
Constructor Summary
Formatter(String fmt, String lang)
          Takes arguments "user" and "format", which are kept constant during the lifetime of the object.
 
Method Summary
 byte[] formatItem(org.jdom.Element element)
           
 byte[] formatItem(OJElement domTree)
          Return a Byte array with the fragment content corresponding to a DOM tree.
 Fragment formatItem(String itemId)
          Return a Fragment corresponding to an Item id, using the Fragment cache.
 void formatItem(String itemId, OutputStream out)
          Write a translated content fragment to an output stream.
 void formatText(String text, OutputStream out)
          Format a text string to the output stream.
 String formatTitle(String originalTitle)
          Transform a title string if it seems to contain an XLM element.
 String getAssemblyFormat()
           
 String getFormatPipeline()
           
 String getLayoutFormat()
           
 String getMimeType()
          Returns the MIME type for the final transformation result.
 Map getXslParams()
          Return the Map with the parameters used for the XSL transformation.
protected  org.jdom.transform.JDOMSource makeTransformationSource(Item item)
          Builds a transformation source for an item.
protected  org.jdom.transform.JDOMSource makeTransformationSource(OJElement domTree)
          Builds a transformation source for a DOM tree.
 void setXslFilename(String xslFilename)
          Set the filename to use for the XSL transformation.
 void writeFragment(org.jdom.Element element, OutputStream output)
           
 void xslTransform(InputStream itemStream, OutputStream output)
          Transform the OMDoc item as read from itemStream, and write the result to output.
 String xslTransform(String xmlText)
           
 void xslTransform(String xmlText, OutputStream output)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static Logger log

DEBUG

protected static boolean DEBUG
Constructor Detail

Formatter

public Formatter(String fmt,
                 String lang)
Takes arguments "user" and "format", which are kept constant during the lifetime of the object.

Parameters:
fmt - format of output document. (eg. "pdf")
lang - human language to use for the page, if available.
Method Detail

getMimeType

public String getMimeType()
Returns the MIME type for the final transformation result.

Returns:
MIME type as string.
See Also:
Format.getMimeType(String)

getFormatPipeline

public String getFormatPipeline()
Returns:
the format pipline string of this Formatter (eg. "LaTeX.PDF")

getAssemblyFormat

public String getAssemblyFormat()
Returns:
the assembly format of this Formatter (ie. the beginning of the format pipe)

getLayoutFormat

public String getLayoutFormat()
Returns:
the layout format of this Formatter (ie. the end of the format pipeline)

getXslParams

public Map getXslParams()
Return the Map with the parameters used for the XSL transformation. The Map can be modified at will before calling xslTransform().

Returns:
the Map with the parameters used for the XSL transformation.

setXslFilename

public void setXslFilename(String xslFilename)
Set the filename to use for the XSL transformation. Must happen before calling xslTransform().

Parameters:
xslFilename -

xslTransform

public void xslTransform(InputStream itemStream,
                         OutputStream output)
                  throws TransformerException
Transform the OMDoc item as read from itemStream, and write the result to output. Will not use the Fragment cache. This is for transformation of items generated on the fly that aren't to be stored, like the output of the CAS console.

Parameters:
itemStream - used to read the OMDoc item content.
output - stream to receive the output.
Throws:
TransformerException - problem with the XSLT transformer.

xslTransform

public void xslTransform(String xmlText,
                         OutputStream output)
                  throws TransformerException
Throws:
TransformerException

xslTransform

public String xslTransform(String xmlText)
                    throws TransformerException,
                           IOException
Throws:
TransformerException
IOException

makeTransformationSource

protected org.jdom.transform.JDOMSource makeTransformationSource(Item item)
Builds a transformation source for an item. This is done by getting the DOM tree and running the PreProcessors on it.


makeTransformationSource

protected org.jdom.transform.JDOMSource makeTransformationSource(OJElement domTree)
Builds a transformation source for a DOM tree. This is done by running the PreProcessors on the tree.


formatItem

public Fragment formatItem(String itemId)
Return a Fragment corresponding to an Item id, using the Fragment cache. If not already found in the cache, the Fragment will be transformed according the format/language of this Formatter and put in the cache.

Returns:
Transformed Fragment, or null on error

formatItem

public void formatItem(String itemId,
                       OutputStream out)
                throws IOException
Write a translated content fragment to an output stream. Output of the XSL transformer is assumed to be in UTF-8. Uses the Fragment cache.

Throws:
IOException

formatItem

public byte[] formatItem(OJElement domTree)
Return a Byte array with the fragment content corresponding to a DOM tree. This doesn't use the fragment cache, since the intended use is for content generated on the fly, instead of being retrieved from MBase. One such use is exercises, but can be applied to anything that requires dynamic generation of content.

Returns:
transformed fragment, or null on error.

formatItem

public byte[] formatItem(org.jdom.Element element)

writeFragment

public void writeFragment(org.jdom.Element element,
                          OutputStream output)

formatText

public void formatText(String text,
                       OutputStream out)
                throws IOException
Format a text string to the output stream.

Parameters:
text - - text to format, encoded in UTF-8.
out - - stream to output to (UTF-8 bytes)
Throws:
IOException

formatTitle

public String formatTitle(String originalTitle)
Transform a title string if it seems to contain an XLM element.

Returns:
transformed title, or originalTitle unchanged.