You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by do...@apache.org on 2015/04/22 21:33:50 UTC
svn commit: r1675464 -
/ofbiz/branches/OFBIZ-6275/framework/base/src/org/ofbiz/base/config/ResourceLoader.java
Author: doogie
Date: Wed Apr 22 19:33:49 2015
New Revision: 1675464
URL: http://svn.apache.org/r1675464
Log:
Provide method variants (readXml{Document,RootElement}) that contain the
body of the deprecated methods (getXml{Document,RootElement}).
Modified:
ofbiz/branches/OFBIZ-6275/framework/base/src/org/ofbiz/base/config/ResourceLoader.java
Modified: ofbiz/branches/OFBIZ-6275/framework/base/src/org/ofbiz/base/config/ResourceLoader.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-6275/framework/base/src/org/ofbiz/base/config/ResourceLoader.java?rev=1675464&r1=1675463&r2=1675464&view=diff
==============================================================================
--- ofbiz/branches/OFBIZ-6275/framework/base/src/org/ofbiz/base/config/ResourceLoader.java (original)
+++ ofbiz/branches/OFBIZ-6275/framework/base/src/org/ofbiz/base/config/ResourceLoader.java Wed Apr 22 19:33:49 2015
@@ -80,8 +80,10 @@ public abstract class ResourceLoader {
return loader;
}
- // This method should be avoided. DOM object trees take a lot of memory and they are not
- // thread-safe, so they should not be cached.
+ /** This method should be avoided. DOM object trees take a lot of memory and they are not
+ * thread-safe, so they should not be cached.
+ * @deprecated use {@link #readXmlRootElement(String)}
+ */
@Deprecated
public static Element getXmlRootElement(String xmlFilename) throws GenericConfigException {
Document document = ResourceLoader.getXmlDocument(xmlFilename);
@@ -93,32 +95,30 @@ public abstract class ResourceLoader {
}
}
+ public static Element readXmlRootElement(String xmlFilename) throws GenericConfigException {
+ Document document = ResourceLoader.readXmlDocument(xmlFilename);
+
+ if (document != null) {
+ return document.getDocumentElement();
+ } else {
+ return null;
+ }
+ }
+
public static void invalidateDocument(String xmlFilename) throws GenericConfigException {
UtilCache.clearCachesThatStartWith(xmlFilename);
}
- // This method should be avoided. DOM object trees take a lot of memory and they are not
- // thread-safe, so they should not be cached.
+ /** This method should be avoided. DOM object trees take a lot of memory and they are not
+ * thread-safe, so they should not be cached.
+ * @deprecated use {@link #readXmlDocument(String)}
+ */
@Deprecated
public static Document getXmlDocument(String xmlFilename) throws GenericConfigException {
Document document = domCache.get(xmlFilename);
if (document == null) {
- URL confUrl = UtilURL.fromResource(xmlFilename);
-
- if (confUrl == null) {
- throw new GenericConfigException("ERROR: could not find the [" + xmlFilename + "] XML file on the classpath");
- }
-
- try {
- document = UtilXml.readXmlDocument(confUrl, true, true);
- } catch (org.xml.sax.SAXException e) {
- throw new GenericConfigException("Error reading " + xmlFilename + "", e);
- } catch (javax.xml.parsers.ParserConfigurationException e) {
- throw new GenericConfigException("Error reading " + xmlFilename + "", e);
- } catch (java.io.IOException e) {
- throw new GenericConfigException("Error reading " + xmlFilename + "", e);
- }
+ document = readXmlDocument(xmlFilename);
if (document != null) {
document = (Document) domCache.putIfAbsentAndGet(xmlFilename, document);
@@ -127,6 +127,24 @@ public abstract class ResourceLoader {
return document;
}
+ public static Document readXmlDocument(String xmlFilename) throws GenericConfigException {
+ URL confUrl = UtilURL.fromResource(xmlFilename);
+
+ if (confUrl == null) {
+ throw new GenericConfigException("ERROR: could not find the [" + xmlFilename + "] XML file on the classpath");
+ }
+
+ try {
+ return UtilXml.readXmlDocument(confUrl, true, true);
+ } catch (org.xml.sax.SAXException e) {
+ throw new GenericConfigException("Error reading " + xmlFilename + "", e);
+ } catch (javax.xml.parsers.ParserConfigurationException e) {
+ throw new GenericConfigException("Error reading " + xmlFilename + "", e);
+ } catch (java.io.IOException e) {
+ throw new GenericConfigException("Error reading " + xmlFilename + "", e);
+ }
+ }
+
private static ResourceLoader makeLoader(Element loaderElement) throws GenericConfigException {
String loaderName = loaderElement.getAttribute("name");
String className = loaderElement.getAttribute("class");