Exemple #1
0
 private void call(Node operation)
     throws ParserConfigurationException, TransformerConfigurationException {
   String opName = operation.getNodeName();
   if (opName.equals("call")) {
     String script =
         Utils.combine(Utils.getParentDir(this.currentScript), operation.getTextContent());
     call(script);
   } else if (opName.equals("apply")) processApply(operation);
   else if (opName.equals("xml")) processXml(operation);
   else if (opName.equals("txt")) processTxt(operation);
   else if (opName.equals("copy")) processCopy(operation);
   else if (opName.equals("delete")) processDelete(operation);
 }
Exemple #2
0
 private void processCopy(Node operation) {
   List<Node> fromNode = getChildNodes(operation, "from");
   List<Node> toNode = getChildNodes(operation, "to");
   if (fromNode.isEmpty() || toNode.isEmpty()) {
     return;
   }
   String path = fromNode.get(0).getTextContent();
   String fromPath = (new File(path).isAbsolute()) ? path : absolutePath(path);
   String toPath = absolutePath(toNode.get(0).getTextContent());
   Boolean copyContents = fromPath.endsWith(File.separator + "*");
   File from = new File((copyContents) ? fromPath.substring(0, fromPath.length() - 2) : fromPath);
   File to = new File(toPath);
   if (!from.exists()) {
     Utils.onError(new Error.FileNotFound(from.getPath()));
     return;
   }
   try {
     if (copyContents) {
       FileUtils.forceMkdir(to);
       FileUtils.copyDirectory(from, to);
     } else if (from.isDirectory()) {
       FileUtils.forceMkdir(to);
       FileUtils.copyDirectoryToDirectory(from, to);
     } else {
       if (to.isDirectory()) {
         FileUtils.forceMkdir(to);
         FileUtils.copyFileToDirectory(from, to);
       } else {
         File toDir = new File(Utils.getParentDir(to));
         FileUtils.forceMkdir(toDir);
         FileUtils.copyFile(from, to);
       }
     }
   } catch (IOException ex) {
     Utils.onError(new Error.FileCopy(from.getPath(), to.getPath()));
   }
 }
Exemple #3
0
 private String absolutePath(String path) {
   return (path.startsWith(".."))
       ? Utils.combine(Utils.getParentDir(this.currentScript), path)
       : Utils.combine(this.targetDir, path);
 }