ca.cbc.sportwire.servlet.data
Class JDOMFile

java.lang.Object
  |
  +--ca.cbc.sportwire.servlet.data.DOMFile
        |
        +--ca.cbc.sportwire.servlet.data.JDOMFile
All Implemented Interfaces:
GlobalCacheProperties, java.lang.Runnable, SportPageProperties
Direct Known Subclasses:
JDOMDB, JDOMtext

public class JDOMFile
extends DOMFile
implements SportPageProperties, java.lang.Runnable

JDOMFile: Creates a JDOM wrapper around an XML Document; this class also provides an empty getInstance method for creating a javabean that can subsequently be loaded with an arbitrary XML document.

Created: Sun Dec 16 01:18:48 EST 2001
 $Log: JDOMFile.java,v $
 Revision 1.23  2002/04/23 04:55:51  garym
 upgrade sources to jaxen 1.0RC1 api

 Revision 1.22  2002/04/19 20:38:04  garym
 released as 2.0

 Revision 1.21  2002/04/15 20:00:51  garym
 using HTMLOutputter to avoid escaping of HTML in the XML stream

 Revision 1.20  2002/04/13 05:36:02  garym
 Fixed XSL search path bug

 Revision 1.19  2002/03/23 19:46:03  garym
 escape messagetext with CDATA for all streamed jdom fields

 Revision 1.18  2002/03/13 18:12:33  garym
 Implemented longvarchar translation filter

 Revision 1.17  2002/03/04 21:40:05  garym
 updated docs

 Revision 1.16  2002/02/18 20:34:04  garym
 implement ad-hoc SQL from $sql.dom()

 Revision 1.15  2002/02/13 19:18:08  garym
 fixed postgres workaround on numeric

 Revision 1.14  2002/02/11 20:57:13  garym
 added JDOMDB to return XML from database queries

 Revision 1.13  2002/01/31 21:20:13  garym
 getRootElement returns null on errors reading xml

 Revision 1.12  2002/01/31 05:33:27  garym
 fixed bug in search for xsl files

 Revision 1.11  2002/01/29 19:33:45  garym
 fixed concurrency bug with global config

 Revision 1.10  2002/01/28 07:01:36  garym
 Implement JDOM transform caching and document parse thread.

 Revision 1.9  2002/01/27 06:39:57  garym
 Added XSL transform and XML output to JDOMFile

 Revision 1.8  2002/01/24 19:50:20  garym
 Major restructuring of beans and pagehandlers

 Revision 1.7  2002/01/16 23:09:24  garym
 Implemented the JDBC pool support and sql property beans

 Revision 1.6  2002/01/16 00:56:26  garym
 current site on cbc.ca/olympics; checkpoint release

 Revision 1.5  2002/01/15 08:28:50  garym
 implemented MRU cache for the JDOMFile objects

 Revision 1.4  2002/01/14 21:51:46  garym
 bug fixes in topics and config files migration to Extended Properties

 Revision 1.3  2002/01/09 04:28:59  garym
 Added test unit stubs and new News support

 Revision 1.2  2001/12/23 17:55:23  garym
 Allow for multiple SportPage apps on one JVM

 Revision 1.1  2001/12/16 22:01:56  garym
 fixes to default page handling


 

Version:
$Id: JDOMFile.java,v 1.23 2002/04/23 04:55:51 garym Exp $
Author:
Gary Lawrence Murphy

Field Summary
private  org.jdom.input.SAXBuilder builder
          SAXBuilder instance to use
(package private) static org.apache.log4j.Category cat
           
protected  org.jdom.Document document
           
protected  java.lang.String filename
           
private  java.lang.String saxclass
           
protected  org.apache.commons.collections.ExtendedProperties sc
           
private  java.lang.String xml
           
 
Fields inherited from interface ca.cbc.sportwire.servlet.data.SportPageProperties
BEAN_SUFFIX, BEANFACTORY_VAR, CONTEXT_VAR, DATE_VAR, DEFAULT_EXTS, DEFAULT_INDEXES, DEFAULT_PAGE_SUFFIX, DEFAULT_SAX_DRIVER_CLASS, DEFAULT_TIMEZONE, DEFAULT_TOPIC, DOM_VAR, ERROR_TEMPLATE_VAR, EXCEPTION_VAR, EXTENSIONS_VAR, FALSE, GLOBAL_VAR, HOME_PROPERTY, INCLUDE_EXTS_PROPERTY, INCLUDE_VAR, INDEX_INDICATOR_VAR, INDEX_TEMPLATE_VAR, LAYOUT_TEMPLATE_VAR, MACRO_LIB_PROPERTY, MISSING_TEMPLATE_VAR, OUTPUT_VAR, PAGE_EXPIRE, PAGE_TEMPLATE_VAR, PANIC_404_PAGE, PANIC_404_PROPERTY, PANIC_500_PAGE, PANIC_500_PROPERTY, PARAM_PARSER_VAR, PATH_VAR, REQUEST_VAR, RESPONSE_VAR, SAX_CLASS_PROPERTY, SERVLET_DEBUG, SERVLET_LOGCONF_PROPERTY, SQL_SUFFIX, TEMPLATE_PATHS_PROPERTY, TIMEZONE_PROPERTY, TRUE, URI_VAR, VELOCITY_LOGFILE_DEFAULT, VELOCITY_LOGFILE_PROPERTY, XML_EXTS, XML_EXTS_PROPERTY, XML_PATHS_PROPERTY, XML_SUFFIX, XSL_EXTS, XSL_EXTS_PROPERTY, XSL_PATHS_PROPERTY
 
Fields inherited from interface ca.cbc.sportwire.servlet.data.GlobalCacheProperties
CACHE_DEFAULT_PERIOD, CACHE_DEFAULT_TIMEOUT, CACHE_PERIOD, CACHE_TIMEOUT, MRU_PROPERTY, MRU_VAR, TTL_PROPERTY, TTL_VAR
 
Constructor Summary
protected JDOMFile(org.apache.velocity.context.Context context)
           
protected JDOMFile(org.apache.commons.collections.ExtendedProperties sc)
           
protected JDOMFile(org.apache.commons.collections.ExtendedProperties sc, org.jdom.Document doc)
           
protected JDOMFile(org.apache.commons.collections.ExtendedProperties sc, java.lang.String filename)
           
 
Method Summary
 java.lang.Object getDocument()
          Get the JDOM Document object; setDocument runs a one-shot thread to do an advance parse/fetch; if the parsing is not complete, we wait for it here; when given the go signal, if the document is still undefined, we return a null.
 java.lang.String getFilename()
          Get the value of filename.
static JDOMFile getInstance(org.apache.velocity.context.Context context)
          getInstance: Creates a JDOMFile object with no document defined; does not cache the object.
static JDOMFile getInstance(org.apache.velocity.context.Context context, java.lang.String filename)
          getInstance: Extracts the global properties from the context and calls that getInstance method.
static JDOMFile getInstance(org.apache.commons.collections.ExtendedProperties sc)
          getInstance: calls the (sc,file) version with a null filename)
static JDOMFile getInstance(org.apache.commons.collections.ExtendedProperties sc, java.lang.String filename)
          getInstance: Returns the JDOM object if the filename is null, otherwise attempts to find a cached JDOM object in the TTL cache or creates a new one, loads the Document and then stashes the new object in the TTL.
 java.lang.Object getRootElement()
          getRootElement: Convenience method to get the first element of the embedded DOM document.
protected  java.lang.String getSaxclass()
          Get the value of saxclass.
 java.lang.String getXml()
          getXml: returns the object as an XML string; used in velocity as $dom.xml
 void getXml(java.io.Writer out)
          getXml: write the xml to a specific writer
 void run()
          run is the Thread method to parse the file and create the document.
 void setDocument(java.lang.String filename)
          setDocument: Tests for the existence and permissions of the file before spawning the thread to read it.
protected  void setFilename(java.lang.String v)
          the filename can only be set once because this string is used to index the object in the persistent TTL cache.
protected  void setSaxclass(java.lang.String v)
          Set the value of saxclass.
 JDOMFile transform(java.io.File xsl)
          transform: If all goes well, this will either find a previous request for this transform and return that object from the cache, or it will transform this object according to the supplied XSL File and return and cache that.
 JDOMFile transform(java.lang.String relxslfile)
          transform will search for the XSL file according to the properties (XSL_PATHS_PROPERTY) and extensions (XSL_EXTS_PROPERTY) and then apply the transform creating a new JDOMFile object.
 java.util.List xpath(java.lang.String path)
          xpath implements the Jaxen XPath extension to JDOM; XPath support is apparently not perfect, but it's probably suitable for our purposes, and the interface is so simple, each upgrade to Jaxen will automatically upgrade all templates using XPath methods.
 java.util.List xpath(java.lang.String path, org.jdom.Element node)
          xpath: apply the xpath to the specified node.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

cat

static org.apache.log4j.Category cat

builder

private org.jdom.input.SAXBuilder builder
SAXBuilder instance to use

sc

protected org.apache.commons.collections.ExtendedProperties sc

filename

protected java.lang.String filename

document

protected org.jdom.Document document

saxclass

private java.lang.String saxclass

xml

private java.lang.String xml
Constructor Detail

JDOMFile

protected JDOMFile(org.apache.velocity.context.Context context)
            throws java.io.FileNotFoundException,
                   java.io.IOException

JDOMFile

protected JDOMFile(org.apache.commons.collections.ExtendedProperties sc)
            throws java.io.FileNotFoundException,
                   java.io.IOException

JDOMFile

protected JDOMFile(org.apache.commons.collections.ExtendedProperties sc,
                   java.lang.String filename)
            throws java.io.FileNotFoundException,
                   java.io.IOException

JDOMFile

protected JDOMFile(org.apache.commons.collections.ExtendedProperties sc,
                   org.jdom.Document doc)
            throws java.io.FileNotFoundException,
                   java.io.IOException
Method Detail

getFilename

public java.lang.String getFilename()
Get the value of filename.
Returns:
String value of filename.

setFilename

protected void setFilename(java.lang.String v)
the filename can only be set once because this string is used to index the object in the persistent TTL cache.
Parameters:
v - Value to assign to filename.

getDocument

public java.lang.Object getDocument()
Get the JDOM Document object; setDocument runs a one-shot thread to do an advance parse/fetch; if the parsing is not complete, we wait for it here; when given the go signal, if the document is still undefined, we return a null. This method is synchronized so we can have all reading threads wait until the doc is defined and just notify the first of them; otherwise the second one in would never get notified (notice was eaten by the first one through the gate).
Overrides:
getDocument in class DOMFile
Returns:
org.jdom.Document value as an Object

getRootElement

public java.lang.Object getRootElement()
getRootElement: Convenience method to get the first element of the embedded DOM document.
Overrides:
getRootElement in class DOMFile
Returns:
an Object value

getSaxclass

protected java.lang.String getSaxclass()
Get the value of saxclass.
Returns:
String value of saxclass.

setSaxclass

protected void setSaxclass(java.lang.String v)
Set the value of saxclass.
Parameters:
v - Value to assign to saxclass.

getInstance

public static JDOMFile getInstance(org.apache.velocity.context.Context context)
                            throws java.io.FileNotFoundException,
                                   java.io.IOException
getInstance: Creates a JDOMFile object with no document defined; does not cache the object. It actually just extracts the global properties from the context and calls that version of getInstance.
Parameters:
context - a Context value
Returns:
a JDOMFile value
Throws:
java.io.FileNotFoundException - if an error occurs
java.io.IOException - if an error occurs

getInstance

public static JDOMFile getInstance(org.apache.velocity.context.Context context,
                                   java.lang.String filename)
                            throws java.io.FileNotFoundException,
                                   java.io.IOException
getInstance: Extracts the global properties from the context and calls that getInstance method.
Parameters:
context - a Context value
filename - a String value
Returns:
a JDOMFile value
Throws:
java.io.FileNotFoundException - if an error occurs
java.io.IOException - if an error occurs

getInstance

public static JDOMFile getInstance(org.apache.commons.collections.ExtendedProperties sc)
                            throws java.io.FileNotFoundException,
                                   java.io.IOException
getInstance: calls the (sc,file) version with a null filename)
Parameters:
sc - an ExtendedProperties value
Returns:
a JDOMFile value
Throws:
java.io.FileNotFoundException - if an error occurs
java.io.IOException - if an error occurs

getInstance

public static JDOMFile getInstance(org.apache.commons.collections.ExtendedProperties sc,
                                   java.lang.String filename)
                            throws java.io.FileNotFoundException,
                                   java.io.IOException
getInstance: Returns the JDOM object if the filename is null, otherwise attempts to find a cached JDOM object in the TTL cache or creates a new one, loads the Document and then stashes the new object in the TTL.
Parameters:
sc - a ExtendedProperties value
filename - a String value
Returns:
a JDOMFile value
Throws:
java.io.FileNotFoundException - if an error occurs
java.io.IOException - if an error occurs

run

public void run()
run is the Thread method to parse the file and create the document. This is only called once, when the constructor is given a valid filename.
Specified by:
run in interface java.lang.Runnable

setDocument

public void setDocument(java.lang.String filename)
                 throws java.io.FileNotFoundException,
                        java.io.IOException
setDocument: Tests for the existence and permissions of the file before spawning the thread to read it.
Overrides:
setDocument in class DOMFile
Parameters:
filename - a String value
Throws:
java.io.FileNotFoundException - if an error occurs
java.io.IOException - if an error occurs

transform

public JDOMFile transform(java.lang.String relxslfile)
transform will search for the XSL file according to the properties (XSL_PATHS_PROPERTY) and extensions (XSL_EXTS_PROPERTY) and then apply the transform creating a new JDOMFile object.
Parameters:
relxslfile - a String value
Returns:
a JDOMFile value

transform

public JDOMFile transform(java.io.File xsl)
transform: If all goes well, this will either find a previous request for this transform and return that object from the cache, or it will transform this object according to the supplied XSL File and return and cache that. Note that if you chain this method (transform a transform) all intermediate documents will be added to the TTL cache.
Parameters:
xsl - a File value set to the absolute file.
Returns:
a JDOMFile or null if an error occurs.

getXml

public java.lang.String getXml()
getXml: returns the object as an XML string; used in velocity as $dom.xml
Returns:
a String value

getXml

public void getXml(java.io.Writer out)
getXml: write the xml to a specific writer
Parameters:
out - a Writer value

xpath

public java.util.List xpath(java.lang.String path)
xpath implements the Jaxen XPath extension to JDOM; XPath support is apparently not perfect, but it's probably suitable for our purposes, and the interface is so simple, each upgrade to Jaxen will automatically upgrade all templates using XPath methods.
Parameters:
path - a String XPath
Returns:
a List of nodes matching the path or null if error

xpath

public java.util.List xpath(java.lang.String path,
                            org.jdom.Element node)
xpath: apply the xpath to the specified node. this method does not work. and may not be all that useful anyway.
Parameters:
path - a String value
node - an Element value
Returns:
a List of nodes or null if Jaxen error