sk.uniba.euromath.gene
Class XsltExporterBase

java.lang.Object
  extended by sk.uniba.euromath.gene.XsltExporterBase
All Implemented Interfaces:
IExporter

public class XsltExporterBase
extends Object
implements IExporter

Serves as the base class for XSLT exporters. It does not handle emp:mark elements specially. No properties are defined. The stylesheet obtains all parameters from the EuroMath as normal stylesheet does.

Version:
1.0
Author:
Martin Vysny

Field Summary
protected  ExportHelper helper
          Helper object for exporter.
protected  ExporterInfo info
          Info object.
static String PARAMETER_DOCUMENT_DIR
          Denotes a string representing directory where the document is stored.
static String PARAMETER_DOCUMENT_EXTENSION
          Denotes a string representing the extension of the document being transformed.
static String PARAMETER_DOCUMENT_NAME
          Denotes a string representing the name of the document being translated.
static String PARAMETER_EUROMATH_IDSTRING
          Denotes a string identificating the EuroMath instance.
static String PARAMETER_IS_ROOT
          Determines whether the stylesheet is processing the root nametree - the nametree that contains root element of the document.
static String PARAMETER_NAMESPACE
          The namespace of all parameters given to the stylesheet.
static String PARAMETER_PARENT_NAMESPACE
          If this nametree is not root then this parameter contains namespace of the parent nametree, otherwise it is not defined.
static String PARAMETER_PROCESSING_SOURCE
          If true then we are transforming source document.
static String PARAMETER_RESULT_DIR
          Denotes a string representing directory where the result document.
static String PARAMETER_RESULT_EXTENSION
          Denotes a string representing the extension of the document being transformed.
static String PARAMETER_RESULT_NAME
          Denotes a string representing the name of the output file that has been given as a parameter to the transformer.
protected  Transformer transformer
          The XSLT transformer instance.
 
Constructor Summary
XsltExporterBase(ExportHelper helper, String xsltUri, ExporterInfo info)
          The constructor.
XsltExporterBase(ExportHelper helper, Transformer transformer, ExporterInfo info)
          The constructor.
 
Method Summary
 void export(Source source, Result result, ExportContext context)
           Exports (transforms) the document from a single namespace and writes it to the result.
protected static void fillParameters(Transformer transformer, ExportContext context)
          Fills the transformer with all neccesary parameters.
 ExporterInfo getInfo()
          Returns information about the exporter.
 Map<String,Object> getProperties()
          Properties that drives the export process.
static XsltExporterBase newFromConfig(ExportHelper helper, sk.uniba.euromath.config.bind.StylesheetType xslt, ExporterInfo info)
          Constructs exporter from given config item.
static XsltExporterBase newIdentity(ExportHelper helper, ExporterInfo info)
          Constructs identity exporter.
 Object offerObject()
           When the exporter accepts the ObjectSource but wants to provide an object as a result to the exporter E (for example it wants E to draw something on a certain instance of Graphics), then return non-null value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

transformer

protected final Transformer transformer
The XSLT transformer instance.


helper

protected final ExportHelper helper
Helper object for exporter.


info

protected final ExporterInfo info
Info object.


PARAMETER_NAMESPACE

public static final String PARAMETER_NAMESPACE
The namespace of all parameters given to the stylesheet.

See Also:
Constant Field Values

PARAMETER_IS_ROOT

public static final String PARAMETER_IS_ROOT
Determines whether the stylesheet is processing the root nametree - the nametree that contains root element of the document. Boolean value.

See Also:
Constant Field Values

PARAMETER_DOCUMENT_NAME

public static final String PARAMETER_DOCUMENT_NAME
Denotes a string representing the name of the document being translated. It does not contain path to the document nor the document extension. String value.

See Also:
Constant Field Values

PARAMETER_DOCUMENT_EXTENSION

public static final String PARAMETER_DOCUMENT_EXTENSION
Denotes a string representing the extension of the document being transformed. The string is empty if the source XML file has no extension. If there is an extension, its first character is a dot. String value.

See Also:
Constant Field Values

PARAMETER_DOCUMENT_DIR

public static final String PARAMETER_DOCUMENT_DIR
Denotes a string representing directory where the document is stored. URI address, always ending with '/'.

See Also:
Constant Field Values

PARAMETER_RESULT_NAME

public static final String PARAMETER_RESULT_NAME
Denotes a string representing the name of the output file that has been given as a parameter to the transformer. The file extension (the character string that terminate the file name, after a dot) is not part of that string, nor is the path to the file. String value. Empty string if transforming for an on-screen renderer.

See Also:
Constant Field Values

PARAMETER_RESULT_EXTENSION

public static final String PARAMETER_RESULT_EXTENSION
Denotes a string representing the extension of the document being transformed. The string is empty if the output file name has no extension, or if the transformer feeds on-screen renderer. If there is an extension, its first character is a dot. String value.

See Also:
Constant Field Values

PARAMETER_RESULT_DIR

public static final String PARAMETER_RESULT_DIR
Denotes a string representing directory where the result document. URI address, always ending with '/'.

See Also:
Constant Field Values

PARAMETER_EUROMATH_IDSTRING

public static final String PARAMETER_EUROMATH_IDSTRING
Denotes a string identificating the EuroMath instance. The string represents a printable product identifier, such as " EuroMath2-1.1.9". String value.

See Also:
Constant Field Values

PARAMETER_PARENT_NAMESPACE

public static final String PARAMETER_PARENT_NAMESPACE
If this nametree is not root then this parameter contains namespace of the parent nametree, otherwise it is not defined.

See Also:
Constant Field Values

PARAMETER_PROCESSING_SOURCE

public static final String PARAMETER_PROCESSING_SOURCE
If true then we are transforming source document. If false then we are processing an output of some exporter.

See Also:
Constant Field Values
Constructor Detail

XsltExporterBase

public XsltExporterBase(ExportHelper helper,
                        String xsltUri,
                        ExporterInfo info)
                 throws ExportException
The constructor. Take care when subclassing: it calls super() constructor.

Parameters:
helper - the helper object.
xsltUri - location of the xslt script, relative to the plugin root.
info - info object about this exporter. It must not support object input nor output.
Throws:
ExportException - if object initialization fails.

XsltExporterBase

public XsltExporterBase(ExportHelper helper,
                        Transformer transformer,
                        ExporterInfo info)
The constructor. Take care when subclassing: it calls super() constructor.

Parameters:
helper - the helper object.
transformer - the transformer instance.
info - information about this exporter. It must not support object input nor output.
Method Detail

newIdentity

public static XsltExporterBase newIdentity(ExportHelper helper,
                                           ExporterInfo info)
                                    throws ExportException
Constructs identity exporter.

Parameters:
helper - the helper object.
info - all namespaces that this stylesheet may ever produce.
Returns:
the instance of identity exporter.
Throws:
ExportException - if construction fails.

newFromConfig

public static XsltExporterBase newFromConfig(ExportHelper helper,
                                             sk.uniba.euromath.config.bind.StylesheetType xslt,
                                             ExporterInfo info)
                                      throws IOException,
                                             ExportException
Constructs exporter from given config item.

Parameters:
helper - the exporter helper instance.
xslt - the XSLT definition.
info - the document class information.
Returns:
the instance of XSLT exporter.
Throws:
IOException - if I/O error occurs.
ExportException - if stylesheet is unavailable or error occured during initialization.

getProperties

public Map<String,Object> getProperties()
Description copied from interface: IExporter
Properties that drives the export process. Currently there are no properties defined, you may use this facility to introduce your own.

Specified by:
getProperties in interface IExporter
Returns:
map of properties. If some required properties are missing then the exporter may fail during the export, with the appropriate error message.

export

public void export(Source source,
                   Result result,
                   ExportContext context)
            throws ExportException
Description copied from interface: IExporter

Exports (transforms) the document from a single namespace and writes it to the result.

If the result is text or binary data and the result is instance of DOMResult or SAXResult then the result must contain one text/cdata node with the result.

If needed then Coordinator may communicate with the Exporter directly via the ObjectResult class, however the plugin may throw an exception when it does not support such return style. You can use this result style to render images in the memory and give it to the renderer (the Coordinator) directly, for example when rendering images to the PDF-FOP result type.

If result does not specify the encoding then UTF-8 should be used as default encoding. If the encoding is not supported by the result file format then any valid encoding can be used. However, Coordinator is strongly encouraged to provide the encoding whenever appropriate. If the need of encoding can be avoided then use the appropriate means to avoid it. For example if the result is DOM, SAX or if StreamResult has non- null writer.

If some required properties are missing or they have incorrect values then UnsupportedOperation exception should be thrown with appropriate error message.

If object is offered as a source then the exporter must be able to free any resources associated with the object (for example it must call dispose() on java.awt.Graphics.

Both source and result must not be closed after the export is done.

Specified by:
export in interface IExporter
Parameters:
source - the source of the transformation. identifier may be null or it may identify the datasource - previous exporter, source document etc. SAXSource: reader is never null, input source is almost always null. DOMSource: node is never null. StreamSource: at least one of StreamSource.getInputStream() and StreamSource.getReader() is not null. If they are both non-null you must select one and use it exclusively - you cannot use read from both. ObjectSource: No assumptions can be made on the value of object - this protocol is user-specific.
result - the result of the transformation. identifier may be null or you may set it to identify this exporter. SAXResult: content handler is never null, lexical handler is not used and is null. node is never null, next sibling is not used and is null. StreamResult: at least one of output stream and writer is not null. If they are both non-null you must select one and use it exclusively - you cannot write to both. ObjectResult: No assumptions can be made on the value of object - this protocol is user-specific.
context - the export context.
Throws:
ExportException - if something goes wrong in the process of transformation - an unrecoverable error. All non-fatal errors and warnings should be logged using the helper's log.

getInfo

public ExporterInfo getInfo()
Description copied from interface: IExporter
Returns information about the exporter.

Specified by:
getInfo in interface IExporter
Returns:
info object. Must be equal with the info object returned by the exporter factory.

offerObject

public Object offerObject()
Description copied from interface: IExporter

When the exporter accepts the ObjectSource but wants to provide an object as a result to the exporter E (for example it wants E to draw something on a certain instance of Graphics), then return non-null value. If this functionality is not needed then just return null - if E requires some object then it can create any object as long as it is instance of class that this exporter expects.

The consumer (the one that receives the object, i.e. this) is responsible for freeing the object if necessary (at the end of the export method), even if this function returned null.

If you want producer (the one that creates the object) to create custom instances then provide a factory object. This trick is used with http://www.uniba.sk/euromath/holder/java.awt.Graphics holder - a factory is returned that is able to produce java.awt.Graphics instances.

Specified by:
offerObject in interface IExporter
Returns:
the object instance, or null.

fillParameters

protected static void fillParameters(Transformer transformer,
                                     ExportContext context)
Fills the transformer with all neccesary parameters.

Parameters:
transformer - the transformer to feed
context - the values of parameters.


Copyright 2003-2003-2006 null. All Rights Reserved.