OFBIZ-6278: Merged changes done at 1675464, 1675465 and 1675466 from OFBIZ-6275 branch to trunk.

Log:
==========================================================
- Make use of ResourceLoader.readXmlRootElement, which is
non-caching; this fixes a deprecation warning.
- Use ResourceLoader.readXmlRootElement, which is a
non-caching version.  This fixes a deprecation warning.
- Provide method variants (readXml{Document,RootElement}) that contain the body of the deprecated methods (getXml{Document,RootElement}).
==========================================================


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1731399 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Deepak Dixit
2016-02-20 13:16:03 +00:00
parent afc7477ebf
commit 94eefdcb72
3 changed files with 39 additions and 21 deletions
@@ -36,7 +36,7 @@ public class JNDIConfigUtil {
private static Element getXmlRootElement() throws GenericConfigException {
try {
return ResourceLoader.getXmlRootElement(JNDIConfigUtil.JNDI_CONFIG_XML_FILENAME);
return ResourceLoader.readXmlRootElement(JNDIConfigUtil.JNDI_CONFIG_XML_FILENAME);
} catch (GenericConfigException e) {
throw new GenericConfigException("Could not get JNDI XML root element", e);
}
@@ -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");
@@ -52,7 +52,7 @@ public class ButtonEventConfig implements java.io.Serializable {
protected boolean disableLock = false;
public static void loadButtonConfig() throws GenericConfigException {
Element root = ResourceLoader.getXmlRootElement(ButtonEventConfig.BUTTON_EVENT_CONFIG);
Element root = ResourceLoader.readXmlRootElement(ButtonEventConfig.BUTTON_EVENT_CONFIG);
List<?> buttonEvents = UtilXml.childElementList(root, "event");
if (!UtilValidate.isEmpty(buttonEvents)) {
Iterator<?> i = buttonEvents.iterator();