|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.cocoon.processor.dcp.DCPEngine
This class implements a DOM processor that evaluates <?dcp? > processing instructions to generate dynamic content.
The following processing instructions are recognized:
<?dcp-object name="objectName" [language="languageName"] code="codeLocation" ?>
This instruction declares an external program (or DCP script) that contains node-generation methods. These methods will be invoked during document processing as dictated by the appearance of subsequent <? dcp-content?> directives (explained below).
Attribute name specifies an author-defined objectName that will be used to qualify method names in the DCP script. This name must be unique within the document.
Attribute language specifies the programming language in which the DCP script is written. Supported values for this attribute are java and javascript (also referred to as ecmascript). This attribute is optional; its default value is java. Other languages may be added in the future. It is valid for the same XML document to use multiple DCP scripts written in different languages.
Attribute code specifies the actual DCP script location. Interpretation of this mandatory attribute is language-dependent. For Java, it is a fully qualified class name. For Javascript, it is a script filename relative to the path of the invoking XML document. The same code can be specified multiple times in a given document, provided a different objectName is used in each case.
<?dcp-content method="object.method" [param1="value" param2="value" ...] ?>
This instruction requests the substitution of its corresponding node by the return value of a named method defined in a DCP script.
Single-valued, named parameters can be passed to node-generation methods by specifying
additional attributes in the
<?dcp-content?>
processing instruction. These attributes are made available to the method through a
Dictionary
argument.
Attribute method defines what method to invoke on a given object. The object name must have been associated with a DCP script by means of a previous <?dcp-object?> processing instruction. Node-generation methods must be public and conform to the following signature:
methodName( [java.util.Dictionary parameters], [org.w3c.Node source] )
where the optional function arguments are:
Methods can return any type of value, including primitive types, void and null. Void and null are understood as a request to remove the corresponding node. Returned values that are instances of org.w3c.Node are simply inserted into the corresponding DOM tree position. Primitive types and regular objects are wrapped as strings in org.w3c.Text nodes. Arrays are wrapped as org.w3c.DocumentFragment's containing as many children as elements in the array; these elements are recursively wrapped according to the above rules.
Field Summary | |
private static java.lang.String |
CODE_ATTRIBUTE
|
private static java.lang.String |
CONTENT_PI
|
private Director |
director
|
private org.w3c.dom.Document |
document
|
private java.util.Hashtable |
globalVariables
|
private java.util.Hashtable |
instances
|
private InterpreterFactory |
interpreterFactory
|
private static java.lang.String |
LANGUAGE_ATTRIBUTE
|
private static java.lang.String |
METHOD_ATTRIBUTE
|
private static java.lang.String |
NAME_ATTRIBUTE
|
private static java.lang.String |
OBJECT_PI
|
private java.util.Dictionary |
parameters
|
private static java.lang.String |
VARIABLE_PI
|
Constructor Summary | |
DCPEngine(org.w3c.dom.Document document,
InterpreterFactory factory,
java.util.Dictionary parameters)
Set the document being processed and any parameters passed by the invoking environment. |
Method Summary | |
private void |
doProcess(org.w3c.dom.Node node)
|
private org.w3c.dom.Node[] |
getChildren(org.w3c.dom.Node node)
|
private void |
parseAttributes(java.lang.String data,
java.util.Hashtable attributes)
|
void |
process()
Process the document substituting <? |
private org.w3c.dom.Node |
processContent(org.w3c.dom.ProcessingInstruction pi)
|
private void |
processObject(org.w3c.dom.ProcessingInstruction pi)
|
private void |
processVariable(org.w3c.dom.ProcessingInstruction pi)
|
Methods inherited from class java.lang.Object |
|
Field Detail |
private static final java.lang.String OBJECT_PI
private static final java.lang.String CONTENT_PI
private static final java.lang.String VARIABLE_PI
private static final java.lang.String NAME_ATTRIBUTE
private static final java.lang.String LANGUAGE_ATTRIBUTE
private static final java.lang.String CODE_ATTRIBUTE
private static final java.lang.String METHOD_ATTRIBUTE
private InterpreterFactory interpreterFactory
private org.w3c.dom.Document document
private Director director
private java.util.Dictionary parameters
private java.util.Hashtable instances
private java.util.Hashtable globalVariables
Constructor Detail |
public DCPEngine(org.w3c.dom.Document document, InterpreterFactory factory, java.util.Dictionary parameters)
This method sets the DOM tree to be scanned for dynamic content <?dcp?> processing instructions as well as the context parameters provided by the invoking environment.
document
- The document to be processed for dynamic contentparameters
- The table of environment variables to be used during processingMethod Detail |
public void process() throws java.lang.Exception
This method carries out the actual expansion of dynamic content processing instructions embedded in the document.
private void doProcess(org.w3c.dom.Node node)
private void processObject(org.w3c.dom.ProcessingInstruction pi) throws java.lang.Exception
private org.w3c.dom.Node processContent(org.w3c.dom.ProcessingInstruction pi) throws java.lang.Exception
private void processVariable(org.w3c.dom.ProcessingInstruction pi) throws java.lang.Exception
private void parseAttributes(java.lang.String data, java.util.Hashtable attributes)
private org.w3c.dom.Node[] getChildren(org.w3c.dom.Node node)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |