|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--com.opencms.template.A_CmsXmlContent
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().
| Field Summary | |
static String |
C_ERR_NODATABLOCK
Error message for bad <PROCESS> tags |
static String |
C_MINIMUM_CLASSNAME
The classname of the super XML content class |
static Class[] |
C_PARAMTYPES_HANDLING_METHODS
parameter types for XML node handling methods. |
static Class[] |
C_PARAMTYPES_USER_METHODS
parameter types for user methods called by METHOD tags |
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 String |
C_TEMPLATE_EXTENSION
Constant extension of the template-files. |
static String |
C_TEMPLATEPATH
Constant pathname, where to find templates |
protected CmsObject |
m_cms
CmsObject Object for accessing resources |
protected Hashtable |
m_firstRunTags
This Hashtable contains some XML tags as keys and the corresponding methods as values. |
protected Vector |
m_knownTags
All XML tags known by this class. |
protected Hashtable |
m_mainProcessTags
This Hashtable contains some XML tags as keys and the corresponding methods as values. |
| 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 Object |
callUserMethod(String methodName,
String parameter,
Object callingObject,
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(String key)
Deletes the file with the given key from the file cache. |
Object |
clone()
Creates a clone of this object. |
void |
createNewFile(CmsObject cms,
String filename,
String documentType)
Create a new CmsFile object containing an empty XML file of the current content type. |
protected void |
fastSetData(String tag,
String data)
Fast method to replace a datablock. |
String |
getAbsoluteFilename()
Gets the absolute filename of the XML file represented by this content class |
protected Hashtable |
getAllData()
Gets all datablocks (the datablock hashtable). |
protected String |
getClassName()
Help method to print nice classnames in error messages |
abstract String |
getContentDescription()
This method should be implemented by every extending class. |
protected Element |
getData(String tag)
Gets a complete datablock from the datablock hashtable. |
protected String |
getDataValue(String tag)
Gets the text and CDATA content of a datablock from the datablock hashtable. |
String |
getEncoding()
Returns current XML document encoding. |
String |
getFilename()
Gets a short filename (without path) of the XML file represented by this content class of the template file. |
protected Element |
getProcessedData(String tag)
Gets a processed datablock from the datablock hashtable. |
protected Element |
getProcessedData(String tag,
Object callingObject)
Gets a processed datablock from the datablock hashtable. |
protected Element |
getProcessedData(String tag,
Object callingObject,
Object userObj)
Gets a processed datablock from the datablock hashtable. |
protected Element |
getProcessedData(String tag,
Object callingObject,
Object userObj,
OutputStream stream)
Gets a processed datablock from the datablock hashtable. |
protected String |
getProcessedDataValue(String tag)
Gets the text and CDATA content of a processed datablock from the datablock hashtable. |
protected String |
getProcessedDataValue(String tag,
Object callingObject)
Gets the text and CDATA content of a processed datablock from the datablock hashtable. |
protected String |
getProcessedDataValue(String tag,
Object callingObject,
Object userObj)
Gets the text and CDATA content of a processed datablock from the datablock hashtable. |
protected String |
getProcessedDataValue(String tag,
Object callingObject,
Object userObj,
OutputStream stream)
Gets the text and CDATA content of a processed datablock from the datablock hashtable. |
protected String |
getTagValue(Element n)
Reads all text or CDATA values from the given XML element, e.g. |
protected Document |
getXmlDocument()
Gets the XML parsed content of this template file as a DOM document. |
abstract String |
getXmlDocumentTagName()
This method should be implemented by every extending class. |
static I_CmsXmlParser |
getXmlParser()
Gets the currently used XML Parser. |
String |
getXmlText()
Prints the XML parsed content to a String |
String |
getXmlText(Node n)
Prints the XML parsed content of a given node and its subnodes to a String |
void |
getXmlText(OutputStream out)
|
void |
getXmlText(OutputStream out,
Node n)
|
void |
getXmlText(Writer out)
Prints the XML parsed content of this template file to the given Writer. |
void |
getXmlText(Writer out,
Node n)
Prints the XML parsed content of the given Node and its subnodes to the given Writer. |
protected boolean |
hasData(String key)
Checks if this Template owns a datablock with the given key. |
void |
init(CmsObject cms,
CmsFile file)
Initialize the XML content class. |
void |
init(CmsObject cms,
Document content,
String filename)
Initialize the class with the given parsed XML DOM document. |
void |
init(CmsObject cms,
String filename)
Initialize the XML content class. |
protected Document |
parse(byte[] content)
|
protected Document |
parse(InputStream content)
Starts the XML parser with the content of the given CmsFile object. |
protected void |
processDocument(Hashtable keys,
Method defaultMethod,
Object callingObject,
Object userObj)
Main processing funtion for the whole XML document. |
protected void |
processNode(Node n,
Hashtable keys,
Method defaultMethod,
Object callingObject,
Object userObj)
Universal main processing function for parsed XML templates. |
protected void |
processNode(Node n,
Hashtable keys,
Method defaultMethod,
Object callingObject,
Object userObj,
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(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. |
void |
registerTag(String tagname)
Registers the given tag to be "known" by the system. |
void |
registerTag(String tagname,
Class c,
String methodName,
int runSelector)
Registeres a tagname together with a corresponding method for processing with processNode. |
protected void |
removeData(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 |
protected void |
setData(String tag,
Element data)
Stores a given datablock element in the datablock hashtable. |
protected void |
setData(String tag,
String data)
Creates a datablock consisting of a single TextNode containing data and stores this block into the datablock-hashtable. |
void |
setEncoding(String encoding)
Sets new encoding for XML document. |
void |
setParsedData(String tag,
String data)
Creates a datablock element by parsing the data string and stores this block into the datablock-hashtable. |
protected void |
throwException(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(String errorMessage,
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(String errorMessage,
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(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. |
String |
toString()
Gets a string representation of this object. |
protected Node |
treeWalker(Node root,
Node n)
Help method to walk through the DOM document tree. |
protected Node |
treeWalkerWidth(Node root,
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 |
public static final Class[] C_PARAMTYPES_HANDLING_METHODS
public static final Class[] C_PARAMTYPES_USER_METHODS
public static final String C_MINIMUM_CLASSNAME
public static final String C_TEMPLATEPATH
public static final String C_TEMPLATE_EXTENSION
public static final String C_ERR_NODATABLOCK
<PROCESS> tags
protected CmsObject m_cms
protected Vector m_knownTags
protected Hashtable m_firstRunTags
protected Hashtable m_mainProcessTags
protected static final int C_REGISTER_FIRST_RUN
protected static final int C_REGISTER_MAIN_RUN
| Constructor Detail |
public A_CmsXmlContent()
| Method Detail |
protected Object callUserMethod(String methodName,
String parameter,
Object callingObject,
Object userObj,
boolean resolveMethods)
throws CmsException
methodName - Name of the method to be called.parameter - Additional parameter passed to the method.callingObject - Reference to the object containing the called method.userObj - Customizable user object that will be passed through to the user method.resolveMethods - If true the methodtags will be resolved even if they have own CacheDirectives.
CmsExceptionC_PARAMTYPES_USER_METHODSpublic static void clearFileCache()
public static void clearFileCache(A_CmsXmlContent doc)
doc - A_CmsXmlContent representing the XML file to be deleted.public static void clearFileCache(String key)
key - Key of the template file to be removed from the cache.
public Object clone()
throws CloneNotSupportedException
clone in interface I_CmsXmlContentclone in class ObjectCloneNotSupportedException
public void createNewFile(CmsObject cms,
String filename,
String documentType)
throws CmsException
getXmlDocumentTagName()
will be used to build the XML document element.
cms - Current cms object used for accessing system resources.filename - Name of the file to be created.documentType - Document type of the new file.
CmsException - if no absolute filename is given or write access failed.
protected void fastSetData(String tag,
String data)
USE WITH CARE!
Using this method only if
null
tag - Key for this datablock.data - String to be put in the datablock.public String getAbsoluteFilename()
getAbsoluteFilename in interface I_CmsXmlContentprotected Hashtable getAllData()
protected String getClassName()
public abstract String getContentDescription()
protected Element getData(String tag)
throws CmsException
tag - Key for the datablocks hashtable.
CmsException
protected String getDataValue(String tag)
throws CmsException
tag - Key for the datablocks hashtable.
CmsExceptionpublic String getFilename()
getFilename in interface I_CmsXmlContent
protected Element getProcessedData(String tag)
throws CmsException
tag - Key for the datablocks hashtable.
CmsException
protected Element getProcessedData(String tag,
Object callingObject)
throws CmsException
tag - Key for the datablocks hashtable.callingObject - Object that should be used to look up user methods.
CmsException
protected Element getProcessedData(String tag,
Object callingObject,
Object userObj)
throws CmsException
The userObj Object is passed to all called user methods. By using this, the initiating class can pass customized data to its methods.
tag - Key for the datablocks hashtable.callingObject - Object that should be used to look up user methods.userObj - any object that should be passed to user methods
CmsException
protected Element getProcessedData(String tag,
Object callingObject,
Object userObj,
OutputStream stream)
throws CmsException
The userObj Object is passed to all called user methods. By using this, the initiating class can pass customized data to its methods.
tag - Key for the datablocks hashtable.callingObject - Object that should be used to look up user methods.userObj - any object that should be passed to user methodsstream - OutputStream that may be used for directly streaming the results or null.
CmsException
protected String getProcessedDataValue(String tag)
throws CmsException
tag - Key for the datablocks hashtable.
CmsException
protected String getProcessedDataValue(String tag,
Object callingObject)
throws CmsException
tag - Key for the datablocks hashtable.callingObject - Object that should be used to look up user methods.
CmsException
protected String getProcessedDataValue(String tag,
Object callingObject,
Object userObj)
throws CmsException
The userObj Object is passed to all called user methods. By using this, the initiating class can pass customized data to its methods.
tag - Key for the datablocks hashtable.callingObject - Object that should be used to look up user methods.userObj - any object that should be passed to user methods
CmsException
protected String getProcessedDataValue(String tag,
Object callingObject,
Object userObj,
OutputStream stream)
throws CmsException
The userObj Object is passed to all called user methods. By using this, the initiating class can pass customized data to its methods.
tag - Key for the datablocks hashtable.callingObject - Object that should be used to look up user methods.userObj - any object that should be passed to user methodsstream - OutputStream that may be used for directly streaming the results or null.
CmsExceptionprotected String getTagValue(Element n)
<ELEMENT>foo blah <![CDATA[<H1>Hello</H1>]]></ELEMENT>.
n - Element that should be read out.
null
if no nodes were found.protected Document getXmlDocument()
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!
public abstract String getXmlDocumentTagName()
public static I_CmsXmlParser getXmlParser()
public String getXmlText()
getXmlText in interface I_CmsXmlContentpublic void getXmlText(Writer out)
getXmlText in interface I_CmsXmlContentout - Writer to print to.
public void getXmlText(Writer out,
Node n)
getXmlText in interface I_CmsXmlContentout - Writer to print to.n - Node that should be printed.public void getXmlText(OutputStream out)
public void getXmlText(OutputStream out,
Node n)
public String getXmlText(Node n)
getXmlText in interface I_CmsXmlContentn - Node that should be printed.
protected void callAllUncalledMethodsSoThatEclipseDoesntComplainAboutThem()
throws CmsException
CmsExceptionprotected boolean hasData(String key)
key - Datablock key to be checked.
public void init(CmsObject cms,
CmsFile file)
throws CmsException
init in interface I_CmsXmlContentcms - CmsObject Object for accessing resources.file - CmsFile object of the file to be loaded and parsed.
CmsException
public void init(CmsObject cms,
String filename)
throws CmsException
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.
init in interface I_CmsXmlContentcms - CmsObject Object for accessing resources.filename - Filename of the file to be loaded.
CmsException
public void init(CmsObject cms,
Document content,
String filename)
throws CmsException
init in interface I_CmsXmlContentcms - CmsObject Object for accessing system resources.filename - OpenCms filename of the XML file.
CmsException
protected Document parse(byte[] content)
throws CmsException
CmsException
protected Document parse(InputStream content)
throws CmsException
content - String to be parsed
CmsExceptionprocessNode(org.w3c.dom.Node, java.util.Hashtable, java.lang.reflect.Method, java.lang.Object, java.lang.Object),
#firstRunParameters
protected void processDocument(Hashtable keys,
Method defaultMethod,
Object callingObject,
Object userObj)
throws CmsException
keys - Hashtable with XML tags to look for and corresponding methods.defaultMethod - Method to be called if the tag is unknown.callingObject - Reference to the object requesting the node processing.userObj - Customizable user object that will be passed through to handling and user methods.
CmsExceptionprocessNode(org.w3c.dom.Node, java.util.Hashtable, java.lang.reflect.Method, java.lang.Object, java.lang.Object)
protected void processNode(Node n,
Hashtable keys,
Method defaultMethod,
Object callingObject,
Object userObj)
throws CmsException
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.
n - Node with its subnodes to processkeys - Hashtable with XML tags to look for and corresponding methods.defaultMethod - Method to be called if the tag is unknown.callingObject - Reference to the Object that requested the node processing.userObj - Customizable user object that will be passed to handling and user methods.
CmsException
protected void processNode(Node n,
Hashtable keys,
Method defaultMethod,
Object callingObject,
Object userObj,
OutputStream stream)
throws CmsException
CmsException
public void readIncludeFile(A_CmsXmlContent include)
throws CmsException
include - completely initialized A_CmsXmlObject to be included
CmsExeption
CmsException
public A_CmsXmlContent readIncludeFile(String filename)
throws CmsException
readIncludeFile in interface I_CmsXmlContentCmsExceptionpublic void registerTag(String tagname)
tagname - Tag name to register.
public void registerTag(String tagname,
Class c,
String methodName,
int 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.
tagname - Tag name to register.c - Class containing the handling method.methodName - Name of the method that should handle a occurance of tag "tagname".runSelector - see description above.protected void removeData(String tag)
tag - Key of the datablock to delete.public void removeFromFileCache()
protected void setData(String tag,
String data)
tag - Key for this datablock.data - String to be put in the datablock.
protected void setData(String tag,
Element data)
tag - Key for this datablock.data - DOM element node for this datablock.
public void setParsedData(String tag,
String data)
throws CmsException
tag - Key for this datablock.data - String to be put in the datablock.
CmsException
protected void throwException(String errorMessage)
throws CmsException
errorMessage - String with the error message to be printed.
CmsException
protected void throwException(String errorMessage,
int type)
throws CmsException
errorMessage - String with the error message to be printed.type - Type of the exception to be thrown.
CmsException
protected void throwException(String errorMessage,
Exception e)
throws CmsException
errorMessage - String with the error message to be printed.e - Original exception.
CmsException
protected void throwException(String errorMessage,
Exception e,
int type)
throws CmsException
errorMessage - String with the error message to be printed.e - Original exception.type - Type of the exception to be thrown.
CmsExceptionpublic String toString()
toString in class Object
protected Node treeWalker(Node root,
Node n)
n - Node representing the actual position in the tree
protected Node treeWalkerWidth(Node root,
Node n)
n - Node representing the actual position in the tree
public void write()
throws CmsException
write in interface I_CmsXmlContentCmsExceptionpublic String getEncoding()
public void setEncoding(String encoding)
encoding -
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||