private String loadProperty(String key) throws IOException { if (_properties == null) { try { _properties = new Properties(); _properties.load( Thread.currentThread() .getContextClassLoader() .getResourceAsStream(this.PROPERTIES_FILENAME)); } catch (IOException e) { log.error("Could not load xml.properties: \n " + e.getMessage()); throw new IOException( "Error loading " + caCOREUnmarshaller.PROPERTIES_FILENAME + " file. Please make sure the file is in your classpath."); } } return _properties.getProperty(key); }
/** @return default mapping file being used for xml serialziation/deserialization */ public Mapping getMapping() throws XMLUtilityException { /* if no mapping file explicity specified then load the default */ log.debug("mapping is null? " + (mapping == null)); if (mapping == null) { log.info("mapping is null; will try to load it"); try { EntityResolver resolver = new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) { if (publicId.equals("-//EXOLAB/Castor Object Mapping DTD Version 1.0//EN")) { InputStream in = Thread.currentThread() .getContextClassLoader() .getResourceAsStream("mapping.dtd"); return new InputSource(in); } return null; } }; org.xml.sax.InputSource mappIS = new org.xml.sax.InputSource( Thread.currentThread() .getContextClassLoader() .getResourceAsStream(loadProperty(this.PROPERTIES_MAPPING_KEY))); Mapping localMapping = new Mapping(); localMapping.setEntityResolver(resolver); localMapping.loadMapping(mappIS); return localMapping; } catch (IOException e) { log.error( "Error reading default xml mapping file ", e); // To change body of catch statement use File | Settings | File Templates. throw new XMLUtilityException("Error reading default xml mapping file ", e); } } return mapping; }