You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by gi...@apache.org on 2005/03/22 20:11:01 UTC
svn commit: r158639 - in
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms: Constants.java
datatype/EnumSelectionList.java datatype/FlowJXPathSelectionList.java
datatype/FlowJXPathSelectionListBuilder.java
Author: giacomo
Date: Tue Mar 22 11:10:59 2005
New Revision: 158639
URL: http://svn.apache.org/viewcvs?view=rev&rev=158639
Log:
added features to the flow-jxpath selection list type
Modified:
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/Constants.java
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/EnumSelectionList.java
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionList.java
cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListBuilder.java
Modified: cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/Constants.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/Constants.java?view=diff&r1=158638&r2=158639
==============================================================================
--- cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/Constants.java (original)
+++ cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/Constants.java Tue Mar 22 11:10:59 2005
@@ -49,5 +49,8 @@
/** I18n catalogue containing the built-in messages. */
public static final String I18N_CATALOGUE = "forms";
+ public static final String I18N_NS = "http://apache.org/cocoon/i18n/2.1";
+ public static final String I18N_PREFIX = "i18n";
+ public static final String I18N_PREFIX_COLON = "i18n:";
}
Modified: cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/EnumSelectionList.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/EnumSelectionList.java?view=diff&r1=158638&r2=158639
==============================================================================
--- cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/EnumSelectionList.java (original)
+++ cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/EnumSelectionList.java Tue Mar 22 11:10:59 2005
@@ -56,8 +56,6 @@
* @version $Id$
*/
public class EnumSelectionList implements SelectionList {
- public static final String I18N_NS = "http://apache.org/cocoon/i18n/2.1";
- public static final String I18N_PREFIX_COLON = "i18n:";
public static final String TEXT_EL = "text";
private Datatype datatype;
@@ -108,9 +106,9 @@
contentHandler.startElement(Constants.INSTANCE_NS, ITEM_EL, Constants.INSTANCE_PREFIX_COLON + ITEM_EL, itemAttrs);
contentHandler.startElement(Constants.INSTANCE_NS, LABEL_EL, Constants.INSTANCE_PREFIX_COLON + LABEL_EL, XMLUtils.EMPTY_ATTRIBUTES);
// TODO: make i18n element optional
- contentHandler.startElement(I18N_NS, TEXT_EL, I18N_PREFIX_COLON + TEXT_EL, XMLUtils.EMPTY_ATTRIBUTES);
+ contentHandler.startElement(Constants.I18N_NS, TEXT_EL, Constants.I18N_PREFIX_COLON + TEXT_EL, XMLUtils.EMPTY_ATTRIBUTES);
contentHandler.characters(stringValue.toCharArray(), 0, stringValue.length());
- contentHandler.endElement(I18N_NS, TEXT_EL, I18N_PREFIX_COLON + TEXT_EL);
+ contentHandler.endElement(Constants.I18N_NS, TEXT_EL, Constants.I18N_PREFIX_COLON + TEXT_EL);
contentHandler.endElement(Constants.INSTANCE_NS, LABEL_EL, Constants.INSTANCE_PREFIX_COLON + LABEL_EL);
contentHandler.endElement(Constants.INSTANCE_NS, ITEM_EL, Constants.INSTANCE_PREFIX_COLON + ITEM_EL);
}
Modified: cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionList.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionList.java?view=diff&r1=158638&r2=158639
==============================================================================
--- cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionList.java (original)
+++ cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionList.java Tue Mar 22 11:10:59 2005
@@ -22,6 +22,7 @@
import org.apache.cocoon.components.ContextHelper;
import org.apache.cocoon.components.flow.FlowHelper;
import org.apache.cocoon.forms.Constants;
+import org.apache.cocoon.forms.util.I18nMessage;
import org.apache.cocoon.xml.AttributesImpl;
import org.apache.cocoon.xml.XMLUtils;
import org.apache.commons.jxpath.JXPathContext;
@@ -46,13 +47,31 @@
private String labelPath;
private Datatype datatype;
private Object model;
-
- public FlowJXPathSelectionList(Context context, String listPath, String valuePath, String labelPath, Datatype datatype) {
+ private boolean nullable = false;
+ private String nullText;
+ private boolean nullTextIsI18nKey = false;
+ private String i18nCatalog;
+ private boolean labelIsI18nKey = false;
+
+ public FlowJXPathSelectionList(Context context,
+ String listPath,
+ String valuePath,
+ String labelPath,
+ Datatype datatype,
+ String nullText,
+ boolean nullTextIsI18nKey,
+ String i18nCatalog,
+ boolean labelIsI18nKey) {
this.context = context;
this.listPath = listPath;
this.valuePath = valuePath;
this.labelPath = labelPath;
this.datatype = datatype;
+ this.nullText = nullText;
+ this.nullable = (nullText != null);
+ this.nullTextIsI18nKey = nullTextIsI18nKey;
+ this.i18nCatalog =i18nCatalog;
+ this.labelIsI18nKey = labelIsI18nKey;
}
/**
@@ -100,6 +119,39 @@
// Start the selection-list
contentHandler.startElement(Constants.INSTANCE_NS, SELECTION_LIST_EL, Constants.INSTANCE_PREFIX_COLON + SELECTION_LIST_EL, XMLUtils.EMPTY_ATTRIBUTES);
+ if( this.nullable ) {
+ final AttributesImpl voidAttrs = new AttributesImpl( );
+ voidAttrs.addCDATAAttribute( "value", "" );
+ contentHandler.startElement( Constants.INSTANCE_NS, ITEM_EL,
+ Constants.INSTANCE_PREFIX_COLON +
+ ITEM_EL, voidAttrs );
+
+ if( this.nullText != null ) {
+ contentHandler.startElement( Constants.INSTANCE_NS, LABEL_EL,
+ Constants.INSTANCE_PREFIX_COLON +
+ LABEL_EL, XMLUtils.EMPTY_ATTRIBUTES );
+
+ if( this.nullTextIsI18nKey ) {
+ if( ( this.i18nCatalog != null ) &&
+ ( this.i18nCatalog.trim( ).length( ) > 0 ) ) {
+ new I18nMessage( this.nullText, this.i18nCatalog ).toSAX( contentHandler );
+ } else {
+ new I18nMessage( this.nullText ).toSAX( contentHandler );
+ }
+ } else {
+ contentHandler.characters( this.nullText.toCharArray( ), 0,
+ this.nullText.length( ) );
+ }
+
+ contentHandler.endElement( Constants.INSTANCE_NS, LABEL_EL,
+ Constants.INSTANCE_PREFIX_COLON +
+ LABEL_EL );
+ }
+
+ contentHandler.endElement( Constants.INSTANCE_NS, ITEM_EL,
+ Constants.INSTANCE_PREFIX_COLON +
+ ITEM_EL );
+ }
while(iter.hasNext()) {
String stringValue = "";
@@ -135,6 +187,15 @@
contentHandler.startElement(Constants.INSTANCE_NS, LABEL_EL, Constants.INSTANCE_PREFIX_COLON + LABEL_EL, XMLUtils.EMPTY_ATTRIBUTES);
if (label instanceof XMLizable) {
((XMLizable)label).toSAX(contentHandler);
+ } else if( this.labelIsI18nKey ) {
+ String stringLabel = label.toString();
+
+ if( ( this.i18nCatalog != null ) &&
+ ( this.i18nCatalog.trim( ).length( ) > 0 ) ) {
+ new I18nMessage( stringLabel, this.i18nCatalog ).toSAX( contentHandler );
+ } else {
+ new I18nMessage( stringLabel ).toSAX( contentHandler );
+ }
} else {
String stringLabel = label.toString();
contentHandler.characters(stringLabel.toCharArray(), 0, stringLabel.length());
Modified: cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListBuilder.java?view=diff&r1=158638&r2=158639
==============================================================================
--- cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListBuilder.java (original)
+++ cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListBuilder.java Tue Mar 22 11:10:59 2005
@@ -18,9 +18,12 @@
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.cocoon.forms.Constants;
import org.apache.cocoon.forms.util.DomHelper;
import org.w3c.dom.Element;
+import java.util.Map;
+
/**
* Builds a selection list that will take its values from the flow page data.
* The items list and, for each item, its value and label, are fetched using
@@ -56,10 +59,37 @@
public SelectionList build(Element selectionListElement, Datatype datatype) throws Exception {
String listPath = DomHelper.getAttribute(selectionListElement, "list-path");
- String keyPath = DomHelper.getAttribute(selectionListElement, "value-path");
- String valuePath = DomHelper.getAttribute(selectionListElement, "label-path");
-
- return new FlowJXPathSelectionList(context, listPath, keyPath, valuePath, datatype);
+ String valuePath = DomHelper.getAttribute(selectionListElement, "value-path");
+ Map nspfx = DomHelper.getInheritedNSDeclarations(selectionListElement);
+ String i18nPfx = (String)nspfx.get( Constants.I18N_NS );
+ String labelPath = DomHelper.getAttribute(selectionListElement, "label-path", null);
+ boolean labelIsI18nKey = false;
+ if( labelPath == null )
+ {
+ labelPath = DomHelper.getAttribute(selectionListElement, i18nPfx + ":label-path");
+ labelIsI18nKey = true;
+ }
+ String nullText = DomHelper.getAttribute(selectionListElement, "null-text", null);
+ boolean nullTextIsI18nKey = false;
+ if( nullText == null ) {
+ nullText = DomHelper.getAttribute(selectionListElement, i18nPfx + ":null-text", null);
+ if( nullText != null ) {
+ nullTextIsI18nKey = true;
+ }
+ }
+
+ String i18nCatalog = DomHelper.getAttribute(selectionListElement, "catalogue", null);
+
+
+ return new FlowJXPathSelectionList(context,
+ listPath,
+ valuePath,
+ labelPath,
+ datatype,
+ nullText,
+ nullTextIsI18nKey,
+ i18nCatalog,
+ labelIsI18nKey);
}
}