本文整理汇总了Java中org.xml.sax.XMLReader.setErrorHandler方法的典型用法代码示例。如果您正苦于以下问题:Java XMLReader.setErrorHandler方法的具体用法?Java XMLReader.setErrorHandler怎么用?Java XMLReader.setErrorHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xml.sax.XMLReader
的用法示例。
在下文中一共展示了XMLReader.setErrorHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSAXParser
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
private static SAXParser getSAXParser(
boolean validating,
JspDocumentParser jspDocParser)
throws Exception {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
// Preserve xmlns attributes
factory.setFeature(
"http://xml.org/sax/features/namespace-prefixes",
true);
factory.setValidating(validating);
//factory.setFeature(
// "http://xml.org/sax/features/validation",
// validating);
// Configure the parser
SAXParser saxParser = factory.newSAXParser();
XMLReader xmlReader = saxParser.getXMLReader();
xmlReader.setProperty(LEXICAL_HANDLER_PROPERTY, jspDocParser);
xmlReader.setErrorHandler(jspDocParser);
return saxParser;
}
示例2: buildItemList
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
@Override
protected List<FeedItem> buildItemList() throws SAXException, ParserConfigurationException, IOException {
XMLReader reader = XMLUtil.createXMLReader( false, true );
FeedHandler handler = new FeedHandler( getMaxItemCount() );
reader.setContentHandler( handler );
reader.setEntityResolver( org.openide.xml.EntityCatalog.getDefault() );
reader.setErrorHandler( new ErrorCatcher() );
reader.parse( findInputSource(new URL(url1)) );
ArrayList<FeedItem> res = new ArrayList<FeedItem>( 2*getMaxItemCount() );
res.addAll( handler.getItemList() );
handler = new FeedHandler( getMaxItemCount() );
reader.setContentHandler( handler );
reader.parse( findInputSource(new URL(url2)) );
res.addAll( handler.getItemList() );
List<FeedItem> items = sortNodes( res );
if( items.size() > getMaxItemCount() ) {
items = items.subList( 0, getMaxItemCount() );
}
return items;
}
示例3: readDriverFromFile
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
private static JDBCDriver readDriverFromFile(FileObject fo) throws IOException, MalformedURLException {
Handler handler = new Handler();
// parse the XM file
try {
XMLReader reader = XMLUtil.createXMLReader();
InputSource is = new InputSource(fo.getInputStream());
is.setSystemId(fo.toURL().toExternalForm());
reader.setContentHandler(handler);
reader.setErrorHandler(handler);
reader.setEntityResolver(EntityCatalog.getDefault());
reader.parse(is);
} catch (SAXException ex) {
throw new IOException(ex.getMessage());
}
// read the driver from the handler
URL[] urls = new URL[handler.urls.size()];
int j = 0;
for (Iterator i = handler.urls.iterator(); i.hasNext(); j++) {
urls[j] = new URL((String)i.next());
}
if (checkClassPathDrivers(handler.clazz, urls) == false) {
return null;
}
if (handler.displayName == null) {
handler.displayName = handler.name;
}
return JDBCDriver.create(handler.name, handler.displayName, handler.clazz, urls);
}
示例4: parse
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
/**
* The recognizer entry method taking an InputSource.
* @param input InputSource to be parsed.
* @throws java.io.IOException on I/O error.
* @throws SAXException propagated exception thrown by a DocumentHandler.
* @throws javax.xml.parsers.ParserConfigurationException a parser satisfining requested configuration can not be created.
* @throws javax.xml.parsers.FactoryConfigurationRrror if the implementation can not be instantiated.
*
*/
public void parse(final InputSource input) throws SAXException, ParserConfigurationException, IOException {
if (used.getAndSet(true)) {
throw new IllegalStateException("The LibraryDeclarationParser was already used, create a new instance"); //NOI18N
}
try {
final XMLReader parser = XMLUtil.createXMLReader(false, true);
parser.setContentHandler(this);
parser.setErrorHandler(getDefaultErrorHandler());
parser.setEntityResolver(this);
parser.parse(input);
} finally {
//Recover recognizer internal state from exceptions to be reusable
if (!context.empty()) {
context.clear();
}
if (buffer.length() > 0) {
buffer.delete(0, buffer.length());
}
expectedNS = null;
}
}
示例5: loadAttributesFromXml
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
private EntryAttributes loadAttributesFromXml(File entriesFile) throws IOException, SAXException {
//Parse the entries file
XMLReader saxReader = XMLUtil.createXMLReader();
XmlEntriesHandler xmlEntriesHandler = new XmlEntriesHandler();
saxReader.setContentHandler(xmlEntriesHandler);
saxReader.setErrorHandler(xmlEntriesHandler);
InputStream inputStream = new java.io.FileInputStream(entriesFile);
try {
saxReader.parse(new InputSource(inputStream));
} catch (SAXException ex) {
throw ex;
} finally {
inputStream.close();
}
return xmlEntriesHandler.getEntryAttributes();
}
示例6: main
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
public static void main(String[] argv) throws Exception {
XMLReader xr = XMLReaderFactory.createXMLReader();
BugCollection bugCollection = new SortedBugCollection();
Project project = new Project();
SAXBugCollectionHandler handler = new SAXBugCollectionHandler(bugCollection, project);
xr.setContentHandler(handler);
xr.setErrorHandler(handler);
// Parse each file provided on the
// command line.
for (int i = 0; i < argv.length; i++) {
FileReader r = new FileReader(argv[i]);
xr.parse(new InputSource(r));
}
}
示例7: instanceCreate
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
@Override
public Object instanceCreate() throws java.io.IOException, ClassNotFoundException {
synchronized (this) {
Object o = refConnection.get();
if (o != null) {
return o;
}
XMLDataObject obj = getHolder();
if (obj == null) {
return null;
}
FileObject connectionFO = obj.getPrimaryFile();
Handler handler = new Handler(connectionFO.getNameExt());
try {
XMLReader reader = XMLUtil.createXMLReader();
InputSource is = new InputSource(obj.getPrimaryFile().getInputStream());
is.setSystemId(connectionFO.toURL().toExternalForm());
reader.setContentHandler(handler);
reader.setErrorHandler(handler);
reader.setEntityResolver(EntityCatalog.getDefault());
reader.parse(is);
} catch (SAXException ex) {
Exception x = ex.getException();
LOGGER.log(Level.FINE, "Cannot read " + obj + ". Cause: " + ex.getLocalizedMessage(), ex);
if (x instanceof java.io.IOException) {
throw (IOException)x;
} else {
throw new java.io.IOException(ex.getMessage());
}
}
DatabaseConnection inst = createDatabaseConnection(handler);
refConnection = new WeakReference<>(inst);
attachListener();
return inst;
}
}
示例8: doReadXML
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
private void doReadXML(InputStream in, Project project) throws IOException, DocumentException {
checkInputStream(in);
try {
SAXBugCollectionHandler handler = new SAXBugCollectionHandler(this, project);
// FIXME: for now, use dom4j's XML parser
XMLReader xr = new org.dom4j.io.aelfred.SAXDriver();
xr.setContentHandler(handler);
xr.setErrorHandler(handler);
Reader reader = new InputStreamReader(in);
xr.parse(new InputSource(reader));
} catch (SAXException e) {
// FIXME: throw SAXException from method?
throw new DocumentException("Parse error", e);
}
// Presumably, project is now up-to-date
project.setModified(false);
}
示例9: testEHFatal
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
/**
* Error Handler to capture all error events to output file. Verifies the
* output file is same as golden file.
*
* @throws Exception If any errors occur.
*/
@Test
public void testEHFatal() throws Exception {
String outputFile = USER_DIR + "EHFatal.out";
String goldFile = GOLDEN_DIR + "EHFatalGF.out";
String xmlFile = XML_DIR + "invalid.xml";
try(MyErrorHandler eHandler = new MyErrorHandler(outputFile);
FileInputStream instream = new FileInputStream(xmlFile)) {
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
XMLReader xmlReader = saxParser.getXMLReader();
xmlReader.setErrorHandler(eHandler);
InputSource is = new InputSource(instream);
xmlReader.parse(is);
fail("Parse should throw SAXException");
} catch (SAXException expected) {
// This is expected.
}
// Need close the output file before we compare it with golden file.
assertTrue(compareWithGold(goldFile, outputFile));
}
示例10: parse
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
/**
* Parse the content given {@link org.xml.sax.InputSource}
* as XML using the specified
* {@link org.xml.sax.helpers.DefaultHandler}.
*
* @param is The InputSource containing the content to be parsed.
* @param dh The SAX DefaultHandler to use.
*
* @throws IllegalArgumentException If the <code>InputSource</code> object
* is <code>null</code>.
* @throws IOException If any IO errors occur.
* @throws SAXException If any SAX errors occur during processing.
*
* @see org.xml.sax.DocumentHandler
*/
public void parse(InputSource is, DefaultHandler dh)
throws SAXException, IOException {
if (is == null) {
throw new IllegalArgumentException("InputSource cannot be null");
}
XMLReader reader = this.getXMLReader();
if (dh != null) {
reader.setContentHandler(dh);
reader.setEntityResolver(dh);
reader.setErrorHandler(dh);
reader.setDTDHandler(dh);
}
reader.parse(is);
}
示例11: load
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
public static void load(ThemeNULL theme, InputStream in) throws IOException {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setValidating(true);
try {
SAXParser parser = spf.newSAXParser();
XMLReader reader = parser.getXMLReader();
XmlHandler handler = new XmlHandler();
handler.theme = theme;
reader.setEntityResolver(handler);
reader.setContentHandler(handler);
reader.setDTDHandler(handler);
reader.setErrorHandler(handler);
InputSource is = new InputSource(in);
is.setEncoding("UTF-8");
reader.parse(is);
} catch (/*SAX|ParserConfiguration*/Exception se) {
se.printStackTrace();
throw new IOException(se.toString());
}
}
示例12: parseAndGetConfig
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
/**
* Parses an xml config file and returns a Config object.
*
* @param xmlFile
* The xml config file which is passed by the user to annotation processing
* @return
* A non null Config object
*/
private Config parseAndGetConfig (File xmlFile, ErrorHandler errorHandler, boolean disableSecureProcessing) throws SAXException, IOException {
XMLReader reader;
try {
SAXParserFactory factory = XmlFactory.createParserFactory(disableSecureProcessing);
reader = factory.newSAXParser().getXMLReader();
} catch (ParserConfigurationException e) {
// in practice this will never happen
throw new Error(e);
}
NGCCRuntimeEx runtime = new NGCCRuntimeEx(errorHandler);
// set up validator
ValidatorHandler validator = configSchema.newValidator();
validator.setErrorHandler(errorHandler);
// the validator will receive events first, then the parser.
reader.setContentHandler(new ForkContentHandler(validator,runtime));
reader.setErrorHandler(errorHandler);
Config config = new Config(runtime);
runtime.setRootHandler(config);
reader.parse(new InputSource(xmlFile.toURL().toExternalForm()));
runtime.reset();
return config;
}
示例13: getInstance
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
public synchronized PaletteItemNode getInstance() {
PaletteItemNode node = refNode.get();
if (node != null)
return node;
FileObject file = xmlDataObject.getPrimaryFile();
if (file.getSize() == 0L) // item file is empty
return null;
PaletteItemHandler handler = new PaletteItemHandler();
try {
XMLReader reader = getXMLReader();
FileObject fo = xmlDataObject.getPrimaryFile();
String urlString = fo.getURL().toExternalForm();
InputSource is = new InputSource(fo.getInputStream());
is.setSystemId(urlString);
reader.setContentHandler(handler);
reader.setErrorHandler(handler);
reader.parse(is);
}
catch (SAXException saxe) {
Logger.getLogger( getClass().getName() ).log( Level.INFO, null, saxe );
return null;
}
catch (IOException ioe) {
Logger.getLogger( getClass().getName() ).log( Level.INFO, null, ioe );
return null;
}
if( handler.isError() )
return null;
node = createPaletteItemNode(handler);
refNode = new WeakReference<PaletteItemNode>(node);
return node;
}
示例14: parse
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
/**
* The recognizer entry method taking an InputSource.
* @param input InputSource to be parsed.
* @throws IOException on I/O error.
* @throws SAXException propagated exception thrown by a DocumentHandler.
*/
public void parse(final InputSource input) throws SAXException, IOException {
XMLReader parser = XMLUtil.createXMLReader(false, false); // fastest mode
parser.setContentHandler(this);
parser.setErrorHandler(this);
parser.setEntityResolver(this);
parser.parse(input);
}
示例15: parse
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
private void parse(InputSource is) throws Exception {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
spf.setValidating(true);
SAXParser parser = spf.newSAXParser();
parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", Bug4934208.class.getResourceAsStream("test.xsd"));
XMLReader r = parser.getXMLReader();
r.setErrorHandler(new DraconianErrorHandler());
r.parse(is);
}