/** * Get the contents of a URL as an XML Document, first trying to read the Document with * validation turned on, and falling back to reading it with validation turned off. * * @param requestingClass the java.lang.Class object of the class that is attempting to load the * resource * @param resource a String describing the full or partial URL of the resource whose contents to * load * @return the actual contents of the resource as an XML Document * @throws ResourceMissingException * @throws java.io.IOException * @throws javax.xml.parsers.ParserConfigurationException * @throws org.xml.sax.SAXException */ public static Document getResourceAsDocument(Class<?> requestingClass, String resource) throws ResourceMissingException, IOException, ParserConfigurationException, SAXException { // Default is non-validating... return getResourceAsDocument(requestingClass, resource, false); }
protected void parseXml() throws Exception { InputSource xmlSource = new InputSource( ResourceLoader.getResourceAsStream( GroupServiceConfiguration.class, SERVICES_XML)); if (xmlSource != null) { XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader(); reader.setContentHandler(serviceHandler); reader.parse(xmlSource); } } }
/** * Returns the requested resource as a URL string. * * @param requestingClass the java.lang.Class object of the class that is attempting to load the * resource * @param resource a String describing the full or partial URL of the resource to load * @return the requested resource as a URL string * @throws ResourceMissingException */ public static String getResourceAsURLString(Class<?> requestingClass, String resource) throws ResourceMissingException { return getResourceAsURL(requestingClass, resource).toString(); }
protected void parseXml() throws Exception { InputSource xmlSource = new InputSource( ResourceLoader.getResourceAsStream( GroupServiceConfiguration.class, SERVICES_XML)); if (xmlSource != null) { XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader(); reader.setContentHandler(serviceHandler); reader.parse(xmlSource); } } }
/** * Get the contents of a URL as an XML Document, first trying to read the Document with * validation turned on, and falling back to reading it with validation turned off. * * @param requestingClass the java.lang.Class object of the class that is attempting to load the * resource * @param resource a String describing the full or partial URL of the resource whose contents to * load * @return the actual contents of the resource as an XML Document * @throws ResourceMissingException * @throws java.io.IOException * @throws javax.xml.parsers.ParserConfigurationException * @throws org.xml.sax.SAXException */ public static Document getResourceAsDocument(Class<?> requestingClass, String resource) throws ResourceMissingException, IOException, ParserConfigurationException, SAXException { // Default is non-validating... return getResourceAsDocument(requestingClass, resource, false); }
/** * Returns the requested resource as a URL string. * * @param requestingClass the java.lang.Class object of the class that is attempting to load the * resource * @param resource a String describing the full or partial URL of the resource to load * @return the requested resource as a URL string * @throws ResourceMissingException */ public static String getResourceAsURLString(Class<?> requestingClass, String resource) throws ResourceMissingException { return getResourceAsURL(requestingClass, resource).toString(); }
/** * Get the contents of a URL as a java.util.Properties object * * @param requestingClass the java.lang.Class object of the class that is attempting to load the * resource * @param resource a String describing the full or partial URL of the resource whose contents to * load * @return the actual contents of the resource as a Properties object * @throws ResourceMissingException * @throws java.io.IOException */ public static Properties getResourceAsProperties(Class<?> requestingClass, String resource) throws ResourceMissingException, IOException { InputStream inputStream = null; Properties props = null; try { inputStream = getResourceAsStream(requestingClass, resource); props = new Properties(); props.load(inputStream); } finally { if (inputStream != null) inputStream.close(); } return props; }
public LDAPGroupStore() { Document config = null; try { config = ResourceLoader.getResourceAsDocument( this.getClass(), "/properties/groups/LDAPGroupStoreConfig.xml", true); } catch (IOException e) { throw new RuntimeException( "LDAPGroupStore: Unable to find configuration configuration document", e); } catch (ResourceMissingException e) { throw new RuntimeException( "LDAPGroupStore: Unable to find configuration configuration document", e); } catch (ParserConfigurationException e) { throw new RuntimeException( "LDAPGroupStore: Unable to parse configuration configuration document", e); } catch (SAXException e) { throw new RuntimeException( "LDAPGroupStore: Unable to parse configuration configuration document", e); } init(config); }
/** * Returns the requested resource as a stream. * * @param requestingClass the java.lang.Class object of the class that is attempting to load the * resource * @param resource a String describing the full or partial URL of the resource to load * @return the requested resource as a stream * @throws ResourceMissingException * @throws java.io.IOException */ public static InputStream getResourceAsStream(Class<?> requestingClass, String resource) throws ResourceMissingException, IOException { return getResourceAsURL(requestingClass, resource).openStream(); }
/** * Get the contents of a URL as a java.util.Properties object * * @param requestingClass the java.lang.Class object of the class that is attempting to load the * resource * @param resource a String describing the full or partial URL of the resource whose contents to * load * @return the actual contents of the resource as a Properties object * @throws ResourceMissingException * @throws java.io.IOException */ public static Properties getResourceAsProperties(Class<?> requestingClass, String resource) throws ResourceMissingException, IOException { InputStream inputStream = null; Properties props = null; try { inputStream = getResourceAsStream(requestingClass, resource); props = new Properties(); props.load(inputStream); } finally { if (inputStream != null) inputStream.close(); } return props; }
public LDAPGroupStore() { Document config = null; try { config = ResourceLoader.getResourceAsDocument( this.getClass(), "/properties/groups/LDAPGroupStoreConfig.xml", true); } catch (IOException e) { throw new RuntimeException( "LDAPGroupStore: Unable to find configuration configuration document", e); } catch (ResourceMissingException e) { throw new RuntimeException( "LDAPGroupStore: Unable to find configuration configuration document", e); } catch (ParserConfigurationException e) { throw new RuntimeException( "LDAPGroupStore: Unable to parse configuration configuration document", e); } catch (SAXException e) { throw new RuntimeException( "LDAPGroupStore: Unable to parse configuration configuration document", e); } init(config); }
/** * Returns the requested resource as a stream. * * @param requestingClass the java.lang.Class object of the class that is attempting to load the * resource * @param resource a String describing the full or partial URL of the resource to load * @return the requested resource as a stream * @throws ResourceMissingException * @throws java.io.IOException */ public static InputStream getResourceAsStream(Class<?> requestingClass, String resource) throws ResourceMissingException, IOException { return getResourceAsURL(requestingClass, resource).openStream(); }
/** * Get the contents of a URL as a String * * @param requestingClass the java.lang.Class object of the class that is attempting to load the * resource * @param resource a String describing the full or partial URL of the resource whose contents to * load * @return the actual contents of the resource as a String * @throws ResourceMissingException * @throws java.io.IOException */ public static String getResourceAsString(Class<?> requestingClass, String resource) throws ResourceMissingException, IOException { String line = null; BufferedReader in = null; StringBuffer sbText = null; try { in = new BufferedReader( new InputStreamReader( getResourceAsStream(requestingClass, resource), UTF_8)); sbText = new StringBuffer(1024); while ((line = in.readLine()) != null) sbText.append(line).append("\n"); } finally { if (in != null) in.close(); } return sbText.toString(); } }
public static long getResourceLastModified(Class<?> requestingClass, String resource) { final URL contentUrl = getResourceAsURL(requestingClass, resource); final String contentFileName = contentUrl.getFile(); // Use JAR modified time if the resource is in a .jar file denoted by ! delimeter final int delimIndex = contentFileName.indexOf('!'); final File contentFile; if (delimIndex > 0) { contentFile = new File(contentFileName.substring(0, delimIndex)); } else { contentFile = new File(contentFileName); } return contentFile.lastModified(); }
/** * Get the contents of a URL as a String * * @param requestingClass the java.lang.Class object of the class that is attempting to load the * resource * @param resource a String describing the full or partial URL of the resource whose contents to * load * @return the actual contents of the resource as a String * @throws ResourceMissingException * @throws java.io.IOException */ public static String getResourceAsString(Class<?> requestingClass, String resource) throws ResourceMissingException, IOException { String line = null; BufferedReader in = null; StringBuffer sbText = null; try { in = new BufferedReader( new InputStreamReader( getResourceAsStream(requestingClass, resource), UTF_8)); sbText = new StringBuffer(1024); while ((line = in.readLine()) != null) sbText.append(line).append("\n"); } finally { if (in != null) in.close(); } return sbText.toString(); } }
public static long getResourceLastModified(Class<?> requestingClass, String resource) { final URL contentUrl = getResourceAsURL(requestingClass, resource); final String contentFileName = contentUrl.getFile(); // Use JAR modified time if the resource is in a .jar file denoted by ! delimeter final int delimIndex = contentFileName.indexOf('!'); final File contentFile; if (delimIndex > 0) { contentFile = new File(contentFileName.substring(0, delimIndex)); } else { contentFile = new File(contentFileName); } return contentFile.lastModified(); }
factoryToUse = ResourceLoader.nonValidatingDocumentBuilderFactory; inputStream = getResourceAsStream(requestingClass, resource); DocumentBuilder db = factoryToUse.newDocumentBuilder();
/** * Returns the requested resource as a SAX input source. * * @param requestingClass the java.lang.Class object of the class that is attempting to load the * resource * @param resource a String describing the full or partial URL of the resource to load * @return the requested resource as a SAX input source * @throws ResourceMissingException * @throws java.io.IOException */ public static InputSource getResourceAsSAXInputSource(Class<?> requestingClass, String resource) throws ResourceMissingException, IOException { URL url = getResourceAsURL(requestingClass, resource); InputSource source = new InputSource(url.openStream()); source.setPublicId(url.toExternalForm()); return source; }
factoryToUse = ResourceLoader.nonValidatingDocumentBuilderFactory; inputStream = getResourceAsStream(requestingClass, resource); DocumentBuilder db = factoryToUse.newDocumentBuilder();
/** * Returns the requested resource as a SAX input source. * * @param requestingClass the java.lang.Class object of the class that is attempting to load the * resource * @param resource a String describing the full or partial URL of the resource to load * @return the requested resource as a SAX input source * @throws ResourceMissingException * @throws java.io.IOException */ public static InputSource getResourceAsSAXInputSource(Class<?> requestingClass, String resource) throws ResourceMissingException, IOException { URL url = getResourceAsURL(requestingClass, resource); InputSource source = new InputSource(url.openStream()); source.setPublicId(url.toExternalForm()); return source; }