⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uploadcontentandimage.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    return "error";                }            }                // Check for existing AUTHOR link            String userLoginId = userLogin.getString("userLoginId");            GenericValue authorContent = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", userLoginId));            if (authorContent != null) {                List authorAssocList = delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentId", ftlContentId, "contentIdTo", userLoginId, "contentAssocTypeId", "AUTHOR"));                List currentAuthorAssocList = EntityUtil.filterByDate(authorAssocList);                //if (Debug.infoOn()) Debug.logInfo("[UploadContentAndImage]currentAuthorAssocList " + currentAuthorAssocList, module);                if (currentAuthorAssocList.size() == 0) {                    // Don't want to bother with permission checking on this association                    GenericValue authorAssoc = delegator.makeValue("ContentAssoc", null);                    authorAssoc.set("contentId", ftlContentId);                    authorAssoc.set("contentIdTo", userLoginId);                    authorAssoc.set("contentAssocTypeId", "AUTHOR");                    authorAssoc.set("fromDate", UtilDateTime.nowTimestamp());                    authorAssoc.set("createdByUserLogin", userLoginId);                    authorAssoc.set("lastModifiedByUserLogin", userLoginId);                    authorAssoc.set("createdDate", UtilDateTime.nowTimestamp());                    authorAssoc.set("lastModifiedDate", UtilDateTime.nowTimestamp());                    authorAssoc.create();                }            }            request.setAttribute("dataResourceId", ftlDataResourceId);            request.setAttribute("drDataResourceId", ftlDataResourceId);            request.setAttribute("contentId", ftlContentId);            request.setAttribute("masterContentId", ftlContentId);            request.setAttribute("contentIdTo", contentIdTo);            String newTrail = passedParams.get("nodeTrailCsv") + "," + ftlContentId;            request.setAttribute("nodeTrailCsv", newTrail);            request.setAttribute("passedParams", passedParams);            //if (Debug.infoOn()) Debug.logInfo("[UploadContentAndImage]newTrail: " + newTrail, module);            TransactionUtil.commit();        } catch( Exception e) {            Debug.logError(e, "[UploadContentAndImage] " , module);            request.setAttribute("_ERROR_MESSAGE_", e.getMessage());            try {                    TransactionUtil.rollback();            } catch(GenericTransactionException e2) {            request.setAttribute("_ERROR_MESSAGE_", e2.getMessage());            return "error";            }            return "error";        }        return "success";    }    public static String uploadContentStuff(HttpServletRequest request, HttpServletResponse response) {               try {            LocalDispatcher dispatcher = (LocalDispatcher)request.getAttribute("dispatcher");            GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");            HttpSession session = request.getSession();            GenericValue userLogin = (GenericValue)session.getAttribute("userLogin");            DiskFileUpload dfu = new DiskFileUpload();            //if (Debug.infoOn()) Debug.logInfo("[UploadContentAndImage]DiskFileUpload " + dfu, module);            java.util.List lst = null;            try {                lst = dfu.parseRequest(request);            } catch (FileUploadException e4) {                request.setAttribute("_ERROR_MESSAGE_", e4.getMessage());                Debug.logError("[UploadContentAndImage.uploadContentAndImage] " + e4.getMessage(), module);                return "error";            }            //if (Debug.infoOn()) Debug.logInfo("[UploadContentAndImage]lst " + lst, module);                if (lst.size() == 0) {                request.setAttribute("_ERROR_MESSAGE_", "No files uploaded");                Debug.logWarning("[DataEvents.uploadImage] No files uploaded", module);                return "error";            }                Map passedParams = new HashMap();            FileItem fi = null;            FileItem imageFi = null;            byte[] imageBytes = {};            passedParams.put("userLogin", userLogin);            for (int i = 0; i < lst.size(); i++) {                fi = (FileItem) lst.get(i);                //String fn = fi.getName();                String fieldName = fi.getFieldName();                if (fi.isFormField()) {                    String fieldStr = fi.getString();                    passedParams.put(fieldName, fieldStr);                } else if (fieldName.startsWith("imageData")) {                    imageFi = fi;                    String fileName = fi.getName();                    passedParams.put("drObjectInfo", fileName);                    String contentType = fi.getContentType();                    passedParams.put("drMimeTypeId", contentType);                    imageBytes = imageFi.get();                    passedParams.put(fieldName, imageBytes);            if (Debug.infoOn()) Debug.logInfo("[UploadContentAndImage]imageData: " + imageBytes.length, module);                }            }            if (Debug.infoOn()) Debug.logInfo("[UploadContentAndImage]passedParams: " + passedParams, module);            String strRowCount = (String)passedParams.get("_rowCount");            if (UtilValidate.isEmpty(strRowCount)) {                strRowCount = "1";            }            int rowCount = Integer.parseInt(strRowCount);            TransactionUtil.begin();            for (int i=0; i < rowCount; i++) {                String suffix = "_o_" + i;                if (i==0)                   suffix = "";                String returnMsg = processContentUpload(passedParams, suffix, request);                if (returnMsg.equals("error")) {                    try {                        TransactionUtil.rollback();                    } catch(GenericTransactionException e2) {                        ServiceUtil.setMessages(request, e2.getMessage(), null, null);                        return "error";                    }                    return "error";                }            }            TransactionUtil.commit();        } catch( Exception e) {            Debug.logError(e, "[UploadContentAndImage] " , module);            request.setAttribute("_ERROR_MESSAGE_", e.getMessage());            try {                TransactionUtil.rollback();            } catch(GenericTransactionException e2) {                request.setAttribute("_ERROR_MESSAGE_", e2.getMessage());                return "error";            }            return "error";        }        return "success";    }    public static String processContentUpload(Map passedParams, String suffix, HttpServletRequest request) throws GenericServiceException {            LocalDispatcher dispatcher = (LocalDispatcher)request.getAttribute("dispatcher");            GenericDelegator delegator = (GenericDelegator)request.getAttribute("delegator");            HttpSession session = request.getSession();            GenericValue userLogin = (GenericValue)session.getAttribute("userLogin");            Map ftlContext = new HashMap();            String contentPurposeString = (String)passedParams.get("contentPurposeString" + suffix);            if (UtilValidate.isEmpty(contentPurposeString)) {                contentPurposeString = (String)passedParams.get("contentPurposeString");            }            List contentPurposeList = StringUtil.split(contentPurposeString,"|");            ftlContext.put("contentPurposeList", contentPurposeList);            String targetOperationString = (String)passedParams.get("targetOperationString" + suffix);            if (UtilValidate.isEmpty(targetOperationString)) {                targetOperationString = (String)passedParams.get("targetOperationString");            }            List targetOperationList = StringUtil.split(targetOperationString,"|");            ftlContext.put("targetOperationList",targetOperationList);            ftlContext.put("userLogin", userLogin);            Object objSequenceNum = passedParams.get("caSequenceNum");            if (objSequenceNum != null ) {            	if (objSequenceNum instanceof String) {            		Long sequenceNum = null;            		try {            	    	sequenceNum = new Long((String)objSequenceNum);                	} catch(NumberFormatException e) {                	}                    passedParams.put("caSequenceNum", sequenceNum);               	}            }            GenericValue contentAssocDataResourceViewFrom = delegator.makeValue("ContentAssocDataResourceViewFrom",null);            ModelEntity modelEntity = delegator.getModelEntity("ContentAssocDataResourceViewFrom");            List fieldNames = modelEntity.getAllFieldNames();            Iterator iter = fieldNames.iterator();            Map ftlContext2 = new HashMap();            Map ftlContext3 = new HashMap();            while (iter.hasNext()) {                String keyName = (String)iter.next();                Object obj = passedParams.get(keyName + suffix);                ftlContext2.put(keyName, obj);            }            if (Debug.infoOn()) Debug.logInfo("[UploadContentStuff]ftlContext2:" + ftlContext2, module);            List errorMessages = new ArrayList();            Locale loc = Locale.getDefault();            try {                SimpleMapProcessor.runSimpleMapProcessor( "org/ofbiz/content/ContentManagementMapProcessors.xml", "contentIn", ftlContext2, ftlContext3, errorMessages, loc);                SimpleMapProcessor.runSimpleMapProcessor( "org/ofbiz/content/ContentManagementMapProcessors.xml", "contentOut", ftlContext3, ftlContext, errorMessages, loc);                ftlContext3 = new HashMap();                SimpleMapProcessor.runSimpleMapProcessor( "org/ofbiz/content/ContentManagementMapProcessors.xml", "dataResourceIn", ftlContext2, ftlContext3, errorMessages, loc);                SimpleMapProcessor.runSimpleMapProcessor( "org/ofbiz/content/ContentManagementMapProcessors.xml", "dataResourceOut", ftlContext3, ftlContext, errorMessages, loc);                ftlContext3 = new HashMap();                SimpleMapProcessor.runSimpleMapProcessor( "org/ofbiz/content/ContentManagementMapProcessors.xml", "contentAssocIn", ftlContext2, ftlContext3, errorMessages, loc);                SimpleMapProcessor.runSimpleMapProcessor( "org/ofbiz/content/ContentManagementMapProcessors.xml", "contentAssocOut", ftlContext3, ftlContext, errorMessages, loc);            } catch(MiniLangException e) {                throw new GenericServiceException(e.getMessage());            }            ftlContext.put("textData", passedParams.get("textData" + suffix));            byte[] bytes = (byte[])passedParams.get("imageData" + suffix);            ByteWrapper byteWrapper = new ByteWrapper(bytes);            ftlContext.put("imageData", byteWrapper);            if (Debug.infoOn()) Debug.logInfo("[UploadContentStuff]byteWrapper:" + byteWrapper, module);            //contentAssocDataResourceViewFrom.setAllFields(ftlContext2, true, null, null);            //ftlContext.putAll(ftlContext2);                         if (Debug.infoOn()) Debug.logInfo("[UploadContentStuff]ftlContext:" + ftlContext, module);            Map ftlResults = null;            try {                ftlResults = dispatcher.runSync("persistContentAndAssoc", ftlContext);            } catch(ServiceAuthException e) {                String msg = e.getMessage();                request.setAttribute("_ERROR_MESSAGE_", msg);                List errorMsgList = (List)request.getAttribute("_EVENT_MESSAGE_LIST_");                if (Debug.infoOn()) Debug.logInfo("[UploadContentStuff]errorMsgList:" + errorMsgList, module);                if (Debug.infoOn()) Debug.logInfo("[UploadContentStuff]msg:" + msg, module);                if (errorMsgList == null) {                    errorMsgList = new ArrayList();                    request.setAttribute("errorMessageList", errorMsgList);                }                errorMsgList.add(msg);                return "error";            }            String msg = ServiceUtil.getErrorMessage(ftlResults);            if (UtilValidate.isNotEmpty(msg)) {                request.setAttribute("_ERROR_MESSAGE_", msg);                List errorMsgList = (List)request.getAttribute("_EVENT_MESSAGE_LIST_");                if (errorMsgList == null) {                    errorMsgList = new ArrayList();                    request.setAttribute("errorMessageList", errorMsgList);                }                errorMsgList.add(msg);                return "error";            }            String returnedContentId = (String)ftlResults.get("contentId");            if (Debug.infoOn()) Debug.logInfo("returnedContentId:" + returnedContentId, module);            request.setAttribute("contentId" + suffix, ftlResults.get("contentId"));            request.setAttribute("caContentIdTo" + suffix, ftlResults.get("contentIdTo"));            request.setAttribute("caContentIdStart" + suffix, ftlResults.get("contentIdTo"));            request.setAttribute("caContentAssocTypeId" + suffix, ftlResults.get("contentAssocTypeId"));            request.setAttribute("caFromDate" + suffix, ftlResults.get("fromDate"));            request.setAttribute("drDataResourceId" + suffix, ftlResults.get("dataResourceId"));            request.setAttribute("caContentId" + suffix, ftlResults.get("contentId"));                        String caContentIdTo = (String)passedParams.get("caContentIdTo");            if (UtilValidate.isNotEmpty(caContentIdTo)) {                Map resequenceContext = new HashMap();                resequenceContext.put("contentIdTo", caContentIdTo);                resequenceContext.put("userLogin", userLogin);                try {                    ftlResults = dispatcher.runSync("resequence", resequenceContext);                } catch(ServiceAuthException e) {                    msg = e.getMessage();                    request.setAttribute("_ERROR_MESSAGE_", msg);                    List errorMsgList = (List)request.getAttribute("_EVENT_MESSAGE_LIST_");                    if (Debug.infoOn()) Debug.logInfo("[UploadContentStuff]errorMsgList:" + errorMsgList, module);                    if (Debug.infoOn()) Debug.logInfo("[UploadContentStuff]msg:" + msg, module);                    if (errorMsgList == null) {                        errorMsgList = new ArrayList();                        request.setAttribute("errorMessageList", errorMsgList);                    }                    errorMsgList.add(msg);                    return "error";                }            }            return "success";    }} // end of UploadContentAndImage

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -