use of javax.xml.parsers.SAXParser in project tomcat by apache.
the class JspDocumentParser method parse.
/*
* Parses a JSP document by responding to SAX events.
*
* @throws JasperException
*/
public static Node.Nodes parse(ParserController pc, String path, Jar jar, Node parent, boolean isTagFile, boolean directivesOnly, String pageEnc, String jspConfigPageEnc, boolean isEncodingSpecifiedInProlog, boolean isBomPresent) throws JasperException {
JspDocumentParser jspDocParser = new JspDocumentParser(pc, path, isTagFile, directivesOnly);
Node.Nodes pageNodes = null;
try {
// Create dummy root and initialize it with given page encodings
Node.Root dummyRoot = new Node.Root(null, parent, true);
dummyRoot.setPageEncoding(pageEnc);
dummyRoot.setJspConfigPageEncoding(jspConfigPageEnc);
dummyRoot.setIsEncodingSpecifiedInProlog(isEncodingSpecifiedInProlog);
dummyRoot.setIsBomPresent(isBomPresent);
jspDocParser.current = dummyRoot;
if (parent == null) {
jspDocParser.addInclude(dummyRoot, jspDocParser.pageInfo.getIncludePrelude());
} else {
jspDocParser.isTop = false;
}
jspDocParser.isValidating = false;
// Parse the input
SAXParser saxParser = getSAXParser(false, jspDocParser);
InputSource source = JspUtil.getInputSource(path, jar, jspDocParser.ctxt);
try {
saxParser.parse(source, jspDocParser);
} catch (EnableDTDValidationException e) {
saxParser = getSAXParser(true, jspDocParser);
jspDocParser.isValidating = true;
try {
source.getByteStream().close();
} catch (IOException e2) {
// ignore
}
source = JspUtil.getInputSource(path, jar, jspDocParser.ctxt);
saxParser.parse(source, jspDocParser);
} finally {
try {
source.getByteStream().close();
} catch (IOException e) {
// ignore
}
}
if (parent == null) {
jspDocParser.addInclude(dummyRoot, jspDocParser.pageInfo.getIncludeCoda());
}
// Create Node.Nodes from dummy root
pageNodes = new Node.Nodes(dummyRoot);
} catch (IOException ioe) {
jspDocParser.err.jspError(ioe, "jsp.error.data.file.read", path);
} catch (SAXParseException e) {
jspDocParser.err.jspError(new Mark(jspDocParser.ctxt, path, e.getLineNumber(), e.getColumnNumber()), e, e.getMessage());
} catch (Exception e) {
jspDocParser.err.jspError(e, "jsp.error.data.file.processing", path);
}
return pageNodes;
}
use of javax.xml.parsers.SAXParser in project cogtool by cogtool.
the class ObjectLoader method load.
/**
* Based on the serialization contained by the given input source
* and the initial aggregate loader (that is, for top-level objects
* that are themselves aggregates), reconstitute the top-level objects
* and return them in an ordered collection.
* <p>
* The caller is responsible for recovering any resources associated
* with the input source (such as <code>close()</code>).
*
* @param src the previously saved serialization of a sequence of objects
* @param initialLoader the loader to use for creating top-level aggregate
* objects; it may be <code>null</code> if no
* top-level object is an aggregate
* @throws ParserConfigurationException based on the SAX parsing
* @throws SAXException based on the SAX parsing
* @throws java.io.IOException if the source generates one
* during read calls generated by the SAX parser
* @throws java.io.IOException
*/
@SuppressWarnings("unchecked")
public List<Object> load(InputSource src, IAggregateLoader initialLoader) throws ParserConfigurationException, SAXException, java.io.IOException {
activeLoaders.push((initialLoader != null) ? initialLoader : AAggregateLoader.ONLY);
// A List will keep the reconstituted objects in order
pendingObjects.push(new ArrayList<Object>());
pushObjectState(IN_COLLECTION);
SAXParser p = parserFactory.newSAXParser();
// The List is populated during the parse
p.parse(src, this);
return (List<Object>) pendingObjects.peek();
}
use of javax.xml.parsers.SAXParser in project OpenPanodroid by duerrfk.
the class RESTRequestorXML method parseResponse.
@Override
protected void parseResponse(InputStream is, int contentLength) {
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
DefaultHandler saxHandler = createSAXHandler();
if (saxHandler == null) {
setSuccessState(false);
} else {
parser.parse(is, saxHandler);
}
} catch (Exception ex) {
setErrorMsg(ex.getLocalizedMessage());
setSuccessState(false);
}
}
use of javax.xml.parsers.SAXParser in project che by eclipse.
the class RefactoringSessionReader method createParser.
/**
* Creates a new parser from the specified factory.
*
* @param factory
* the parser factoring to use
* @return the created parser
* @throws ParserConfigurationException
* if no parser is available with the given configuration
* @throws SAXException
* if an error occurs while creating the parser
*/
private SAXParser createParser(final SAXParserFactory factory) throws ParserConfigurationException, SAXException {
final SAXParser parser = factory.newSAXParser();
final XMLReader reader = parser.getXMLReader();
try {
//$NON-NLS-1$
reader.setFeature("http://xml.org/sax/features/validation", false);
//$NON-NLS-1$
reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
} catch (SAXNotRecognizedException exception) {
// Do nothing
} catch (SAXNotSupportedException exception) {
// Do nothing
}
return parser;
}
use of javax.xml.parsers.SAXParser in project che by eclipse.
the class CheCodeFormatterOptions method getCheDefaultSettings.
private Map<String, String> getCheDefaultSettings() {
SAXParserFactory factory = SAXParserFactory.newInstance();
XMLParser parserXML = new XMLParser();
try {
SAXParser parser = factory.newSAXParser();
parser.parse(getClass().getResourceAsStream(DEFAULT_CODESTYLE), parserXML);
} catch (ParserConfigurationException | SAXException | IOException e) {
LOG.error("It is not possible to parse file " + DEFAULT_CODESTYLE, e);
}
return parserXML.getSettings();
}
Aggregations