/** * Creates a new RedwoodChannels object, concatenating the channels from * this RedwoodChannels with some additional channels. * @param moreChannelNames The channel names to also include * @return A RedwoodChannels representing the current and new channels. */ public RedwoodChannels channels(Object... moreChannelNames) { //(copy array) Object[] result = new Object[channelNames.length + moreChannelNames.length]; System.arraycopy(channelNames, 0, result, 0, channelNames.length); System.arraycopy(moreChannelNames, 0, result, channelNames.length, moreChannelNames.length); //(create channels) return new RedwoodChannels(result); }
public void fatal(Object... objs) { log(Util.revConcat(objs, ERR, FORCE)); System.exit(1); } }
/** * {@inheritDoc} */ @Override @SuppressWarnings("unchecked") public void prettyLog(RedwoodChannels channels, String description) { Redwood.startTrack(description); // sort keys by class name List<Class> sortedKeys = new ArrayList<>(this.keySet()); sortedKeys.sort(Comparator.comparing(Class::getCanonicalName)); // log key/value pairs for (Class key : sortedKeys) { String keyName = key.getCanonicalName().replace("class ", ""); Object value = this.get(key); if (PrettyLogger.dispatchable(value)) { PrettyLogger.log(channels, keyName, value); } else { channels.logf("%s = %s", keyName, value); } } Redwood.endTrack(description); }
/** * Returns a validating XML parser given an XSD (not DTD!). * * @param schemaFile File wit hXML schema * @return An XML parser in the form of a DocumentBuilder */ public static DocumentBuilder getValidatingXmlParser(File schemaFile) { DocumentBuilder db = null; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = factory.newSchema(schemaFile); dbf.setSchema(schema); db = dbf.newDocumentBuilder(); db.setErrorHandler(new SAXErrorHandler()); } catch (ParserConfigurationException e) { log.warnf("%s: Unable to create XML parser\n", XMLUtils.class.getName()); log.warn(e); } catch (SAXException e) { log.warnf("%s: XML parsing exception while loading schema %s\n", XMLUtils.class.getName(),schemaFile.getPath()); log.warn(e); } catch(UnsupportedOperationException e) { log.warnf("%s: API error while setting up XML parser. Check your JAXP version\n", XMLUtils.class.getName()); log.warn(e); } return db; }
/** * Returns a validating XML parser given an XSD (not DTD!). * * @param schemaFile File wit hXML schema * @return An XML parser in the form of a DocumentBuilder */ public static DocumentBuilder getValidatingXmlParser(File schemaFile) { DocumentBuilder db = null; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = factory.newSchema(schemaFile); dbf.setSchema(schema); db = dbf.newDocumentBuilder(); db.setErrorHandler(new SAXErrorHandler()); } catch (ParserConfigurationException e) { log.warnf("%s: Unable to create XML parser\n", XMLUtils.class.getName()); log.warn(e); } catch (SAXException e) { log.warnf("%s: XML parsing exception while loading schema %s\n", XMLUtils.class.getName(),schemaFile.getPath()); log.warn(e); } catch(UnsupportedOperationException e) { log.warnf("%s: API error while setting up XML parser. Check your JAXP version\n", XMLUtils.class.getName()); log.warn(e); } return db; }
/** * Returns a non-validating XML parser. The parser ignores both DTDs and XSDs. * * @return An XML parser in the form of a DocumentBuilder */ public static DocumentBuilder getXmlParser() { DocumentBuilder db = null; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); //Disable DTD loading and validation //See http://stackoverflow.com/questions/155101/make-documentbuilder-parse-ignore-dtd-references dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); db = dbf.newDocumentBuilder(); db.setErrorHandler(new SAXErrorHandler()); } catch (ParserConfigurationException e) { log.warnf("%s: Unable to create XML parser\n", XMLUtils.class.getName()); log.warn(e); } catch(UnsupportedOperationException e) { log.warnf("%s: API error while setting up XML parser. Check your JAXP version\n", XMLUtils.class.getName()); log.warn(e); } return db; }
/** * Returns a non-validating XML parser. The parser ignores both DTDs and XSDs. * * @return An XML parser in the form of a DocumentBuilder */ public static DocumentBuilder getXmlParser() { DocumentBuilder db = null; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); //Disable DTD loading and validation //See http://stackoverflow.com/questions/155101/make-documentbuilder-parse-ignore-dtd-references dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); db = dbf.newDocumentBuilder(); db.setErrorHandler(new SAXErrorHandler()); } catch (ParserConfigurationException e) { log.warnf("%s: Unable to create XML parser\n", XMLUtils.class.getName()); log.warn(e); } catch(UnsupportedOperationException e) { log.warnf("%s: API error while setting up XML parser. Check your JAXP version\n", XMLUtils.class.getName()); log.warn(e); } return db; }
private static <T> void log(RedwoodChannels channels, String description, T[] array) { Redwood.startTrack(description); if (array == null) { channels.log("(array is null)"); } else if (array.length == 0) { channels.log("(empty)"); } else { int index = 0; for (T item : array) { if (dispatchable(item)) { log(channels, "Index " + index, item); } else { channels.logf("Index %d: %s", index, item); } index++; } } Redwood.endTrack(description); }
private static <T> void log(RedwoodChannels channels, String description, T[] array) { Redwood.startTrack(description); if (array == null) { channels.log("(array is null)"); } else if (array.length == 0) { channels.log("(empty)"); } else { int index = 0; for (T item : array) { if (dispatchable(item)) { log(channels, "Index " + index, item); } else { channels.logf("Index %d: %s", index, item); } index++; } } Redwood.endTrack(description); } }
private static <T> void log(RedwoodChannels channels, String description, Iterable<T> iterable) { Redwood.startTrack(description); if (iterable == null) { channels.log("(iterable is null)"); } else { int index = 0; for (T item : iterable) { if (dispatchable(item) && item != iterable) { log(channels, "Index " + index, item); } else { channels.logf("Index %d: %s", index, item == iterable ? "...<infinite loop>" : item); } index++; } if (index == 0) { channels.log("(empty)"); } } Redwood.endTrack(description); }
public static RedwoodChannels channels(Object... channels) { return new RedwoodChannels(channels); }
public static RedwoodChannels channels(Object... channels) { return new RedwoodChannels(channels); }
/** * Creates a new RedwoodChannels object, concatenating the channels from * this RedwoodChannels with some additional channels. * @param moreChannelNames The channel names to also include * @return A RedwoodChannels representing the current and new channels. */ public RedwoodChannels channels(Object... moreChannelNames) { //(copy array) Object[] result = new Object[channelNames.length + moreChannelNames.length]; System.arraycopy(channelNames, 0, result, 0, channelNames.length); System.arraycopy(moreChannelNames, 0, result, channelNames.length, moreChannelNames.length); //(create channels) return new RedwoodChannels(result); }
/** * Creates a new RedwoodChannels object, concatenating the channels from * this RedwoodChannels with some additional channels. * @param moreChannelNames The channel names to also include * @return A RedwoodChannels representing the current and new channels. */ public RedwoodChannels channels(Object... moreChannelNames) { //(copy array) Object[] result = new Object[channelNames.length + moreChannelNames.length]; System.arraycopy(channelNames, 0, result, 0, channelNames.length); System.arraycopy(moreChannelNames, 0, result, channelNames.length, moreChannelNames.length); //(create channels) return new RedwoodChannels(result); }
/** * Creates a new RedwoodChannels object, concatenating the channels from * this RedwoodChannels with some additional channels. * @param moreChannelNames The channel names to also include * @return A RedwoodChannels representing the current and new channels. */ public RedwoodChannels channels(Object... moreChannelNames) { //(copy array) Object[] result = new Object[channelNames.length + moreChannelNames.length]; System.arraycopy(channelNames, 0, result, 0, channelNames.length); System.arraycopy(moreChannelNames, 0, result, channelNames.length, moreChannelNames.length); //(create channels) return new RedwoodChannels(result); }
/** Log to the debug channel. @see RedwoodChannels#logf(Flag, String, Object...) */ public void debugf(String format, Object... args) { debug((Supplier<String>) () -> new Formatter().format(format, args).toString()); }
/** Log to the debug channel. @see RedwoodChannels#logf(Flag, String, Object...) */ public void debugf(String format, Object... args) { debug((Supplier<String>) () -> new Formatter().format(format, args).toString()); }
/** * Create an object representing a group of channels. * {@link RedwoodChannels} contains a more complete description. * * @see RedwoodChannels */ public static RedwoodChannels channels(Object... channelNames) { return new RedwoodChannels(channelNames); }
/** * Create an object representing a group of channels. * {@link RedwoodChannels} contains a more complete description. * * @see RedwoodChannels */ public static RedwoodChannels channels(Object... channelNames) { return new RedwoodChannels(channelNames); }
/** * Create an object representing a group of channels. * {@link RedwoodChannels} contains a more complete description. * * @see RedwoodChannels */ public static RedwoodChannels channels(Object... channelNames) { return new RedwoodChannels(channelNames); }