コード例 #1
0
 @Override
 public void shutdown() {
   super.shutdown();
   if (csp != null) {
     csp.shutdown();
   }
 }
コード例 #2
0
  @Override
  public void process(
      ContentSpecConfiguration cspConfig,
      RESTManager restManager,
      ErrorLoggerManager elm,
      UserV1 user) {
    // If files is empty then we must be using a csprocessor.cfg file
    if (files.size() == 0 && cspConfig.getContentSpecId() != null) {
      TopicV1 contentSpec =
          restManager.getReader().getContentSpecById(cspConfig.getContentSpecId(), null);
      String fileName =
          StringUtilities.escapeTitle(contentSpec.getTitle())
              + "-post."
              + Constants.FILENAME_EXTENSION;
      File file = new File(fileName);
      if (!file.exists()) {
        // Backwards compatibility check for files ending with .txt
        file = new File(StringUtilities.escapeTitle(contentSpec.getTitle()) + "-post.txt");
        if (!file.exists()) {
          printError(String.format(Constants.NO_FILE_FOUND_FOR_CONFIG, fileName), false);
          shutdown(Constants.EXIT_FAILURE);
        }
      }
      files.add(file);
    }

    // Check that the parameters are valid
    if (!isValid()) {
      printError(Constants.ERROR_NO_FILE_MSG, true);
      shutdown(Constants.EXIT_FAILURE);
    }

    // Good point to check for a shutdown
    if (isAppShuttingDown()) {
      shutdown.set(true);
      return;
    }

    boolean success = false;

    // Read in the file contents
    String contentSpec = FileUtilities.readFileContents(files.get(0));

    if (contentSpec == null || contentSpec.equals("")) {
      printError(Constants.ERROR_EMPTY_FILE_MSG, false);
      shutdown(Constants.EXIT_FAILURE);
    }

    // Good point to check for a shutdown
    if (isAppShuttingDown()) {
      shutdown.set(true);
      return;
    }

    // Process the content spec to see if its valid
    csp = new ContentSpecProcessor(restManager, elm, permissive, true);
    try {
      success = csp.processContentSpec(contentSpec, user, ContentSpecParser.ParsingMode.EITHER);
    } catch (Exception e) {
      printError(Constants.ERROR_INTERNAL_ERROR, false);
      shutdown(Constants.EXIT_INTERNAL_SERVER_ERROR);
    }

    // Good point to check for a shutdown
    if (isAppShuttingDown()) {
      shutdown.set(true);
      return;
    }

    // Print the logs
    if (success) {
      JCommander.getConsole().println("VALID");
    } else {
      JCommander.getConsole().println(elm.generateLogs());
      JCommander.getConsole().println("INVALID");
      JCommander.getConsole().println("");
      shutdown(Constants.EXIT_TOPIC_INVALID);
    }
  }