Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.opencms.template
Class A_CmsXmlContent  view A_CmsXmlContent download A_CmsXmlContent.java

java.lang.Object
  extended bycom.opencms.template.A_CmsXmlContent
All Implemented Interfaces:
java.lang.Cloneable, I_CmsContent, com.opencms.boot.I_CmsLogChannels, I_CmsXmlContent
Direct Known Subclasses:
CmsXmlControlFile, CmsXmlTemplateFile

public abstract class A_CmsXmlContent
extends java.lang.Object
implements I_CmsXmlContent, com.opencms.boot.I_CmsLogChannels

Abstract class for OpenCms files with XML content.

This class implements basic functionality for OpenCms XML files. For each XML file content type (e.g. XML template files, XML control files, XML news article files, ...) a customized class extending this abstract class has to be implemented.

The functionality of this class is:

After creating a new instance of the children of this class it has to be initialized by calling the init method.

While initializing the content of the given file will be read and parsed with the XML parser. After this, the parsed document will be scanned for INCLUDE tags and for DATA tags. DATA tags will be stored in an internal Hashtable an can easily be accessed by the getData methods or by a PROCESS tag.

Extending classes have to implement the abstract methods getXmlDocumentTagName() and getContentDescription().

Version:
$Revision: 1.72 $ $Date: 2003/02/17 10:02:55 $

Field Summary
private static boolean C_DEBUG
          Boolean for additional debug output control
static java.lang.String C_ERR_NODATABLOCK
          Error message for bad <PROCESS> tags
static java.lang.String C_MINIMUM_CLASSNAME
          The classname of the super XML content class
static java.lang.Class[] C_PARAMTYPES_HANDLING_METHODS
          parameter types for XML node handling methods.
static java.lang.Class[] C_PARAMTYPES_USER_METHODS
          parameter types for user methods called by METHOD tags
private static boolean C_PRINTNODES
          Flag to enable / disable printNode() method
protected static int C_REGISTER_FIRST_RUN
          constant for registering handling tags
protected static int C_REGISTER_MAIN_RUN
          constant for registering handling tags
static java.lang.String C_TEMPLATE_EXTENSION
          Constant extension of the template-files.
static java.lang.String C_TEMPLATEPATH
          Constant pathname, where to find templates
private  java.util.Hashtable m_blocks
          All datablocks in DOM format
protected  com.opencms.file.CmsObject m_cms
          CmsObject Object for accessing resources
private  org.w3c.dom.Document m_content
          DOM representaion of the template content.
private static java.util.Hashtable m_filecache
          Cache for parsed documents
private  java.lang.String m_filename
          Filename this template was read from
protected  java.util.Hashtable m_firstRunTags
          This Hashtable contains some XML tags as keys and the corresponding methods as values.
private  java.util.Vector m_includedTemplates
          Reference All included A_CmsXmlContents
protected  java.util.Vector m_knownTags
          All XML tags known by this class.
protected  java.util.Hashtable m_mainProcessTags
          This Hashtable contains some XML tags as keys and the corresponding methods as values.
private  java.lang.String m_newEncoding
           
private static I_CmsXmlParser parser
          XML parser
 
Fields inherited from interface com.opencms.boot.I_CmsLogChannels
C_FLEX_CACHE, C_FLEX_LOADER, C_LOGGING, C_MODULE_CRITICAL, C_MODULE_DEBUG, C_MODULE_INFO, C_OPENCMS_CACHE, C_OPENCMS_CRITICAL, C_OPENCMS_CRONSCHEDULER, C_OPENCMS_DEBUG, C_OPENCMS_ELEMENTCACHE, C_OPENCMS_INFO, C_OPENCMS_INIT, C_OPENCMS_POOL, C_OPENCMS_STATICEXPORT, C_OPENCMS_STREAMING, C_PREPROCESSOR_IS_LOGGING
 
Constructor Summary
A_CmsXmlContent()
          Constructor for creating a new instance of this class
 
Method Summary
protected  void callAllUncalledMethodsSoThatEclipseDoesntComplainAboutThem()
          This method is just a hack so that the Eclise IDE will not show the methods listed here as warnings when the "unused private methods" option is selected, since they are called only using reclection API.
protected  java.lang.Object callUserMethod(java.lang.String methodName, java.lang.String parameter, java.lang.Object callingObject, java.lang.Object userObj, boolean resolveMethods)
          Calls a user method in the object callingObject.
static void clearFileCache()
          Deletes all files from the file cache.
static void clearFileCache(A_CmsXmlContent doc)
          Deletes the file represented by the given A_CmsXmlContent from the file cache.
static void clearFileCache(java.lang.String key)
          Deletes the file with the given key from the file cache.
 java.lang.Object clone()
          Creates a clone of this object.
private  java.util.Hashtable concatData(java.util.Hashtable data1, java.util.Hashtable data2)
          Concats two datablock hashtables and returns the resulting one.
 void createNewFile(com.opencms.file.CmsObject cms, java.lang.String filename, java.lang.String documentType)
          Create a new CmsFile object containing an empty XML file of the current content type.
protected  void fastSetData(java.lang.String tag, java.lang.String data)
          Fast method to replace a datablock.
 java.lang.String getAbsoluteFilename()
          Gets the absolute filename of the XML file represented by this content class
protected  java.util.Hashtable getAllData()
          Gets all datablocks (the datablock hashtable).
protected  java.lang.String getClassName()
          Help method to print nice classnames in error messages
abstract  java.lang.String getContentDescription()
          This method should be implemented by every extending class.
protected  org.w3c.dom.Element getData(java.lang.String tag)
          Gets a complete datablock from the datablock hashtable.
protected  java.lang.String getDataValue(java.lang.String tag)
          Gets the text and CDATA content of a datablock from the datablock hashtable.
 java.lang.String getEncoding()
          Returns current XML document encoding.
 java.lang.String getFilename()
          Gets a short filename (without path) of the XML file represented by this content class of the template file.
protected  org.w3c.dom.Element getProcessedData(java.lang.String tag)
          Gets a processed datablock from the datablock hashtable.
protected  org.w3c.dom.Element getProcessedData(java.lang.String tag, java.lang.Object callingObject)
          Gets a processed datablock from the datablock hashtable.
protected  org.w3c.dom.Element getProcessedData(java.lang.String tag, java.lang.Object callingObject, java.lang.Object userObj)
          Gets a processed datablock from the datablock hashtable.
protected  org.w3c.dom.Element getProcessedData(java.lang.String tag, java.lang.Object callingObject, java.lang.Object userObj, java.io.OutputStream stream)
          Gets a processed datablock from the datablock hashtable.
protected  java.lang.String getProcessedDataValue(java.lang.String tag)
          Gets the text and CDATA content of a processed datablock from the datablock hashtable.
protected  java.lang.String getProcessedDataValue(java.lang.String tag, java.lang.Object callingObject)
          Gets the text and CDATA content of a processed datablock from the datablock hashtable.
protected  java.lang.String getProcessedDataValue(java.lang.String tag, java.lang.Object callingObject, java.lang.Object userObj)
          Gets the text and CDATA content of a processed datablock from the datablock hashtable.
protected  java.lang.String getProcessedDataValue(java.lang.String tag, java.lang.Object callingObject, java.lang.Object userObj, java.io.OutputStream stream)
          Gets the text and CDATA content of a processed datablock from the datablock hashtable.
protected  java.lang.String getTagValue(org.w3c.dom.Element n)
          Reads all text or CDATA values from the given XML element, e.g.
private  java.lang.reflect.Method getUserMethod(java.lang.String methodName, java.lang.Object callingObject)
          Looks up a user defined method requested by a "METHOD" tag.
protected  org.w3c.dom.Document getXmlDocument()
          Gets the XML parsed content of this template file as a DOM document.
abstract  java.lang.String getXmlDocumentTagName()
          This method should be implemented by every extending class.
static I_CmsXmlParser getXmlParser()
          Gets the currently used XML Parser.
 java.lang.String getXmlText()
          Prints the XML parsed content to a String
 java.lang.String getXmlText(org.w3c.dom.Node n)
          Prints the XML parsed content of a given node and its subnodes to a String
 void getXmlText(java.io.OutputStream out)
           
 void getXmlText(java.io.OutputStream out, org.w3c.dom.Node n)
           
 void getXmlText(java.io.Writer out)
          Prints the XML parsed content of this template file to the given Writer.
 void getXmlText(java.io.Writer out, org.w3c.dom.Node n)
          Prints the XML parsed content of the given Node and its subnodes to the given Writer.
private  void handleDataTag(org.w3c.dom.Element n, java.lang.Object callingObject, java.lang.Object userObj)
          Handling of "DATA" tags and unknown tags.
private  java.lang.Object handleIncludeTag(org.w3c.dom.Element n, java.lang.Object callingObject, java.lang.Object userObj)
          Handling of "INCLUDE" tags.
private  java.lang.Object handleLinkTag(org.w3c.dom.Element n, java.lang.Object callingObject, java.lang.Object userObj)
          Handling of "LINK" tags.
private  java.lang.Object handleMethodTag(org.w3c.dom.Element n, java.lang.Object callingObject, java.lang.Object userObj)
          Handling of the "METHOD name=..." tags.
private  java.lang.Object handleMethodTagForSure(org.w3c.dom.Element n, java.lang.Object callingObject, java.lang.Object userObj)
          Handling of the "METHOD name=..." tags.
private  java.lang.Object handleProcessTag(org.w3c.dom.Element n, java.lang.Object callingObject, java.lang.Object userObj)
          Handling of the "PROCESS" tags.
protected  boolean hasData(java.lang.String key)
          Checks if this Template owns a datablock with the given key.
 void init(com.opencms.file.CmsObject cms, com.opencms.file.CmsFile file)
          Initialize the XML content class.
 void init(com.opencms.file.CmsObject cms, org.w3c.dom.Document content, java.lang.String filename)
          Initialize the class with the given parsed XML DOM document.
 void init(com.opencms.file.CmsObject cms, java.lang.String filename)
          Initialize the XML content class.
private  void insertNewDatablock(java.lang.String tag, org.w3c.dom.Element data)
          Internal method for creating a new datablock.
private  org.w3c.dom.Document loadCachedDocument(java.lang.String filename)
          Reloads a previously cached parsed content.
protected  org.w3c.dom.Document parse(byte[] content)
           
protected  org.w3c.dom.Document parse(java.io.InputStream content)
          Starts the XML parser with the content of the given CmsFile object.
private  void printNode(org.w3c.dom.Node node, int depth, java.lang.String path)
          Prints all nodes of a XML locale file in depth first order split by "." to STDOUT.
protected  void processDocument(java.util.Hashtable keys, java.lang.reflect.Method defaultMethod, java.lang.Object callingObject, java.lang.Object userObj)
          Main processing funtion for the whole XML document.
protected  void processNode(org.w3c.dom.Node n, java.util.Hashtable keys, java.lang.reflect.Method defaultMethod, java.lang.Object callingObject, java.lang.Object userObj)
          Universal main processing function for parsed XML templates.
protected  void processNode(org.w3c.dom.Node n, java.util.Hashtable keys, java.lang.reflect.Method defaultMethod, java.lang.Object callingObject, java.lang.Object userObj, java.io.OutputStream stream)
           
 void readIncludeFile(A_CmsXmlContent include)
          Read the datablocks of the given content file and include them into the own Hashtable of datablocks.
 A_CmsXmlContent readIncludeFile(java.lang.String filename)
          Parses the given file and stores it in the internal list of included files and appends the relevant data structures of the new file to its own structures.
private  void registerAllTags()
          Internal method registering all special tags relevant for the basic functionality of this abstract class.
 void registerTag(java.lang.String tagname)
          Registers the given tag to be "known" by the system.
 void registerTag(java.lang.String tagname, java.lang.Class c, java.lang.String methodName, int runSelector)
          Registeres a tagname together with a corresponding method for processing with processNode.
protected  void removeData(java.lang.String tag)
          Remove a datablock from the internal hashtable and from the XML document
 void removeFromFileCache()
          Deletes this object from the internal XML file cache
private  org.w3c.dom.NodeList replaceTagByComment(org.w3c.dom.Element n, java.lang.Object callingObject, java.lang.Object userObj)
          Generates a XML comment.
protected  void setData(java.lang.String tag, org.w3c.dom.Element data)
          Stores a given datablock element in the datablock hashtable.
protected  void setData(java.lang.String tag, java.lang.String data)
          Creates a datablock consisting of a single TextNode containing data and stores this block into the datablock-hashtable.
 void setEncoding(java.lang.String encoding)
          Sets new encoding for XML document.
 void setParsedData(java.lang.String tag, java.lang.String data)
          Creates a datablock element by parsing the data string and stores this block into the datablock-hashtable.
private  org.w3c.dom.NodeList stringToNodeList(java.lang.String s)
          Utility method for converting a String to a NodeList containing a single TextNode.
protected  void throwException(java.lang.String errorMessage)
          Help method that handles any occuring exception by writing an error message to the OpenCms logfile and throwing a CmsException of the type "unknown".
protected  void throwException(java.lang.String errorMessage, java.lang.Exception e)
          Help method that handles any occuring exception by writing an error message to the OpenCms logfile and throwing a CmsException of the type "unknown".
protected  void throwException(java.lang.String errorMessage, java.lang.Exception e, int type)
          Help method that handles any occuring exception by writing an error message to the OpenCms logfile and throwing a CmsException of the type "unknown".
protected  void throwException(java.lang.String errorMessage, int type)
          Help method that handles any occuring exception by writing an error message to the OpenCms logfile and throwing a CmsException of the given type.
 java.lang.String toString()
          Gets a string representation of this object.
protected  org.w3c.dom.Node treeWalker(org.w3c.dom.Node root, org.w3c.dom.Node n)
          Help method to walk through the DOM document tree.
protected  org.w3c.dom.Node treeWalkerWidth(org.w3c.dom.Node root, org.w3c.dom.Node n)
          Help method to walk through the DOM document tree by a width-first-order.
 void write()
          Writes the XML document back to the OpenCms system.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

C_PARAMTYPES_HANDLING_METHODS

public static final java.lang.Class[] C_PARAMTYPES_HANDLING_METHODS
parameter types for XML node handling methods.


C_PARAMTYPES_USER_METHODS

public static final java.lang.Class[] C_PARAMTYPES_USER_METHODS
parameter types for user methods called by METHOD tags


C_MINIMUM_CLASSNAME

public static final java.lang.String C_MINIMUM_CLASSNAME
The classname of the super XML content class

See Also:
Constant Field Values

C_TEMPLATEPATH

public static final java.lang.String C_TEMPLATEPATH
Constant pathname, where to find templates

See Also:
Constant Field Values

C_TEMPLATE_EXTENSION

public static final java.lang.String C_TEMPLATE_EXTENSION
Constant extension of the template-files.

See Also:
Constant Field Values

C_ERR_NODATABLOCK

public static final java.lang.String C_ERR_NODATABLOCK
Error message for bad <PROCESS> tags

See Also:
Constant Field Values

m_cms

protected com.opencms.file.CmsObject m_cms
CmsObject Object for accessing resources


m_knownTags

protected java.util.Vector m_knownTags
All XML tags known by this class.


m_firstRunTags

protected java.util.Hashtable m_firstRunTags
This Hashtable contains some XML tags as keys and the corresponding methods as values. Used to pass to processNode() to read in include files and scan for datablocks.


m_mainProcessTags

protected java.util.Hashtable m_mainProcessTags
This Hashtable contains some XML tags as keys and the corresponding methods as values. Used to pass to processNode() before generating HTML output.


C_REGISTER_FIRST_RUN

protected static final int C_REGISTER_FIRST_RUN
constant for registering handling tags

See Also:
Constant Field Values

C_REGISTER_MAIN_RUN

protected static final int C_REGISTER_MAIN_RUN
constant for registering handling tags

See Also:
Constant Field Values

C_DEBUG

private static final boolean C_DEBUG
Boolean for additional debug output control

See Also:
Constant Field Values

m_content

private org.w3c.dom.Document m_content
DOM representaion of the template content.


m_filename

private java.lang.String m_filename
Filename this template was read from


m_blocks

private java.util.Hashtable m_blocks
All datablocks in DOM format


m_includedTemplates

private java.util.Vector m_includedTemplates
Reference All included A_CmsXmlContents


m_filecache

private static java.util.Hashtable m_filecache
Cache for parsed documents


parser

private static I_CmsXmlParser parser
XML parser


m_newEncoding

private java.lang.String m_newEncoding

C_PRINTNODES

private static final boolean C_PRINTNODES
Flag to enable / disable printNode() method

See Also:
Constant Field Values
Constructor Detail

A_CmsXmlContent

public A_CmsXmlContent()
Constructor for creating a new instance of this class

Method Detail

callUserMethod

protected java.lang.Object callUserMethod(java.lang.String methodName,
                                          java.lang.String parameter,
                                          java.lang.Object callingObject,
                                          java.lang.Object userObj,
                                          boolean resolveMethods)
                                   throws com.opencms.core.CmsException
Calls a user method in the object callingObject. Every user method has to user the parameter types defined in C_PARAMTYPES_USER_METHODS to be recognized by this method.


clearFileCache

public static void clearFileCache()
Deletes all files from the file cache.


clearFileCache

public static void clearFileCache(A_CmsXmlContent doc)
Deletes the file represented by the given A_CmsXmlContent from the file cache.


clearFileCache

public static void clearFileCache(java.lang.String key)
Deletes the file with the given key from the file cache. If no such file exists nothing happens.


clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Creates a clone of this object.

Specified by:
clone in interface I_CmsXmlContent

concatData

private java.util.Hashtable concatData(java.util.Hashtable data1,
                                       java.util.Hashtable data2)
Concats two datablock hashtables and returns the resulting one.


createNewFile

public void createNewFile(com.opencms.file.CmsObject cms,
                          java.lang.String filename,
                          java.lang.String documentType)
                   throws com.opencms.core.CmsException
Create a new CmsFile object containing an empty XML file of the current content type. The String returned by getXmlDocumentTagName() will be used to build the XML document element.


fastSetData

protected void fastSetData(java.lang.String tag,
                           java.lang.String data)
Fast method to replace a datablock.

USE WITH CARE!

Using this method only if

  • The tag name is given in lowercase
  • The datablock already exists (it may be empty)
  • Neither tag nor data are null
  • You are sure, there will occure no errors


getAbsoluteFilename

public java.lang.String getAbsoluteFilename()
Gets the absolute filename of the XML file represented by this content class

Specified by:
getAbsoluteFilename in interface I_CmsXmlContent

getAllData

protected java.util.Hashtable getAllData()
Gets all datablocks (the datablock hashtable).


getClassName

protected java.lang.String getClassName()
Help method to print nice classnames in error messages


getContentDescription

public abstract java.lang.String getContentDescription()
This method should be implemented by every extending class. It returns a short description of the content definition type (e.g. "OpenCms news article").


getData

protected org.w3c.dom.Element getData(java.lang.String tag)
                               throws com.opencms.core.CmsException
Gets a complete datablock from the datablock hashtable.


getDataValue

protected java.lang.String getDataValue(java.lang.String tag)
                                 throws com.opencms.core.CmsException
Gets the text and CDATA content of a datablock from the datablock hashtable.


getFilename

public java.lang.String getFilename()
Gets a short filename (without path) of the XML file represented by this content class of the template file.

Specified by:
getFilename in interface I_CmsXmlContent

getProcessedData

protected org.w3c.dom.Element getProcessedData(java.lang.String tag)
                                        throws com.opencms.core.CmsException
Gets a processed datablock from the datablock hashtable.


getProcessedData

protected org.w3c.dom.Element getProcessedData(java.lang.String tag,
                                               java.lang.Object callingObject)
                                        throws com.opencms.core.CmsException
Gets a processed datablock from the datablock hashtable.


getProcessedData

protected org.w3c.dom.Element getProcessedData(java.lang.String tag,
                                               java.lang.Object callingObject,
                                               java.lang.Object userObj)
                                        throws com.opencms.core.CmsException
Gets a processed datablock from the datablock hashtable.

The userObj Object is passed to all called user methods. By using this, the initiating class can pass customized data to its methods.


getProcessedData

protected org.w3c.dom.Element getProcessedData(java.lang.String tag,
                                               java.lang.Object callingObject,
                                               java.lang.Object userObj,
                                               java.io.OutputStream stream)
                                        throws com.opencms.core.CmsException
Gets a processed datablock from the datablock hashtable.

The userObj Object is passed to all called user methods. By using this, the initiating class can pass customized data to its methods.


getProcessedDataValue

protected java.lang.String getProcessedDataValue(java.lang.String tag)
                                          throws com.opencms.core.CmsException
Gets the text and CDATA content of a processed datablock from the datablock hashtable.


getProcessedDataValue

protected java.lang.String getProcessedDataValue(java.lang.String tag,
                                                 java.lang.Object callingObject)
                                          throws com.opencms.core.CmsException
Gets the text and CDATA content of a processed datablock from the datablock hashtable.


getProcessedDataValue

protected java.lang.String getProcessedDataValue(java.lang.String tag,
                                                 java.lang.Object callingObject,
                                                 java.lang.Object userObj)
                                          throws com.opencms.core.CmsException
Gets the text and CDATA content of a processed datablock from the datablock hashtable.

The userObj Object is passed to all called user methods. By using this, the initiating class can pass customized data to its methods.


getProcessedDataValue

protected java.lang.String getProcessedDataValue(java.lang.String tag,
                                                 java.lang.Object callingObject,
                                                 java.lang.Object userObj,
                                                 java.io.OutputStream stream)
                                          throws com.opencms.core.CmsException
Gets the text and CDATA content of a processed datablock from the datablock hashtable. An eventually given output stream is user for streaming the generated result directly to the response output stream while processing.

The userObj Object is passed to all called user methods. By using this, the initiating class can pass customized data to its methods.


getTagValue

protected java.lang.String getTagValue(org.w3c.dom.Element n)
Reads all text or CDATA values from the given XML element, e.g. <ELEMENT>foo blah <![CDATA[<H1>Hello</H1>]]></ELEMENT>.


getUserMethod

private java.lang.reflect.Method getUserMethod(java.lang.String methodName,
                                               java.lang.Object callingObject)
                                        throws java.lang.NoSuchMethodException
Looks up a user defined method requested by a "METHOD" tag. The method is searched in the Object callingObject.


getXmlDocument

protected org.w3c.dom.Document getXmlDocument()
Gets the XML parsed content of this template file as a DOM document.

WARNING: The returned value is the original DOM document, not a clone. Any changes will take effect to the behaviour of this class. Especially datablocks are concerned by this!


getXmlDocumentTagName

public abstract java.lang.String getXmlDocumentTagName()
This method should be implemented by every extending class. It returns the name of the XML document tag to scan for.


getXmlParser

public static I_CmsXmlParser getXmlParser()
Gets the currently used XML Parser.


getXmlText

public java.lang.String getXmlText()
Prints the XML parsed content to a String

Specified by:
getXmlText in interface I_CmsXmlContent

getXmlText

public void getXmlText(java.io.Writer out)
Prints the XML parsed content of this template file to the given Writer.

Specified by:
getXmlText in interface I_CmsXmlContent

getXmlText

public void getXmlText(java.io.Writer out,
                       org.w3c.dom.Node n)
Prints the XML parsed content of the given Node and its subnodes to the given Writer.

Specified by:
getXmlText in interface I_CmsXmlContent

getXmlText

public void getXmlText(java.io.OutputStream out)

getXmlText

public void getXmlText(java.io.OutputStream out,
                       org.w3c.dom.Node n)

getXmlText

public java.lang.String getXmlText(org.w3c.dom.Node n)
Prints the XML parsed content of a given node and its subnodes to a String

Specified by:
getXmlText in interface I_CmsXmlContent

callAllUncalledMethodsSoThatEclipseDoesntComplainAboutThem

protected void callAllUncalledMethodsSoThatEclipseDoesntComplainAboutThem()
                                                                   throws com.opencms.core.CmsException
This method is just a hack so that the Eclise IDE will not show the methods listed here as warnings when the "unused private methods" option is selected, since they are called only using reclection API. Do not use this method.


handleDataTag

private void handleDataTag(org.w3c.dom.Element n,
                           java.lang.Object callingObject,
                           java.lang.Object userObj)
Handling of "DATA" tags and unknown tags. A reference to each data tag ist stored in an internal hashtable with the name of the datablock as key. Nested datablocks are stored with names like outername.innername


handleIncludeTag

private java.lang.Object handleIncludeTag(org.w3c.dom.Element n,
                                          java.lang.Object callingObject,
                                          java.lang.Object userObj)
                                   throws com.opencms.core.CmsException
Handling of "INCLUDE" tags.


handleLinkTag

private java.lang.Object handleLinkTag(org.w3c.dom.Element n,
                                       java.lang.Object callingObject,
                                       java.lang.Object userObj)
                                throws com.opencms.core.CmsException
Handling of "LINK" tags.


handleMethodTag

private java.lang.Object handleMethodTag(org.w3c.dom.Element n,
                                         java.lang.Object callingObject,
                                         java.lang.Object userObj)
                                  throws com.opencms.core.CmsException
Handling of the "METHOD name=..." tags. Name attribute and value of the element are read and the user method 'name' is invoked with the element value as parameter.


handleMethodTagForSure

private java.lang.Object handleMethodTagForSure(org.w3c.dom.Element n,
                                                java.lang.Object callingObject,
                                                java.lang.Object userObj)
                                         throws com.opencms.core.CmsException
Handling of the "METHOD name=..." tags. In contrast to the method handleMethodTag this method resolves every method even if it has it own CacheDirectives. It is used only for getProcessedDataValue. Name attribute and value of the element are read and the user method 'name' is invoked with the element value as parameter.


handleProcessTag

private java.lang.Object handleProcessTag(org.w3c.dom.Element n,
                                          java.lang.Object callingObject,
                                          java.lang.Object userObj)
Handling of the "PROCESS" tags. Looks up the requested datablocks in the internal hashtable and returns its subnodes.


hasData

protected boolean hasData(java.lang.String key)
Checks if this Template owns a datablock with the given key.


init

public void init(com.opencms.file.CmsObject cms,
                 com.opencms.file.CmsFile file)
          throws com.opencms.core.CmsException
Initialize the XML content class. Load and parse the content of the given CmsFile object.

Specified by:
init in interface I_CmsXmlContent

init

public void init(com.opencms.file.CmsObject cms,
                 java.lang.String filename)
          throws com.opencms.core.CmsException
Initialize the XML content class. Load and parse the content of the given CmsFile object.

If a previously cached parsed content exists, it will be re-used.

If no absolute file name ist given, template files will be searched a hierachical order using lookupAbsoluteFilename.

Specified by:
init in interface I_CmsXmlContent

printNode

private void printNode(org.w3c.dom.Node node,
                       int depth,
                       java.lang.String path)
Prints all nodes of a XML locale file in depth first order split by "." to STDOUT.

This method is useful for backward compatibility: you can copy the output of this method (which is written to $TOMCAT_HOME/logs/catalina. out) to build Java resource bundles. This method is for internal use only, should be deactivated on a production system!

Activate this method by setting the value of C_PRINTNODES to true;


init

public void init(com.opencms.file.CmsObject cms,
                 org.w3c.dom.Document content,
                 java.lang.String filename)
          throws com.opencms.core.CmsException
Initialize the class with the given parsed XML DOM document.

Specified by:
init in interface I_CmsXmlContent

insertNewDatablock

private void insertNewDatablock(java.lang.String tag,
                                org.w3c.dom.Element data)
Internal method for creating a new datablock.

This method is called by setData() if a new, not existing datablock must be created.

Functionality: If a non-hierarchical datablock is given, it is inserted at the end of the DOM document. If a hierarchical datablock is given, all possible parent names are checked in a backward oriented order. If a datablock with a name that equals a part of the hierarchy is found, the new datablock will be created as a (sub)child of this datablock.


loadCachedDocument

private org.w3c.dom.Document loadCachedDocument(java.lang.String filename)
Reloads a previously cached parsed content.


replaceTagByComment

private org.w3c.dom.NodeList replaceTagByComment(org.w3c.dom.Element n,
                                                 java.lang.Object callingObject,
                                                 java.lang.Object userObj)
Generates a XML comment. It's used to replace no longer needed DOM elements by a short XML comment


parse

protected org.w3c.dom.Document parse(byte[] content)
                              throws com.opencms.core.CmsException

parse

protected org.w3c.dom.Document parse(java.io.InputStream content)
                              throws com.opencms.core.CmsException
Starts the XML parser with the content of the given CmsFile object. After parsing the document it is scanned for INCLUDE and DATA tags by calling processNode with m_firstRunParameters.


processDocument

protected void processDocument(java.util.Hashtable keys,
                               java.lang.reflect.Method defaultMethod,
                               java.lang.Object callingObject,
                               java.lang.Object userObj)
                        throws com.opencms.core.CmsException
Main processing funtion for the whole XML document.


processNode

protected void processNode(org.w3c.dom.Node n,
                           java.util.Hashtable keys,
                           java.lang.reflect.Method defaultMethod,
                           java.lang.Object callingObject,
                           java.lang.Object userObj)
                    throws com.opencms.core.CmsException
Universal main processing function for parsed XML templates. The given node is processed by a tree walk.

Every XML tag will be looked up in the Hashtable "keys". If a corresponding entry is found, the tag will be handled by the corresponding function returned from the Hashtable.

If an unknown tag is detected the method defaultMethod is called instead. Is defaultMethod == null nothing will be done with unknown tags.

The invoked handling methods are allowed to return null or objects of the type String, Node, Integer or byte[]. If the return value is null, nothing happens. In all other cases the handled node in the tree will be replaced by a new node. The value of this new node depends on the type of the returned value.


processNode

protected void processNode(org.w3c.dom.Node n,
                           java.util.Hashtable keys,
                           java.lang.reflect.Method defaultMethod,
                           java.lang.Object callingObject,
                           java.lang.Object userObj,
                           java.io.OutputStream stream)
                    throws com.opencms.core.CmsException

readIncludeFile

public void readIncludeFile(A_CmsXmlContent include)
                     throws com.opencms.core.CmsException
Read the datablocks of the given content file and include them into the own Hashtable of datablocks.


readIncludeFile

public A_CmsXmlContent readIncludeFile(java.lang.String filename)
                                throws com.opencms.core.CmsException
Parses the given file and stores it in the internal list of included files and appends the relevant data structures of the new file to its own structures.

Specified by:
readIncludeFile in interface I_CmsXmlContent

registerAllTags

private void registerAllTags()
Internal method registering all special tags relevant for the basic functionality of this abstract class.

OpenCms special tags are:

  • INCLUDE: used to include other XML files
  • DATA: used to define a datablock that can be handled by getData or processed by getProcessedData or PROCESS
  • PROCESS: used to insert earlier or external defined datablocks
  • METHOD: used to call customized methods in the initiating user object
All unknown tags will be treated as a shortcut for <DATA name="...">.


registerTag

public void registerTag(java.lang.String tagname)
Registers the given tag to be "known" by the system. So this tag will not be handled by the default method of processNode. Under normal circumstances this feature will only be used for the XML document tag.


registerTag

public void registerTag(java.lang.String tagname,
                        java.lang.Class c,
                        java.lang.String methodName,
                        int runSelector)
Registeres a tagname together with a corresponding method for processing with processNode. Tags can be registered for two different runs of the processNode method. This can be selected by the runSelector.

C_REGISTER_FIRST_RUN registeres the given tag for the first run of processNode, just after parsing a XML document. The basic functionality of this class uses this run to scan for INCLUDE and DATA tags.

C_REGISTER_MAIN_RUN registeres the given tag for the main run of processNode. This will be initiated by getProcessedData(), processDocument() or any PROCESS tag.


removeData

protected void removeData(java.lang.String tag)
Remove a datablock from the internal hashtable and from the XML document


removeFromFileCache

public void removeFromFileCache()
Deletes this object from the internal XML file cache


setData

protected void setData(java.lang.String tag,
                       java.lang.String data)
Creates a datablock consisting of a single TextNode containing data and stores this block into the datablock-hashtable.


setData

protected void setData(java.lang.String tag,
                       org.w3c.dom.Element data)
Stores a given datablock element in the datablock hashtable.


setParsedData

public void setParsedData(java.lang.String tag,
                          java.lang.String data)
                   throws com.opencms.core.CmsException
Creates a datablock element by parsing the data string and stores this block into the datablock-hashtable.


stringToNodeList

private org.w3c.dom.NodeList stringToNodeList(java.lang.String s)
Utility method for converting a String to a NodeList containing a single TextNode.


throwException

protected void throwException(java.lang.String errorMessage)
                       throws com.opencms.core.CmsException
Help method that handles any occuring exception by writing an error message to the OpenCms logfile and throwing a CmsException of the type "unknown".


throwException

protected void throwException(java.lang.String errorMessage,
                              int type)
                       throws com.opencms.core.CmsException
Help method that handles any occuring exception by writing an error message to the OpenCms logfile and throwing a CmsException of the given type.


throwException

protected void throwException(java.lang.String errorMessage,
                              java.lang.Exception e)
                       throws com.opencms.core.CmsException
Help method that handles any occuring exception by writing an error message to the OpenCms logfile and throwing a CmsException of the type "unknown".


throwException

protected void throwException(java.lang.String errorMessage,
                              java.lang.Exception e,
                              int type)
                       throws com.opencms.core.CmsException
Help method that handles any occuring exception by writing an error message to the OpenCms logfile and throwing a CmsException of the type "unknown".


toString

public java.lang.String toString()
Gets a string representation of this object.


treeWalker

protected org.w3c.dom.Node treeWalker(org.w3c.dom.Node root,
                                      org.w3c.dom.Node n)
Help method to walk through the DOM document tree. First it will be looked for children of the given node. If there are no children, the siblings and the siblings of our parents are examined. This will be done by calling treeWalkerWidth.


treeWalkerWidth

protected org.w3c.dom.Node treeWalkerWidth(org.w3c.dom.Node root,
                                           org.w3c.dom.Node n)
Help method to walk through the DOM document tree by a width-first-order.


write

public void write()
           throws com.opencms.core.CmsException
Writes the XML document back to the OpenCms system.

Specified by:
write in interface I_CmsXmlContent

getEncoding

public java.lang.String getEncoding()
Returns current XML document encoding.


setEncoding

public void setEncoding(java.lang.String encoding)
Sets new encoding for XML document.