sk.uniba.euromath.gene.builtin
Class LaTeXCoordinator

java.lang.Object
  extended by sk.uniba.euromath.gene.builtin.LaTeXCoordinator
All Implemented Interfaces:
ICoordinator

public class LaTeXCoordinator
extends Object
implements ICoordinator

Implements the LaTeX output class functionality.

Default result object

Since the LaTeX format is a character stream format all exporters general output should be a character stream. However, the result requested from the exporters is not StreamResult- the SAXResult is used instead. That is because the exporter can emit the emp:mark element. The element is used to mark entrypoints to nametree with another namespace - it should be a simple 1:1 copy from source document fragment.

The coordinator thus expects the http://www.uniba.sk/euromath/holder/latex and http://www.uniba.sk/euromath/holder/eps namespaces transmitted via SAXSource. Coordinator produces LaTeX StreamOutput.

Specialities

None.

Author:
Martin Vysny

Constructor Summary
LaTeXCoordinator(ExportHelper helper)
          Constructs the instance of the coordinator.
 
Method Summary
 void alterContext(IExporter exporter, ExportContext context, NamespacePath path)
           May be called anytime during the export process.
 IConfigurator configure()
          Configures the coordinator for exporting a particular document.
 void dispose()
          Disposes of this coordinator.
 void finishExport()
          Finalizes the export of the document.
 ExportGraphBuilder getGraphBuilder()
          Called after the configure() method.
 ExportHelper getHelper()
          Returns helper instance provided to the coordinator.
(package private) static Map<String,EnumSet<SourceEnum>> getNamespaces()
          Returns namespaces accepted.
 EnumSet<SourceEnum> getSource(String namespace)
           Specifies the input types that the coordinator's partialResultEvent method is able to receive from exporters.
 TransformGraph getTransformationGraph()
          Called only if getGraphBuilder() returned null.
 Object offerObject(String namespace)
           When the coordinator accepts the ObjectSource but wants to provide an object as a result to the exporter E (for example it wants E to draw something in a certain instance of Graphics), then return non-null value.
 Source partialResultEvent(DocumentFragment processed, NamespacePath path, Source source, String sourceNamespace, CoordinatorInputKey key)
          Using this method the coordinator is queried if it wants to modify the final result of one exporter pipe.
 OutputStream requestResult(String fileName)
          May be used when exporter wishes to write additional files as its output (an image that is referenced by XML produced by the exporter for example).
 Result startExport(URLDir root, String fileName, String systemId)
           Initiates the export itself.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LaTeXCoordinator

public LaTeXCoordinator(ExportHelper helper)
Constructs the instance of the coordinator.

Parameters:
helper - the export helper instance
Method Detail

configure

public IConfigurator configure()
Description copied from interface: ICoordinator
Configures the coordinator for exporting a particular document. This includes querying the user for some coordinator-specific information, like output encoding, the style of produced document etc.

Specified by:
configure in interface ICoordinator
Returns:
a configurator instance or null if the coordinator does not need to be configured.

getGraphBuilder

public ExportGraphBuilder getGraphBuilder()
Description copied from interface: ICoordinator
Called after the configure() method. Returns configured instance of the graph builder.

Specified by:
getGraphBuilder in interface ICoordinator
Returns:
configured graph builder instance. May be null - in such case the getTransformationChain() is used to determine the exporter graph.

getTransformationGraph

public TransformGraph getTransformationGraph()
Description copied from interface: ICoordinator
Called only if getGraphBuilder() returned null. Describes the exporter graph directly. Returns non-empty map that maps each namespace present in the document to a TransformationInfo instance describing exporter chain exporting the namespace.

Specified by:
getTransformationGraph in interface ICoordinator
Returns:
object describing the exporter connections. If null then the exporting process fails.

getHelper

public ExportHelper getHelper()
Description copied from interface: ICoordinator
Returns helper instance provided to the coordinator.

Specified by:
getHelper in interface ICoordinator
Returns:
helper instance given to the coordinator.

getSource

public EnumSet<SourceEnum> getSource(String namespace)
Description copied from interface: ICoordinator

Specifies the input types that the coordinator's partialResultEvent method is able to receive from exporters. If it accepts multiple types then the output with highest priority is picked. ObjectSource has the highest priority, followed by SAX, DOM and Stream.

Warning: this method result must be consistent with result returned by the CoordinatorInfo object instance for this coordinator class!

Specified by:
getSource in interface ICoordinator
Parameters:
namespace - the namespace of the fragment that this coordinator may receive.
Returns:
all source types that the coordinator accepts, or null if coordinator does not accept fragments with given namespace.

getNamespaces

static Map<String,EnumSet<SourceEnum>> getNamespaces()
Returns namespaces accepted.

Returns:
namespaces accepted.

finishExport

public void finishExport()
                  throws ExportException,
                         IOException
Description copied from interface: ICoordinator
Finalizes the export of the document. It should finish writing all files, close all opened streams and files.

Specified by:
finishExport in interface ICoordinator
Throws:
ExportException - if something goes wrong
IOException - if i/o error occurs.

startExport

public Result startExport(URLDir root,
                          String fileName,
                          String systemId)
                   throws ExportException,
                          IOException
Description copied from interface: ICoordinator

Initiates the export itself. Coordinator must return a result where exporters results are written.

Coordinator is responsible to convert exporter's output (in the partialResultEvent() method) to Source instance compatible with the result object returned by this method. Failure to do so results in an ExportException during the export. Some kinds of sources can be converted automatically; for reference please see SourceEnum's convert method.

Specified by:
startExport in interface ICoordinator
Parameters:
root - the directory where the file will be exported. Here the primary result (PDF file, HTML file, whatever) will be stored. Coordinator may create additional directories and files whenever needed (for example png/jpg images referenced by the primary html file etc).
fileName - the name of the primary file being exported.
systemId - system identifier of the primary output file, constructed from root and fileName parameters for convenience. A OS-dependent identifier, suitable to be passed to File object.
Returns:
result where the final exporter product is written. A final product of exporters is stored here; all emp:mark elements are replaced by transformation results. DOM source is given as a DOM node containing the whole document, SAX source gives result on-the-fly.
Throws:
ExportException - if something goes wrong
IOException - if i/o error occurs.

dispose

public void dispose()
Description copied from interface: ICoordinator
Disposes of this coordinator. It should dispose its helper instance.

Specified by:
dispose in interface ICoordinator

partialResultEvent

public Source partialResultEvent(DocumentFragment processed,
                                 NamespacePath path,
                                 Source source,
                                 String sourceNamespace,
                                 CoordinatorInputKey key)
                          throws ExportException,
                                 IOException
Description copied from interface: ICoordinator
Using this method the coordinator is queried if it wants to modify the final result of one exporter pipe. If yes then non-null value must be returned - this Source object shall be used as a replacement of the result. The source parameter (or the result of the method if non-null) is then stored into memory. When all exporters finish, these stored pieces are put together and finally transmitted to the coordinator again using the export() call.

Specified by:
partialResultEvent in interface ICoordinator
Parameters:
processed - this document fragment is being processed and the Result holds part (or whole) result of the fragment processing.
path - the namespace path to the parent product.
source - contains the result of a nametree processing. If the systemId is not null then it is a system-dependent local filesystem path to a file that holds the content of this result. Warning: instance of SAXSource is a live instance - if you call parse on the XMLReader instance then it reads the whole result. If this result is not stored and returned in a Source then it is lost. You may convert it to the DOMSource, make necessary adjustments and then convert back to the SAXSource and return. You may also construct new XMLReader (reading from the old source and making adjustments on-the-fly) and return it.
sourceNamespace - the namespace of the source.
key - uniquely identifies the pipe from exporter to the coordinator.
Returns:
If null then returned source is put into the 'big picture' as-is. If not null then the content of the source is ignored and the returned Source instance is used instead.
Throws:
ExportException - if error occurs during the source processing
IOException - if error occurs during reading the source.

requestResult

public OutputStream requestResult(String fileName)
                           throws IOException
Description copied from interface: ICoordinator
May be used when exporter wishes to write additional files as its output (an image that is referenced by XML produced by the exporter for example). It is caller's responsibility to close opened stream.

Specified by:
requestResult in interface ICoordinator
Parameters:
fileName - the name of the file being created. The coordinator may ignore the filename if it is not part of the result file (for example when a PNG image is embedded in result PDF file). Coordinator may change the filename if a file with this name already exists. If null or empty string, coordinator may generate any name.
Returns:
opened output stream, never null.
Throws:
IOException - if i/o error occurs.

offerObject

public Object offerObject(String namespace)
Description copied from interface: ICoordinator

When the coordinator accepts the ObjectSource but wants to provide an object as a result to the exporter E (for example it wants E to draw something in 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 ICoordinator
Parameters:
namespace - the namespace that communicates using the Object source/result kind.
Returns:
the object instance, or null.

alterContext

public void alterContext(IExporter exporter,
                         ExportContext context,
                         NamespacePath path)
Description copied from interface: ICoordinator

May be called anytime during the export process. By modifying given context values the coordinator may force the GENE engine to report another context to an exporter.

If you don't want to override GENE default behaviour just use an empty implementation.

Specified by:
alterContext in interface ICoordinator
Parameters:
exporter - this exporter is about to be executed with given context object. Never null. The coordinator must NOT call the IExporter.export(Source, Result, ExportContext) method.
context - current context object. Never null.
path - current namespace path. It must NOT be altered. Never null.


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