You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2005/11/14 20:53:56 UTC
svn commit: r344193 -
/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/transformation/CopletTransformer.java
Author: cziegeler
Date: Mon Nov 14 11:53:42 2005
New Revision: 344193
URL: http://svn.apache.org/viewcvs?rev=344193&view=rev
Log:
Fix bug in streaming of coplet information
Add streaming of layout information
Modified:
cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/transformation/CopletTransformer.java
Modified: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/transformation/CopletTransformer.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/transformation/CopletTransformer.java?rev=344193&r1=344192&r2=344193&view=diff
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/transformation/CopletTransformer.java (original)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/transformation/CopletTransformer.java Mon Nov 14 11:53:42 2005
@@ -31,6 +31,7 @@
import org.apache.cocoon.portal.event.layout.LayoutJXPathEvent;
import org.apache.cocoon.portal.layout.Layout;
import org.apache.cocoon.xml.AttributesImpl;
+import org.apache.cocoon.xml.XMLUtils;
import org.apache.commons.jxpath.JXPathContext;
import org.apache.excalibur.xml.sax.XMLizable;
import org.xml.sax.Attributes;
@@ -38,19 +39,27 @@
/**
* This transformer offers various functions for developing pipeline based coplets.
+ * All elements that are processed by this transformer have the namespace
+ * "http://apache.org/cocoon/portal/coplet/1.0". We assume in the following docs
+ * that a prefix "coplet" has been defined for this namespace.
*
- * Includes coplet instance data by using JXPath expressions.
- * The transformer searches for tags <coplet:coplet xmlns:coplet="http://apache.org/cocoon/portal/coplet/1.0">.
- * They must have an attribute "select" that contains a valid JXPath expression applying to the coplet instance data.<br><br>
+ * Including information from a coplet
+ * With the "coplet" element, information from a coplet can be included in the document.
+ * The element must have an attribute "select" that contains a valid JXPath expression
+ * applying to the coplet instance data, e.g.
+ * <coplet:coplet select="title">
+ * The above statement only works if the pipeline is a pipeline for the current coplet.
+ * If you want to include information from an arbitrary coplet, you can use the "id"
+ * attribute to specify the identifier of the instance.
*
* Example:<br><br>
*
- * <pre><maxpageable xmlns:coplet="http://apache.org/cocoon/portal/coplet/1.0">
- * <coplet:coplet select="copletData.maxpageable"/>
- * </maxpageable><br></pre>
+ * <pre><title xmlns:coplet="http://apache.org/cocoon/portal/coplet/1.0">
+ * <coplet:coplet select="title"/>
+ * </title><br></pre>
+ *
+ * The transformer will insert the string value of the coplet's title.
*
- * The transformer will insert the boolean value specifying whether the coplet is
- * maxpageable or not.<br>
* Please see also the documentation of superclass AbstractCopletTransformer for how
* the coplet instance data are acquired.
*
@@ -62,12 +71,13 @@
/** The namespace URI to listen for. */
public static final String NAMESPACE_URI = "http://apache.org/cocoon/portal/coplet/1.0";
- /** The XML element name to listen for: coplet. */
+ /** The XML element name for including coplet information: coplet. */
public static final String COPLET_ELEM = "coplet";
- /**
- * The attribute containing the JXPath expression.
- */
+ /** The XML element name for including layout information: layout. */
+ public static final String LAYOUT_ELEM = "coplet";
+
+ /** The attribute containing the JXPath expression: select. */
public static final String SELECT_ATTR = "select";
@@ -130,18 +140,37 @@
if (name.equals(COPLET_ELEM)) {
String expression = attr.getValue(SELECT_ATTR);
if (expression == null) {
- throw new ProcessingException("Attribute "+SELECT_ATTR+" must be spcified.");
+ throw new SAXException("Attribute '"+SELECT_ATTR+"' must be specified on element " + COPLET_ELEM + ".");
}
-
- CopletInstanceData cid = this.getCopletInstanceData();
-
- JXPathContext jxpathContext = JXPathContext.newContext( cid );
- Object object = jxpathContext.getValue(expression);
-
- if (object == null) {
- throw new ProcessingException("Could not find value for expression "+expression);
+ final String copletId = attr.getValue("id");
+ final CopletInstanceData cid = this.getCopletInstanceData(copletId);
+ if ( cid == null ) {
+ throw new SAXException("Unable to find coplet instance data with id '" + copletId + "'.");
}
-
+ final JXPathContext jxpathContext = JXPathContext.newContext( cid );
+ final Object object = jxpathContext.getValue(expression);
+ if (object != null) {
+ XMLUtils.valueOf(contentHandler, object);
+ }
+ } else if (name.equals(LAYOUT_ELEM) ) {
+ String expression = attr.getValue(SELECT_ATTR);
+ if (expression == null) {
+ throw new SAXException("Attribute '"+SELECT_ATTR+"' must be specified on element " + LAYOUT_ELEM + ".");
+ }
+ final String layoutId = attr.getValue("id");
+ if ( layoutId == null ) {
+ throw new SAXException("Attribute 'id' must be specified on element " + LAYOUT_ELEM + ".");
+ }
+ final String profile = attr.getValue("profile");
+ final Layout l = this.portalService.getComponentManager().getProfileManager().getPortalLayout(profile, layoutId);
+ if ( l == null ) {
+ throw new SAXException("Unable to find layout with id '" + layoutId + "' in profile '" + profile + "'.");
+ }
+ final JXPathContext jxpathContext = JXPathContext.newContext( l );
+ final Object object = jxpathContext.getValue(expression);
+ if (object != null) {
+ XMLUtils.valueOf(contentHandler, object);
+ }
} else if (name.equals(LINK_ELEM)) {
final LinkService linkService = this.portalService.getComponentManager().getLinkService();
@@ -270,8 +299,6 @@
}
} else if ( name.equals(CONTENT_ELEM) && this.insideLinks ) {
this.content = this.endSAXRecording();
- } else if (!name.equals(COPLET_ELEM) && !name.equals(PARAMETER_ELEM)) {
- throw new SAXException("Unknown element '"+name+"' in namespace '"+NAMESPACE_URI+"'.");
}
}