Java tutorial
/* * Copyright (C) 2010---2014 (wuweixing)<349446658@qq.com> * * This file is part of Wabacus * * Wabacus is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.wabacus.config.component; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.wabacus.config.Config; import com.wabacus.config.component.application.IApplicationConfigBean; import com.wabacus.config.component.application.report.AbsConfigBean; import com.wabacus.config.component.application.report.ConditionBean; import com.wabacus.config.component.application.report.ReportBean; import com.wabacus.config.component.container.AbsContainerConfigBean; import com.wabacus.config.component.container.page.PageBean; import com.wabacus.config.other.ButtonsBean; import com.wabacus.config.template.TemplateBean; import com.wabacus.config.template.TemplateParser; import com.wabacus.exception.WabacusConfigLoadingException; import com.wabacus.exception.WabacusRuntimeException; import com.wabacus.system.buttons.AbsButtonType; import com.wabacus.util.Tools; public class ComponentConfigLoadAssistant { private final static Log log = LogFactory.getLog(ComponentConfigLoadAssistant.class); private final static ComponentConfigLoadAssistant instance = new ComponentConfigLoadAssistant(); private ComponentConfigLoadAssistant() { } public static ComponentConfigLoadAssistant getInstance() { return instance; } public void checkAndAddButtons(ReportBean reportbean, Class buttonType, String defaultkey) { ButtonsBean bbeans = reportbean.getButtonsBean(); if (bbeans == null) { bbeans = new ButtonsBean(reportbean); reportbean.setButtonsBean(bbeans); } List<AbsButtonType> lstButtons = bbeans.getAllCertainTypeButtonsList(buttonType); if ((lstButtons == null || lstButtons.size() == 0) && defaultkey != null && !defaultkey.trim().equals("")) { AbsButtonType buttonObj = Config.getInstance().getResourceButton(null, reportbean, defaultkey, buttonType); buttonObj.setDefaultNameIfNoName(); ComponentConfigLoadManager.addButtonToPositions(reportbean, buttonObj); } } public String createComponentRefreshGuidByRefreshId(PageBean pbean, String componentId, String refreshid) { IComponentConfigBean ccbean = pbean.getChildComponentBean(componentId, true); if (ccbean == null) throw new WabacusRuntimeException( "?" + pbean.getId() + "?id" + componentId + ""); if (refreshid == null || refreshid.trim().equals("")) refreshid = componentId; String refreshGuid = null; if (refreshid.equals(pbean.getId())) { refreshGuid = pbean.getGuid(); } else if (refreshid.equals(componentId)) { refreshGuid = ccbean.getGuid(); } else { IComponentConfigBean refreshContainerObj = pbean.getChildComponentBean(refreshid, true);//? if (!(refreshContainerObj instanceof AbsContainerConfigBean)) { throw new WabacusRuntimeException( "?" + ccbean.getGuid() + "refreshGuidrefreshid" + refreshid + "??ID?ID"); } refreshGuid = ((AbsContainerConfigBean) refreshContainerObj).getChildRefreshGuid(componentId); } return refreshGuid; } public void validateApplicationRefreshid(IApplicationConfigBean applicationBean) { if (applicationBean.getRefreshid() == null || applicationBean.getRefreshid().trim().equals("")) return; if (applicationBean.getRefreshid().trim().equals(applicationBean.getId())) return; IComponentConfigBean refreshComponentBean = null; if (applicationBean.getPageBean().getId().equals(applicationBean.getRefreshid())) { refreshComponentBean = applicationBean.getPageBean(); } else { refreshComponentBean = applicationBean.getPageBean() .getChildComponentBean(applicationBean.getRefreshid(), true); } if (refreshComponentBean == null) { throw new WabacusConfigLoadingException(applicationBean.getPath() + "refreshid" + applicationBean.getRefreshid() + "?"); } if (!(refreshComponentBean instanceof AbsContainerConfigBean)) { throw new WabacusConfigLoadingException(applicationBean.getPath() + "refreshid" + applicationBean.getRefreshid() + "???"); } if (((AbsContainerConfigBean) refreshComponentBean).getChildComponentBean(applicationBean.getId(), true) == null) { throw new WabacusConfigLoadingException(applicationBean.getPath() + "refreshid" + applicationBean.getRefreshid() + "??"); } } public boolean isStaticTemplateResource(String template) { if (Tools.isDefineKey("classpath", template)) return true; if (Tools.isDefineKey("$", template)) return true; if (Tools.isDefineKey("absolute", template)) return true; if (Tools.isDefineKey("relative", template)) return true; return false; } public TemplateBean getStaticTemplateBeanByConfig(PageBean pbean, String template) { TemplateBean tplBean = null; template = template == null ? "" : template.trim(); if (Tools.isDefineKey("$", template)) { tplBean = (TemplateBean) Config.getInstance().getResourceObject(null, pbean, template, true); } else {//?html/htm? tplBean = Config.getInstance().getFileTemplate(template); if (tplBean == null) { tplBean = TemplateParser.parseTemplateByPath(template); if (tplBean != null) Config.getInstance().addFileTemplate(template, tplBean); } } return tplBean; } public Object[] parseIncludeApplicationids(IComponentConfigBean ccbeanOwner, List<String> lstConfigApplicationids) { if (ccbeanOwner instanceof AbsContainerConfigBean) { if (lstConfigApplicationids == null || lstConfigApplicationids.size() == 0) {//?include??ID lstConfigApplicationids = ((AbsContainerConfigBean) ccbeanOwner).getLstAllChildApplicationIds(true); } } else if (lstConfigApplicationids == null || lstConfigApplicationids.size() == 0) { lstConfigApplicationids = new ArrayList<String>(); lstConfigApplicationids.add(ccbeanOwner.getId()); } StringBuffer appidsBuf = new StringBuffer(); List<String> lstAppids = new ArrayList<String>(); Map<String, Integer> mReportidsAndPagesize = new HashMap<String, Integer>(); for (String appidTmp : lstConfigApplicationids) { if (appidTmp == null || appidTmp.trim().equals("") || lstAppids.contains(appidTmp.trim())) continue; appidTmp = appidTmp.trim(); int idxLeft = appidTmp.indexOf("{"); int idxRight = appidTmp.indexOf("}"); int ipagesize = Integer.MIN_VALUE; if (idxLeft > 0 && idxRight == appidTmp.length() - 1) { String pagesize = appidTmp.substring(idxLeft + 1, idxRight).trim(); appidTmp = appidTmp.substring(0, idxLeft).trim(); if (appidTmp.equals("")) continue; if (!pagesize.equals("")) ipagesize = Integer.parseInt(pagesize); } ReportBean rbean = ccbeanOwner.getPageBean().getReportChild(appidTmp, true); if (rbean != null) mReportidsAndPagesize.put(appidTmp, ipagesize);//? if (ccbeanOwner.getPageBean().getApplicationChild(appidTmp, true) == null) { throw new WabacusConfigLoadingException("" + ccbeanOwner.getPath() + "??include?ID" + appidTmp + "?"); } lstAppids.add(appidTmp); appidsBuf.append(appidTmp + ";"); } // {//includeid // mReportidsAndPagesize.put(ccbeanOwner.getId(),Integer.MIN_VALUE);// return new Object[] { appidsBuf.toString(), lstAppids, mReportidsAndPagesize }; } public List<ConditionBean> cloneLstConditionBeans(AbsConfigBean parent, List<ConditionBean> lstConditions) { if (lstConditions == null) return null; List<ConditionBean> lstConNew = new ArrayList<ConditionBean>(); for (ConditionBean cbTmp : lstConditions) { lstConNew.add((ConditionBean) cbTmp.clone(parent)); } return lstConNew; } }