public static int parseValue(int def, XMLHelper node) { try { return Integer.parseInt(node.getValue()); } catch (Exception e) { node.setValue(def); return def; } }
public static Color parseValue(Color def, XMLHelper node) { try { return Color.decode(node.getValue()); } catch (Exception e) { node.setValue(def); return def; } }
public static float parseValue(float def, XMLHelper node) { try { return Float.parseFloat(node.getValue()); } catch (Exception e) { node.setValue(def); return def; } }
public XMLHelper createSubNode(String subnode) { int pos = subnode.lastIndexOf(DELIM); if (pos >= 0) { XMLHelper helper = getSubNode(subnode.substring(0, pos)); return helper.createSubNode(subnode.substring(pos + 1)); } else { return new XMLHelper( (Element) element.appendChild(element.getOwnerDocument().createElement(subnode)), true); } }
public static boolean parseValue(boolean def, XMLHelper node) { String value = node.getValue().toUpperCase(); if ("TRUE".compareTo(value) == 0) { return true; } else if ("FALSE".compareTo(value) == 0) { return false; } else { node.setValue(def); return def; } }
public String getValue(String subnode, String def) { XMLHelper helper = getSubNode(subnode); // To account for the case where the default is not a blank string, but we may want to // eventually set the setting to one // We don't do this if we are doing getValue() on this node, because we should know if its new // or not if (helper.getIsNewNode()) { helper.setValue(def); return def; } else { return helper.getValue(); } }
public XMLHelper getSubNodeByName(String subnode, String name, String namenode) { XMLHelper[] list = getSubNodeList(subnode); if (list.length != 0) { for (int i = 0; i < list.length; i++) { if (list[i].getSubNode(namenode).getValue().compareTo(name) == 0) { return list[i]; } } } XMLHelper node = createSubNode(subnode); node.createSubNode(namenode).setValue(name); return node; }
public void deleteSubNode(String subnode) { int pos = subnode.lastIndexOf(DELIM); if (pos >= 0) { XMLHelper helper = getSubNode(subnode.substring(0, pos)); helper.deleteSubNode(subnode.substring(pos + 1)); } else { NodeList list = getImediateElementsByTagName(subnode); try { element.removeChild(list.item(0)); } catch (Exception e) { } } }
public XMLHelper[] getSubNodeList(String subnode) { int pos = subnode.lastIndexOf(DELIM); if (pos >= 0) { XMLHelper helper = getSubNode(subnode.substring(0, pos)); return helper.getSubNodeList(subnode.substring(pos + 1)); } else { NodeList list = getImediateElementsByTagName(subnode); XMLHelper[] results = new XMLHelper[list.getLength()]; int length = list.getLength(); for (int i = 0; i < length; i++) { results[i] = new XMLHelper((Element) list.item(i)); } return results; } }
public void deleteSubNodes(String subnode) { int pos = subnode.lastIndexOf(DELIM); if (pos >= 0) { XMLHelper helper = getSubNode(subnode.substring(0, pos)); helper.deleteSubNodes(subnode.substring(pos + 1)); } else { NodeList list = getImediateElementsByTagName(subnode); int length = list.getLength(); for (int i = 0; i < length; i++) { try { element.removeChild(list.item(i)); } catch (Exception e) { } } } }