Files
ofbiz-framework/applications/content/groovyScripts/layout/EditSubContent.groovy
T
Jacques Le Roux a4cd270ca4 Fixed: You cannot edit an image in content
(OFBIZ-7000)

If you get to
content/control/EditLayout?drDataResourceId=NOCONTENTFOUND&contentId=NOCONTENTFOUND
When trying to editing you get an error

Mohammed Rehan Khan explored the issue and found that there is a condition in 
DataResourceWorker method to render content of 'text' mime type only, for others
 it returns exception.

We can fix this by setting up mimeTypeID as null in request param

Question: Why setting up mimeTypeTypeId as 'null' is fixing this issue?
Answer: As we don't have image specific worker method for rendering these type 
of contents, so we are using DataResourceWorker.renderDataResourceAsText() 
to render image type content as well. Due to following condition, 
targetMimeTypeId is setting up as "text/html" if sent null and hence not 
throwing the exception reported in the ticket.

Thanks: Mohammed Rehan Khan for the patch

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1765094 13f79535-47bb-0310-9956-ffa450edef68
2016-10-15 17:12:28 +00:00

55 lines
2.2 KiB
Groovy

/*
* 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.
*/
import org.apache.ofbiz.base.util.*
import org.apache.ofbiz.base.util.template.FreeMarkerWorker
import org.apache.ofbiz.entity.*
import org.apache.ofbiz.entity.model.*
import org.apache.ofbiz.content.data.DataResourceWorker
import org.apache.ofbiz.webapp.ftl.FreeMarkerViewHandler
import java.io.StringWriter
import freemarker.template.WrappingTemplateModel
import javax.servlet.*
import javax.servlet.http.*
Locale locale = UtilHttp.getLocale(request);
if (currentValue) {
dataResourceId = currentValue.drDataResourceId;
dataResourceTypeId = currentValue.drDataResourceTypeId;
if (dataResourceTypeId) {
mimeTypeId = currentValue.drMimeTypeId;
rootDir = request.getSession().getServletContext().getRealPath("/");
wrapper = FreeMarkerWorker.getDefaultOfbizWrapper();
WrappingTemplateModel.setDefaultObjectWrapper(wrapper);
templateRoot = [:];
FreeMarkerViewHandler.prepOfbizRoot(templateRoot, request, response);
ctx = [:];
ctx.rootDir = rootDir;
// webSiteId and https need to go here, too
templateRoot.context = ctx;
out = new StringWriter();
currentValue.drDataTemplateTypeId = "NONE";
DataResourceWorker.renderDataResourceAsText(delegator, dataResourceId, out, templateRoot, locale, null, false);
textData = out.toString();
context.textData = textData;
}
}