Beispiel #1
0
 /**
  * 建站向导 保存站点
  *
  * @return
  */
 public String guideSite() {
   // 添加
   if (siteService.haveSourcePath(site.getSourcepath())) {
     write("<script>alert('此源文件目录已存在');history.back();</script>", "GBK");
     return null;
   }
   // 创建源文件目录
   FileUtil.mkdir(getHttpRequest().getRealPath("/") + "site/" + site.getSourcepath());
   siteService.insert(site);
   OperLogUtil.log(getLoginName(), "添加站点 " + site.getName(), getHttpRequest());
   return "guideTemplet";
 }
Beispiel #2
0
  /**
   * 编辑处理
   *
   * @return
   */
  public String editDo() {
    try {
      if (site.getName() != null) {
        site.setName(site.getName().replace("'", "‘").replace("\"", "“"));
      }
      if (site.getId() != null && site.getId().trim().length() > 0) {
        // 更新
        Site oldSite = siteService.findById(site.getId());
        // 如果原来有和现在的logo不同则删除原来的logo文件
        if (!oldLogo.equals(oldSite.getLogo())) {
          if (oldSite.getLogo() != null && oldSite.getLogo().trim().length() > 0) {
            FileUtil.del(
                getHttpRequest().getRealPath("/").replace("\\", "/") + oldSite.getLogo().trim());
          }
        } else {
          site.setLogo(oldLogo);
        }
        if (logo != null) {
          // 生成目标文件
          String root = getHttpRequest().getRealPath("/").replace("\\", "/");
          String ext = FileUtil.getExt(logoFileName).toLowerCase();
          if (!".jpg".equals(ext)
              && !".jpeg".equals(ext)
              && !".gif".equals(ext)
              && !".png".equals(ext)) {
            write(
                "<script>alert('logo只能上传jpg,jpeg,gif,png格式的图片!');history.back();</script>", "GBK");
            return null;
          }
          String id = UUID.randomUUID().toString();
          File targetFile = new File(root + "/upload/" + site.getId() + "/" + id + ext);
          File folder = new File(root + "/upload/" + site.getId() + "/");
          if (!folder.exists()) {
            folder.mkdirs();
          }
          if (!targetFile.exists()) {
            targetFile.createNewFile();
          }
          // 复制到目标文件
          FileUtil.copy(logo, targetFile);

          // 生成访问地址
          site.setLogo("/upload/" + site.getId() + "/" + id + ext);
        }
        if (site.getIndextemplet() != null
            && site.getIndextemplet().trim().length() > 0
            && !site.getIndextemplet().equals(oldSite.getIndextemplet())) {
          templet = templetService.findById(site.getIndextemplet());
          if (templet != null) {
            // 复制模板文件夹下resources文件夹到此站点
            try {
              FileUtil.copyDirectiory(
                  getHttpRequest().getRealPath("/") + "/templet/" + templet.getId() + "/resources",
                  getHttpRequest().getRealPath("/")
                      + "/site/"
                      + site.getSourcepath()
                      + "/resources");
            } catch (IOException e) {
              e.printStackTrace();
            }
          }
        }
        siteService.update(site);
        // 处理静态化调度
        init("htmlquartzService");
        if (htmlquartzService.findBySiteid(site.getId()) != null) {
          htmlquartzService.update(htmlquartz);
        } else {
          htmlquartz.setSiteid(site.getId());
          htmlquartzService.insert(htmlquartz);
        }
        siteService.updateHtmlSiteJob(getServletContext(), site, htmlquartz);
        OperLogUtil.log(getLoginName(), "更新站点 " + site.getName(), getHttpRequest());
      } else {
        // 添加
        if (siteService.haveSourcePath(site.getSourcepath())) {
          write("<script>alert('此源文件目录已存在');history.back();</script>", "GBK");
          return null;
        }
        if (logo != null) {
          // 生成目标文件
          String root = getHttpRequest().getRealPath("/").replace("\\", "/");
          String ext = FileUtil.getExt(logoFileName).toLowerCase();
          if (!".jpg".equals(ext)
              && !".jpeg".equals(ext)
              && !".gif".equals(ext)
              && !".png".equals(ext)) {
            write(
                "<script>alert('logo只能上传jpg,jpeg,gif,png格式的图片!');history.back();</script>", "GBK");
            return null;
          }
          String id = UUID.randomUUID().toString();
          File targetFile = new File(root + "/upload/" + site.getId() + "/" + id + ext);
          File folder = new File(root + "/upload/" + site.getId() + "/");
          if (!folder.exists()) {
            folder.mkdirs();
          }
          if (!targetFile.exists()) {
            targetFile.createNewFile();
          }
          // 复制到目标文件
          FileUtil.copy(logo, targetFile);
          // 生成访问地址
          site.setLogo("/upload/" + site.getId() + "/" + id + ext);
        }
        // 创建源文件目录
        FileUtil.mkdir(getHttpRequest().getRealPath("/") + "site/" + site.getSourcepath());
        boolean isinit = false;
        if (site.getIndextemplet() != null && site.getIndextemplet().trim().length() > 0) {
          templet = templetService.findById(site.getIndextemplet());
          if (templet != null) {
            // 复制模板文件夹下resources文件夹到此站点
            try {
              FileUtil.copyDirectiory(
                  getHttpRequest().getRealPath("/") + "/templet/" + templet.getId() + "/resources",
                  getHttpRequest().getRealPath("/")
                      + "/site/"
                      + site.getSourcepath()
                      + "/resources");
              // 判断模板是否有初始化数据
              init("templetChannelService");
              if (templetChannelService.count(templet.getId()) > 0) {
                isinit = true;
              } else {
                init("templetLinkService");
                if (templetLinkService.count(templet.getId()) > 0) {
                  isinit = true;
                }
              }
            } catch (IOException e) {
              e.printStackTrace();
            }
          }
        }
        siteService.insert(site);
        // 处理静态化调度
        init("htmlquartzService");
        htmlquartz.setSiteid(site.getId());
        htmlquartzService.insert(htmlquartz);
        siteService.updateHtmlSiteJob(getServletContext(), site, htmlquartz);
        OperLogUtil.log(getLoginName(), "添加站点 " + site.getName(), getHttpRequest());
        if (isinit) {
          return "init";
        }
      }
      write(
          "<script>alert('操作成功');location.href='site_edit.do?site.id="
              + site.getId()
              + "';</script>",
          "GBK");
    } catch (Exception e) {
      DBProException(e);
      write(e.toString(), "GBK");
    }

    return null;
  }