Package org.xdams.page.upload.bean

Examples of org.xdams.page.upload.bean.UploadCommandLine


        uploadBean.setCompositionReplaceName(theXMLConfUpload.valoreNodo(prefixUpload + "[" + (i + 1) + "]" + "/compositionReplaceName/text()"));
        uploadBean.setAssociatePathDir(theXMLConfUpload.valoreNodo(prefixUpload + "[" + (i + 1) + "]" + "/associatePathDir/text()"));
       
        int countCommand = theXMLConfUpload.contaNodi(prefixUpload + "[" + (i + 1) + "]" + "/commandList/command");
        for (int j = 0; j < countCommand; j++) {
          UploadCommandLine commandLine = new UploadCommandLine();
          commandLine.setCommandLine(theXMLConfUpload.valoreNodo(prefixUpload + "[" + (i + 1) + "]" + "/commandList/command[" + (j + 1) + "]/commandLine/text()"));
          commandLine.setUploadTempPath(theXMLConfUpload.valoreNodo(prefixUpload + "[" + (i + 1) + "]" + "/commandList/command[" + (j + 1) + "]/uploadTempPath/text()"));
          commandLine.setUploadMode(theXMLConfUpload.valoreNodo(prefixUpload + "[" + (i + 1) + "]" + "/commandList/command[" + (j + 1) + "]/uploadMode/text()"));
          commandLine.setUploadPath(theXMLConfUpload.valoreNodo(prefixUpload + "[" + (i + 1) + "]" + "/commandList/command[" + (j + 1) + "]/uploadPath/text()"));
          if (commandLine.getUploadPath().toLowerCase().contains("webapp")) {
            Map<String, String> valuesMap = new HashMap<String, String>();
            valuesMap.put("webApp", (String) modelMap.get("realPath"));
            StrSubstitutor strSubstitutor = new StrSubstitutor(valuesMap);
            commandLine.setUploadPath(strSubstitutor.replace(commandLine.getUploadPath()));
          }
          commandLine.setUploadNameDir(theXMLConfUpload.valoreNodo(prefixUpload + "[" + (i + 1) + "]" + "/commandList/command[" + (j + 1) + "]/uploadNameDir/text()"));
          uploadBean.getCommandLine().add(commandLine);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here


      System.out.println(uploadBean);
      // da prendere dentro workflowBean
      String archiveName = workFlowBean.getAlias();
      String domainName = userBean.getAccountRef();
      for (int i = 0; i < uploadBean.getCommandLine().size(); i++) {
        UploadCommandLine uploadCommandLine = uploadBean.getCommandLine().get(i);
        try {
          File fileUploadTempPath = new File(uploadCommandLine.getUploadTempPath());
          if (!(fileUploadTempPath.exists())) {
            fileUploadTempPath.mkdirs();
          }
          File uploadFile = new File(uploadCommandLine.getUploadTempPath() + System.getProperty("file.separator") + CommonUtils.stripPunctuation(FilenameUtils.getBaseName(uploadBean.getName()), '-') + "." + FilenameUtils.getExtension(uploadBean.getName()));

          uploadFile.setReadable(true);
          if (!uploadFile.exists()) {
            uploadBean.getFiledata().transferTo(uploadFile);
          }
        } catch (Exception e) {
          uploadBean.getResultError().append("errore nel copia nella cartella temporanea: " + e.getMessage());
          throw e;
        }

        String numFile = "0001";
        StringBuilder uploadPath = null;
        try {
          // controlli su filesystem se esiste la radice getUploadPath e la sua composizione
          uploadPath = new StringBuilder(uploadCommandLine.getUploadPath().trim());
          if (!uploadPath.toString().endsWith(System.getProperty("file.separator"))) {
            uploadPath.append(System.getProperty("file.separator"));
          }

          uploadPath.append(domainName);
          uploadPath.append(System.getProperty("file.separator"));
          uploadPath.append(archiveName);
          uploadPath.append(System.getProperty("file.separator"));
          uploadPath.append(uploadCommandLine.getUploadNameDir());
          uploadPath.append(System.getProperty("file.separator"));
          // tolgo la punteggiatura
          uploadBean.setIdRecord(CompositionRule.stripPunctuation(uploadBean.getIdRecord(), '\u0000'));
          if (uploadBean.getRenameFile().equalsIgnoreCase("true")) {
            uploadPath.append(CompositionRule.compose(uploadBean.getCompositionRuleDir(), uploadBean.getIdRecord(), System.getProperty("file.separator")));
          }
          File fileUploadPath = new File(uploadPath.toString());
          System.out.println(uploadPath);
          if (!(fileUploadPath.exists())) {
            fileUploadPath.mkdirs();
          } else {
            if (fileUploadPath.listFiles().length == 0) {
              numFile = StringUtils.leftPad("1", 4, "0");
            } else {
              numFile = StringUtils.leftPad("" + (fileUploadPath.listFiles().length + 1), 4, "0");
            }
          }
          if (uploadBean.getRenameFile().equalsIgnoreCase("true") && !uploadBean.getCompositionReplaceName().trim().equals("")) {
            uploadBean.setIdRecord(uploadBean.getIdRecord().replaceAll(uploadBean.getCompositionReplaceName(), ""));
          }
          if (uploadBean.getRenameFile().equalsIgnoreCase("true")) {
            uploadPath.append(CompositionRule.compose(uploadBean.getCompositionRuleFile(), uploadBean.getIdRecord(), "."));
            uploadPath.append(numFile);
            uploadPath.append(".");
            uploadPath.append(org.apache.commons.io.FilenameUtils.getExtension(uploadBean.getName()));
          } else {
            uploadPath.append(uploadBean.getName());
          }

        } catch (Exception e1) {
          throw e1;
        }
        System.out.println("UploadCommand.execute() uploadPath.toString() " + uploadPath.toString());

        // verifico se devo lanciare un comando oppure no
        if (!uploadCommandLine.getCommandLine().trim().equals("") && uploadBean.getUploadType().equalsIgnoreCase("resize")) {
          Map<String, String> valuesMap = new HashMap<String, String>();

          if (CommonUtils.isWindows()) {
            valuesMap.put("imgIn", "\"" + uploadCommandLine.getUploadTempPath() + System.getProperty("file.separator") + CommonUtils.stripPunctuation(FilenameUtils.getBaseName(uploadBean.getName()), '-') + "." + FilenameUtils.getExtension(uploadBean.getName()) + "\"");
            valuesMap.put("imgOut", "\"" + uploadPath.toString() + "\"");
          } else {
            System.out.println("quiiiiiiiii");
            valuesMap.put("imgIn", (uploadCommandLine.getUploadTempPath() + System.getProperty("file.separator") + CommonUtils.stripPunctuation(FilenameUtils.getBaseName(uploadBean.getName()), '-') + "." + FilenameUtils.getExtension(uploadBean.getName())));
            System.out.println("spazi linux" + (uploadCommandLine.getUploadTempPath() + System.getProperty("file.separator") + CommonUtils.stripPunctuation(FilenameUtils.getBaseName(uploadBean.getName()), '-') + "." + FilenameUtils.getExtension(uploadBean.getName())));
            valuesMap.put("imgOut", (uploadPath.toString()));
          }
          StrSubstitutor strSubstitutor = new StrSubstitutor(valuesMap);
          String cmd = strSubstitutor.replace(uploadCommandLine.getCommandLine());
          System.out.println(cmd);
          try {
            Runtime runtime = Runtime.getRuntime();
            Process process = runtime.exec(cmd);
            process.waitFor();
            if (process.exitValue() != 0) {
              InputStream lsOut = process.getErrorStream();
              InputStreamReader r = new InputStreamReader(lsOut);
              BufferedReader in = new BufferedReader(r);
              String line;
              int maxLine = 0;
              while ((line = in.readLine()) != null && maxLine < 10) {
                uploadBean.getResultError().append(line);
                maxLine++;
              }
              in.close();
              r.close();
              lsOut.close();
              System.out.println(uploadBean.getResultError());
            } else {
              String resultName = StringUtils.remove(uploadPath.toString(), uploadCommandLine.getUploadPath());
              resultName = StringUtils.remove(resultName, archiveName);
              // resultName = StringUtils.remove(resultName, domainName);
              resultName = StringUtils.replaceOnce(resultName, domainName, "");
              resultName = StringUtils.remove(resultName, uploadCommandLine.getUploadNameDir());
              resultName = resultName.replaceAll("\\\\", "/");
              resultName = resultName.replaceAll("[/]*(.*)", "/$1");
              if (resultName.endsWith("/")) {
                try {
                  resultName = resultName.substring(0, resultName.length() - 1);
                } catch (Exception e) {
                  uploadBean.getResultError().append(e.getMessage());
                }
              }
              uploadBean.setResult(new StringBuilder(resultName));
              System.out.println("uploadPath resize: " + resultName);
            }
          } catch (Exception e) {
            uploadBean.getResultError().append("errore nel processo di conversione file: " + e.getMessage());
          }
        } else {
          try {
            FileUtils.copyFile(new File(uploadCommandLine.getUploadTempPath() + System.getProperty("file.separator") + CommonUtils.stripPunctuation(FilenameUtils.getBaseName(uploadBean.getName()), '-') + "." + FilenameUtils.getExtension(uploadBean.getName())), new File(uploadPath.toString()));
            System.out.println("uploadPath.toString() " + uploadPath.toString());
            String resultName = StringUtils.remove(uploadPath.toString(), uploadCommandLine.getUploadPath());
            resultName = StringUtils.remove(resultName, archiveName);
            // resultName = StringUtils.remove(resultName, domainName);
            resultName = StringUtils.replaceOnce(resultName, domainName, "");
            resultName = StringUtils.remove(resultName, uploadCommandLine.getUploadNameDir());
            resultName = resultName.replaceAll("\\\\", "/");
            resultName = resultName.replaceAll("[/]*(.*)", "/$1");
            if (resultName.endsWith("/")) {
              try {
                resultName = resultName.substring(0, resultName.length() - 1);
View Full Code Here

TOP

Related Classes of org.xdams.page.upload.bean.UploadCommandLine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.