From 91972d0e9d2dccd0449857daddcae7a2bc6226a7 Mon Sep 17 00:00:00 2001 From: benfry Date: Sat, 22 Dec 2012 16:35:51 +0000 Subject: [PATCH] fix XML indentation and Android issues (issue #1512) --- android/core/src/processing/data/XML.java | 16 +++++++--------- core/src/processing/data/XML.java | 16 +++++++--------- core/todo.txt | 5 +++-- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/android/core/src/processing/data/XML.java b/android/core/src/processing/data/XML.java index f4e9e90ac..14556c8e4 100644 --- a/android/core/src/processing/data/XML.java +++ b/android/core/src/processing/data/XML.java @@ -829,25 +829,23 @@ public class XML implements Serializable { // least the Giants are getting blown out by the Falcons. final String decl = ""; - - // needed for splitting or when adding decl below? - //System.getProperty("line.separator") + final String sep = System.getProperty("line.separator"); StringWriter tempWriter = new StringWriter(); StreamResult tempResult = new StreamResult(tempWriter); transformer.transform(new DOMSource(node), tempResult); - String[] tempLines = PApplet.split(tempWriter.toString(), '\n'); - PApplet.println(tempLines); - if (tempLines[0].startsWith(decl)) { + String[] tempLines = PApplet.split(tempWriter.toString(), sep); +// PApplet.println(tempLines); + if (tempLines[0].startsWith("") + 2; //if (tempLines[0].length() == decl.length()) { if (tempLines[0].length() == declEnd) { // If it's all the XML declaration, remove it - PApplet.println("removing first line"); +// PApplet.println("removing first line"); tempLines = PApplet.subset(tempLines, 1); } else { - PApplet.println("removing part of first line"); +// PApplet.println("removing part of first line"); // If the first node has been moved to this line, be more careful //tempLines[0] = tempLines[0].substring(decl.length()); tempLines[0] = tempLines[0].substring(declEnd); @@ -866,7 +864,7 @@ public class XML implements Serializable { // DOMSource source = new DOMSource(node); Source source = new StreamSource(new StringReader(singleLine)); transformer.transform(source, xmlOutput); - return decl + "\n" + stringWriter.toString(); + return decl + sep + stringWriter.toString(); // return xmlOutput.getWriter().toString(); } catch (Exception e) { diff --git a/core/src/processing/data/XML.java b/core/src/processing/data/XML.java index f4e9e90ac..14556c8e4 100644 --- a/core/src/processing/data/XML.java +++ b/core/src/processing/data/XML.java @@ -829,25 +829,23 @@ public class XML implements Serializable { // least the Giants are getting blown out by the Falcons. final String decl = ""; - - // needed for splitting or when adding decl below? - //System.getProperty("line.separator") + final String sep = System.getProperty("line.separator"); StringWriter tempWriter = new StringWriter(); StreamResult tempResult = new StreamResult(tempWriter); transformer.transform(new DOMSource(node), tempResult); - String[] tempLines = PApplet.split(tempWriter.toString(), '\n'); - PApplet.println(tempLines); - if (tempLines[0].startsWith(decl)) { + String[] tempLines = PApplet.split(tempWriter.toString(), sep); +// PApplet.println(tempLines); + if (tempLines[0].startsWith("") + 2; //if (tempLines[0].length() == decl.length()) { if (tempLines[0].length() == declEnd) { // If it's all the XML declaration, remove it - PApplet.println("removing first line"); +// PApplet.println("removing first line"); tempLines = PApplet.subset(tempLines, 1); } else { - PApplet.println("removing part of first line"); +// PApplet.println("removing part of first line"); // If the first node has been moved to this line, be more careful //tempLines[0] = tempLines[0].substring(decl.length()); tempLines[0] = tempLines[0].substring(declEnd); @@ -866,7 +864,7 @@ public class XML implements Serializable { // DOMSource source = new DOMSource(node); Source source = new StreamSource(new StringReader(singleLine)); transformer.transform(source, xmlOutput); - return decl + "\n" + stringWriter.toString(); + return decl + sep + stringWriter.toString(); // return xmlOutput.getWriter().toString(); } catch (Exception e) { diff --git a/core/todo.txt b/core/todo.txt index 74e6cd19c..4334263fc 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -87,8 +87,9 @@ o 3) we deprecate our nice short getFloat/getInt/etc and go with o getXxxxAttribute() and getXxxxContent() methods. X not gonna do getFloatContent() since it's not really any shorter X beginning slash in getChild() threw an NPE -_ XML.format(0) throws error -_ http://code.google.com/p/processing/issues/detail?id=1512 +X XML.format(0) throws error +X http://code.google.com/p/processing/issues/detail?id=1512 +X fix XML problems on Android as well decisions on data X are we comfortable with setInt/Float/etc instead of just set(int, blah)