Author: dolander
Date: Thu Jan 27 11:38:18 2005
New Revision: 128334

URL: http://svn.apache.org/viewcvs?view=rev&rev=128334
Log:
Remove the addScriptCode() and placeScriptCode() methods from the 
IScriptReporter interface (and implementations)
These are replaced by addScriptFunction() which now takes an enum 
(ScriptPlacement) to place the script.


Added:
   
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptPlacement.java
Modified:
   
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/PopupSupport.java
   
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/internal/ReturnActionViewRenderer.java
   
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/IScriptReporter.java
   
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptBlock.java
   
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptContainer.java
   
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptRequestState.java
   
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/javaScript.properties

Modified: 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/PopupSupport.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/PopupSupport.java?view=diff&rev=128334&p1=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/PopupSupport.java&r1=128333&p2=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/PopupSupport.java&r2=128334
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/PopupSupport.java
    (original)
+++ 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/PopupSupport.java
    Thu Jan 27 11:38:18 2005
@@ -179,7 +179,7 @@
         assert (_onPopupDone != null);   // addParams() should ensure that 
this isn't null
         String func = ScriptRequestState.getString("popupSupportOnPopupDone", 
new Object[]{_onPopupDone});
         if (scriptReporter != null) {
-            scriptReporter.addScriptFunction(func);
+            scriptReporter.addScriptFunction(null, func);
         }
         else {
             ScriptRequestState.writeScriptBlock(req, results, func);

Modified: 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/internal/ReturnActionViewRenderer.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/internal/ReturnActionViewRenderer.java?view=diff&rev=128334&p1=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/internal/ReturnActionViewRenderer.java&r1=128333&p2=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/internal/ReturnActionViewRenderer.java&r2=128334
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/internal/ReturnActionViewRenderer.java
    (original)
+++ 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/internal/ReturnActionViewRenderer.java
    Thu Jan 27 11:38:18 2005
@@ -22,6 +22,8 @@
 import org.apache.beehive.netui.pageflow.internal.ViewRenderer;
 import org.apache.beehive.netui.tags.javascript.ScriptRequestState;
 import org.apache.beehive.netui.tags.rendering.ResponseRenderAppender;
+import org.apache.beehive.netui.tags.rendering.ScriptTag;
+import org.apache.beehive.netui.tags.rendering.TagRenderingBase;
 import org.apache.beehive.netui.tags.javascript.ScriptRequestState;
 import org.apache.beehive.netui.util.logging.Logger;
 
@@ -91,11 +93,15 @@
         _callbackFunc = request.getParameter(CALLBACK_PARAM);
     }
 
+    // $todo: JavaScript?
     public void renderView( ServletRequest request, ServletResponse response, 
ServletContext servletContext )
             throws IOException
     {
         ResponseRenderAppender appender = new ResponseRenderAppender(response);
-        ScriptRequestState.writeScriptStart(appender);
+        ScriptTag.State state = new ScriptTag.State();
+        TagRenderingBase br = 
TagRenderingBase.Factory.getRendering(TagRenderingBase.SCRIPT_TAG, request);
+        br.doStartTag(appender,state);
+
         appender.append(ScriptRequestState.getString("popupReturn_begin", 
null));
         assert request instanceof HttpServletRequest : 
request.getClass().getName();
         HttpServletRequest httpRequest = (HttpServletRequest) request;
@@ -121,6 +127,6 @@
         }
         
         appender.append(ScriptRequestState.getString("popupReturn_end", new 
Object[]{ _callbackFunc} ));
-        ScriptRequestState.writeScriptEnd(appender);
+        br.doEndTag(appender);
     }
 }

Modified: 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/IScriptReporter.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/IScriptReporter.java?view=diff&rev=128334&p1=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/IScriptReporter.java&r1=128333&p2=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/IScriptReporter.java&r2=128334
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/IScriptReporter.java
   (original)
+++ 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/IScriptReporter.java
   Thu Jan 27 11:38:18 2005
@@ -29,25 +29,11 @@
 public interface IScriptReporter
 {
     /**
-     * This method will add Script as top level code that runs when
-     * the page is loaded.
-     * @param script the text of the script.  This value must not be null.
-     */
-    void addScriptCode(String script);
-
-    /**
-     * This method is similar to the addScriptCode call except you may specify 
that the
-     * code be put either before or after the Framework generated code within 
the ScriptContainer.
-     * @param script the text of the script.  This value must not be null.
-     * @param after boolean indicating to place the script either before or 
after the framework generated JavaScript.
-     */
-    void placeScriptCode(String script, boolean after);
-
-    /**
      * This method will add Script as a function.
+     * @param placement
      * @param script the text of the function. This value must not be null.
      */
-    void addScriptFunction(String script);
+    void addScriptFunction(ScriptPlacement placement, String script);
 
     /**
      * This method will add a new method to the initialization code.
@@ -64,6 +50,12 @@
      */
     void addLegacyTagIdMappings(String tagId, String tagName);
 
+    /**
+     *
+     * @param tagId
+     * @param realId
+     * @param realName
+     */
     void addTagIdMappings(String tagId, String realId, String realName);
 
 

Modified: 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptBlock.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptBlock.java?view=diff&rev=128334&p1=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptBlock.java&r1=128333&p2=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptBlock.java&r2=128334
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptBlock.java
       (original)
+++ 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptBlock.java
       Thu Jan 27 11:38:18 2005
@@ -34,10 +34,7 @@
  */
 public class ScriptBlock extends AbstractSimpleTag
 {
-    public enum Placement { INLINE, BEFORE, AFTER }
-
-    private Placement _placement = Placement.INLINE;
-
+    private ScriptPlacement _placement = ScriptPlacement.PLACE_INLINE;
 
     /**
      * Return the name of the Tag.
@@ -59,11 +56,11 @@
     public void setPlacement(String placement)
     {
         if (placement.equals("after"))
-            _placement = Placement.AFTER;
+            _placement = ScriptPlacement.PLACE_AFTER;
         else if (placement.equals("before"))
-            _placement = Placement.BEFORE;
+            _placement = ScriptPlacement.PLACE_BEFORE;
         else
-            _placement = Placement.INLINE;
+            _placement = ScriptPlacement.PLACE_INLINE;
     }
 
     /**
@@ -86,12 +83,11 @@
         IScriptReporter sr = getScriptReporter();
 
         // if we are writting the javaScript inline then do it....
-       if (_placement == Placement.INLINE || sr == null) {
+       if (_placement == ScriptPlacement.PLACE_INLINE|| sr == null) {
             
ScriptRequestState.writeScriptBlock(pageContext.getRequest(),writer,script);
             return;
         }
 
-         boolean after =  (_placement == Placement.AFTER);
-        sr.placeScriptCode(script,after);
+         sr.addScriptFunction(_placement,script);
     }
 }

Modified: 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptContainer.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptContainer.java?view=diff&rev=128334&p1=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptContainer.java&r1=128333&p2=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptContainer.java&r2=128334
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptContainer.java
   (original)
+++ 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptContainer.java
   Thu Jan 27 11:38:18 2005
@@ -18,10 +18,11 @@
 package org.apache.beehive.netui.tags.javascript;
 
 import org.apache.beehive.netui.tags.AbstractClassicTag;
-import org.apache.beehive.netui.tags.RequestUtils;
 import org.apache.beehive.netui.tags.TagConfig;
 import org.apache.beehive.netui.tags.rendering.AbstractRenderAppender;
 import org.apache.beehive.netui.tags.rendering.WriteRenderAppender;
+import org.apache.beehive.netui.tags.rendering.ScriptTag;
+import org.apache.beehive.netui.tags.rendering.TagRenderingBase;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.jsp.JspException;
@@ -69,7 +70,6 @@
 {
     private String _idScope = null;
     private ArrayList<String> _funcBlocks;
-    //private ArrayList<String> _codeBlocks;
     private ArrayList<String> _codeBefore;
     private ArrayList<String> _codeAfter;
     private HashMap<String,String> _initNames;
@@ -93,55 +93,33 @@
 
     /**
      * This method will add Script as a function.
+     * @param placement
      * @param script the text of the function. This value must not be null.
      */
-    public void addScriptFunction(String script)
+    public void addScriptFunction(ScriptPlacement placement, String script)
     {
         assert (script != null) : "The paramter 'script' must not be null";
 
         // get the list of function blocks and add this script to it.
-        if (_funcBlocks == null) {
-            _funcBlocks = new ArrayList<String>();
+        if (placement == null || placement == 
ScriptPlacement.PLACE_INFRAMEWORK) {
+            if (_funcBlocks == null) {
+                _funcBlocks = new ArrayList<String>();
+            }
+            assert (_funcBlocks != null) : "_funcBlocks should not be null";
+            _funcBlocks.add(script);
         }
-        assert (_funcBlocks != null) : "_funcBlocks should not be null";
-        _funcBlocks.add(script);
-    }
-
-    /**
-     * This method will add Script as top level code that runs when
-     * the page is loaded.
-     * @param script the text of the script
-     */
-    public void addScriptCode(String script)
-    {
-        /*
-        assert (script != null) : "The parameter 'script' must not be null";
-        if (_codeBlocks == null) {
-            _codeBlocks = new ArrayList<String>();
+        else if (placement == ScriptPlacement.PLACE_BEFORE) {
+            if (_codeBefore == null)
+                _codeBefore = new ArrayList<String>();
+            _codeBefore.add(script);
         }
-        assert (_codeBlocks != null) : "_cldeBlocks should not be null";
-        _codeBlocks.add(script);
-        */
-    }
-
-    /**
-     * This method is similar to the addScriptCode call except you may specify 
that the
-     * code be put either before or after the Framework generated code within 
the ScriptContainer.
-     * @param script the text of the script.  This value must not be null.
-     * @param after boolean indicating to place the script either before or 
after the framework generated JavaScript.
-     */
-    public void placeScriptCode(String script, boolean after)
-    {
-        assert (script != null) : "The parameter 'script' must not be null";
-        if (after) {
+        else if (placement == ScriptPlacement.PLACE_AFTER) {
             if (_codeAfter == null)
                 _codeAfter = new ArrayList<String>();
             _codeAfter.add(script);
         }
         else {
-            if (_codeBefore == null)
-                _codeBefore = new ArrayList<String>();
-            _codeBefore.add(script);
+            assert(false) : "unsupported placement:" + placement;
         }
     }
 
@@ -220,7 +198,7 @@
         if (isRunAtClient()) {
             addInitCode();
         }
-        writeScriptBlock(sb);
+        writeFrameworkScript(sb);
         writeAfterBlocks(sb);
         _writeScript = true;
     }
@@ -356,7 +334,7 @@
             writer.append("</div>");
         }
 
-        writeScriptBlock(writer);
+        writeFrameworkScript(writer);
         writeAfterBlocks(writer);
         localRelease();
         return EVAL_PAGE;
@@ -407,7 +385,7 @@
 
         String script = ScriptRequestState.getString("createNetUI", new 
Object[]{req.getContextPath(),
                                                                               
initSb.toString()});
-        addScriptFunction(script);
+        addScriptFunction(null, script);
     }
 
     /**
@@ -458,7 +436,7 @@
     /**
      * This will write the script block.
      */
-    protected void writeScriptBlock(AbstractRenderAppender sb)
+    protected void writeFrameworkScript(AbstractRenderAppender sb)
     {
         boolean script = false;
         ScriptRequestState jsu = 
ScriptRequestState.getScriptRequestState((HttpServletRequest) 
pageContext.getRequest());
@@ -491,28 +469,15 @@
         if (writeLegacy || _writeId || writeName)
             jsu.writeNetuiNameFunctions(this, writeLegacy, _writeId, 
writeName);
 
-        /*
-        // @todo: delete this
-        if (_codeBlocks != null && _codeBlocks.size() > 0) {
-            if (!script) {
-                ScriptRequestState.writeScriptStart(sb);
-                script = true;
-            }
-            String s = ScriptRequestState.getString("codeComment", null);
-            sb.append(s);
-            int cnt = _codeBlocks.size();
-            for (int i = 0; i < cnt; i++) {
-                sb.append(_codeBlocks.get(i));
-                if (i != cnt - 1) {
-                    sb.append("\n");
-                }
-            }
-        }
-        */
-
+        ScriptTag.State state = null;
+        TagRenderingBase br = null;
         if (_funcBlocks != null && _funcBlocks.size() > 0) {
             if (!script) {
-                ScriptRequestState.writeScriptStart(sb);
+                state = new ScriptTag.State();
+                //@todo: test compat
+                sb.append("\n\n");
+                br = 
TagRenderingBase.Factory.getRendering(TagRenderingBase.SCRIPT_TAG, 
pageContext.getRequest());
+                br.doStartTag(sb,state);
                 script = true;
             }
             String s = ScriptRequestState.getString("functionComment", null);
@@ -526,8 +491,12 @@
             }
         }
 
-        if (script)
-            ScriptRequestState.writeScriptEnd(sb);
+        if (script) {
+            assert(br!=null);
+            br.doEndTag(sb);
+            //@todo: test compat
+            sb.append("\n\n");
+        }
     }
 
     /////////////////////////////////// Private Support 
////////////////////////////////////
@@ -593,8 +562,6 @@
 
         if (_funcBlocks != null)
             _funcBlocks.clear();
-        //if (_codeBlocks != null)
-        //    _codeBlocks.clear();
         if (_codeBefore != null)
             _codeBefore.clear();
         if (_codeAfter != null)

Added: 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptPlacement.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptPlacement.java?view=auto&rev=128334
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptPlacement.java
   Thu Jan 27 11:38:18 2005
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.tags.javascript;
+
+/**
+ *
+ */
+public enum ScriptPlacement 
+{
+    PLACE_BEFORE,
+    PLACE_AFTER,
+    PLACE_INLINE,
+    PLACE_INFRAMEWORK;
+}

Modified: 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptRequestState.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptRequestState.java?view=diff&rev=128334&p1=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptRequestState.java&r1=128333&p2=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptRequestState.java&r2=128334
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptRequestState.java
        (original)
+++ 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptRequestState.java
        Thu Jan 27 11:38:18 2005
@@ -110,7 +110,7 @@
             return;
         }
         
-        scriptReporter.addScriptFunction(s);
+        scriptReporter.addScriptFunction(null, s);
     }
 
     /**
@@ -171,7 +171,7 @@
     {
         String s = getString(mapObj, new Object[]{entries});
         if (scriptRepoter != null) {
-            scriptRepoter.addScriptFunction(s);
+            scriptRepoter.addScriptFunction(null, s);
             return null;
         }
         return s;
@@ -225,32 +225,16 @@
         ScriptTag.State state = new ScriptTag.State();
         TagRenderingBase br = 
TagRenderingBase.Factory.getRendering(TagRenderingBase.SCRIPT_TAG, req);
 
+        //@todo: test compat
         results.append("\n\n");
         br.doStartTag(results,state);
         results.append(script);
         br.doEndTag(results);
+        //@todo: test compat
         results.append("\n\n");
     }
 
     /**
-     * @param results
-     */
-    public static void writeScriptStart(AbstractRenderAppender results)
-    {
-        results.append("\n\n<script language=\"JavaScript\" 
type=\"text/JavaScript\">\n");
-        results.append("<!--\n");
-    }
-
-    /**
-     * @param results
-     */
-    public static void writeScriptEnd(AbstractRenderAppender results)
-    {
-        results.append("-->\n");
-        results.append("</script>\n\n");
-    }
-
-    /**
      * Returns the string specified by aKey from the errors.properties bundle.
      * @param aKey The key for the message pattern in the bundle.
      * @param args The args to use in the message format.
@@ -287,7 +271,7 @@
             case ROLLOVER:
                 return "rollover";
         }
-        assert(false) : "getFeature Fell through on feature:" + feature;
+        assert(false) : "getFeature fell through on feature:" + feature;
         return null;
     }
 
@@ -324,7 +308,6 @@
        else {
            String s = getString("idMappingEntry", new Object[]{tagId, value});
            writeScriptBlock(_req, results, s);
-
        }
    }
 
@@ -371,7 +354,7 @@
 
         String s = getString(bundleString, null);
         if (scriptReporter != null)
-            scriptReporter.addScriptFunction(s);
+            scriptReporter.addScriptFunction(null, s);
         else {
             sb.append(s);
             sb.append("\n");

Modified: 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/javaScript.properties
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/javaScript.properties?view=diff&rev=128334&p1=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/javaScript.properties&r1=128333&p2=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/javaScript.properties&r2=128334
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/javaScript.properties
  (original)
+++ 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/javaScript.properties
  Thu Jan 27 11:38:18 2005
@@ -3,12 +3,6 @@
 # the JavaScriptUtils class needs updating because it caches the Bundle 
internally
 # so it is only looked up once.
 
-# This is a header comment for the code that will run when the page is loaded
-codeComment=\
-// **** This section contains code that will run when the page is loaded 
****\n\
-\n\
-\n
-
 functionComment=\
 \n// **** Start the NetUI Framework Generated JavaScript ****\n\
 \n

Reply via email to