Author: jonesde
Date: Fri Jan 19 12:07:36 2007 New Revision: 497934 URL: http://svn.apache.org/viewvc?view=rev&rev=497934 Log: Some fixes for the RenderContentAsText tag, also some cleanups; the related/similar ones need similar changes, in general this code is still pretty messy though Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/webapp/ftl/RenderContentAsText.java Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/webapp/ftl/RenderContentAsText.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/webapp/ftl/RenderContentAsText.java?view=diff&rev=497934&r1=497933&r2=497934 ============================================================================== --- ofbiz/trunk/applications/content/src/org/ofbiz/content/webapp/ftl/RenderContentAsText.java (original) +++ ofbiz/trunk/applications/content/src/org/ofbiz/content/webapp/ftl/RenderContentAsText.java Fri Jan 19 12:07:36 2007 @@ -33,6 +33,8 @@ import org.ofbiz.base.util.GeneralException; import org.ofbiz.base.util.UtilDateTime; import org.ofbiz.base.util.UtilFormatOut; +import org.ofbiz.base.util.UtilHttp; +import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.template.FreeMarkerWorker; @@ -43,7 +45,7 @@ import freemarker.core.Environment; import freemarker.template.TemplateTransformModel; -//import com.clarkware.profiler.Profiler; + /** * RenderContentAsText - Freemarker Transform for Content rendering * This transform cannot be called recursively (at this time). @@ -55,7 +57,6 @@ public static final String [] saveKeyNames = {"contentId", "subContentId", "subDataResourceTypeId", "mimeTypeId", "whenMap", "locale", "wrapTemplateId", "encloseWrapText", "nullThruDatesOnly", "globalNodeTrail"}; public Writer getWriter(final Writer out, Map args) { - final StringBuffer buf = new StringBuffer(); final Environment env = Environment.getCurrentEnvironment(); //final Map templateCtx = (Map) FreeMarkerWorker.getWrappedObject("context", env); //final Map templateCtx = new HashMap(); @@ -63,18 +64,18 @@ final HttpServletRequest request = (HttpServletRequest) FreeMarkerWorker.getWrappedObject("request", env); final HttpServletResponse response = (HttpServletResponse) FreeMarkerWorker.getWrappedObject("response", env); final Map templateRoot = FreeMarkerWorker.createEnvironmentMap(env); - if (Debug.infoOn()) Debug.logInfo("in RenderSubContent, contentId(0):" + templateRoot.get( "contentId"), module); + if (Debug.infoOn()) Debug.logInfo("in RenderSubContent, contentId(0):" + templateRoot.get("contentId"), module); FreeMarkerWorker.getSiteParameters(request, templateRoot); final Map savedValuesUp = new HashMap(); FreeMarkerWorker.saveContextValues(templateRoot, upSaveKeyNames, savedValuesUp); FreeMarkerWorker.overrideWithArgs(templateRoot, args); - if (Debug.infoOn()) Debug.logInfo("in RenderSubContent, contentId(2):" + templateRoot.get( "contentId"), module); - final GenericValue userLogin = (GenericValue) FreeMarkerWorker.getWrappedObject("userLogin", env); - List trail = (List)templateRoot.get( "globalNodeTrail"); + if (Debug.infoOn()) Debug.logInfo("in RenderSubContent, contentId(2):" + templateRoot.get("contentId"), module); + // not used yet: final GenericValue userLogin = (GenericValue) FreeMarkerWorker.getWrappedObject("userLogin", env); + // not used yet: List trail = (List)templateRoot.get("globalNodeTrail"); //if (Debug.infoOn()) Debug.logInfo("in Render(0), globalNodeTrail ." + trail , module); - String contentAssocPredicateId = (String)templateRoot.get( "contentAssocPredicateId"); - String strNullThruDatesOnly = (String)templateRoot.get( "nullThruDatesOnly"); - Boolean nullThruDatesOnly = (strNullThruDatesOnly != null && strNullThruDatesOnly.equalsIgnoreCase("true")) ? Boolean.TRUE :Boolean.FALSE; + // not used yet: String contentAssocPredicateId = (String)templateRoot.get("contentAssocPredicateId"); + // not used yet: String strNullThruDatesOnly = (String)templateRoot.get("nullThruDatesOnly"); + // not used yet: Boolean nullThruDatesOnly = (strNullThruDatesOnly != null && strNullThruDatesOnly.equalsIgnoreCase("true")) ? Boolean.TRUE :Boolean.FALSE; final String thisContentId = (String)templateRoot.get("contentId"); final String xmlEscape = (String)templateRoot.get("xmlEscape"); final boolean directAssocMode = UtilValidate.isNotEmpty(thisContentId) ? true : false; @@ -101,7 +102,7 @@ subContentIdSub = (String) view.get("contentId"); } // This order is taken so that the dataResourceType can be overridden in the transform arguments. - String subDataResourceTypeId = (String)templateRoot.get( "subDataResourceTypeId"); + String subDataResourceTypeId = (String)templateRoot.get("subDataResourceTypeId"); if (UtilValidate.isEmpty(subDataResourceTypeId)) { try { subDataResourceTypeId = (String) view.get("drDataResourceTypeId"); @@ -113,11 +114,11 @@ // being passed. } String mimeTypeId = FreeMarkerWorker.getMimeTypeId(delegator, view, templateRoot); - templateRoot.put( "drDataResourceId", dataResourceId); - templateRoot.put( "mimeTypeId", mimeTypeId); - templateRoot.put( "dataResourceId", dataResourceId); - templateRoot.put( "subContentId", subContentIdSub); - templateRoot.put( "subDataResourceTypeId", subDataResourceTypeId); + templateRoot.put("drDataResourceId", dataResourceId); + templateRoot.put("mimeTypeId", mimeTypeId); + templateRoot.put("dataResourceId", dataResourceId); + templateRoot.put("subContentId", subContentIdSub); + templateRoot.put("subDataResourceTypeId", subDataResourceTypeId); */ final Map savedValues = new HashMap(); @@ -132,7 +133,7 @@ } public void close() throws IOException { - List globalNodeTrail = (List)templateRoot.get( "globalNodeTrail"); + List globalNodeTrail = (List)templateRoot.get("globalNodeTrail"); if (Debug.infoOn()) Debug.logInfo("Render close, globalNodeTrail(2a):" + ContentWorker.nodeTrailToCsv(globalNodeTrail), ""); try { renderSubContent(); @@ -143,11 +144,19 @@ } public void renderSubContent() throws IOException { + String mimeTypeId = (String) templateRoot.get("mimeTypeId"); + Object localeObject = templateRoot.get("locale"); + Locale locale = null; + if (localeObject == null) { + locale = UtilHttp.getLocale(request); + } else { + locale = UtilMisc.ensureLocale(localeObject); + } //TemplateHashModel dataRoot = env.getDataModel(); - Timestamp fromDate = UtilDateTime.nowTimestamp(); - List passedGlobalNodeTrail = (List)templateRoot.get( "globalNodeTrail"); - String editRequestName = (String)templateRoot.get( "editRequestName"); + // Timestamp fromDate = UtilDateTime.nowTimestamp(); + // List passedGlobalNodeTrail = (List)templateRoot.get("globalNodeTrail"); + String editRequestName = (String)templateRoot.get("editRequestName"); if (Debug.infoOn()) Debug.logInfo("in Render(3), editRequestName ." + editRequestName , module); /* GenericValue thisView = null; @@ -159,24 +168,18 @@ if (map != null) thisView = (GenericValue)map.get("value"); } - if (Debug.infoOn()) Debug.logInfo("in RenderSubContent, subContentId:" + templateRoot.get( "subContentId"), module); - if (Debug.infoOn()) Debug.logInfo("in RenderSubContent, contentId:" + templateRoot.get( "contentId"), module); + if (Debug.infoOn()) Debug.logInfo("in RenderSubContent, subContentId:" + templateRoot.get("subContentId"), module); + if (Debug.infoOn()) Debug.logInfo("in RenderSubContent, contentId:" + templateRoot.get("contentId"), module); */ - - String mimeTypeId = (String) templateRoot.get( "mimeTypeId"); - Locale locale = (Locale) templateRoot.get( "locale"); - if (locale == null) - locale = Locale.getDefault(); - if (UtilValidate.isNotEmpty(editRequestName)) { String editStyle = getEditStyle(); openEditWrap(out, editStyle); } - if (Debug.infoOn()) Debug.logInfo("in RenderSubContent, contentId(2):" + templateRoot.get( "contentId"), module); - if (Debug.infoOn()) Debug.logInfo("in RenderSubContent, subContentId(2):" + templateRoot.get( "subContentId"), module); + if (Debug.infoOn()) Debug.logInfo("in RenderSubContent, contentId(2):" + templateRoot.get("contentId"), module); + if (Debug.infoOn()) Debug.logInfo("in RenderSubContent, subContentId(2):" + templateRoot.get("subContentId"), module); FreeMarkerWorker.saveContextValues(templateRoot, saveKeyNames, savedValues); //if (thisView != null) { try { @@ -202,15 +205,13 @@ } public void openEditWrap(Writer out, String editStyle) throws IOException { - String divStr = "<div class=\"" + editStyle + "\">"; out.write(divStr); } public void closeEditWrap(Writer out, String editRequestName) throws IOException { - - if (Debug.infoOn()) Debug.logInfo("in RenderSubContent, contentId(3):" + templateRoot.get( "contentId"), module); - if (Debug.infoOn()) Debug.logInfo("in RenderSubContent, subContentId(3):" + templateRoot.get( "subContentId"), module); + if (Debug.infoOn()) Debug.logInfo("in RenderSubContent, contentId(3):" + templateRoot.get("contentId"), module); + if (Debug.infoOn()) Debug.logInfo("in RenderSubContent, subContentId(3):" + templateRoot.get("subContentId"), module); StringBuffer sb = new StringBuffer(); String fullRequest = editRequestName; String contentId = null; @@ -230,7 +231,6 @@ } public String getEditStyle() { - String editStyle = (String)templateRoot.get("editStyle"); if (UtilValidate.isEmpty(editStyle)) { editStyle = UtilProperties.getPropertyValue("content", "defaultEditStyle"); @@ -241,7 +241,5 @@ return editStyle; } }; - } - } |
Free forum by Nabble | Edit this page |