Esempio n. 1
0
  /**
   * 把模板保存至模板库
   *
   * @return
   */
  @SuppressWarnings("unchecked")
  public void saveAsTemplateLib(Map map) throws BusinessServiceException {
    try {
      if (!map.isEmpty()) {
        CmsTemplateLib lib = (CmsTemplateLib) map.get("cmsTemplateLib");
        CmsTemplate template = (CmsTemplate) map.get("cmsTemplate");
        // 保存模板库信息
        preparedTemplateDao.insertCmsTemplateLib(lib);
        // 保存模板信息
        preparedTemplateDao.insertCmsTemplate(template);
        // 保存参数信息
        for (Iterator iterator = template.getCmsTplDts().iterator(); iterator.hasNext(); ) {
          CmsTplDt cmsTplDt = (CmsTplDt) iterator.next();
          preparedTemplateDao.insertTemplateDatatags(cmsTplDt);
        }
      }

    } catch (FrameworkDAOException e) {
      throw new BusinessServiceException("数据库操作异常!", e);
    }
  }
Esempio n. 2
0
  /**
   * 把模板保存至模板库
   *
   * @return
   */
  @SuppressWarnings("unchecked")
  @Transactional(rollbackFor = {RuntimeException.class, Exception.class})
  public void saveAsTemplateLibDeal(Map paramMap) throws BusinessServiceException {
    PageTemplateInfo pageTemplateInfo = (PageTemplateInfo) paramMap.get("pageTemplateInfo");
    String currentUser = (String) paramMap.get("currentUser");
    Date date = new Date();

    // 查询当前模板信息及参数信息
    CmsSiteTpl cmsSiteTpl = findTplByTemplateId(pageTemplateInfo.getTemplateId());

    PreparedTemplateManageBo preparedTemplateManageBo =
        SpringBeanUtil.getBean("preparedTemplateManageBo");

    if (preparedTemplateManageBo.queryTemplateByKey(cmsSiteTpl.getTemplateKey()) == null) {
      List<CmsSiteTplDt> list = queryTemplateDatatags(cmsSiteTpl.getTemplateId());

      // 复制模板库内容
      CmsTemplateLib lib = new CmsTemplateLib();
      lib.setCreatedBy(currentUser);
      lib.setCreatedDate(date);
      lib.setUpdateBy(currentUser);
      lib.setUpdateDate(date);
      lib.setLibDescription(cmsSiteTpl.getCmsSite().getSiteName());
      lib.setLibName(cmsSiteTpl.getCmsSite().getSiteName());

      // 复制模板内容
      CmsTemplate template = new CmsTemplate();
      template.setCmsTemplateLib(lib);
      template.setCreatedBy(currentUser);
      template.setCreatedDate(date);
      template.setUpdateBy(currentUser);
      template.setUpdateDate(date);
      template.setDescription(cmsSiteTpl.getDescription());
      template.setPath(cmsSiteTpl.getPath());
      template.setTargetFile(cmsSiteTpl.getTargetFile());
      template.setTemplateFile(cmsSiteTpl.getTemplateFile());
      template.setTemplateKey(cmsSiteTpl.getTemplateKey());
      template.setTemplateName(cmsSiteTpl.getTemplateName());
      // 模板文件保存到文件系统中
      // url = systemConfigBo.getSysParam().getTemplatepath() + url;
      // template.setTemplateContent(FileOperationUtils.readFile(url));

      // 复制模板参数
      for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {
        CmsSiteTplDt cmsSiteTplDt = (CmsSiteTplDt) iterator.next();
        // 新建模板对象
        CmsTplDt cmsTplDt = new CmsTplDt();
        cmsTplDt.setCreatedBy(currentUser);
        cmsTplDt.setCreatedDate(date);
        cmsTplDt.setUpdateBy(currentUser);
        cmsTplDt.setUpdateDate(date);
        cmsTplDt.setDatatagId(cmsSiteTplDt.getDatatagId());
        cmsTplDt.setDatatagKey(cmsSiteTplDt.getDatatagKey());
        // cmsTplDt.setTemplateKey(cmsSiteTpl.getTemplateKey());
        // //2010-08-13
        cmsTplDt.setCmsTemplate(template);

        for (Iterator iterator2 = cmsSiteTplDt.getCmsSiteTplDtparams().iterator();
            iterator2.hasNext(); ) {
          CmsSiteTplDtparam cmsSiteTplDtparam = (CmsSiteTplDtparam) iterator2.next();
          // 新建参数对象
          CmsTplDtparam cmsTplDtparam = new CmsTplDtparam();
          // cmsTplDtparam.setDatatagId(cmsSiteTplDt.getDatatagId());
          // cmsTplDtparam.setTemplateKey(cmsSiteTpl.getTemplateKey());
          // //2010-08-13
          cmsTplDtparam.setCmsTplDt(cmsTplDt);
          cmsTplDtparam.setDefaultValue(cmsSiteTplDtparam.getValue());
          cmsTplDtparam.setParamKey(cmsSiteTplDtparam.getParamKey());
          cmsTplDtparam.setParamName(cmsSiteTplDtparam.getParamName());
          // 添加到模板信息中
          cmsTplDt.getCmsTplDtparams().add(cmsTplDtparam);
        }
        template.getCmsTplDts().add(cmsTplDt);
      }

      Map map = new HashMap();
      map.put("cmsTemplateLib", lib);
      map.put("cmsTemplate", template);

      saveAsTemplateLib(map);
    } else {
      throw new BusinessServiceException("该模板已经存在模板库中!");
    }
  }