sylvain     2003/08/17 14:03:42

  Modified:    src/blocks/woody/java/org/apache/cocoon/woody/transformation
                        WidgetReplacingPipe.java
               src/blocks/woody/samples/xsl/html woody-default.xsl
  Log:
  Prevent the production of <wi:styling> if it's already present in a <wt:widget>.
  This allows to pass styling information as attributes of <wi:style>
  
  Revision  Changes    Path
  1.9       +17 -3     
cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/transformation/WidgetReplacingPipe.java
  
  Index: WidgetReplacingPipe.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/transformation/WidgetReplacingPipe.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- WidgetReplacingPipe.java  16 Aug 2003 20:41:04 -0000      1.8
  +++ WidgetReplacingPipe.java  17 Aug 2003 21:03:42 -0000      1.9
  @@ -108,6 +108,9 @@
   
       protected WoodyTemplateTransformer.InsertStylingContentHandler stylingHandler = 
new WoodyTemplateTransformer.InsertStylingContentHandler();
       protected WoodyTemplateTransformer pipeContext;
  +    
  +    /** Have we encountered a <wi:style> element in a widget ? */
  +    protected boolean gotStylingElement = false;
   
       public void init(Widget contextWidget, WoodyTemplateTransformer pipeContext) {
           this.contextWidget = contextWidget;
  @@ -124,6 +127,7 @@
               checkContextWidgetAvailable(qName);
               inWidgetElement = true;
               widgetElementNesting = elementNestingCounter;
  +            gotStylingElement = false;
               xmlCompiler.recycle();
   
               // retrieve widget here, but its XML will only be streamed in the 
endElement call
  @@ -132,6 +136,10 @@
               if (repeaterWidget && !(widget instanceof Repeater))
                   throw new SAXException("WoodyTemplateTransformer: the element 
\"repeater-widget\" can only be used for repeater widgets.");
           } else if (inWidgetElement) {
  +            if (elementNestingCounter == widgetElementNesting + 1 &&
  +                Constants.WI_NS.equals(namespaceURI) && 
STYLING_EL.equals(localName)) {
  +                gotStylingElement = true;
  +            }
               xmlCompiler.startElement(namespaceURI, localName, qName, attributes);
           } else if (namespaceURI.equals(Constants.WT_NS)) {
               if (localName.equals("widget-label")) {
  @@ -487,9 +495,15 @@
               if (elementNesting == 0 && saxFragment != null) {
                   interpreter.setContentHandler(contentHandler);
                   interpreter.setLexicalHandler(lexicalHandler);
  -                contentHandler.startElement(Constants.WI_NS, STYLING_EL, 
Constants.WI_PREFIX_COLON + STYLING_EL, Constants.EMPTY_ATTRS);
  -                interpreter.deserialize(saxFragment);
  -                contentHandler.endElement(Constants.WI_NS, STYLING_EL, 
Constants.WI_PREFIX_COLON + STYLING_EL);
  +                if (gotStylingElement) {
  +                    // Just deserialize
  +                    interpreter.deserialize(saxFragment);
  +                } else {
  +                    // Insert an enclosing <wi:styling>
  +                    contentHandler.startElement(Constants.WI_NS, STYLING_EL, 
Constants.WI_PREFIX_COLON + STYLING_EL, Constants.EMPTY_ATTRS);
  +                    interpreter.deserialize(saxFragment);
  +                    contentHandler.endElement(Constants.WI_NS, STYLING_EL, 
Constants.WI_PREFIX_COLON + STYLING_EL);
  +                } 
               }
               super.endElement(uri, loc, raw);
           }
  
  
  
  1.9       +3 -1      cocoon-2.1/src/blocks/woody/samples/xsl/html/woody-default.xsl
  
  Index: woody-default.xsl
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/samples/xsl/html/woody-default.xsl,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- woody-default.xsl 16 Aug 2003 20:41:04 -0000      1.8
  +++ woody-default.xsl 17 Aug 2003 21:03:42 -0000      1.9
  @@ -31,7 +31,9 @@
   
     <xsl:template name="field">
       <xsl:param name="fieldelement"/>
  -    <input name="{$fieldelement/@id}" value="{$fieldelement/wi:value}"/>
  +    <input name="{$fieldelement/@id}" value="{$fieldelement/wi:value}">
  +      <xsl:copy-of select="wi:styling/@*"/>
  +    </input>
     </xsl:template>
   
     <xsl:template name="field-with-selection-list">
  
  
  

Reply via email to