예제 #1
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;
  }
예제 #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("该模板已经存在模板库中!");
    }
  }