@Override public void transform(List<String> args, Object root, OutputStream out) { assert root != null; assert context != null; populateContext(context); Reporter reporter = context.getReporter(); reporter.logInfo(reporter.message("*KEY*", "Transforming result using ''{0}'' transformer...", getName())); // extract significant time intervals Set<TimeInterval> intervals = extractISDIntervals(root, context); if (reporter.getDebugLevel() > 0) { StringBuffer sb = new StringBuffer(); for (TimeInterval interval : intervals) { if (sb.length() > 0) sb.append(','); sb.append(interval); } reporter.logDebug(reporter.message("*KEY*", "Resolved active intervals: {0}.", "{" + sb + "}")); } writeISDSequence(root, context, intervals, out); }
protected boolean verifyOtherItem(Object content, Locator locator, VerifierContext context) { boolean failed = false; if (content instanceof Image) failed = !verify((Image) content, locator, context); if (failed) { Reporter reporter = context.getReporter(); reporter.logError(reporter.message(locator, "*KEY*", "Invalid image item.")); } return !failed; }
private void showProcessingInfo() { Reporter reporter = getReporter(); int level = reporter.getVerbosityLevel(); if (level > 0) { if (level > 1) showConfigurationInfo(); if (reporter.isTreatingWarningAsError()) reporter.logInfo(reporter.message("*KEY*", "Warnings are treated as errors.")); else if (reporter.areWarningsDisabled()) reporter.logInfo(reporter.message("*KEY*", "Warnings are disabled.")); else if (reporter.areWarningsHidden()) reporter.logInfo(reporter.message("*KEY*", "Warnings are hidden.")); } }
public void configureReporter(Reporter reporter) { if (!reporter.hasDisabledWarning("missing-timing")) reporter.enableWarning("missing-timing"); if (!reporter.hasEnabledWarning("references-external-image")) reporter.disableWarning("references-external-image"); if (!reporter.hasDisabledWarning("uses-line-height-normal")) reporter.enableWarning("uses-line-height-normal"); if (!reporter.hasDisabledWarning("uses-non-recommended-font-family")) reporter.enableWarning("uses-non-recommended-font-family"); }
private void logPruning(Message message) { Reporter reporter = getReporter(); if (foreignTreatment == ForeignTreatment.Error) { reporter.logError(message); } if (foreignTreatment == ForeignTreatment.Warning) { if (reporter.isWarningEnabled("foreign")) { if (reporter.logWarning(message)) reporter.logError(message); } } else if (foreignTreatment == ForeignTreatment.Info) reporter.logInfo(message); } }
option = option.substring(2); if (option.equals("debug")) { int debug = reporter.getDebugLevel(); if (debug < 1) debug = 1; else debug += 1; reporter.setDebugLevel(debug); } else if (option.equals("debug-exceptions")) { int debug = reporter.getDebugLevel(); if (debug < 2) debug = 2; reporter.setDebugLevel(debug); } else if (option.equals("debug-level")) { if (index + 1 > numArgs) int debug = reporter.getDebugLevel(); if (debugNew > debug) reporter.setDebugLevel(debugNew); } else if (option.equals("disable-warnings")) { reporter.disableWarnings(); } else if (option.equals("expect-errors")) { if (index + 1 > numArgs) throw new ShowUsageException(); } else if (option.equals("hide-resource-location")) { reporter.hideLocation(); } else if (option.equals("hide-resource-path")) { reporter.hidePath();
protected boolean verifyNonEmptyOrPadded(Object content, QName name, String value, Locator locator, VerifierContext context) { Reporter reporter = context.getReporter(); if (value.length() == 0) { reporter.logInfo(reporter.message(locator, "*KEY*", "Empty {0} not permitted, got ''{1}''.", name, value)); return false; } else if (Strings.isAllXMLSpace(value)) { reporter.logInfo(reporter.message(locator, "*KEY*", "The value of {0} is entirely XML space characters, got ''{1}''.", name, value)); return false; } else if (!value.equals(value.trim())) { reporter.logInfo(reporter.message(locator, "*KEY*", "XML space padding not permitted on {0}, got ''{1}''.", name, value)); return false; } else return true; }
String[] tokens = value.split("\\s+"); for (String token : tokens) { if (reporter.hasDefaultWarning(token)) reporter.enableWarning(token); if (reporter.hasDefaultWarning(token)) reporter.disableWarning(token); try { setRestartOptions(RestartOptions.valueOf(value)); reporter.logInfo(reporter.message("*KEY*", "Found processing options, signalling restart: ''{0}''.", value)); } catch (RestartOptions.ParserException e) { reporter.logError(reporter.message("*KEY*", "Invalid processing options syntax for value ''{0}'': {1}.", value, e.getMessage()));
public static Configuration fromLocator(URL locator, ConfigurationDefaults defaults, Class<? extends Configuration> cls, Reporter reporter) throws IOException { try { return (locator != null) ? fromStream(locator.openStream(), defaults, cls, reporter) : null; } catch (IOException e) { reporter.logError(e); return null; } }
private void debug(int level, String label, String details) { Reporter reporter = context.getReporter(); if (reporter.getDebugLevel() >= level) { reporter.logDebug(reporter.message("*KEY*", "{0}: {1}[{2}].", label, helper.getClassString(content), details)); } }
final int minHeaderLength = 10; if (lineLength < minHeaderLength) { if (reporter.isWarningEnabled("bad-header-length")) { if (reporter.logWarning(reporter.message(locator, "w.001", "Header too short, got length {0}, expected {1}.", lineLength, minHeaderLength))) fail = true; final int minFieldCount = 3; if (fields.length != minFieldCount) { Message message = reporter.message(locator, "w.002", "Header bad field count, got {0}, expected {1}.", fields.length, minFieldCount); if (reporter.isWarningEnabled("bad-header-field-count")) { if (reporter.logWarning(message)) fail = true; return !fail; if (fields.length < 1) { if (reporter.isWarningEnabled("bad-header-preamble")) { Message message = reporter.message(locator, "w.003", "Header preamble field missing."); if (reporter.logWarning(message)) fail = true; String preamble = fields[0]; if (!preamble.equals(preambleExpected)) { reporter.logDebug(reporter.message("d.001", "''{0}'' != ''{1}''", dump(preamble), dump(preambleExpected))); if (reporter.isWarningEnabled("bad-header-preamble")) { Message message = reporter.message(locator, "w.004", "Header preamble field invalid, got ''{0}'', expected ''{1}''.", preamble, preambleExpected); if (reporter.logWarning(message)) fail = true; return !fail;
private Object writeISDAsFile(Document document, int sequenceIndex, TransformerContext context) { Reporter reporter = context.getReporter(); FileOutputStream fos = null; BufferedOutputStream bos = null; try { String outputFileName = outputPatternFormatter.format(new Object[]{Integer.valueOf(sequenceIndex)}); File outputFile = new File(outputDirectory, outputFileName); fos = new FileOutputStream(outputFile); bos = new BufferedOutputStream(fos); writeISD(document, bos, context); reporter.logInfo(reporter.message("*KEY*", "Wrote ISD ''{0}''.", outputFile.getAbsolutePath())); return outputFile; } catch (FileNotFoundException e) { reporter.logError(e); return null; } finally { IOUtil.closeSafely(bos); IOUtil.closeSafely(fos); } }
private void setReporter(Reporter reporter, PrintWriter reporterOutput, String reporterOutputEncoding, boolean reporterIncludeSource, boolean closeOldReporter) { if (reporter == this.reporter) return; if (this.reporter != null) this.reporter.flush(); if (closeOldReporter) { try { if (this.reporter != null) this.reporter.close(); } catch (IOException e) { } finally { this.reporter = null; } } try { if (!reporter.isOpen()) reporter.open(defaultWarningSpecifications, reporterOutput, getReporterBundle(), reporterOutputEncoding, reporterIncludeSource); this.reporter = reporter; this.includeSource = reporterIncludeSource; } catch (Throwable e) { this.reporter = null; } }
public void setReporter(Reporter reporter, PrintWriter reporterOutput, String reporterOutputEncoding, boolean reporterIncludeSource, boolean closeOldReporter) { if (reporter == this.reporter) return; if (this.reporter != null) this.reporter.flush(); if (closeOldReporter) { try { if (this.reporter != null) this.reporter.close(); } catch (IOException e) { } finally { this.reporter = null; } } try { reporter.open(defaultWarningSpecifications, reporterOutput, null, reporterOutputEncoding, reporterIncludeSource); this.reporter = reporter; this.includeSource = reporterIncludeSource; } catch (Throwable e) { this.reporter = null; } }
private URL getSchemaResource(String resourceName) throws SchemaValidationErrorException { Reporter reporter = getReporter(); reporter.logDebug(reporter.message("*KEY*", "Searching for built-in schema at {0}...", resourceName)); try { URL urlSchema = null; Enumeration<URL> resources = getClass().getClassLoader().getResources(resourceName); while (resources.hasMoreElements()) { URL url = resources.nextElement(); String urlPath = url.getPath(); if (urlPath.indexOf(resourceName) == (urlPath.length() - resourceName.length())) { reporter.logDebug(reporter.message("*KEY*", "Found resource match at '{'{0}'}'.", url)); urlSchema = url; break; } else { reporter.logDebug(reporter.message("*KEY*", "Skipping partial resource match at '{'{0}'}'.", url)); } } if (urlSchema == null) { Message message = reporter.message("*KEY*:", "Can't find schema resource '{'{0}'}'.", resourceName); reporter.logDebug(message); throw new SchemaValidationErrorException(new MissingResourceException(message.toString(), getClass().getName(), resourceName)); } return urlSchema; } catch (IOException e) { throw new SchemaValidationErrorException(e); } }
private List<String> processNonOptionArguments(List<String> nonOptionArgs, OptionProcessor optionProcessor) { if ((outputFile != null) && (nonOptionArgs.size() > 1)) { throw new InvalidOptionUsageException("output-file", getReporter().message("x.019", "must not be used when multiple URL arguments are specified")); } if (optionProcessor != null) nonOptionArgs = optionProcessor.processNonOptionArguments(nonOptionArgs); return nonOptionArgs; }
allowModifiedUTF8 = true; } else if (option.equals("debug")) { int debug = reporter.getDebugLevel(); if (debug < 1) debug = 1; else debug += 1; reporter.setDebugLevel(debug); } else if (option.equals("debug-exceptions")) { int debug = reporter.getDebugLevel(); if (debug < 2) debug = 2; reporter.setDebugLevel(debug); } else if (option.equals("debug-level")) { if (index + 1 > numArgs) debugNew = Integer.parseInt(level); } catch (NumberFormatException e) { throw new InvalidOptionUsageException("debug-level", reporter.message("x.004", "bad debug level syntax: {0}", level)); int debug = reporter.getDebugLevel(); if (debugNew > debug) reporter.setDebugLevel(debugNew); } else if (option.equals("default-alignment")) { if (index + 1 > numArgs) defaultWhitespace = args.get(++index); if (!defaultWhitespace.equals("default") && !defaultWhitespace.equals("preserve")) throw new InvalidOptionUsageException("default-whitespace", getReporter().message("x.020", "unknown whitespace value: {0}", arg));
public static void badWallClockTime(String value, Location location, VerifierContext context, TimeParameters timeParameters) { Reporter reporter = context.getReporter(); Locator locator = location.getLocator(); Message m; if (value.indexOf('T') >= 0) { // date-time format contains 'T', while other forms do not m = reporter.message(locator, "*KEY*", "Bad date-time form of wall clock <timeExpression>."); } else if (value.indexOf('-') >= 0) { // date format contains '-', but not 'T' m = reporter.message(locator, "*KEY*", "Bad date form of wall clock <timeExpression>."); } else if (value.indexOf(':') >= 0) { // wall-time format contains ':', but not 'T' and not '-' m = reporter.message(locator, "*KEY*", "Bad wall-time form of wallclock time <timeExpression>."); } else { // no hint on intended format m = reporter.message(locator, "*KEY*", "Bad wall clock <timeExpression>."); } reporter.logInfo(m); }
public void fatalError(SAXParseException e) { // don't terminated validation on validation error getReporter().logError(e); } public void warning(SAXParseException e) {