public TBXSynchronousOperation createWPSSyncOperation(File newServicePath, String processingName)
      throws Exception {
    TBXSynchronousOperation operationShellDescr = WPSOperation.newWPSSyncOperation(processingName);
    FileInputStream topStream, bottomStream;
    SequenceInputStream seqStream;
    /*Vector<InputStream> streams;
    topStream=new FileInputStream(new File(newServicePath,EXECUTE_ENVIRONMENT_TXT_FILE_TOP));
    bottomStream=new FileInputStream(new File(newServicePath,EXECUTE_ENVIRONMENT_TXT_FILE_BOTTOM));
    streams=new Vector<InputStream>();
    streams.add(topStream);*/
    File shellScriptFolder = new File(newServicePath, SHELL_SCRIPT_PATH);
    shellScriptFolder.mkdirs();
    IOUtil.copy(
        shellStream,
        new FileOutputStream(
            new File(
                shellScriptFolder, SHELL_SCRIPT_FILE_PREFIX + processingName + "_original.sh")));
    /*streams.add(new FileInputStream(new File(shellScriptFolder,SHELL_SCRIPT_FILE_PREFIX+processingName+"_original.sh")));
    String shellOutpManager=IOUtil.inputToString(new FileInputStream(new File(newServicePath,SHELL_SCRIPT_PATH+"/"+SHELL_SCRIPT_FILE_PREFIX+processingName+"_outputManager.tmp")));
    shellOutpManager=shellOutpManager.replaceAll("<", "&lt;");
    shellOutpManager=shellOutpManager.replaceAll(">", "&gt;");
    shellOutpManager=shellOutpManager.replaceAll("&", "&amp;");
    streams.add(new ByteArrayInputStream(shellOutpManager.getBytes()));
    streams.add(bottomStream);

    seqStream=new SequenceInputStream(streams.elements());
    String shellScript=IOUtil.inputToString(seqStream);
    FileOutputStream shellScriptOutputStream=new FileOutputStream(new File(newServicePath,EXECUTE_ENVIRONMENT_XSL_FILE_PATH));
    shellScriptOutputStream.write(shellScript.getBytes());
    shellScriptOutputStream.close();*/

    String shellOutpManager =
        IOUtil.loadString(
            new File(
                newServicePath,
                SHELL_SCRIPT_PATH
                    + "/"
                    + SHELL_SCRIPT_FILE_PREFIX
                    + processingName
                    + "_outputManager.tmp"));
    String shellProcessScript =
        IOUtil.inputToString(
                new FileInputStream(
                    new File(
                        shellScriptFolder,
                        SHELL_SCRIPT_FILE_PREFIX + processingName + "_original.sh")))
            + shellOutpManager;
    FileOutputStream shellScriptOutputStream =
        new FileOutputStream(
            new File(newServicePath, getScriptPathforProcessingName(processingName)));
    shellScriptOutputStream.write(shellProcessScript.getBytes());
    shellScriptOutputStream.close();

    operationShellDescr.setScripts(
        getExecuteScriptDescriptorSync(newServicePath, EXECUTE_OPERATION_PREFIX + processingName));
    operationShellDescr.setAdmittedHosts("");
    return operationShellDescr;
  }
  public void updateScriptEngine(File newServicePath, String processingName, Object script)
      throws Exception {
    FileInputStream topStream, bottomStream;
    SequenceInputStream seqStream;
    shellStream = (InputStream) script;
    /*Vector<InputStream> streams;
    topStream=new FileInputStream(new File(newServicePath,EXECUTE_ENVIRONMENT_TXT_FILE_TOP));
    bottomStream=new FileInputStream(new File(newServicePath,EXECUTE_ENVIRONMENT_TXT_FILE_BOTTOM));
    streams=new Vector<InputStream>();
    streams.add(topStream);*/
    File shellScriptFolder = new File(newServicePath, SHELL_SCRIPT_PATH);
    shellScriptFolder.mkdirs();
    IOUtil.copy(
        shellStream,
        new FileOutputStream(
            new File(
                shellScriptFolder, SHELL_SCRIPT_FILE_PREFIX + processingName + "_original.sh")));
    // streams.add(new FileInputStream(new
    // File(shellScriptFolder,SHELL_SCRIPT_FILE_PREFIX+processingName+"_original.sh")));
    /*String shellOutpManager=IOUtil.inputToString(new FileInputStream(new File(newServicePath,SHELL_SCRIPT_PATH+"/"+SHELL_SCRIPT_FILE_PREFIX+processingName+"_outputManager.tmp")));
    shellOutpManager=shellOutpManager.replaceAll("<", "&lt;");
    shellOutpManager=shellOutpManager.replaceAll(">", "&gt;");
    shellOutpManager=shellOutpManager.replaceAll("&", "&amp;");
    streams.add(new ByteArrayInputStream(shellOutpManager.getBytes()));
    streams.add(bottomStream);

    seqStream=new SequenceInputStream(streams.elements());
    String shellScript=IOUtil.inputToString(seqStream);
    FileOutputStream shellScriptOutputStream=new FileOutputStream(new File(newServicePath,EXECUTE_ENVIRONMENT_XSL_FILE_PATH));
    shellScriptOutputStream.write(shellScript.getBytes());
    shellScriptOutputStream.close();*/

    String shellOutpManager =
        IOUtil.loadString(
            new File(
                newServicePath,
                SHELL_SCRIPT_PATH
                    + "/"
                    + SHELL_SCRIPT_FILE_PREFIX
                    + processingName
                    + "_outputManager.tmp"));
    String shellProcessScript =
        IOUtil.inputToString(
                new FileInputStream(
                    new File(
                        shellScriptFolder,
                        SHELL_SCRIPT_FILE_PREFIX + processingName + "_original.sh")))
            + shellOutpManager;
    FileOutputStream shellScriptOutputStream =
        new FileOutputStream(
            new File(newServicePath, getScriptPathforProcessingName(processingName)));
    shellScriptOutputStream.write(shellProcessScript.getBytes());
    shellScriptOutputStream.close();
  }
  @Override
  public Result execute(ChainContext cc) {
    try {
      StoreItem storeItem = (StoreItem) cc.getAttribute(CommandsConstants.STORE_ITEM);
      File appDir = (File) cc.getAttribute(CommandsConstants.APP_DIR);
      String itemId = (String) cc.getAttribute(CommandsConstants.ITEM_ID);
      String fileName = (String) cc.getAttribute(CommandsConstants.DOWNLOADED_FILE_NAME);
      String username = itemId;
      String password = StringUtil.getRandom(8);

      Properties prop = Prefs.load(appDir);

      boolean internalDeployRequested = false;

      for (String ftp : storeItem.publishFtp) {
        if (ftp.equals("ftp:")) internalDeployRequested = true;
      }

      if (prop.getProperty("publish.local.ftp.enable").equals("true")
          || internalDeployRequested == true) {
        File fromFile = new File(prop.getProperty("download.dir"), itemId);
        File userRoot = new File(prop.getProperty("publish.local.ftp.rootdir"), username);
        File toFile = new File(userRoot, fileName);

        userRoot.mkdirs();
        IOUtil.copyFile(fromFile, toFile);

        FTPService ftpServer;

        ftpServer = FTPService.getInstance();
        ftpServer.addUser(username, password, userRoot.getAbsolutePath());

        String url;

        url =
            "ftp://"
                + username
                + ":"
                + password
                + "@"
                + prop.getProperty("publish.local.ftp.ip")
                + ":"
                + prop.getProperty("publish.local.ftp.port")
                + "/"
                + fileName;
        FTPAccessible.add(itemId, url);
      }
    } catch (Exception e) {
      Log.logException(e);
      return new Result(Result.FAIL);
    }
    return new Result(Result.SUCCESS);
  }
 public String generateEngineTemplate(
     File newServicePath, Document describeDocument, String processingName) throws Exception {
   Document xslDocument;
   String shellTemplate = null;
   File stylesheet = new File(newServicePath, SHELL_TEMPLATE_XSLT_PATH);
   File shellScriptFolder = new File(newServicePath, SHELL_SCRIPT_PATH);
   shellScriptFolder.mkdirs();
   if (stylesheet.exists()) {
     xslDocument = domUtil.fileToDocument(stylesheet);
     transformer = TransformerFactory.newInstance().newTransformer(new DOMSource(xslDocument));
     transformer.transform(
         new StreamSource(DOMUtil.getDocumentAsInputStream(describeDocument)),
         new StreamResult(
             new FileOutputStream(
                 new File(
                     shellScriptFolder,
                     SHELL_SCRIPT_FILE_PREFIX + processingName + "_template.sh"))));
     shellTemplate =
         IOUtil.loadString(
             new File(
                 shellScriptFolder, SHELL_SCRIPT_FILE_PREFIX + processingName + "_template.sh"));
   }
   return shellTemplate;
 }
  @Override
  public Object executeTag(org.w3c.dom.Element connEl) throws Exception {
    CswClient client;
    Object opType = null;
    try {
      String operationType =
          this.engine.evaluateString(
              connEl.getAttribute("type"), IEngine.EngineStringType.ATTRIBUTE);

      LinkedList<Element> children = DOMUtil.getChildren(connEl);
      client = (CswClient) this.executeChildTag(children.get(0));

      Document xmlSnippet;
      xmlSnippet = (Document) this.executeChildTag(children.get(1));

      TransactionType t = new TransactionType();

      if (operationType.equals("DELETE")) {
        DeleteType delete = new DeleteType();
        delete.setTypeName(evaluateAttribute(connEl, "typeName"));

        QueryConstraintType con = new QueryConstraintType();
        con.setVersion("");
        delete.setConstraint(con);

        JAXBElement<FilterType> filter =
            (JAXBElement<FilterType>)
                JAXBUtil.getInstance().unmarshall(DOMUtil.getDocumentAsInputStream(xmlSnippet));
        con.setFilter(filter.getValue());

        opType = delete;
      } else if (operationType.equals("INSERT")) {
        InsertType insert = new InsertType();
        insert
            .getAny()
            .add(JAXBUtil.getInstance().unmarshall(DOMUtil.getDocumentAsInputStream(xmlSnippet)));
        opType = insert;
      } /*else
        {
            UpdateType update=new UpdateType();
            update.getAny().add(JAXBUtil.getInstance().unmarshall(DOMUtil.getDocumentAsInputStream(xmlSnippet)));
            opType=update;
        }*/

      t.getInsertOrUpdateOrDelete().add(opType);
      TransactionResponseType response = client.transact(t);

      File tempFile = IOUtil.getTemporaryFile();

      JAXBUtil.getInstance()
          .marshall(
              OFactory.csw.createTransactionResponse(response), new FileOutputStream(tempFile));

      DOMUtil util;
      util = new DOMUtil();
      Document xmlDoc = util.fileToDocument(tempFile);
      tempFile.delete();

      return xmlDoc;
    } catch (Exception e) {
      e.printStackTrace();
      throw e;
    }

    // JAXBUtil.getInstance().marshall(response, new
    // FileOutputStream("/home/massi/TEMP/GetRecordsResponse.xml"));

  }