sk.uniba.euromath.gene
Class ExportHelper

java.lang.Object
  extended by sk.uniba.euromath.gene.ExportHelper

public final class ExportHelper
extends Object

Provides the context on the document level. There is exactly one instance created for each coordinator.

Author:
Martin Vysny

Field Summary
(package private)  XMLAccess doc
          The document reference.
 
Constructor Summary
ExportHelper(XMLAccess doc)
          Creates instance of the object.
 
Method Summary
 void dispose()
          Closes this instance, deleting all temporary files created by this instance.
 void disposeOfTempFile(StreamResult result)
          Disposes of the temporary file.
 XMLAccess getDocument()
          Returns the document being exported.
 String getExtension(String namespaceURI)
          Returns the default extension for the resource.
 Messages getMessages()
          All messages (errors occured during the export process, etc) should be stored here.
 String getResourceName(String name, String namespace)
          Computes the file name of given resource, including the extension.
 ContentHandler getSaxSerializer(OutputStream os, String encoding, XMLSerializerPropertiesWidget deq)
          Returns the SAX serializer.
 File getTempFile(StreamResult result)
          Returns File instance associated with given stream result object.
 StreamResult newTempFile(String ext, boolean openStream)
          Creates new temporary file and returns stream pointing to that file.
static FileOutputStream openStream(String file)
          Tries to open the output stream onto the file.
 OutputStream requestResult(String fileName)
           Calls coordinator's requestResult() method.
static void serializeDOM(OutputStream os, String encoding, XMLSerializerPropertiesWidget deq, Node node)
          Serializes the document object model.
(package private)  void setCoordinator(ICoordinator coordinator)
          Sets the underlying instance of the coordinator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

doc

final XMLAccess doc
The document reference.

Constructor Detail

ExportHelper

ExportHelper(XMLAccess doc)
Creates instance of the object. Should be called from the CoordinatorProvider object only.

Parameters:
doc - the document being exported
Method Detail

getDocument

public XMLAccess getDocument()
Returns the document being exported.

Returns:
the document instance.

getResourceName

public String getResourceName(String name,
                              String namespace)
Computes the file name of given resource, including the extension. If no name is provided by the ResultInfo then automatic numbering is used.

Parameters:
name - the name of the resource. May be null - in such case an unique name is generated automatically.
namespace - namespace of the resource, used to guess filename extension appended to the name.
Returns:
the resource (file) name including extension, never null.

getExtension

public String getExtension(String namespaceURI)
Returns the default extension for the resource.

Parameters:
namespaceURI - the namespace identifier of the resource.
Returns:
the extension of the resource, starting with dot, or empty string if no extension is registered.

openStream

public static FileOutputStream openStream(String file)
                                   throws IOException
Tries to open the output stream onto the file. The file is overwritten. If the path does not exist then it is created.

Parameters:
file - full path to the file.
Returns:
the output stream writing into the desired file, never null.
Throws:
IOException - if the file cannot be overwritten, the path cannot be created etc.

serializeDOM

public static void serializeDOM(OutputStream os,
                                String encoding,
                                XMLSerializerPropertiesWidget deq,
                                Node node)
                         throws IOException
Serializes the document object model. Uses the DOM Level 3 Load/Save functionality, for details please see the DOM Level3 LS documentation.

Parameters:
os - send serialized document here.
encoding - the encoding of the document. If null then default is used.
deq - output format parameters. May be null - in such case it is ignored.
node - node to serialize.
Throws:
IOException - if serialization fails.

getSaxSerializer

public ContentHandler getSaxSerializer(OutputStream os,
                                       String encoding,
                                       XMLSerializerPropertiesWidget deq)
                                throws IOException
Returns the SAX serializer.

Parameters:
os - send serialized document here
encoding - the encoding of the document
deq - output format parameters
Returns:
SAX serializer in the form of content handler.
Throws:
IOException - if serializer error occurs.

newTempFile

public StreamResult newTempFile(String ext,
                                boolean openStream)
                         throws IOException
Creates new temporary file and returns stream pointing to that file.

Parameters:
ext - the extension of the file, must starting with dot. If null then default .tmp extension is used.
openStream - if true then StreamResult shall have initialized output stream field.
Returns:
the StreamResult instance.
Throws:
IOException - if temp file cannot be created.

disposeOfTempFile

public void disposeOfTempFile(StreamResult result)
                       throws IOException
Disposes of the temporary file. It closes the stream if it has been opened, and deletes the file.

Parameters:
result - the result object denoting temporary file.
Throws:
IOException - if file cannot be closed.

getTempFile

public File getTempFile(StreamResult result)
Returns File instance associated with given stream result object.

Parameters:
result - the temporary file created by this instance of helper.
Returns:
File instance or null if given result was not created by this helper instance.

dispose

public void dispose()
Closes this instance, deleting all temporary files created by this instance. After call to this method no other methods may be called.


requestResult

public OutputStream requestResult(String fileName)
                           throws IOException

Calls coordinator's requestResult() method.

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.

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.

setCoordinator

void setCoordinator(ICoordinator coordinator)
Sets the underlying instance of the coordinator.

Parameters:
coordinator - the coordinator instance.

getMessages

public Messages getMessages()
All messages (errors occured during the export process, etc) should be stored here.

Returns:
the messages instance.


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