From 0f2a452462bed8f9370630d39aff408163198455 Mon Sep 17 00:00:00 2001 From: benfry Date: Wed, 5 Sep 2007 15:03:23 +0000 Subject: [PATCH] added getChild(name/path) and getChildren(name/path) to xml library --- core/todo.txt | 19 ++-- todo.txt | 17 +++ xml/src/processing/xml/XMLElement.java | 142 +++++++++++++++++++------ 3 files changed, 137 insertions(+), 41 deletions(-) diff --git a/core/todo.txt b/core/todo.txt index d823fb3b4..438666a4c 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -9,6 +9,17 @@ X some auto-gunzip implemented _ need to finish auto-gunzip X fix bug where sort() on 0 length array would return null X instead, returns an array +X unregisterXxxx() calls to remove methods from libs +X http://dev.processing.org/bugs/show_bug.cgi?id=312 +X implemented by ewjordan + +_ opengl mipmaps are leaking (regression in spite of #150 fix) +_ http://dev.processing.org/bugs/show_bug.cgi?id=610 + +_ 100x100 issues are exhibited on bh140c PCs, test and fix! +_ http://dev.processing.org/bugs/show_bug.cgi?id=197 +_ width/height on problem machine prints out as: +_ 100,200 and 128,200 _ loadBytes() and saveStream() functions badly need optimization! _ don't bother using a buffering stream, just handle internally. gah! @@ -18,9 +29,6 @@ _ the number of cases where this works is small (half of url streams) _ and who knows if the value returned will be correct _ (i.e. will it be the uncompressed or compressed size of the data?) -_ opengl mipmaps are leaking -_ http://dev.processing.org/bugs/show_bug.cgi?id=610 - _ loadBytes() doesn't do auto gunzip? but loadStrings and createReader do? X this might be a good solution for dealing with the differences _ with loadBytes(), they can use gzipInput (or loadBytesGZ?) @@ -32,9 +40,6 @@ _ do the same for createWriter() et al _ update the reference to cover parseXxxx() stuff _ also add notes about parseInt/Float(blah, otherwise) -_ unregisterXxxx() calls to remove methods from libs -_ http://dev.processing.org/bugs/show_bug.cgi?id=312 - _ offscreen buffers fail with texture mapping _ pixels not being set opaque (only with textures?) @@ -203,8 +208,6 @@ _ http://dev.processing.org/bugs/show_bug.cgi?id=511 _ applet sizing issues with external vm _ could this possibly be related to the linux bug? _ http://dev.processing.org/bugs/show_bug.cgi?id=430 -_ 100x100 issues are exhibited on bh140c PCs, test and fix! -_ http://dev.processing.org/bugs/show_bug.cgi?id=197 _ alloc() stuff not fixed because of thread halting _ problem where alloc happens inside setup(), so, uh.. _ http://dev.processing.org/bugs/show_bug.cgi?id=369 diff --git a/todo.txt b/todo.txt index 1e3d79038..9d11dd75b 100644 --- a/todo.txt +++ b/todo.txt @@ -7,6 +7,8 @@ X move open menu to its own X BGraphics, BImage, void loop() -> give an error saying it's old code X better yet, only do this when "not found" errors come up _ need to fix changes.html because it lists out of date alpha->beta changes +X added getChild(name/path), getChildren(name/path) to xml library +_ add notes about these to the reference multiple sketch support X basic structural moves to handle multiple sketches @@ -36,10 +38,19 @@ _ tough to do with the multiple directories/submenus _ add methods for "add" and "remove" for sketches _ also a rename method, which could just be a remove and add _ libraries and examples won't be rebuilt during the session +_ editor console is broken, because re-routes System.out _ test on windows _ test on linux _ make sure quit being handled properly on windows/linux _ make editor buttons light up and clear properly +_ inside sketch.java, don't hardwire the file extension types +_ arduino uses .c, .cpp, .h instead of .java + +You could greatly simplify the creation of disk-images using this cmd-line: + hdiutil create -size 5m -fs HFS+ -volname Fooble foo +To mount the disk-image, without having it appear in the Finder: + hdiutil attach -nobrowse foo.dmg +The main advantage is that these don't require root privileges _ make sure loadStrings(), loadImage(), etc all have security warning in docs _ make clear that open() with one param should only have a single param @@ -121,6 +132,7 @@ _ should we use if() or if in the reference charset changes _ need to set a default charset for use in files (utf8) _ add option to change charset or specify as part of loading +_ need to specify the default encoding _ xml element needs to be readable from other charsets _ same with the other methods like loadStrings() _ could also be a way to handle gzip too? @@ -151,6 +163,7 @@ void sortSwap(int a, int b) { 0127 _ dynamic tools menu (requires moving files around) _ this means can integrate the autoformat stuff +_ processing.mess/tools has chandler's template stuff _ finish up debian package support (see the processing.mess folder) @@ -645,6 +658,8 @@ _ Blah.class will confuse the preproc _ http://dev.processing.org/bugs/show_bug.cgi?id=481 _ non-matching curly brackets sometimes don't cause an error _ http://dev.processing.org/bugs/show_bug.cgi?id=507 +_ syntax highlighting error with // and /* +_ http://dev.processing.org/bugs/show_bug.cgi?id=609 hacked for fix, needs real fix _ NullPointerException on unterminated comment at end of code @@ -1077,6 +1092,8 @@ _ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=VideoCamera;action= LIBRARIES / Video +_ add more information about multiple camera inputs +_ add info about "access" errors being quicktime errors _ documented in faq, add something to the lib "camera not installed" _ quicktime.std.stdQTException(QTjava:6.1.3gl),-9405=couldntgetrequiredcomponent,qtversion:7108000 at quicktime.std.stdQTExceptionchekcerror _ need to add resize method to capture object diff --git a/xml/src/processing/xml/XMLElement.java b/xml/src/processing/xml/XMLElement.java index 13eb0f4a7..a14139a61 100644 --- a/xml/src/processing/xml/XMLElement.java +++ b/xml/src/processing/xml/XMLElement.java @@ -55,6 +55,11 @@ import processing.core.PApplet; * altered, however it should be clear that this code is almost entirely his * work, with no connection to the Processing project. *

+ * Alterations/additions for the Processing library:

* The intent of this library (with regard to Processing) is to provide an * extremely simple (and compact) means of reading and writing XML data from a * sketch. As such, this is not a full-featured library for handling XML data. @@ -63,7 +68,7 @@ import processing.core.PApplet; * * import processing.xml.*; * - * XMLElement xml = new XMLElement("filename.xml", this); + * XMLElement xml = new XMLElement(this, "filename.xml"); * int childCount = xml.getChildCount(); * for (int i = 0; i < childCount; i++) { * XMLElement kid = xml.getChild(i); @@ -72,13 +77,13 @@ import processing.core.PApplet; * } * * @author Marc De Scheemaecker - * <cyberelf@mac.com> + * @author Ben Fry */ public class XMLElement { static final boolean DEBUG = false; - - + + /** * The attributes given to the element. * @@ -154,13 +159,13 @@ public class XMLElement */ private boolean ignoreUnknownEntities = true; - + /** - * For attributes such as NOWRAP that aren't set equal to anything, + * For attributes such as NOWRAP that aren't set equal to anything, * parse without giving an error, and set their contents to an empty String. */ private boolean ignoreMissingAttributes = true; - + /** * The line number where the element starts. @@ -464,9 +469,8 @@ public class XMLElement /** * Begin parsing XML data passed in from a PApplet. This code * wraps exception handling, for more advanced exception handling, - * use the constructor that takes a Reader or InputStream, - * or use the parseFromReader() method. - * @author fry + * use the constructor that takes a Reader or InputStream. + * @author processing.org * @param filename * @param parent */ @@ -474,11 +478,7 @@ public class XMLElement this(); try { Reader r = parent.createReader(filename); - if (r == null) { - System.err.println("The file " + filename + - " could not be found."); - return; - } + //if (r == null) return; parseFromReader(r); } catch (IOException e) { e.printStackTrace(); @@ -486,24 +486,25 @@ public class XMLElement } - /** - * Create and parse immediately. - * @author fry - */ public XMLElement(Reader r) throws IOException { this(); parseFromReader(r); } - /** - * Create and parse immediately. - * @author fry - */ + public XMLElement(String s) { + try { + parseString(s); + } catch (XMLParseException e) { + e.printStackTrace(); + } + } + + public XMLElement(InputStream input) throws IOException { - this(); - InputStreamReader r = new InputStreamReader(input); - parseFromReader(r); + this(new InputStreamReader(input, "UTF-8")); +// InputStreamReader r = new InputStreamReader(input); +// parseFromReader(r); } @@ -794,7 +795,7 @@ public class XMLElement /** - * Quick accessor for a particular element + * Quick accessor for an element at a particular index. * @author processing.org */ public XMLElement getChild(int which) { @@ -802,6 +803,81 @@ public class XMLElement } + /** + * Get a child by its name or path. + * @param name element name or path/to/element + * @return + * @author processing.org + */ + public XMLElement getChild(String name) { + if (name.indexOf('/') != -1) { + return getChild(PApplet.split(name, '/'), 0); + } + int childCount = getChildCount(); + for (int i = 0; i < childCount; i++) { + XMLElement kid = getChild(i); + if (kid.getName().equals(name)) { + return kid; + } + } + return null; + } + + + protected XMLElement getChild(String[] items, int offset) { + int childCount = getChildCount(); + for (int i = 0; i < childCount; i++) { + XMLElement kid = getChild(i); + if (kid.getName().equals(items[offset])) { + if (offset == items.length-1) { + return kid; + } else { + return kid.getChild(items, offset+1); + } + } + } + return null; + } + + + /** + * Get any children that match this name or path. Similar to getChild(), + * but will grab multiple matches rather than only the first. + * @param name element name or path/to/element + * @return + * @author processing.org + */ + public XMLElement[] getChildren(String name) { + if (name.indexOf('/') != -1) { + return getChildren(PApplet.split(name, '/'), 0); + } + int childCount = getChildCount(); + XMLElement[] matches = new XMLElement[childCount]; + int matchCount = 0; + for (int i = 0; i < childCount; i++) { + XMLElement kid = getChild(i); + if (kid.getName().equals(name)) { + matches[matchCount++] = kid; + } + } + return (XMLElement[]) PApplet.subset(matches, 0, matchCount); + } + + + protected XMLElement[] getChildren(String[] items, int offset) { + if (offset == items.length-1) { + return getChildren(items[offset]); + } + XMLElement[] matches = getChildren(items[offset]); + XMLElement[] outgoing = new XMLElement[0]; + for (int i = 0; i < matches.length; i++) { + XMLElement[] kidMatches = matches[i].getChildren(items, offset+1); + outgoing = (XMLElement[]) PApplet.concat(outgoing, kidMatches); + } + return outgoing; + } + + /** * Returns the PCDATA content of the object. If there is no such content, * null is returned. @@ -2203,16 +2279,16 @@ public class XMLElement // don't allow delimiters in this case for (;;) { char ch = this.readChar(); - if ((ch == ' ') || + if ((ch == ' ') || (ch == '\t') || (ch == '\n') || (ch == '\r') || - (ch == '/') || (ch == '>')) { + (ch == '/') || (ch == '>')) { unreadChar(ch); return; } else { string.append(ch); } } - + } else { for (;;) { char ch = this.readChar(); @@ -2499,7 +2575,7 @@ public class XMLElement this.scanString(buf); elt.setAttribute(key, buf); if (DEBUG) System.out.println(" value is " + buf); - } + } ch = this.scanWhitespace(); if (DEBUG) System.out.println("scan of white produced " + ch); } @@ -2642,9 +2718,9 @@ public class XMLElement } } } - - /** + + /** * Version of resolveEntity that gives up when it hits its ending delimiter. * Handles parsing stuff where the URL contains an ampersand. */