Пример #1
0
  /**
   * 添加模板数据标签
   *
   * @return
   */
  @Transactional(rollbackFor = {RuntimeException.class, Exception.class})
  public void copyDatatagToSiteTpls(CmsDatatag datatag, Integer templateId)
      throws BusinessServiceException {
    // 新建站点模板对象并赋值
    CmsSiteTplDt cmsSiteTplDt = new CmsSiteTplDt();
    cmsSiteTplDt.setCreatedBy(datatag.getCreatedBy());
    cmsSiteTplDt.setCreatedDate(datatag.getCreatedDate());
    cmsSiteTplDt.setUpdateBy(datatag.getUpdateBy());
    cmsSiteTplDt.setUpdateDate(datatag.getUpdateDate());
    cmsSiteTplDt.setDatatagId(datatag.getDatatagId());
    cmsSiteTplDt.setDatatagKey(datatag.getDatatagKey());
    cmsSiteTplDt.setDatatagName(datatag.getDatatagName());
    CmsSiteTpl siteTpl = new CmsSiteTpl();
    siteTpl.setTemplateId(templateId);
    cmsSiteTplDt.setSiteTpl(siteTpl);
    // 存储数据模板标签及参数
    for (Iterator<CmsDatatagParam> it = datatag.getDatatagParams().iterator(); it.hasNext(); ) {
      CmsDatatagParam prams = it.next();
      CmsSiteTplDtparam cmsTplParam = new CmsSiteTplDtparam();

      cmsTplParam.setSiteTplDt(cmsSiteTplDt);
      cmsTplParam.setParamKey(prams.getParamKey());
      cmsTplParam.setParamName(prams.getParamName());
      cmsSiteTplDt.getCmsSiteTplDtparams().add(cmsTplParam);
    }
    copyDatatagToSiteTpls(cmsSiteTplDt);
  }
Пример #2
0
  /**
   * 删除模板
   *
   * @return
   */
  @SuppressWarnings("unchecked")
  public String removeSiteTemplate(Map paramMap) throws BusinessServiceException {

    PageTemplateInfo pageTemplateInfo = (PageTemplateInfo) paramMap.get("pageTemplateInfo");
    String url = (String) paramMap.get("url");
    String msg = "删除模板失败";
    if (pageTemplateInfo != null) {
      CmsSiteTpl cmsSiteTpl = new CmsSiteTpl();
      cmsSiteTpl.setTemplateId(pageTemplateInfo.getTemplateId());
      removeSiteTemplate(cmsSiteTpl);
      // 删除模板文件
      SystemConfigBo systemConfigBo = SpringBeanUtil.getBean("systemConfigBo");
      url = systemConfigBo.getTemplatepath() + url;
      if (FileOperationUtils.deleteFile(url)) {
        msg = "删除文件成功!";
      }
    }
    return msg;
  }
Пример #3
0
  /**
   * 获取数据库中文件列表并进行页面数据整合
   *
   * @param path
   * @return
   * @throws BusinessServiceException
   */
  @SuppressWarnings("unchecked")
  public Map querySiteTemplates(Map paramMap) throws BusinessServiceException {
    String path = (String) paramMap.get("path");
    String siteId = (String) paramMap.get("siteId");
    String businessCode = (String) paramMap.get("businessCode");

    // 获取数据库中文件列表
    List<CmsSiteTpl> list = (List<CmsSiteTpl>) querySiteTemplates(siteId, businessCode, path);
    List<PageTemplateInfo> fileInfoList = new ArrayList<PageTemplateInfo>();
    Iterator<CmsSiteTpl> it = list.iterator();
    Map model = new HashMap();
    String tempDirectoryName = "";

    while (it.hasNext()) {
      CmsSiteTpl cmsSiteTpl = it.next();
      PageTemplateInfo pageTemplateInfo = new PageTemplateInfo();
      String filePath = cmsSiteTpl.getPath();
      // 如果为文件
      if (filePath != null && filePath.equals(path)) {
        pageTemplateInfo.setDirectory(false);
        pageTemplateInfo.setFileName(cmsSiteTpl.getTemplateFile());
        pageTemplateInfo.setImagePath(
            FileOperationUtils.getFileImagePath(
                pageTemplateInfo.isDirectory(), pageTemplateInfo.getFileName()));
        pageTemplateInfo.setFilePath(path);
        pageTemplateInfo.setTemplateKey(cmsSiteTpl.getTemplateKey());
        pageTemplateInfo.setTemplateName(cmsSiteTpl.getTemplateName());
        pageTemplateInfo.setTemplateId(cmsSiteTpl.getTemplateId());
        fileInfoList.add(pageTemplateInfo);

      } else { // 如果为文件夹
        // 获取子目录名称
        String directoryName = filePath.substring(path.length());
        int index = directoryName.indexOf("/");
        if (index > 0) {
          directoryName = directoryName.substring(0, index);
        }
        if (!tempDirectoryName.equals(directoryName)) {
          tempDirectoryName = directoryName;
          pageTemplateInfo.setDirectory(true);
          pageTemplateInfo.setFileName(directoryName);
          pageTemplateInfo.setImagePath(
              FileOperationUtils.getFileImagePath(
                  pageTemplateInfo.isDirectory(), pageTemplateInfo.getFileName()));
          pageTemplateInfo.setFilePath(path);
          pageTemplateInfo.setTemplateKey(null); // 文件夹没有对应的模板Key
          fileInfoList.add(pageTemplateInfo);
        }
      }
    }

    model.put("path", path);
    model.put("fileInfoList", fileInfoList);

    return model;
  }
Пример #4
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("该模板已经存在模板库中!");
    }
  }