Hi all,

A new enhanced implementation of my JSP like Cocoon Tag-Library is now
available. I think it is now ready to go into scratchpad ;-). The first version
I have posted some weeks ago. I send the Code of the Taglib implementation as a
PATH in the next 10 minutes, to keep this mail smaller than 100k.

I have appended examples (webapp.zip, parent.html)
Three different Tag Interfaces are now available:

**Tag**, a Tag which does not consume or produce content. Example is
org.apache.cocoon.taglib.i18n.LocaleTag which only defines a "LocaleContext" for
the embedded child Tags. A child Tag can use
LocaleTag localeTag = (LocaleTag) TagSupport.findAncestorWithClass(this,
LocaleTag.class);
to find its enclosing LocaleTag. LocaleTag can also select the Locale as an
attribute from the request, session, or application
 (<i18n:locale localeRef="$session/locale">).  See also parent.xhtml in
webapp.zip attachment (sorry for using xhtml directly and not XML/XSLT).


**XMLProducerTag**, a Tag which only produces content. Example
org.apache.cocoon.taglib.test.HelloWorldTag which prints out "Hello World" in
german or english dependent of the enclosing LocaleTag.


**XMLConsumerTag**, consumes content only (no examples in the moment)


**TransformerTag**, works like a Transformer see
org.apache.cocoon.taglib.string.UpperCaseTag which translate the text content to
upper case.


**IterationTag**, for Tags which need to iterate.
A simple example for a IterationTag is org.apache.cocoon.taglib.test.
IterationTestTag. The Iteration Tag itself does not implement the Iteration
loop, this is implemented by the TagTransformer (see start and endElement
Method). With IterationTestTag you can repeat the content as specified by count
attribute (default is 2).
Tag attributes are automatic mapped to the corresponding set method.


The Taglib implementation also allows setting and getting Variables. The
implementation is based on the Jakarta JXPath Project. There are predefined
variables request, session and application which are mapped to Cocoon Request,
Session and Context Object. This works like JSP request, session and application
scope.
Look at org.apache.cocoon.taglib.VarTagSupport for the implementation. The
VariableContext is implemented as a RequestLifecycleComponent, so each Pipeline
has it's own set of variables.

Example:
The org.apache.cocoon.taglib.test.acting.TagtestAction adds one attribute
BrowserLocales (Enumeration of the Browser Locales) to the Request and one
attribute RequestInfo (Collection, five entries) to the Session.


<jxpath:forEach var="i" items="$request/BrowserLocales" >
   <li><jxpath:out value="$i/language" /></li>
</jxpath:forEach>

forEach Tag (org.apache.cocoon.taglib.jxpath.core.ForEachTag) loops over all
Browser Locales and assign the current value to the variable i. The out Tag
selects from the variable i (type Locale) the language property. This works,
because JXPath applies Xpath expressions to graphs of objects of all kinds,
JavaBeans, Maps, DOM etc, including mixtures thereof. I have added support for
Cocoon Request, Session and Context.

<jxpath:out value="$session/RequestInfo[5]/language" />
selects the attribute RequestInfo from the Session. The 5th value of the
returned Collection, a Locale, is selected and the language property is send out
to the SAX-Pipeline.

With the OutTag is is also possible to set attributes.
<jxpath:out var="$session/language" value="$session/RequestInfo[5]/language" />
Now the session attribute language is set with the result of the value
expression.

Please look at the "parent.html" attachment. This file is the output of the
parent.xhtml (webapp.zip).

I you want to see a live demo, you can add the examples of webapp.zip file to
your cocoon engine. Add the compiled Classes of taglib.zip (extract from my
PATCH) to your cocoon engine. You need to add the content from tag.xconf to your
cocoon.xconf and configure the rest of the files as a subsitemap (see
sitemap.xmap) in your webapplication. Start with TaglibTest.xhtml.

I have also implemented a SourceTag, wich is able to insert the output of a
Source. I have used Cocoon 2.0.3, may be this tag is not working with 2.1 HEAD
because of changes in the Source implementation. With this SourceTag it is
possible to design a page as a set of components (pipelines). The SourceTag is
used in the variable-r.xhtml example.

I hope my Java code is better than my English explanation ;-)

Regards,
Volker

(See attached file: webapp.zip)(See attached file: parent.html)

Attachment: webapp.zip
Description: .ZIP File

Attachment: parent.html
Description: Binary data

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to