diff --git a/android/core/src/processing/data/XML.java b/android/core/src/processing/data/XML.java index 14556c8e4..e20921dc3 100644 --- a/android/core/src/processing/data/XML.java +++ b/android/core/src/processing/data/XML.java @@ -43,6 +43,8 @@ import processing.core.PApplet; * * @webref data:composite * @see PApplet#loadXML(String) + * @see PApplet#parseXML(String) + * @see PApplet#saveXML(XML, String) */ public class XML implements Serializable { @@ -75,16 +77,26 @@ public class XML implements Serializable { // this(parent.createReader(filename)); // } + + /** + * @param file description TBD + */ public XML(File file) throws IOException, ParserConfigurationException, SAXException { this(file, null); } + /** + * @param options description TBD + */ public XML(File file, String options) throws IOException, ParserConfigurationException, SAXException { this(PApplet.createReader(file), options); } + /** + * @param input description TBD + */ public XML(InputStream input) throws IOException, ParserConfigurationException, SAXException { this(input, null); } @@ -138,6 +150,9 @@ public class XML implements Serializable { } + /** + * @param name description TBD + */ // TODO is there a more efficient way of doing this? wow. public XML(String name) throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); @@ -749,6 +764,58 @@ public class XML implements Serializable { } + public int getIntContent() { + return getIntContent(0); + } + + + public int getIntContent(int defaultValue) { + return PApplet.parseInt(node.getTextContent(), defaultValue); + } + + + public float getFloatContent() { + return getFloatContent(0); + } + + + public float getFloatContent(float defaultValue) { + return PApplet.parseFloat(node.getTextContent(), defaultValue); + } + + + public long getLongContent() { + return getLongContent(0); + } + + + public long getLongContent(long defaultValue) { + String c = node.getTextContent(); + if (c != null) { + try { + return Long.parseLong(c); + } catch (NumberFormatException nfe) { } + } + return defaultValue; + } + + + public double getDoubleContent() { + return getDoubleContent(0); + } + + + public double getDoubleContent(double defaultValue) { + String c = node.getTextContent(); + if (c != null) { + try { + return Double.parseDouble(c); + } catch (NumberFormatException nfe) { } + } + return defaultValue; + } + + /** * @webref xml:method * @brief Sets the content of an element @@ -758,6 +825,26 @@ public class XML implements Serializable { } + public void setIntContent(int value) { + setContent(String.valueOf(value)); + } + + + public void setFloatContent(float value) { + setContent(String.valueOf(value)); + } + + + public void setLongContent(long value) { + setContent(String.valueOf(value)); + } + + + public void setDoubleContent(double value) { + setContent(String.valueOf(value)); + } + + /** * Format this XML data as a String. * diff --git a/core/src/processing/data/XML.java b/core/src/processing/data/XML.java index 572c71065..71711e8b5 100644 --- a/core/src/processing/data/XML.java +++ b/core/src/processing/data/XML.java @@ -765,6 +765,58 @@ public class XML implements Serializable { } + public int getIntContent() { + return getIntContent(0); + } + + + public int getIntContent(int defaultValue) { + return PApplet.parseInt(node.getTextContent(), defaultValue); + } + + + public float getFloatContent() { + return getFloatContent(0); + } + + + public float getFloatContent(float defaultValue) { + return PApplet.parseFloat(node.getTextContent(), defaultValue); + } + + + public long getLongContent() { + return getLongContent(0); + } + + + public long getLongContent(long defaultValue) { + String c = node.getTextContent(); + if (c != null) { + try { + return Long.parseLong(c); + } catch (NumberFormatException nfe) { } + } + return defaultValue; + } + + + public double getDoubleContent() { + return getDoubleContent(0); + } + + + public double getDoubleContent(double defaultValue) { + String c = node.getTextContent(); + if (c != null) { + try { + return Double.parseDouble(c); + } catch (NumberFormatException nfe) { } + } + return defaultValue; + } + + /** * @webref xml:method * @brief Sets the content of an element @@ -774,6 +826,26 @@ public class XML implements Serializable { } + public void setIntContent(int value) { + setContent(String.valueOf(value)); + } + + + public void setFloatContent(float value) { + setContent(String.valueOf(value)); + } + + + public void setLongContent(long value) { + setContent(String.valueOf(value)); + } + + + public void setDoubleContent(double value) { + setContent(String.valueOf(value)); + } + + /** * Format this XML data as a String. * diff --git a/core/todo.txt b/core/todo.txt index 829d67c39..890cf3e03 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -6,14 +6,16 @@ X https://github.com/processing/processing/issues/1682 A image caches not being properly disposed (weak references broken?) X http://code.google.com/p/processing/issues/detail?id=1353 A https://github.com/processing/processing/issues/1391 +X implement content specifiers +X getIntContent() +X getFloatContent() +X getContent() or getStringContent()? _ tint() with JAVA2D does not automatically refresh (with possible fix) _ https://github.com/processing/processing/issues/1730 -_ implement content specifiers -getIntContent() -getFloatContent() -getContent() or getStringContent()? +_ table writing twice when .csv is added +_ https://github.com/processing/processing/issues/1734 finish json support _ https://github.com/processing/processing/issues/1660 diff --git a/todo.txt b/todo.txt index 5713d3785..e846ab225 100644 --- a/todo.txt +++ b/todo.txt @@ -8,10 +8,7 @@ X incorporate JDI changes from Manindra X fix autoformat to indent like the p5 book/examples X http://code.google.com/p/processing/issues/detail?id=325 X https://github.com/processing/processing/issues/364 -X fix problem with retina checking on Java 7 - -_ table writing twice when .csv is added -_ https://github.com/processing/processing/issues/1734 +X fix NPE problem with retina checking on Java 7 _ / breaks syntax highlighting _ https://github.com/processing/processing/issues/1681