File src/de/openrat/client/util/CMSNode.java

Last commit: Thu Jan 10 18:06:28 2019 +0100	Jan Dankert	Convert serverside-Exception into a Java Exception.
1 package de.openrat.client.util; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 6 public class CMSNode { 7 8 private static final CMSNode EMPTY_NODE = new CMSNode(null, null, new ArrayList<>()); 9 10 private String name; 11 private String value; 12 private List<CMSNode> children; 13 14 public CMSNode(String name, String value, List<CMSNode> children) { 15 super(); 16 this.name = name; 17 this.value = value; 18 this.children = children; 19 } 20 21 public List<CMSNode> getChildren() { 22 23 if (children != null) 24 return children; 25 else 26 return new ArrayList<CMSNode>(); 27 } 28 29 public String getFirstChildValue(String name) { 30 CMSNode node = getFirstChildByName(name); 31 if (node != null) 32 return node.getValue(); 33 else 34 return null; 35 } 36 37 public CMSNode getFirstChildByName(String name) { 38 39 if (children == null) 40 return EMPTY_NODE; 41 42 for (CMSNode node : children) { 43 if (name.equals(node.getName())) 44 return node; 45 } 46 47 return EMPTY_NODE; 48 } 49 50 public String getValue() { 51 return value; 52 } 53 54 public boolean isTrue() { 55 return Boolean.valueOf(value).booleanValue(); 56 } 57 58 public int toInt() { 59 return NumberUtils.toInt(value); 60 } 61 62 public long toLong() { 63 return NumberUtils.toLong(value); 64 } 65 66 67 public String getName() { 68 return name; 69 } 70 71 public boolean isEmpty() { 72 return name == null; 73 } 74 75 public boolean isNotEmpty() { 76 return !isEmpty(); 77 } 78 79 @Override 80 public String toString() { 81 return this.getClass().getSimpleName() + ": " + getName() + "=" + getValue() + " children:" + children.size() + " " 82 + children.toString(); 83 } 84 }
Download src/de/openrat/client/util/CMSNode.java
History Thu, 10 Jan 2019 18:06:28 +0100 Jan Dankert Convert serverside-Exception into a Java Exception. Fri, 30 Sep 2016 23:38:24 +0200 dankert Parsen der Server-Notices und füllen der CMSResponse. Weitere Doku mit JavaDoc. Fri, 30 Sep 2016 22:45:01 +0200 dankert first version of the java api.