📄 contentprep.bsh
字号:
/* * $Id: contentprep.bsh 5462 2005-08-05 18:35:48Z jonesde $ * * Copyright (c) 2003 The Open For Business Project - www.ofbiz.org * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * *//** * * @author <a href="mailto:byersa@automationgroups.com">Al Byers</a> * @version $Rev: 5462 $ * @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 formdispatcher = (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); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -