All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.easyinnova.policy_checker.Main Maven / Gradle / Ivy

The newest version!
/**
 * 

Main.java

This program is free software: you can redistribute it * and/or modify it under the terms of the GNU General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any later version; or, * at your choice, under the terms of the Mozilla Public License, v. 2.0. SPDX GPL-3.0+ or MPL-2.0+. *

This program is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License and the Mozilla Public License for more details.

*

You should have received a copy of the GNU General Public License and the Mozilla Public * License along with this program. If not, see http://www.gnu.org/licenses/ * and at http://mozilla.org/MPL/2.0 .

NB: for the * statement, include Easy Innova SL or other company/Person contributing the code.

* 2015 Easy Innova, SL

*/ package com.easyinnova.policy_checker; import com.easyinnova.implementation_checker.ImplementationCheckerValidator; import com.easyinnova.implementation_checker.ValidationResult; import com.easyinnova.implementation_checker.rules.RuleResult; import com.easyinnova.policy_checker.ArgumentParser; import com.easyinnova.policy_checker.PolicyChecker; import com.easyinnova.policy_checker.model.Rules; import com.easyinnova.tiff.reader.TiffReader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * Created by Adria Llorens on 27/12/2016. */ public class Main { public static void main(String[] args) { // Arguments List params = new ArrayList(Arrays.asList(args)); ArgumentParser parser = new ArgumentParser(); PolicyChecker policy = new PolicyChecker(); if (!parser.parse(params)) { displayHelp(); } if (parser.isError()){ return; } // All OK String path = parser.getPath(); try { TiffReader tr = new TiffReader(); int readerRes = tr.readFile(path, false); switch (readerRes) { case -1: System.out.println("File '" + path + "' does not exist"); break; case -2: System.out.println("IO Exception in file '" + path + "'"); break; case 0: ImplementationCheckerValidator validator = new ImplementationCheckerValidator(); Rules rules = parser.getRules(); ValidationResult result = policy.validateRules(validator.getValidationXmlString(tr), rules); printResults("ERROR", result.getErrors()); printResults("Warning", result.getWarnings(false)); if (result.getErrors().size() == 0 && result.getWarnings(false).size() == 0){ System.out.println("All rules OK!"); } break; } } catch (Exception e) { e.printStackTrace(); } } private static void displayHelp() { System.out.println("Usage: policy-checker [--rule ] filepath"); System.out.println(""); System.out.println("Rule specification:\n" + "\tType must be 'error' or 'warning'.\n" + "\tTag must be an accepted Tag. Use 'policy-checker --list' to see the list of accepted tags.\n" + "\tOperator must be 'GT' (Grather than), 'LT' (Less than) or 'EQ' (Equals).\n" + "\t\tExample: --rule error ImageWidth GT 500\n" + "\t\tExample: --rule warning ImageLength EQ 500"); } private static void printResults(String type, List results) { for (RuleResult result : results) { System.out.println(type); System.out.println(" Rule: " + result.getRule().getDescription().getValue()); System.out.println(" Output: " + result.getDescription()); System.out.println(); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy