The content widget was not using the dataResourceId attribute. To make it work I had to

copy someone's brilliant WidgetContentWorker pattern.


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@577932 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Alfred Maxwell Byers
2007-09-20 21:30:44 +00:00
parent f0dd2096d5
commit e0d985e8cc
4 changed files with 111 additions and 3 deletions
@@ -68,7 +68,7 @@ import javolution.util.FastMap;
/**
* 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";
@@ -1135,4 +1135,14 @@ public class DataResourceWorker {
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);
}
}
@@ -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;
}
@@ -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);
}
}
}
@@ -38,6 +38,7 @@ import org.ofbiz.entity.GenericValue;
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 @@ public class HtmlScreenRenderer implements ScreenStringRenderer {
//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 @@ public class HtmlScreenRenderer implements ScreenStringRenderer {
// 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 {