Ejemplo n.º 1
0
 private static boolean renameZipShp(String userName, InfoPreview infoPreview, String tempUserDir)
     throws ResourceNotFoundFault {
   String tempUserZipDir = PublishUtility.createDir(tempUserDir + PublishUtility.ZIP_DIR_NAME);
   boolean result = false;
   LayerPublishAction layerPublishAction = infoPreview.getLayerPublishAction();
   String newName = userName + "_shp_" + infoPreview.getNewName();
   if (layerPublishAction != null
       && layerPublishAction.equals(LayerPublishAction.RENAME)
       && newName != null
       && !newName.equalsIgnoreCase(infoPreview.getDataStoreName())) {
     String fileName = tempUserZipDir + infoPreview.getDataStoreName() + ".zip";
     File previousFile = new File(fileName);
     ZipFile zipSrc = null;
     String renameDirPath = tempUserZipDir + "rename" + System.getProperty("file.separator");
     try {
       PublishUtility.createDir(renameDirPath);
       logger.debug("********* ManageRename renameDirPath: " + renameDirPath);
       // Decomprime il contenuto dello zip nella cartella rename
       zipSrc = new ZipFile(previousFile);
       Enumeration<? extends ZipEntry> entries = zipSrc.entries();
       while (entries.hasMoreElements()) {
         ZipEntry entry = entries.nextElement();
         PublishUtility.extractEntryToFile(entry, zipSrc, renameDirPath);
       }
       logger.debug("********* ManageRename element unzipped");
       // Dopo l'estrazione rinominare e creare zip
       compressFiles(
           tempUserZipDir,
           renameDirPath,
           newName + ".zip",
           infoPreview.getDataStoreName(),
           newName);
       logger.debug("********* ManageRename after compress file");
       // Cancellare vecchio zip
       previousFile.delete();
       logger.debug("********* ManageRename after delete previous file");
       result = Boolean.TRUE;
     } catch (Exception e) {
       logger.error("ERRORE : " + e);
       throw new ResourceNotFoundFault(e.getMessage());
     } finally {
       try {
         zipSrc.close();
         // Cancella cartella rename
         PublishUtility.deleteDir(renameDirPath);
         logger.debug("********* ManageRename succesfully removed rename dir");
       } catch (IOException ex) {
       }
     }
     logger.debug("Shape Zip renamed: " + result);
     if (result) {
       infoPreview.setDataStoreName(newName);
     }
   }
   return result;
 }
Ejemplo n.º 2
0
  private static boolean renameTif(String userName, InfoPreview infoPreview, String tempUserDir)
      throws ResourceNotFoundFault {
    boolean result = false;
    String tempUserTifDir = PublishUtility.createDir(tempUserDir + PublishUtility.TIF_DIR_NAME);
    LayerPublishAction layerPublishAction = infoPreview.getLayerPublishAction();
    String newName = userName + "_" + infoPreview.getNewName();

    if (layerPublishAction != null
        && layerPublishAction.equals(LayerPublishAction.RENAME)
        && newName != null
        && !newName.equalsIgnoreCase(infoPreview.getDataStoreName())) {
      // Rinominare il file nuovo con il nuovo nome

    } else if (layerPublishAction != null
        && layerPublishAction.equals(LayerPublishAction.OVERRIDE)) {
      // Cancellare il vecchio file e rinominare il file nuovo con il vecchio nome
      logger.debug("renameTif in Override operation");
      String fileName = tempUserTifDir + infoPreview.getDataStoreName() + ".tif";
      File previousFile = new File(fileName);
      previousFile.delete();
      newName = infoPreview.getDataStoreName();
      logger.debug("renameTif after Override operation: " + newName);
    }
    String origName = infoPreview.getFileName();
    String fileName = tempUserTifDir + origName + ".tif";
    File previousFile = new File(fileName);
    previousFile.renameTo(new File(tempUserTifDir + newName + ".tif"));
    //
    String SLDFileName = origName + ".sld";
    File fileSLD = new File(tempUserTifDir, SLDFileName);
    if (fileSLD.exists()) {
      File filePublished = PublishUtility.copyFile(fileSLD, tempUserTifDir, newName + ".sld", true);
      fileSLD.delete();
    }
    //
    String TFWFileName = origName + ".tfw";
    File fileTFW = new File(tempUserTifDir, TFWFileName);
    if (fileTFW.exists()) {
      PublishUtility.copyFile(fileTFW, tempUserTifDir, newName + ".tfw", true);
      fileTFW.delete();
    }
    String PRJFileName = origName + ".prj";
    File filePRJ = new File(tempUserTifDir, PRJFileName);
    if (filePRJ.exists()) {
      PublishUtility.copyFile(filePRJ, tempUserTifDir, newName + ".prj", true);
      filePRJ.delete();
    }
    infoPreview.setDataStoreName(newName);
    result = Boolean.TRUE;
    logger.debug("Tif renamed: " + result);
    return result;
  }
Ejemplo n.º 3
0
  /**
   * ***************
   *
   * @param zipFileName the name of the resulting zip file
   * @param shpFileName the name of the shp file to compress
   * @return
   */
  public static ZipOutputStream compressFiles(
      String tempUserZipDir,
      String tempUserDir,
      String zipFileName,
      String origName,
      String destName) {
    ZipOutputStream out;
    try {
      out = new ZipOutputStream(new FileOutputStream(tempUserZipDir + zipFileName));
      File shpFile = new File(tempUserDir + origName + ".shp");
      File dbfFile = new File(tempUserDir + origName + ".dbf");
      File shxFile = new File(tempUserDir + origName + ".shx"); // sbn&&sbx&&CPG
      File prjFile = new File(tempUserDir + origName + ".prj");

      File shpDestFile = shpFile;
      File dbfDestFile = dbfFile;
      File shxDestFile = shxFile;
      File prjDestFile = prjFile;

      File sldFile = new File(tempUserDir + origName + ".sld");
      File sldDestFile = sldFile;
      File cpgFile = new File(tempUserDir + origName + ".cpg");
      File cpgDestFile = cpgFile;

      if (destName != null) {
        shpDestFile = new File(tempUserDir + destName + ".shp");
        shpFile.renameTo(shpDestFile);
        dbfDestFile = new File(tempUserDir + destName + ".dbf");
        dbfFile.renameTo(dbfDestFile);
        shxDestFile = new File(tempUserDir + destName + ".shx");
        shxFile.renameTo(shxDestFile);
        prjDestFile = new File(tempUserDir + destName + ".prj");
        prjFile.renameTo(prjDestFile);
        sldDestFile = new File(tempUserDir + destName + ".sld");
        sldFile.renameTo(sldDestFile);
        cpgDestFile = new File(tempUserDir + destName + ".cpg");
        cpgFile.renameTo(cpgDestFile);
      }
      out = PublishUtility.compress(out, shpDestFile);
      out = PublishUtility.compress(out, dbfDestFile);
      out = PublishUtility.compress(out, shxDestFile);
      out = PublishUtility.compress(out, prjDestFile);
      if (sldDestFile.exists()) {
        out = PublishUtility.compress(out, sldDestFile);
      }
      if (cpgDestFile.exists()) {
        out = PublishUtility.compress(out, cpgDestFile);
      }
      out.close();
    } catch (Exception ex) {
      logger.error("Exception compressing: " + zipFileName + " - " + ex);
      return null;
    }
    return out;
  }