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

📄 contentworker.java

📁 国外的一套开源CRM
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        }
        GenericDelegator delegator = view.getDelegator();
        content = delegator.makeValue("Content", null);
        content.setPKFields(view);
        content.setNonPKFields(view);
        String dataResourceId = null;
        try {
            dataResourceId = (String) view.get("drDataResourceId");
        } catch (Exception e) {
            dataResourceId = (String) view.get("dataResourceId");
        }
        content.set("dataResourceId", dataResourceId);
        return content;
    }

    public static Map renderSubContentAsText(GenericDelegator delegator, String contentId, Writer out, String mapKey, String subContentId, GenericValue subContentDataResourceView, 
            Map templateContext, Locale locale, String mimeTypeId, GenericValue userLogin, Timestamp fromDate) throws GeneralException, IOException {

        //Map context = (Map) FreeMarkerWorker.get(templateContext, "context");
        //if (Debug.verboseOn()) Debug.logVerbose(" in renderSubContentAsText, mimeTypeId:" + mimeTypeId, module);
        Map results = new HashMap();
        //GenericValue content = null;
        if (subContentDataResourceView == null) {
            subContentDataResourceView = ContentWorker.getSubContent(delegator, contentId, mapKey, subContentId, userLogin, null, fromDate);
        }
        results.put("view", subContentDataResourceView);
        if (subContentDataResourceView == null) {
            //throw new IOException("SubContentDataResourceView is null.");
            if (Debug.verboseOn()) Debug.logVerbose(" in renderSubContentAsText, SubContentDataResourceView is null", module);
            return results;
        }

        //String dataResourceId = (String) subContentDataResourceView.get("drDataResourceId");
        subContentId = (String) subContentDataResourceView.get("contentId");
        //GenericValue dataResourceContentView = null;

        if (templateContext == null) {
            templateContext = new HashMap();
        }

        renderContentAsText(delegator, subContentId, out, templateContext, subContentDataResourceView, locale, mimeTypeId);

        return results;
    }

    public static Map renderSubContentAsTextCache(GenericDelegator delegator, String contentId, Writer out, String mapKey, String subContentId, GenericValue subContentDataResourceView, 
            Map templateContext, Locale locale, String mimeTypeId, GenericValue userLogin, Timestamp fromDate) throws GeneralException, IOException {

        //Map context = (Map) FreeMarkerWorker.get(templateContext, "context");
        //if (Debug.verboseOn()) Debug.logVerbose(" in renderSubContentAsText, mimeTypeId:" + mimeTypeId, module);
        Map results = new HashMap();
        //GenericValue content = null;
        if (subContentDataResourceView == null) 
                subContentDataResourceView = ContentWorker.getSubContent(delegator, contentId, mapKey, subContentId, userLogin, null, fromDate);
        results.put("view", subContentDataResourceView);
        if (subContentDataResourceView == null) {
            //throw new IOException("SubContentDataResourceView is null.");
            if (Debug.verboseOn()) Debug.logVerbose(" in renderSubContentAsText, SubContentDataResourceView is null", module);
            return results;
        }

        //String dataResourceId = (String) subContentDataResourceView.get("drDataResourceId");
        subContentId = (String) subContentDataResourceView.get("contentId");
        //GenericValue dataResourceContentView = null;

        if (templateContext == null) {
            templateContext = new HashMap();
        }

        renderContentAsTextCache(delegator, subContentId, out, templateContext, subContentDataResourceView, locale, mimeTypeId);

        return results;
    }

    public static Map renderContentAsText(GenericDelegator delegator, String contentId, Writer out, Map templateContext, GenericValue view, Locale locale, String mimeTypeId) throws GeneralException, IOException {
        //Map context = (Map) FreeMarkerWorker.get(templateContext, "context");
        //if (Debug.verboseOn()) Debug.logVerbose(" in renderContentAsText, mimeTypeId:" + mimeTypeId, module);
        Map results = new HashMap();
        GenericValue content = null;

        if (view == null) {
            if (contentId == null) {
                throw new IOException("ContentId is null");
            }
            try {
                List lst = delegator.findByAnd("SubContentDataResourceView", UtilMisc.toMap("contentId", contentId), UtilMisc.toList("-fromDate"));
                if (lst != null && lst.size() > 0) {
                    view = (GenericValue) lst.get(0);
                } else {
                    if (Debug.verboseOn()) Debug.logVerbose(" in renderContentAsText, no SubContentDataResourceView found.", module);
                    throw new IOException("SubContentDataResourceView not found in renderSubContentAsText" + " for contentId=" + contentId);
                }
            } catch (GenericEntityException e) {
                throw new IOException(e.getMessage());
            }
        }
        if (view != null) {
            Map contentMap = new HashMap();
            try {
                SimpleMapProcessor.runSimpleMapProcessor("org/ofbiz/content/ContentManagementMapProcessors.xml", "contentIn", view, contentMap, new ArrayList(), locale);
            } catch (MiniLangException e) {
                throw new IOException(e.getMessage());
            }
            content = delegator.makeValue("Content", contentMap);
        }

        results.put("view", view);
        results.put("content", content);

        if (locale != null) {
            String targetLocaleString = locale.toString();
            String thisLocaleString = (String) view.get("localeString");
            thisLocaleString = (thisLocaleString != null) ? thisLocaleString : "";
            //if (Debug.verboseOn()) Debug.logVerbose("thisLocaleString" + thisLocaleString, "");
            if (targetLocaleString != null && !targetLocaleString.equalsIgnoreCase(thisLocaleString)) {
                view = findAlternateLocaleContent(delegator, view, locale);
            }
        }

        //String contentTypeId = (String) view.get("contentTypeId");
        String dataResourceId = null;
        try {
            dataResourceId = (String) view.get("drDataResourceId");
        } catch (Exception e) {
            dataResourceId = (String) view.get("dataResourceId");
        }
        if (templateContext == null) {
            templateContext = new HashMap();
        }

        // TODO: what should we REALLY do here? looks like there is no decision between Java and Service style error handling...
        //try {
        if (Debug.verboseOn()) Debug.logVerbose("in renderContentAsText, view" + view, "");
        if (Debug.verboseOn()) Debug.logVerbose("in renderContentAsText, dataResourceId" + dataResourceId, "");
        if (UtilValidate.isNotEmpty(dataResourceId) || view != null)
            DataResourceWorker.renderDataResourceAsText(delegator, dataResourceId, out, templateContext, view, locale, mimeTypeId);
        //} catch (IOException e) {
        //    return ServiceUtil.returnError(e.getMessage());
        //}

        return results;
    }

    public static Map renderContentAsTextCache(GenericDelegator delegator, String contentId, Writer out, Map templateContext, GenericValue view, Locale locale, String mimeTypeId) throws GeneralException, IOException {
        //Map context = (Map) FreeMarkerWorker.get(templateContext, "context");
        //if (Debug.verboseOn()) Debug.logVerbose(" in renderContentAsText, mimeTypeId:" + mimeTypeId, module);
        Map results = new HashMap();
        GenericValue content = null;

        if (view == null) {
            if (contentId == null) {
                throw new IOException("ContentId is null");
            }
            try {
                List lst = delegator.findByAndCache("SubContentDataResourceView", UtilMisc.toMap("contentId", contentId), UtilMisc.toList("-fromDate"));
                if (lst != null && lst.size() > 0) {
                    view = (GenericValue) lst.get(0);
                } else {
                    if (Debug.verboseOn()) Debug.logVerbose(" in renderContentAsText, no SubContentDataResourceView found.", module);
                    throw new IOException("SubContentDataResourceView not found in renderSubContentAsText" + " for contentId=" + contentId);
                }
            } catch (GenericEntityException e) {
                throw new IOException(e.getMessage());
            }
        }
        if (view != null) {
            Map contentMap = new HashMap();
            try {
                SimpleMapProcessor.runSimpleMapProcessor("org/ofbiz/content/ContentManagementMapProcessors.xml", "contentIn", view, contentMap, new ArrayList(), locale);
            } catch (MiniLangException e) {
                throw new IOException(e.getMessage());
            }
            content = delegator.makeValue("Content", contentMap);
        }

        results.put("view", view);
        results.put("content", content);

        if (locale != null) {
            String targetLocaleString = locale.toString();
            String thisLocaleString = (String) view.get("localeString");
            thisLocaleString = (thisLocaleString != null) ? thisLocaleString : "";
            //if (Debug.verboseOn()) Debug.logVerbose("thisLocaleString" + thisLocaleString, "");
            if (targetLocaleString != null && !targetLocaleString.equalsIgnoreCase(thisLocaleString)) {
                view = findAlternateLocaleContent(delegator, view, locale);
            }
        }
        if (Debug.verboseOn()) Debug.logVerbose(" in renderContentAsText, content." + content, module);

        //String contentTypeId = (String) view.get("contentTypeId");
        String dataResourceId = null;
        try {
            dataResourceId = (String) view.get("drDataResourceId");
        } catch (Exception e) {
            dataResourceId = (String) view.get("dataResourceId");
            view = null; // renderDataResourceAsText will expect DataResource values if not null
        }
        if (Debug.verboseOn()) Debug.logVerbose(" in renderContentAsText, dataResourceId." + dataResourceId, module);
        if (Debug.verboseOn()) Debug.logVerbose(" in renderContentAsText, view." + view, module);

        if (templateContext == null) {
            templateContext = new HashMap();
        }

        // TODO: what should we REALLY do here? looks like there is no decision between Java and Service style error handling...
        //try {
        if (Debug.verboseOn()) Debug.logVerbose("in renderContentAsText, view" + view, "");
        if (Debug.verboseOn()) Debug.logVerbose("in renderContentAsText, dataResourceId" + dataResourceId, "");
        if (UtilValidate.isNotEmpty(dataResourceId) || view != null)
            DataResourceWorker.renderDataResourceAsTextCache(delegator, dataResourceId, out, templateContext, view, locale, mimeTypeId);
        //} catch (IOException e) {
        //    return ServiceUtil.returnError(e.getMessage());
        //}

        return results;
    }

    public static Map buildPickContext(GenericDelegator delegator, String contentAssocTypeId, String assocContentId, String direction, GenericValue thisContent) throws GenericEntityException {

        Map ctx = new HashMap();
        ctx.put("contentAssocTypeId", contentAssocTypeId);
        ctx.put("contentId", assocContentId);
        String assocRelation = null;
        // This needs to be the opposite
        if (direction != null && direction.equalsIgnoreCase("From")) {
            ctx.put("contentIdFrom", assocContentId);
            assocRelation = "FromContent";
        } else {
            ctx.put("contentIdTo", assocContentId);
            assocRelation = "ToContent";
        }
        if (thisContent == null)
            thisContent = delegator.findByPrimaryKeyCache("Content",
                                   UtilMisc.toMap("contentId", assocContentId));
        ctx.put("content", thisContent);
        List purposes = getPurposes(thisContent);
        ctx.put("purposes", purposes);
        List contentTypeAncestry = new ArrayList();
        String contentTypeId = (String)thisContent.get("contentTypeId");
        getContentTypeAncestry(delegator, contentTypeId, contentTypeAncestry);
        ctx.put("typeAncestry", contentTypeAncestry);
        return ctx;
    }
}

⌨️ 快捷键说明

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