示例#1
0
 /**
  * 同步模板资源
  *
  * @return
  */
 public String syncRes() {
   if (site != null
       && site.getIndextemplet() != null
       && site.getIndextemplet().trim().length() > 0
       && site.getId() != null
       && site.getId().trim().length() > 0) {
     templet = templetService.findById(site.getIndextemplet());
     site = siteService.findById(site.getId());
     if (site != null && templet != null) {
       // 复制模板文件夹下resources文件夹到此站点
       try {
         FileUtil.copyDirectiory(
             getHttpRequest().getRealPath("/") + "/templet/" + templet.getId() + "/resources",
             getHttpRequest().getRealPath("/") + "/site/" + site.getSourcepath() + "/resources");
         write("操作成功", "UTF-8");
       } catch (IOException e) {
         e.printStackTrace();
         write("操作失败:" + e.getMessage(), "UTF-8");
       }
     } else {
       write("操作失败:没有传递正确的参数", "UTF-8");
     }
   } else {
     write("操作失败:没有传递正确的参数", "UTF-8");
   }
   return null;
 }
示例#2
0
 /**
  * 设置页面
  *
  * @return
  */
 public String config() {
   site = getManageSite();
   if (site != null) {
     // 设置模板名称
     if (site.getIndextemplet() != null && site.getIndextemplet().trim().length() > 0) {
       templet = templetService.findById(site.getIndextemplet());
       if (templet != null) {
         site.setIndextempletName(templet.getName());
       }
     }
     init("htmlquartzService");
     htmlquartz = htmlquartzService.findBySiteid(site.getId());
   }
   return "config";
 }
示例#3
0
 /**
  * 添加页面
  *
  * @return
  */
 public String edit() {
   if (site != null && site.getId() != null && site.getId().trim().length() > 0) {
     site = siteService.findById(site.getId());
     // 设置模板名称
     if (site.getIndextemplet() != null && site.getIndextemplet().trim().length() > 0) {
       templet = templetService.findById(site.getIndextemplet());
       if (templet != null) {
         site.setIndextempletName(templet.getName());
       }
     }
     init("htmlquartzService");
     htmlquartz = htmlquartzService.findBySiteid(site.getId());
   }
   return "edit";
 }
示例#4
0
 /**
  * 建站向导 初始化站点
  *
  * @return
  */
 public String guideInit() {
   try {
     if (site.getId() != null
         && site.getId().trim().length() > 0
         && site.getIndextemplet() != null
         && site.getIndextemplet().trim().length() > 0) {
       site = siteService.findById(site.getId());
       templet = templetService.findById(site.getIndextemplet());
       if (site != null && templet != null) {
         init("templetChannelService");
         templetChannelService.importSiteChannels(templet, site);
         init("templetLinkService");
         templetLinkService.importSiteLinks(templet, site);
       }
     }
     return guideCompleted();
   } catch (Exception e) {
     e.printStackTrace();
     showMessage = "站点初始化失败:" + e.getMessage();
     return showMessage(showMessage, forwardUrl, forwardSeconds);
   }
 }
示例#5
0
  /**
   * 设置页面处理
   *
   * @return
   */
  public String configDo() {
    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("/") + oldSite.getLogo().trim());
          }
        } else {
          site.setLogo(oldLogo);
        }
        if (logo != null) {
          // 生成目标文件
          String root = getHttpRequest().getRealPath("/");
          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);
        getHttpSession().setAttribute("manageSite", site);
        OperLogUtil.log(getLoginName(), "站点设置 " + site.getName(), getHttpRequest());
      }
      write(
          "<script>alert('操作成功');location.href='site_config.do?pageFuncId="
              + pageFuncId
              + "';</script>",
          "GBK");
    } catch (Exception e) {
      DBProException(e);
      write(e.toString(), "GBK");
    }

    return null;
  }
示例#6
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;
  }
示例#7
0
 /**
  * 建站向导 选择模板
  *
  * @return
  */
 public String guideTemplet() {
   if (site != null && StringUtils.isNotEmpty(site.getId())) {
     site = siteService.findById(site.getId());
     if (site != null) {
       if ("0".equals(type)) {
         // 选择模板
         site.setIndextemplet(templet.getId());
       } else {
         // 创建新模板
         init("templetService");
         templet.setState("1");
         templet.setAdduser(getLoginAdmin().getId());
         site.setIndextemplet(templetService.add(templet));
         String realPath = getHttpRequest().getRealPath("/");
         try {
           FileUtil.copyDirectiory(
               realPath + "/templet/default", realPath + "/templet/" + templet.getId());
         } catch (IOException e) {
           e.printStackTrace();
           showMessage = e.getMessage();
           return showMessage(showMessage, forwardUrl, forwardSeconds);
         }
       }
       // 创建源文件目录
       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.update(site);
       OperLogUtil.log(getLoginName(), "添加站点 " + site.getName(), getHttpRequest());
       if (isinit) {
         return "guideInit";
       }
       return guideCompleted();
     } else {
       showMessage = "没有找到此站点";
       return showMessage(showMessage, forwardUrl, forwardSeconds);
     }
   } else {
     showMessage = "没有传递站点id参数";
     return showMessage(showMessage, forwardUrl, forwardSeconds);
   }
 }