svn commit: r513985 [1/3] - in /ofbiz/trunk: applications/content/ applications/content/config/ applications/content/data/ applications/content/entitydef/ applications/content/script/org/ofbiz/content/data/ applications/content/servicedef/ applications...

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

svn commit: r513985 [1/3] - in /ofbiz/trunk: applications/content/ applications/content/config/ applications/content/data/ applications/content/entitydef/ applications/content/script/org/ofbiz/content/data/ applications/content/servicedef/ applications...

jaz-3
Author: jaz
Date: Fri Mar  2 14:03:48 2007
New Revision: 513985

URL: http://svn.apache.org/viewvc?view=rev&rev=513985
Log:
Big content rendering refactor; condensed methods used for rendering content into one, flagged to cache or not. This will make maintaining this much easier. Implemented new streaming event which will send all type of files not just images (deprecating the img event); added mime-type templates to remove the hard coded templates in DataResourceWorker; now supports additional types besides image/*; updated all code using the old methods; however left them in place (deprecated) until we are sure no BSH files use these old methods

Added:
    ofbiz/trunk/applications/content/data/MimeTypeTemplate.xml   (with props)
    ofbiz/trunk/applications/content/template/mime-type/
    ofbiz/trunk/applications/content/template/mime-type/flash-flv.ftl   (with props)
    ofbiz/trunk/applications/content/template/mime-type/flash-swf.ftl   (with props)
    ofbiz/trunk/applications/content/template/mime-type/image.ftl   (with props)
    ofbiz/trunk/applications/content/template/mime-type/quicktime.ftl   (with props)
Modified:
    ofbiz/trunk/applications/content/config/ContentUiLabels.properties
    ofbiz/trunk/applications/content/config/content.properties
    ofbiz/trunk/applications/content/entitydef/entitygroup.xml
    ofbiz/trunk/applications/content/entitydef/entitymodel.xml
    ofbiz/trunk/applications/content/ofbiz-component.xml
    ofbiz/trunk/applications/content/script/org/ofbiz/content/data/DataServices.xml
    ofbiz/trunk/applications/content/servicedef/services_contenttypes.xml
    ofbiz/trunk/applications/content/src/org/ofbiz/content/blog/BlogRssServices.java
    ofbiz/trunk/applications/content/src/org/ofbiz/content/cms/CmsEvents.java
    ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentServices.java
    ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java
    ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataEvents.java
    ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java
    ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataServices.java
    ofbiz/trunk/applications/content/src/org/ofbiz/content/search/ContentDocument.java
    ofbiz/trunk/applications/content/src/org/ofbiz/content/search/DataResourceDocument.java
    ofbiz/trunk/applications/content/src/org/ofbiz/content/webapp/ftl/EditRenderSubContentCacheTransform.java
    ofbiz/trunk/applications/content/src/org/ofbiz/content/webapp/ftl/EditRenderSubContentTransform.java
    ofbiz/trunk/applications/content/src/org/ofbiz/content/webapp/ftl/LoopSubContentTransform.java
    ofbiz/trunk/applications/content/src/org/ofbiz/content/webapp/ftl/RenderContentAsText.java
    ofbiz/trunk/applications/content/src/org/ofbiz/content/webapp/ftl/RenderSubContentAsText.java
    ofbiz/trunk/applications/content/src/org/ofbiz/content/webapp/ftl/RenderSubContentCacheTransform.java
    ofbiz/trunk/applications/content/src/org/ofbiz/content/webapp/ftl/RenderSubContentTransform.java
    ofbiz/trunk/applications/content/src/org/ofbiz/content/webapp/ftl/TraverseSubContentTransform.java
    ofbiz/trunk/applications/content/src/org/ofbiz/content/webapp/ftl/WrapSubContentCacheTransform.java
    ofbiz/trunk/applications/content/webapp/content/WEB-INF/actions/website/WebSitePublishPoint.bsh
    ofbiz/trunk/applications/content/webapp/content/WEB-INF/controller.xml
    ofbiz/trunk/applications/content/webapp/content/datasetup/DataResourceSetupMenus.xml
    ofbiz/trunk/applications/content/webapp/content/datasetup/DataSetupForms.xml
    ofbiz/trunk/applications/content/webapp/content/website/WebSiteCMSContent.ftl
    ofbiz/trunk/applications/content/widget/datasetup/DataResourceSetupScreens.xml
    ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderContentWrapper.java
    ofbiz/trunk/applications/party/src/org/ofbiz/party/content/PartyContentWrapper.java
    ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryContentWrapper.java
    ofbiz/trunk/applications/product/src/org/ofbiz/product/config/ProductConfigItemContentWrapper.java
    ofbiz/trunk/applications/product/src/org/ofbiz/product/product/KeywordIndex.java
    ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductContentWrapper.java
    ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/dhl/DhlServices.java
    ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/content/WorkEffortContentWrapper.java
    ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortKeywordIndex.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ContentWorkerInterface.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlScreenRenderer.java

Modified: ofbiz/trunk/applications/content/config/ContentUiLabels.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/config/ContentUiLabels.properties?view=diff&rev=513985&r1=513984&r2=513985
==============================================================================
--- ofbiz/trunk/applications/content/config/ContentUiLabels.properties (original)
+++ ofbiz/trunk/applications/content/config/ContentUiLabels.properties Fri Mar  2 14:03:48 2007
@@ -42,6 +42,7 @@
 ContentMetadata=Metadata
 ContentMetaDataPred=MetaData Predicate
 ContentMimeType=Mime Type
+ContentMimeTypeHtmlTemplate=Mime Type Template
 ContentContent=Content
 ContentContentManagerApplication=Content Manager Application
 ContentSubContent=SubContent

Modified: ofbiz/trunk/applications/content/config/content.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/config/content.properties?view=diff&rev=513985&r1=513984&r2=513985
==============================================================================
--- ofbiz/trunk/applications/content/config/content.properties (original)
+++ ofbiz/trunk/applications/content/config/content.properties Fri Mar  2 14:03:48 2007
@@ -19,6 +19,9 @@
 owner.content.id=CONTENT_ROOT
 img.request=/content/control/img/
 img.request.param.name=imgId
+
+stream.permission.service=genericContentPermission
+
 #baseUrl=http://localhost:8080
 disable.ftl.template.cache=true
 permissionRecorderOn=true

Added: ofbiz/trunk/applications/content/data/MimeTypeTemplate.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/data/MimeTypeTemplate.xml?view=auto&rev=513985
==============================================================================
--- ofbiz/trunk/applications/content/data/MimeTypeTemplate.xml (added)
+++ ofbiz/trunk/applications/content/data/MimeTypeTemplate.xml Fri Mar  2 14:03:48 2007
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+  -->
+
+<entity-engine-xml>
+    <!-- application templates -->
+    <MimeTypeHtmlTemplate mimeTypeId="application/x-shockwave-flash" templateLocation="component://content/template/mime-type/flash-swf.ftl"/>
+
+    <!-- image template -->
+    <MimeTypeHtmlTemplate mimeTypeId="image/jpeg" templateLocation="component://content/template/mime-type/image.ftl"/>
+    <MimeTypeHtmlTemplate mimeTypeId="image/pjpeg" templateLocation="component://content/template/mime-type/image.ftl"/>
+    <MimeTypeHtmlTemplate mimeTypeId="image/gif" templateLocation="component://content/template/mime-type/image.ftl"/>
+    <MimeTypeHtmlTemplate mimeTypeId="image/tiff" templateLocation="component://content/template/mime-type/image.ftl"/>
+    <MimeTypeHtmlTemplate mimeTypeId="image/png" templateLocation="component://content/template/mime-type/image.ftl"/>
+
+    <!-- video templates -->
+    <MimeTypeHtmlTemplate mimeTypeId="video/quicktime" templateLocation="component://content/template/mime-type/quicktime.ftl"/>
+    <MimeTypeHtmlTemplate mimeTypeId="video/x-flv" templateLocation="component://content/template/mime-type/flash-flv.ftl"/>    
+</entity-engine-xml>

Propchange: ofbiz/trunk/applications/content/data/MimeTypeTemplate.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/applications/content/data/MimeTypeTemplate.xml
------------------------------------------------------------------------------
    svn:keywords = "Date Rev Author URL Id"

Propchange: ofbiz/trunk/applications/content/data/MimeTypeTemplate.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: ofbiz/trunk/applications/content/entitydef/entitygroup.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/entitydef/entitygroup.xml?view=diff&rev=513985&r1=513984&r2=513985
==============================================================================
--- ofbiz/trunk/applications/content/entitydef/entitygroup.xml (original)
+++ ofbiz/trunk/applications/content/entitydef/entitygroup.xml Fri Mar  2 14:03:48 2007
@@ -88,6 +88,7 @@
     <entity-group group="org.ofbiz" entity="ImageDataResource" />
     <entity-group group="org.ofbiz" entity="MetaDataPredicate" />
     <entity-group group="org.ofbiz" entity="MimeType" />
+    <entity-group group="org.ofbiz" entity="MimeTypeHtmlTemplate" />
     <entity-group group="org.ofbiz" entity="OtherDataResource" />
     <entity-group group="org.ofbiz" entity="VideoDataResource" />
 

Modified: ofbiz/trunk/applications/content/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/entitydef/entitymodel.xml?view=diff&rev=513985&r1=513984&r2=513985
==============================================================================
--- ofbiz/trunk/applications/content/entitydef/entitymodel.xml (original)
+++ ofbiz/trunk/applications/content/entitydef/entitymodel.xml Fri Mar  2 14:03:48 2007
@@ -830,6 +830,7 @@
       <field name="dataResourceName" type="name"></field>
       <field name="localeString" type="very-short"></field>
       <field name="mimeTypeId" type="id-long"></field>
+      <field name="mimeTypeTemplateId" type="id"></field>
       <field name="characterSetId" type="id-long"></field>
       <field name="objectInfo" type="long-varchar"></field>
       <field name="relatedDetailId" type="id"><description>Depending on the dataResourceTypeId this can point to other entities, like: Survey, SurveyResponse, etc.</description></field>
@@ -842,6 +843,9 @@
       <relation type="one" fk-name="DTRSRC_STATUS" rel-entity-name="StatusItem">
         <key-map field-name="statusId"/>
       </relation>
+      <relation type="one" fk-name="DATA_REC_TO_MIMTPL" title="MimeTmpl" rel-entity-name="DataResource">
+        <key-map field-name="mimeTypeTemplateId" rel-field-name="dataResourceId"/>
+      </relation>
       <relation type="one" fk-name="DATA_REC_TO_TYPE" rel-entity-name="DataResourceType">
         <key-map field-name="dataResourceTypeId"/>
       </relation>
@@ -1077,6 +1081,17 @@
       <field name="mimeTypeId" type="id-long-ne"></field>
       <field name="description" type="description"></field>
       <prim-key field="mimeTypeId"/>
+    </entity>
+    <entity entity-name="MimeTypeHtmlTemplate"
+            package-name="org.ofbiz.content.data"
+            default-resource-name="ContentEntityLabels"
+            title="Mime Text Template Entity">
+      <field name="mimeTypeId" type="id-long-ne"></field>
+      <field name="templateLocation" type="long-varchar"></field>
+      <prim-key field="mimeTypeId"/>
+      <relation type="one" fk-name="MIMETYPE_TPL_MT" rel-entity-name="MimeType">
+          <key-map field-name="mimeTypeId"/>
+      </relation>      
     </entity>
     <entity entity-name="OtherDataResource"
             package-name="org.ofbiz.content.data"

Modified: ofbiz/trunk/applications/content/ofbiz-component.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/ofbiz-component.xml?view=diff&rev=513985&r1=513984&r2=513985
==============================================================================
--- ofbiz/trunk/applications/content/ofbiz-component.xml (original)
+++ ofbiz/trunk/applications/content/ofbiz-component.xml Fri Mar  2 14:03:48 2007
@@ -32,6 +32,7 @@
     <entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml"/>
     <entity-resource type="data" reader-name="seed" loader="main" location="data/ContentTypeData.xml"/>
     <entity-resource type="data" reader-name="seed" loader="main" location="data/MimeTypeData.xml"/>
+    <entity-resource type="data" reader-name="seed" loader="main" location="data/MimeTypeTemplate.xml"/>
     <entity-resource type="data" reader-name="seed" loader="main" location="data/DataCategoryData.xml"/>
     <entity-resource type="data" reader-name="seed" loader="main" location="data/BlogData.xml"/>
     <entity-resource type="data" reader-name="demo" loader="main" location="data/BlogDemoData.xml"/>

Modified: ofbiz/trunk/applications/content/script/org/ofbiz/content/data/DataServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/script/org/ofbiz/content/data/DataServices.xml?view=diff&rev=513985&r1=513984&r2=513985
==============================================================================
--- ofbiz/trunk/applications/content/script/org/ofbiz/content/data/DataServices.xml (original)
+++ ofbiz/trunk/applications/content/script/org/ofbiz/content/data/DataServices.xml Fri Mar  2 14:03:48 2007
@@ -355,6 +355,27 @@
         <remove-value value-name="lookedUpValue"/>
     </simple-method>
 
+    <!-- Methods for MimeTypeHtmlTemplate -->
+    <simple-method method-name="createMimeTypeHtmlTemplate" short-description="Create MimeTypeHtmlTemplate">
+        <make-value entity-name="MimeTypeHtmlTemplate" value-name="newEntity"/>
+        <set-nonpk-fields map-name="parameters" value-name="newEntity"/>
+        <set-pk-fields map-name="parameters" value-name="newEntity"/>        
+        <create-value value-name="newEntity"/>
+    </simple-method>
+    <simple-method method-name="updateMimeTypeHtmlTemplate" short-description="Update MimeTypeHtmlTemplate">
+        <make-value entity-name="MimeTypeHtmlTemplate" value-name="lookupKeyValue"/>
+        <set-pk-fields map-name="parameters" value-name="lookupKeyValue"/>
+        <find-by-primary-key entity-name="MimeTypeHtmlTemplate" map-name="lookupKeyValue" value-name="lookedUpValue"/>
+        <set-nonpk-fields map-name="parameters" value-name="lookedUpValue"/>
+        <store-value value-name="lookedUpValue"/>
+    </simple-method>
+    <simple-method method-name="removeMimeTypeHtmlTemplate" short-description="Remove MimeTypeHtmlTemplate">
+        <make-value entity-name="MimeTypeHtmlTemplate" value-name="lookupKeyValue"/>
+        <set-pk-fields map-name="parameters" value-name="lookupKeyValue"/>
+        <find-by-primary-key entity-name="MimeTypeHtmlTemplate" map-name="lookupKeyValue" value-name="lookedUpValue"/>
+        <remove-value value-name="lookedUpValue"/>
+    </simple-method>
+
     <!-- Methods for ElectronicText -->
     <simple-method method-name="createElectronicText" short-description="Create Electronic Text">
         <make-value entity-name="ElectronicText" value-name="newEntity"/>
@@ -623,9 +644,31 @@
         <if-empty field-name="dataResource">
             <add-error><fail-message message="No data resource found for ID: [$parameters.dataResourceId}]"/></add-error>
         </if-empty>
-        <if-empty field-name="_uploadedFile_fileName" map-name="parameters">
-            <add-error><fail-message message="No uploaded content found in context"/></add-error>
-        </if-empty>
+        <if>
+            <condition>
+                <if-empty field-name="_uploadedFile_fileName" map-name="parameters"/>
+            </condition>
+            <then>
+                <if>
+                    <condition>
+                        <or>
+                            <if-empty field-name="isUpdate"/>
+                            <if-compare field-name="isUpdate" value="Y" operator="not-equals"/>
+                        </or>
+                    </condition>
+                    <then>
+                        <add-error><fail-message message="No uploaded content found in context"/></add-error>
+                    </then>
+                    <else>
+                        <!-- if not upload is found on an update; its okay, don't do anything just return -->
+                        <field-to-result field-name="dataResourceId" map-name="dataResource"/>
+                        <field-to-result field-name="mimeTypeId" map-name="dataResource"/>
+                        <return/>
+                    </else>
+                </if>
+
+            </then>
+        </if>
         <check-errors/>
 
         <call-class-method class-name="org.ofbiz.content.data.DataResourceWorker" method-name="getDataResourceContentUploadPath" ret-field-name="uploadPath"/>
@@ -661,9 +704,31 @@
         <if-empty field-name="dataResource">
             <add-error><fail-message message="No data resource found for ID: [$parameters.dataResourceId}]"/></add-error>
         </if-empty>
-        <if-empty field-name="_uploadedFile_fileName" map-name="parameters">
-            <add-error><fail-message message="No uploaded content found in context"/></add-error>
-        </if-empty>
+        <if>
+            <condition>
+                <if-empty field-name="_uploadedFile_fileName" map-name="parameters"/>
+            </condition>
+            <then>
+                <if>
+                    <condition>
+                        <or>
+                            <if-empty field-name="isUpdate"/>
+                            <if-compare field-name="isUpdate" value="Y" operator="not-equals"/>
+                        </or>
+                    </condition>
+                    <then>
+                        <add-error><fail-message message="No uploaded content found in context"/></add-error>
+                    </then>
+                    <else>
+                        <!-- if not upload is found on an update; its okay, don't do anything just return -->
+                        <field-to-result field-name="dataResourceId" map-name="dataResource"/>
+                        <field-to-result field-name="mimeTypeId" map-name="dataResource"/>
+                        <return/>
+                    </else>
+                </if>
+
+            </then>
+        </if>
         <check-errors/>
 
         <!-- update the data resource with file data -->
@@ -695,9 +760,31 @@
         <if-empty field-name="dataResource">
             <add-error><fail-message message="No data resource found for ID: [$parameters.dataResourceId}]"/></add-error>
         </if-empty>
-        <if-empty field-name="_uploadedFile_fileName" map-name="parameters">
-            <add-error><fail-message message="No uploaded content found in context"/></add-error>
-        </if-empty>
+        <if>
+            <condition>
+                <if-empty field-name="_uploadedFile_fileName" map-name="parameters"/>
+            </condition>
+            <then>
+                <if>
+                    <condition>
+                        <or>
+                            <if-empty field-name="isUpdate"/>
+                            <if-compare field-name="isUpdate" value="Y" operator="not-equals"/>
+                        </or>
+                    </condition>
+                    <then>
+                        <add-error><fail-message message="No uploaded content found in context"/></add-error>
+                    </then>
+                    <else>
+                        <!-- if not upload is found on an update; its okay, don't do anything just return -->
+                        <field-to-result field-name="dataResourceId" map-name="dataResource"/>
+                        <field-to-result field-name="mimeTypeId" map-name="dataResource"/>
+                        <return/>
+                    </else>
+                </if>
+
+            </then>
+        </if>
         <check-errors/>
 
         <!-- update the data resource with file data -->
@@ -729,9 +816,31 @@
         <if-empty field-name="dataResource">
             <add-error><fail-message message="No data resource found for ID: [$parameters.dataResourceId}]"/></add-error>
         </if-empty>
-        <if-empty field-name="_uploadedFile_fileName" map-name="parameters">
-            <add-error><fail-message message="No uploaded content found in context"/></add-error>
-        </if-empty>
+        <if>
+            <condition>
+                <if-empty field-name="_uploadedFile_fileName" map-name="parameters"/>
+            </condition>
+            <then>
+                <if>
+                    <condition>
+                        <or>
+                            <if-empty field-name="isUpdate"/>
+                            <if-compare field-name="isUpdate" value="Y" operator="not-equals"/>
+                        </or>
+                    </condition>
+                    <then>
+                        <add-error><fail-message message="No uploaded content found in context"/></add-error>
+                    </then>
+                    <else>
+                        <!-- if not upload is found on an update; its okay, don't do anything just return -->
+                        <field-to-result field-name="dataResourceId" map-name="dataResource"/>
+                        <field-to-result field-name="mimeTypeId" map-name="dataResource"/>
+                        <return/>
+                    </else>
+                </if>
+
+            </then>
+        </if>
         <check-errors/>
 
         <!-- update the data resource with file data -->
@@ -763,9 +872,31 @@
         <if-empty field-name="dataResource">
             <add-error><fail-message message="No data resource found for ID: [$parameters.dataResourceId}]"/></add-error>
         </if-empty>
-        <if-empty field-name="_uploadedFile_fileName" map-name="parameters">
-            <add-error><fail-message message="No uploaded content found in context"/></add-error>
-        </if-empty>
+        <if>
+            <condition>
+                <if-empty field-name="_uploadedFile_fileName" map-name="parameters"/>
+            </condition>
+            <then>
+                <if>
+                    <condition>
+                        <or>
+                            <if-empty field-name="isUpdate"/>
+                            <if-compare field-name="isUpdate" value="Y" operator="not-equals"/>
+                        </or>
+                    </condition>
+                    <then>
+                        <add-error><fail-message message="No uploaded content found in context"/></add-error>
+                    </then>
+                    <else>
+                        <!-- if not upload is found on an update; its okay, don't do anything just return -->
+                        <field-to-result field-name="dataResourceId" map-name="dataResource"/>
+                        <field-to-result field-name="mimeTypeId" map-name="dataResource"/>
+                        <return/>
+                    </else>
+                </if>
+
+            </then>
+        </if>
         <check-errors/>
 
         <!-- update the data resource with file data -->

Modified: ofbiz/trunk/applications/content/servicedef/services_contenttypes.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/servicedef/services_contenttypes.xml?view=diff&rev=513985&r1=513984&r2=513985
==============================================================================
--- ofbiz/trunk/applications/content/servicedef/services_contenttypes.xml (original)
+++ ofbiz/trunk/applications/content/servicedef/services_contenttypes.xml Fri Mar  2 14:03:48 2007
@@ -254,4 +254,24 @@
         <description>Remove MimeType</description>
         <auto-attributes include="pk" mode="IN" optional="false"/>
     </service>
+
+    <!-- MimeTypeHtmlTemplate services -->
+    <service name="createMimeTypeHtmlTemplate" engine="simple" default-entity-name="MimeTypeHtmlTemplate" auth="true"
+            location="org/ofbiz/content/data/DataServices.xml" invoke="createMimeTypeHtmlTemplate">
+        <description>Create a MimeTypeHtmlTemplate</description>
+        <auto-attributes include="pk" mode="IN" optional="false"/>
+        <auto-attributes include="nonpk" mode="IN" optional="true"/>
+        <override name="fromDate" optional="true"/>
+    </service>
+    <service name="updateMimeTypeHtmlTemplate" engine="simple" default-entity-name="MimeTypeHtmlTemplate" auth="true"
+            location="org/ofbiz/content/data/DataServices.xml" invoke="updateMimeTypeHtmlTemplate">
+        <description>Update a MimeTypeHtmlTemplate</description>
+        <auto-attributes include="pk" mode="IN" optional="false"/>
+        <auto-attributes include="nonpk" mode="IN" optional="true"/>
+    </service>
+    <service name="removeMimeTypeHtmlTemplate" engine="simple" default-entity-name="MimeTypeHtmlTemplate" auth="true"
+            location="org/ofbiz/content/data/DataServices.xml" invoke="removeMimeTypeHtmlTemplate">
+        <description>Remove MimeTypeHtmlTemplate</description>
+        <auto-attributes include="pk" mode="IN" optional="false"/>
+    </service>
 </services>

Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/blog/BlogRssServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/blog/BlogRssServices.java?view=diff&rev=513985&r1=513984&r2=513985
==============================================================================
--- ofbiz/trunk/applications/content/src/org/ofbiz/content/blog/BlogRssServices.java (original)
+++ ofbiz/trunk/applications/content/src/org/ofbiz/content/blog/BlogRssServices.java Fri Mar  2 14:03:48 2007
@@ -89,8 +89,6 @@
     }
 
     public static List generateEntryList(GenericDelegator delegator, String contentId, String entryLink, Locale locale, GenericValue userLogin) {
-        Timestamp fromDate = UtilDateTime.nowTimestamp();
-
         List entries = FastList.newInstance();
         List exprs = FastList.newInstance();
         exprs.add(new EntityExpr("contentIdStart", EntityOperator.EQUALS, contentId));
@@ -110,7 +108,7 @@
                 GenericValue v = (GenericValue) i.next();
                 String sub = null;
                 try {
-                    sub = ContentWorker.renderSubContentAsTextCache(delegator, v.getString("contentId"), mapKey, null, new HashMap(), locale, mimeTypeId, userLogin, fromDate);
+                    sub = ContentWorker.renderSubContentAsText(delegator, v.getString("contentId"), mapKey, new HashMap(), locale, mimeTypeId, true);
                 } catch (GeneralException e) {
                     Debug.logError(e, module);
                 } catch (IOException e) {

Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/cms/CmsEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/cms/CmsEvents.java?view=diff&rev=513985&r1=513984&r2=513985
==============================================================================
--- ofbiz/trunk/applications/content/src/org/ofbiz/content/cms/CmsEvents.java (original)
+++ ofbiz/trunk/applications/content/src/org/ofbiz/content/cms/CmsEvents.java Fri Mar  2 14:03:48 2007
@@ -187,10 +187,12 @@
 
                     // render
                     if (UtilValidate.isEmpty(mapKey)) {
-                        ContentWorker.renderContentAsTextCache(delegator, contentId, writer, templateMap, null, locale, "text/html");
+                        ContentWorker.renderContentAsText(delegator, contentId, writer, templateMap, locale, "text/html", true);
+                        //ContentWorker.renderContentAsTextCache(delegator, contentId, writer, templateMap, null, locale, "text/html");
                     } else {
-                        ContentWorker.renderSubContentAsTextCache(delegator, contentId, writer, mapKey, null, templateMap,
-                            locale, "text/html", userLogin, fromDate, Boolean.FALSE);
+                        ContentWorker.renderSubContentAsText(delegator, contentId, writer, mapKey, templateMap, locale, "text/html", true);
+                        //ContentWorker.renderSubContentAsTextCache(delegator, contentId, writer, mapKey, null, templateMap, locale, "text/html", userLogin, fromDate, Boolean.FALSE);
+
                     }
 
                 } catch (IOException e) {

Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentServices.java?view=diff&rev=513985&r1=513984&r2=513985
==============================================================================
--- ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentServices.java (original)
+++ ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentServices.java Fri Mar  2 14:03:48 2007
@@ -886,7 +886,7 @@
         }
 
         try {
-            results = ContentWorker.renderSubContentAsTextCache(delegator, contentId, outWriter, mapKey, subContentDataResourceView, templateContext, locale, mimeTypeId, userLogin, fromDate);
+            ContentWorker.renderSubContentAsText(delegator, contentId, outWriter, mapKey, templateContext, locale, mimeTypeId, true);
             out.write(outWriter.toString());
             results.put("textData", outWriter.toString());
         } catch (GeneralException e) {
@@ -931,8 +931,12 @@
 
         Writer outWriter = new StringWriter();
         GenericValue view = (GenericValue)context.get("subContentDataResourceView");
+        if (view != null && view.containsKey("contentId")) {
+            contentId = view.getString("contentId");
+        }
+
         try {
-            Map thisResults = ContentWorker.renderContentAsTextCache(delegator, contentId, outWriter, templateContext, view, locale, mimeTypeId);
+            ContentWorker.renderContentAsText(delegator, contentId, outWriter, templateContext, locale, mimeTypeId, true);
             out.write(outWriter.toString());
             results.put("textData", outWriter.toString());
         } catch (GeneralException e) {

Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java?view=diff&rev=513985&r1=513984&r2=513985
==============================================================================
--- ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java (original)
+++ ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java Fri Mar  2 14:03:48 2007
@@ -62,7 +62,6 @@
 import bsh.EvalError;
 import freemarker.ext.dom.NodeModel;
 import javolution.util.FastMap;
-//import com.clarkware.profiler.Profiler;
 
 /**
  * ContentWorker Class
@@ -72,56 +71,251 @@
     public static final String module = ContentWorker.class.getName();
 
     public ContentWorker() { }
-    
+
+    public GenericValue getWebSitePublishPointExt(GenericDelegator delegator, String contentId, boolean ignoreCache) throws GenericEntityException {
+        return ContentManagementWorker.getWebSitePublishPoint(delegator, contentId, ignoreCache);
+    }
+
     public GenericValue getCurrentContentExt(GenericDelegator delegator, List trail, GenericValue userLogin, Map ctx, Boolean nullThruDatesOnly, String contentAssocPredicateId) throws GeneralException {
         return getCurrentContent(delegator, trail, userLogin, ctx, nullThruDatesOnly, contentAssocPredicateId);
     }
 
-    public Map renderSubContentAsTextExt(GenericDelegator delegator, String contentId, Writer out, String mapKey, String subContentId, GenericValue subContentDataResourceView,
-            Map templateContext, Locale locale, String mimeTypeId, GenericValue userLogin, Timestamp fromDate) throws GeneralException, IOException {
-        return renderSubContentAsText(delegator, contentId, out, mapKey, subContentId, subContentDataResourceView,
-                templateContext, locale, mimeTypeId, userLogin, fromDate);
+    public String getMimeTypeIdExt(GenericDelegator delegator, GenericValue view, Map ctx) {
+        return getMimeTypeId(delegator, view, ctx);
     }
 
-    public String renderSubContentAsTextCacheExt(GenericDelegator delegator, String contentId,  String mapKey, GenericValue subContentDataResourceView,
-            Map templateRoot, Locale locale, String mimeTypeId, GenericValue userLogin, Timestamp fromDate) throws GeneralException, IOException {
-        return renderSubContentAsTextCache(delegator, contentId, mapKey, subContentDataResourceView,
-                templateRoot, locale, mimeTypeId, userLogin, fromDate);
+    // new rendering methods
+    public void renderContentAsTextExt(GenericDelegator delegator, String contentId, Writer out, Map templateContext, Locale locale, String mimeTypeId, boolean cache) throws GeneralException, IOException {
+        renderContentAsText(delegator, contentId, out, templateContext, locale, mimeTypeId, cache);
     }
 
-    public Map renderSubContentAsTextCacheExt(GenericDelegator delegator, String contentId, Writer out, String mapKey,  GenericValue subContentDataResourceView,
-            Map templateRoot, Locale locale, String mimeTypeId, GenericValue userLogin, Timestamp fromDate) throws GeneralException, IOException {
-        return renderSubContentAsTextCache(delegator, contentId, out, mapKey, subContentDataResourceView,
-                templateRoot, locale, mimeTypeId, userLogin, fromDate);
+    public void renderSubContentAsTextExt(GenericDelegator delegator, String contentId, Writer out, String mapKey, Map templateContext, Locale locale, String mimeTypeId, boolean cache) throws GeneralException, IOException {
+        renderSubContentAsText(delegator, contentId, out, mapKey, templateContext, locale, mimeTypeId, cache);
     }
 
-    public Map renderSubContentAsTextCacheExt(GenericDelegator delegator, String contentId, Writer out, String mapKey,  GenericValue subContentDataResourceView,
-            Map templateRoot, Locale locale, String mimeTypeId, GenericValue userLogin, Timestamp fromDate, Boolean nullThruDatesOnly) throws GeneralException, IOException {
-        return renderSubContentAsTextCache(delegator, contentId, out, mapKey, subContentDataResourceView,
-                templateRoot, locale, mimeTypeId, userLogin, fromDate, nullThruDatesOnly);
+    public String renderSubContentAsTextExt(GenericDelegator delegator, String contentId, String mapKey, Map templateContext, Locale locale, String mimeTypeId, boolean cache) throws GeneralException, IOException {
+        return renderSubContentAsText(delegator, contentId, mapKey, templateContext, locale, mimeTypeId, cache);
     }
 
-    public Map renderContentAsTextExt(GenericDelegator delegator, String contentId, Writer out, Map templateContext, GenericValue view, Locale locale, String mimeTypeId) throws GeneralException, IOException {
-        return renderContentAsText(delegator, contentId, out, templateContext, view, locale, mimeTypeId);
+    public String renderContentAsTextExt(GenericDelegator delegator, String contentId, Map templateContext, Locale locale, String mimeTypeId, boolean cache) throws GeneralException, IOException {
+        return renderContentAsText(delegator, contentId, templateContext, locale, mimeTypeId, cache);
     }
 
-    public String renderContentAsTextCacheExt(GenericDelegator delegator, String contentId,  Map templateContext, GenericValue view, Locale locale, String mimeTypeId) throws GeneralException, IOException {
-        return renderContentAsTextCache(delegator, contentId,  templateContext, view, locale, mimeTypeId);
+    // -------------------------------------
+    // Content rendering methods
+    // -------------------------------------
+
+    public static String renderContentAsText(GenericDelegator delegator, String contentId, Map templateContext,
+            Locale locale, String mimeTypeId, boolean cache) throws GeneralException, IOException {
+        return renderContentAsText(delegator, contentId, templateContext, locale, mimeTypeId, true, cache);
     }
 
-    public Map renderContentAsTextCacheExt(GenericDelegator delegator, String contentId, Writer out, Map templateContext, GenericValue view, Locale locale, String mimeTypeId) throws GeneralException, IOException {
-        return renderContentAsTextCache(delegator, contentId, out, templateContext, view, locale, mimeTypeId);
+    public static String renderContentAsText(GenericDelegator delegator, String contentId, Map templateContext,
+            Locale locale, String mimeTypeId, boolean useTemplate, boolean cache) throws GeneralException, IOException {
+        Writer writer = new StringWriter();
+        renderContentAsText(delegator, contentId, writer, templateContext, locale, mimeTypeId, cache);
+        return writer.toString();
     }
 
-    public String getMimeTypeIdExt(GenericDelegator delegator, GenericValue view, Map ctx) {
-        return getMimeTypeId(delegator, view, ctx);
+    public static void renderContentAsText(GenericDelegator delegator, String contentId, Writer out,
+            Map templateContext, Locale locale, String mimeTypeId, boolean cache) throws GeneralException, IOException {
+        GenericValue content;
+        if (cache) {
+            content = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", contentId));
+        } else {
+            content = delegator.findByPrimaryKey("Content", UtilMisc.toMap("contentId", contentId));
+        }
+        if (content == null) {
+            throw new GeneralException("No content found for content ID [" + contentId + "]");
+        }
+
+        // if the content is a PUBLISH_POINT and the data resource is not defined; get the related content
+        if (content.get("contentTypeId").equals("WEB_SITE_PUB_PT") && content.get("dataResourceId") == null) {
+            List relContentIds = delegator.findByAnd("ContentAssocDataResourceViewTo",
+                    UtilMisc.toMap("contentIdStart", content.get("contentId"),"statusId","CTNT_PUBLISHED",
+                    "caContentAssocTypeId", "PUBLISH_LINK"), UtilMisc.toList("caFromDate"));
+
+            relContentIds = EntityUtil.filterByDate(relContentIds, UtilDateTime.nowTimestamp(), "caFromDate", "caThruDate", true);
+            if (relContentIds != null && relContentIds.size() > 0) {
+                content = EntityUtil.getFirst(relContentIds);
+            }
+
+            if (content == null) {
+                throw new GeneralException("No related content found for publish point [" + contentId + "]");
+            }
+        }
+
+        // check for alternate content per locale
+        if (locale != null) {
+            String thisLocaleString = (String) content.get("localeString");
+            String targetLocaleString = locale.toString();
+
+            thisLocaleString = (thisLocaleString != null) ? thisLocaleString : "";
+            if (targetLocaleString != null && !targetLocaleString.equalsIgnoreCase(thisLocaleString)) {
+                GenericValue altContent = ContentWorker.findAlternateLocaleContent(delegator, content, locale);
+                if (altContent != null) {
+                    content = altContent;
+                }
+            }
+        }
+
+        // get the data resource info
+        String templateDataResourceId = content.getString("templateDataResourceId");
+        String dataResourceId = content.getString("dataResourceId");
+        contentId = content.getString("contentId");
+
+        if (templateContext == null) {
+            templateContext = FastMap.newInstance();
+        }
+        
+        // set this contentId in the template context
+        templateContext.put("contentId", contentId);
+
+        // render all sub-content; place in template context under mapKey name
+        List subContent = delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentId", contentId,
+                "contentAssocTypeId", "SUB_CONTENT"), UtilMisc.toList("-fromDate"));
+        subContent = EntityUtil.filterByDate(subContent);
+
+        if (subContent != null && subContent.size() > 0) {
+            Iterator i = subContent.iterator();
+            while (i.hasNext()) {
+                GenericValue contentAssoc = (GenericValue) i.next();
+                String contentIdTo = contentAssoc.getString("contentIdTo");
+                String key = contentAssoc.getString("mapKey");
+                String textData = ContentWorker.renderContentAsText(delegator, contentIdTo, FastMap.newInstance(), locale, mimeTypeId, cache);
+                if (UtilValidate.isNotEmpty(textData)) {
+                    templateContext.put(key, textData);
+                }
+            }
+        }
+
+        // now if no template; just render the data
+        if (UtilValidate.isEmpty(templateDataResourceId) || templateContext.containsKey("ignoreTemplate")) {
+            DataResourceWorker.renderDataResourceAsText(delegator, dataResourceId, out, templateContext, locale, mimeTypeId, cache);
+
+        // there is a template; render the data and then the template
+        } else {
+            Writer dataWriter = new StringWriter();
+            DataResourceWorker.renderDataResourceAsText(delegator, dataResourceId, dataWriter,
+                    templateContext, locale, mimeTypeId, cache);
+
+            String textData = dataWriter.toString();
+            if (textData != null) {
+                textData = textData.trim();
+            }
+
+            String mimeType;
+            try {
+                mimeType = DataResourceWorker.getDataResourceMimeType(delegator, dataResourceId, null);
+            } catch (GenericEntityException e) {
+                throw new GeneralException(e.getMessage());
+            }
+
+            // using FTL to handle XML? not really sure what this is doing...
+            if (UtilValidate.isNotEmpty(mimeType)) {
+                if (mimeType.toLowerCase().indexOf("xml") >= 0) {
+                    StringReader sr = new StringReader(textData);
+                    try {
+                        NodeModel nodeModel = NodeModel.parse(new InputSource(sr));
+                        templateContext.put("doc", nodeModel);
+                    } catch (SAXException e) {
+                        throw new GeneralException(e.getMessage());
+                    } catch (ParserConfigurationException e2) {
+                        throw new GeneralException(e2.getMessage());
+                    }
+                } else {
+                    // must be text
+                    templateContext.put("textData", textData);
+                }
+            } else {
+                templateContext.put("textData", textData);
+            }
+
+            // render the template
+            DataResourceWorker.renderDataResourceAsText(delegator, templateDataResourceId, out, templateContext, locale, mimeTypeId, cache);
+        }
     }
 
-    public GenericValue getWebSitePublishPointExt(GenericDelegator delegator, String contentId, boolean ignoreCache) throws GenericEntityException {
-        return ContentManagementWorker.getWebSitePublishPoint(delegator, contentId, ignoreCache);
+    public static String renderSubContentAsText(GenericDelegator delegator, String contentId, String mapKey, Map templateContext,
+            Locale locale, String mimeTypeId, boolean cache) throws GeneralException, IOException {
+        Writer writer = new StringWriter();
+        renderSubContentAsText(delegator, contentId, writer, mapKey, templateContext, locale, mimeTypeId, cache);
+        return writer.toString();
+    }
+
+    public static void renderSubContentAsText(GenericDelegator delegator, String contentId, Writer out, String mapKey,
+            Map templateContext, Locale locale, String mimeTypeId, boolean cache) throws GeneralException, IOException {
+
+        // find the sub-content with matching mapKey
+        List orderBy = UtilMisc.toList("-fromDate");
+        List exprs = UtilMisc.toList(new EntityExpr("contentId", EntityOperator.EQUALS, contentId),
+                //new EntityExpr("contentAssocTypeId", EntityOperator.EQUALS, "SUB_CONTENT"),
+                new EntityExpr("mapKey", EntityOperator.EQUALS, mapKey));
+
+        List assocs;
+        if (cache) {
+            assocs = delegator.findByConditionCache("ContentAssoc", new EntityConditionList(exprs, EntityOperator.AND), null, orderBy);
+        } else {
+            assocs = delegator.findByCondition("ContentAssoc", new EntityConditionList(exprs, EntityOperator.AND), null, orderBy);
+        }
+        assocs = EntityUtil.filterByDate(assocs);
+        GenericValue subContent = EntityUtil.getFirst(assocs);
+
+        if (subContent == null) {
+            throw new GeneralException("No sub-content found with map-key [" + mapKey + "] for content [" + contentId + "]");
+        }
+
+        String subContentId = subContent.getString("contentIdTo");
+        templateContext.put("mapKey", mapKey);
+        renderContentAsText(delegator, subContentId, out, templateContext, locale, mimeTypeId, cache);
+    }
+
+    /** @deprecated */
+    public static Map renderContentAsText(GenericDelegator delegator, String contentId, Writer out, Map templateContext,
+            GenericValue view, Locale locale, String mimeTypeId) throws GeneralException, IOException {
+        renderContentAsText(delegator, contentId, out, templateContext, locale, mimeTypeId, false);
+        return FastMap.newInstance();
+    }
+
+    /** @deprecated */
+    public static String renderContentAsTextCache(GenericDelegator delegator, String contentId,  Map templateContext, GenericValue view, Locale locale, String mimeTypeId) throws GeneralException, IOException {
+        return renderContentAsText(delegator, contentId, templateContext, locale, mimeTypeId, true);
+    }
+
+    /** @deprecated */
+    public static Map renderContentAsTextCache(GenericDelegator delegator, String contentId, Writer out, Map templateContext,
+            GenericValue view, Locale locale, String mimeTypeId) throws GeneralException, IOException {
+        renderContentAsText(delegator, contentId, out, templateContext, locale, mimeTypeId, true);
+        return FastMap.newInstance();
+    }
+
+    /** @deprecated */
+    public static Map renderSubContentAsText(GenericDelegator delegator, String contentId, Writer out, String mapKey, String subContentId, GenericValue subContentDataResourceView,
+            Map templateContext, Locale locale, String mimeTypeId, GenericValue userLogin, Timestamp fromDate) throws GeneralException, IOException {
+        renderSubContentAsText(delegator, contentId, out, mapKey, templateContext, locale, mimeTypeId, false);
+        return FastMap.newInstance();
+    }
+
+    /** @deprecated */
+    public static String renderSubContentAsTextCache(GenericDelegator delegator, String contentId,  String mapKey,  GenericValue subContentDataResourceView,
+            Map templateRoot, Locale locale, String mimeTypeId, GenericValue userLogin, Timestamp fromDate) throws GeneralException, IOException {
+        return renderSubContentAsText(delegator, contentId, mapKey, templateRoot, locale, mimeTypeId, true);
+    }
+
+    /** @deprecated */
+    public static Map renderSubContentAsTextCache(GenericDelegator delegator, String contentId, Writer out, String mapKey,  GenericValue subContentDataResourceView,
+            Map templateRoot, Locale locale, String mimeTypeId, GenericValue userLogin, Timestamp fromDate) throws GeneralException, IOException {
+        renderSubContentAsText(delegator, contentId, out, mapKey, templateRoot, locale, mimeTypeId, true);
+        return FastMap.newInstance();
+    }
+
+    /** @deprecated */
+    public static Map renderSubContentAsTextCache(GenericDelegator delegator, String contentId, Writer out, String mapKey, GenericValue subContentDataResourceView,
+            Map templateRoot, Locale locale, String mimeTypeId, GenericValue userLogin, Timestamp fromDate, Boolean nullThruDatesOnly) throws GeneralException, IOException {
+        renderSubContentAsText(delegator, contentId, out, mapKey, templateRoot, locale, mimeTypeId, true);
+        return FastMap.newInstance();
     }
 
-    
     public static GenericValue findAlternateLocaleContent(GenericDelegator delegator, GenericValue view, Locale locale) {
         GenericValue contentAssocDataResourceViewFrom = view;
         if (locale == null) {
@@ -1006,305 +1200,6 @@
         }
         content.set("dataResourceId", dataResourceId);
         return content;
-    }
-
-    public static Map renderSubContentAsText(GenericDelegator delegator, String contentId, Writer out, String mapKey, String subContentId, GenericValue subContentDataResourceView,
-            Map templateContext, Locale locale, String mimeTypeId, GenericValue userLogin, Timestamp fromDate) throws GeneralException, IOException {
-
-        Map results = new HashMap();
-        //GenericValue content = null;
-        if (subContentDataResourceView == null) {
-            subContentDataResourceView = getSubContentCache(delegator, contentId, mapKey, subContentId, userLogin, null, fromDate, Boolean.FALSE, null);
-        }
-
-        results.put("view", subContentDataResourceView);
-        if (subContentDataResourceView == null) {
-            //throw new IOException("SubContentDataResourceView is null.");
-            return results;
-        }
-
-        //String dataResourceId = (String) subContentDataResourceView.get("drDataResourceId");
-        contentId = (String) subContentDataResourceView.get("contentId");
-        //GenericValue dataResourceContentView = null;
-
-        if (templateContext == null) {
-            templateContext = new HashMap();
-        }
-
-        renderContentAsText(delegator, contentId, out, templateContext, subContentDataResourceView, locale, mimeTypeId);
-
-        return results;
-    }
-
-    public static String renderSubContentAsTextCache(GenericDelegator delegator, String contentId,  String mapKey,  GenericValue subContentDataResourceView,
-            Map templateRoot, Locale locale, String mimeTypeId, GenericValue userLogin, Timestamp fromDate) throws GeneralException, IOException {
-        Boolean nullThruDatesOnly = Boolean.FALSE;
-        Writer outWriter = new StringWriter();
-        Map map = renderSubContentAsTextCache(delegator, contentId, outWriter, mapKey, subContentDataResourceView, templateRoot, locale, mimeTypeId, userLogin, fromDate, nullThruDatesOnly);
-        return outWriter.toString();
-    }
-
-    public static Map renderSubContentAsTextCache(GenericDelegator delegator, String contentId, Writer out, String mapKey,  GenericValue subContentDataResourceView,
-            Map templateRoot, Locale locale, String mimeTypeId, GenericValue userLogin, Timestamp fromDate) throws GeneralException, IOException {
-        Boolean nullThruDatesOnly = Boolean.FALSE;
-        return renderSubContentAsTextCache(delegator, contentId, out, mapKey, subContentDataResourceView,
-            templateRoot, locale, mimeTypeId, userLogin, fromDate, nullThruDatesOnly);
-    }
-
-    /**
-     */
-    public static Map renderSubContentAsTextCache(GenericDelegator delegator, String contentId, Writer out, String mapKey, GenericValue subContentDataResourceView,
-            Map templateRoot, Locale locale, String mimeTypeId, GenericValue userLogin, Timestamp fromDate, Boolean nullThruDatesOnly) throws GeneralException, IOException {
-
-        //Debug.logInfo("in renderSubContentAsTextCache contentId=[" + contentId + "] mapKey=[" + mapKey + "]", module);
-
-        Map results = new HashMap();
-        //GenericValue content = null;
-        if (subContentDataResourceView == null) {
-            String contentAssocPredicateId = null;
-            try {
-                subContentDataResourceView = getSubContentCache(delegator, contentId, mapKey, userLogin, null, fromDate, nullThruDatesOnly, contentAssocPredicateId );
-            } catch(GenericEntityException e) {
-                throw new GeneralException(e.getMessage());
-            }
-        }
-        //Debug.logInfo("subContentDataResourceView=" + subContentDataResourceView, module);
-        
-        results.put("view", subContentDataResourceView);
-        if (subContentDataResourceView == null) {
-            //throw new IOException("SubContentDataResourceView is null.");
-            return results;
-        }
-
-        String contentIdSub = (String) subContentDataResourceView.get("contentId");
-
-        if (templateRoot == null) {
-            templateRoot = new HashMap();
-        }
-
-        // hold on to the mapKey
-        templateRoot.put("mapKey", mapKey);
-        
-        //templateRoot.put("contentId", contentIdSub);
-        //templateRoot.put("subContentId", null);
-
-        renderContentAsTextCache(delegator, contentIdSub, out, templateRoot, subContentDataResourceView, locale, mimeTypeId);
-
-        return results;
-    }
-
-    public static Map renderContentAsText(GenericDelegator delegator, String contentId, Writer out, Map templateContext, GenericValue view, Locale locale, String mimeTypeId) throws GeneralException, IOException {
-        //Map context = (Map) FreeMarkerWorker.get(templateContext, "context");
-        Map results = new HashMap();
-        GenericValue content = null;
-
-        if (view == null) {
-            if (contentId == null) {
-                throw new IOException("ContentId is null");
-            }
-            try {
-                List lst = delegator.findByAnd("SubContentDataResourceView", UtilMisc.toMap("contentId", contentId));
-                if (lst != null && lst.size() > 0) {
-                    view = (GenericValue) lst.get(0);
-                } else {
-                    throw new IOException("SubContentDataResourceView not found in renderSubContentAsText" + " for contentId=" + contentId);
-                }
-            } catch (GenericEntityException e) {
-                throw new IOException(e.getMessage());
-            }
-        }
-        if (view != null) {
-            Map contentMap = new HashMap();
-            try {
-                SimpleMapProcessor.runSimpleMapProcessor("org/ofbiz/content/ContentManagementMapProcessors.xml", "contentIn", view, contentMap, new ArrayList(), locale);
-            } catch (MiniLangException e) {
-                throw new IOException(e.getMessage());
-            }
-            content = delegator.makeValue("Content", contentMap);
-        }
-
-        results.put("view", view);
-        results.put("content", content);
-
-        if (locale != null) {
-            String targetLocaleString = locale.toString();
-            String thisLocaleString = (String) view.get("localeString");
-            thisLocaleString = (thisLocaleString != null) ? thisLocaleString : "";
-            if (targetLocaleString != null && !targetLocaleString.equalsIgnoreCase(thisLocaleString)) {
-                view = findAlternateLocaleContent(delegator, view, locale);
-            }
-        }
-
-        //String contentTypeId = (String) view.get("contentTypeId");
-        String dataResourceId = null;
-        try {
-            dataResourceId = (String) view.get("drDataResourceId");
-        } catch (Exception e) {
-            dataResourceId = (String) view.get("dataResourceId");
-        }
-        if (templateContext == null) {
-            templateContext = new HashMap();
-        }
-
-        // TODO: what should we REALLY do here? looks like there is no decision between Java and Service style error handling...
-        //try {
-        if (UtilValidate.isNotEmpty(dataResourceId) || view != null)
-            DataResourceWorker.renderDataResourceAsText(delegator, dataResourceId, out, templateContext, view, locale, mimeTypeId);
-        //} catch (IOException e) {
-        //    return ServiceUtil.returnError(e.getMessage());
-        //}
-
-        return results;
-    }
-
-    public static String renderContentAsTextCache(GenericDelegator delegator, String contentId,  Map templateContext, GenericValue view, Locale locale, String mimeTypeId) throws GeneralException, IOException {
-        Writer outWriter = new StringWriter();
-        renderContentAsTextCache(delegator, contentId, outWriter, templateContext, view, locale, mimeTypeId);
-        return outWriter.toString();
-    }
-
-    public static Map renderContentAsTextCache(GenericDelegator delegator, String contentId, Writer out, Map templateContext, GenericValue view, Locale locale, String mimeTypeId) throws GeneralException, IOException {
-
-        Map results = new HashMap();
-
-        GenericValue content = null;
-
-        if (view == null) {
-            if (contentId == null) {
-                throw new GeneralException("ContentId is null");
-            }
-            try {
-                List lst = delegator.findByAndCache("SubContentDataResourceView", UtilMisc.toMap("contentId", contentId), null);
-                if (lst != null && lst.size() > 0) {
-                    view = (GenericValue) lst.get(0);
-                } else {
-                    throw new GeneralException("SubContentDataResourceView not found in renderSubContentAsText" + " for contentId=" + contentId);
-                }
-            } catch (GenericEntityException e) {
-                throw new GeneralException(e.getMessage());
-            }
-        }
-        if (view != null) {
-            Map contentMap = new HashMap();
-            try {
-                SimpleMapProcessor.runSimpleMapProcessor("org/ofbiz/content/ContentManagementMapProcessors.xml", "contentIn", view, contentMap, new ArrayList(), locale);
-            } catch (MiniLangException e) {
-                throw new IOException(e.getMessage());
-            }
-            content = delegator.makeValue("Content", contentMap);
-        }
-
-        results.put("view", view);
-        results.put("content", content);
-
-        // if the contentId is a publishpoint and the resource ID is not defined get the related contentId
-        if (view.get("contentTypeId").equals("WEB_SITE_PUB_PT") && view.get("dataResourceId") == null) {
-            List relContentIds = delegator.findByAnd("ContentAssocDataResourceViewTo",
-                    UtilMisc.toMap("contentIdStart", view.get("contentId"),"statusId","CTNT_PUBLISHED", "caContentAssocTypeId", "PUBLISH_LINK"),
-                    UtilMisc.toList("caFromDate"));
-            relContentIds = EntityUtil.filterByDate(relContentIds, UtilDateTime.nowTimestamp(), "caFromDate", "caThruDate", true);
-            if (relContentIds != null && relContentIds.size() > 0) {
-                view = (GenericValue) relContentIds.get(0);
-            }
-            else {
-                throw new GeneralException("No related content found for publish point contentId=" + contentId);
-            }
-        }
-        
-        if (locale != null) {
-            String targetLocaleString = locale.toString();
-            String thisLocaleString = (String) view.get("localeString");
-            thisLocaleString = (thisLocaleString != null) ? thisLocaleString : "";
-            //if (Debug.infoOn()) Debug.logInfo("renderContentAsTextCache, thisLocaleString(2):" + thisLocaleString, "");
-            //if (Debug.infoOn()) Debug.logInfo("renderContentAsTextCache, targetLocaleString(2):" + targetLocaleString, "");
-            if (UtilValidate.isNotEmpty(targetLocaleString) && !targetLocaleString.equalsIgnoreCase(thisLocaleString)) {
-                GenericValue localeView = findAlternateLocaleContent(delegator, view, locale);
-                if (localeView != null)
-                    view = localeView;
-            }
-        }
-
-        String templateDataResourceId = (String)view.get("templateDataResourceId");
-
-        //String contentTypeId = (String) view.get("contentTypeId");
-        String dataResourceId = null;
-        try {
-            dataResourceId = (String) view.get("drDataResourceId");
-        } catch (Exception e) {
-            dataResourceId = (String) view.get("dataResourceId");
-            view = null; // renderDataResourceAsText will expect DataResource values if not null
-        }
-
-        if (templateContext == null) {
-            templateContext = FastMap.newInstance();
-        }
-
-        // render all sub-content; place in template context under mapKey name
-        List subContent = delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentId", contentId,
-                "contentAssocTypeId", "SUB_CONTENT"), UtilMisc.toList("-fromDate"));
-        subContent = EntityUtil.filterByDate(subContent);
-        
-        if (subContent != null && subContent.size() > 0) {
-            Iterator i = subContent.iterator();
-            while (i.hasNext()) {
-                GenericValue contentAssoc = (GenericValue) i.next();
-                String contentIdTo = contentAssoc.getString("contentIdTo");
-                String key = contentAssoc.getString("mapKey");
-                String textData = ContentWorker.renderContentAsTextCache(delegator, contentIdTo, FastMap.newInstance(), null, locale, mimeTypeId);
-                if (UtilValidate.isNotEmpty(textData)) {
-                    templateContext.put(key, textData);
-                }                
-            }
-        }
-
-        // TODO: what should we REALLY do here? looks like there is no decision between Java and Service style error handling...
-
-        if (UtilValidate.isEmpty(templateDataResourceId)) {
-            // Debug.logInfo("=====rendering contentId" + contentId + " dataResourceId:" + dataResourceId + " view:" + view,module);
-            if (UtilValidate.isNotEmpty(dataResourceId) || view != null)
-                DataResourceWorker.renderDataResourceAsTextCache(delegator, dataResourceId, out, templateContext, view, locale, mimeTypeId);
-
-        } else {
-            if (UtilValidate.isNotEmpty(dataResourceId) || view != null) {
-                StringWriter sw = new StringWriter();
-                DataResourceWorker.renderDataResourceAsTextCache(delegator, dataResourceId, sw, templateContext, view, locale, mimeTypeId);
-                String s = sw.toString();
-                if (UtilValidate.isNotEmpty(s))
-                    s = s.trim();
-                //if (Debug.infoOn()) Debug.logInfo("renderTextAsStringCache, s:" + s, "");
-                
-                if (Debug.infoOn()) Debug.logInfo("renderContentAsTextCache, dataResourceId(2):" + dataResourceId, "");
-                //if (Debug.infoOn()) Debug.logInfo("renderTextAsStringCache, view(3):" + view, "");
-                String reqdType = null;
-                try {
-                    reqdType = DataResourceWorker.getDataResourceMimeType(delegator, dataResourceId, view);
-                } catch(GenericEntityException e) {
-                    throw new GeneralException(e.getMessage());
-                }
-                if (Debug.infoOn()) Debug.logInfo("renderContentAsTextCache, reqdType(2):" + reqdType, "");
-                if (UtilValidate.isNotEmpty(reqdType)) {
-                    if (reqdType.toLowerCase().indexOf("xml") >= 0) {
-                        StringReader sr = new StringReader(s);
-                        try {
-                            NodeModel nodeModel = NodeModel.parse(new InputSource(sr));
-                            if (Debug.infoOn()) Debug.logInfo("renderTextAsStringCache, doc:" + nodeModel, "");
-                            templateContext.put("doc", nodeModel);
-                        } catch(SAXException e) {
-                            throw new GeneralException(e.getMessage());
-                        } catch(ParserConfigurationException e2) {
-                            throw new GeneralException(e2.getMessage());
-                        }
-                    } else {
-                        // must be text
-                        templateContext.put("textData", sw.toString());
-                    }
-                } else {
-                    templateContext.put("textData", sw.toString());
-                }
-            }
-            DataResourceWorker.renderDataResourceAsTextCache(delegator, templateDataResourceId, out, templateContext, null, locale, mimeTypeId);
-        }
-        return results;
     }
 
     public static Map buildPickContext(GenericDelegator delegator, String contentAssocTypeId, String assocContentId, String direction, GenericValue thisContent) throws GenericEntityException {

Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataEvents.java?view=diff&rev=513985&r1=513984&r2=513985
==============================================================================
--- ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataEvents.java (original)
+++ ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataEvents.java Fri Mar  2 14:03:48 2007
@@ -20,6 +20,7 @@
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.io.InputStream;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
@@ -42,6 +43,7 @@
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.service.GenericServiceException;
 import org.ofbiz.service.LocalDispatcher;
+import org.ofbiz.service.ServiceUtil;
 
 /**
  * DataEvents Class
@@ -55,7 +57,172 @@
         return DataResourceWorker.uploadAndStoreImage(request, "dataResourceId", "imageData");
     }
 
+    /** Streams any binary content data to the browser */
+    public static String serveObjectData(HttpServletRequest request, HttpServletResponse response) {
+        GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");
+        LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
+        HttpSession session = request.getSession();
+
+        GenericValue userLogin = (GenericValue) session.getAttribute("userLogin");
+        String userAgent = request.getHeader("User-Agent");
+        String contentId = request.getParameter("contentId");
+        if (UtilValidate.isEmpty(contentId)) {
+            String errorMsg = "Required parameter contentId not found!";
+            Debug.logError(errorMsg, module);
+            request.setAttribute("_ERROR_MESSAGE_", errorMsg);
+            return "error";
+        }
+
+        // get the permission service required for streaming data; default is always the genericContentPermission
+        String permissionService = UtilProperties.getPropertyValue("content.properties", "stream.permission.service", "genericContentPermission");
+
+        // get the content record
+        GenericValue content;
+        try {
+            content = delegator.findByPrimaryKey("Content", UtilMisc.toMap("contentId", contentId));
+        } catch (GenericEntityException e) {
+            Debug.logError(e, module);
+            request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
+            return "error";
+        }
+
+        // make sure content exists
+        if (content == null) {
+            String errorMsg = "No content found for Content ID: " + contentId;
+            Debug.logError(errorMsg, module);
+            request.setAttribute("_ERROR_MESSAGE_", errorMsg);
+            return "error";
+        }
+
+        // make sure there is a DataResource for this content
+        String dataResourceId = content.getString("dataResourceId");
+        if (UtilValidate.isEmpty(dataResourceId)) {
+            String errorMsg = "No Data Resource found for Content ID: " + contentId;
+            Debug.logError(errorMsg, module);
+            request.setAttribute("_ERROR_MESSAGE_", errorMsg);
+            return "error";
+        }
+
+        // get the data resource
+        GenericValue dataResource;
+        try {
+            dataResource = delegator.findByPrimaryKey("DataResource", UtilMisc.toMap("dataResourceId", dataResourceId));
+        } catch (GenericEntityException e) {
+            Debug.logError(e, module);
+            request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
+            return "error";
+        }
+
+        // make sure the data resource exists
+        if (dataResource == null) {
+            String errorMsg = "No Data Resource found for ID: " + dataResourceId;
+            Debug.logError(errorMsg, module);
+            request.setAttribute("_ERROR_MESSAGE_", errorMsg);
+            return "error";
+        }
+
+        // see if data resource is public or not
+        String isPublic = dataResource.getString("isPublic");
+        if (UtilValidate.isEmpty(isPublic)) {
+            isPublic = "N";
+        }
+
+        // not public check security
+        if (!"Y".equalsIgnoreCase(isPublic)) {
+            // do security check
+            Map permSvcCtx = UtilMisc.toMap("userLogin", userLogin, "mainAction", "VIEW", "contentId", contentId);
+            Map permSvcResp;
+            try {
+                permSvcResp = dispatcher.runSync(permissionService, permSvcCtx);
+            } catch (GenericServiceException e) {
+                Debug.logError(e, module);
+                request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
+                return "error";
+            }
+            if (ServiceUtil.isError(permSvcResp)) {
+                String errorMsg = ServiceUtil.getErrorMessage(permSvcResp);
+                Debug.logError(errorMsg, module);
+                request.setAttribute("_ERROR_MESSAGE_", errorMsg);
+                return "error";
+            }
+
+            // no service errors; now check the actual response
+            Boolean hasPermission = (Boolean) permSvcResp.get("hasPermission");
+            if (!hasPermission.booleanValue()) {
+                String errorMsg = (String) permSvcResp.get("failMessage");
+                Debug.logError(errorMsg, module);
+                request.setAttribute("_ERROR_MESSAGE_", errorMsg);
+                return "error";
+            }
+        }
+
+        // get objects needed for data processing
+        String contextRoot = (String) request.getAttribute("_CONTEXT_ROOT_");
+        String webSiteId = (String) session.getAttribute("webSiteId");
+        String dataName = dataResource.getString("dataResourceName");
+        Locale locale = UtilHttp.getLocale(request);
+
+        // get the mime type
+        String mimeType = DataResourceWorker.getMimeType(dataResource);
+
+        // hack for IE and mime types
+        if (userAgent.indexOf("MSIE") > -1) {
+            Debug.log("Found MSIE changing mime type from - " + mimeType, module);
+            mimeType = "application/octet-stream";
+        }
+
+        // for local resources; use HTTPS if we are requested via HTTPS
+        String https = "false";
+        String protocol = request.getProtocol();
+        if ("https".equalsIgnoreCase(protocol)) {
+            https = "true";
+        }
+
+        // get the data resource stream and conent length
+        Map resourceData;
+        try {
+            resourceData = DataResourceWorker.getDataResourceStream(dataResource, https, webSiteId, locale, contextRoot, false);
+        } catch (IOException e) {
+            Debug.logError(e, "Error getting DataResource stream", module);
+            request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
+            return "error";
+        } catch (GeneralException e) {
+            Debug.logError(e, "Error getting DataResource stream", module);
+            request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
+            return "error";
+        }
+
+        // get the stream data
+        InputStream stream = null;
+        Long length = null;
+
+        if (resourceData != null) {
+            stream = (InputStream) resourceData.get("stream");
+            length = (Long) resourceData.get("length");
+        }
+        Debug.log("Got resource data stream: " + length + " bytes", module);
+        
+        // stream the content to the browser
+        if (stream != null && length != null) {
+            try {
+                UtilHttp.streamContentToBrowser(response, stream, length.intValue(), mimeType, dataName);
+            } catch (IOException e) {
+                Debug.logError(e, "Unable to write content to browser", module);
+                request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
+                return "error";
+            }
+        } else {
+            String errorMsg = "No data is available.";
+            Debug.logError(errorMsg, module);
+            request.setAttribute("_ERROR_MESSAGE_", errorMsg);
+            return "error";
+        }
+
+        return "success";
+    }
+
     /** Streams ImageDataResource data to the output. */
+    // TODO: remove this method in favor of serveObjectData
     public static String serveImage(HttpServletRequest request, HttpServletResponse response) {
         HttpSession session = request.getSession();
         ServletContext application = session.getServletContext();