cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding RepeaterJXPathBindingBuilder.java RepeaterJXPathBinding.java
Date Thu, 18 Sep 2003 20:16:13 GMT
mpo         2003/09/18 13:16:13

  Modified:    src/blocks/woody/java/org/apache/cocoon/woody/binding
                        RepeaterJXPathBindingBuilder.java
                        RepeaterJXPathBinding.java
  Log:
  Adding support for convertor on the uniqueRowId of a repeater.
  (Renaming some variables for clarity while at it.)
  
  The new convertor should be added as follows:
  <wb:repeater ...>
    <wd:convertor type=".." />
   ..
  </wb:repeater>
  
  Revision  Changes    Path
  1.5       +22 -9     cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/RepeaterJXPathBindingBuilder.java
  
  Index: RepeaterJXPathBindingBuilder.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/RepeaterJXPathBindingBuilder.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- RepeaterJXPathBindingBuilder.java	26 Aug 2003 13:10:12 -0000	1.4
  +++ RepeaterJXPathBindingBuilder.java	18 Sep 2003 20:16:13 -0000	1.5
  @@ -50,6 +50,11 @@
   */
   package org.apache.cocoon.woody.binding;
   
  +import java.util.Locale;
  +
  +import org.apache.cocoon.i18n.I18nUtils;
  +import org.apache.cocoon.woody.Constants;
  +import org.apache.cocoon.woody.datatype.convertor.Convertor;
   import org.apache.cocoon.woody.util.DomHelper;
   import org.w3c.dom.Element;
   
  @@ -103,9 +108,21 @@
               String rowPath = DomHelper.getAttribute(bindingElm, "row-path");
               String uniqueRowId =
                   DomHelper.getAttribute(bindingElm, "unique-row-id");
  -            String uniquePath =
  +            String uniqueRowIdPath =
                   DomHelper.getAttribute(bindingElm, "unique-path");
   
  +
  +            Convertor convertor = null;
  +            Locale convertorLocale = Locale.US;
  +            Element convertorEl = DomHelper.getChildElement(bindingElm, Constants.WD_NS,
"convertor");
  +            if (convertorEl != null) {
  +                String datatype = DomHelper.getAttribute(convertorEl, "datatype");
  +                String localeStr = convertorEl.getAttribute("datatype");
  +                if (!localeStr.equals(""))
  +                    convertorLocale = I18nUtils.parseLocale(localeStr);
  +                convertor = assistant.getDatatypeManager().createConvertor(datatype, convertorEl);
  +            }
  +
               Element childWrapElement =
                   DomHelper.getChildElement(
                       bindingElm,
  @@ -139,14 +156,10 @@
   
               RepeaterJXPathBinding repeaterBinding =
                   new RepeaterJXPathBinding(
  -                    repeaterId,
  -                    parentPath,
  -                    rowPath,
  -                    uniqueRowId,
  -                    uniquePath,
  -                    childBindings,
  -                    insertBinding,
  -                    deleteBindings);
  +                    repeaterId, parentPath, rowPath,
  +                    uniqueRowId, uniqueRowIdPath,
  +                    convertor, convertorLocale, 
  +                    childBindings, insertBinding, deleteBindings);
   
               return repeaterBinding;
           } catch (BindingException e) {
  
  
  
  1.7       +42 -11    cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/RepeaterJXPathBinding.java
  
  Index: RepeaterJXPathBinding.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/RepeaterJXPathBinding.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- RepeaterJXPathBinding.java	9 Sep 2003 09:14:52 -0000	1.6
  +++ RepeaterJXPathBinding.java	18 Sep 2003 20:16:13 -0000	1.7
  @@ -54,9 +54,11 @@
   import java.util.HashSet;
   import java.util.Iterator;
   import java.util.List;
  +import java.util.Locale;
   import java.util.Set;
   
   import org.apache.avalon.framework.logger.Logger;
  +import org.apache.cocoon.woody.datatype.convertor.Convertor;
   import org.apache.cocoon.woody.formmodel.Widget;
   import org.apache.cocoon.woody.formmodel.Repeater;
   import org.apache.commons.jxpath.JXPathContext;
  @@ -73,7 +75,9 @@
       private final String repeaterPath;
       private final String rowPath;
       private final String uniqueRowId;
  -    private final String uniqueRowPath;
  +    private final String uniqueRowIdPath;
  +    private final Convertor uniqueRowIdConvertor;
  +    private final Locale uniqueRowIdConvertorLocale;
       private final ValueJXPathBinding uniqueFieldBinding;
       private final JXPathBindingBase rowBinding;
       private final JXPathBindingBase insertRowBinding;
  @@ -82,16 +86,30 @@
       /**
        * Constructs RepeaterJXPathBinding
        */
  -    public RepeaterJXPathBinding(String repeaterId, String repeaterPath, String rowPath,
String uniqueRowId,
  -                                 String uniqueRowPath, JXPathBindingBase[] childBindings,
  +    public RepeaterJXPathBinding(String repeaterId, String repeaterPath, String rowPath,

  +                                 String uniqueRowId, String uniqueRowPath, 
  +                                 JXPathBindingBase[] childBindings,
  +                                 JXPathBindingBase insertBinding, JXPathBindingBase[] deleteBindings)
{
  +        this(repeaterId, repeaterPath, rowPath, uniqueRowId, uniqueRowPath, null, null,
childBindings, insertBinding, deleteBindings);
  +    }
  +
  +    /**
  +     * Constructs RepeaterJXPathBinding
  +     */
  +    public RepeaterJXPathBinding(String repeaterId, String repeaterPath, String rowPath,

  +                                 String uniqueRowId, String uniqueRowPath, 
  +                                 Convertor convertor, Locale convertorLocale, 
  +                                 JXPathBindingBase[] childBindings,
                                    JXPathBindingBase insertBinding, JXPathBindingBase[] deleteBindings)
{
           this.repeaterId = repeaterId;
           this.repeaterPath = repeaterPath;
           this.rowPath = rowPath;
           this.uniqueRowId = uniqueRowId;
  -        this.uniqueRowPath = uniqueRowPath;
  +        this.uniqueRowIdPath = uniqueRowPath;
           this.uniqueFieldBinding =
  -            new ValueJXPathBinding(uniqueRowId, uniqueRowPath, true, null, null, null);
  +            new ValueJXPathBinding(uniqueRowId, uniqueRowPath, true, null, convertor, convertorLocale);
  +        this.uniqueRowIdConvertor = convertor;
  +        this.uniqueRowIdConvertorLocale = convertorLocale;
           this.rowBinding = new ComposedJXPathBindingBase(childBindings);
           this.insertRowBinding = insertBinding;
           this.deleteRowBinding = new ComposedJXPathBindingBase(deleteBindings);
  @@ -154,9 +172,8 @@
           for (int i = 0; i < formRowCount; i++) {
               Repeater.RepeaterRow thisRow = repeater.getRow(i);
   
  -            //TODO future might need data-conversion here
               Widget rowIdWidget = thisRow.getWidget(this.uniqueRowId);
  -            String rowIdValue = (String) rowIdWidget.getValue();
  +            Object rowIdValue = rowIdWidget.getValue();
   
               if (rowIdValue != null) {
                   //if rowIdValue != null --> iterate nodes to find match 
  @@ -167,8 +184,15 @@
                       JXPathContext rowContext =
                           repeaterContext.getRelativeContext(jxp);
   
  -                    //TODO future might need data-conversion here
  -                    String matchId = (String) rowContext.getValue(this.uniqueRowPath);
  +                    Object matchId = rowContext.getValue(this.uniqueRowIdPath);
  +                    if (matchId != null && this.uniqueRowIdConvertor != null) {
  +                        if (matchId instanceof String) {
  +                            matchId = this.uniqueRowIdConvertor.convertFromString((String)matchId,
this.uniqueRowIdConvertorLocale, null);
  +                        } else {
  +                            getLogger().warn("Convertor ignored on backend-value which
isn't of type String.");
  +                        }                            
  +                    }                        
  +
                       if (rowIdValue.equals(matchId)) {
                           // match! --> bind to children
                           this.rowBinding.saveFormToModel(thisRow, rowContext);
  @@ -189,9 +213,16 @@
           while (rowPointers.hasNext()) {
               Pointer jxp = (Pointer) rowPointers.next();
               JXPathContext rowContext = repeaterContext.getRelativeContext(jxp);
  -            //TODO future might need data-conversion here
  -            String matchId = (String) rowContext.getValue(this.uniqueRowPath);
   
  +            Object matchId = rowContext.getValue(this.uniqueRowIdPath);
  +            if (matchId != null && this.uniqueRowIdConvertor != null) {
  +                if (matchId instanceof String) {
  +                    matchId = this.uniqueRowIdConvertor.convertFromString((String)matchId,
this.uniqueRowIdConvertorLocale, null);
  +                } else {
  +                    getLogger().warn("Convertor ignored on backend-value which isn't of
type String.");
  +                }                            
  +            }  
  +            
               // check if matchPath was in list of updates, if not --> bind for delete
               if (!updatedRowIds.contains(matchId)) {
                   rowsToDelete.add(rowContext);
  
  
  

Mime
View raw message