View Javadoc

1   package org.ocltf.utils;
2   
3   import java.net.URL;
4   
5   import org.apache.commons.logging.Log;
6   import org.apache.commons.logging.LogFactory;
7   
8   
9   /***
10   * Contains utilities for loading XML resources. Similar
11   * to FileResource except handles XML resources in a similar fashion.
12   * 
13   * @author Chad Brandon
14   */
15  public class XmlResourceUtils {
16  	
17  	private static final Log logger = LogFactory.getLog(XmlResourceUtils.class);
18  
19  	/***
20  	 * Retreives an XML resource from the class pacakge
21  	 * @param resourceName - the name of the resource
22  	 * @return URL
23  	 */
24  	public static URL getResource(String resourceName) {
25  		String methodName = "getXmlResource";
26  		if (logger.isDebugEnabled()) {
27  			logger.debug("performing " + methodName 
28  				+ " with resourceName (" + resourceName + ")");	
29  		}
30  		ExceptionUtils.checkEmpty(methodName, "resourceName", resourceName);
31  		resourceName = resourceName.replace('.', '/') + ".xml";
32  		return FileResourceUtils.getResource(resourceName);
33  	}	
34  	
35  	/***
36  	 * Loads the contents and then converts the contents to a string.
37  	 * @param resourceName
38  	 * @return
39  	 */
40  	public static String getResourceContentsAsString(String resourceName) {
41  		String methodName = "getResourceContentsAsString";
42  		if (logger.isDebugEnabled()) {
43  			logger.debug("performing " + methodName 
44  				+ " with resourceName (" + resourceName + ")");	
45  		}
46  		ExceptionUtils.checkEmpty(methodName, "resourceName", resourceName);
47  		resourceName = resourceName.replace('.', '/') + ".xml";
48  		return FileResourceUtils.getResourceContentsAsString(resourceName);		
49  	}
50  }