more fix for defect #16

This commit is contained in:
ccancellieri 2011-09-14 01:24:17 +02:00
parent b48b04be9c
commit f179c04a42
2 changed files with 16 additions and 13 deletions

View File

@ -56,28 +56,22 @@ public class PropertyXMLEncoder extends XmlElement {
public PropertyXMLEncoder(final String rootName) {
super(rootName);
}
protected void add(final String key, final String value) {
if (key != null && value != null) {
add(this.getRoot(), key, value);
}
}
protected void set(final String key, final String value) {
set(getRoot(), key, value);
public void set(final String key, final String value) {
if (key != null && value != null) {
set(getRoot(), key, value);
}
}
private void set(final Element e, final String key, final String value){
if (!key.contains("/")) {
if (key != null && value != null) {
Element pp = null;
if ((pp = contains(key)) == null)
add(key, value);
add(e,key, value);
else {
remove(pp);
add(key, value);
add(e,key, value);
}
}
} else {
final int i = key.indexOf("/");
final String childName = key.substring(0, i);
@ -86,11 +80,19 @@ public class PropertyXMLEncoder extends XmlElement {
Element child = e.getChild(childName);
if (child == null) {
child = new Element(childName);
e.addContent(child);
add(child,newkey,value);
}
set(child, newkey, value);
}
}
public void add(final String key, final String value) {
if (key != null && value != null) {
add(this.getRoot(), key, value);
}
}
private void add(Element e, String key, String value) {
if (!key.contains("/")) {
e.addContent(new Element(key).setText(value));

View File

@ -90,7 +90,8 @@ public class GSCoverageEncoderTest extends TestCase {
dim2.addPresentation(Presentation.LIST);
encoder.addMetadata("elev", dim2);
LOGGER.info(encoder.toString());
if (LOGGER.isInfoEnabled())
LOGGER.info(encoder.toString());
final Element el=encoder.contains("metadata");
Assert.assertNotNull(el);