Skip to content

Commit 2646049

Browse files
committed
work on wrapping up XML changes
1 parent f5cf7b3 commit 2646049

File tree

10 files changed

+225
-111
lines changed

10 files changed

+225
-111
lines changed

app/src/processing/mode/android/Manifest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import java.io.File;
2525
import java.io.FileNotFoundException;
26-
import java.io.FileReader;
2726
import java.io.IOException;
2827
import java.io.PrintWriter;
2928

@@ -201,7 +200,7 @@ protected void writeBuild(File file, String className,
201200
// load the copy from the build location and start messing with it
202201
XML mf = null;
203202
try {
204-
mf = new XML(new FileReader(file));
203+
mf = new XML(file);
205204

206205
// package name, or default
207206
String p = mf.getString("package").trim();
@@ -241,7 +240,7 @@ protected void load() {
241240
File manifestFile = getManifestFile();
242241
if (manifestFile.exists()) {
243242
try {
244-
xml = new XML(new FileReader(manifestFile));
243+
xml = new XML(manifestFile);
245244
} catch (Exception e) {
246245
e.printStackTrace();
247246
System.err.println("Problem reading AndroidManifest.xml, creating a new version");
@@ -261,7 +260,7 @@ protected void load() {
261260
if (xml == null) {
262261
writeBlankManifest(manifestFile);
263262
try {
264-
xml = new XML(new FileReader(manifestFile));
263+
xml = new XML(manifestFile);
265264
} catch (FileNotFoundException e) {
266265
System.err.println("Could not read " + manifestFile.getAbsolutePath());
267266
e.printStackTrace();

core/src/processing/core/PApplet.java

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5822,15 +5822,46 @@ header[17] image descriptor (packed bits)
58225822
* @see PApplet#loadTable(String)
58235823
*/
58245824
public XML loadXML(String filename) {
5825+
return loadXML(filename, null);
5826+
}
5827+
5828+
5829+
// version that uses 'options' though there are currently no supported options
5830+
public XML loadXML(String filename, String options) {
58255831
try {
5826-
return new XML(this, filename);
5832+
return new XML(createInput(filename), options);
58275833
} catch (Exception e) {
58285834
e.printStackTrace();
58295835
return null;
58305836
}
58315837
}
58325838

58335839

5840+
public XML parseXML(String xmlString) {
5841+
return parseXML(xmlString, null);
5842+
}
5843+
5844+
5845+
public XML parseXML(String xmlString, String options) {
5846+
try {
5847+
return XML.parse(xmlString, options);
5848+
} catch (Exception e) {
5849+
e.printStackTrace();
5850+
return null;
5851+
}
5852+
}
5853+
5854+
5855+
public boolean saveXML(XML xml, String filename) {
5856+
return saveXML(xml, filename, null);
5857+
}
5858+
5859+
5860+
public boolean saveXML(XML xml, String filename, String options) {
5861+
return xml.save(saveFile(filename), options);
5862+
}
5863+
5864+
58345865
public Table createTable() {
58355866
return new Table();
58365867
}
@@ -5869,17 +5900,19 @@ public Table loadTable(String filename, String options) {
58695900
}
58705901

58715902

5872-
public void saveTable(Table table, String filename) {
5873-
saveTable(table, filename, null);
5903+
public boolean saveTable(Table table, String filename) {
5904+
return saveTable(table, filename, null);
58745905
}
58755906

58765907

5877-
public void saveTable(Table table, String filename, String options) {
5908+
public boolean saveTable(Table table, String filename, String options) {
58785909
try {
58795910
table.save(saveFile(filename), options);
5911+
return true;
58805912
} catch (IOException e) {
58815913
e.printStackTrace();
58825914
}
5915+
return false;
58835916
}
58845917

58855918

@@ -10847,6 +10880,11 @@ public PShape loadShape(String filename) {
1084710880
}
1084810881

1084910882

10883+
public PShape loadShape(String filename, String options) {
10884+
return g.loadShape(filename, options);
10885+
}
10886+
10887+
1085010888
/**
1085110889
* @webref shape
1085210890
* @see PShape

core/src/processing/core/PGraphics.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,11 @@ public void endShape(int mode) {
16041604
* @see PApplet#createShape()
16051605
*/
16061606
public PShape loadShape(String filename) {
1607+
return loadShape(filename, null);
1608+
}
1609+
1610+
1611+
public PShape loadShape(String filename, String options) {
16071612
showMissingWarning("loadShape");
16081613
return null;
16091614
}

core/src/processing/core/PGraphicsJava2D.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,17 +1380,23 @@ public void update(boolean tint, int tintColor) {
13801380

13811381
@Override
13821382
public PShape loadShape(String filename) {
1383+
return loadShape(filename, null);
1384+
}
1385+
1386+
1387+
@Override
1388+
public PShape loadShape(String filename, String options) {
13831389
String extension = PApplet.getExtension(filename);
13841390

13851391
PShapeSVG svg = null;
13861392

13871393
if (extension.equals("svg")) {
1388-
svg = new PShapeSVG(parent, filename);
1394+
svg = new PShapeSVG(parent.loadXML(filename));
13891395

13901396
} else if (extension.equals("svgz")) {
13911397
try {
13921398
InputStream input = new GZIPInputStream(parent.createInput(filename));
1393-
XML xml = new XML(PApplet.createReader(input));
1399+
XML xml = new XML(input, options);
13941400
svg = new PShapeSVG(xml);
13951401
} catch (Exception e) {
13961402
e.printStackTrace();

core/src/processing/core/PShapeSVG.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,14 @@ public class PShapeSVG extends PShape {
159159
String fillName; // id of another object
160160

161161

162-
/**
163-
* Initializes a new SVG Object with the given filename.
164-
*/
165-
public PShapeSVG(PApplet parent, String filename) {
166-
// this will grab the root document, starting <svg ...>
167-
// the xml version and initial comments are ignored
168-
this(parent.loadXML(filename));
169-
}
162+
// /**
163+
// * Initializes a new SVG Object with the given filename.
164+
// */
165+
// public PShapeSVG(PApplet parent, String filename) {
166+
// // this will grab the root document, starting <svg ...>
167+
// // the xml version and initial comments are ignored
168+
// this(parent.loadXML(filename));
169+
// }
170170

171171

172172
/**

core/src/processing/data/Table.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ public Table(File file, String options) throws IOException {
119119
}
120120

121121

122+
public Table(InputStream input) throws IOException {
123+
this(input, null);
124+
}
125+
126+
122127
/**
123128
* Read the table from a stream. Possible options include:
124129
* <ul>
@@ -479,7 +484,6 @@ static protected int nextComma(char[] c, int index) {
479484
// compiler) of an inner class by the runtime.
480485

481486
/** incomplete, do not use */
482-
// public void parseInto(PApplet sketch, String fieldName) {
483487
public void parseInto(Object enclosingObject, String fieldName) {
484488
Class<?> target = null;
485489
Object outgoing = null;
@@ -1043,14 +1047,23 @@ public void setTableType(String type) {
10431047

10441048
/**
10451049
* Set the titles (and if a second column is present) the data types for
1046-
* this table based on a file loaded separately.
1050+
* this table based on a file loaded separately. This will look for the
1051+
* title in column 0, and the type in column 1. Better yet, specify a
1052+
* column named "title" and another named "type" in the dictionary table
1053+
* to future-proof the code.
10471054
* @param dictionary
10481055
*/
10491056
public void setColumnTypes(Table dictionary) {
1050-
setColumnTitles(dictionary.getStringColumn(0));
1057+
int titleCol = 0;
1058+
int typeCol = 1;
1059+
if (dictionary.hasColumnTitles()) {
1060+
titleCol = dictionary.getColumnIndex("title", true);
1061+
typeCol = dictionary.getColumnIndex("type", true);
1062+
}
1063+
setColumnTitles(dictionary.getStringColumn(titleCol));
10511064
if (dictionary.getColumnCount() > 1) {
10521065
for (int i = 0; i < dictionary.getRowCount(); i++) {
1053-
setColumnType(i, dictionary.getString(i, 1));
1066+
setColumnType(i, dictionary.getString(i, typeCol));
10541067
}
10551068
}
10561069
}
@@ -1061,7 +1074,9 @@ public void setColumnTypes(Table dictionary) {
10611074

10621075
/**
10631076
* Remove the first row from the data set, and use it as the column titles.
1077+
* Use loadTable("table.csv", "header") instead.
10641078
*/
1079+
@Deprecated
10651080
public String[] removeTitleRow() {
10661081
String[] titles = getStringRow(0);
10671082
removeRow(0);
@@ -1089,6 +1104,11 @@ public void setColumnTitle(int column, String title) {
10891104
}
10901105

10911106

1107+
public boolean hasColumnTitles() {
1108+
return columnTitles != null;
1109+
}
1110+
1111+
10921112
public String[] getColumnTitles() {
10931113
return columnTitles;
10941114
}

core/src/processing/data/TableODS.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ public TableODS(PApplet parent, String filename, String worksheet, boolean actua
4343
*/
4444
protected TableODS(InputStream input, String worksheet, boolean actual) {
4545
try {
46-
InputStreamReader isr = new InputStreamReader(input, "UTF-8");
47-
BufferedReader reader = new BufferedReader(isr);
48-
read(reader, worksheet, actual);
46+
// InputStreamReader isr = new InputStreamReader(input, "UTF-8");
47+
// BufferedReader reader = new BufferedReader(isr);
48+
// read(reader, worksheet, actual);
49+
read(input, worksheet, actual);
4950

5051
} catch (UnsupportedEncodingException uee) {
5152
uee.printStackTrace();
@@ -59,8 +60,11 @@ protected TableODS(InputStream input, String worksheet, boolean actual) {
5960
}
6061

6162

62-
protected void read(BufferedReader reader, String worksheet, boolean actual) throws IOException, ParserConfigurationException, SAXException {
63-
XML xml = new XML(reader);
63+
// protected void read(BufferedReader reader, String worksheet, boolean actual) throws IOException, ParserConfigurationException, SAXException {
64+
// XML xml = new XML(reader);
65+
protected void read(InputStream input, String worksheet, boolean actual) throws IOException, ParserConfigurationException, SAXException {
66+
XML xml = new XML(input);
67+
6468
// XML x = new XML(reader);
6569
// PApplet.saveStrings(new File("/Users/fry/Desktop/namespacefix.xml"), new String[] { xml.toString() });
6670
// PApplet.saveStrings(new File("/Users/fry/Desktop/newparser.xml"), new String[] { x.toString() });

0 commit comments

Comments
 (0)