You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by rg...@apache.org on 2004/11/08 07:07:17 UTC
svn commit: rev 56906 - cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/layout/renderer/aspect/impl
Author: rgoers
Date: Sun Nov 7 22:07:15 2004
New Revision: 56906
Modified:
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/layout/renderer/aspect/impl/TabContentAspect.java
Log:
bug 31229 - generate navigation for non-selected tabs
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/layout/renderer/aspect/impl/TabContentAspect.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/layout/renderer/aspect/impl/TabContentAspect.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/layout/renderer/aspect/impl/TabContentAspect.java Sun Nov 7 22:07:15 2004
@@ -18,6 +18,8 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
import org.apache.avalon.framework.parameters.ParameterException;
import org.apache.avalon.framework.parameters.Parameters;
@@ -47,6 +49,23 @@
* </composite>
* </pre>
*
+ * <h2>Example XML with sub-navigation:</h2>
+ * <pre>
+ * <composite>
+ * <named-item name="..." parameter="link-event"/>
+ * <named-item name="..." selected="true">
+ * <!-- output from processing layout -->
+ * </named-item>
+ * <named-item name="..." parameter="link-event"/>
+ * <named-item name="..." parameter="link-event">
+ * <<i>child-tag-name</i>>
+ * <named-item name="..." parameter="link-event"/>
+ * <named-item name="..." parameter="link-event"/>
+ * </<i>child-tag-name</i>>
+ * </named-item>
+ * </composite>
+ * </pre>
+ *
* <h2>Applicable to:</h2>
* <ul>
* <li>{@link org.apache.cocoon.portal.layout.CompositeLayout}</li>
@@ -60,6 +79,10 @@
* <td></td><td>String</td><td><code>"composite"</code></td></tr>
* <tr><th>root-tag</th><td>Should a tag enclosing the following output be generated?</td>
* <td></td><td>boolean</td><td><code>true</code></td></tr>
+ * <tr><th>child-tag-name</th><td>The name of the tag to enclose named items (i.e. the subnavigation)
+ * of non-selected items. If a value is not specified then no sub-navigation named items will be
+ * generated.</td>
+ * <td></td><td>String</td><td><code>""</code></td></tr>
* </tbody></table>
*
* @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
@@ -95,6 +118,7 @@
// loop over all tabs
for (int j = 0; j < tabLayout.getSize(); j++) {
Item tab = tabLayout.getItem(j);
+ ChangeAspectDataEvent event = null;
// open named-item tag
attributes.clear();
@@ -104,7 +128,7 @@
if (j == selected) {
attributes.addCDATAAttribute("selected", "true");
}
- ChangeAspectDataEvent event = new ChangeAspectDataEvent(tabLayout, config.aspectName, new Integer(j));
+ event = new ChangeAspectDataEvent(tabLayout, config.aspectName, new Integer(j));
attributes.addCDATAAttribute("parameter", service.getComponentManager().getLinkService().getLinkURI(event));
// add parameters
@@ -117,7 +141,12 @@
XMLUtils.startElement(handler, "named-item", attributes);
if (j == selected) {
this.processLayout(tab.getLayout(), service, handler);
+ } else if (config.showAllNav) {
+ List events = new ArrayList();
+ events.add(event);
+ this.processNav(context, tab.getLayout(), service, handler, events);
}
+
// close named-item tag
XMLUtils.endElement(handler, "named-item");
}
@@ -128,8 +157,6 @@
} else {
throw new SAXException("Wrong layout type, TabLayout expected: " + layout.getClass().getName());
}
-
-
}
/**
@@ -148,14 +175,89 @@
return Collections.singletonList(desc).iterator();
}
+ /*
+ * Generate the sub navigation for non-selected tabs
+ * @param context
+ * @param layout
+ * @param service
+ * @param handler
+ * @throws SAXException
+ */
+ private void processNav(RendererAspectContext context,
+ Layout layout,
+ PortalService service,
+ ContentHandler handler,
+ List parentEvents)
+ throws SAXException {
+ if (layout instanceof CompositeLayout) {
+ CompositeLayout tabLayout = (CompositeLayout)layout;
+
+ if (tabLayout.getSize() == 0) {
+ return;
+ }
+ TabPreparedConfiguration config =
+ (TabPreparedConfiguration) context.getAspectConfiguration();
+ AttributesImpl attributes = new AttributesImpl();
+ boolean subNav = false;
+
+ // loop over all tabs
+ for (int j = 0; j < tabLayout.getSize(); j++) {
+ Item tab = tabLayout.getItem(j);
+
+ // open named-item tag
+ attributes.clear();
+ if (tab instanceof NamedItem) {
+ if (!subNav) {
+ XMLUtils.startElement(handler, config.childTagName);
+ subNav = true;
+ }
+ attributes.addCDATAAttribute("name",
+ String.valueOf(((NamedItem) tab).getName()));
+ ChangeAspectDataEvent event = new ChangeAspectDataEvent(tabLayout,
+ config.aspectName, new Integer(j));
+ List events = new ArrayList(parentEvents);
+ events.add(event);
+
+ attributes.addCDATAAttribute("parameter",
+ service.getComponentManager().getLinkService().getLinkURI(events));
+
+ // add parameters
+ final Iterator iter = tab.getParameters().entrySet().iterator();
+ while (iter.hasNext()) {
+ final Map.Entry entry = (Map.Entry) iter.next();
+ attributes.addCDATAAttribute((String) entry.getKey(),
+ (String) entry.getValue());
+ }
+
+ XMLUtils.startElement(handler, "named-item", attributes);
+
+ this.processNav(context, tab.getLayout(), service, handler, events);
+
+ // close named-item tag
+ XMLUtils.endElement(handler, "named-item");
+ }
+
+
+ }
+ // close sub-nav tag
+ if (subNav) {
+ XMLUtils.endElement(handler, config.childTagName);
+ }
+ }
+ }
+
protected class TabPreparedConfiguration extends PreparedConfiguration {
public String aspectName;
public String store;
-
+ public boolean showAllNav = false;
+ public String childTagName;
+
public void takeValues(TabPreparedConfiguration from) {
super.takeValues(from);
this.aspectName = from.aspectName;
this.store = from.store;
+ this.showAllNav = from.showAllNav;
+ this.childTagName = from.childTagName;
}
}
@@ -168,6 +270,10 @@
pc.takeValues((PreparedConfiguration)super.prepareConfiguration(configuration));
pc.aspectName = configuration.getParameter("aspect-name", "tab");
pc.store = configuration.getParameter("store");
+ pc.childTagName = configuration.getParameter("child-tag-name", "");
+ if (!pc.childTagName.equals("")) {
+ pc.showAllNav = true;
+ }
return pc;
}
RE: svn commit: rev 56906 - cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/layout/renderer/aspect/impl
Posted by Carsten Ziegeler <cz...@apache.org>.
Did you also commit this into trunk? (Maybe I did oversee it is currently
a little bit difficult to read emails :( )
Carsten
> -----Original Message-----
> From: rgoers@apache.org [mailto:rgoers@apache.org]
> Sent: Monday, November 08, 2004 7:07 AM
> To: cvs@cocoon.apache.org
> Subject: svn commit: rev 56906 -
> cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache
/cocoon/portal/layout/renderer/aspect/impl
>
> Author: rgoers
> Date: Sun Nov 7 22:07:15 2004
> New Revision: 56906
>
> Modified:
>
> cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache
/cocoon/portal/layout/renderer/aspect/impl/TabContentAspect.java
> Log:
> bug 31229 - generate navigation for non-selected tabs
>
>
> Modified:
> cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache
/cocoon/portal/layout/renderer/aspect/impl/TabContentAspect.java
> ==============================================================
> ================
> ---
> cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache
/cocoon/portal/layout/renderer/aspect/impl/TabContentAspect.java
(original)
> +++
> cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache
/cocoon/portal/layout/renderer/aspect/impl/TabContentAspect.java Sun
Nov 7 > 22:07:15 2004
> @@ -18,6 +18,8 @@
> import java.util.Collections;
> import java.util.Iterator;
> import java.util.Map;
> +import java.util.List;
> +import java.util.ArrayList;
>
> import org.apache.avalon.framework.parameters.ParameterException;
> import org.apache.avalon.framework.parameters.Parameters;
> @@ -47,6 +49,23 @@
> * </composite>
> * </pre>
> *
> + * <h2>Example XML with sub-navigation:</h2>
> + * <pre>
> + * <composite>
> + * <named-item name="..." parameter="link-event"/>
> + * <named-item name="..." selected="true">
> + * <!-- output from processing layout -->
> + * </named-item>
> + * <named-item name="..." parameter="link-event"/>
> + * <named-item name="..." parameter="link-event">
> + * <<i>child-tag-name</i>>
> + * <named-item name="..." parameter="link-event"/>
> + * <named-item name="..." parameter="link-event"/>
> + * </<i>child-tag-name</i>>
> + * </named-item>
> + * </composite>
> + * </pre>
> + *
> * <h2>Applicable to:</h2>
> * <ul>
> * <li>{@link org.apache.cocoon.portal.layout.CompositeLayout}</li>
> @@ -60,6 +79,10 @@
> *
> <td></td><td>String</td><td><code>"composite"</code></td></tr>
> * <tr><th>root-tag</th><td>Should a tag enclosing the
> following output be generated?</td>
> * <td></td><td>boolean</td><td><code>true</code></td></tr>
> + * <tr><th>child-tag-name</th><td>The name of the tag to
> enclose named
> + items (i.e. the subnavigation)
> + * of non-selected items. If a value is not specified then no
> + sub-navigation named items will be
> + * generated.</td>
> + * <td></td><td>String</td><td><code>""</code></td></tr>
> * </tbody></table>
> *
> * @author <a href="mailto:cziegeler@s-und-n.de">Carsten
> Ziegeler</a> @@ -95,6 +118,7 @@
> // loop over all tabs
> for (int j = 0; j < tabLayout.getSize(); j++) {
> Item tab = tabLayout.getItem(j);
> + ChangeAspectDataEvent event = null;
>
> // open named-item tag
> attributes.clear();
> @@ -104,7 +128,7 @@
> if (j == selected) {
> attributes.addCDATAAttribute("selected", "true");
> }
> - ChangeAspectDataEvent event = new
> ChangeAspectDataEvent(tabLayout, config.aspectName, new Integer(j));
> + event = new ChangeAspectDataEvent(tabLayout,
> + config.aspectName, new Integer(j));
> attributes.addCDATAAttribute("parameter",
> service.getComponentManager().getLinkService().getLinkURI(event));
>
> // add parameters
> @@ -117,7 +141,12 @@
> XMLUtils.startElement(handler, "named-item",
> attributes);
> if (j == selected) {
> this.processLayout(tab.getLayout(),
> service, handler);
> + } else if (config.showAllNav) {
> + List events = new ArrayList();
> + events.add(event);
> + this.processNav(context,
> tab.getLayout(), service,
> + handler, events);
> }
> +
> // close named-item tag
> XMLUtils.endElement(handler, "named-item");
> }
> @@ -128,8 +157,6 @@
> } else {
> throw new SAXException("Wrong layout type,
> TabLayout expected: " + layout.getClass().getName());
> }
> -
> -
> }
>
> /**
> @@ -148,14 +175,89 @@
> return Collections.singletonList(desc).iterator();
> }
>
> + /*
> + * Generate the sub navigation for non-selected tabs
> + * @param context
> + * @param layout
> + * @param service
> + * @param handler
> + * @throws SAXException
> + */
> + private void processNav(RendererAspectContext context,
> + Layout layout,
> + PortalService service,
> + ContentHandler handler,
> + List parentEvents)
> + throws SAXException {
> + if (layout instanceof CompositeLayout) {
> + CompositeLayout tabLayout = (CompositeLayout)layout;
> +
> + if (tabLayout.getSize() == 0) {
> + return;
> + }
> + TabPreparedConfiguration config =
> + (TabPreparedConfiguration)
> context.getAspectConfiguration();
> + AttributesImpl attributes = new AttributesImpl();
> + boolean subNav = false;
> +
> + // loop over all tabs
> + for (int j = 0; j < tabLayout.getSize(); j++) {
> + Item tab = tabLayout.getItem(j);
> +
> + // open named-item tag
> + attributes.clear();
> + if (tab instanceof NamedItem) {
> + if (!subNav) {
> + XMLUtils.startElement(handler,
> config.childTagName);
> + subNav = true;
> + }
> + attributes.addCDATAAttribute("name",
> + String.valueOf(((NamedItem) tab).getName()));
> + ChangeAspectDataEvent event = new
> ChangeAspectDataEvent(tabLayout,
> + config.aspectName, new Integer(j));
> + List events = new ArrayList(parentEvents);
> + events.add(event);
> +
> + attributes.addCDATAAttribute("parameter",
> +
> + service.getComponentManager().getLinkService().getLinkURI(events));
> +
> + // add parameters
> + final Iterator iter =
> tab.getParameters().entrySet().iterator();
> + while (iter.hasNext()) {
> + final Map.Entry entry = (Map.Entry)
> iter.next();
> +
> attributes.addCDATAAttribute((String) entry.getKey(),
> + (String) entry.getValue());
> + }
> +
> + XMLUtils.startElement(handler, "named-item",
> + attributes);
> +
> + this.processNav(context,
> tab.getLayout(), service,
> + handler, events);
> +
> + // close named-item tag
> + XMLUtils.endElement(handler, "named-item");
> + }
> +
> +
> + }
> + // close sub-nav tag
> + if (subNav) {
> + XMLUtils.endElement(handler, config.childTagName);
> + }
> + }
> + }
> +
> protected class TabPreparedConfiguration extends
> PreparedConfiguration {
> public String aspectName;
> public String store;
> -
> + public boolean showAllNav = false;
> + public String childTagName;
> +
> public void takeValues(TabPreparedConfiguration from) {
> super.takeValues(from);
> this.aspectName = from.aspectName;
> this.store = from.store;
> + this.showAllNav = from.showAllNav;
> + this.childTagName = from.childTagName;
> }
> }
>
> @@ -168,6 +270,10 @@
>
> pc.takeValues((PreparedConfiguration)super.prepareConfiguratio
> n(configuration));
> pc.aspectName =
> configuration.getParameter("aspect-name", "tab");
> pc.store = configuration.getParameter("store");
> + pc.childTagName =
> configuration.getParameter("child-tag-name", "");
> + if (!pc.childTagName.equals("")) {
> + pc.showAllNav = true;
> + }
> return pc;
> }
>
>