📄 contentservices.java
字号:
/* * $Id: ContentServices.java 7074 2006-03-25 00:04:33Z jonesde $ * * Copyright (c) 2001-2005 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. */package org.ofbiz.content.content;import java.io.ByteArrayOutputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.io.StringWriter;import java.io.Writer;import java.sql.Timestamp;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Locale;import java.util.Map;import java.util.Set;import javax.xml.parsers.ParserConfigurationException;import org.apache.avalon.framework.logger.Log4JLogger;import org.apache.avalon.framework.logger.Logger;import org.apache.fop.apps.Driver;import org.apache.fop.image.FopImageFactory;import org.apache.fop.messaging.MessageHandler;import org.apache.fop.tools.DocumentInputSource;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.GeneralException;import org.ofbiz.base.util.StringUtil;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.UtilValidate;import org.ofbiz.base.util.UtilXml;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.condition.EntityConditionList;import org.ofbiz.entity.condition.EntityExpr;import org.ofbiz.entity.condition.EntityOperator;import org.ofbiz.entity.util.ByteWrapper;import org.ofbiz.entity.util.EntityUtil;import org.ofbiz.security.Security;import org.ofbiz.service.DispatchContext;import org.ofbiz.service.GenericServiceException;import org.ofbiz.service.LocalDispatcher;import org.ofbiz.service.ModelService;import org.ofbiz.service.ServiceUtil;import org.w3c.dom.Document;import org.xml.sax.InputSource;import org.xml.sax.SAXException;/** * ContentServices Class * * @author <a href="mailto:byersa@automationgroups.com">Al Byers</a> * @version $Rev: 7074 $ * @since 2.2 * * */public class ContentServices { public static final String module = ContentServices.class.getName(); /** * findRelatedContent Finds the related */ public static Map findRelatedContent(DispatchContext dctx, Map context) { LocalDispatcher dispatcher = dctx.getDispatcher(); Map results = new HashMap(); GenericValue currentContent = (GenericValue) context.get("currentContent"); String fromDate = (String) context.get("fromDate"); String thruDate = (String) context.get("thruDate"); String toFrom = (String) context.get("toFrom"); if (toFrom == null) { toFrom = "TO"; } else { toFrom = toFrom.toUpperCase(); } List assocTypes = (List) context.get("contentAssocTypeList"); List targetOperations = (List) context.get("targetOperationList"); List contentList = null; List contentTypes = (List) context.get("contentTypeList"); try { contentList = ContentWorker.getAssociatedContent(currentContent, toFrom, assocTypes, contentTypes, fromDate, thruDate); } catch (GenericEntityException e) { return ServiceUtil.returnError("Error getting associated content: " + e.toString()); } if (targetOperations == null || targetOperations.isEmpty()) { results.put("contentList", contentList); return results; } Map serviceInMap = new HashMap(); serviceInMap.put("userLogin", context.get("userLogin")); serviceInMap.put("targetOperationList", targetOperations); serviceInMap.put("entityOperation", context.get("entityOperation")); List permittedList = new ArrayList(); Iterator it = contentList.iterator(); Map permResults = null; while (it.hasNext()) { GenericValue content = (GenericValue) it.next(); serviceInMap.put("currentContent", content); try { permResults = dispatcher.runSync("checkContentPermission", serviceInMap); } catch (GenericServiceException e) { Debug.logError(e, "Problem checking permissions", "ContentServices"); return ServiceUtil.returnError("Problem checking permissions"); } String permissionStatus = (String) permResults.get("permissionStatus"); if (permissionStatus != null && permissionStatus.equalsIgnoreCase("granted")) { permittedList.add(content); } } results.put("contentList", permittedList); return results; } /** * This is a generic service for traversing a Content tree, typical of a blog response tree. It calls the ContentWorker.traverse method. */ public static Map findContentParents(DispatchContext dctx, Map context) { HashMap results = new HashMap(); List parentList = new ArrayList(); results.put("parentList", parentList); LocalDispatcher dispatcher = dctx.getDispatcher(); String contentId = (String)context.get("contentId"); String contentAssocTypeId = (String)context.get("contentAssocTypeId"); String direction = (String)context.get("direction"); if (UtilValidate.isEmpty(direction)) direction="To"; Map traversMap = new HashMap(); traversMap.put("contentId", contentId); traversMap.put("direction", direction); traversMap.put("contentAssocTypeId", contentAssocTypeId); try { Map thisResults = dispatcher.runSync("traverseContent", traversMap); String errorMsg = ServiceUtil.getErrorMessage(thisResults); if (UtilValidate.isNotEmpty(errorMsg) ) { Debug.logError( "Problem in traverseContent. " + errorMsg, module); return ServiceUtil.returnError(errorMsg); } Map nodeMap = (Map)thisResults.get("nodeMap"); walkParentTree(nodeMap, parentList); } catch (GenericServiceException e) { return ServiceUtil.returnFailure(e.getMessage()); } return results; } private static void walkParentTree(Map nodeMap, List parentList) { List kids = (List)nodeMap.get("kids"); if (kids == null || kids.size() == 0) { parentList.add(nodeMap.get("contentId")); } else { Iterator iter = kids.iterator(); while (iter.hasNext()) { Map node = (Map) iter.next(); walkParentTree(node, parentList); } } } /** * This is a generic service for traversing a Content tree, typical of a blog response tree. It calls the ContentWorker.traverse method. */ public static Map traverseContent(DispatchContext dctx, Map context) { GenericDelegator delegator = dctx.getDelegator(); HashMap results = new HashMap(); String contentId = (String) context.get("contentId"); String direction = (String) context.get("direction"); if (direction != null && direction.equalsIgnoreCase("From")) { direction = "From"; } else { direction = "To"; } if (contentId == null) { contentId = "PUBLISH_ROOT"; } GenericValue content = null; try { content = delegator.findByPrimaryKey("Content", UtilMisc.toMap("contentId", contentId)); } catch (GenericEntityException e) { System.out.println("Entity Error:" + e.getMessage()); return ServiceUtil.returnError("Error in retrieving Content. " + e.getMessage()); } String fromDateStr = (String) context.get("fromDateStr"); String thruDateStr = (String) context.get("thruDateStr"); Timestamp fromDate = null; if (fromDateStr != null && fromDateStr.length() > 0) { fromDate = UtilDateTime.toTimestamp(fromDateStr); } Timestamp thruDate = null; if (thruDateStr != null && thruDateStr.length() > 0) { thruDate = UtilDateTime.toTimestamp(thruDateStr); } Map whenMap = new HashMap(); whenMap.put("followWhen", context.get("followWhen")); whenMap.put("pickWhen", context.get("pickWhen")); whenMap.put("returnBeforePickWhen", context.get("returnBeforePickWhen")); whenMap.put("returnAfterPickWhen", context.get("returnAfterPickWhen")); String startContentAssocTypeId = (String) context.get("contentAssocTypeId"); if (startContentAssocTypeId != null) { startContentAssocTypeId = "PUBLISH"; } Map nodeMap = new HashMap(); List pickList = new ArrayList(); ContentWorker.traverse(delegator, content, fromDate, thruDate, whenMap, 0, nodeMap, startContentAssocTypeId, pickList, direction); results.put("nodeMap", nodeMap); results.put("pickList", pickList); return results; } /** * Create a Content service. The work is done in a separate method so that complex services that need this functionality do not need to incur the * reflection performance penalty. */ public static Map createContent(DispatchContext dctx, Map context) { /* context.put("entityOperation", "_CREATE"); List targetOperationList = ContentWorker.prepTargetOperationList(context, "_CREATE"); List contentPurposeList = ContentWorker.prepContentPurposeList(context); context.put("targetOperationList", targetOperationList); context.put("contentPurposeList", contentPurposeList); // for checking permissions //context.put("skipPermissionCheck", null); */ Map result = createContentMethod(dctx, context);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -