[diablu commit] r312 - in trunk/MailMan/Examples/Processing/FlickrBrowser: . application.linux application.linux/...

0 views
Skip to first unread message

codesite...@google.com

unread,
Nov 6, 2008, 1:26:20 PM11/6/08
to diablu...@googlegroups.com
Author: jorgediablu
Date: Thu Nov 6 10:24:22 2008
New Revision: 312

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/
trunk/MailMan/Examples/Processing/FlickrBrowser/Encoder.pde
trunk/MailMan/Examples/Processing/FlickrBrowser/FlickrBrowser.pde
trunk/MailMan/Examples/Processing/FlickrBrowser/application.linux/

trunk/MailMan/Examples/Processing/FlickrBrowser/application.linux/FlickrBrowser
trunk/MailMan/Examples/Processing/FlickrBrowser/application.linux/lib/

trunk/MailMan/Examples/Processing/FlickrBrowser/application.linux/lib/FlickrBrowser.jar
(contents, props changed)

trunk/MailMan/Examples/Processing/FlickrBrowser/application.linux/lib/core.jar
(contents, props changed)

trunk/MailMan/Examples/Processing/FlickrBrowser/application.linux/lib/oscP5.jar
(contents, props changed)
trunk/MailMan/Examples/Processing/FlickrBrowser/application.linux/source/

trunk/MailMan/Examples/Processing/FlickrBrowser/application.linux/source/Encoder.pde

trunk/MailMan/Examples/Processing/FlickrBrowser/application.linux/source/FlickrBrowser.java

trunk/MailMan/Examples/Processing/FlickrBrowser/application.linux/source/FlickrBrowser.pde
trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/

trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/FlickrBrowser.app/

trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/FlickrBrowser.app/Contents/

trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/FlickrBrowser.app/Contents/Info.plist

trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/FlickrBrowser.app/Contents/MacOS/

trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/FlickrBrowser.app/Contents/MacOS/JavaApplicationStub
(contents, props changed)

trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/FlickrBrowser.app/Contents/PkgInfo

trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/FlickrBrowser.app/Contents/Resources/

trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/FlickrBrowser.app/Contents/Resources/Java/

trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/FlickrBrowser.app/Contents/Resources/Java/FlickrBrowser.jar
(contents, props changed)

trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/FlickrBrowser.app/Contents/Resources/Java/core.jar
(contents, props changed)

trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/FlickrBrowser.app/Contents/Resources/Java/oscP5.jar
(contents, props changed)

trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/FlickrBrowser.app/Contents/Resources/sketch.icns
(contents, props changed)

trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/readme.txt

trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/source/

trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/source/Encoder.pde

trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/source/FlickrBrowser.java

trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/source/FlickrBrowser.pde
trunk/MailMan/Examples/Processing/FlickrBrowser/application.windows/

trunk/MailMan/Examples/Processing/FlickrBrowser/application.windows/FlickrBrowser.exe
(contents, props changed)
trunk/MailMan/Examples/Processing/FlickrBrowser/application.windows/lib/

trunk/MailMan/Examples/Processing/FlickrBrowser/application.windows/lib/FlickrBrowser.jar
(contents, props changed)

trunk/MailMan/Examples/Processing/FlickrBrowser/application.windows/lib/args.txt

trunk/MailMan/Examples/Processing/FlickrBrowser/application.windows/lib/core.jar
(contents, props changed)

trunk/MailMan/Examples/Processing/FlickrBrowser/application.windows/lib/oscP5.jar
(contents, props changed)

trunk/MailMan/Examples/Processing/FlickrBrowser/application.windows/source/

trunk/MailMan/Examples/Processing/FlickrBrowser/application.windows/source/Encoder.pde

trunk/MailMan/Examples/Processing/FlickrBrowser/application.windows/source/FlickrBrowser.java

trunk/MailMan/Examples/Processing/FlickrBrowser/application.windows/source/FlickrBrowser.pde
trunk/MailMan/Examples/Processing/FlickrBrowser/neterror.html
trunk/MailMan/Examples/Processing/FlickrBrowser/notSupported.html
trunk/MailMan/Examples/Processing/FlickrBrowser/start.bat

Log:
[Mailman] Added FlickrBrowser example. FlickrBrowser accepts tags and asks
the default internet browser to search on flickr (in slideshow mode).

Added: trunk/MailMan/Examples/Processing/FlickrBrowser/Encoder.pde
==============================================================================
--- (empty file)
+++ trunk/MailMan/Examples/Processing/FlickrBrowser/Encoder.pde Thu Nov 6
10:24:22 2008
@@ -0,0 +1,138 @@
+
+import java.io.*;
+
+
+ /**
+ * Encodes an already formed URL using the
<CODE>application/x-www-form-urlencoded</CODE>
+ * MIME format.
+ *
+ * @param s The String (URL) to be converted.
+ *
+ * @return The converted String (URL).
+ */
+ String URLEncode(String s) {
+ int questionMark = s.indexOf('?');
+
+ if (questionMark == -1) { // no parameters
+ return s;
+ } else {
+ return s.substring(0, questionMark+1) +
encodeURL(s.substring(questionMark+1));
+ }
+ }
+
+ /**
+ * Base on code in
http://forums.java.sun.com/thread.jspa?threadID=409913&messageID=1806947
+ * Converts a String to the
<CODE>application/x-www-form-urlencoded</CODE> MIME
+ * format.
+ *
+ * @param s The String to be converted.
+ *
+ * @return The converted String.
+ */
+ String encode(String s) {
+ StringBuffer out = new StringBuffer();
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+
+ DataOutputStream dOut = new DataOutputStream(bOut);
+
+ try {
+ dOut.writeUTF(s);
+ } catch (IOException ioe) {
+ return null;
+ }
+
+ ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray());
+
+ /* UTF strings have 2 bytes to indicate the size, so skip these */
+ bIn.read();
+ bIn.read();
+
+ int c = bIn.read();
+ while (c >= 0) {
+ if ((c >= 'a' && c <= 'z')
+ || (c >= 'A' && c <= 'Z')
+ || (c >= '0' && c <= '9')
+ || c == '.' || c == '-' || c == '*' || c == '_') {
+ out.append((char) c);
+ } else if (c == ' ') {
+ out.append('+');
+ } else {
+ if (c < 128) {
+ appendHex(c,out);
+ } else if (c < 224) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ } else if (c < 240) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ appendHex(bIn.read(),out);
+ }
+
+ }
+ c = bIn.read();
+ }
+ return out.toString();
+ }
+
+ /**
+ * Base on code in
http://forums.java.sun.com/thread.jspa?threadID=409913&messageID=1806947
+ *
+ * Similar to encode but we don't encode the '=' and '&' characters. This
+ * way we can use this to encode an already formed URL (or better, the
parameter
+ * part of an already formed URL).
+ */
+ String encodeURL(String s) {
+ StringBuffer out = new StringBuffer();
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+
+ DataOutputStream dOut = new DataOutputStream(bOut);
+
+ try {
+ dOut.writeUTF(s);
+ } catch (IOException ioe) {
+ return null;
+ }
+
+ ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray());
+
+ /* UTF strings have 2 bytes to indicate the size, so skip these */
+ bIn.read();
+ bIn.read();
+
+ int c = bIn.read();
+ while (c >= 0) {
+ if ((c >= 'a' && c <= 'z')
+ || (c >= 'A' && c <= 'Z')
+ || (c >= '0' && c <= '9')
+ || c == '.' || c == '-'
+ || c == '*' || c == '_'
+ || c == '=' || c == '&') {
+ out.append((char) c);
+ } else if (c == ' ') {
+ out.append('+');
+ } else {
+ if (c < 128) {
+ appendHex(c,out);
+ } else if (c < 224) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ } else if (c < 240) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ appendHex(bIn.read(),out);
+ }
+
+ }
+ c = bIn.read();
+ }
+ return out.toString();
+ }
+
+ void appendHex(int arg0, StringBuffer buff){
+ buff.append('%');
+ if (arg0<16) {
+ buff.append('0');
+ }
+ buff.append(Integer.toHexString(arg0));
+ }
+

Added: trunk/MailMan/Examples/Processing/FlickrBrowser/FlickrBrowser.pde
==============================================================================
--- (empty file)
+++ trunk/MailMan/Examples/Processing/FlickrBrowser/FlickrBrowser.pde Thu
Nov 6 10:24:22 2008
@@ -0,0 +1,237 @@
+
+import netP5.*;
+import oscP5.*;
+import java.net.*;
+
+
+OscP5 osc;
+NetAddress myRemoteLocation;
+
+OscProperties oscp;
+OscP5 oscClient;
+OscP5 oscServer;
+
+
+int lastInteraction = millis();
+boolean retry = false;
+
+int MAX_WORDS = 100;
+Vector words;
+
+void setup ()
+{
+
+ frameRate(1);
+
+ oscClient = new OscP5(this, "127.0.0.1", 12000, OscP5.UDP);
+ oscServer = new OscP5(this, 12001, OscP5.UDP);
+
+ myRemoteLocation = new NetAddress("127.0.0.1", 12000);
+
+ words = new Vector();
+}
+
+
+void draw()
+{
+ if (retry) {
+ if (millis() > lastInteraction+10000) {
+ String c = (String)words.get(words.size()-1);
+ //println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " ---- Using friendly name "+c);
+ lastInteraction=millis();
+ if (ping()) {
+ link(URLEncode("http://www.flickr.com/search/show/?q=\""+c+"\""));
+ retry = false;
+ } else {
+ showNetError();
+ }
+
+ }
+ }
+ if (millis() > lastInteraction+1000*60*30) {
+ if (words.size() > 0) {
+ String c = (String)words.get((int)random(words.size()));
+ println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " ---- Reusing old tag "+c);
+
+ if (ping()) {
+ lastInteraction=millis();
+ link(URLEncode("http://www.flickr.com/search/show/?q=\""+c+"\""));
+ } else {
+ showNetError();
+ lastInteraction=lastInteraction+10*1000; // retry 10 sec later
+ }
+ }
+ }
+}
+
+
+void oscEvent(OscMessage theOscMessage)
+{
+
+ if(theOscMessage.addrPattern().equals("/Diablu/Mailman/ReceivePath"))
+ {
+ recievePath(theOscMessage);
+ }
+ else {
+ println(theOscMessage);
+ }
+
+}
+
+void recievePath(OscMessage theOscMessage)
+{
+ retry = false;
+ String uuid = (String) theOscMessage.arguments()[0];
+ String fname = (String) theOscMessage.arguments()[1];
+ String originalFilename = (String) theOscMessage.arguments()[2];
+ String filename = (String) theOscMessage.arguments()[4];
+ String mimetype = (String) theOscMessage.arguments()[3];
+
+ // println(uuid + " " + fname + " " +filename + " "+ mimetype);
+
+ int[] n = new int[2];
+
+ //String content = s;
+
+ String ext = filename;
+ ext = ext.substring(ext.lastIndexOf('.') +1);
+
+ String content = "";
+ if(ext.compareToIgnoreCase("txt") == 0) {
+
+ content = parseTxt(filename);
+
+ }
+ else if(ext.compareToIgnoreCase("vnt") == 0) {
+
+ content = parseVnt(filename);
+ }
+ else { //not supported
+ lastInteraction=millis();
+ words.add(fname);
+ if (words.size() > MAX_WORDS) {
+ words.remove(0);
+ }
+ println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " fname " + uuid + " "+ fname + " " +
originalFilename + " " + filename + " " + mimetype + " " + fname);
+
+
+ showNotSupported();
+ retry = true; // show error, then retry last word
+ return;
+ }
+
+ if (content.length() > 0) {
+ lastInteraction=millis();
+ words.add(content);
+ if (words.size() > MAX_WORDS) {
+ words.remove(0);
+ }
+ println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " content " + uuid + " "+ fname + " " +
originalFilename + " " + filename + " " + mimetype + " " + content);
+ if (ping()) {
+
link(URLEncode("http://www.flickr.com/search/show/?q=\""+content+"\""));
+ } else {
+ showNetError();
+ retry = true;
+ }
+
+ }
+}
+
+void showNotSupported() {
+ link(sketchPath("notSupported.html"));
+
+}
+void showNetError() {
+ link(sketchPath("neterror.html"));
+}
+
+String parseTxt(String filename)
+{
+ byte bytes[] = loadBytes(filename);
+ //println(bytes);
+ String content;
+ try{
+ if(bytes[0] == -1 && bytes[1] == -2)
+ {
+ content = new String(bytes, 0, bytes.length , "UTF-16");
+ }
+ else{
+ content = new String(bytes, 0, bytes.length , "ISO-8859-1");
+ }
+ //tb.addContent(content);
+ return content;
+
+ }
+ catch (UnsupportedEncodingException ex) {
+
+ }
+ return "";
+
+}
+
+String parseVnt(String filename)
+{
+ byte bytes[] = loadBytes(filename);
+ //println(bytes);
+ String content="";
+ String body = "";
+ try{
+ if(bytes[0] == -1 && bytes[1] == -2)
+ {
+ content = new String(bytes, 0, bytes.length , "UTF-16");
+ }
+ else{
+ content = new String(bytes, 0, bytes.length , "ISO-8859-1");
+ }
+ //tb.addContent(content);
+
+
+ }
+ catch (UnsupportedEncodingException ex) {
+ println(ex.getMessage());
+ }
+
+
+ int start = content.toUpperCase().indexOf("BODY");
+ if(start < 0)
+ return "";
+ content = content.substring(start);
+ int dd = content.toUpperCase().indexOf(":");
+ if(dd < 0)
+ return "";
+ content = content.substring(dd+1);
+ int nl = content.toUpperCase().indexOf("\n");
+ if(nl < 0)
+ return "";
+ content = content.substring(0, nl);
+
+ while(content.toUpperCase().indexOf("=0A") != -1)
+ {
+ body += content.substring(0, content.toUpperCase().indexOf("=0A"))
+ " ";
+ content = content.substring(content.toUpperCase().indexOf("=0A")+3);
+ }
+ body += content;
+
+
+ return body;
+
+}
+
+void mousePressed() {
+ println(ping());
+
+}
+
+boolean ping() {
+
+ try {
+ Socket s = new Socket("jorgecardoso.eu", 80);
+ } catch(Exception e) {
+ return false;
+ }
+ return true;
+
+}
+
+
+

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.linux/FlickrBrowser
==============================================================================
--- (empty file)
+++
trunk/MailMan/Examples/Processing/FlickrBrowser/application.linux/FlickrBrowser
Thu Nov 6 10:24:22 2008
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+APPDIR=$(dirname "$0")
+java -Djava.library.path="$APPDIR"
-cp "$APPDIR/lib/FlickrBrowser.jar:$APPDIR/lib/core.jar:$APPDIR/lib/oscP5.jar:$APPDIR/lib/oscP5.jar"
FlickrBrowser

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.linux/lib/FlickrBrowser.jar
==============================================================================
Binary file. No diff available.

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.linux/lib/core.jar
==============================================================================
Binary file. No diff available.

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.linux/lib/oscP5.jar
==============================================================================
Binary file. No diff available.

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.linux/source/Encoder.pde
==============================================================================
--- (empty file)
+++
trunk/MailMan/Examples/Processing/FlickrBrowser/application.linux/source/Encoder.pde
Thu Nov 6 10:24:22 2008
@@ -0,0 +1,138 @@
+
+import java.io.*;
+
+
+ /**
+ * Encodes an already formed URL using the
<CODE>application/x-www-form-urlencoded</CODE>
+ * MIME format.
+ *
+ * @param s The String (URL) to be converted.
+ *
+ * @return The converted String (URL).
+ */
+ String URLEncode(String s) {
+ int questionMark = s.indexOf('?');
+
+ if (questionMark == -1) { // no parameters
+ return s;
+ } else {
+ return s.substring(0, questionMark+1) +
encodeURL(s.substring(questionMark+1));
+ }
+ }
+
+ /**
+ * Base on code in
http://forums.java.sun.com/thread.jspa?threadID=409913&messageID=1806947
+ * Converts a String to the
<CODE>application/x-www-form-urlencoded</CODE> MIME
+ * format.
+ *
+ * @param s The String to be converted.
+ *
+ * @return The converted String.
+ */
+ String encode(String s) {
+ StringBuffer out = new StringBuffer();
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+
+ DataOutputStream dOut = new DataOutputStream(bOut);
+
+ try {
+ dOut.writeUTF(s);
+ } catch (IOException ioe) {
+ return null;
+ }
+
+ ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray());
+
+ /* UTF strings have 2 bytes to indicate the size, so skip these */
+ bIn.read();
+ bIn.read();
+
+ int c = bIn.read();
+ while (c >= 0) {
+ if ((c >= 'a' && c <= 'z')
+ || (c >= 'A' && c <= 'Z')
+ || (c >= '0' && c <= '9')
+ || c == '.' || c == '-' || c == '*' || c == '_') {
+ out.append((char) c);
+ } else if (c == ' ') {
+ out.append('+');
+ } else {
+ if (c < 128) {
+ appendHex(c,out);
+ } else if (c < 224) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ } else if (c < 240) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ appendHex(bIn.read(),out);
+ }
+
+ }
+ c = bIn.read();
+ }
+ return out.toString();
+ }
+
+ /**
+ * Base on code in
http://forums.java.sun.com/thread.jspa?threadID=409913&messageID=1806947
+ *
+ * Similar to encode but we don't encode the '=' and '&' characters. This
+ * way we can use this to encode an already formed URL (or better, the
parameter
+ * part of an already formed URL).
+ */
+ String encodeURL(String s) {
+ StringBuffer out = new StringBuffer();
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+
+ DataOutputStream dOut = new DataOutputStream(bOut);
+
+ try {
+ dOut.writeUTF(s);
+ } catch (IOException ioe) {
+ return null;
+ }
+
+ ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray());
+
+ /* UTF strings have 2 bytes to indicate the size, so skip these */
+ bIn.read();
+ bIn.read();
+
+ int c = bIn.read();
+ while (c >= 0) {
+ if ((c >= 'a' && c <= 'z')
+ || (c >= 'A' && c <= 'Z')
+ || (c >= '0' && c <= '9')
+ || c == '.' || c == '-'
+ || c == '*' || c == '_'
+ || c == '=' || c == '&') {
+ out.append((char) c);
+ } else if (c == ' ') {
+ out.append('+');
+ } else {
+ if (c < 128) {
+ appendHex(c,out);
+ } else if (c < 224) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ } else if (c < 240) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ appendHex(bIn.read(),out);
+ }
+
+ }
+ c = bIn.read();
+ }
+ return out.toString();
+ }
+
+ void appendHex(int arg0, StringBuffer buff){
+ buff.append('%');
+ if (arg0<16) {
+ buff.append('0');
+ }
+ buff.append(Integer.toHexString(arg0));
+ }
+

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.linux/source/FlickrBrowser.java
==============================================================================
--- (empty file)
+++
trunk/MailMan/Examples/Processing/FlickrBrowser/application.linux/source/FlickrBrowser.java
Thu Nov 6 10:24:22 2008
@@ -0,0 +1,378 @@
+import processing.core.*; import netP5.*; import oscP5.*; import
java.net.*; import java.io.*; import java.applet.*; import java.awt.*;
import java.awt.image.*; import java.awt.event.*; import java.io.*; import
java.net.*; import java.text.*; import java.util.*; import java.util.zip.*;
public class FlickrBrowser extends PApplet {
+
+
+
+
+
+OscP5 osc;
+NetAddress myRemoteLocation;
+
+OscProperties oscp;
+OscP5 oscClient;
+OscP5 oscServer;
+
+
+int lastInteraction = millis();
+boolean retry = false;
+
+int MAX_WORDS = 100;
+Vector words;
+
+public void setup ()
+{
+
+ frameRate(1);
+
+ oscClient = new OscP5(this, "127.0.0.1", 12000, OscP5.UDP);
+ oscServer = new OscP5(this, 12001, OscP5.UDP);
+
+ myRemoteLocation = new NetAddress("127.0.0.1", 12000);
+
+ words = new Vector();
+}
+
+
+public void draw()
+{
+ if (retry) {
+ if (millis() > lastInteraction+10000) {
+ String c = (String)words.get(words.size()-1);
+ //println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " ---- Using friendly name "+c);
+ lastInteraction=millis();
+ if (ping()) {
+ link(URLEncode("http://www.flickr.com/search/show/?q=\""+c+"\""));
+ retry = false;
+ } else {
+ showNetError();
+ }
+
+ }
+ }
+ if (millis() > lastInteraction+1000*60*30) {
+ if (words.size() > 0) {
+ String c = (String)words.get((int)random(words.size()));
+ println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " ---- Reusing old tag "+c);
+
+ if (ping()) {
+ lastInteraction=millis();
+ link(URLEncode("http://www.flickr.com/search/show/?q=\""+c+"\""));
+ } else {
+ showNetError();
+ lastInteraction=lastInteraction+10*1000; // retry 10 sec later
+ }
+ }
+ }
+}
+
+
+public void oscEvent(OscMessage theOscMessage)
+{
+
+ if(theOscMessage.addrPattern().equals("/Diablu/Mailman/ReceivePath"))
+ {
+ recievePath(theOscMessage);
+ }
+ else {
+ println(theOscMessage);
+ }
+
+}
+
+public void recievePath(OscMessage theOscMessage)
+{
+ retry = false;
+ String uuid = (String) theOscMessage.arguments()[0];
+ String fname = (String) theOscMessage.arguments()[1];
+ String originalFilename = (String) theOscMessage.arguments()[2];
+ String filename = (String) theOscMessage.arguments()[4];
+ String mimetype = (String) theOscMessage.arguments()[3];
+
+ // println(uuid + " " + fname + " " +filename + " "+ mimetype);
+
+ int[] n = new int[2];
+
+ //String content = s;
+
+ String ext = filename;
+ ext = ext.substring(ext.lastIndexOf('.') +1);
+
+ String content = "";
+ if(ext.compareToIgnoreCase("txt") == 0) {
+
+ content = parseTxt(filename);
+
+ }
+ else if(ext.compareToIgnoreCase("vnt") == 0) {
+
+ content = parseVnt(filename);
+ }
+ else { //not supported
+ lastInteraction=millis();
+ words.add(fname);
+ if (words.size() > MAX_WORDS) {
+ words.remove(0);
+ }
+ println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " fname " + uuid + " "+ fname + " " +
originalFilename + " " + filename + " " + mimetype + " " + fname);
+
+
+ showNotSupported();
+ retry = true; // show error, then retry last word
+ return;
+ }
+
+ if (content.length() > 0) {
+ lastInteraction=millis();
+ words.add(content);
+ if (words.size() > MAX_WORDS) {
+ words.remove(0);
+ }
+ println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " content " + uuid + " "+ fname + " " +
originalFilename + " " + filename + " " + mimetype + " " + content);
+ if (ping()) {
+
link(URLEncode("http://www.flickr.com/search/show/?q=\""+content+"\""));
+ } else {
+ showNetError();
+ retry = true;
+ }
+
+ }
+}
+
+public void showNotSupported() {
+ link(sketchPath("notSupported.html"));
+
+}
+public void showNetError() {
+ link(sketchPath("neterror.html"));
+}
+
+public String parseTxt(String filename)
+{
+ byte bytes[] = loadBytes(filename);
+ //println(bytes);
+ String content;
+ try{
+ if(bytes[0] == -1 && bytes[1] == -2)
+ {
+ content = new String(bytes, 0, bytes.length , "UTF-16");
+ }
+ else{
+ content = new String(bytes, 0, bytes.length , "ISO-8859-1");
+ }
+ //tb.addContent(content);
+ return content;
+
+ }
+ catch (UnsupportedEncodingException ex) {
+
+ }
+ return "";
+
+}
+
+public String parseVnt(String filename)
+{
+ byte bytes[] = loadBytes(filename);
+ //println(bytes);
+ String content="";
+ String body = "";
+ try{
+ if(bytes[0] == -1 && bytes[1] == -2)
+ {
+ content = new String(bytes, 0, bytes.length , "UTF-16");
+ }
+ else{
+ content = new String(bytes, 0, bytes.length , "ISO-8859-1");
+ }
+ //tb.addContent(content);
+
+
+ }
+ catch (UnsupportedEncodingException ex) {
+ println(ex.getMessage());
+ }
+
+
+ int start = content.toUpperCase().indexOf("BODY");
+ if(start < 0)
+ return "";
+ content = content.substring(start);
+ int dd = content.toUpperCase().indexOf(":");
+ if(dd < 0)
+ return "";
+ content = content.substring(dd+1);
+ int nl = content.toUpperCase().indexOf("\n");
+ if(nl < 0)
+ return "";
+ content = content.substring(0, nl);
+
+ while(content.toUpperCase().indexOf("=0A") != -1)
+ {
+ body += content.substring(0, content.toUpperCase().indexOf("=0A"))
+ " ";
+ content = content.substring(content.toUpperCase().indexOf("=0A")+3);
+ }
+ body += content;
+
+
+ return body;
+
+}
+
+public void mousePressed() {
+ println(ping());
+
+}
+
+public boolean ping() {
+
+ try {
+ Socket s = new Socket("jorgecardoso.eu", 80);
+ } catch(Exception e) {
+ return false;
+ }
+ return true;
+
+}
+
+
+
+
+
+
+
+
+ /**
+ * Encodes an already formed URL using the
<CODE>application/x-www-form-urlencoded</CODE>
+ * MIME format.
+ *
+ * @param s The String (URL) to be converted.
+ *
+ * @return The converted String (URL).
+ */
+ public String URLEncode(String s) {
+ int questionMark = s.indexOf('?');
+
+ if (questionMark == -1) { // no parameters
+ return s;
+ } else {
+ return s.substring(0, questionMark+1) +
encodeURL(s.substring(questionMark+1));
+ }
+ }
+
+ /**
+ * Base on code in
http://forums.java.sun.com/thread.jspa?threadID=409913&messageID=1806947
+ * Converts a String to the
<CODE>application/x-www-form-urlencoded</CODE> MIME
+ * format.
+ *
+ * @param s The String to be converted.
+ *
+ * @return The converted String.
+ */
+ public String encode(String s) {
+ StringBuffer out = new StringBuffer();
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+
+ DataOutputStream dOut = new DataOutputStream(bOut);
+
+ try {
+ dOut.writeUTF(s);
+ } catch (IOException ioe) {
+ return null;
+ }
+
+ ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray());
+
+ /* UTF strings have 2 bytes to indicate the size, so skip these */
+ bIn.read();
+ bIn.read();
+
+ int c = bIn.read();
+ while (c >= 0) {
+ if ((c >= 'a' && c <= 'z')
+ || (c >= 'A' && c <= 'Z')
+ || (c >= '0' && c <= '9')
+ || c == '.' || c == '-' || c == '*' || c == '_') {
+ out.append((char) c);
+ } else if (c == ' ') {
+ out.append('+');
+ } else {
+ if (c < 128) {
+ appendHex(c,out);
+ } else if (c < 224) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ } else if (c < 240) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ appendHex(bIn.read(),out);
+ }
+
+ }
+ c = bIn.read();
+ }
+ return out.toString();
+ }
+
+ /**
+ * Base on code in
http://forums.java.sun.com/thread.jspa?threadID=409913&messageID=1806947
+ *
+ * Similar to encode but we don't encode the '=' and '&' characters. This
+ * way we can use this to encode an already formed URL (or better, the
parameter
+ * part of an already formed URL).
+ */
+ public String encodeURL(String s) {
+ StringBuffer out = new StringBuffer();
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+
+ DataOutputStream dOut = new DataOutputStream(bOut);
+
+ try {
+ dOut.writeUTF(s);
+ } catch (IOException ioe) {
+ return null;
+ }
+
+ ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray());
+
+ /* UTF strings have 2 bytes to indicate the size, so skip these */
+ bIn.read();
+ bIn.read();
+
+ int c = bIn.read();
+ while (c >= 0) {
+ if ((c >= 'a' && c <= 'z')
+ || (c >= 'A' && c <= 'Z')
+ || (c >= '0' && c <= '9')
+ || c == '.' || c == '-'
+ || c == '*' || c == '_'
+ || c == '=' || c == '&') {
+ out.append((char) c);
+ } else if (c == ' ') {
+ out.append('+');
+ } else {
+ if (c < 128) {
+ appendHex(c,out);
+ } else if (c < 224) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ } else if (c < 240) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ appendHex(bIn.read(),out);
+ }
+
+ }
+ c = bIn.read();
+ }
+ return out.toString();
+ }
+
+ public void appendHex(int arg0, StringBuffer buff){
+ buff.append('%');
+ if (arg0<16) {
+ buff.append('0');
+ }
+ buff.append(Integer.toHexString(arg0));
+ }
+
+
+ static public void main(String args[]) { PApplet.main(new String[]
{ "FlickrBrowser" }); }}
\ No newline at end of file

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.linux/source/FlickrBrowser.pde
==============================================================================
--- (empty file)
+++
trunk/MailMan/Examples/Processing/FlickrBrowser/application.linux/source/FlickrBrowser.pde
Thu Nov 6 10:24:22 2008
@@ -0,0 +1,237 @@
+
+import netP5.*;
+import oscP5.*;
+import java.net.*;
+
+
+OscP5 osc;
+NetAddress myRemoteLocation;
+
+OscProperties oscp;
+OscP5 oscClient;
+OscP5 oscServer;
+
+
+int lastInteraction = millis();
+boolean retry = false;
+
+int MAX_WORDS = 100;
+Vector words;
+
+void setup ()
+{
+
+ frameRate(1);
+
+ oscClient = new OscP5(this, "127.0.0.1", 12000, OscP5.UDP);
+ oscServer = new OscP5(this, 12001, OscP5.UDP);
+
+ myRemoteLocation = new NetAddress("127.0.0.1", 12000);
+
+ words = new Vector();
+}
+
+
+void draw()
+{
+ if (retry) {
+ if (millis() > lastInteraction+10000) {
+ String c = (String)words.get(words.size()-1);
+ //println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " ---- Using friendly name "+c);
+ lastInteraction=millis();
+ if (ping()) {
+ link(URLEncode("http://www.flickr.com/search/show/?q=\""+c+"\""));
+ retry = false;
+ } else {
+ showNetError();
+ }
+
+ }
+ }
+ if (millis() > lastInteraction+1000*60*30) {
+ if (words.size() > 0) {
+ String c = (String)words.get((int)random(words.size()));
+ println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " ---- Reusing old tag "+c);
+
+ if (ping()) {
+ lastInteraction=millis();
+ link(URLEncode("http://www.flickr.com/search/show/?q=\""+c+"\""));
+ } else {
+ showNetError();
+ lastInteraction=lastInteraction+10*1000; // retry 10 sec later
+ }
+ }
+ }
+}
+
+
+void oscEvent(OscMessage theOscMessage)
+{
+
+ if(theOscMessage.addrPattern().equals("/Diablu/Mailman/ReceivePath"))
+ {
+ recievePath(theOscMessage);
+ }
+ else {
+ println(theOscMessage);
+ }
+
+}
+
+void recievePath(OscMessage theOscMessage)
+{
+ retry = false;
+ String uuid = (String) theOscMessage.arguments()[0];
+ String fname = (String) theOscMessage.arguments()[1];
+ String originalFilename = (String) theOscMessage.arguments()[2];
+ String filename = (String) theOscMessage.arguments()[4];
+ String mimetype = (String) theOscMessage.arguments()[3];
+
+ // println(uuid + " " + fname + " " +filename + " "+ mimetype);
+
+ int[] n = new int[2];
+
+ //String content = s;
+
+ String ext = filename;
+ ext = ext.substring(ext.lastIndexOf('.') +1);
+
+ String content = "";
+ if(ext.compareToIgnoreCase("txt") == 0) {
+
+ content = parseTxt(filename);
+
+ }
+ else if(ext.compareToIgnoreCase("vnt") == 0) {
+
+ content = parseVnt(filename);
+ }
+ else { //not supported
+ lastInteraction=millis();
+ words.add(fname);
+ if (words.size() > MAX_WORDS) {
+ words.remove(0);
+ }
+ println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " fname " + uuid + " "+ fname + " " +
originalFilename + " " + filename + " " + mimetype + " " + fname);
+
+
+ showNotSupported();
+ retry = true; // show error, then retry last word
+ return;
+ }
+
+ if (content.length() > 0) {
+ lastInteraction=millis();
+ words.add(content);
+ if (words.size() > MAX_WORDS) {
+ words.remove(0);
+ }
+ println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " content " + uuid + " "+ fname + " " +
originalFilename + " " + filename + " " + mimetype + " " + content);
+ if (ping()) {
+
link(URLEncode("http://www.flickr.com/search/show/?q=\""+content+"\""));
+ } else {
+ showNetError();
+ retry = true;
+ }
+
+ }
+}
+
+void showNotSupported() {
+ link(sketchPath("notSupported.html"));
+
+}
+void showNetError() {
+ link(sketchPath("neterror.html"));
+}
+
+String parseTxt(String filename)
+{
+ byte bytes[] = loadBytes(filename);
+ //println(bytes);
+ String content;
+ try{
+ if(bytes[0] == -1 && bytes[1] == -2)
+ {
+ content = new String(bytes, 0, bytes.length , "UTF-16");
+ }
+ else{
+ content = new String(bytes, 0, bytes.length , "ISO-8859-1");
+ }
+ //tb.addContent(content);
+ return content;
+
+ }
+ catch (UnsupportedEncodingException ex) {
+
+ }
+ return "";
+
+}
+
+String parseVnt(String filename)
+{
+ byte bytes[] = loadBytes(filename);
+ //println(bytes);
+ String content="";
+ String body = "";
+ try{
+ if(bytes[0] == -1 && bytes[1] == -2)
+ {
+ content = new String(bytes, 0, bytes.length , "UTF-16");
+ }
+ else{
+ content = new String(bytes, 0, bytes.length , "ISO-8859-1");
+ }
+ //tb.addContent(content);
+
+
+ }
+ catch (UnsupportedEncodingException ex) {
+ println(ex.getMessage());
+ }
+
+
+ int start = content.toUpperCase().indexOf("BODY");
+ if(start < 0)
+ return "";
+ content = content.substring(start);
+ int dd = content.toUpperCase().indexOf(":");
+ if(dd < 0)
+ return "";
+ content = content.substring(dd+1);
+ int nl = content.toUpperCase().indexOf("\n");
+ if(nl < 0)
+ return "";
+ content = content.substring(0, nl);
+
+ while(content.toUpperCase().indexOf("=0A") != -1)
+ {
+ body += content.substring(0, content.toUpperCase().indexOf("=0A"))
+ " ";
+ content = content.substring(content.toUpperCase().indexOf("=0A")+3);
+ }
+ body += content;
+
+
+ return body;
+
+}
+
+void mousePressed() {
+ println(ping());
+
+}
+
+boolean ping() {
+
+ try {
+ Socket s = new Socket("jorgecardoso.eu", 80);
+ } catch(Exception e) {
+ return false;
+ }
+ return true;
+
+}
+
+
+

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/FlickrBrowser.app/Contents/Info.plist
==============================================================================
--- (empty file)
+++
trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/FlickrBrowser.app/Contents/Info.plist
Thu Nov 6 10:24:22 2008
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist
SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="0.9">
+<dict>
+ <key>CFBundleName</key>
+ <string>FlickrBrowser</string>
+ <key>CFBundleVersion</key>
+ <string>10.2</string>
+ <key>CFBundleAllowMixedLocalizations</key>
+ <string>true</string>
+ <key>CFBundleExecutable</key>
+ <string>JavaApplicationStub</string>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleIconFile</key>
+ <string>sketch.icns</string>
+ <key>CFBundleIdentifier</key>
+ <string>FlickrBrowser</string>
+ <key>Java</key>
+ <dict>
+ <key>VMOptions</key>
+ <string>-Xms128M -Xmx256M</string>
+ <key>MainClass</key>
+ <string>FlickrBrowser</string>
+ <key>JVMVersion</key>
+ <string>1.3+</string>
+ <key>ClassPath</key>
+
<string>$JAVAROOT/FlickrBrowser.jar:$JAVAROOT/core.jar:$JAVAROOT/oscP5.jar:$JAVAROOT/oscP5.jar</string>
+
+ <key>Properties</key>
+ <!--
http://developer.apple.com/releasenotes/Java/java141/system_properties/chapter_4_section_1.html#//apple_ref/doc/uid/TP30000285
-->
+ <dict>
+ <key>apple.laf.useScreenMenuBar</key>
+ <string>true</string>
+ <key>apple.awt.showGrowBox</key>
+ <string>false</string>
+ <key>com.apple.smallTabs</key>
+ <string>true</string>
+ <key>apple.awt.Antialiasing</key>
+ <string>false</string>
+ <key>apple.awt.TextAntialiasing</key>
+ <string>true</string>
+ <key>com.apple.hwaccel</key>
+ <string>true</string>
+ <key>apple.awt.use-file-dialog-packages</key>
+ <string>false</string>
+ </dict>
+ </dict>
+</dict>
+</plist>

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/FlickrBrowser.app/Contents/MacOS/JavaApplicationStub
==============================================================================
Binary file. No diff available.

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/FlickrBrowser.app/Contents/PkgInfo
==============================================================================
--- (empty file)
+++
trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/FlickrBrowser.app/Contents/PkgInfo
Thu Nov 6 10:24:22 2008
@@ -0,0 +1 @@
+APPL????
\ No newline at end of file

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/FlickrBrowser.app/Contents/Resources/Java/FlickrBrowser.jar
==============================================================================
Binary file. No diff available.

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/FlickrBrowser.app/Contents/Resources/Java/core.jar
==============================================================================
Binary file. No diff available.

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/FlickrBrowser.app/Contents/Resources/Java/oscP5.jar
==============================================================================
Binary file. No diff available.

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/FlickrBrowser.app/Contents/Resources/sketch.icns
==============================================================================
Binary file. No diff available.

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/readme.txt
==============================================================================
--- (empty file)
+++
trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/readme.txt
Thu Nov 6 10:24:22 2008
@@ -0,0 +1,8 @@
+This application was created on Windows, which doesn't
+properly support setting files as "executable",
+a necessity for applications on Mac OS X.
+
+To fix this, use the Terminal on Mac OS X, and from this
+directory, type the following:
+
+chmod +x FlickrBrowser.app/Contents/MacOS/JavaApplicationStub

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/source/Encoder.pde
==============================================================================
--- (empty file)
+++
trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/source/Encoder.pde
Thu Nov 6 10:24:22 2008
@@ -0,0 +1,138 @@
+
+import java.io.*;
+
+
+ /**
+ * Encodes an already formed URL using the
<CODE>application/x-www-form-urlencoded</CODE>
+ * MIME format.
+ *
+ * @param s The String (URL) to be converted.
+ *
+ * @return The converted String (URL).
+ */
+ String URLEncode(String s) {
+ int questionMark = s.indexOf('?');
+
+ if (questionMark == -1) { // no parameters
+ return s;
+ } else {
+ return s.substring(0, questionMark+1) +
encodeURL(s.substring(questionMark+1));
+ }
+ }
+
+ /**
+ * Base on code in
http://forums.java.sun.com/thread.jspa?threadID=409913&messageID=1806947
+ * Converts a String to the
<CODE>application/x-www-form-urlencoded</CODE> MIME
+ * format.
+ *
+ * @param s The String to be converted.
+ *
+ * @return The converted String.
+ */
+ String encode(String s) {
+ StringBuffer out = new StringBuffer();
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+
+ DataOutputStream dOut = new DataOutputStream(bOut);
+
+ try {
+ dOut.writeUTF(s);
+ } catch (IOException ioe) {
+ return null;
+ }
+
+ ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray());
+
+ /* UTF strings have 2 bytes to indicate the size, so skip these */
+ bIn.read();
+ bIn.read();
+
+ int c = bIn.read();
+ while (c >= 0) {
+ if ((c >= 'a' && c <= 'z')
+ || (c >= 'A' && c <= 'Z')
+ || (c >= '0' && c <= '9')
+ || c == '.' || c == '-' || c == '*' || c == '_') {
+ out.append((char) c);
+ } else if (c == ' ') {
+ out.append('+');
+ } else {
+ if (c < 128) {
+ appendHex(c,out);
+ } else if (c < 224) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ } else if (c < 240) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ appendHex(bIn.read(),out);
+ }
+
+ }
+ c = bIn.read();
+ }
+ return out.toString();
+ }
+
+ /**
+ * Base on code in
http://forums.java.sun.com/thread.jspa?threadID=409913&messageID=1806947
+ *
+ * Similar to encode but we don't encode the '=' and '&' characters. This
+ * way we can use this to encode an already formed URL (or better, the
parameter
+ * part of an already formed URL).
+ */
+ String encodeURL(String s) {
+ StringBuffer out = new StringBuffer();
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+
+ DataOutputStream dOut = new DataOutputStream(bOut);
+
+ try {
+ dOut.writeUTF(s);
+ } catch (IOException ioe) {
+ return null;
+ }
+
+ ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray());
+
+ /* UTF strings have 2 bytes to indicate the size, so skip these */
+ bIn.read();
+ bIn.read();
+
+ int c = bIn.read();
+ while (c >= 0) {
+ if ((c >= 'a' && c <= 'z')
+ || (c >= 'A' && c <= 'Z')
+ || (c >= '0' && c <= '9')
+ || c == '.' || c == '-'
+ || c == '*' || c == '_'
+ || c == '=' || c == '&') {
+ out.append((char) c);
+ } else if (c == ' ') {
+ out.append('+');
+ } else {
+ if (c < 128) {
+ appendHex(c,out);
+ } else if (c < 224) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ } else if (c < 240) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ appendHex(bIn.read(),out);
+ }
+
+ }
+ c = bIn.read();
+ }
+ return out.toString();
+ }
+
+ void appendHex(int arg0, StringBuffer buff){
+ buff.append('%');
+ if (arg0<16) {
+ buff.append('0');
+ }
+ buff.append(Integer.toHexString(arg0));
+ }
+

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/source/FlickrBrowser.java
==============================================================================
--- (empty file)
+++
trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/source/FlickrBrowser.java
Thu Nov 6 10:24:22 2008
@@ -0,0 +1,378 @@
+import processing.core.*; import netP5.*; import oscP5.*; import
java.net.*; import java.io.*; import java.applet.*; import java.awt.*;
import java.awt.image.*; import java.awt.event.*; import java.io.*; import
java.net.*; import java.text.*; import java.util.*; import java.util.zip.*;
public class FlickrBrowser extends PApplet {
+
+
+
+
+
+OscP5 osc;
+NetAddress myRemoteLocation;
+
+OscProperties oscp;
+OscP5 oscClient;
+OscP5 oscServer;
+
+
+int lastInteraction = millis();
+boolean retry = false;
+
+int MAX_WORDS = 100;
+Vector words;
+
+public void setup ()
+{
+
+ frameRate(1);
+
+ oscClient = new OscP5(this, "127.0.0.1", 12000, OscP5.UDP);
+ oscServer = new OscP5(this, 12001, OscP5.UDP);
+
+ myRemoteLocation = new NetAddress("127.0.0.1", 12000);
+
+ words = new Vector();
+}
+
+
+public void draw()
+{
+ if (retry) {
+ if (millis() > lastInteraction+10000) {
+ String c = (String)words.get(words.size()-1);
+ //println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " ---- Using friendly name "+c);
+ lastInteraction=millis();
+ if (ping()) {
+ link(URLEncode("http://www.flickr.com/search/show/?q=\""+c+"\""));
+ retry = false;
+ } else {
+ showNetError();
+ }
+
+ }
+ }
+ if (millis() > lastInteraction+1000*60*30) {
+ if (words.size() > 0) {
+ String c = (String)words.get((int)random(words.size()));
+ println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " ---- Reusing old tag "+c);
+
+ if (ping()) {
+ lastInteraction=millis();
+ link(URLEncode("http://www.flickr.com/search/show/?q=\""+c+"\""));
+ } else {
+ showNetError();
+ lastInteraction=lastInteraction+10*1000; // retry 10 sec later
+ }
+ }
+ }
+}
+
+
+public void oscEvent(OscMessage theOscMessage)
+{
+
+ if(theOscMessage.addrPattern().equals("/Diablu/Mailman/ReceivePath"))
+ {
+ recievePath(theOscMessage);
+ }
+ else {
+ println(theOscMessage);
+ }
+
+}
+
+public void recievePath(OscMessage theOscMessage)
+{
+ retry = false;
+ String uuid = (String) theOscMessage.arguments()[0];
+ String fname = (String) theOscMessage.arguments()[1];
+ String originalFilename = (String) theOscMessage.arguments()[2];
+ String filename = (String) theOscMessage.arguments()[4];
+ String mimetype = (String) theOscMessage.arguments()[3];
+
+ // println(uuid + " " + fname + " " +filename + " "+ mimetype);
+
+ int[] n = new int[2];
+
+ //String content = s;
+
+ String ext = filename;
+ ext = ext.substring(ext.lastIndexOf('.') +1);
+
+ String content = "";
+ if(ext.compareToIgnoreCase("txt") == 0) {
+
+ content = parseTxt(filename);
+
+ }
+ else if(ext.compareToIgnoreCase("vnt") == 0) {
+
+ content = parseVnt(filename);
+ }
+ else { //not supported
+ lastInteraction=millis();
+ words.add(fname);
+ if (words.size() > MAX_WORDS) {
+ words.remove(0);
+ }
+ println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " fname " + uuid + " "+ fname + " " +
originalFilename + " " + filename + " " + mimetype + " " + fname);
+
+
+ showNotSupported();
+ retry = true; // show error, then retry last word
+ return;
+ }
+
+ if (content.length() > 0) {
+ lastInteraction=millis();
+ words.add(content);
+ if (words.size() > MAX_WORDS) {
+ words.remove(0);
+ }
+ println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " content " + uuid + " "+ fname + " " +
originalFilename + " " + filename + " " + mimetype + " " + content);
+ if (ping()) {
+
link(URLEncode("http://www.flickr.com/search/show/?q=\""+content+"\""));
+ } else {
+ showNetError();
+ retry = true;
+ }
+
+ }
+}
+
+public void showNotSupported() {
+ link(sketchPath("notSupported.html"));
+
+}
+public void showNetError() {
+ link(sketchPath("neterror.html"));
+}
+
+public String parseTxt(String filename)
+{
+ byte bytes[] = loadBytes(filename);
+ //println(bytes);
+ String content;
+ try{
+ if(bytes[0] == -1 && bytes[1] == -2)
+ {
+ content = new String(bytes, 0, bytes.length , "UTF-16");
+ }
+ else{
+ content = new String(bytes, 0, bytes.length , "ISO-8859-1");
+ }
+ //tb.addContent(content);
+ return content;
+
+ }
+ catch (UnsupportedEncodingException ex) {
+
+ }
+ return "";
+
+}
+
+public String parseVnt(String filename)
+{
+ byte bytes[] = loadBytes(filename);
+ //println(bytes);
+ String content="";
+ String body = "";
+ try{
+ if(bytes[0] == -1 && bytes[1] == -2)
+ {
+ content = new String(bytes, 0, bytes.length , "UTF-16");
+ }
+ else{
+ content = new String(bytes, 0, bytes.length , "ISO-8859-1");
+ }
+ //tb.addContent(content);
+
+
+ }
+ catch (UnsupportedEncodingException ex) {
+ println(ex.getMessage());
+ }
+
+
+ int start = content.toUpperCase().indexOf("BODY");
+ if(start < 0)
+ return "";
+ content = content.substring(start);
+ int dd = content.toUpperCase().indexOf(":");
+ if(dd < 0)
+ return "";
+ content = content.substring(dd+1);
+ int nl = content.toUpperCase().indexOf("\n");
+ if(nl < 0)
+ return "";
+ content = content.substring(0, nl);
+
+ while(content.toUpperCase().indexOf("=0A") != -1)
+ {
+ body += content.substring(0, content.toUpperCase().indexOf("=0A"))
+ " ";
+ content = content.substring(content.toUpperCase().indexOf("=0A")+3);
+ }
+ body += content;
+
+
+ return body;
+
+}
+
+public void mousePressed() {
+ println(ping());
+
+}
+
+public boolean ping() {
+
+ try {
+ Socket s = new Socket("jorgecardoso.eu", 80);
+ } catch(Exception e) {
+ return false;
+ }
+ return true;
+
+}
+
+
+
+
+
+
+
+
+ /**
+ * Encodes an already formed URL using the
<CODE>application/x-www-form-urlencoded</CODE>
+ * MIME format.
+ *
+ * @param s The String (URL) to be converted.
+ *
+ * @return The converted String (URL).
+ */
+ public String URLEncode(String s) {
+ int questionMark = s.indexOf('?');
+
+ if (questionMark == -1) { // no parameters
+ return s;
+ } else {
+ return s.substring(0, questionMark+1) +
encodeURL(s.substring(questionMark+1));
+ }
+ }
+
+ /**
+ * Base on code in
http://forums.java.sun.com/thread.jspa?threadID=409913&messageID=1806947
+ * Converts a String to the
<CODE>application/x-www-form-urlencoded</CODE> MIME
+ * format.
+ *
+ * @param s The String to be converted.
+ *
+ * @return The converted String.
+ */
+ public String encode(String s) {
+ StringBuffer out = new StringBuffer();
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+
+ DataOutputStream dOut = new DataOutputStream(bOut);
+
+ try {
+ dOut.writeUTF(s);
+ } catch (IOException ioe) {
+ return null;
+ }
+
+ ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray());
+
+ /* UTF strings have 2 bytes to indicate the size, so skip these */
+ bIn.read();
+ bIn.read();
+
+ int c = bIn.read();
+ while (c >= 0) {
+ if ((c >= 'a' && c <= 'z')
+ || (c >= 'A' && c <= 'Z')
+ || (c >= '0' && c <= '9')
+ || c == '.' || c == '-' || c == '*' || c == '_') {
+ out.append((char) c);
+ } else if (c == ' ') {
+ out.append('+');
+ } else {
+ if (c < 128) {
+ appendHex(c,out);
+ } else if (c < 224) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ } else if (c < 240) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ appendHex(bIn.read(),out);
+ }
+
+ }
+ c = bIn.read();
+ }
+ return out.toString();
+ }
+
+ /**
+ * Base on code in
http://forums.java.sun.com/thread.jspa?threadID=409913&messageID=1806947
+ *
+ * Similar to encode but we don't encode the '=' and '&' characters. This
+ * way we can use this to encode an already formed URL (or better, the
parameter
+ * part of an already formed URL).
+ */
+ public String encodeURL(String s) {
+ StringBuffer out = new StringBuffer();
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+
+ DataOutputStream dOut = new DataOutputStream(bOut);
+
+ try {
+ dOut.writeUTF(s);
+ } catch (IOException ioe) {
+ return null;
+ }
+
+ ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray());
+
+ /* UTF strings have 2 bytes to indicate the size, so skip these */
+ bIn.read();
+ bIn.read();
+
+ int c = bIn.read();
+ while (c >= 0) {
+ if ((c >= 'a' && c <= 'z')
+ || (c >= 'A' && c <= 'Z')
+ || (c >= '0' && c <= '9')
+ || c == '.' || c == '-'
+ || c == '*' || c == '_'
+ || c == '=' || c == '&') {
+ out.append((char) c);
+ } else if (c == ' ') {
+ out.append('+');
+ } else {
+ if (c < 128) {
+ appendHex(c,out);
+ } else if (c < 224) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ } else if (c < 240) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ appendHex(bIn.read(),out);
+ }
+
+ }
+ c = bIn.read();
+ }
+ return out.toString();
+ }
+
+ public void appendHex(int arg0, StringBuffer buff){
+ buff.append('%');
+ if (arg0<16) {
+ buff.append('0');
+ }
+ buff.append(Integer.toHexString(arg0));
+ }
+
+
+ static public void main(String args[]) { PApplet.main(new String[]
{ "FlickrBrowser" }); }}
\ No newline at end of file

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/source/FlickrBrowser.pde
==============================================================================
--- (empty file)
+++
trunk/MailMan/Examples/Processing/FlickrBrowser/application.macosx/source/FlickrBrowser.pde
Thu Nov 6 10:24:22 2008
@@ -0,0 +1,237 @@
+
+import netP5.*;
+import oscP5.*;
+import java.net.*;
+
+
+OscP5 osc;
+NetAddress myRemoteLocation;
+
+OscProperties oscp;
+OscP5 oscClient;
+OscP5 oscServer;
+
+
+int lastInteraction = millis();
+boolean retry = false;
+
+int MAX_WORDS = 100;
+Vector words;
+
+void setup ()
+{
+
+ frameRate(1);
+
+ oscClient = new OscP5(this, "127.0.0.1", 12000, OscP5.UDP);
+ oscServer = new OscP5(this, 12001, OscP5.UDP);
+
+ myRemoteLocation = new NetAddress("127.0.0.1", 12000);
+
+ words = new Vector();
+}
+
+
+void draw()
+{
+ if (retry) {
+ if (millis() > lastInteraction+10000) {
+ String c = (String)words.get(words.size()-1);
+ //println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " ---- Using friendly name "+c);
+ lastInteraction=millis();
+ if (ping()) {
+ link(URLEncode("http://www.flickr.com/search/show/?q=\""+c+"\""));
+ retry = false;
+ } else {
+ showNetError();
+ }
+
+ }
+ }
+ if (millis() > lastInteraction+1000*60*30) {
+ if (words.size() > 0) {
+ String c = (String)words.get((int)random(words.size()));
+ println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " ---- Reusing old tag "+c);
+
+ if (ping()) {
+ lastInteraction=millis();
+ link(URLEncode("http://www.flickr.com/search/show/?q=\""+c+"\""));
+ } else {
+ showNetError();
+ lastInteraction=lastInteraction+10*1000; // retry 10 sec later
+ }
+ }
+ }
+}
+
+
+void oscEvent(OscMessage theOscMessage)
+{
+
+ if(theOscMessage.addrPattern().equals("/Diablu/Mailman/ReceivePath"))
+ {
+ recievePath(theOscMessage);
+ }
+ else {
+ println(theOscMessage);
+ }
+
+}
+
+void recievePath(OscMessage theOscMessage)
+{
+ retry = false;
+ String uuid = (String) theOscMessage.arguments()[0];
+ String fname = (String) theOscMessage.arguments()[1];
+ String originalFilename = (String) theOscMessage.arguments()[2];
+ String filename = (String) theOscMessage.arguments()[4];
+ String mimetype = (String) theOscMessage.arguments()[3];
+
+ // println(uuid + " " + fname + " " +filename + " "+ mimetype);
+
+ int[] n = new int[2];
+
+ //String content = s;
+
+ String ext = filename;
+ ext = ext.substring(ext.lastIndexOf('.') +1);
+
+ String content = "";
+ if(ext.compareToIgnoreCase("txt") == 0) {
+
+ content = parseTxt(filename);
+
+ }
+ else if(ext.compareToIgnoreCase("vnt") == 0) {
+
+ content = parseVnt(filename);
+ }
+ else { //not supported
+ lastInteraction=millis();
+ words.add(fname);
+ if (words.size() > MAX_WORDS) {
+ words.remove(0);
+ }
+ println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " fname " + uuid + " "+ fname + " " +
originalFilename + " " + filename + " " + mimetype + " " + fname);
+
+
+ showNotSupported();
+ retry = true; // show error, then retry last word
+ return;
+ }
+
+ if (content.length() > 0) {
+ lastInteraction=millis();
+ words.add(content);
+ if (words.size() > MAX_WORDS) {
+ words.remove(0);
+ }
+ println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " content " + uuid + " "+ fname + " " +
originalFilename + " " + filename + " " + mimetype + " " + content);
+ if (ping()) {
+
link(URLEncode("http://www.flickr.com/search/show/?q=\""+content+"\""));
+ } else {
+ showNetError();
+ retry = true;
+ }
+
+ }
+}
+
+void showNotSupported() {
+ link(sketchPath("notSupported.html"));
+
+}
+void showNetError() {
+ link(sketchPath("neterror.html"));
+}
+
+String parseTxt(String filename)
+{
+ byte bytes[] = loadBytes(filename);
+ //println(bytes);
+ String content;
+ try{
+ if(bytes[0] == -1 && bytes[1] == -2)
+ {
+ content = new String(bytes, 0, bytes.length , "UTF-16");
+ }
+ else{
+ content = new String(bytes, 0, bytes.length , "ISO-8859-1");
+ }
+ //tb.addContent(content);
+ return content;
+
+ }
+ catch (UnsupportedEncodingException ex) {
+
+ }
+ return "";
+
+}
+
+String parseVnt(String filename)
+{
+ byte bytes[] = loadBytes(filename);
+ //println(bytes);
+ String content="";
+ String body = "";
+ try{
+ if(bytes[0] == -1 && bytes[1] == -2)
+ {
+ content = new String(bytes, 0, bytes.length , "UTF-16");
+ }
+ else{
+ content = new String(bytes, 0, bytes.length , "ISO-8859-1");
+ }
+ //tb.addContent(content);
+
+
+ }
+ catch (UnsupportedEncodingException ex) {
+ println(ex.getMessage());
+ }
+
+
+ int start = content.toUpperCase().indexOf("BODY");
+ if(start < 0)
+ return "";
+ content = content.substring(start);
+ int dd = content.toUpperCase().indexOf(":");
+ if(dd < 0)
+ return "";
+ content = content.substring(dd+1);
+ int nl = content.toUpperCase().indexOf("\n");
+ if(nl < 0)
+ return "";
+ content = content.substring(0, nl);
+
+ while(content.toUpperCase().indexOf("=0A") != -1)
+ {
+ body += content.substring(0, content.toUpperCase().indexOf("=0A"))
+ " ";
+ content = content.substring(content.toUpperCase().indexOf("=0A")+3);
+ }
+ body += content;
+
+
+ return body;
+
+}
+
+void mousePressed() {
+ println(ping());
+
+}
+
+boolean ping() {
+
+ try {
+ Socket s = new Socket("jorgecardoso.eu", 80);
+ } catch(Exception e) {
+ return false;
+ }
+ return true;
+
+}
+
+
+

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.windows/FlickrBrowser.exe
==============================================================================
Binary file. No diff available.

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.windows/lib/FlickrBrowser.jar
==============================================================================
Binary file. No diff available.

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.windows/lib/args.txt
==============================================================================
--- (empty file)
+++
trunk/MailMan/Examples/Processing/FlickrBrowser/application.windows/lib/args.txt
Thu Nov 6 10:24:22 2008
@@ -0,0 +1,3 @@
+ -Xms64m -Xmx512m
+FlickrBrowser
+FlickrBrowser.jar,core.jar,oscP5.jar,oscP5.jar

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.windows/lib/core.jar
==============================================================================
Binary file. No diff available.

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.windows/lib/oscP5.jar
==============================================================================
Binary file. No diff available.

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.windows/source/Encoder.pde
==============================================================================
--- (empty file)
+++
trunk/MailMan/Examples/Processing/FlickrBrowser/application.windows/source/Encoder.pde
Thu Nov 6 10:24:22 2008
@@ -0,0 +1,138 @@
+
+import java.io.*;
+
+
+ /**
+ * Encodes an already formed URL using the
<CODE>application/x-www-form-urlencoded</CODE>
+ * MIME format.
+ *
+ * @param s The String (URL) to be converted.
+ *
+ * @return The converted String (URL).
+ */
+ String URLEncode(String s) {
+ int questionMark = s.indexOf('?');
+
+ if (questionMark == -1) { // no parameters
+ return s;
+ } else {
+ return s.substring(0, questionMark+1) +
encodeURL(s.substring(questionMark+1));
+ }
+ }
+
+ /**
+ * Base on code in
http://forums.java.sun.com/thread.jspa?threadID=409913&messageID=1806947
+ * Converts a String to the
<CODE>application/x-www-form-urlencoded</CODE> MIME
+ * format.
+ *
+ * @param s The String to be converted.
+ *
+ * @return The converted String.
+ */
+ String encode(String s) {
+ StringBuffer out = new StringBuffer();
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+
+ DataOutputStream dOut = new DataOutputStream(bOut);
+
+ try {
+ dOut.writeUTF(s);
+ } catch (IOException ioe) {
+ return null;
+ }
+
+ ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray());
+
+ /* UTF strings have 2 bytes to indicate the size, so skip these */
+ bIn.read();
+ bIn.read();
+
+ int c = bIn.read();
+ while (c >= 0) {
+ if ((c >= 'a' && c <= 'z')
+ || (c >= 'A' && c <= 'Z')
+ || (c >= '0' && c <= '9')
+ || c == '.' || c == '-' || c == '*' || c == '_') {
+ out.append((char) c);
+ } else if (c == ' ') {
+ out.append('+');
+ } else {
+ if (c < 128) {
+ appendHex(c,out);
+ } else if (c < 224) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ } else if (c < 240) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ appendHex(bIn.read(),out);
+ }
+
+ }
+ c = bIn.read();
+ }
+ return out.toString();
+ }
+
+ /**
+ * Base on code in
http://forums.java.sun.com/thread.jspa?threadID=409913&messageID=1806947
+ *
+ * Similar to encode but we don't encode the '=' and '&' characters. This
+ * way we can use this to encode an already formed URL (or better, the
parameter
+ * part of an already formed URL).
+ */
+ String encodeURL(String s) {
+ StringBuffer out = new StringBuffer();
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+
+ DataOutputStream dOut = new DataOutputStream(bOut);
+
+ try {
+ dOut.writeUTF(s);
+ } catch (IOException ioe) {
+ return null;
+ }
+
+ ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray());
+
+ /* UTF strings have 2 bytes to indicate the size, so skip these */
+ bIn.read();
+ bIn.read();
+
+ int c = bIn.read();
+ while (c >= 0) {
+ if ((c >= 'a' && c <= 'z')
+ || (c >= 'A' && c <= 'Z')
+ || (c >= '0' && c <= '9')
+ || c == '.' || c == '-'
+ || c == '*' || c == '_'
+ || c == '=' || c == '&') {
+ out.append((char) c);
+ } else if (c == ' ') {
+ out.append('+');
+ } else {
+ if (c < 128) {
+ appendHex(c,out);
+ } else if (c < 224) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ } else if (c < 240) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ appendHex(bIn.read(),out);
+ }
+
+ }
+ c = bIn.read();
+ }
+ return out.toString();
+ }
+
+ void appendHex(int arg0, StringBuffer buff){
+ buff.append('%');
+ if (arg0<16) {
+ buff.append('0');
+ }
+ buff.append(Integer.toHexString(arg0));
+ }
+

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.windows/source/FlickrBrowser.java
==============================================================================
--- (empty file)
+++
trunk/MailMan/Examples/Processing/FlickrBrowser/application.windows/source/FlickrBrowser.java
Thu Nov 6 10:24:22 2008
@@ -0,0 +1,378 @@
+import processing.core.*; import netP5.*; import oscP5.*; import
java.net.*; import java.io.*; import java.applet.*; import java.awt.*;
import java.awt.image.*; import java.awt.event.*; import java.io.*; import
java.net.*; import java.text.*; import java.util.*; import java.util.zip.*;
public class FlickrBrowser extends PApplet {
+
+
+
+
+
+OscP5 osc;
+NetAddress myRemoteLocation;
+
+OscProperties oscp;
+OscP5 oscClient;
+OscP5 oscServer;
+
+
+int lastInteraction = millis();
+boolean retry = false;
+
+int MAX_WORDS = 100;
+Vector words;
+
+public void setup ()
+{
+
+ frameRate(1);
+
+ oscClient = new OscP5(this, "127.0.0.1", 12000, OscP5.UDP);
+ oscServer = new OscP5(this, 12001, OscP5.UDP);
+
+ myRemoteLocation = new NetAddress("127.0.0.1", 12000);
+
+ words = new Vector();
+}
+
+
+public void draw()
+{
+ if (retry) {
+ if (millis() > lastInteraction+10000) {
+ String c = (String)words.get(words.size()-1);
+ //println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " ---- Using friendly name "+c);
+ lastInteraction=millis();
+ if (ping()) {
+ link(URLEncode("http://www.flickr.com/search/show/?q=\""+c+"\""));
+ retry = false;
+ } else {
+ showNetError();
+ }
+
+ }
+ }
+ if (millis() > lastInteraction+1000*60*30) {
+ if (words.size() > 0) {
+ String c = (String)words.get((int)random(words.size()));
+ println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " ---- Reusing old tag "+c);
+
+ if (ping()) {
+ lastInteraction=millis();
+ link(URLEncode("http://www.flickr.com/search/show/?q=\""+c+"\""));
+ } else {
+ showNetError();
+ lastInteraction=lastInteraction+10*1000; // retry 10 sec later
+ }
+ }
+ }
+}
+
+
+public void oscEvent(OscMessage theOscMessage)
+{
+
+ if(theOscMessage.addrPattern().equals("/Diablu/Mailman/ReceivePath"))
+ {
+ recievePath(theOscMessage);
+ }
+ else {
+ println(theOscMessage);
+ }
+
+}
+
+public void recievePath(OscMessage theOscMessage)
+{
+ retry = false;
+ String uuid = (String) theOscMessage.arguments()[0];
+ String fname = (String) theOscMessage.arguments()[1];
+ String originalFilename = (String) theOscMessage.arguments()[2];
+ String filename = (String) theOscMessage.arguments()[4];
+ String mimetype = (String) theOscMessage.arguments()[3];
+
+ // println(uuid + " " + fname + " " +filename + " "+ mimetype);
+
+ int[] n = new int[2];
+
+ //String content = s;
+
+ String ext = filename;
+ ext = ext.substring(ext.lastIndexOf('.') +1);
+
+ String content = "";
+ if(ext.compareToIgnoreCase("txt") == 0) {
+
+ content = parseTxt(filename);
+
+ }
+ else if(ext.compareToIgnoreCase("vnt") == 0) {
+
+ content = parseVnt(filename);
+ }
+ else { //not supported
+ lastInteraction=millis();
+ words.add(fname);
+ if (words.size() > MAX_WORDS) {
+ words.remove(0);
+ }
+ println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " fname " + uuid + " "+ fname + " " +
originalFilename + " " + filename + " " + mimetype + " " + fname);
+
+
+ showNotSupported();
+ retry = true; // show error, then retry last word
+ return;
+ }
+
+ if (content.length() > 0) {
+ lastInteraction=millis();
+ words.add(content);
+ if (words.size() > MAX_WORDS) {
+ words.remove(0);
+ }
+ println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " content " + uuid + " "+ fname + " " +
originalFilename + " " + filename + " " + mimetype + " " + content);
+ if (ping()) {
+
link(URLEncode("http://www.flickr.com/search/show/?q=\""+content+"\""));
+ } else {
+ showNetError();
+ retry = true;
+ }
+
+ }
+}
+
+public void showNotSupported() {
+ link(sketchPath("notSupported.html"));
+
+}
+public void showNetError() {
+ link(sketchPath("neterror.html"));
+}
+
+public String parseTxt(String filename)
+{
+ byte bytes[] = loadBytes(filename);
+ //println(bytes);
+ String content;
+ try{
+ if(bytes[0] == -1 && bytes[1] == -2)
+ {
+ content = new String(bytes, 0, bytes.length , "UTF-16");
+ }
+ else{
+ content = new String(bytes, 0, bytes.length , "ISO-8859-1");
+ }
+ //tb.addContent(content);
+ return content;
+
+ }
+ catch (UnsupportedEncodingException ex) {
+
+ }
+ return "";
+
+}
+
+public String parseVnt(String filename)
+{
+ byte bytes[] = loadBytes(filename);
+ //println(bytes);
+ String content="";
+ String body = "";
+ try{
+ if(bytes[0] == -1 && bytes[1] == -2)
+ {
+ content = new String(bytes, 0, bytes.length , "UTF-16");
+ }
+ else{
+ content = new String(bytes, 0, bytes.length , "ISO-8859-1");
+ }
+ //tb.addContent(content);
+
+
+ }
+ catch (UnsupportedEncodingException ex) {
+ println(ex.getMessage());
+ }
+
+
+ int start = content.toUpperCase().indexOf("BODY");
+ if(start < 0)
+ return "";
+ content = content.substring(start);
+ int dd = content.toUpperCase().indexOf(":");
+ if(dd < 0)
+ return "";
+ content = content.substring(dd+1);
+ int nl = content.toUpperCase().indexOf("\n");
+ if(nl < 0)
+ return "";
+ content = content.substring(0, nl);
+
+ while(content.toUpperCase().indexOf("=0A") != -1)
+ {
+ body += content.substring(0, content.toUpperCase().indexOf("=0A"))
+ " ";
+ content = content.substring(content.toUpperCase().indexOf("=0A")+3);
+ }
+ body += content;
+
+
+ return body;
+
+}
+
+public void mousePressed() {
+ println(ping());
+
+}
+
+public boolean ping() {
+
+ try {
+ Socket s = new Socket("jorgecardoso.eu", 80);
+ } catch(Exception e) {
+ return false;
+ }
+ return true;
+
+}
+
+
+
+
+
+
+
+
+ /**
+ * Encodes an already formed URL using the
<CODE>application/x-www-form-urlencoded</CODE>
+ * MIME format.
+ *
+ * @param s The String (URL) to be converted.
+ *
+ * @return The converted String (URL).
+ */
+ public String URLEncode(String s) {
+ int questionMark = s.indexOf('?');
+
+ if (questionMark == -1) { // no parameters
+ return s;
+ } else {
+ return s.substring(0, questionMark+1) +
encodeURL(s.substring(questionMark+1));
+ }
+ }
+
+ /**
+ * Base on code in
http://forums.java.sun.com/thread.jspa?threadID=409913&messageID=1806947
+ * Converts a String to the
<CODE>application/x-www-form-urlencoded</CODE> MIME
+ * format.
+ *
+ * @param s The String to be converted.
+ *
+ * @return The converted String.
+ */
+ public String encode(String s) {
+ StringBuffer out = new StringBuffer();
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+
+ DataOutputStream dOut = new DataOutputStream(bOut);
+
+ try {
+ dOut.writeUTF(s);
+ } catch (IOException ioe) {
+ return null;
+ }
+
+ ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray());
+
+ /* UTF strings have 2 bytes to indicate the size, so skip these */
+ bIn.read();
+ bIn.read();
+
+ int c = bIn.read();
+ while (c >= 0) {
+ if ((c >= 'a' && c <= 'z')
+ || (c >= 'A' && c <= 'Z')
+ || (c >= '0' && c <= '9')
+ || c == '.' || c == '-' || c == '*' || c == '_') {
+ out.append((char) c);
+ } else if (c == ' ') {
+ out.append('+');
+ } else {
+ if (c < 128) {
+ appendHex(c,out);
+ } else if (c < 224) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ } else if (c < 240) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ appendHex(bIn.read(),out);
+ }
+
+ }
+ c = bIn.read();
+ }
+ return out.toString();
+ }
+
+ /**
+ * Base on code in
http://forums.java.sun.com/thread.jspa?threadID=409913&messageID=1806947
+ *
+ * Similar to encode but we don't encode the '=' and '&' characters. This
+ * way we can use this to encode an already formed URL (or better, the
parameter
+ * part of an already formed URL).
+ */
+ public String encodeURL(String s) {
+ StringBuffer out = new StringBuffer();
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+
+ DataOutputStream dOut = new DataOutputStream(bOut);
+
+ try {
+ dOut.writeUTF(s);
+ } catch (IOException ioe) {
+ return null;
+ }
+
+ ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray());
+
+ /* UTF strings have 2 bytes to indicate the size, so skip these */
+ bIn.read();
+ bIn.read();
+
+ int c = bIn.read();
+ while (c >= 0) {
+ if ((c >= 'a' && c <= 'z')
+ || (c >= 'A' && c <= 'Z')
+ || (c >= '0' && c <= '9')
+ || c == '.' || c == '-'
+ || c == '*' || c == '_'
+ || c == '=' || c == '&') {
+ out.append((char) c);
+ } else if (c == ' ') {
+ out.append('+');
+ } else {
+ if (c < 128) {
+ appendHex(c,out);
+ } else if (c < 224) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ } else if (c < 240) {
+ appendHex(c,out);
+ appendHex(bIn.read(),out);
+ appendHex(bIn.read(),out);
+ }
+
+ }
+ c = bIn.read();
+ }
+ return out.toString();
+ }
+
+ public void appendHex(int arg0, StringBuffer buff){
+ buff.append('%');
+ if (arg0<16) {
+ buff.append('0');
+ }
+ buff.append(Integer.toHexString(arg0));
+ }
+
+
+ static public void main(String args[]) { PApplet.main(new String[]
{ "FlickrBrowser" }); }}
\ No newline at end of file

Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/application.windows/source/FlickrBrowser.pde
==============================================================================
--- (empty file)
+++
trunk/MailMan/Examples/Processing/FlickrBrowser/application.windows/source/FlickrBrowser.pde
Thu Nov 6 10:24:22 2008
@@ -0,0 +1,237 @@
+
+import netP5.*;
+import oscP5.*;
+import java.net.*;
+
+
+OscP5 osc;
+NetAddress myRemoteLocation;
+
+OscProperties oscp;
+OscP5 oscClient;
+OscP5 oscServer;
+
+
+int lastInteraction = millis();
+boolean retry = false;
+
+int MAX_WORDS = 100;
+Vector words;
+
+void setup ()
+{
+
+ frameRate(1);
+
+ oscClient = new OscP5(this, "127.0.0.1", 12000, OscP5.UDP);
+ oscServer = new OscP5(this, 12001, OscP5.UDP);
+
+ myRemoteLocation = new NetAddress("127.0.0.1", 12000);
+
+ words = new Vector();
+}
+
+
+void draw()
+{
+ if (retry) {
+ if (millis() > lastInteraction+10000) {
+ String c = (String)words.get(words.size()-1);
+ //println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " ---- Using friendly name "+c);
+ lastInteraction=millis();
+ if (ping()) {
+ link(URLEncode("http://www.flickr.com/search/show/?q=\""+c+"\""));
+ retry = false;
+ } else {
+ showNetError();
+ }
+
+ }
+ }
+ if (millis() > lastInteraction+1000*60*30) {
+ if (words.size() > 0) {
+ String c = (String)words.get((int)random(words.size()));
+ println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " ---- Reusing old tag "+c);
+
+ if (ping()) {
+ lastInteraction=millis();
+ link(URLEncode("http://www.flickr.com/search/show/?q=\""+c+"\""));
+ } else {
+ showNetError();
+ lastInteraction=lastInteraction+10*1000; // retry 10 sec later
+ }
+ }
+ }
+}
+
+
+void oscEvent(OscMessage theOscMessage)
+{
+
+ if(theOscMessage.addrPattern().equals("/Diablu/Mailman/ReceivePath"))
+ {
+ recievePath(theOscMessage);
+ }
+ else {
+ println(theOscMessage);
+ }
+
+}
+
+void recievePath(OscMessage theOscMessage)
+{
+ retry = false;
+ String uuid = (String) theOscMessage.arguments()[0];
+ String fname = (String) theOscMessage.arguments()[1];
+ String originalFilename = (String) theOscMessage.arguments()[2];
+ String filename = (String) theOscMessage.arguments()[4];
+ String mimetype = (String) theOscMessage.arguments()[3];
+
+ // println(uuid + " " + fname + " " +filename + " "+ mimetype);
+
+ int[] n = new int[2];
+
+ //String content = s;
+
+ String ext = filename;
+ ext = ext.substring(ext.lastIndexOf('.') +1);
+
+ String content = "";
+ if(ext.compareToIgnoreCase("txt") == 0) {
+
+ content = parseTxt(filename);
+
+ }
+ else if(ext.compareToIgnoreCase("vnt") == 0) {
+
+ content = parseVnt(filename);
+ }
+ else { //not supported
+ lastInteraction=millis();
+ words.add(fname);
+ if (words.size() > MAX_WORDS) {
+ words.remove(0);
+ }
+ println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " fname " + uuid + " "+ fname + " " +
originalFilename + " " + filename + " " + mimetype + " " + fname);
+
+
+ showNotSupported();
+ retry = true; // show error, then retry last word
+ return;
+ }
+
+ if (content.length() > 0) {
+ lastInteraction=millis();
+ words.add(content);
+ if (words.size() > MAX_WORDS) {
+ words.remove(0);
+ }
+ println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " content " + uuid + " "+ fname + " " +
originalFilename + " " + filename + " " + mimetype + " " + content);
+ if (ping()) {
+
link(URLEncode("http://www.flickr.com/search/show/?q=\""+content+"\""));
+ } else {
+ showNetError();
+ retry = true;
+ }
+
+ }
+}
+
+void showNotSupported() {
+ link(sketchPath("notSupported.html"));
+
+}
+void showNetError() {
+ link(sketchPath("neterror.html"));
+}
+
+String parseTxt(String filename)
+{
+ byte bytes[] = loadBytes(filename);
+ //println(bytes);
+ String content;
+ try{
+ if(bytes[0] == -1 && bytes[1] == -2)
+ {
+ content = new String(bytes, 0, bytes.length , "UTF-16");
+ }
+ else{
+ content = new String(bytes, 0, bytes.length , "ISO-8859-1");
+ }
+ //tb.addContent(content);
+ return content;
+
+ }
+ catch (UnsupportedEncodingException ex) {
+
+ }
+ return "";
+
+}
+
+String parseVnt(String filename)
+{
+ byte bytes[] = loadBytes(filename);
+ //println(bytes);
+ String content="";
+ String body = "";
+ try{
+ if(bytes[0] == -1 && bytes[1] == -2)
+ {
+ content = new String(bytes, 0, bytes.length , "UTF-16");
+ }
+ else{
+ content = new String(bytes, 0, bytes.length , "ISO-8859-1");
+ }
+ //tb.addContent(content);
+
+
+ }
+ catch (UnsupportedEncodingException ex) {
+ println(ex.getMessage());
+ }
+
+
+ int start = content.toUpperCase().indexOf("BODY");
+ if(start < 0)
+ return "";
+ content = content.substring(start);
+ int dd = content.toUpperCase().indexOf(":");
+ if(dd < 0)
+ return "";
+ content = content.substring(dd+1);
+ int nl = content.toUpperCase().indexOf("\n");
+ if(nl < 0)
+ return "";
+ content = content.substring(0, nl);
+
+ while(content.toUpperCase().indexOf("=0A") != -1)
+ {
+ body += content.substring(0, content.toUpperCase().indexOf("=0A"))
+ " ";
+ content = content.substring(content.toUpperCase().indexOf("=0A")+3);
+ }
+ body += content;
+
+
+ return body;
+
+}
+
+void mousePressed() {
+ println(ping());
+
+}
+
+boolean ping() {
+
+ try {
+ Socket s = new Socket("jorgecardoso.eu", 80);
+ } catch(Exception e) {
+ return false;
+ }
+ return true;
+
+}
+
+
+

Added: trunk/MailMan/Examples/Processing/FlickrBrowser/neterror.html
==============================================================================
--- (empty file)
+++ trunk/MailMan/Examples/Processing/FlickrBrowser/neterror.html Thu Nov
6 10:24:22 2008
@@ -0,0 +1,42 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+"http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<title>Untitled Document</title>
+<style type="text/css">
+<!--
+body {
+ background-color: #000000;
+}
+body,td,th {
+ font-family: Arial, Helvetica, sans-serif, Arial Black;
+ color: #FFFFFF;
+}
+.centro {
+ border: 1px solid #FFFFFF;
+}
+.style1 {font-size: medium}
+.style2 {font-size: x-large; }
+-->
+</style>
+<script language="JavaScript" type="text/JavaScript">
+<!--
+function MM_reloadPage(init) { //reloads the window if Nav4 resized
+ if (init==true) with (navigator) {if
((appName=="Netscape")&&(parseInt(appVersion)==4)) {
+ document.MM_pgW=innerWidth; document.MM_pgH=innerHeight;
onresize=MM_reloadPage; }}
+ else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH)
location.reload();
+}
+MM_reloadPage(true);
+//-->
+</script>
+</head>
+
+<body>
+<div id="Layer1" style="position:absolute; left:415px; top:303px;
width:350px; height:151px; z-index:1" class="centro">
+ <p class="style2">Oops! </p>
+ <p class="style1">Parece que perdi a liga��o � Internet!</p>
+ <p class="style1">Vou tentar outra vez daqui a uns segundos... </p>
+</div>
+</body>
+</html>

Added: trunk/MailMan/Examples/Processing/FlickrBrowser/notSupported.html
==============================================================================
--- (empty file)
+++ trunk/MailMan/Examples/Processing/FlickrBrowser/notSupported.html Thu
Nov 6 10:24:22 2008
@@ -0,0 +1,43 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+"http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<title>Untitled Document</title>
+<style type="text/css">
+<!--
+body {
+ background-color: #000000;
+}
+body,td,th {
+ font-family: Arial, Helvetica, sans-serif, Arial Black;
+ color: #FFFFFF;
+}
+.centro {
+ border: 1px solid #FFFFFF;
+}
+.style1 {font-size: medium}
+.style2 {font-size: x-large; }
+-->
+</style>
+<script language="JavaScript" type="text/JavaScript">
+<!--
+function MM_reloadPage(init) { //reloads the window if Nav4 resized
+ if (init==true) with (navigator) {if
((appName=="Netscape")&&(parseInt(appVersion)==4)) {
+ document.MM_pgW=innerWidth; document.MM_pgH=innerHeight;
onresize=MM_reloadPage; }}
+ else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH)
location.reload();
+}
+MM_reloadPage(true);
+//-->
+</script>
+</head>
+
+<body>
+<div id="Layer1" style="position:absolute; left:415px; top:303px;
width:350px; height:151px; z-index:1" class="centro">
+ <p class="style2">Oops! </p>
+ <p class="style1">O ficheiro que enviou n&atilde;o &eacute;
suportado!</p>
+ <p class="style1">Vou tentar usar o nome do seu dispositivo para
procurar... </p>
+ <p class="style1">Aceito ficheiros de texto e notas (.txt e .vnt) </p>
+</div>
+</body>
+</html>

Added: trunk/MailMan/Examples/Processing/FlickrBrowser/start.bat
==============================================================================
--- (empty file)
+++ trunk/MailMan/Examples/Processing/FlickrBrowser/start.bat Thu Nov 6
10:24:22 2008
@@ -0,0 +1 @@
+java -cp
application.windows\lib\core.jar;application.windows\lib\FlickrBrowser.jar;application.windows\lib\oscP5.jar
processing.core.PApplet FlickrBrowser >> flickrBrowser.log
Reply all
Reply to author
Forward
0 new messages