jacquard 1.12.0 by The Web Engineering Factory and Toolworks

uk.co.weft.domutil
Class DocumentGeneratorImpl

java.lang.Object
  extended byuk.co.weft.domutil.DocumentGeneratorImpl
All Implemented Interfaces:
DocumentGenerator
Direct Known Subclasses:
DayView, JustFetchGenerator, ResultsGenerator, XHTMLDocumentGenerator

public class DocumentGeneratorImpl
extends java.lang.Object
implements DocumentGenerator

a simple DocumentGenerator implementation which can be specialised.

Recognises the following configuration property:

allow_xsl_from_context
Boolean: if true, allow the URL of an XSL stylesheet to be passed in the context. Optional. Defaults to false because this may have security implications.
debug
Boolean: if true, print debugging messages to System.err. Optional. Defaults to false.
document_type_name
String: name of the Document Type to use. Optional. No default.
document_type_public_id
String: Public ID of the document type to use. Optional. Read only if
document_type_system_id
String: System ID of the document type to use. Optional. Read only if document_type_name is also set. No default.
dom_implementation_class
String: the name of the org.w3c.dom.DOMImplementation class to use. The class named must obviously be in the Web app's classpath. Optional. Defaults to org.apache.xerces.dom.DOMImplementationImpl.
root_generator_class
String: the class name of an ElementGenerator with a zero-arg constructor which serves as the root generator for this document. Experimental. Optional. No default.
xml_namespace_uri
String: The AML namespace URI to use. Optional. No default.

Version:
$Revision: 1.15.4.7 $ This revision: $Author: simon $
Author:
Simon Brooke

Field Summary
protected  boolean allowXSLFromContext
          do we allow the XSL stylesheet to be specified in the context? Normally we don't!
protected  boolean debug
          whether or not I'm in debug mode; if I am I may print debugging messages to System.err
protected  DocumentType doctype
          My document type
protected  java.lang.String dtdPublicId
          the public Id to use when generating a DTD declaration, if any
protected static java.lang.String DTDPUBLICIDCONFIGTOKEN
          a token on which I shall seek in my config the value of the DTD public identifier to use, if I generate a DTD declaration
protected  java.lang.String dtdQualifiedName
          the qualified name to use when generating a DTD declaration, it any
protected static java.lang.String DTDQUALIFIEDNAMECONFIGTOKEN
          a token on which I shall seek in my config the value of the DTD qualified name to use, if I generate a DTD declaration
protected  java.lang.String dtdSystemId
          the system Id to use when generating a DTD declaration, if any
protected static java.lang.String DTDSYSTEMIDCONFIGTOKEN
          a token on which I shall seek in my config the value of the DTD system identifier to use, if I generate a DTD declaration
protected  boolean generateDTD
          whether or not to generate a DTD declaration
 boolean genxml
          Deprecated. no longer used - other people's serializer's don't need this!
protected  NodeGenerator rootGenerator
          the object which generates my root node.
protected  java.lang.String rootName
          the name of the document root element when created.
protected  java.lang.String xmlns
          the default XML namespace URI - none
protected  java.lang.String xslStylesheetName
          the name of the XSL stylesheet I am to use, if any
 
Constructor Summary
DocumentGeneratorImpl()
           
 
Method Summary
protected  boolean accept(Context context)
          Whether or not I want to accept this context.
protected  java.lang.String cleanString(java.lang.String val)
          clean a string, using Printer.cleanString to do the real work
 void destroy()
          Do any cleaning up I need to do when my Servlet shuts down
 Document generate(Context context)
          generate a document.
protected  java.lang.String getNamespaceURI(Context context)
          return the value of xml_namespace_uri in the current context, or, if none, the value in the original configuration
 NodeGenerator getRootGenerator()
           
 NodeGenerator getRootGenerator(Context c)
          get my root node generator object
 java.lang.String getTransformURL(Context context)
          get the URL of my preferred XSL transform as a String.
 void init(Context config)
          Initialise me with configuration from this context.
 void init(javax.servlet.ServletConfig config)
          Deprecated. From Jacquard 2.0, a ServletConfig won't be passed. Specialise init( Context) instead.
 void setRootGenerator(NodeGenerator rootGenerator)
          sets the default root generator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DTDPUBLICIDCONFIGTOKEN

protected static final java.lang.String DTDPUBLICIDCONFIGTOKEN
a token on which I shall seek in my config the value of the DTD public identifier to use, if I generate a DTD declaration

See Also:
Constant Field Values

DTDSYSTEMIDCONFIGTOKEN

protected static final java.lang.String DTDSYSTEMIDCONFIGTOKEN
a token on which I shall seek in my config the value of the DTD system identifier to use, if I generate a DTD declaration

See Also:
Constant Field Values

DTDQUALIFIEDNAMECONFIGTOKEN

protected static final java.lang.String DTDQUALIFIEDNAMECONFIGTOKEN
a token on which I shall seek in my config the value of the DTD qualified name to use, if I generate a DTD declaration

See Also:
Constant Field Values

genxml

public boolean genxml
Deprecated. no longer used - other people's serializer's don't need this!

do I generate XML or not?


doctype

protected DocumentType doctype
My document type


rootGenerator

protected NodeGenerator rootGenerator
the object which generates my root node. TODO: this should probably be private, but that would break a fair bit of legacy code. Don't use it directly; use getters and setters


dtdPublicId

protected java.lang.String dtdPublicId
the public Id to use when generating a DTD declaration, if any


dtdQualifiedName

protected java.lang.String dtdQualifiedName
the qualified name to use when generating a DTD declaration, it any


dtdSystemId

protected java.lang.String dtdSystemId
the system Id to use when generating a DTD declaration, if any


rootName

protected java.lang.String rootName
the name of the document root element when created. As this is immediately replaced by the node generated by the root generator, it should never be seen.


xmlns

protected java.lang.String xmlns
the default XML namespace URI - none


xslStylesheetName

protected java.lang.String xslStylesheetName
the name of the XSL stylesheet I am to use, if any


allowXSLFromContext

protected boolean allowXSLFromContext
do we allow the XSL stylesheet to be specified in the context? Normally we don't!


debug

protected boolean debug
whether or not I'm in debug mode; if I am I may print debugging messages to System.err


generateDTD

protected boolean generateDTD
whether or not to generate a DTD declaration

Constructor Detail

DocumentGeneratorImpl

public DocumentGeneratorImpl()
Method Detail

setRootGenerator

public void setRootGenerator(NodeGenerator rootGenerator)
                      throws InitialisationException
sets the default root generator

Parameters:
rootGenerator - The rootGenerator to set.
Throws:
throws - InitialisationException if the generator passed isn't suitable
InitialisationException

getRootGenerator

public NodeGenerator getRootGenerator()
Returns:
Returns the default root generator.
See Also:
getRootGenerator(Context)

getRootGenerator

public NodeGenerator getRootGenerator(Context c)
                               throws GenerationException
get my root node generator object

Parameters:
c - the context in which I am generating. Ignored, but specialisations could use this to select alternate generators based on values in the context
Returns:
my root generator
Throws:
GenerationException - if rootGenerator is null.

getTransformURL

public java.lang.String getTransformURL(Context context)
                                 throws GenerationException
get the URL of my preferred XSL transform as a String. Default behaviour is to return the value of the xsl_stylesheet magic token in the context if and only if allow_xsl_from_context was true in config, else that which was in the Servlet configuration. Specialise if you want something different.

Specified by:
getTransformURL in interface DocumentGenerator
Parameters:
context - the context for the present service
Throws:
GenerationException

destroy

public void destroy()
Do any cleaning up I need to do when my Servlet shuts down

Specified by:
destroy in interface DocumentGenerator

generate

public Document generate(Context context)
                  throws GenerationException,
                         DOMException
generate a document.

Specified by:
generate in interface DocumentGenerator
Parameters:
context - the context for this request
Returns:
a document, or null if I can't sensibly generate one in this context
Throws:
GenerationException - if application layer code breaks
DOMException - if anything in Xerces breaks

init

public void init(Context config)
          throws InitialisationException
Initialise me with configuration from this context. Specialisation: reads allow_xsl_from_context, xml_namespace_uri, root_element_name from conffiguration; read and initilise dom_implementation_class. Also reads document_type_name, document_type_public_id and document_type_system_id and, if document_type_name is non-null, creates a DocumentType object.

Specified by:
init in interface DocumentGenerator
Parameters:
config - my initial configuration
Throws:
InitialisationException

init

public void init(javax.servlet.ServletConfig config)
          throws javax.servlet.ServletException
Deprecated. From Jacquard 2.0, a ServletConfig won't be passed. Specialise init( Context) instead.

Initialise me with the configuration of my servlet, if any. Specialisation: read allow_xsl_from_context property

Throws:
javax.servlet.ServletException

getNamespaceURI

protected java.lang.String getNamespaceURI(Context context)
                                    throws GenerationException
return the value of xml_namespace_uri in the current context, or, if none, the value in the original configuration

Parameters:
context - the context for the current service
Throws:
GenerationException - never thrown, but specialisations might want to.

accept

protected boolean accept(Context context)
Whether or not I want to accept this context. Useful if you are chaining generators. Specialise this if you may not want to accept the context, the default version just returns true.

Parameters:
context - the context of this service
Returns:
true if I think I can sensibly generate a document in this context, false otherwise.

cleanString

protected java.lang.String cleanString(java.lang.String val)
clean a string, using Printer.cleanString to do the real work


jacquard 1.12.0 by The Web Engineering Factory and Toolworks