cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/util I18nMessage.java
Date Thu, 29 Jan 2004 03:18:05 GMT
vgritsenko    2004/01/28 19:18:05

  Modified:    src/blocks/woody/java/org/apache/cocoon/woody/datatype
                        FlowJXPathSelectionList.java
               src/blocks/woody/java/org/apache/cocoon/woody/flow/javascript
                        ScriptableWidget.java
               src/blocks/woody/java/org/apache/cocoon/woody/util
                        I18nMessage.java
  Log:
  Support XMLizable labels in the FlowJXPath selection list
  
  Revision  Changes    Path
  1.5       +31 -23    cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/FlowJXPathSelectionList.java
  
  Index: FlowJXPathSelectionList.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/FlowJXPathSelectionList.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- FlowJXPathSelectionList.java	10 Dec 2003 23:34:11 -0000	1.4
  +++ FlowJXPathSelectionList.java	29 Jan 2004 03:18:05 -0000	1.5
  @@ -60,12 +60,14 @@
   import org.apache.cocoon.xml.AttributesImpl;
   import org.apache.commons.jxpath.JXPathContext;
   import org.apache.commons.jxpath.Pointer;
  +import org.apache.excalibur.xml.sax.XMLizable;
  +
   import org.xml.sax.ContentHandler;
   import org.xml.sax.SAXException;
   
   /**
    * A selection list that takes its values from the flow page data.
  - * 
  + *
    * @see org.apache.cocoon.woody.datatype.FlowJXPathSelectionListBuilder
    * @author <a href="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
    * @version CVS $Id$
  @@ -78,7 +80,7 @@
       private String labelPath;
       private Datatype datatype;
       private Object model;
  -    
  +
       public FlowJXPathSelectionList(Context context, String listPath, String valuePath,
String labelPath, Datatype datatype) {
           this.context = context;
           this.listPath = listPath;
  @@ -86,13 +88,13 @@
           this.labelPath = labelPath;
           this.datatype = datatype;
       }
  -    
  +
       /**
        * Builds a dynamic selection list from an in-memory collection.
        * @see org.apache.cocoon.woody.formmodel.Field#setSelectionList(Object model, String
valuePath, String labelPath)
  -     * @param model The collection used as a model for the selection list. 
  +     * @param model The collection used as a model for the selection list.
        * @param valuePath An XPath expression referring to the attribute used
  -     * to populate the values of the list's items. 
  +     * to populate the values of the list's items.
        * @param labelPath An XPath expression referring to the attribute used
        * to populate the labels of the list's items.
        * @param datatype
  @@ -109,62 +111,68 @@
       }
   
       public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws
SAXException {
  -
           JXPathContext ctx = null;
           Iterator iter = null;
           if (model == null) {
               Object flowData = FlowHelper.getContextObject(ContextHelper.getObjectModel(this.context));
  -        
               if (flowData == null) {
                   throw new SAXException("No flow data to produce selection list");
               }
  +
               // Move to the list location
               ctx = JXPathContext.newContext(flowData);
  -        
  +
               // Iterate on all elements of the list
               iter = ctx.iteratePointers(this.listPath);
  -        }
  -        else {
  +        } else {
               // Move to the list location
               ctx = JXPathContext.newContext(model);
  -        
  +
               // Iterate on all elements of the list
               iter = ctx.iteratePointers(".");
           }
  -        
  +
           // Start the selection-list
           contentHandler.startElement(Constants.WI_NS, SELECTION_LIST_EL, Constants.WI_PREFIX_COLON
+ SELECTION_LIST_EL, Constants.EMPTY_ATTRS);
  -        
  -        while(iter.hasNext()) {
   
  +        while(iter.hasNext()) {
               String stringValue = "";
  -            String stringLabel = null;
  +            Object label = null;
  +
               // Get a context on the current item
               Pointer ptr = (Pointer)iter.next();
               if (ptr.getValue() != null) {
                   JXPathContext itemCtx = ctx.getRelativeContext(ptr);
  -                
  +
                   // Get the value as a string
                   Object value = itemCtx.getValue(this.valuePath);
                   stringValue = this.datatype.convertToString(value, locale);
  -                
  +
                   // Get the label (can be ommitted)
                   itemCtx.setLenient(true);
  -                Object label = itemCtx.getValue(this.labelPath);
  -                stringLabel = (label == null) ? stringValue : label.toString();
  +                label = itemCtx.getValue(this.labelPath);
  +                if (label == null) {
  +                    label = stringValue;
  +                }
               }
  +
               // Output this item
               AttributesImpl itemAttrs = new AttributesImpl();
               itemAttrs.addCDATAAttribute("value", stringValue);
               contentHandler.startElement(Constants.WI_NS, ITEM_EL, Constants.WI_PREFIX_COLON
+ ITEM_EL, itemAttrs);
  -            if (stringLabel != null) {
  +            if (label != null) {
                   contentHandler.startElement(Constants.WI_NS, LABEL_EL, Constants.WI_PREFIX_COLON
+ LABEL_EL, Constants.EMPTY_ATTRS);
  -                contentHandler.characters(stringLabel.toCharArray(), 0, stringLabel.length());
  +                if (label instanceof XMLizable) {
  +                    ((XMLizable)label).toSAX(contentHandler);
  +                } else {
  +                    String stringLabel = label.toString();
  +                    contentHandler.characters(stringLabel.toCharArray(), 0, stringLabel.length());
  +                }
                   contentHandler.endElement(Constants.WI_NS, LABEL_EL, Constants.WI_PREFIX_COLON
+ LABEL_EL);
               }
               contentHandler.endElement(Constants.WI_NS, ITEM_EL, Constants.WI_PREFIX_COLON
+ ITEM_EL);
           }
  -        
  +
           // End the selection-list
           contentHandler.endElement(Constants.WI_NS, SELECTION_LIST_EL, Constants.WI_PREFIX_COLON
+ SELECTION_LIST_EL);
       }
  
  
  
  1.5       +6 -6      cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/flow/javascript/ScriptableWidget.java
  
  Index: ScriptableWidget.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/flow/javascript/ScriptableWidget.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ScriptableWidget.java	30 Dec 2003 19:22:37 -0000	1.4
  +++ ScriptableWidget.java	29 Jan 2004 03:18:05 -0000	1.5
  @@ -100,7 +100,7 @@
               if (id.equals("length")) {
                   return true;
               }
  -	} else if (delegate instanceof MultiValueField) {
  +        } else if (delegate instanceof MultiValueField) {
               if (id.equals("length")) {
                   return true;
               }
  @@ -109,7 +109,7 @@
               if (sub != null) {
                   return true;
               }
  -        } 
  +        }
           return super.has(id, start);
       }
   
  @@ -226,7 +226,7 @@
                   value = unwrap(value);
                   if (value instanceof Double) {
                       // make woody accept a JS Number
  -                    Class typeClass = 
  +                    Class typeClass =
                           field.getFieldDefinition().getDatatype().getTypeClass();
                       if (typeClass == long.class || typeClass == Long.class) {
                           value = new Long(((Number)value).longValue());
  @@ -236,8 +236,8 @@
                           value = new Float(((Number)value).floatValue());
                       } else if (typeClass == short.class || typeClass == Short.class) {
                           value = new Short(((Number)value).shortValue());
  -                    } 
  -                } 
  +                    }
  +                }
                   field.setValue(value);
                   return;
               } else if (sub instanceof BooleanField) {
  @@ -313,7 +313,7 @@
           }
           return Undefined.instance;
       }
  -    
  +
       public boolean jsFunction_equals(Object other) {
           if (other instanceof ScriptableWidget) {
               ScriptableWidget otherWidget = (ScriptableWidget)other;
  
  
  
  1.4       +8 -4      cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/util/I18nMessage.java
  
  Index: I18nMessage.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/util/I18nMessage.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- I18nMessage.java	31 Dec 2003 10:27:18 -0000	1.3
  +++ I18nMessage.java	29 Jan 2004 03:18:05 -0000	1.4
  @@ -64,7 +64,7 @@
    *
    * <p>This generates an autonomous SAX-blurb, i.e. all necessary namespace
    * declarations will be made, and no start/endDocument events will be generated.
  - * 
  + *
    * @version CVS $Id$
    */
   public class I18nMessage implements XMLizable {
  @@ -138,15 +138,19 @@
   
       public void toSAX(ContentHandler contentHandler) throws SAXException {
           contentHandler.startPrefixMapping("i18n", I18nTransformer.I18N_NAMESPACE_URI);
  -        AttributesImpl i18nAttrs = new AttributesImpl();
           if (parameters != null) {
               contentHandler.startElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TRANSLATE_ELEMENT,
"i18n:" + I18nTransformer.I18N_TRANSLATE_ELEMENT, Constants.EMPTY_ATTRS);
           }
  -        if (catalogue != null)
  +
  +        AttributesImpl i18nAttrs = new AttributesImpl();
  +        if (catalogue != null) {
               i18nAttrs.addCDATAAttribute(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_CATALOGUE_ATTRIBUTE,
"i18n:" + I18nTransformer.I18N_CATALOGUE_ATTRIBUTE, catalogue);
  +        }
  +
           contentHandler.startElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TEXT_ELEMENT,
"i18n:" + I18nTransformer.I18N_TEXT_ELEMENT, i18nAttrs);
           contentHandler.characters(key.toCharArray(), 0, key.length());
           contentHandler.endElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TEXT_ELEMENT,
"i18n:" + I18nTransformer.I18N_TEXT_ELEMENT);
  +
           // the parameters
           if (parameters != null) {
               for (int i = 0; i < parameters.length; i++) {
  
  
  

Mime
View raw message