svn commit: r995206 - in /ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen: ModelScreenWidget.java ScreenFactory.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r995206 - in /ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen: ModelScreenWidget.java ScreenFactory.java

doogie-3
Author: doogie
Date: Wed Sep  8 19:03:42 2010
New Revision: 995206

URL: http://svn.apache.org/viewvc?rev=995206&view=rev
Log:
Move duplicated code that has one screen widget calling another screen,
into a global helper method.  Eventually, this method will be altered to
be able to 'change' which screen is actually included, based on various
conditions at runtime.  This will be used to eventually support partial
ajax page updates.

Modified:
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFactory.java

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java?rev=995206&r1=995205&r2=995206&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java Wed Sep  8 19:03:42 2010
@@ -507,37 +507,7 @@ public abstract class ModelScreenWidget
                 return;
             }
 
-            // check to see if the name is a composite name separated by a #, if so split it up and get it by the full loc#name
-            if (ScreenFactory.isCombinedName(name)) {
-                String combinedName = name;
-                location = ScreenFactory.getResourceNameFromCombined(combinedName);
-                name = ScreenFactory.getScreenNameFromCombined(combinedName);
-            }
-
-            ModelScreen modelScreen = null;
-            if (UtilValidate.isNotEmpty(location)) {
-                try {
-                    modelScreen = ScreenFactory.getScreenFromLocation(location, name);
-                } catch (IOException e) {
-                    String errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString();
-                    Debug.logError(e, errMsg, module);
-                    throw new RuntimeException(errMsg);
-                } catch (SAXException e) {
-                    String errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString();
-                    Debug.logError(e, errMsg, module);
-                    throw new RuntimeException(errMsg);
-                } catch (ParserConfigurationException e) {
-                    String errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString();
-                    Debug.logError(e, errMsg, module);
-                    throw new RuntimeException(errMsg);
-                }
-            } else {
-                modelScreen = this.modelScreen.modelScreenMap.get(name);
-                if (modelScreen == null) {
-                    throw new IllegalArgumentException("Could not find screen with name [" + name + "] in the same file as the screen with name [" + this.modelScreen.getName() + "]");
-                }
-            }
-            modelScreen.renderScreenString(writer, context, screenStringRenderer);
+            ScreenFactory.renderReferencedScreen(name, location, this, writer, context, screenStringRenderer);
 
             if (protectScope) {
                 UtilGenerics.<MapStack<String>>cast(context).pop();
@@ -604,37 +574,7 @@ public abstract class ModelScreenWidget
             String name = this.getName(context);
             String location = this.getLocation(context);
 
-            // check to see if the name is a composite name separated by a #, if so split it up and get it by the full loc#name
-            if (ScreenFactory.isCombinedName(name)) {
-                String combinedName = name;
-                location = ScreenFactory.getResourceNameFromCombined(combinedName);
-                name = ScreenFactory.getScreenNameFromCombined(combinedName);
-            }
-
-            ModelScreen modelScreen = null;
-            if (UtilValidate.isNotEmpty(location)) {
-                try {
-                    modelScreen = ScreenFactory.getScreenFromLocation(location, name);
-                } catch (IOException e) {
-                    String errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString();
-                    Debug.logError(e, errMsg, module);
-                    throw new RuntimeException(errMsg);
-                } catch (SAXException e) {
-                    String errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString();
-                    Debug.logError(e, errMsg, module);
-                    throw new RuntimeException(errMsg);
-                } catch (ParserConfigurationException e) {
-                    String errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString();
-                    Debug.logError(e, errMsg, module);
-                    throw new RuntimeException(errMsg);
-                }
-            } else {
-                modelScreen = this.modelScreen.modelScreenMap.get(name);
-                if (modelScreen == null) {
-                    throw new IllegalArgumentException("Could not find screen with name [" + name + "] in the same file as the screen with name [" + this.modelScreen.getName() + "]");
-                }
-            }
-            modelScreen.renderScreenString(writer, context, screenStringRenderer);
+            ScreenFactory.renderReferencedScreen(name, location, this, writer, context, screenStringRenderer);
 
             contextMs.pop();
         }

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFactory.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFactory.java?rev=995206&r1=995205&r2=995206&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFactory.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFactory.java Wed Sep  8 19:03:42 2010
@@ -31,7 +31,9 @@ import javolution.util.FastMap;
 
 import org.ofbiz.base.location.FlexibleLocation;
 import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.GeneralException;
 import org.ofbiz.base.util.UtilHttp;
+import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.base.util.UtilXml;
 import org.ofbiz.base.util.cache.UtilCache;
 import org.w3c.dom.Document;
@@ -178,4 +180,39 @@ public class ScreenFactory {
         }
         return modelScreenMap;
     }
+
+    public static void renderReferencedScreen(String name, String location, ModelScreenWidget parentWidget, Appendable writer, Map<String, Object> context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException {
+        // check to see if the name is a composite name separated by a #, if so split it up and get it by the full loc#name
+        if (ScreenFactory.isCombinedName(name)) {
+            String combinedName = name;
+            location = ScreenFactory.getResourceNameFromCombined(combinedName);
+            name = ScreenFactory.getScreenNameFromCombined(combinedName);
+        }
+
+        ModelScreen modelScreen = null;
+        if (UtilValidate.isNotEmpty(location)) {
+            try {
+                modelScreen = ScreenFactory.getScreenFromLocation(location, name);
+            } catch (IOException e) {
+                String errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString();
+                Debug.logError(e, errMsg, module);
+                throw new RuntimeException(errMsg);
+            } catch (SAXException e) {
+                String errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString();
+                Debug.logError(e, errMsg, module);
+                throw new RuntimeException(errMsg);
+            } catch (ParserConfigurationException e) {
+                String errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString();
+                Debug.logError(e, errMsg, module);
+                throw new RuntimeException(errMsg);
+            }
+        } else {
+            modelScreen = parentWidget.getModelScreen().modelScreenMap.get(name);
+            if (modelScreen == null) {
+                throw new IllegalArgumentException("Could not find screen with name [" + name + "] in the same file as the screen with name [" + parentWidget.getModelScreen().getName() + "]");
+            }
+        }
+        //Debug.logInfo("parent(" + parentWidget + ") rendering(" + modelScreen + ")", module);
+        modelScreen.renderScreenString(writer, context, screenStringRenderer);
+    }
 }