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; }
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; }