Changeset 5395 for CMDIValidator
- Timestamp:
- 06/27/14 00:13:30 (10 years ago)
- Location:
- CMDIValidator/trunk/cmdi-validator-core/src/main/java/eu/clarin/cmdi/validator
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
CMDIValidator/trunk/cmdi-validator-core/src/main/java/eu/clarin/cmdi/validator/CMDIValidator.java
r5394 r5395 23 23 import java.net.MalformedURLException; 24 24 import java.net.URL; 25 import java.util. Collections;25 import java.util.ArrayList; 26 26 import java.util.LinkedHashSet; 27 27 import java.util.LinkedList; … … 218 218 final List<CMDIValidatorExtension> exts = config.getExtensions(); 219 219 if (exts != null) { 220 this.extensions = new LinkedList<CMDIValidatorExtension>(); 220 this.extensions = 221 new ArrayList<CMDIValidatorExtension>(exts.size()); 221 222 for (CMDIValidatorExtension extension : exts) { 222 223 extension.initalize(processor); … … 461 462 private final XsltTransformer schematronValidator; 462 463 private final DocumentBuilder builder; 463 private final ResultImpl result = new ResultImpl();464 private CMDIValidatorWriteableResult result; 464 465 465 466 … … 610 611 TFileInputStream stream = null; 611 612 try { 613 612 614 /* 613 615 * step 0: prepare … … 615 617 logger.debug("validating file '{}' ({} bytes)", 616 618 file, file.length()); 617 result .setFile(file);619 result = new CMDIValidatorWriteableResultImpl(file); 618 620 stream = new TFileInputStream(file); 619 621 … … 654 656 "error closing file '" + file + "'", e); 655 657 } finally { 656 if (handler != null) { 657 if (result.isHighestSeverity(Severity.ERROR)) { 658 handler.onValidationFailure(result); 659 } else { 660 handler.onValidationSuccess(result); 658 if ((result != null) && (handler != null)) { 659 try { 660 if (result.isHighestSeverity(Severity.ERROR)) { 661 handler.onValidationFailure(result); 662 } else { 663 handler.onValidationSuccess(result); 664 } 665 } finally { 666 result = null; 661 667 } 662 668 } 663 result.reset();664 669 } 665 670 } … … 1012 1017 } // class ShadowCacheGrammarPool 1013 1018 1014 1015 private static final class ResultImpl implements1016 CMDIValidatorWriteableResult {1017 private final List<Message> messages = new LinkedList<Message>();1018 private File file;1019 private Severity highestSeverity;1020 1021 1022 private ResultImpl() {1023 reset();1024 }1025 1026 1027 @Override1028 public File getFile() {1029 return file;1030 }1031 1032 1033 @Override1034 public Severity getHighestSeverity() {1035 return highestSeverity;1036 }1037 1038 1039 @Override1040 public boolean isHighestSeverity(Severity severity) {1041 if (severity == null) {1042 throw new NullPointerException("severity == null");1043 }1044 return this.highestSeverity.equals(severity);1045 }1046 1047 1048 @Override1049 public List<Message> getMessages() {1050 if (messages.isEmpty()) {1051 return Collections.emptyList();1052 } else {1053 return Collections.unmodifiableList(messages);1054 }1055 }1056 1057 1058 @Override1059 public Message getFirstMessage() {1060 return messages.isEmpty() ? null : messages.get(0);1061 }1062 1063 1064 @Override1065 public Message getFirstMessage(Severity severity) {1066 if (severity == null) {1067 throw new NullPointerException("severity == null");1068 }1069 1070 if (!messages.isEmpty()) {1071 for (Message msg : messages) {1072 if (severity.equals(msg.getSeverity())) {1073 return msg;1074 }1075 }1076 }1077 return null;1078 }1079 1080 1081 @Override1082 public int getMessageCount() {1083 return messages.size();1084 }1085 1086 1087 @Override1088 public int getMessageCount(Severity severity) {1089 if (severity == null) {1090 throw new NullPointerException("severity == null");1091 }1092 1093 int count = 0;1094 if (!messages.isEmpty()) {1095 for (Message msg : messages) {1096 if (severity.equals(msg.getSeverity())) {1097 count++;1098 }1099 }1100 }1101 return count;1102 }1103 1104 1105 @Override1106 public void reportInfo(int line, int col, String message) {1107 reportInfo(line, col, message, null);1108 }1109 1110 1111 @Override1112 public void reportInfo(int line, int col, String message,1113 Throwable cause) {1114 messages.add(new MessageImpl(Severity.INFO, line, col, message,1115 cause));1116 }1117 1118 1119 @Override1120 public void reportWarning(int line, int col, String message) {1121 reportWarning(line, col, message, null);1122 }1123 1124 1125 @Override1126 public void reportWarning(int line, int col, String message,1127 Throwable cause) {1128 switch (highestSeverity) {1129 case WARNING:1130 /* FALL-THROUGH */1131 case ERROR:1132 break;1133 default:1134 highestSeverity = Severity.WARNING;1135 }1136 messages.add(new MessageImpl(Severity.WARNING, line, col, message,1137 cause));1138 }1139 1140 1141 @Override1142 public void reportError(int line, int col, String message) {1143 reportError(line, col, message, null);1144 }1145 1146 1147 @Override1148 public void reportError(int line, int col, String message,1149 Throwable cause) {1150 switch (highestSeverity) {1151 case ERROR:1152 break;1153 default:1154 highestSeverity = Severity.ERROR;1155 }1156 messages.add(new MessageImpl(Severity.ERROR, line, col, message,1157 cause));1158 }1159 1160 1161 private void setFile(File file) {1162 this.file = file;1163 }1164 1165 1166 private void reset() {1167 this.messages.clear();1168 this.file = null;1169 this.highestSeverity = Severity.INFO;1170 }1171 } // class ResultImpl1172 1173 1174 private static final class MessageImpl implements1175 CMDIValidatorResult.Message {1176 private final Severity severity;1177 private final int line;1178 private final int col;1179 private final String message;1180 private final Throwable cause;1181 1182 1183 private MessageImpl(Severity severity, int line, int col,1184 String message, Throwable cause) {1185 this.severity = severity;1186 this.line = line;1187 this.col = col;1188 this.message = message;1189 this.cause = cause;1190 }1191 1192 1193 @Override1194 public Severity getSeverity() {1195 return severity;1196 }1197 1198 1199 @Override1200 public int getLineNumber() {1201 return line;1202 }1203 1204 1205 @Override1206 public int getColumnNumber() {1207 return col;1208 }1209 1210 1211 @Override1212 public String getMessage() {1213 return message;1214 }1215 1216 1217 @Override1218 public Throwable getCause() {1219 return cause;1220 }1221 } // class MessageImpl1222 1223 1019 } // class CMDIValidator -
CMDIValidator/trunk/cmdi-validator-core/src/main/java/eu/clarin/cmdi/validator/CMDIValidatorConfig.java
r5384 r5395 19 19 import java.io.File; 20 20 import java.io.FileFilter; 21 import java.util.ArrayList; 21 22 import java.util.Collections; 22 import java.util.LinkedList;23 23 import java.util.List; 24 24 … … 165 165 } 166 166 if (config.extensions == null) { 167 config.extensions = new LinkedList<CMDIValidatorExtension>();167 config.extensions = new ArrayList<CMDIValidatorExtension>(); 168 168 } 169 169 config.extensions.add(extension); -
CMDIValidator/trunk/cmdi-validator-core/src/main/java/eu/clarin/cmdi/validator/CMDIValidatorResult.java
r5384 r5395 28 28 return "I"; 29 29 } 30 31 @Override 32 public int priority() { 33 return 1; 34 } 30 35 }, 31 36 WARNING { … … 33 38 public String getShortcut() { 34 39 return "W"; 40 } 41 42 @Override 43 public int priority() { 44 return 2; 35 45 } 36 46 }, … … 40 50 return "E"; 41 51 } 52 53 @Override 54 public int priority() { 55 return 3; 56 } 42 57 }; 43 58 44 59 public abstract String getShortcut(); 60 61 62 public abstract int priority(); 45 63 } // enum Severity 46 64
Note: See TracChangeset
for help on using the changeset viewer.