close 110. IllegalArgument on getVersion on Geoserver 2.1
This commit is contained in:
parent
471c860007
commit
eee603e2fe
@ -43,7 +43,7 @@ import org.jdom.Element;
|
||||
public class GSVersionDecoder extends XmlElement {
|
||||
public final static String ABOUT = "about";
|
||||
|
||||
final private GSAboutResource geoserver;
|
||||
private GSAboutResource geoserver;
|
||||
|
||||
public class GSAboutResource extends XmlElement {
|
||||
public final static String RESOURCE = "resource";
|
||||
@ -52,10 +52,14 @@ public class GSVersionDecoder extends XmlElement {
|
||||
|
||||
public final static String VERSION = "Version";
|
||||
|
||||
final private Element version;
|
||||
private Element version;
|
||||
|
||||
public GSAboutResource() {
|
||||
super(RESOURCE);
|
||||
create();
|
||||
}
|
||||
|
||||
private void create(){
|
||||
setRoot(RESOURCE);
|
||||
version = new Element(VERSION);
|
||||
addContent(version);
|
||||
}
|
||||
@ -78,8 +82,14 @@ public class GSVersionDecoder extends XmlElement {
|
||||
}
|
||||
|
||||
public GSAboutResource(Element el) {
|
||||
super(el);
|
||||
version = ElementUtils.contains(el, GSAboutResource.VERSION);
|
||||
super();
|
||||
if (el!=null){
|
||||
setRoot(el);
|
||||
version = ElementUtils.contains(el, GSAboutResource.VERSION);
|
||||
} else {
|
||||
create();
|
||||
setVersion(GSVersionDecoder.VERSION.UNRECOGNIZED.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void setVersion(String v){
|
||||
@ -94,13 +104,22 @@ public class GSVersionDecoder extends XmlElement {
|
||||
* @param document
|
||||
*/
|
||||
public GSVersionDecoder(String document) {
|
||||
super(JDOMBuilder.buildElement(document));
|
||||
geoserver = new GSAboutResource(ElementUtils.contains(this.getRoot(),
|
||||
GSAboutResource.RESOURCE));
|
||||
Element root=JDOMBuilder.buildElement(document);
|
||||
if (root!=null){
|
||||
setRoot(root);
|
||||
geoserver = new GSAboutResource(ElementUtils.contains(this.getRoot(),
|
||||
GSAboutResource.RESOURCE));
|
||||
}else {
|
||||
create();
|
||||
}
|
||||
}
|
||||
|
||||
public GSVersionDecoder() {
|
||||
super("about");
|
||||
create();
|
||||
}
|
||||
|
||||
private void create(){
|
||||
setRoot("about");
|
||||
geoserver = new GSAboutResource();
|
||||
addContent(geoserver.getRoot());
|
||||
}
|
||||
|
||||
@ -39,9 +39,10 @@ import org.jdom.output.XMLOutputter;
|
||||
*/
|
||||
public class XmlElement{
|
||||
|
||||
private final Element root;
|
||||
private Element root;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final static XMLOutputter OUTPUTTER = new XMLOutputter(Format.getCompactFormat());
|
||||
|
||||
@ -52,14 +53,34 @@ public class XmlElement{
|
||||
public XmlElement(final Element e) {
|
||||
root = e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty constructor:<br/>
|
||||
* Use {@link #setRoot()} to initialize the root
|
||||
*/
|
||||
protected XmlElement() {
|
||||
}
|
||||
|
||||
/**
|
||||
* update the root of this node
|
||||
* @param root
|
||||
*/
|
||||
protected void setRoot(final Element root) {
|
||||
this.root = root;
|
||||
}
|
||||
|
||||
/**
|
||||
* update the root of this node
|
||||
* @param name is the name of the root node
|
||||
*/
|
||||
protected void setRoot(final String name){
|
||||
root=new Element(name);
|
||||
}
|
||||
|
||||
public Element getRoot(){
|
||||
return root;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private XmlElement(){root=null;};
|
||||
|
||||
protected void add(final String nodename, final String nodetext) {
|
||||
add(nodename,new Text(nodetext));
|
||||
}
|
||||
|
||||
@ -66,6 +66,10 @@ public class VersionDecoderTest extends GeoserverRESTTest {
|
||||
Assert.assertEquals(GSVersionDecoder.VERSION.v23, dec.getVersion());
|
||||
Assert.assertEquals("_CustomGeoServerName_", dec.getGeoServer().getName());
|
||||
|
||||
dec=new GSVersionDecoder(null);
|
||||
Assert.assertEquals(GSVersionDecoder.VERSION.UNRECOGNIZED, dec.getVersion());
|
||||
Assert.assertEquals(null, dec.getGeoServer().getName());
|
||||
|
||||
//print(dec.getRoot());
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user