Author: vyemialyanchyk
Date: 2009-09-08 11:09:41 -0400 (Tue, 08 Sep 2009)
New Revision: 17474
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/preferences/AbstractConsoleConfigurationPreferences.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4824 - inspect and fix potential unsafe code
places to proper usage of w3c dom and the changes in upcoming WTP 3.2
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/preferences/AbstractConsoleConfigurationPreferences.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/preferences/AbstractConsoleConfigurationPreferences.java 2009-09-08
15:05:35 UTC (rev 17473)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/preferences/AbstractConsoleConfigurationPreferences.java 2009-09-08
15:09:41 UTC (rev 17474)
@@ -210,9 +210,10 @@
String[] mappings = new String[0];
String[] classpath = new String[0];
- cfgName = node.getAttribute(NAME_ATTRIB);
+ if (node.hasAttribute(NAME_ATTRIB)) {
+ cfgName = node.getAttribute(NAME_ATTRIB);
+ }
-
String attribute = node.getAttribute(ANNOTATIONS_ATTRIB);
if(StringHelper.isNotEmpty( attribute )) {
boolean oldAnnotationFlag = ((attribute != null) &&
attribute.equalsIgnoreCase("true")); //$NON-NLS-1$
@@ -231,7 +232,7 @@
setProjectName( attribute );
attribute = node.getAttribute( USE_PROJECT_CLASSPATH_ATTRIB );
- setUseProjectClasspath((attribute != null) &&
attribute.equalsIgnoreCase("true")); //$NON-NLS-1$
+ setUseProjectClasspath("true".equalsIgnoreCase(attribute)); //$NON-NLS-1$
attribute = node.getAttribute(ENTITYRESOLVER_ATTRIB);
if(attribute!=null && attribute.trim().length()>0) {
@@ -240,12 +241,18 @@
NodeList elements = node.getElementsByTagName(HIBERNATE_CONFIG_XML_TAG);
if(elements.getLength()==1) {
- cfgFile = ( (Element)elements.item(0) ).getAttribute(LOCATION_ATTRIB);
+ final Element el = (Element)elements.item(0);
+ if (el.hasAttribute(LOCATION_ATTRIB)) {
+ cfgFile = el.getAttribute(LOCATION_ATTRIB);
+ }
}
elements = node.getElementsByTagName(HIBERNATE_PROPERTIES_TAG);
if(elements.getLength()==1) {
- propFile = ( (Element)elements.item(0) ).getAttribute(LOCATION_ATTRIB);
+ final Element el = (Element)elements.item(0);
+ if (el.hasAttribute(LOCATION_ATTRIB)) {
+ propFile = el.getAttribute(LOCATION_ATTRIB);
+ }
}
@@ -276,7 +283,8 @@
result = new String[maps.getLength()];
for (int j = 0; j < maps.getLength(); j++) {
Element child = (Element) maps.item(j);
- result[j] = child.getAttribute(LOCATION_ATTRIB);
+ result[j] = child.hasAttribute(LOCATION_ATTRIB) ?
+ child.getAttribute(LOCATION_ATTRIB) : null;
}
}
return result;