propane 3.10.0-java → 3.11.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/wrapper/maven-wrapper.properties +1 -1
  3. data/CHANGELOG.md +2 -0
  4. data/README.md +7 -7
  5. data/lib/propane/app.rb +2 -5
  6. data/lib/propane/helper_methods.rb +6 -6
  7. data/lib/propane/version.rb +1 -1
  8. data/lib/{propane-3.10.0.jar → propane-3.11.0.jar} +0 -0
  9. data/pom.rb +6 -6
  10. data/pom.xml +6 -6
  11. data/propane.gemspec +3 -3
  12. data/src/main/java/monkstone/noise/OpenSimplex2F.java +838 -737
  13. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +8 -13
  14. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +14 -28
  15. data/src/main/java/processing/awt/PImageAWT.java +6 -4
  16. data/src/main/java/processing/core/PApplet.java +71 -59
  17. data/src/main/java/processing/core/PImage.java +14 -14
  18. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +13 -13
  19. data/src/main/java/processing/opengl/PShader.java +1 -6
  20. data/src/main/java/processing/opengl/PSurfaceJOGL.java +6 -6
  21. data/{lib/java/processing/opengl → src/main/resources}/cursors/arrow.png +0 -0
  22. data/{lib/java/processing/opengl → src/main/resources}/cursors/cross.png +0 -0
  23. data/{lib/java/processing/opengl → src/main/resources}/cursors/hand.png +0 -0
  24. data/{lib/java/processing/opengl → src/main/resources}/cursors/license.txt +0 -0
  25. data/{lib/java/processing/opengl → src/main/resources}/cursors/move.png +0 -0
  26. data/{lib/java/processing/opengl → src/main/resources}/cursors/text.png +0 -0
  27. data/{lib/java/processing/opengl → src/main/resources}/cursors/wait.png +0 -0
  28. data/{lib/java/processing/opengl → src/main/resources}/shaders/ColorFrag.glsl +0 -0
  29. data/{lib/java/processing/opengl → src/main/resources}/shaders/ColorVert.glsl +0 -0
  30. data/{lib/java/processing/opengl → src/main/resources}/shaders/LightFrag.glsl +0 -0
  31. data/{lib/java/processing/opengl → src/main/resources}/shaders/LightVert.glsl +0 -0
  32. data/{lib/java/processing/opengl → src/main/resources}/shaders/LineFrag.glsl +0 -0
  33. data/{lib/java/processing/opengl → src/main/resources}/shaders/LineVert.glsl +0 -0
  34. data/{lib/java/processing/opengl → src/main/resources}/shaders/MaskFrag.glsl +0 -0
  35. data/{lib/java/processing/opengl → src/main/resources}/shaders/PointFrag.glsl +0 -0
  36. data/{lib/java/processing/opengl → src/main/resources}/shaders/PointVert.glsl +0 -0
  37. data/{lib/java/processing/opengl → src/main/resources}/shaders/TexFrag.glsl +0 -0
  38. data/{lib/java/processing/opengl → src/main/resources}/shaders/TexLightFrag.glsl +0 -0
  39. data/{lib/java/processing/opengl → src/main/resources}/shaders/TexLightVert.glsl +0 -0
  40. data/{lib/java/processing/opengl → src/main/resources}/shaders/TexVert.glsl +0 -0
  41. data/test/test_helper.rb +1 -0
  42. data/vendors/Rakefile +1 -1
  43. metadata +29 -155
  44. data/lib/java/japplemenubar/JAppleMenuBar.java +0 -88
  45. data/lib/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
  46. data/lib/java/monkstone/ColorUtil.java +0 -127
  47. data/lib/java/monkstone/MathToolModule.java +0 -287
  48. data/lib/java/monkstone/PropaneLibrary.java +0 -46
  49. data/lib/java/monkstone/core/LibraryProxy.java +0 -136
  50. data/lib/java/monkstone/fastmath/DegLutTables.java +0 -111
  51. data/lib/java/monkstone/fastmath/Deglut.java +0 -71
  52. data/lib/java/monkstone/fastmath/package-info.java +0 -6
  53. data/lib/java/monkstone/filechooser/Chooser.java +0 -39
  54. data/lib/java/monkstone/noise/FastTerrain.java +0 -874
  55. data/lib/java/monkstone/noise/Noise.java +0 -90
  56. data/lib/java/monkstone/noise/NoiseGenerator.java +0 -75
  57. data/lib/java/monkstone/noise/NoiseMode.java +0 -28
  58. data/lib/java/monkstone/noise/OpenSimplex2F.java +0 -881
  59. data/lib/java/monkstone/noise/OpenSimplex2S.java +0 -1106
  60. data/lib/java/monkstone/noise/SmoothTerrain.java +0 -1099
  61. data/lib/java/monkstone/slider/CustomHorizontalSlider.java +0 -164
  62. data/lib/java/monkstone/slider/CustomVerticalSlider.java +0 -178
  63. data/lib/java/monkstone/slider/SimpleHorizontalSlider.java +0 -145
  64. data/lib/java/monkstone/slider/SimpleSlider.java +0 -166
  65. data/lib/java/monkstone/slider/SimpleVerticalSlider.java +0 -157
  66. data/lib/java/monkstone/slider/Slider.java +0 -61
  67. data/lib/java/monkstone/slider/SliderBar.java +0 -245
  68. data/lib/java/monkstone/slider/SliderGroup.java +0 -56
  69. data/lib/java/monkstone/slider/WheelHandler.java +0 -35
  70. data/lib/java/monkstone/vecmath/GfxRender.java +0 -86
  71. data/lib/java/monkstone/vecmath/JRender.java +0 -56
  72. data/lib/java/monkstone/vecmath/ShapeRender.java +0 -87
  73. data/lib/java/monkstone/vecmath/package-info.java +0 -20
  74. data/lib/java/monkstone/vecmath/vec2/Vec2.java +0 -802
  75. data/lib/java/monkstone/vecmath/vec2/package-info.java +0 -6
  76. data/lib/java/monkstone/vecmath/vec3/Vec3.java +0 -727
  77. data/lib/java/monkstone/vecmath/vec3/package-info.java +0 -6
  78. data/lib/java/monkstone/videoevent/CaptureEvent.java +0 -27
  79. data/lib/java/monkstone/videoevent/MovieEvent.java +0 -32
  80. data/lib/java/monkstone/videoevent/package-info.java +0 -20
  81. data/lib/java/processing/awt/PGraphicsJava2D.java +0 -3040
  82. data/lib/java/processing/awt/PImageAWT.java +0 -377
  83. data/lib/java/processing/awt/PShapeJava2D.java +0 -387
  84. data/lib/java/processing/awt/PSurfaceAWT.java +0 -1581
  85. data/lib/java/processing/awt/ShimAWT.java +0 -581
  86. data/lib/java/processing/core/PApplet.java +0 -15156
  87. data/lib/java/processing/core/PConstants.java +0 -523
  88. data/lib/java/processing/core/PFont.java +0 -1126
  89. data/lib/java/processing/core/PGraphics.java +0 -8600
  90. data/lib/java/processing/core/PImage.java +0 -3377
  91. data/lib/java/processing/core/PMatrix.java +0 -208
  92. data/lib/java/processing/core/PMatrix2D.java +0 -562
  93. data/lib/java/processing/core/PMatrix3D.java +0 -890
  94. data/lib/java/processing/core/PShape.java +0 -3561
  95. data/lib/java/processing/core/PShapeOBJ.java +0 -483
  96. data/lib/java/processing/core/PShapeSVG.java +0 -2016
  97. data/lib/java/processing/core/PStyle.java +0 -63
  98. data/lib/java/processing/core/PSurface.java +0 -198
  99. data/lib/java/processing/core/PSurfaceNone.java +0 -431
  100. data/lib/java/processing/core/PVector.java +0 -1066
  101. data/lib/java/processing/core/ThinkDifferent.java +0 -115
  102. data/lib/java/processing/data/DoubleDict.java +0 -850
  103. data/lib/java/processing/data/DoubleList.java +0 -928
  104. data/lib/java/processing/data/FloatDict.java +0 -847
  105. data/lib/java/processing/data/FloatList.java +0 -936
  106. data/lib/java/processing/data/IntDict.java +0 -807
  107. data/lib/java/processing/data/IntList.java +0 -936
  108. data/lib/java/processing/data/JSONArray.java +0 -1260
  109. data/lib/java/processing/data/JSONObject.java +0 -2282
  110. data/lib/java/processing/data/JSONTokener.java +0 -435
  111. data/lib/java/processing/data/LongDict.java +0 -802
  112. data/lib/java/processing/data/LongList.java +0 -937
  113. data/lib/java/processing/data/Sort.java +0 -46
  114. data/lib/java/processing/data/StringDict.java +0 -613
  115. data/lib/java/processing/data/StringList.java +0 -800
  116. data/lib/java/processing/data/Table.java +0 -4936
  117. data/lib/java/processing/data/TableRow.java +0 -198
  118. data/lib/java/processing/data/XML.java +0 -1156
  119. data/lib/java/processing/dxf/RawDXF.java +0 -404
  120. data/lib/java/processing/event/Event.java +0 -125
  121. data/lib/java/processing/event/KeyEvent.java +0 -70
  122. data/lib/java/processing/event/MouseEvent.java +0 -114
  123. data/lib/java/processing/event/TouchEvent.java +0 -57
  124. data/lib/java/processing/javafx/PGraphicsFX2D.java +0 -32
  125. data/lib/java/processing/javafx/PSurfaceFX.java +0 -173
  126. data/lib/java/processing/net/Client.java +0 -744
  127. data/lib/java/processing/net/Server.java +0 -388
  128. data/lib/java/processing/opengl/FontTexture.java +0 -378
  129. data/lib/java/processing/opengl/FrameBuffer.java +0 -513
  130. data/lib/java/processing/opengl/LinePath.java +0 -627
  131. data/lib/java/processing/opengl/LineStroker.java +0 -681
  132. data/lib/java/processing/opengl/PGL.java +0 -3483
  133. data/lib/java/processing/opengl/PGraphics2D.java +0 -615
  134. data/lib/java/processing/opengl/PGraphics3D.java +0 -281
  135. data/lib/java/processing/opengl/PGraphicsOpenGL.java +0 -13753
  136. data/lib/java/processing/opengl/PJOGL.java +0 -2008
  137. data/lib/java/processing/opengl/PShader.java +0 -1484
  138. data/lib/java/processing/opengl/PShapeOpenGL.java +0 -5269
  139. data/lib/java/processing/opengl/PSurfaceJOGL.java +0 -1385
  140. data/lib/java/processing/opengl/Texture.java +0 -1696
  141. data/lib/java/processing/opengl/VertexBuffer.java +0 -88
  142. data/lib/java/processing/pdf/PGraphicsPDF.java +0 -581
  143. data/lib/java/processing/svg/PGraphicsSVG.java +0 -378
  144. data/src/main/java/processing/opengl/cursors/arrow.png +0 -0
  145. data/src/main/java/processing/opengl/cursors/cross.png +0 -0
  146. data/src/main/java/processing/opengl/cursors/hand.png +0 -0
  147. data/src/main/java/processing/opengl/cursors/license.txt +0 -27
  148. data/src/main/java/processing/opengl/cursors/move.png +0 -0
  149. data/src/main/java/processing/opengl/cursors/text.png +0 -0
  150. data/src/main/java/processing/opengl/cursors/wait.png +0 -0
  151. data/src/main/java/processing/opengl/shaders/ColorFrag.glsl +0 -32
  152. data/src/main/java/processing/opengl/shaders/ColorVert.glsl +0 -34
  153. data/src/main/java/processing/opengl/shaders/LightFrag.glsl +0 -33
  154. data/src/main/java/processing/opengl/shaders/LightVert.glsl +0 -151
  155. data/src/main/java/processing/opengl/shaders/LineFrag.glsl +0 -32
  156. data/src/main/java/processing/opengl/shaders/LineVert.glsl +0 -100
  157. data/src/main/java/processing/opengl/shaders/MaskFrag.glsl +0 -40
  158. data/src/main/java/processing/opengl/shaders/PointFrag.glsl +0 -32
  159. data/src/main/java/processing/opengl/shaders/PointVert.glsl +0 -56
  160. data/src/main/java/processing/opengl/shaders/TexFrag.glsl +0 -37
  161. data/src/main/java/processing/opengl/shaders/TexLightFrag.glsl +0 -37
  162. data/src/main/java/processing/opengl/shaders/TexLightVert.glsl +0 -157
  163. data/src/main/java/processing/opengl/shaders/TexVert.glsl +0 -38
@@ -1,1156 +0,0 @@
1
- /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
-
3
- /*
4
- Part of the Processing project - http://processing.org
5
-
6
- Copyright (c) 2012 The Processing Foundation
7
- Copyright (c) 2009-12 Ben Fry and Casey Reas
8
-
9
- This library is free software; you can redistribute it and/or
10
- modify it under the terms of the GNU Lesser General Public
11
- License as published by the Free Software Foundation, version 2.
12
-
13
- This library is distributed in the hope that it will be useful,
14
- but WITHOUT ANY WARRANTY; without even the implied warranty
15
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
- See the GNU Lesser General Public License for more details.
17
-
18
- You should have received a copy of the GNU Lesser General
19
- Public License along with this library; if not, write to the
20
- Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21
- Boston, MA 02111-1307 USA
22
- */
23
-
24
- package processing.data;
25
-
26
- import java.io.*;
27
-
28
- import javax.xml.parsers.*;
29
-
30
- import org.w3c.dom.*;
31
- import org.xml.sax.*;
32
-
33
- import javax.xml.transform.*;
34
- import javax.xml.transform.dom.*;
35
- import javax.xml.transform.stream.*;
36
- import javax.xml.xpath.XPathConstants;
37
- import javax.xml.xpath.XPathExpression;
38
- import javax.xml.xpath.XPathFactory;
39
-
40
- import processing.core.PApplet;
41
-
42
-
43
- /**
44
- * This is the base class used for the Processing XML library,
45
- * representing a single node of an XML tree.
46
- *
47
- * @webref data:composite
48
- * @see PApplet#loadXML(String)
49
- * @see PApplet#parseXML(String)
50
- * @see PApplet#saveXML(XML, String)
51
- */
52
- public class XML implements Serializable {
53
-
54
- /** The internal representation, a DOM node. */
55
- protected Node node;
56
-
57
- // /** Cached locally because it's used often. */
58
- // protected String name;
59
-
60
- /** The parent element. */
61
- protected XML parent;
62
-
63
- /** Child elements, once loaded. */
64
- protected XML[] children;
65
-
66
- /**
67
- * @nowebref
68
- */
69
- protected XML() { }
70
-
71
-
72
- // /**
73
- // * Begin parsing XML data passed in from a PApplet. This code
74
- // * wraps exception handling, for more advanced exception handling,
75
- // * use the constructor that takes a Reader or InputStream.
76
- // *
77
- // * @throws SAXException
78
- // * @throws ParserConfigurationException
79
- // * @throws IOException
80
- // */
81
- // public XML(PApplet parent, String filename) throws IOException, ParserConfigurationException, SAXException {
82
- // this(parent.createReader(filename));
83
- // }
84
-
85
-
86
- /**
87
- * Advanced users only; use loadXML() in PApplet. This is not a supported
88
- * function and is subject to change. It is available simply for users that
89
- * would like to handle the exceptions in a particular way.
90
- *
91
- * @nowebref
92
- */
93
- public XML(File file) throws IOException, ParserConfigurationException, SAXException {
94
- this(file, null);
95
- }
96
-
97
-
98
- /**
99
- * Advanced users only; use loadXML() in PApplet.
100
- *
101
- * @nowebref
102
- */
103
- public XML(File file, String options) throws IOException, ParserConfigurationException, SAXException {
104
- this(PApplet.createReader(file), options);
105
- }
106
-
107
- /**
108
- * @nowebref
109
- */
110
- public XML(InputStream input) throws IOException, ParserConfigurationException, SAXException {
111
- this(input, null);
112
- }
113
-
114
-
115
- /**
116
- * Unlike the loadXML() method in PApplet, this version works with files
117
- * that are not in UTF-8 format.
118
- *
119
- * @nowebref
120
- */
121
- public XML(InputStream input, String options) throws IOException, ParserConfigurationException, SAXException {
122
- //this(PApplet.createReader(input), options); // won't handle non-UTF8
123
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
124
-
125
- try {
126
- // Prevent 503 errors from www.w3.org
127
- factory.setAttribute("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
128
- } catch (IllegalArgumentException e) {
129
- // ignore this; Android doesn't like it
130
- }
131
-
132
- factory.setExpandEntityReferences(false);
133
- DocumentBuilder builder = factory.newDocumentBuilder();
134
- Document document = builder.parse(new InputSource(input));
135
- node = document.getDocumentElement();
136
- }
137
-
138
-
139
- /**
140
- * Advanced users only; use loadXML() in PApplet.
141
- *
142
- * @nowebref
143
- */
144
- public XML(Reader reader) throws IOException, ParserConfigurationException, SAXException {
145
- this(reader, null);
146
- }
147
-
148
-
149
- /**
150
- * Advanced users only; use loadXML() in PApplet.
151
- *
152
- * Added extra code to handle \u2028 (Unicode NLF), which is sometimes
153
- * inserted by web browsers (Safari?) and not distinguishable from a "real"
154
- * LF (or CRLF) in some text editors (i.e. TextEdit on OS X). Only doing
155
- * this for XML (and not all Reader objects) because LFs are essential.
156
- * https://github.com/processing/processing/issues/2100
157
- *
158
- * @nowebref
159
- */
160
- public XML(final Reader reader, String options) throws IOException, ParserConfigurationException, SAXException {
161
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
162
-
163
- // Prevent 503 errors from www.w3.org
164
- try {
165
- factory.setAttribute("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
166
- } catch (IllegalArgumentException e) {
167
- // ignore this; Android doesn't like it
168
- }
169
-
170
- // without a validating DTD, this doesn't do anything since it doesn't know what is ignorable
171
- // factory.setIgnoringElementContentWhitespace(true);
172
-
173
- factory.setExpandEntityReferences(false);
174
- // factory.setExpandEntityReferences(true);
175
-
176
- // factory.setCoalescing(true);
177
- // builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
178
- DocumentBuilder builder = factory.newDocumentBuilder();
179
- // builder.setEntityResolver()
180
-
181
- // SAXParserFactory spf = SAXParserFactory.newInstance();
182
- // spf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
183
- // SAXParser p = spf.newSAXParser();
184
-
185
- // builder = DocumentBuilderFactory.newDocumentBuilder();
186
- // builder = new SAXBuilder();
187
- // builder.setValidation(validating);
188
-
189
- Document document = builder.parse(new InputSource(new Reader() {
190
- @Override
191
- public int read(char[] cbuf, int off, int len) throws IOException {
192
- int count = reader.read(cbuf, off, len);
193
- for (int i = 0; i < count; i++) {
194
- if (cbuf[off+i] == '\u2028') {
195
- cbuf[off+i] = '\n';
196
- }
197
- }
198
- return count;
199
- }
200
-
201
- @Override
202
- public void close() throws IOException {
203
- reader.close();
204
- }
205
- }));
206
- node = document.getDocumentElement();
207
- }
208
-
209
-
210
- /**
211
- * @param name creates a node with this name
212
- *
213
- */
214
- public XML(String name) {
215
- try {
216
- // TODO is there a more efficient way of doing this? wow.
217
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
218
- DocumentBuilder builder = factory.newDocumentBuilder();
219
- Document document = builder.newDocument();
220
- node = document.createElement(name);
221
- this.parent = null;
222
-
223
- } catch (ParserConfigurationException pce) {
224
- throw new RuntimeException(pce);
225
- }
226
- }
227
-
228
- /**
229
- * @nowebref
230
- */
231
- protected XML(XML parent, Node node) {
232
- this.node = node;
233
- this.parent = parent;
234
-
235
- for (String attr : parent.listAttributes()) {
236
- if (attr.startsWith("xmlns")) {
237
- // Copy namespace attributes to the kids, otherwise this XML
238
- // can no longer be printed (or manipulated in most ways).
239
- // Only do this when it's an Element, otherwise it's trying to set
240
- // attributes on text notes (interstitial content).
241
- if (node instanceof Element) {
242
- setString(attr, parent.getString(attr));
243
- }
244
- }
245
- }
246
- }
247
-
248
-
249
- /**
250
- * @webref xml:method
251
- * @brief Converts String content to an XML object
252
- * @param data the content to be parsed as XML
253
- * @return an XML object, or null
254
- * @throws SAXException
255
- * @throws ParserConfigurationException
256
- * @throws IOException
257
- * @nowebref
258
- */
259
- static public XML parse(String data) throws IOException, ParserConfigurationException, SAXException {
260
- return XML.parse(data, null);
261
- }
262
-
263
- /**
264
- * @nowebref
265
- */
266
- static public XML parse(String data, String options) throws IOException, ParserConfigurationException, SAXException {
267
- return new XML(new StringReader(data), null);
268
- }
269
-
270
-
271
- // protected boolean save(OutputStream output) {
272
- // return write(PApplet.createWriter(output));
273
- // }
274
-
275
-
276
- public boolean save(File file) {
277
- return save(file, null);
278
- }
279
-
280
-
281
- public boolean save(File file, String options) {
282
- PrintWriter writer = PApplet.createWriter(file);
283
- boolean result = write(writer);
284
- writer.flush();
285
- writer.close();
286
- return result;
287
- }
288
-
289
-
290
- // Sends this object and its kids to a Writer with an indent of 2 spaces,
291
- // including the declaration at the top so that the output will be valid XML.
292
- public boolean write(PrintWriter output) {
293
- output.print(format(2));
294
- output.flush();
295
- return true;
296
- }
297
-
298
-
299
- /**
300
- * Returns the parent element. This method returns null for the root
301
- * element.
302
- *
303
- * @webref xml:method
304
- * @brief Gets a copy of the element's parent
305
- */
306
- public XML getParent() {
307
- return this.parent;
308
- }
309
-
310
- /**
311
- * Internal function; not included in reference.
312
- */
313
- protected Object getNative() {
314
- return node;
315
- }
316
-
317
-
318
- /**
319
- * Returns the full name (i.e. the name including an eventual namespace
320
- * prefix) of the element.
321
- *
322
- * @webref xml:method
323
- * @brief Gets the element's full name
324
- * @return the name, or null if the element only contains #PCDATA.
325
- */
326
- public String getName() {
327
- // return name;
328
- return node.getNodeName();
329
- }
330
-
331
- /**
332
- * @webref xml:method
333
- * @brief Sets the element's name
334
- */
335
- public void setName(String newName) {
336
- Document document = node.getOwnerDocument();
337
- node = document.renameNode(node, null, newName);
338
- // name = node.getNodeName();
339
- }
340
-
341
-
342
- /**
343
- * Returns the name of the element (without namespace prefix).
344
- *
345
- * Internal function; not included in reference.
346
- */
347
- public String getLocalName() {
348
- return node.getLocalName();
349
- }
350
-
351
-
352
- /**
353
- * Honey, can you just check on the kids? Thanks.
354
- *
355
- * Internal function; not included in reference.
356
- */
357
- protected void checkChildren() {
358
- if (children == null) {
359
- NodeList kids = node.getChildNodes();
360
- int childCount = kids.getLength();
361
- children = new XML[childCount];
362
- for (int i = 0; i < childCount; i++) {
363
- children[i] = new XML(this, kids.item(i));
364
- }
365
- }
366
- }
367
-
368
-
369
- /**
370
- * Returns the number of children.
371
- *
372
- * @webref xml:method
373
- * @brief Returns the element's number of children
374
- * @return the count.
375
- */
376
- public int getChildCount() {
377
- checkChildren();
378
- return children.length;
379
- }
380
-
381
-
382
- /**
383
- * Returns a boolean of whether or not there are children.
384
- *
385
- * @webref xml:method
386
- * @brief Checks whether or not an element has any children
387
- */
388
- public boolean hasChildren() {
389
- checkChildren();
390
- return children.length > 0;
391
- }
392
-
393
-
394
- /**
395
- * Put the names of all children into an array. Same as looping through
396
- * each child and calling getName() on each XMLElement.
397
- *
398
- * @webref xml:method
399
- * @brief Returns the names of all children as an array
400
- */
401
- public String[] listChildren() {
402
- // NodeList children = node.getChildNodes();
403
- // int childCount = children.getLength();
404
- // String[] outgoing = new String[childCount];
405
- // for (int i = 0; i < childCount; i++) {
406
- // Node kid = children.item(i);
407
- // if (kid.getNodeType() == Node.ELEMENT_NODE) {
408
- // outgoing[i] = kid.getNodeName();
409
- // } // otherwise just leave him null
410
- // }
411
- checkChildren();
412
- String[] outgoing = new String[children.length];
413
- for (int i = 0; i < children.length; i++) {
414
- outgoing[i] = children[i].getName();
415
- }
416
- return outgoing;
417
- }
418
-
419
-
420
- /**
421
- * Returns an array containing all the child elements.
422
- *
423
- * @webref xml:method
424
- * @brief Returns an array containing all child elements
425
- */
426
- public XML[] getChildren() {
427
- // NodeList children = node.getChildNodes();
428
- // int childCount = children.getLength();
429
- // XMLElement[] kids = new XMLElement[childCount];
430
- // for (int i = 0; i < childCount; i++) {
431
- // Node kid = children.item(i);
432
- // kids[i] = new XMLElement(this, kid);
433
- // }
434
- // return kids;
435
- checkChildren();
436
- return children;
437
- }
438
-
439
-
440
- /**
441
- * Quick accessor for an element at a particular index.
442
- *
443
- * @webref xml:method
444
- * @brief Returns the child element with the specified index value or path
445
- */
446
- public XML getChild(int index) {
447
- checkChildren();
448
- return children[index];
449
- }
450
-
451
-
452
- /**
453
- * Get a child by its name or path.
454
- *
455
- * @param name element name or path/to/element
456
- * @return the first matching element or null if no match
457
- */
458
- public XML getChild(String name) {
459
- if (name.length() > 0 && name.charAt(0) == '/') {
460
- throw new IllegalArgumentException("getChild() should not begin with a slash");
461
- }
462
- if (name.indexOf('/') != -1) {
463
- return getChildRecursive(PApplet.split(name, '/'), 0);
464
- }
465
- int childCount = getChildCount();
466
- for (int i = 0; i < childCount; i++) {
467
- XML kid = getChild(i);
468
- String kidName = kid.getName();
469
- if (kidName != null && kidName.equals(name)) {
470
- return kid;
471
- }
472
- }
473
- return null;
474
- }
475
-
476
-
477
- /**
478
- * Internal helper function for getChild(String).
479
- *
480
- * @param items result of splitting the query on slashes
481
- * @param offset where in the items[] array we're currently looking
482
- * @return matching element or null if no match
483
- * @author processing.org
484
- */
485
- protected XML getChildRecursive(String[] items, int offset) {
486
- // if it's a number, do an index instead
487
- if (Character.isDigit(items[offset].charAt(0))) {
488
- XML kid = getChild(Integer.parseInt(items[offset]));
489
- if (offset == items.length-1) {
490
- return kid;
491
- } else {
492
- return kid.getChildRecursive(items, offset+1);
493
- }
494
- }
495
- int childCount = getChildCount();
496
- for (int i = 0; i < childCount; i++) {
497
- XML kid = getChild(i);
498
- String kidName = kid.getName();
499
- if (kidName != null && kidName.equals(items[offset])) {
500
- if (offset == items.length-1) {
501
- return kid;
502
- } else {
503
- return kid.getChildRecursive(items, offset+1);
504
- }
505
- }
506
- }
507
- return null;
508
- }
509
-
510
-
511
- /**
512
- * Get any children that match this name or path. Similar to getChild(),
513
- * but will grab multiple matches rather than only the first.
514
- *
515
- * @param name element name or path/to/element
516
- * @return array of child elements that match
517
- * @author processing.org
518
- */
519
- public XML[] getChildren(String name) {
520
- if (name.length() > 0 && name.charAt(0) == '/') {
521
- throw new IllegalArgumentException("getChildren() should not begin with a slash");
522
- }
523
- if (name.indexOf('/') != -1) {
524
- return getChildrenRecursive(PApplet.split(name, '/'), 0);
525
- }
526
- // if it's a number, do an index instead
527
- // (returns a single element array, since this will be a single match
528
- if (Character.isDigit(name.charAt(0))) {
529
- return new XML[] { getChild(Integer.parseInt(name)) };
530
- }
531
- int childCount = getChildCount();
532
- XML[] matches = new XML[childCount];
533
- int matchCount = 0;
534
- for (int i = 0; i < childCount; i++) {
535
- XML kid = getChild(i);
536
- String kidName = kid.getName();
537
- if (kidName != null && kidName.equals(name)) {
538
- matches[matchCount++] = kid;
539
- }
540
- }
541
- return (XML[]) PApplet.subset(matches, 0, matchCount);
542
- }
543
-
544
-
545
- protected XML[] getChildrenRecursive(String[] items, int offset) {
546
- if (offset == items.length-1) {
547
- return getChildren(items[offset]);
548
- }
549
- XML[] matches = getChildren(items[offset]);
550
- XML[] outgoing = new XML[0];
551
- for (int i = 0; i < matches.length; i++) {
552
- XML[] kidMatches = matches[i].getChildrenRecursive(items, offset+1);
553
- outgoing = (XML[]) PApplet.concat(outgoing, kidMatches);
554
- }
555
- return outgoing;
556
- }
557
-
558
-
559
- /**
560
- * @webref xml:method
561
- * @brief Appends a new child to the element
562
- */
563
- public XML addChild(String tag) {
564
- Document document = node.getOwnerDocument();
565
- Node newChild = document.createElement(tag);
566
- return appendChild(newChild);
567
- }
568
-
569
-
570
- public XML addChild(XML child) {
571
- Document document = node.getOwnerDocument();
572
- Node newChild = document.importNode((Node) child.getNative(), true);
573
- return appendChild(newChild);
574
- }
575
-
576
-
577
- /** Internal handler to add the node structure. */
578
- protected XML appendChild(Node newNode) {
579
- node.appendChild(newNode);
580
- XML newbie = new XML(this, newNode);
581
- if (children != null) {
582
- children = (XML[]) PApplet.concat(children, new XML[] { newbie });
583
- }
584
- return newbie;
585
- }
586
-
587
-
588
- /**
589
- * @webref xml:method
590
- * @brief Removes the specified child
591
- */
592
- public void removeChild(XML kid) {
593
- node.removeChild(kid.node);
594
- children = null; // TODO not efficient
595
- }
596
-
597
- /**
598
- * Removes whitespace nodes.
599
- * Those whitespace nodes are required to reconstruct the original XML's spacing and indentation.
600
- * If you call this and use saveXML() your original spacing will be gone.
601
- *
602
- * @nowebref
603
- * @brief Removes whitespace nodes
604
- */
605
- public void trim() {
606
- try {
607
- XPathFactory xpathFactory = XPathFactory.newInstance();
608
- XPathExpression xpathExp =
609
- xpathFactory.newXPath().compile("//text()[normalize-space(.) = '']");
610
- NodeList emptyTextNodes = (NodeList)
611
- xpathExp.evaluate(node, XPathConstants.NODESET);
612
-
613
- // Remove each empty text node from document.
614
- for (int i = 0; i < emptyTextNodes.getLength(); i++) {
615
- Node emptyTextNode = emptyTextNodes.item(i);
616
- emptyTextNode.getParentNode().removeChild(emptyTextNode);
617
- }
618
- } catch (Exception e) {
619
- throw new RuntimeException(e);
620
- }
621
- }
622
-
623
-
624
- // /** Remove whitespace nodes. */
625
- // public void trim() {
626
- ////// public static boolean isWhitespace(XML xml) {
627
- ////// if (xml.node.getNodeType() != Node.TEXT_NODE)
628
- ////// return false;
629
- ////// Matcher m = whitespace.matcher(xml.node.getNodeValue());
630
- ////// return m.matches();
631
- ////// }
632
- //// trim(this);
633
- //// }
634
- //
635
- // checkChildren();
636
- // int index = 0;
637
- // for (int i = 0; i < children.length; i++) {
638
- // if (i != index) {
639
- // children[index] = children[i];
640
- // }
641
- // Node childNode = (Node) children[i].getNative();
642
- // if (childNode.getNodeType() != Node.TEXT_NODE ||
643
- // children[i].getContent().trim().length() > 0) {
644
- // children[i].trim();
645
- // index++;
646
- // }
647
- // }
648
- // if (index != children.length) {
649
- // children = (XML[]) PApplet.subset(children, 0, index);
650
- // }
651
- //
652
- // // possibility, but would have to re-parse the object
653
- //// helpdesk.objects.com.au/java/how-do-i-remove-whitespace-from-an-xml-document
654
- //// TransformerFactory factory = TransformerFactory.newInstance();
655
- //// Transformer transformer = factory.newTransformer(new StreamSource("strip-space.xsl"));
656
- //// DOMSource source = new DOMSource(document);
657
- //// StreamResult result = new StreamResult(System.out);
658
- //// transformer.transform(source, result);
659
- //
660
- //// <xsl:stylesheet version="1.0"
661
- //// xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
662
- //// <xsl:output method="xml" omit-xml-declaration="yes"/>
663
- //// <xsl:strip-space elements="*"/>
664
- //// <xsl:template match="@*|node()">
665
- //// <xsl:copy>
666
- //// <xsl:apply-templates select="@*|node()"/>
667
- //// </xsl:copy>
668
- //// </xsl:template>
669
- //// </xsl:stylesheet>
670
- // }
671
-
672
-
673
- /**
674
- * Returns the number of attributes.
675
- *
676
- * @webref xml:method
677
- * @brief Counts the specified element's number of attributes
678
- */
679
- public int getAttributeCount() {
680
- return node.getAttributes().getLength();
681
- }
682
-
683
-
684
- /**
685
- * Get a list of the names for all of the attributes for this node.
686
- *
687
- * @webref xml:method
688
- * @brief Returns a list of names of all attributes as an array
689
- */
690
- public String[] listAttributes() {
691
- NamedNodeMap nnm = node.getAttributes();
692
- String[] outgoing = new String[nnm.getLength()];
693
- for (int i = 0; i < outgoing.length; i++) {
694
- outgoing[i] = nnm.item(i).getNodeName();
695
- }
696
- return outgoing;
697
- }
698
-
699
- /**
700
- * Returns whether an attribute exists.
701
- *
702
- * @webref xml:method
703
- * @brief Checks whether or not an element has the specified attribute
704
- */
705
- public boolean hasAttribute(String name) {
706
- return (node.getAttributes().getNamedItem(name) != null);
707
- }
708
-
709
-
710
- /**
711
- * Returns the value of an attribute.
712
- *
713
- * @param name the non-null name of the attribute.
714
- * @return the value, or null if the attribute does not exist.
715
- */
716
- // public String getAttribute(String name) {
717
- // return this.getAttribute(name, null);
718
- // }
719
-
720
-
721
- /**
722
- * Returns the value of an attribute.
723
- *
724
- * @param name the non-null full name of the attribute.
725
- * @param defaultValue the default value of the attribute.
726
- * @return the value, or defaultValue if the attribute does not exist.
727
- */
728
- // public String getAttribute(String name, String defaultValue) {
729
- // Node attr = node.getAttributes().getNamedItem(name);
730
- // return (attr == null) ? defaultValue : attr.getNodeValue();
731
- // }
732
-
733
-
734
- /**
735
- * @webref xml:method
736
- * @brief Gets the content of an attribute as a String
737
- */
738
- public String getString(String name) {
739
- return getString(name, null);
740
- }
741
-
742
-
743
- public String getString(String name, String defaultValue) {
744
- NamedNodeMap attrs = node.getAttributes();
745
- if (attrs != null) {
746
- Node attr = attrs.getNamedItem(name);
747
- if (attr != null) {
748
- return attr.getNodeValue();
749
- }
750
- }
751
- return defaultValue;
752
- }
753
-
754
-
755
- /**
756
- * @webref xml:method
757
- * @brief Sets the content of an attribute as a String
758
- */
759
- public void setString(String name, String value) {
760
- ((Element) node).setAttribute(name, value);
761
- }
762
-
763
-
764
- /**
765
- * @webref xml:method
766
- * @brief Gets the content of an attribute as an int
767
- */
768
- public int getInt(String name) {
769
- return getInt(name, 0);
770
- }
771
-
772
-
773
- /**
774
- * @webref xml:method
775
- * @brief Sets the content of an attribute as an int
776
- */
777
- public void setInt(String name, int value) {
778
- setString(name, String.valueOf(value));
779
- }
780
-
781
-
782
- /**
783
- * Returns the value of an attribute.
784
- *
785
- * @param name the non-null full name of the attribute
786
- * @param defaultValue the default value of the attribute
787
- * @return the value, or defaultValue if the attribute does not exist
788
- */
789
- public int getInt(String name, int defaultValue) {
790
- String value = getString(name);
791
- return (value == null) ? defaultValue : Integer.parseInt(value);
792
- }
793
-
794
-
795
- /**
796
- * @webref xml:method
797
- * @brief Sets the content of an element as an int
798
- */
799
- public void setLong(String name, long value) {
800
- setString(name, String.valueOf(value));
801
- }
802
-
803
-
804
- /**
805
- * Returns the value of an attribute.
806
- *
807
- * @param name the non-null full name of the attribute.
808
- * @param defaultValue the default value of the attribute.
809
- * @return the value, or defaultValue if the attribute does not exist.
810
- */
811
- public long getLong(String name, long defaultValue) {
812
- String value = getString(name);
813
- return (value == null) ? defaultValue : Long.parseLong(value);
814
- }
815
-
816
-
817
- /**
818
- * Returns the value of an attribute, or zero if not present.
819
- *
820
- * @webref xml:method
821
- * @brief Gets the content of an attribute as a float
822
- */
823
- public float getFloat(String name) {
824
- return getFloat(name, 0);
825
- }
826
-
827
-
828
- /**
829
- * Returns the value of an attribute.
830
- *
831
- * @param name the non-null full name of the attribute.
832
- * @param defaultValue the default value of the attribute.
833
- * @return the value, or defaultValue if the attribute does not exist.
834
- */
835
- public float getFloat(String name, float defaultValue) {
836
- String value = getString(name);
837
- return (value == null) ? defaultValue : Float.parseFloat(value);
838
- }
839
-
840
-
841
- /**
842
- * @webref xml:method
843
- * @brief Sets the content of an attribute as a float
844
- */
845
- public void setFloat(String name, float value) {
846
- setString(name, String.valueOf(value));
847
- }
848
-
849
-
850
- public double getDouble(String name) {
851
- return getDouble(name, 0);
852
- }
853
-
854
-
855
- /**
856
- * Returns the value of an attribute.
857
- *
858
- * @param name the non-null full name of the attribute
859
- * @param defaultValue the default value of the attribute
860
- * @return the value, or defaultValue if the attribute does not exist
861
- */
862
- public double getDouble(String name, double defaultValue) {
863
- String value = getString(name);
864
- return (value == null) ? defaultValue : Double.parseDouble(value);
865
- }
866
-
867
-
868
- public void setDouble(String name, double value) {
869
- setString(name, String.valueOf(value));
870
- }
871
-
872
-
873
- /**
874
- * Return the #PCDATA content of the element. If the element has a
875
- * combination of #PCDATA content and child elements, the #PCDATA
876
- * sections can be retrieved as unnamed child objects. In this case,
877
- * this method returns null.
878
- *
879
- * @webref xml:method
880
- * @brief Gets the content of an element
881
- * @return the content.
882
- * @see XML#getIntContent()
883
- * @see XML#getFloatContent()
884
- */
885
- public String getContent() {
886
- return node.getTextContent();
887
- }
888
-
889
-
890
- public String getContent(String defaultValue) {
891
- String s = node.getTextContent();
892
- return (s != null) ? s : defaultValue;
893
- }
894
-
895
-
896
- /**
897
- * @webref xml:method
898
- * @brief Gets the content of an element as an int
899
- * @return the content.
900
- * @see XML#getContent()
901
- * @see XML#getFloatContent()
902
- */
903
- public int getIntContent() {
904
- return getIntContent(0);
905
- }
906
-
907
-
908
- /**
909
- * @param defaultValue the default value of the attribute
910
- */
911
- public int getIntContent(int defaultValue) {
912
- return PApplet.parseInt(node.getTextContent(), defaultValue);
913
- }
914
-
915
-
916
- /**
917
- * @webref xml:method
918
- * @brief Gets the content of an element as a float
919
- * @return the content.
920
- * @see XML#getContent()
921
- * @see XML#getIntContent()
922
- */
923
- public float getFloatContent() {
924
- return getFloatContent(0);
925
- }
926
-
927
-
928
- /**
929
- * @param defaultValue the default value of the attribute
930
- */
931
- public float getFloatContent(float defaultValue) {
932
- return PApplet.parseFloat(node.getTextContent(), defaultValue);
933
- }
934
-
935
-
936
- public long getLongContent() {
937
- return getLongContent(0);
938
- }
939
-
940
-
941
- public long getLongContent(long defaultValue) {
942
- String c = node.getTextContent();
943
- if (c != null) {
944
- try {
945
- return Long.parseLong(c);
946
- } catch (NumberFormatException nfe) { }
947
- }
948
- return defaultValue;
949
- }
950
-
951
-
952
- public double getDoubleContent() {
953
- return getDoubleContent(0);
954
- }
955
-
956
-
957
- public double getDoubleContent(double defaultValue) {
958
- String c = node.getTextContent();
959
- if (c != null) {
960
- try {
961
- return Double.parseDouble(c);
962
- } catch (NumberFormatException nfe) { }
963
- }
964
- return defaultValue;
965
- }
966
-
967
-
968
- /**
969
- * @webref xml:method
970
- * @brief Sets the content of an element
971
- */
972
- public void setContent(String text) {
973
- node.setTextContent(text);
974
- }
975
-
976
-
977
- public void setIntContent(int value) {
978
- setContent(String.valueOf(value));
979
- }
980
-
981
-
982
- public void setFloatContent(float value) {
983
- setContent(String.valueOf(value));
984
- }
985
-
986
-
987
- public void setLongContent(long value) {
988
- setContent(String.valueOf(value));
989
- }
990
-
991
-
992
- public void setDoubleContent(double value) {
993
- setContent(String.valueOf(value));
994
- }
995
-
996
-
997
- /**
998
- * Format this XML data as a String.
999
- *
1000
- * @webref xml:method
1001
- * @brief Formats XML data as a String
1002
- * @param indent -1 for a single line (and no declaration), >= 0 for indents and newlines
1003
- * @return the content
1004
- * @see XML#toString()
1005
- */
1006
- public String format(int indent) {
1007
- try {
1008
- // entities = doctype.getEntities()
1009
- boolean useIndentAmount = false;
1010
- TransformerFactory factory = TransformerFactory.newInstance();
1011
- if (indent != -1) {
1012
- try {
1013
- factory.setAttribute("indent-number", indent);
1014
- } catch (IllegalArgumentException e) {
1015
- useIndentAmount = true;
1016
- }
1017
- }
1018
- Transformer transformer = factory.newTransformer();
1019
-
1020
- // Add the XML declaration at the top if this node is the root and we're
1021
- // not writing to a single line (indent = -1 means single line).
1022
- if (indent == -1 || parent == null) {
1023
- transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
1024
- } else {
1025
- transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
1026
- }
1027
-
1028
- // transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "sample.dtd");
1029
-
1030
- transformer.setOutputProperty(OutputKeys.METHOD, "xml");
1031
-
1032
- // transformer.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, "yes"); // huh?
1033
-
1034
- // transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,
1035
- // "-//W3C//DTD XHTML 1.0 Transitional//EN");
1036
- // transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,
1037
- // "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd");
1038
-
1039
- // For Android, because (at least 2.3.3) doesn't like indent-number
1040
- if (useIndentAmount) {
1041
- transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", String.valueOf(indent));
1042
- }
1043
-
1044
- // transformer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1");
1045
- // transformer.setOutputProperty(OutputKeys.ENCODING,"UTF8");
1046
- transformer.setOutputProperty(OutputKeys.ENCODING,"UTF-8");
1047
- // transformer.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS
1048
-
1049
- // Always indent, otherwise the XML declaration will just be jammed
1050
- // onto the first line with the XML code as well.
1051
- transformer.setOutputProperty(OutputKeys.INDENT, "yes");
1052
-
1053
- // Properties p = transformer.getOutputProperties();
1054
- // for (Object key : p.keySet()) {
1055
- // System.out.println(key + " -> " + p.get(key));
1056
- // }
1057
-
1058
- // If you smell something, that's because this code stinks. No matter
1059
- // the settings of the Transformer object, if the XML document already
1060
- // has whitespace elements, it won't bother re-indenting/re-formatting.
1061
- // So instead, transform the data once into a single line string.
1062
- // If indent is -1, then we're done. Otherwise re-run and the settings
1063
- // of the factory will kick in. If you know a better way to do this,
1064
- // please contribute. I've wasted too much of my Sunday on it. But at
1065
- // least the Giants are getting blown out by the Falcons.
1066
-
1067
- final String decl = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
1068
- final String sep = System.getProperty("line.separator");
1069
-
1070
- StringWriter tempWriter = new StringWriter();
1071
- StreamResult tempResult = new StreamResult(tempWriter);
1072
- transformer.transform(new DOMSource(node), tempResult);
1073
- String[] tempLines = PApplet.split(tempWriter.toString(), sep);
1074
- // PApplet.println(tempLines);
1075
- if (tempLines[0].startsWith("<?xml")) {
1076
- // Remove XML declaration from the top before slamming into one line
1077
- int declEnd = tempLines[0].indexOf("?>") + 2;
1078
- //if (tempLines[0].length() == decl.length()) {
1079
- if (tempLines[0].length() == declEnd) {
1080
- // If it's all the XML declaration, remove it
1081
- // PApplet.println("removing first line");
1082
- tempLines = PApplet.subset(tempLines, 1);
1083
- } else {
1084
- // PApplet.println("removing part of first line");
1085
- // If the first node has been moved to this line, be more careful
1086
- //tempLines[0] = tempLines[0].substring(decl.length());
1087
- tempLines[0] = tempLines[0].substring(declEnd);
1088
- }
1089
- }
1090
- String singleLine = PApplet.join(PApplet.trim(tempLines), "");
1091
- if (indent == -1) {
1092
- return singleLine;
1093
- }
1094
-
1095
- // Might just be whitespace, which won't be valid XML for parsing below.
1096
- // https://github.com/processing/processing/issues/1796
1097
- // Since indent is not -1, that means they want valid XML,
1098
- // so we'll give them the single line plus the decl... Lame? sure.
1099
- if (singleLine.trim().length() == 0) {
1100
- // You want whitespace? I've got your whitespace right here.
1101
- return decl + sep + singleLine;
1102
- }
1103
-
1104
- // Since the indent is not -1, bring back the XML declaration
1105
- //transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
1106
-
1107
- StringWriter stringWriter = new StringWriter();
1108
- StreamResult xmlOutput = new StreamResult(stringWriter);
1109
- // DOMSource source = new DOMSource(node);
1110
- Source source = new StreamSource(new StringReader(singleLine));
1111
- transformer.transform(source, xmlOutput);
1112
- String outgoing = stringWriter.toString();
1113
-
1114
- // Add the XML declaration to the top if it's not there already
1115
- if (outgoing.startsWith(decl)) {
1116
- int declen = decl.length();
1117
- int seplen = sep.length();
1118
- if (outgoing.length() > declen + seplen &&
1119
- !outgoing.substring(declen, declen + seplen).equals(sep)) {
1120
- // make sure there's a line break between the XML decl and the code
1121
- return outgoing.substring(0, decl.length()) +
1122
- sep + outgoing.substring(decl.length());
1123
- }
1124
- return outgoing;
1125
- } else {
1126
- return decl + sep + outgoing;
1127
- }
1128
-
1129
- } catch (Exception e) {
1130
- e.printStackTrace();
1131
- }
1132
- return null;
1133
- }
1134
-
1135
-
1136
- public void print() {
1137
- PApplet.println(format(2));
1138
- }
1139
-
1140
-
1141
- /**
1142
- * Return the XML document formatted with two spaces for indents.
1143
- * Chosen to do this since it's the most common case (e.g. with println()).
1144
- * Same as format(2). Use the format() function for more options.
1145
- *
1146
- * @webref xml:method
1147
- * @brief Gets XML data as a String using default formatting
1148
- * @return the content
1149
- * @see XML#format(int)
1150
- */
1151
- @Override
1152
- public String toString() {
1153
- //return format(2);
1154
- return format(-1);
1155
- }
1156
- }