Files
ofbiz-framework/applications/content/widget/cms/contentprep.bsh
T
Jacopo Cappellato d4d3f3d355 License change from MIT to ASL2.0 for the files of the content component.
Thanks to Scott Gray for the patch (Apache OFBIZ-87).

git-svn-id: https://svn.apache.org/repos/asf/incubator/ofbiz/trunk@422872 13f79535-47bb-0310-9956-ffa450edef68
2006-07-17 21:12:16 +00:00

155 lines
6.8 KiB
Plaintext

/*
* Copyright 2001-2006 The Apache Software Foundation
*
* Licensed 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.
*/
/**
*
* @author <a href="mailto:byersa@automationgroups.com">Al Byers</a>
* @version $Revision$
* @since 3.0
*/
import org.ofbiz.base.util.*;
import org.ofbiz.entity.*;
import org.ofbiz.security.*;
import org.ofbiz.service.*;
import org.ofbiz.entity.model.*;
import org.ofbiz.widget.html.*;
import org.ofbiz.widget.form.*;
import org.ofbiz.content.data.DataResourceWorker;
import org.ofbiz.webapp.ftl.FreeMarkerViewHandler;
import org.ofbiz.content.content.ContentWorker;
import org.ofbiz.content.ContentManagementWorker;
import java.io.StringWriter;
import freemarker.ext.beans.BeansWrapper;
import freemarker.template.SimpleHash;
import freemarker.template.WrappingTemplateModel;
import javax.servlet.*;
import javax.servlet.http.*;
// load edit or create Content form
dispatcher = (LocalDispatcher)request.getAttribute("dispatcher");
delegator = (GenericDelegator) request.getAttribute("delegator");
ServletContext servletContext = session.getServletContext();
security = (Security)request.getAttribute("security");
//Debug.logInfo("in contentprep, security:" + security, "");
userLogin = session.getAttribute("userLogin");
GenericValue currentValue = null;
singleWrapper = context.get("singleWrapper");
paramMap = UtilHttp.getParameterMap(request);
contentId = "";
if (UtilValidate.isEmpty(contentId))
contentId = (String)ContentManagementWorker.getFromSomewhere("masterContentId", paramMap, request, context);
if (UtilValidate.isEmpty(contentId))
contentId = (String)ContentManagementWorker.getFromSomewhere("contentId", paramMap, request, context);
if (UtilValidate.isEmpty(contentId))
contentId = (String)ContentManagementWorker.getFromSomewhere("contentIdTo", paramMap, request, context);
Debug.logInfo("in contentprep, contentId:" + contentId, "");
ancestorList = new ArrayList();
ContentWorker.getContentAncestry(delegator, contentId, "PUBLISH_LINK", "to", ancestorList);
Debug.logInfo("in contentprep, ancestorList:" + ancestorList, "");
String rootPubPt = null;
if (ancestorList.size() > 0) {
rootPubPt = (String) ancestorList.get(0);
ancestorList = new ArrayList();
ContentWorker.getContentAncestry(delegator, rootPubPt, "SUBSITE", "to", ancestorList);
Debug.logInfo("in contentprep, ancestorList(1):" + ancestorList, "");
if (ancestorList.size() > 0) {
rootPubPt = (String) ancestorList.get(0);
}
}
//Debug.logInfo("in contentprep, contentId(1):" + contentId, "");
if (currentValue == null) {
currentValue = (GenericValue)request.getAttribute("currentValue");
//Debug.logInfo("in contentprep, currentValue(0):" + currentValue, "");
}
if (UtilValidate.isEmpty(contentId) && currentValue != null) {
contentId = currentValue.getString("contentId");
}
if (UtilValidate.isNotEmpty(contentId) && currentValue == null) {
currentValue = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", contentId));
}
context.put("currentValue", currentValue);
Debug.logInfo("in contentprep, currentValue(1):" + currentValue, "");
Locale locale = Locale.getDefault();
if (currentValue != null) {
dataResourceId = (String)currentValue.get("dataResourceId");
context.put("contentId", contentId);
context.put("contentName", currentValue.get("contentName"));
context.put("description", currentValue.get("description"));
context.put("statusId", currentValue.get("statusId"));
dataResourceId = currentValue.get("dataResourceId");
context.put("dataResourceId", dataResourceId);
mimeTypeId = (String)currentValue.get("mimeTypeId");
rootDir = request.getSession().getServletContext().getRealPath("/");
wrapper = BeansWrapper.getDefaultInstance();
WrappingTemplateModel.setDefaultObjectWrapper(wrapper);
//templateRoot = new SimpleHash(wrapper);
templateRoot = new HashMap();
FreeMarkerViewHandler.prepOfbizRoot(templateRoot, request, response);
templateRoot.put("rootDir", rootDir);
// webSiteId and https need to go here, too
fromDate = UtilDateTime.nowTimestamp();
assocTypes = null;
//assocTypes = UtilMisc.toList("SUB_CONTENT");
if ( currentValue != null) {
Debug.logInfo("in contentprep, contentId(4):" + contentId, "");
Debug.logInfo("in contentprep, dataResourceId(4):" + dataResourceId, "");
currentView = delegator.findByPrimaryKey("ContentDataResourceView", UtilMisc.toMap("contentId", contentId, "drDataResourceId", dataResourceId));
Debug.logInfo("in contentprep, currentView:" + currentView, "");
textData = ContentWorker.renderContentAsTextCache(delegator, null, templateRoot, currentView, locale, mimeTypeId);
Debug.logInfo("in contentprep, textData:" + textData, "");
context.put("textData", textData);
context.put("currentView", currentView);
assocList = ContentWorker.getContentAssocViewList(delegator, contentId, null, "SUB_CONTENT", null, null);
textList = new ArrayList();
iter = assocList.iterator();
while (iter.hasNext()) {
contentAssocDataResourceView = iter.next();
Debug.logInfo("in contentprep, contentAssocDataResourceView:" + contentAssocDataResourceView, "");
localeString = contentAssocDataResourceView.getString("drLocaleString");
thisLocale = locale;
if (UtilValidate.isNotEmpty(localeString)) {
thisLocale = UtilMisc.parseLocale(localeString);
}
thisMimeTypeId = (String)contentAssocDataResourceView.get("drMimeTypeId");
if (UtilValidate.isEmpty(thisMimeTypeId)) {
thisMimeTypeId = mimeTypeId;
}
childText = ContentWorker.renderContentAsTextCache(delegator, null, templateRoot, contentAssocDataResourceView, locale, mimeTypeId);
Debug.logInfo("in contentprep, childText:" + childText, "");
map = new HashMap();
map.put("entity", contentAssocDataResourceView);
map.put("text", childText);
map.put("id", contentAssocDataResourceView.get("contentId"));
textList.add(map);
}
context.put("textList", textList);
}
}