org.barracudamvc.core.util.dom
Class DefaultDOMWriter

java.lang.Object
  extended byorg.barracudamvc.core.util.dom.DefaultDOMWriter
All Implemented Interfaces:
DOMWriter

public class DefaultDOMWriter
extends Object
implements DOMWriter

This class provides the default implementation for writing a DOM. XMLC is used for formatting the dom. Besides output options features supplied by XMLC, supported features include pretty printing and preventing page caching (which prevents any redisplay of the page even via the back button) or setting a max-age (which generally allows for redisplay of a page via the back button, but not when revisiting the URL). So, the prevent caching and max age features are mutually exclusive. Default behavior is for default output options (obtained automatically from the current document), no pretty printing, and setting a max-age header of 0 (zero). Defaults may be modified via class static variables or overridden explicitly via constructors and/or mutators.


Field Summary
protected  String contentDisposition
           
protected  String contentType
           
static int DEFAULT_MAX_AGE
          default value for max age of rendered page, 0 (zero) unless modified at runtime
static String DEFAULT_OO_PUBLIC_ID
          default OutputOptions public id (ie.
static String DEFAULT_OO_SYSTEM_ID
          default OutputOptions system id (ie.
static boolean DEFAULT_PREVENT_CACHING
          default value for preventing caching, false unless modified at runtime
static boolean DEFAULT_PRINT_PRETTY
          default value for pretty printing, false unless modified at runtime
protected  org.enhydra.xml.io.DOMFormatter dfm
           
protected  boolean leaveWriterOpen
           
protected static org.apache.log4j.Logger logger
           
protected  int maxAge
           
protected  org.enhydra.xml.io.OutputOptions oo
           
protected  boolean preventCaching
           
protected  boolean printPretty
           
 
Constructor Summary
DefaultDOMWriter()
          Default constructor
DefaultDOMWriter(boolean printPretty)
          Public constructor.
DefaultDOMWriter(org.enhydra.xml.io.OutputOptions oo)
          Public constructor.
DefaultDOMWriter(org.enhydra.xml.io.OutputOptions ioo, boolean iprintPretty, boolean ipreventCaching, int imaxAge)
          Public constructor.
 
Method Summary
 String getContentDisposition()
          Get the content disposition
 String getContentType()
          Get the content type
static org.enhydra.xml.io.OutputOptions getDefaultOutputOptions(Document doc)
           
 boolean getLeaveWriterOpen()
          return true if the writer is configured to leave the output stream open
 org.enhydra.xml.io.OutputOptions getOutputOptions()
           
 void prepareResponse(Node node, javax.servlet.http.HttpServletResponse resp)
          Prepare the response object
 void setContentDisposition(String icontentDisposition)
          Set the content disposition (ie.
 void setContentType(String icontentType)
          Set the content type (defaults to "text/html" or "text/xml" depending on the document type
 void setLeaveWriterOpen(boolean val)
          Set true if we want to leave the writer open (ie. for multiple writes)
 void setMaxAge(int imax)
           
 void setOutputOptions(org.enhydra.xml.io.OutputOptions ioo)
           
 void setPrettyPrint(boolean val)
           
 void setPreventCaching(boolean val)
           
 void write(Node node, javax.servlet.http.HttpServletResponse resp)
          Write a DOM to a ServletResponse object.
 void write(Node node, OutputStream out)
          Write a DOM to an OutputStream.
 void write(Node node, Writer writer)
          Write a DOM to a Writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final org.apache.log4j.Logger logger

DEFAULT_OO_PUBLIC_ID

public static String DEFAULT_OO_PUBLIC_ID
default OutputOptions public id (ie. "-//W3C//DTD HTML 4.01 Transitional//EN"); if set, the default output options will use this value


DEFAULT_OO_SYSTEM_ID

public static String DEFAULT_OO_SYSTEM_ID
default OutputOptions system id (ie. "http://www.w3.org/TR/html401/loose.dtd"); if set, the default output options will use this value


DEFAULT_PRINT_PRETTY

public static boolean DEFAULT_PRINT_PRETTY
default value for pretty printing, false unless modified at runtime


DEFAULT_PREVENT_CACHING

public static boolean DEFAULT_PREVENT_CACHING
default value for preventing caching, false unless modified at runtime


DEFAULT_MAX_AGE

public static int DEFAULT_MAX_AGE
default value for max age of rendered page, 0 (zero) unless modified at runtime


dfm

protected org.enhydra.xml.io.DOMFormatter dfm

oo

protected org.enhydra.xml.io.OutputOptions oo

contentType

protected String contentType

contentDisposition

protected String contentDisposition

printPretty

protected boolean printPretty

preventCaching

protected boolean preventCaching

leaveWriterOpen

protected boolean leaveWriterOpen

maxAge

protected int maxAge
Constructor Detail

DefaultDOMWriter

public DefaultDOMWriter()
Default constructor


DefaultDOMWriter

public DefaultDOMWriter(org.enhydra.xml.io.OutputOptions oo)
Public constructor. Allows you to specify OutputOptions.

Parameters:
oo - OutputOptions to specify how the DOM should be formatted

DefaultDOMWriter

public DefaultDOMWriter(boolean printPretty)
Public constructor. Allows you to specify pretty printing.

Parameters:
printPretty - true if pretty print

DefaultDOMWriter

public DefaultDOMWriter(org.enhydra.xml.io.OutputOptions ioo,
                        boolean iprintPretty,
                        boolean ipreventCaching,
                        int imaxAge)
Public constructor. Allows you to specify output options, pretty printing and whether or not the page should be cached or the max-age header for the page (how many seconds until it expires). Note that the latter two options are mutually exclusive.

Parameters:
ioo - OutputOptions to specify how the DOM should be formatted, may be null
iprintPretty - true if pretty print
ipreventCaching - true if we want to prevent client side caching of the page
imaxAge - how many seconds until the page should expire
Method Detail

setContentType

public void setContentType(String icontentType)
Set the content type (defaults to "text/html" or "text/xml" depending on the document type


getContentType

public String getContentType()
Get the content type


setContentDisposition

public void setContentDisposition(String icontentDisposition)
Set the content disposition (ie. "inline; filename=foo.txt", defaults to null)


getContentDisposition

public String getContentDisposition()
Get the content disposition


setLeaveWriterOpen

public void setLeaveWriterOpen(boolean val)
Set true if we want to leave the writer open (ie. for multiple writes)

Specified by:
setLeaveWriterOpen in interface DOMWriter

getLeaveWriterOpen

public boolean getLeaveWriterOpen()
return true if the writer is configured to leave the output stream open

Specified by:
getLeaveWriterOpen in interface DOMWriter

prepareResponse

public void prepareResponse(Node node,
                            javax.servlet.http.HttpServletResponse resp)
                     throws IOException
Prepare the response object

Specified by:
prepareResponse in interface DOMWriter
Parameters:
node - the DOM node to be written out
resp - the HttpServletResponse object
Throws:
IOException

write

public void write(Node node,
                  javax.servlet.http.HttpServletResponse resp)
           throws IOException
Write a DOM to a ServletResponse object. This method will automatically set the content type for you.

Specified by:
write in interface DOMWriter
Parameters:
node - the DOM node to be written out
resp - the HttpServletResponse object
Throws:
IOException

write

public void write(Node node,
                  OutputStream out)
           throws IOException
Write a DOM to an OutputStream.

Specified by:
write in interface DOMWriter
Parameters:
node - the DOM node to be written out
out - the OutputStream to be written to
Throws:
IOException

write

public void write(Node node,
                  Writer writer)
           throws IOException
Write a DOM to a Writer.

Specified by:
write in interface DOMWriter
Parameters:
node - the DOM node to be written out
writer - the writer to be written to
Throws:
IOException

setPrettyPrint

public void setPrettyPrint(boolean val)

setPreventCaching

public void setPreventCaching(boolean val)

setMaxAge

public void setMaxAge(int imax)

setOutputOptions

public void setOutputOptions(org.enhydra.xml.io.OutputOptions ioo)

getOutputOptions

public org.enhydra.xml.io.OutputOptions getOutputOptions()
Since:
saw_020204_1

getDefaultOutputOptions

public static org.enhydra.xml.io.OutputOptions getDefaultOutputOptions(Document doc)


Copyright © 2004 BarracudaMVC.org All Rights Reserved.