svn commit: r577932 - in /ofbiz/trunk: applications/content/src/org/ofbiz/content/data/ framework/widget/src/org/ofbiz/widget/ framework/widget/src/org/ofbiz/widget/html/

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

svn commit: r577932 - in /ofbiz/trunk: applications/content/src/org/ofbiz/content/data/ framework/widget/src/org/ofbiz/widget/ framework/widget/src/org/ofbiz/widget/html/

byersa-3
Author: byersa
Date: Thu Sep 20 14:30:44 2007
New Revision: 577932

URL: http://svn.apache.org/viewvc?rev=577932&view=rev
Log:
The content widget was not using the dataResourceId attribute. To make it work I had to
copy someone's brilliant WidgetContentWorker pattern.

Added:
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/DataResourceWorkerInterface.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/WidgetDataResourceWorker.java
Modified:
    ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlScreenRenderer.java

Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java?rev=577932&r1=577931&r2=577932&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java (original)
+++ ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java Thu Sep 20 14:30:44 2007
@@ -68,7 +68,7 @@
 /**
  * DataResourceWorker Class
  */
-public class DataResourceWorker {
+public class DataResourceWorker  implements org.ofbiz.widget.DataResourceWorkerInterface {
 
     public static final String module = DataResourceWorker.class.getName();
     public static final String err_resource = "ContentErrorUiLabel";
@@ -1134,5 +1134,15 @@
         streamDataResource(baos, delegator, dataResourceId, https, webSiteId, locale, rootDir);
         ByteWrapper byteWrapper = new ByteWrapper(baos.toByteArray());
         return byteWrapper;
+    }
+    
+    public String renderDataResourceAsTextExt(GenericDelegator delegator, String dataResourceId, Map templateContext,
+            Locale locale, String targetMimeTypeId, boolean cache) throws GeneralException, IOException {
+        return renderDataResourceAsText(delegator, dataResourceId, templateContext, locale, targetMimeTypeId, cache);
+    }
+    
+    public void renderDataResourceAsTextExt(GenericDelegator delegator, String dataResourceId, Writer out, Map templateContext,
+            Locale locale, String targetMimeTypeId, boolean cache) throws GeneralException, IOException {
+        renderDataResourceAsText(delegator, dataResourceId, out, templateContext, locale, targetMimeTypeId, cache);
     }
 }

Added: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/DataResourceWorkerInterface.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/DataResourceWorkerInterface.java?rev=577932&view=auto
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/DataResourceWorkerInterface.java (added)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/DataResourceWorkerInterface.java Thu Sep 20 14:30:44 2007
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ *******************************************************************************/
+package org.ofbiz.widget;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import org.ofbiz.base.util.GeneralException;
+import org.ofbiz.entity.GenericDelegator;
+import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.service.LocalDispatcher;
+
+/**
+ * ContentWorkerInterface
+ */
+public interface DataResourceWorkerInterface {
+    public String renderDataResourceAsTextExt(GenericDelegator delegator, String dataResourceId, Map templateContext,
+            Locale locale, String targetMimeTypeId, boolean cache) throws GeneralException, IOException;
+    
+    public void renderDataResourceAsTextExt(GenericDelegator delegator, String dataResourceId, Writer out, Map templateContext,
+            Locale locale, String targetMimeTypeId, boolean cache) throws GeneralException, IOException;
+}

Added: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/WidgetDataResourceWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/WidgetDataResourceWorker.java?rev=577932&view=auto
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/WidgetDataResourceWorker.java (added)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/WidgetDataResourceWorker.java Thu Sep 20 14:30:44 2007
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ *******************************************************************************/
+package org.ofbiz.widget;
+
+import org.ofbiz.base.util.Debug;
+
+/**
+ * WidgetContentWorker Class
+ */
+public class WidgetDataResourceWorker {
+    public static final String module = WidgetDataResourceWorker.class.getName();
+    public static DataResourceWorkerInterface dataresourceWorker = null;
+    static {
+        try {
+            ClassLoader loader = Thread.currentThread().getContextClassLoader();
+            // note: loadClass is necessary for these since this class doesn't know anything about them at compile time
+            dataresourceWorker = (DataResourceWorkerInterface) loader.loadClass("org.ofbiz.content.data.DataResourceWorker").newInstance();
+        } catch (ClassNotFoundException e) {
+            Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module);
+        } catch (IllegalAccessException e) {
+            Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module);
+        } catch (InstantiationException e) {
+            Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module);
+        }
+    }
+}

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlScreenRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlScreenRenderer.java?rev=577932&r1=577931&r2=577932&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlScreenRenderer.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlScreenRenderer.java Thu Sep 20 14:30:44 2007
@@ -38,6 +38,7 @@
 import org.ofbiz.webapp.control.RequestHandler;
 import org.ofbiz.webapp.taglib.ContentUrlTag;
 import org.ofbiz.widget.WidgetContentWorker;
+import org.ofbiz.widget.WidgetDataResourceWorker;
 import org.ofbiz.widget.screen.ModelScreenWidget;
 import org.ofbiz.widget.screen.ScreenStringRenderer;
 import org.ofbiz.service.LocalDispatcher;
@@ -287,6 +288,7 @@
         //Boolean nullThruDatesOnly = new Boolean(false);
         String mimeTypeId = "text/html";
         String expandedContentId = content.getContentId(context);
+        String expandedDataResourceId = content.getDataResourceId(context);
         String renderedContent = null;
         LocalDispatcher dispatcher = (LocalDispatcher) context.get("dispatcher");
         GenericDelegator delegator = (GenericDelegator) context.get("delegator");
@@ -294,11 +296,23 @@
         // make a new map for content rendering; so our current map does not get clobbered
         Map contentContext = FastMap.newInstance();
         contentContext.putAll(context);
-
+        String dataResourceId = (String)contentContext.get("dataResourceId");
         if (Debug.verboseOn()) Debug.logVerbose("expandedContentId:" + expandedContentId, module);
         
         try {
-            if (UtilValidate.isNotEmpty(expandedContentId)) {
+            if (UtilValidate.isNotEmpty(expandedDataResourceId)) {
+               if (WidgetDataResourceWorker.dataresourceWorker != null) {
+                   renderedContent = WidgetDataResourceWorker.dataresourceWorker.renderDataResourceAsTextExt(delegator, expandedDataResourceId, contentContext, locale, mimeTypeId, false);
+               } else {
+                   Debug.logError("Not rendering content, not WidgetDataResourceWorker.dataresourceWorker found.", module);
+               }
+            } else if (UtilValidate.isNotEmpty(dataResourceId)) {
+                if (WidgetDataResourceWorker.dataresourceWorker != null) {
+                    renderedContent = WidgetDataResourceWorker.dataresourceWorker.renderDataResourceAsTextExt(delegator, dataResourceId, contentContext, locale, mimeTypeId, false);
+                } else {
+                    Debug.logError("Not rendering content, not WidgetDataResourceWorker.dataresourceWorker found.", module);
+                }
+            } else if (UtilValidate.isNotEmpty(expandedContentId)) {
                 if (WidgetContentWorker.contentWorker != null) {
                     renderedContent = WidgetContentWorker.contentWorker.renderContentAsTextExt(dispatcher, delegator, expandedContentId, contentContext, locale, mimeTypeId, true);
                 } else {