Ejemplo n.º 1
0
 public void dealFile(String fileName, byte[] bs) {
   try {
     bs = convertCharset(bs);
   } catch (UnsupportedEncodingException e) {
     e.printStackTrace();
   }
   fileName = fileName.substring("File:".length());
   this.task.setCurrentInfo("正在导入站点文件:" + fileName);
   String root =
       Config.getContextRealPath()
           + Config.getValue("Statical.TargetDir")
           + "/"
           + this.map.getString("Alias");
   root = root + "/";
   fileName = root + fileName;
   fileName = fileName.replaceAll("[\\\\/]+", "/");
   String dirName = fileName.substring(0, fileName.lastIndexOf('/'));
   File dir = new File(dirName);
   if (!dir.exists()) {
     dir.mkdirs();
   }
   FileUtil.writeByte(fileName, bs);
 }
Ejemplo n.º 2
0
  public static Mapx getSiteInfo(String file) throws Exception {
    FileInputStream fin = null;
    try {
      fin = new FileInputStream(file);
      fin.read();
      byte[] bs = new byte[8];
      fin.read(bs);

      bs = new byte[4];
      if (!bufferRead(bs, fin)) {
        return null;
      }
      int len = NumberUtil.toInt(bs);
      byte[] bs = new byte[len];
      if (!bufferRead(bs, fin)) return null;
      int len;
      byte[] bs = new byte[4];
      if (!bufferRead(bs, fin)) {
        return null;
      }
      int len = NumberUtil.toInt(bs);
      byte[] bs = new byte[len];
      if (!bufferRead(bs, fin)) return null;
      int len;
      byte[] bs = ZipUtil.unzip(bs);
      DataTable dt = (DataTable) FileUtil.unserialize(bs);
      return dt.getDataRow(0).toCaseIgnoreMapx();
    } finally {
      if (fin != null)
        try {
          fin.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
    }
  }
Ejemplo n.º 3
0
  public boolean importSite(String poolName) {
    User.UserData user = new User.UserData();
    user.setUserName("admin");
    user.setBranchInnerCode("86");
    user.setLogin(true);
    user.setManager(true);
    User.setCurrent(user);

    this.isNewSite =
        (("0".equals(this.map.getString("ID"))) || (StringUtil.isEmpty(this.map.getString("ID"))));
    this.NoRelas = SiteTableRela.getNoRelaArray();
    this.TableRelas = SiteTableRela.getRelas();
    this.da = new DataAccess();
    FileInputStream fin = null;
    try {
      fin = new FileInputStream(this.file);
      this.da.setAutoCommit(false);
      this.ExportCharset = ((fin.read() == 1) ? "GBK" : "UTF-8");
      byte[] bs = new byte[8];
      fin.read(bs);
      this.siteID = NumberUtil.toLong(bs);
      boolean flag = true;
      int i = 0;
      while (true) {
        bs = new byte[4];
        if (!bufferRead(bs, fin)) {
          break;
        }
        int len = NumberUtil.toInt(bs);
        bs = new byte[len];
        if (!bufferRead(bs, fin)) {
          flag = false;
          break;
        }
        Object obj = FileUtil.unserialize(bs);

        bs = new byte[4];
        if (!bufferRead(bs, fin)) {
          flag = false;
          break;
        }
        len = NumberUtil.toInt(bs);
        bs = new byte[len];
        if (!bufferRead(bs, fin)) {
          flag = false;
          break;
        }
        bs = ZipUtil.unzip(bs);
        this.task.setPercent(i * 100 / 200);
        dealOneEntry(bs, obj);
        ++i;
      }
      if (flag) {
        this.da.commit();
      } else {
        LogUtil.error("读取站点导出文件时发生错误!");
        this.da.rollback();
      }
      this.da.setAutoCommit(true);
      Site.updatePrivAndFile(this.map.getString("Alias"));
      return flag;
    } catch (Exception e1) {
      e1.printStackTrace();
      try {
        this.da.rollback();
      } catch (SQLException e) {
        e.printStackTrace();
      }
      return false;
    } finally {
      try {
        this.da.setAutoCommit(true);
      } catch (Exception e) {
        e.printStackTrace();
      }
      try {
        this.da.close();
      } catch (Exception e) {
        e.printStackTrace();
      }
      try {
        fin.close();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
Ejemplo n.º 4
0
  public void dealZCSite(DataRow dr) {
    if (this.isNewSite) {
      if ((LicenseInfo.getName().equals("TrailUser"))
          && (new QueryBuilder("select count(*) from ZCSite").executeInt() >= 1)) {
        throw new RuntimeException("站点数超出限制,请联系泽元软件更换License!");
      }
      this.newSiteID = NoUtil.getMaxID("SiteID");
      ZCSiteSchema site = new ZCSiteSchema();
      site.setValue(dr);
      site.setID(this.newSiteID);
      site.setName(this.map.getString("Name"));
      site.setAlias(this.map.getString("Alias"));
      site.setURL(this.map.getString("URL"));
      site.setHitCount(0L);
      site.setChannelCount(0L);
      site.setSpecialCount(0L);
      site.setMagzineCount(0L);
      site.setArticleCount(0L);
      site.setImageLibCount(1L);
      site.setVideoLibCount(1L);
      site.setAudioLibCount(1L);
      site.setAttachmentLibCount(1L);
      site.setBranchInnerCode(User.getBranchInnerCode());
      site.setAddTime(new Date());
      site.setAddUser(User.getUserName());
      site.setConfigXML(ConfigImageLib.imageLibConfigDefault);
      this.da.insert(site);
      Transaction trans = new Transaction();
      Site.addDefaultPriv(this.newSiteID, trans);
      trans.setDataAccess(this.da);
      trans.commit(false);
      addIDMapping("ZCSite", String.valueOf(this.siteID), String.valueOf(this.newSiteID));
    } else {
      ZCSiteSchema site = new ZCSiteSchema();
      site.setID(this.map.getString("ID"));
      this.newSiteID = site.getID();
      site.fill();

      this.task.setCurrentInfo("正在备份数据,可能需要较长时间,请耐心等待");

      SiteExporter se = new SiteExporter(site.getID());
      se.exportSite(
          Config.getContextRealPath()
              + "WEB-INF/data/backup/"
              + site.getAlias()
              + "_"
              + System.currentTimeMillis()
              + ".dat");

      addIDMapping("ZCSite", dr.getString("ID"), String.valueOf(site.getID()));
      this.da.deleteAndBackup(site);
      BlockingTransaction tran = new BlockingTransaction(this.da);
      Site.delSiteRela(site.getID(), tran);

      String sitePath =
          Config.getContextRealPath()
              + Config.getValue("Statical.TemplateDir")
              + "/"
              + site.getAlias();
      FileUtil.delete(sitePath);

      site = new ZCSiteSchema();
      site.setValue(dr);

      this.da.insert(site);
    }
  }
Ejemplo n.º 5
0
 public void dealOneEntry(byte[] bs, Object obj) throws Exception {
   if ((bs == null) || (obj == null)) {
     return;
   }
   if (obj instanceof String) {
     String name = obj.toString();
     if (name.startsWith("File:")) {
       dealFile(name, bs);
     } else if (name.startsWith("CustomTable:")) {
       name = name.substring("CustomTable:".length());
       this.task.setCurrentInfo("正在导入自定义表:" + name);
       DataTable dt = (DataTable) FileUtil.unserialize(bs);
       try {
         if (!this.customTableMap.containsKey(name)) {
           QueryBuilder qb =
               new QueryBuilder(
                   "select * from ZCCustomTableColumn where exists (select ID from ZCCustomTable where SiteID=? and Code=? and Type='Custom' and ZCCustomTableColumn.TableID=ID)",
                   this.newSiteID,
                   name);
           DataTable cdt = this.da.executeDataTable(qb);
           SchemaColumn[] scs = new SchemaColumn[cdt.getRowCount()];
           for (int j = 0; j < scs.length; ++j) {
             DataRow cdr = cdt.getDataRow(j);
             int type = Integer.parseInt(cdr.getString("DataType"));
             SchemaColumn sc =
                 new SchemaColumn(
                     cdr.getString("Code"),
                     type,
                     j,
                     cdr.getInt("Length"),
                     0,
                     "Y".equals(cdr.getString("isMandatory")),
                     "Y".equals(cdr.getString("isPrimaryKey")));
             scs[j] = sc;
           }
           TableCreator tc = new TableCreator(this.da.getConnection().getDBConfig().DBType);
           tc.createTable(scs, name, true);
           tc.executeAndClear(this.da.getConnection());
           this.customTableMap.put(name, "");
           StringBuffer sb = new StringBuffer("insert into " + name + "(");
           for (int j = 0; j < cdt.getRowCount(); ++j) {
             if (j != 0) {
               sb.append(",");
             }
             sb.append(cdt.get(j, "Code"));
           }
           sb.append(") values (");
           for (int j = 0; j < cdt.getRowCount(); ++j) {
             if (j != 0) {
               sb.append(",");
             }
             sb.append("?");
           }
           sb.append(")");
           this.insertQB = new QueryBuilder(sb.toString());
           this.insertQB.setBatchMode(true);
         }
         dealCustomTable(dt, this.insertQB);
       } catch (Exception e) {
         LogUtil.warn("未成功导入表" + name);
         e.printStackTrace();
       }
     } else {
       dealSiteIDTable(name, (DataTable) FileUtil.unserialize(bs));
     }
   } else {
     dealRelaTable((SiteTableRela.TableRela) obj, (DataTable) FileUtil.unserialize(bs));
   }
 }