本文整理汇总了Java中jdk.internal.org.xml.sax.SAXException类的典型用法代码示例。如果您正苦于以下问题:Java SAXException类的具体用法?Java SAXException怎么用?Java SAXException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SAXException类属于jdk.internal.org.xml.sax包,在下文中一共展示了SAXException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: load
import jdk.internal.org.xml.sax.SAXException; //导入依赖的package包/类
public void load(Properties props, InputStream in)
throws IOException, InvalidPropertiesFormatException, UnsupportedEncodingException
{
this.properties = props;
try {
SAXParser parser = new SAXParserImpl();
parser.parse(in, this);
} catch (SAXException saxe) {
throw new InvalidPropertiesFormatException(saxe);
}
/**
* String xmlVersion = propertiesElement.getAttribute("version"); if
* (xmlVersion.compareTo(EXTERNAL_XML_VERSION) > 0) throw new
* InvalidPropertiesFormatException( "Exported Properties file format
* version " + xmlVersion + " is not supported. This java installation
* can read" + " versions " + EXTERNAL_XML_VERSION + " or older. You" +
* " may need to install a newer version of JDK.");
*/
}
示例2: parse
import jdk.internal.org.xml.sax.SAXException; //导入依赖的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 handler The SAX DefaultHandler to use.
* @exception IOException If any IO errors occur.
* @exception IllegalArgumentException If the InputSource or handler is
* null.
* @exception SAXException If the underlying parser throws a SAXException
* while parsing.
* @see org.xml.sax.helpers.DefaultHandler
*/
public void parse(InputSource is, DefaultHandler handler)
throws SAXException, IOException
{
if ((is == null) || (handler == null)) {
throw new IllegalArgumentException("");
}
// Set up the handler
mHandCont = handler;
mHandDtd = handler;
mHandErr = handler;
mHandEnt = handler;
// Set up the document
mInp = new Input(BUFFSIZE_READER);
mPh = PH_BEFORE_DOC; // before parsing
try {
setinp(is);
} catch (SAXException | IOException | RuntimeException saxe) {
throw saxe;
} catch (Exception e) {
panic(e.toString());
}
parse();
}
示例3: parse
import jdk.internal.org.xml.sax.SAXException; //导入依赖的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);
}
示例4: parse
import jdk.internal.org.xml.sax.SAXException; //导入依赖的package包/类
/**
* Parse the content of the file specified as XML using the
* specified {@link org.xml.sax.helpers.DefaultHandler}.
*
* @param f The file containing the XML to parse
* @param dh The SAX DefaultHandler to use.
*
* @throws IllegalArgumentException If the File object is null.
* @throws IOException If any IO errors occur.
* @throws SAXException If any SAX errors occur during processing.
*
* @see org.xml.sax.DocumentHandler
*/
public void parse(File f, DefaultHandler dh)
throws SAXException, IOException
{
if (f == null) {
throw new IllegalArgumentException("File cannot be null");
}
//convert file to appropriate URI, f.toURI().toASCIIString()
//converts the URI to string as per rule specified in
//RFC 2396,
InputSource input = new InputSource(f.toURI().toASCIIString());
this.parse(input, dh);
}
示例5: endElement
import jdk.internal.org.xml.sax.SAXException; //导入依赖的package包/类
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (!ALLOWED_ELEMENTS.contains(qName)) {
fatalError(new SAXParseException("Element: " + qName + " is invalid, must match \"(comment?,entry*)\".", null));
}
if (validEntry) {
properties.setProperty(key, buf.toString());
buf.delete(0, buf.length());
validEntry = false;
}
}
示例6: bflash_ws
import jdk.internal.org.xml.sax.SAXException; //导入依赖的package包/类
/**
* Reports white space characters and empties the parser's buffer. This
* method is called only if parser is going to return control to the main
* loop. This means that this method may use parser buffer to report white
* space without copeing characters to temporary buffer.
*/
protected void bflash_ws() throws SAXException {
if (mBuffIdx >= 0) {
// BUG: With additional info from DTD and xml:space attr [#2.10]
// the following call can be supported:
// mHandCont.ignorableWhitespace(mBuff, 0, (mBuffIdx + 1));
// Textual data has been read
mHandCont.characters(mBuff, 0, (mBuffIdx + 1));
mBuffIdx = -1;
}
}
示例7: startElement
import jdk.internal.org.xml.sax.SAXException; //导入依赖的package包/类
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException
{
if (rootElem < 2) {
rootElem++;
}
if (rootElm == null) {
fatalError(new SAXParseException("An XML properties document must contain"
+ " the DOCTYPE declaration as defined by java.util.Properties.", null));
}
if (rootElem == 1 && !rootElm.equals(qName)) {
fatalError(new SAXParseException("Document root element \"" + qName
+ "\", must match DOCTYPE root \"" + rootElm + "\"", null));
}
if (!ALLOWED_ELEMENTS.contains(qName)) {
fatalError(new SAXParseException("Element type \"" + qName + "\" must be declared.", null));
}
if (qName.equals(ELEMENT_ENTRY)) {
validEntry = true;
key = attributes.getValue(ATTR_KEY);
if (key == null) {
fatalError(new SAXParseException("Attribute \"key\" is required and must be specified for element type \"entry\"", null));
}
} else if (qName.equals(ALLOWED_COMMENT)) {
if (sawComment) {
fatalError(new SAXParseException("Only one comment element may be allowed. "
+ "The content of element type \"properties\" must match \"(comment?,entry*)\"", null));
}
sawComment = true;
}
}
示例8: bflash
import jdk.internal.org.xml.sax.SAXException; //导入依赖的package包/类
/**
* Reports characters and empties the parser's buffer. This method is called
* only if parser is going to return control to the main loop. This means
* that this method may use parser buffer to report white space without
* copying characters to temporary buffer.
*/
protected void bflash() throws SAXException {
if (mBuffIdx >= 0) {
// Textual data has been read
mHandCont.characters(mBuff, 0, (mBuffIdx + 1));
mBuffIdx = -1;
}
}
示例9: panic
import jdk.internal.org.xml.sax.SAXException; //导入依赖的package包/类
/**
* Notifies the handler about fatal parsing error.
*
* @param msg The problem description message.
*/
protected void panic(String msg) throws SAXException {
SAXParseException spe = new SAXParseException(msg, this);
mHandErr.fatalError(spe);
throw spe; // [#1.2] fatal error definition
}
示例10: notationDecl
import jdk.internal.org.xml.sax.SAXException; //导入依赖的package包/类
@Override
public void notationDecl(String name, String publicId, String systemId) throws SAXException {
rootElm = name;
}
示例11: error
import jdk.internal.org.xml.sax.SAXException; //导入依赖的package包/类
@Override
public void error(SAXParseException x) throws SAXException {
throw x;
}
示例12: fatalError
import jdk.internal.org.xml.sax.SAXException; //导入依赖的package包/类
@Override
public void fatalError(SAXParseException x) throws SAXException {
throw x;
}
示例13: warning
import jdk.internal.org.xml.sax.SAXException; //导入依赖的package包/类
@Override
public void warning(SAXParseException x) throws SAXException {
throw x;
}
示例14: characters
import jdk.internal.org.xml.sax.SAXException; //导入依赖的package包/类
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
if (validEntry) {
buf.append(ch, start, length);
}
}
示例15: parse
import jdk.internal.org.xml.sax.SAXException; //导入依赖的package包/类
/**
* Parse an XML document.
*
* <p>The application can use this method to instruct the XML reader to
* begin parsing an XML document from any valid input source (a character
* stream, a byte stream, or a URI).</p>
*
* <p>Applications may not invoke this method while a parse is in progress
* (they should create a new XMLReader instead for each nested XML
* document). Once a parse is complete, an application may reuse the same
* XMLReader object, possibly with a different input source.</p>
*
* <p>During the parse, the XMLReader will provide information about the XML
* document through the registered event handlers.</p>
*
* <p>This method is synchronous: it will not return until parsing has
* ended. If a client application wants to terminate parsing early, it
* should throw an exception.</p>
*
* @param is The input source for the top-level of the XML document.
* @exception org.xml.sax.SAXException Any SAX exception, possibly wrapping
* another exception.
* @exception java.io.IOException An IO exception from the parser, possibly
* from a byte stream or character stream supplied by the application.
* @see org.xml.sax.InputSource
* @see #parse(java.lang.String)
* @see #setEntityResolver
* @see #setDTDHandler
* @see #setContentHandler
* @see #setErrorHandler
*/
public void parse(InputSource is) throws IOException, SAXException {
if (is == null) {
throw new IllegalArgumentException("");
}
// Set up the document
mInp = new Input(BUFFSIZE_READER);
mPh = PH_BEFORE_DOC; // before parsing
try {
setinp(is);
} catch (SAXException saxe) {
throw saxe;
} catch (IOException ioe) {
throw ioe;
} catch (RuntimeException rte) {
throw rte;
} catch (Exception e) {
panic(e.toString());
}
parse();
}