|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.jmatchparser.template.Parser
public class Parser
A parser for MatchTemplate
s. Each parser can be used for parsing
exactly one file/input stream; the templates can be reused for parsing more
than one file.
Constructor Summary | |
---|---|
Parser(Class<?> clazz,
String resourceName,
String encoding)
Create a new parser using a new MatchTemplate . |
|
Parser(File file,
String encoding)
Create a new parser using a new MatchTemplate . |
|
Parser(MatchTemplate.MatchTemplateResolver resolver,
String templateName,
BufferedReader br)
Create a new parser using a new MatchTemplate . |
|
Parser(MatchTemplate template)
Create a new parser using an existing MatchTemplate . |
|
Parser(String filename,
String encoding)
Create a new parser using a new MatchTemplate . |
Method Summary | ||
---|---|---|
void |
addCallback(String name,
CallbackFunction function)
Add a callback function to this parser. |
|
static void |
convertDOMToCSV(Document doc,
AbstractCSVWriter[] writers)
Convert a DOM Document to one or more CSV files. |
|
void |
parse(BufferedReader reader,
Element target)
Parse a buffered reader and add the resulting XML to a DOM Element . |
|
Document |
parse(BufferedReader reader,
String toplevelTag)
Parse a buffered reader and create a new DOM Document from the
resulting XML. |
|
|
parse(BufferedReader reader,
Unmarshaller unmarshaller,
Class<T> clazz)
Parse a buffered reader using a JAXB Unmarshaller for parsing the
resulting XML. |
|
void |
parse(CharSequence file,
Element target)
Parse a String or other char sequence and add the resulting XML
to a DOM Element . |
|
Document |
parse(CharSequence file,
String toplevelTag)
Parse a String or other char sequence and create a new DOM
Document from the resulting XML. |
|
|
parse(CharSequence file,
Unmarshaller unmarshaller,
Class<T> clazz)
Parse a String or other char sequence using a JAXB
Unmarshaller for parsing the resulting XML. |
|
void |
parse(InputStream stream,
String encoding,
Element target)
Parse an input stream and add the resulting XML to a DOM Element . |
|
Document |
parse(InputStream stream,
String encoding,
String toplevelTag)
Parse an input stream and create a new DOM Document from the
resulting XML. |
|
|
parse(InputStream stream,
String encoding,
Unmarshaller unmarshaller,
Class<T> clazz)
Parse an input stream using a JAXB Unmarshaller for parsing the
resulting XML. |
|
void |
parseToCSV(BufferedReader reader,
AbstractCSVWriter writer)
Parse a buffered reader to a CSV file. |
|
void |
parseToCSV(CharSequence file,
AbstractCSVWriter writer)
Parse a String or other char sequence to a CSV file. |
|
void |
parseToCSV(InputStream stream,
String encoding,
AbstractCSVWriter writer)
Parse an input stream to a CSV file. |
|
void |
setDebugStream(PrintStream debugStream)
Set the debug stream where DEBUGWRITE and
DUMPLINE commands write to. |
|
void |
setLocal(String name,
String value)
Set a local variable in this parser. |
|
void |
setParserName(String parserName)
Set the name of this parser. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Parser(String filename, String encoding) throws IOException
MatchTemplate
.
filename
- Name of the fileencoding
- File encoding
IOException
MatchTemplate.MatchTemplate(String, String, Formatter...)
public Parser(File file, String encoding) throws IOException
MatchTemplate
.
file
- The fileencoding
- File encoding
IOException
MatchTemplate.MatchTemplate(File, String, Formatter...)
public Parser(Class<?> clazz, String resourceName, String encoding) throws IOException
MatchTemplate
.
clazz
- Class to use as a base for finding the resourceresourceName
- Name of the resourceencoding
- File encoding
IOException
MatchTemplate.MatchTemplate(Class, String, String, Formatter...)
public Parser(MatchTemplate.MatchTemplateResolver resolver, String templateName, BufferedReader br) throws IOException
MatchTemplate
.
resolver
- Match template resolver for resolving additional template
names ($INCLUDE), optionaltemplateName
- Name of the templatebr
- Reader to read the template from
IOException
MatchTemplate.MatchTemplate(MatchTemplate.MatchTemplateResolver,
String, BufferedReader, Formatter...)
public Parser(MatchTemplate template)
MatchTemplate
.
template
- The match template to useMethod Detail |
---|
public void setLocal(String name, String value)
name
- Name of the variablevalue
- Value of the variablepublic void setParserName(String parserName)
public <T> T parse(InputStream stream, String encoding, Unmarshaller unmarshaller, Class<T> clazz) throws ParserException, ParserConfigurationException, IOException, JAXBException
Unmarshaller
for parsing the
resulting XML.
T
- Type of the unmarshalled objectstream
- Input stream to parseencoding
- Encoding of the streamunmarshaller
- Unmarshaller
to useclazz
- Class of the unmarshalled object
ParserException
ParserConfigurationException
IOException
JAXBException
public Document parse(InputStream stream, String encoding, String toplevelTag) throws ParserException, ParserConfigurationException, IOException
Document
from the
resulting XML.
stream
- Input stream to parseencoding
- Encoding of the streamtoplevelTag
- Tag of the document element to use in the new document
Document
ParserException
ParserConfigurationException
IOException
public void parse(InputStream stream, String encoding, Element target) throws ParserException, IOException
Element
.
stream
- Input stream to parseencoding
- Encoding of the streamtarget
- Element to add the XML to
ParserException
IOException
public <T> T parse(BufferedReader reader, Unmarshaller unmarshaller, Class<T> clazz) throws ParserException, ParserConfigurationException, IOException, JAXBException
Unmarshaller
for parsing the
resulting XML.
T
- Type of the unmarshalled objectreader
- BufferedReader
to parseunmarshaller
- Unmarshaller
to useclazz
- Class of the unmarshalled object
ParserException
ParserConfigurationException
IOException
JAXBException
public Document parse(BufferedReader reader, String toplevelTag) throws ParserException, ParserConfigurationException, IOException
Document
from the
resulting XML.
reader
- BufferedReader
to parsetoplevelTag
- Tag of the document element to use in the new document
Document
ParserException
ParserConfigurationException
IOException
public void parse(BufferedReader reader, Element target) throws ParserException, IOException
Element
.
reader
- BufferedReader
to parsetarget
- Element to add the XML to
ParserException
IOException
public <T> T parse(CharSequence file, Unmarshaller unmarshaller, Class<T> clazz) throws ParserException, ParserConfigurationException, IOException, JAXBException
String
or other char sequence using a JAXB
Unmarshaller
for parsing the resulting XML.
T
- Type of the unmarshalled objectfile
- CharSequence
to parseunmarshaller
- Unmarshaller
to useclazz
- Class of the unmarshalled object
ParserException
ParserConfigurationException
IOException
JAXBException
public Document parse(CharSequence file, String toplevelTag) throws ParserException, ParserConfigurationException, IOException
String
or other char sequence and create a new DOM
Document
from the resulting XML.
file
- CharSequence
to parsetoplevelTag
- Tag of the document element to use in the new document
Document
ParserException
ParserConfigurationException
IOException
public void parse(CharSequence file, Element target) throws ParserException, IOException
String
or other char sequence and add the resulting XML
to a DOM Element
.
file
- CharSequence
to parsetarget
- Element to add the XML to
ParserException
IOException
public void parseToCSV(InputStream stream, String encoding, AbstractCSVWriter writer) throws ParserConfigurationException, ParserException, IOException
stream
- Input stream to parseencoding
- Encoding of the streamwriter
- AbstractCSVWriter
to write the file to
ParserConfigurationException
ParserException
IOException
public void parseToCSV(BufferedReader reader, AbstractCSVWriter writer) throws ParserConfigurationException, ParserException, IOException
reader
- BufferedReader
to parsewriter
- AbstractCSVWriter
to write the file to
ParserConfigurationException
ParserException
IOException
public void parseToCSV(CharSequence file, AbstractCSVWriter writer) throws ParserConfigurationException, ParserException, IOException
String
or other char sequence to a CSV file.
file
- CharSequence
to parsewriter
- AbstractCSVWriter
to write the file to
ParserConfigurationException
ParserException
IOException
public static void convertDOMToCSV(Document doc, AbstractCSVWriter[] writers) throws IOException
Document
to one or more CSV files. Each child
element of the document element is a row, each child element of a row is
a cell. Rows may have an attribute @file
which contains the
zero-based index of the writer to save this row to (zero by default); all
other attributes are ignored.
doc
- Document
to parsewriters
- AbstractCSVWriter
(s) to write the file(s) to
IOException
public void addCallback(String name, CallbackFunction function)
name
- Name of the functionfunction
- Function to addpublic void setDebugStream(PrintStream debugStream)
DEBUGWRITE
and
DUMPLINE
commands write to.
debugStream
- New debug stream to use
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |