public void generate() throws IOException, SAXException, ProcessingException {
// access input data, using specified encoding if any
InputStreamReader in = null;
try {
if (this.inputSource.getInputStream() == null) {
throw new ProcessingException("Source '" + this.inputSource.getURI() + "' not found");
}
if (encoding != null) {
in = new InputStreamReader(this.inputSource.getInputStream(), encoding);
} else {
in = new InputStreamReader(this.inputSource.getInputStream());
}
} catch (SourceException se) {
throw new ProcessingException("Error during resolving of '" + this.source + "'.", se);
}
// setup a Locator in case parser detects input errors
final LocatorImpl locator = new LocatorImpl();
locator.setSystemId(this.inputSource.getURI());
locator.setLineNumber(1);
locator.setColumnNumber(1);
contentHandler.setDocumentLocator(locator);
// start parsing, read and process all input lines
parser.startDocument(contentHandler);
LineNumberReader reader = new LineNumberReader(in);
String line, newline = null;
while (true) {
if (newline == null) {
line = reader.readLine();
} else {
line = newline;
}
if (line == null) {
break;
}
newline = reader.readLine();
locator.setLineNumber(reader.getLineNumber());
locator.setColumnNumber(1);
parser.processLine(line);
if (newline == null) {
break;
}
}
// done parsing
parser.endDocument();
}
|
public void setup(SourceResolver resolver,
Map objectmodel,
String src,
Parameters parameters) throws IOException, SAXException, ProcessingException {
super.setup(resolver, objectmodel, src, parameters);
try {
encoding = parameters.getParameter("encoding", null);
preserveSpace = parameters.getParameterAsBoolean("preserve-space",false);
validTagnameChars = parameters.getParameter("valid-tagname-chars",null);
inputSource = resolver.resolveURI(src);
final SimpleSlopParser ssp = new SimpleSlopParser();
parser = ssp;
ssp.setPreserveWhitespace(preserveSpace);
ssp.setValidTagnameChars(validTagnameChars);
} catch (SourceException se) {
throw new ProcessingException("Error during resolving of '" + src + "'.", se);
}
}
Set the SourceResolver, objectModel Map, the source and sitemap
Parameters used to process the request. |