下面列出了org.xml.sax.SAXException#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void parse (InputSource input) throws SAXException, IOException
{
XMLReader managedReader = null;
try {
if (getParent() == null) {
try {
managedReader = XMLReaderManager.getInstance(_overrideDefaultParser)
.getXMLReader();
setParent(managedReader);
} catch (SAXException e) {
throw new SAXException(e.toString());
}
}
// call parse on the parent
getParent().parse(input);
} finally {
if (managedReader != null) {
XMLReaderManager.getInstance(_overrideDefaultParser).releaseXMLReader(managedReader);
}
}
}
@Test
public void testException() {
try {
parse();
} catch (SAXException e) {
// e.printStackTrace();
String msg = e.toString();
if (msg.indexOf("systemId") == -1) {
Assert.fail("CR6889654 -- details should be returned.");
}
if (msg.indexOf(MSG) == -1) {
Assert.fail("CR6889649 -- additional error message not returned.");
}
System.out.println("error message:\n" + msg);
}
}
@Test(dataProvider = "illegalCharactersData")
public void test(int character) throws Exception {
// Construct the XML document as a String
int[] cps = new int[]{character};
String txt = new String(cps, 0, cps.length);
String inxml = "<topElement attTest=\'" + txt + "\'/>";
String exceptionText = "NO EXCEPTION OBSERVED";
String hexString = "0x" + Integer.toHexString(character);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating(false);
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource isrc = new InputSource(new StringReader(inxml));
try {
db.parse(isrc);
} catch (SAXException e) {
exceptionText = e.toString();
}
System.out.println("Got Exception:" + exceptionText);
assertTrue(exceptionText.contains("attribute \"attTest\""));
assertTrue(exceptionText.contains("element is \"topElement\""));
assertTrue(exceptionText.contains("Unicode: " + hexString));
}
public void parse (InputSource input) throws SAXException, IOException
{
XMLReader managedReader = null;
try {
if (getParent() == null) {
try {
managedReader = XMLReaderManager.getInstance(_useServicesMechanism)
.getXMLReader();
setParent(managedReader);
} catch (SAXException e) {
throw new SAXException(e.toString());
}
}
// call parse on the parent
getParent().parse(input);
} finally {
if (managedReader != null) {
XMLReaderManager.getInstance(_useServicesMechanism).releaseXMLReader(managedReader);
}
}
}
private void flush()
{
try
{
if (m_firstTagNotEmitted)
{
emitFirstTag();
}
if (m_needToCallStartDocument)
{
m_handler.startDocument();
m_needToCallStartDocument = false;
}
}
catch(SAXException e)
{
throw new RuntimeException(e.toString());
}
}
private void flush()
{
try
{
if (m_firstTagNotEmitted)
{
emitFirstTag();
}
if (m_needToCallStartDocument)
{
m_handler.startDocument();
m_needToCallStartDocument = false;
}
}
catch(SAXException e)
{
throw new RuntimeException(e.toString());
}
}
@Test(dataProvider = "illegalCharactersData")
public void test(int character) throws Exception {
// Construct the XML document as a String
int[] cps = new int[]{character};
String txt = new String(cps, 0, cps.length);
String inxml = "<topElement attTest=\'" + txt + "\'/>";
String exceptionText = "NO EXCEPTION OBSERVED";
String hexString = "0x" + Integer.toHexString(character);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating(false);
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource isrc = new InputSource(new StringReader(inxml));
try {
db.parse(isrc);
} catch (SAXException e) {
exceptionText = e.toString();
}
System.out.println("Got Exception:" + exceptionText);
assertTrue(exceptionText.contains("attribute \"attTest\""));
assertTrue(exceptionText.contains("element is \"topElement\""));
assertTrue(exceptionText.contains("Unicode: " + hexString));
}
private void flush()
{
try
{
if (m_firstTagNotEmitted)
{
emitFirstTag();
}
if (m_needToCallStartDocument)
{
m_handler.startDocument();
m_needToCallStartDocument = false;
}
}
catch(SAXException e)
{
throw new RuntimeException(e.toString());
}
}
@Test(dataProvider = "illegalCharactersData")
public void test(int character) throws Exception {
// Construct the XML document as a String
int[] cps = new int[]{character};
String txt = new String(cps, 0, cps.length);
String inxml = "<topElement attTest=\'" + txt + "\'/>";
String exceptionText = "NO EXCEPTION OBSERVED";
String hexString = "0x" + Integer.toHexString(character);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating(false);
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource isrc = new InputSource(new StringReader(inxml));
try {
db.parse(isrc);
} catch (SAXException e) {
exceptionText = e.toString();
}
System.out.println("Got Exception:" + exceptionText);
assertTrue(exceptionText.contains("attribute \"attTest\""));
assertTrue(exceptionText.contains("element is \"topElement\""));
assertTrue(exceptionText.contains("Unicode: " + hexString));
}
private void flush()
{
try
{
if (m_firstTagNotEmitted)
{
emitFirstTag();
}
if (m_needToCallStartDocument)
{
m_handler.startDocument();
m_needToCallStartDocument = false;
}
}
catch(SAXException e)
{
throw new RuntimeException(e.toString());
}
}
private void flush()
{
try
{
if (m_firstTagNotEmitted)
{
emitFirstTag();
}
if (m_needToCallStartDocument)
{
m_handler.startDocument();
m_needToCallStartDocument = false;
}
}
catch(SAXException e)
{
throw new RuntimeException(e.toString());
}
}
@Test(dataProvider = "illegalCharactersData")
public void test(int character) throws Exception {
// Construct the XML document as a String
int[] cps = new int[]{character};
String txt = new String(cps, 0, cps.length);
String inxml = "<topElement attTest=\'" + txt + "\'/>";
String exceptionText = "NO EXCEPTION OBSERVED";
String hexString = "0x" + Integer.toHexString(character);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating(false);
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource isrc = new InputSource(new StringReader(inxml));
try {
db.parse(isrc);
} catch (SAXException e) {
exceptionText = e.toString();
}
System.out.println("Got Exception:" + exceptionText);
assertTrue(exceptionText.contains("attribute \"attTest\""));
assertTrue(exceptionText.contains("element is \"topElement\""));
assertTrue(exceptionText.contains("Unicode: " + hexString));
}
@Override
public void parse (InputSource input) throws SAXException, IOException
{
XMLReader managedReader = null;
try {
if (getParent() == null) {
try {
managedReader = XMLReaderManager.getInstance(_overrideDefaultParser)
.getXMLReader();
setParent(managedReader);
} catch (SAXException e) {
throw new SAXException(e.toString());
}
}
// call parse on the parent
getParent().parse(input);
} finally {
if (managedReader != null) {
XMLReaderManager.getInstance(_overrideDefaultParser).releaseXMLReader(managedReader);
}
}
}
@Override
public void write(TopicMapIF topicmap) throws IOException {
try {
export(topicmap, out);
}
catch (SAXException e) {
if (e.getException() instanceof IOException)
throw (IOException) e.getException();
throw new IOException("XML writing problem: " + e.toString());
}
}
private void flush() {
try {
if (m_firstTagNotEmitted) {
emitFirstTag();
}
if (m_needToCallStartDocument) {
m_handler.startDocument();
m_needToCallStartDocument = false;
}
} catch(SAXException e) {
throw new RuntimeException(e.toString());
}
}
@Override
public List<ServiceRef> handleResponse (final HttpResponse response) throws IOException {
checkReponseCode(response);
try {
final byte[] data = EntityUtils.toByteArray(response.getEntity());
final List<ServiceRef> accounts = new PostToAccountsXml(new ByteArrayInputStream(data)).getAccounts();
if (this.sw != null) this.sw.writePostToAccountsToCache(new String(data, Charset.forName("UTF-8")));
return accounts;
}
catch (final SAXException e) {
throw new IOException("Failed to parse response: " + e.toString(), e);
}
}
protected final void addEnd(String name) {
try {
h.endElement("", name, name);
} catch (SAXException ex) {
throw new RuntimeException(ex.toString());
}
}
public HTMLPage.Scriptable getDocument() {
try {
if (!isHTML()) replaceText( BLANK_HTML, HTML_CONTENT );
return getReceivedPage().getScriptableObject();
} catch (SAXException e) {
throw new RuntimeException( e.toString() );
}
}
protected final void addStart(String name, Attributes attrs) {
try {
h.startElement("", name, name, attrs);
} catch (SAXException ex) {
throw new RuntimeException(ex.toString());
}
}
/**
* Saves a given UIMA aggregate component desciption in a specified XML descriptor file.
*
* @param aggDescription
* The given UIMA aggregate component desciption.
* @param aggDescFile
* The given XML descriptor file.
* @throws IOException
* If an I/O exception occurrs.
*/
static void saveAggregateDescription(AnalysisEngineDescription aggDescription, File aggDescFile)
throws IOException {
try (Writer fWriter = new FileWriter(aggDescFile)) {
aggDescription.toXML(fWriter);
} catch (SAXException exc) {
throw new IOException(exc.toString());
}
}