@Test public void testGetSourceXxeSAXSource() throws Exception { PgSQLXML xml = new PgSQLXML(null, XXE_EXAMPLE); SAXSource source = xml.getSource(SAXSource.class); try { sourceToString(source); fail("Assert throw the exception here"); } catch (TransformerException ex) { String message = ex.getCause().getMessage(); assertTrue( "Expected to get a <<DOCTYPE disallowed>> TransformerException. Actual message is " + message, message.startsWith("DOCTYPE is disallowed")); } }
public synchronized <T extends Source> T getSource(Class<T> sourceClass) throws SQLException { checkFreed(); ensureInitialized(); if (_data == null) { return null; } try { if (sourceClass == null || DOMSource.class.equals(sourceClass)) { DocumentBuilder builder = getXmlFactoryFactory().newDocumentBuilder(); InputSource input = new InputSource(new StringReader(_data)); return (T) new DOMSource(builder.parse(input)); } else if (SAXSource.class.equals(sourceClass)) { XMLReader reader = getXmlFactoryFactory().createXMLReader(); InputSource is = new InputSource(new StringReader(_data)); return (T) new SAXSource(reader, is); } else if (StreamSource.class.equals(sourceClass)) { return (T) new StreamSource(new StringReader(_data)); } else if (StAXSource.class.equals(sourceClass)) { XMLInputFactory xif = getXmlFactoryFactory().newXMLInputFactory(); XMLStreamReader xsr = xif.createXMLStreamReader(new StringReader(_data)); return (T) new StAXSource(xsr); } } catch (Exception e) { throw new PSQLException(GT.tr("Unable to decode xml data."), PSQLState.DATA_ERROR, e); } throw new PSQLException(GT.tr("Unknown XML Source class: {0}", sourceClass), PSQLState.INVALID_PARAMETER_TYPE); }
PgSQLXML implements SQLXML { public synchronized <T extends Source> T getSource(Class<T> sourceClass) throws SQLException { checkFreed(); ensureInitialized(); if (_data == null) { return null; } try { if (sourceClass == null || DOMSource.class.equals(sourceClass)) { DocumentBuilder builder = getXmlFactoryFactory().newDocumentBuilder(); InputSource input = new InputSource(new StringReader(_data)); return (T) new DOMSource(builder.parse(input)); } else if (SAXSource.class.equals(sourceClass)) { XMLReader reader = getXmlFactoryFactory().createXMLReader(); InputSource is = new InputSource(new StringReader(_data)); return (T) new SAXSource(reader, is); } else if (StreamSource.class.equals(sourceClass)) { return (T) new StreamSource(new StringReader(_data)); } else if (StAXSource.class.equals(sourceClass)) { XMLInputFactory xif = getXmlFactoryFactory().newXMLInputFactory(); XMLStreamReader xsr = xif.createXMLStreamReader(new StringReader(_data)); return (T) new StAXSource(xsr); } } catch (Exception e) { throw new PSQLException(GT.tr("Unable to decode xml data."), PSQLState.DATA_ERROR, e); } throw new PSQLException(GT.tr("Unknown XML Source class: {0}", sourceClass), PSQLState.INVALID_PARAMETER_TYPE); } }
PgSQLXML implements SQLXML { public synchronized <T extends Source> T getSource(Class<T> sourceClass) throws SQLException { checkFreed(); ensureInitialized(); if (_data == null) { return null; } try { if (sourceClass == null || DOMSource.class.equals(sourceClass)) { DocumentBuilder builder = getXmlFactoryFactory().newDocumentBuilder(); InputSource input = new InputSource(new StringReader(_data)); return (T) new DOMSource(builder.parse(input)); } else if (SAXSource.class.equals(sourceClass)) { XMLReader reader = getXmlFactoryFactory().createXMLReader(); InputSource is = new InputSource(new StringReader(_data)); return (T) new SAXSource(reader, is); } else if (StreamSource.class.equals(sourceClass)) { return (T) new StreamSource(new StringReader(_data)); } else if (StAXSource.class.equals(sourceClass)) { XMLInputFactory xif = getXmlFactoryFactory().newXMLInputFactory(); XMLStreamReader xsr = xif.createXMLStreamReader(new StringReader(_data)); return (T) new StAXSource(xsr); } } catch (Exception e) { throw new PSQLException(GT.tr("Unable to decode xml data."), PSQLState.DATA_ERROR, e); } throw new PSQLException(GT.tr("Unknown XML Source class: {0}", sourceClass), PSQLState.INVALID_PARAMETER_TYPE); } PgSQLXML(BaseConnection conn);  PgSQLXML(BaseConnection conn, String data); private  PgSQLXML(BaseConnection conn, String data, boolean initialized); }
PgSQLXML implements SQLXML { public synchronized <T extends Source> T getSource(Class<T> sourceClass) throws SQLException { checkFreed(); ensureInitialized(); if (_data == null) { return null; } try { if (sourceClass == null || DOMSource.class.equals(sourceClass)) { DocumentBuilder builder = getXmlFactoryFactory().newDocumentBuilder(); InputSource input = new InputSource(new StringReader(_data)); return (T) new DOMSource(builder.parse(input)); } else if (SAXSource.class.equals(sourceClass)) { XMLReader reader = getXmlFactoryFactory().createXMLReader(); InputSource is = new InputSource(new StringReader(_data)); return (T) new SAXSource(reader, is); } else if (StreamSource.class.equals(sourceClass)) { return (T) new StreamSource(new StringReader(_data)); } else if (StAXSource.class.equals(sourceClass)) { XMLInputFactory xif = getXmlFactoryFactory().newXMLInputFactory(); XMLStreamReader xsr = xif.createXMLStreamReader(new StringReader(_data)); return (T) new StAXSource(xsr); } } catch (Exception e) { throw new PSQLException(GT.tr("Unable to decode xml data."), PSQLState.DATA_ERROR, e); } throw new PSQLException(GT.tr("Unknown XML Source class: {0}", sourceClass), PSQLState.INVALID_PARAMETER_TYPE); } PgSQLXML(BaseConnection conn);  PgSQLXML(BaseConnection conn, String data); private  PgSQLXML(BaseConnection conn, String data, boolean initialized); synchronized void free(); synchronized InputStream getBinaryStream(); synchronized Reader getCharacterStream(); synchronized T getSource(Class<T> sourceClass); synchronized String getString(); synchronized OutputStream setBinaryStream(); synchronized Writer setCharacterStream(); synchronized T setResult(Class<T> resultClass); synchronized void setString(String value); }
PgSQLXML implements SQLXML { public synchronized <T extends Source> T getSource(Class<T> sourceClass) throws SQLException { checkFreed(); ensureInitialized(); if (_data == null) { return null; } try { if (sourceClass == null || DOMSource.class.equals(sourceClass)) { DocumentBuilder builder = getXmlFactoryFactory().newDocumentBuilder(); InputSource input = new InputSource(new StringReader(_data)); return (T) new DOMSource(builder.parse(input)); } else if (SAXSource.class.equals(sourceClass)) { XMLReader reader = getXmlFactoryFactory().createXMLReader(); InputSource is = new InputSource(new StringReader(_data)); return (T) new SAXSource(reader, is); } else if (StreamSource.class.equals(sourceClass)) { return (T) new StreamSource(new StringReader(_data)); } else if (StAXSource.class.equals(sourceClass)) { XMLInputFactory xif = getXmlFactoryFactory().newXMLInputFactory(); XMLStreamReader xsr = xif.createXMLStreamReader(new StringReader(_data)); return (T) new StAXSource(xsr); } } catch (Exception e) { throw new PSQLException(GT.tr("Unable to decode xml data."), PSQLState.DATA_ERROR, e); } throw new PSQLException(GT.tr("Unknown XML Source class: {0}", sourceClass), PSQLState.INVALID_PARAMETER_TYPE); } PgSQLXML(BaseConnection conn);  PgSQLXML(BaseConnection conn, String data); private  PgSQLXML(BaseConnection conn, String data, boolean initialized); synchronized void free(); synchronized InputStream getBinaryStream(); synchronized Reader getCharacterStream(); synchronized T getSource(Class<T> sourceClass); synchronized String getString(); synchronized OutputStream setBinaryStream(); synchronized Writer setCharacterStream(); synchronized T setResult(Class<T> resultClass); synchronized void setString(String value);  }