commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: jakarta-commons/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml TransformTag.java
Date Wed, 27 Oct 2004 21:51:13 GMT
dion        2004/10/27 14:51:13

  Modified:    jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml
                        TransformTag.java
  Log:
  Use WeakReferenceWrapperScript for Jelly-148
  
  Revision  Changes    Path
  1.6       +58 -4     jakarta-commons/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/TransformTag.java
  
  Index: TransformTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/TransformTag.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TransformTag.java	9 Sep 2004 12:24:40 -0000	1.5
  +++ TransformTag.java	27 Oct 2004 21:51:13 -0000	1.6
  @@ -38,6 +38,7 @@
   import javax.xml.transform.sax.TransformerHandler;
   import javax.xml.transform.stream.StreamSource;
   
  +import org.apache.commons.jelly.JellyContext;
   import org.apache.commons.jelly.JellyException;
   import org.apache.commons.jelly.JellyTagException;
   import org.apache.commons.jelly.MissingAttributeException;
  @@ -47,6 +48,7 @@
   import org.apache.commons.jelly.impl.ScriptBlock;
   import org.apache.commons.jelly.impl.StaticTagScript;
   import org.apache.commons.jelly.impl.TagScript;
  +import org.apache.commons.jelly.impl.WeakReferenceWrapperScript;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.dom4j.Document;
  @@ -357,7 +359,11 @@
       private void doNestedParamTag(XMLOutput output) throws JellyTagException {
           // find any nested param tags and run them
           Script bodyScript = this.getBody();
  -        if (bodyScript instanceof ScriptBlock) {
  +        
  +        if (bodyScript instanceof WeakReferenceWrapperScript) {
  +            WeakReferenceWrapperScript wrws = (WeakReferenceWrapperScript) bodyScript;
  +            invokeNestedTagsOfType(wrws, ParamTag.class,context,output);
  +        }else if (bodyScript instanceof ScriptBlock) {
               ScriptBlock scriptBlock = (ScriptBlock) bodyScript;
               List scriptList = scriptBlock.getScriptList();
               for (Iterator iter = scriptList.iterator(); iter.hasNext(); ) {
  @@ -381,6 +387,47 @@
           }
       }
   
  +    /** Locates all child TagScripts, whose tags are of the type
  +     * given. These tags are executed with the provided JellyContext and output.
  +     * <p/>
  +     * <strong>This method is in place
  +     * to support specific features in the XML tag library and
  +     * shouldn't be used by anyone at all.
  +     * This method will be removed in a near-future verison of jelly.</strong>
  +     * <p/>
  +     * 
  +     * XXX if possible, this is actually more bogus than "containsScriptType", it must
be removed ASAP
  +     * 
  +     * @param clazz Execute all child tags of this type
  +     * @param output The output to use when executing the tags.
  +     * @throws JellyTagException
  +     */
  +    public void invokeNestedTagsOfType(WeakReferenceWrapperScript wrws, Class clazz, JellyContext
context, XMLOutput output) throws JellyTagException {
  +        Object bodyScript = wrws.script();
  +        
  +        if (bodyScript instanceof ScriptBlock) {
  +            ScriptBlock scriptBlock = (ScriptBlock) bodyScript;
  +            List scriptList = scriptBlock.getScriptList();
  +            for (Iterator iter = scriptList.iterator(); iter.hasNext(); ) {
  +                Script script = (Script) iter.next();
  +                if (script instanceof TagScript) {
  +    
  +                    Tag tag = null;
  +                    try {
  +                        tag = ((TagScript) script).getTag();
  +                    } catch (JellyException e) {
  +                        throw new JellyTagException(e);
  +                    }
  +    
  +                    if (tag instanceof ParamTag) {
  +                        script.run(context, output);
  +                    }
  +                } // instanceof
  +            } // for
  +        } // if
  +    }
  +
  +    
       /** A helper class that converts a transform tag body to an XMLReader
         * to hide the details of where the input for the transform is obtained
         *
  @@ -487,11 +534,18 @@
            * xml parser, i.e. its only text) to generate SAX events or not
            *
            * @return True if tag body should be parsed or false if invoked only
  +         * @throws JellyTagException
            */
  -        private boolean shouldParseBody() {
  +        private boolean shouldParseBody() throws JellyTagException {
               boolean result = false;
               // check to see if we need to parse the body or just invoke it
               Script bodyScript = this.tag.getBody();
  +            
  +            if (bodyScript instanceof WeakReferenceWrapperScript) {
  +                WeakReferenceWrapperScript wrws = (WeakReferenceWrapperScript) bodyScript;
  +                return wrws.containsScriptType(StaticTagScript.class);
  +            }
  +            
               if (bodyScript instanceof ScriptBlock) {
                   ScriptBlock scriptBlock = (ScriptBlock) bodyScript;
                   List scriptList = scriptBlock.getScriptList();
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message