Java Code Examples for org.xml.sax.SAXException#toString()

The following examples show how to use org.xml.sax.SAXException#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TrAXFilter.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@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);
        }
    }
}
 
Example 2
Source File: TrAXFilter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@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);
        }
    }
}
 
Example 3
Source File: BadExceptionMessageTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@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));
}
 
Example 4
Source File: ToUnknownStream.java    From j2objc with Apache License 2.0 6 votes vote down vote up
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());
    }
      

}
 
Example 5
Source File: ToUnknownStream.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
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());
    }


}
 
Example 6
Source File: BadExceptionMessageTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@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));
}
 
Example 7
Source File: ToUnknownStream.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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());
    }


}
 
Example 8
Source File: BadExceptionMessageTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@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));
}
 
Example 9
Source File: ToUnknownStream.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
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());
    }


}
 
Example 10
Source File: ToUnknownStream.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
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());
    }


}
 
Example 11
Source File: TrAXFilter.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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);
        }
    }
}
 
Example 12
Source File: Bug8073385.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@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));
}
 
Example 13
Source File: Bug6889654Test.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@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);
    }
}
 
Example 14
Source File: ToUnknownStream.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
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());
    }
}
 
Example 15
Source File: SuccessWhale.java    From Onosendai with Apache License 2.0 5 votes vote down vote up
@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);
	}
}
 
Example 16
Source File: SAXAdapter.java    From annotation-tools with MIT License 5 votes vote down vote up
protected final void addEnd(String name) {
    try {
        h.endElement("", name, name);
    } catch (SAXException ex) {
        throw new RuntimeException(ex.toString());
    }
}
 
Example 17
Source File: WebResponse.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public HTMLPage.Scriptable getDocument() {
    try {
        if (!isHTML()) replaceText( BLANK_HTML, HTML_CONTENT );
        return getReceivedPage().getScriptableObject();
    } catch (SAXException e) {
        throw new RuntimeException( e.toString() );
    }
}
 
Example 18
Source File: CanonicalTopicMapWriter.java    From ontopia with Apache License 2.0 5 votes vote down vote up
@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());
  }
}
 
Example 19
Source File: SAXAdapter.java    From annotation-tools with MIT License 5 votes vote down vote up
protected final void addStart(String name, Attributes attrs) {
    try {
        h.startElement("", name, name, attrs);
    } catch (SAXException ex) {
        throw new RuntimeException(ex.toString());
    }
}
 
Example 20
Source File: PMUimaAgent.java    From uima-uimaj with Apache License 2.0 3 votes vote down vote up
/**
 * 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());
  }
}