@Test public void testBadXml() { try { URL configFile = this.getClass().getClassLoader().getResource( "org/apache/tiles/config/malformed-defs.xml"); assertNotNull("Config file not found", configFile); InputStream source = configFile.openStream(); reader.read(source); fail("Should've thrown an exception."); } catch (DefinitionsFactoryException e) { if (log.isDebugEnabled()) { log.debug("Exception caught, it is OK", e); } } catch (Exception e) { fail("Exception reading configuration." + e); } }
public Map<String, Definition> read(Object source) { definitions = new LinkedHashMap<String, Definition>(); if (source == null) { return null; } InputStream input; try { input = (InputStream) source; } catch (ClassCastException e) { throw new DefinitionsFactoryException( "Invalid source type. Requires java.io.InputStream.", e); } try { digester.push(this); digester.parse(input); } catch (SAXException e) { throw new DefinitionsFactoryException( "XML error reading definitions.", e); } catch (IOException e) { throw new DefinitionsFactoryException( "I/O Error reading definitions.", e); } finally { digester.clear(); } return definitions; }
DigesterDefinitionsReader implements DefinitionsReader { public Map<String, Definition> read(Object source) { definitions = new LinkedHashMap<String, Definition>(); if (source == null) { return null; } InputStream input; try { input = (InputStream) source; } catch (ClassCastException e) { throw new DefinitionsFactoryException( "Invalid source type. Requires java.io.InputStream.", e); } try { digester.push(this); digester.parse(input); } catch (SAXException e) { throw new DefinitionsFactoryException( "XML error reading definitions.", e); } catch (IOException e) { throw new DefinitionsFactoryException( "I/O Error reading definitions.", e); } finally { digester.clear(); } return definitions; } }
DigesterDefinitionsReader implements DefinitionsReader { public Map<String, Definition> read(Object source) { definitions = new LinkedHashMap<String, Definition>(); if (source == null) { return null; } InputStream input; try { input = (InputStream) source; } catch (ClassCastException e) { throw new DefinitionsFactoryException( "Invalid source type. Requires java.io.InputStream.", e); } try { digester.push(this); digester.parse(input); } catch (SAXException e) { throw new DefinitionsFactoryException( "XML error reading definitions.", e); } catch (IOException e) { throw new DefinitionsFactoryException( "I/O Error reading definitions.", e); } finally { digester.clear(); } return definitions; } DigesterDefinitionsReader(); }
DigesterDefinitionsReader implements DefinitionsReader { public Map<String, Definition> read(Object source) { definitions = new LinkedHashMap<String, Definition>(); if (source == null) { return null; } InputStream input; try { input = (InputStream) source; } catch (ClassCastException e) { throw new DefinitionsFactoryException( "Invalid source type. Requires java.io.InputStream.", e); } try { digester.push(this); digester.parse(input); } catch (SAXException e) { throw new DefinitionsFactoryException( "XML error reading definitions.", e); } catch (IOException e) { throw new DefinitionsFactoryException( "I/O Error reading definitions.", e); } finally { digester.clear(); } return definitions; } DigesterDefinitionsReader(); void setValidating(boolean validating); Map<String, Definition> read(Object source); void addDefinition(Definition definition); }
DigesterDefinitionsReader implements DefinitionsReader { public Map<String, Definition> read(Object source) { definitions = new LinkedHashMap<String, Definition>(); if (source == null) { return null; } InputStream input; try { input = (InputStream) source; } catch (ClassCastException e) { throw new DefinitionsFactoryException( "Invalid source type. Requires java.io.InputStream.", e); } try { digester.push(this); digester.parse(input); } catch (SAXException e) { throw new DefinitionsFactoryException( "XML error reading definitions.", e); } catch (IOException e) { throw new DefinitionsFactoryException( "I/O Error reading definitions.", e); } finally { digester.clear(); } return definitions; } DigesterDefinitionsReader(); void setValidating(boolean validating); Map<String, Definition> read(Object source); void addDefinition(Definition definition); static final String PARSER_VALIDATE_PARAMETER_NAME; }