public static void main(String[] args) {
   if (args.length < 1) {
     System.out.println("Usage: java Parser [input]");
     System.exit(0);
   }
   Parser p = new Parser(args[0]);
 }
 private void exec(String command) throws IOException, InterruptedException {
   System.out.println(command);
   final Runtime runtime = Runtime.getRuntime();
   final Process process = runtime.exec(command);
   int retVal = process.waitFor();
   if (retVal != 0) {
     System.exit(retVal);
   }
 }
  @Override
  public void execute(String folder) {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    // dbf.setNamespaceAware(true);
    // dbf.setValidating(true);
    // dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
    try {
      DocumentBuilder db = dbf.newDocumentBuilder();
      // db.setErrorHandler(new DefaultHandler());

      Document document = db.parse(Paths.get(folder, "changelog.xml").toFile());

      NodeList nodeList = document.getElementsByTagName("include");
      for (int i = 0; i < nodeList.getLength(); i++) {
        final Node node = nodeList.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
          final String mode = node.getAttributes().getNamedItem("mode").getTextContent();
          final String filePath = node.getAttributes().getNamedItem("file").getTextContent();
          final File file = Paths.get(folder, filePath).toFile();
          final String checksum = DigestUtils.sha1Hex(new FileInputStream(file));
          final String author = System.getProperty("user.name");
          final String options = node.getAttributes().getNamedItem("options").getTextContent();

          // row = getODChangeLog(where id = i)
          // if ( != checksum.equals(row.getDisplayValue("checksum")) {
          // System.err.println("Error file has been modified since previous migration: " +
          // filePath);
          // System.err.println("Invalid checksum: item n° "+ i + " file computed checksum: " +
          // checksum + " doesn't match previous checksum in od: " +
          // row.getDisplayValue("checksum"));
          // System.exit(-1);
          // }

          final String validateCommand =
              new StringBuilder("arsxml validate -i ").append(file.getAbsolutePath()).toString();
          exec(validateCommand);

          final String arsxmlCommand =
              new StringBuilder("arsxml ")
                  .append(mode)
                  .append(" ")
                  .append(options)
                  .append(" ")
                  .append(file.getAbsolutePath())
                  .toString();
          exec(arsxmlCommand);

          SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd-hhmmss.S");
          String timestamp = formatter.format(new Date());
          // insert in ODCHANGELOG (i, checksum, filePath, author, timestamp, Version.VERSION)
        }
      }
    } catch (IOException | ParserConfigurationException | SAXException | InterruptedException e) {
      throw new RuntimeException(e);
    }
  }
  /**
   * Main program.
   *
   * <p>\u0040param args Program parameters.
   */
  public static void main(String[] args) {
    //  Initialize.
    try {
      if (!initialize(args)) {
        System.exit(1);
      }
      //  Process all files.

      long startTime = System.currentTimeMillis();

      int filesProcessed = processFiles(args);

      long processingTime = (System.currentTimeMillis() - startTime + 999) / 1000;

      //  Terminate.

      terminate(filesProcessed, processingTime);
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }
  }
示例#5
0
  /** The main entry point */
  public static void main(String[] args) throws FileNotFoundException, IOException {

    String xmlfile = null;
    int debug = 0;
    int maxErrs = 10;
    boolean nsAware = true;
    boolean validating = true;
    boolean showWarnings = (debug > 2);
    boolean showErrors = true;
    Vector catalogFiles = new Vector();

    for (int i = 0; i < args.length; i++) {
      if (args[i].equals("-c")) {
        ++i;
        catalogFiles.add(args[i]);
        continue;
      }

      if (args[i].equals("-w")) {
        validating = false;
        continue;
      }

      if (args[i].equals("-v")) {
        validating = true;
        continue;
      }

      if (args[i].equals("-n")) {
        nsAware = false;
        continue;
      }

      if (args[i].equals("-N")) {
        nsAware = true;
        continue;
      }

      if (args[i].equals("-d")) {
        ++i;
        String debugstr = args[i];
        try {
          debug = Integer.parseInt(debugstr);
          if (debug >= 0) {
            Debug.setDebug(debug);
            showWarnings = (debug > 2);
          }
        } catch (Exception e) {
          // nop
        }
        continue;
      }

      if (args[i].equals("-E")) {
        ++i;
        String errstr = args[i];
        try {
          int errs = Integer.parseInt(errstr);
          if (errs >= 0) {
            maxErrs = errs;
          }
        } catch (Exception e) {
          // nop
        }
        continue;
      }

      xmlfile = args[i];
    }

    if (xmlfile == null) {
      System.out.println("Usage: org.apache.xml.resolver.apps.xread [opts] xmlfile");
      System.exit(1);
    }

    ResolvingXMLReader reader = new ResolvingXMLReader();

    try {
      reader.setFeature("http://xml.org/sax/features/namespaces", nsAware);
      reader.setFeature("http://xml.org/sax/features/validation", validating);
    } catch (SAXException e) {
      // nop;
    }

    Catalog catalog = reader.getCatalog();

    for (int count = 0; count < catalogFiles.size(); count++) {
      String file = (String) catalogFiles.elementAt(count);
      catalog.parseCatalog(file);
    }

    XParseError xpe = new XParseError(showErrors, showWarnings);
    xpe.setMaxMessages(maxErrs);
    reader.setErrorHandler(xpe);

    String parseType = validating ? "validating" : "well-formed";
    String nsType = nsAware ? "namespace-aware" : "namespace-ignorant";
    if (maxErrs > 0) {
      System.out.println("Attempting " + parseType + ", " + nsType + " parse");
    }

    Date startTime = new Date();

    try {
      reader.parse(xmlfile);
    } catch (SAXException sx) {
      System.out.println("SAX Exception: " + sx);
    } catch (Exception e) {
      e.printStackTrace();
    }

    Date endTime = new Date();

    long millisec = endTime.getTime() - startTime.getTime();
    long secs = 0;
    long mins = 0;
    long hours = 0;

    if (millisec > 1000) {
      secs = millisec / 1000;
      millisec = millisec % 1000;
    }

    if (secs > 60) {
      mins = secs / 60;
      secs = secs % 60;
    }

    if (mins > 60) {
      hours = mins / 60;
      mins = mins % 60;
    }

    if (maxErrs > 0) {
      System.out.print("Parse ");
      if (xpe.getFatalCount() > 0) {
        System.out.print("failed ");
      } else {
        System.out.print("succeeded ");
        System.out.print("(");
        if (hours > 0) {
          System.out.print(hours + ":");
        }
        if (hours > 0 || mins > 0) {
          System.out.print(mins + ":");
        }
        System.out.print(secs + "." + millisec);
        System.out.print(") ");
      }
      System.out.print("with ");

      int errCount = xpe.getErrorCount();
      int warnCount = xpe.getWarningCount();

      if (errCount > 0) {
        System.out.print(errCount + " error");
        System.out.print(errCount > 1 ? "s" : "");
        System.out.print(" and ");
      } else {
        System.out.print("no errors and ");
      }

      if (warnCount > 0) {
        System.out.print(warnCount + " warning");
        System.out.print(warnCount > 1 ? "s" : "");
        System.out.print(".");
      } else {
        System.out.print("no warnings.");
      }

      System.out.println("");
    }

    if (xpe.getErrorCount() > 0) {
      System.exit(1);
    }
  }