Package net.loomchild.segment.util
Class Util
java.lang.Object
net.loomchild.segment.util.Util
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Patterncompile(SrxDocument document, String regex) static voidCopies the whole content of a reader to a writer.static StringChanges unlimited length pattern to limited length pattern.static JAXBContextgetContext(Class<?>... classesToBeBound) static JAXBContextgetContext(String context) static JAXBContextgetContext(String context, ClassLoader classLoader) static FileInputStreamgetFileInputStream(String fileName) Opens a file for reading and returns input stream associated with it.static FileOutputStreamgetFileOutputStream(String fileName) Opens a file for writing and returns output stream associated with it.static ManifestgetJarManifest(Class<?> klass) Returns Manifest of a jar containing given class.static <T> TgetParameter(Object value, T defaultValue) Returns value if it is not null or default value if it is null.static ReadergetReader(InputStream inputStream) static InputStreamgetResourceStream(String name) Finds a resource using system classloader and returns it as input stream.static SchemaReads a XML schema from given reader.static SchemaReads a XML schema from given readers.static Sourcestatic TemplatesgetTemplates(Reader reader) Returns XML transform templates from given reader containing XSLT stylesheet.static WritergetWriter(OutputStream outputStream) static XMLReaderstatic XMLReadergetXmlReader(Schema schema) Returns XMLReader validating against given XML schema.static StringReads whole contents of a reader to a string.static StringremoveBlockQuotes(String pattern) Replaces block quotes in regular expressions with normal quotes.static StringremoveCapturingGroups(String pattern) Replaces capturing groups with non-capturing groups in the given regular expression.static voidPerforms XSLT transformation.static voidPerforms XSLT transformation.static voidPerforms XML schema validation and XSLT transformation.static voidtransform(Templates templates, Schema schema, Reader reader, Writer writer, Map<String, Object> parameterMap) Performs XML schema validation and XSLT transformation.
-
Field Details
-
READ_BUFFER_SIZE
public static final int READ_BUFFER_SIZE- See Also:
-
MANIFEST_PATH
- See Also:
-
STAR_PATTERN
-
PLUS_PATTERN
-
RANGE_PATTERN
-
CAPTURING_GROUP_PATTERN
-
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
getReader
- Parameters:
inputStream-- Returns:
- UTF-8 encoded reader from given input stream
- Throws:
IORuntimeException- if IO error occurs
-
getWriter
- Parameters:
outputStream-- Returns:
- UTF-8 encoded writer to a given output stream
- Throws:
IORuntimeException- if IO error occurs
-
getFileInputStream
Opens a file for reading and returns input stream associated with it.- Parameters:
fileName-- Returns:
- input stream
- Throws:
IORuntimeException- if IO error occurs
-
getFileOutputStream
Opens a file for writing and returns output stream associated with it.- Parameters:
fileName-- Returns:
- output stream
- Throws:
IORuntimeException- if IO error occurs
-
getResourceStream
Finds a resource using system classloader and returns it as input stream.- Parameters:
name- resource name- Returns:
- resource input stream
- Throws:
ResourceNotFoundException- if resource can not be found- See Also:
-
readAll
Reads whole contents of a reader to a string.- Parameters:
reader-- Returns:
- a string containing reader contents
- Throws:
IORuntimeException- on IO error
-
copyAll
Copies the whole content of a reader to a writer.- Parameters:
reader-writer-- Throws:
IORuntimeException- on IO error
-
getJarManifest
Returns Manifest of a jar containing given class. If class is not in a jar, throwsResourceNotFoundException.- Parameters:
klass- class- Returns:
- manifest
- Throws:
ResourceNotFoundException- if manifest was not found
-
getXmlReader
Returns XMLReader validating against given XML schema. The reader ignores DTD defined in XML file.- Parameters:
schema-- Returns:
- XMLReader
-
getXmlReader
- Returns:
- XMLReader without XML schema associated with it
- See Also:
-
getSchema
Reads a XML schema from given reader.- Parameters:
reader-- Returns:
- XML Schema
-
getSchema
Reads a XML schema from given readers. Schema files can depend on one another.- Parameters:
readerArray- readers containing XML schemas- Returns:
- XML Schema object
-
getSource
- Parameters:
reader-schema- XML schema- Returns:
- XML source from given reader and with given schema
-
getContext
- Parameters:
context- context package name- Returns:
- JAXB context
-
getContext
- Parameters:
context- context package nameclassLoader- class loader used to load classes from the context- Returns:
- JAXB context; loads the classes using given classloader
-
getContext
- Parameters:
classesToBeBound-- Returns:
- JAXBContext according to classes to bind Dependency classes are also loaded automatically.
-
getTemplates
Returns XML transform templates from given reader containing XSLT stylesheet.- Parameters:
reader-- Returns:
- templates; they can be reused many times to perform the transformation
-
transform
public static void transform(Templates templates, Schema schema, Reader reader, Writer writer, Map<String, Object> parameterMap) Performs XML schema validation and XSLT transformation.- Parameters:
templates- XSLT stylesheetschema- XML schema to validate againstreader- reader with input documentwriter- writer which will be used to write outputparameterMap- transformation parameters
-
transform
Performs XML schema validation and XSLT transformation.- Parameters:
templates- XSLT stylesheetschema- XML schema to validate againstreader- reader with input documentwriter- writer which will be used to write output
-
transform
public static void transform(Templates templates, Reader reader, Writer writer, Map<String, Object> parameterMap) Performs XSLT transformation.- Parameters:
templates- XSLT stylesheetreader- reader with input documentwriter- writer which will be used to write outputparameterMap- transformation parameters
-
transform
Performs XSLT transformation.- Parameters:
templates- XSLT stylesheetreader- reader with input documentwriter- writer which will be used to write output
-
removeBlockQuotes
Replaces block quotes in regular expressions with normal quotes. For example "\Qabc\E" will be replace with "\a\b\c".- Parameters:
pattern-- Returns:
- pattern with replaced block quotes
-
finitize
Changes unlimited length pattern to limited length pattern. It is done by replacing constructs with "*" and "+" symbols with their finite counterparts - "{0,n}" and {1,n}. As a side effect block quotes are replaced with normal quotes by usingremoveBlockQuotes(String).- Parameters:
pattern- pattern to be finitizedinfinity- "n" number- Returns:
- limited length pattern
-
compile
-
removeCapturingGroups
Replaces capturing groups with non-capturing groups in the given regular expression. As a side effect block quotes are replaced with normal quotes by usingremoveBlockQuotes(String).- Parameters:
pattern-- Returns:
- modified pattern
-
getParameter
Returns value if it is not null or default value if it is null. Automatically cast value to the same type as default value.- Parameters:
value- objectdefaultValue- default value.- Returns:
- object value or default value if object value is null
- Throws:
ClassCastException- when value cannot be cast to default value type
-
getEmptyParameterMap
-