diff --git a/grendel/sources/grendel/URL/StHyperlinkListener.java b/grendel/sources/grendel/URL/StHyperlinkListener.java new file mode 100644 index 000000000000..32aabb9e587c --- /dev/null +++ b/grendel/sources/grendel/URL/StHyperlinkListener.java @@ -0,0 +1,169 @@ +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * StHyperlinkListener.java + * + * Created on 09 August 2005, 15:29 + * + * ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Grendel mail/news client. + * + * The Initial Developer of the Original Code is + * Kieran Maclean. + * Portions created by the Initial Developer are Copyright (C) 2005 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +package grendel.URL; +import grendel.URL.attachment.AttachmentRequested; +import grendel.URL.attachment.AttachmentURLConnection; +import grendel.messaging.ExceptionNotice; +import grendel.messaging.Notice; +import grendel.messaging.NoticeBoard; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.Hashtable; + +import javax.swing.JTextPane; +import javax.swing.event.HyperlinkEvent; +import javax.swing.event.HyperlinkListener; + + +/** + * + * @author hash9 + */ +public class StHyperlinkListener implements HyperlinkListener { + + /** Creates a new instance of StHyperlinkListener */ + public StHyperlinkListener() { + addMessageEventListener(new AttachmentRequested()); + addMessageEventListener(new URLRequested()); + } + + /** + * Called when a hypertext link is updated. + * + * @param e the event responsible for the update + */ + public void hyperlinkUpdate(HyperlinkEvent e) { + try { + if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) { + // System.out.println("Request for url: "+e.getURL()); + // System.out.println("Request for ref: "+e.getDescription()); + + if (e.getURL()!=null) { + request(e.getURL()); + /*try { + + new URLRequested(e.getURL()).openInBrowser(); + } catch (IOException ioe) { + ioe.printStackTrace(); + } catch (Exception ex) { + ex.printStackTrace(); + }*/ + } else { + class NoticeMessage extends Notice { + private String s; + NoticeMessage(String s) { + this.s = s; + } + public String toString() { + return s; + } + } + NoticeBoard.publish(new NoticeMessage("Unsupported URL: "+ e.getDescription())); + } + } + } catch (Exception e1) { + } + } + + /** + * Add a listener for url requested events. + */ + public static void addMessageEventListener(URLRequestedListener l) { + listeners.put(l,"*"); + } + + /** + * Add a listener for url requested events for a perticular protocal. + */ + public static void addMessageEventListener(String protocal, URLRequestedListener l) throws MalformedURLException { + URL url = new URL(protocal,"",""); + listeners.put(l,url.getProtocol()); + } + /** + * Remove a listener for url requested events. + */ + public static void removeMessageEventListener(URLRequestedListener l) { + listeners.remove(l); + } + + private static Hashtable listeners = new Hashtable(); + + /** + * Request that a URL be processed. + */ + public static void request(URL url) { + URLRequestedEvent e =new URLRequestedEvent(url); + for (URLRequestedListener l : listeners.keySet()) { + String protocal = listeners.get(l); + if (protocal.equalsIgnoreCase("*")) { + new URLRequestedHandler(l,e); + } else if (protocal.equalsIgnoreCase(e.getUrl().getProtocol())) { + new URLRequestedHandler(l,e); + } + } + } + + private static final class URLRequestedHandler extends Thread { + private URLRequestedEvent e; + private URLRequestedListener l; + + /** Creates a new instance of URLRequestedHandler */ + public URLRequestedHandler(URLRequestedListener l, URLRequestedEvent e) { + this.e = e; + this.l = l; + this.start(); + } + + public void run() { + try{ + l.URLRequested(e); + } catch (Exception e) { + NoticeBoard.publish(new ExceptionNotice(e)); + } + } + } +} + diff --git a/grendel/sources/grendel/URL/URLRequested.java b/grendel/sources/grendel/URL/URLRequested.java new file mode 100644 index 000000000000..bb90902034a7 --- /dev/null +++ b/grendel/sources/grendel/URL/URLRequested.java @@ -0,0 +1,88 @@ +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * URLExtWrapper.java + * + * Created on 08 August 2005, 18:13 + * + * ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Grendel mail/news client. + * + * The Initial Developer of the Original Code is + * Kieran Maclean. + * Portions created by the Initial Developer are Copyright (C) 2005 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ +package grendel.URL; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStreamReader; + +import java.net.URL; +import java.net.URLConnection; +import java.net.URLStreamHandler; + + +/** + * + * @author hash9 + */ +public class URLRequested implements URLRequestedListener{ + public void URLRequested(URLRequestedEvent e) { + if (! e.isConsumed()) { + // Wait incase some where else consumes the event + synchronized(this) { + try { + this.wait(100); + } catch (InterruptedException ex) { + ex.printStackTrace(); + } + } + if (! e.isConsumed()) { + try { + Process p=Runtime.getRuntime().exec( + "C:\\Program Files\\Mozilla Firefox\\firefox.exe "+ + e.getUrl().toExternalForm()); + BufferedInputStream bis=new BufferedInputStream(p.getErrorStream()); + int i=0; + + while (i!=-1) { + i=bis.read(); + System.err.write(i); + } + } catch (IOException ioe) { + ioe.printStackTrace(); + } + } + } + } +} + + diff --git a/grendel/sources/grendel/URL/URLRequestedEvent.java b/grendel/sources/grendel/URL/URLRequestedEvent.java new file mode 100644 index 000000000000..e850ef423769 --- /dev/null +++ b/grendel/sources/grendel/URL/URLRequestedEvent.java @@ -0,0 +1,70 @@ +/* + * URLRequestedEvent.java + * + * Created on 07 September 2005, 20:52 + * + * ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Grendel mail/news client. + * + * The Initial Developer of the Original Code is + * Kieran Maclean. + * Portions created by the Initial Developer are Copyright (C) 2005 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +package grendel.URL; + +import java.net.URL; + +/** + * + * @author hash9 + */ +public class URLRequestedEvent { + private URL url; + private boolean consumed = false; + + /** Creates a new instance of URLRequestedEvent */ + public URLRequestedEvent(URL url) { + this.url = url; + } + + public URL getUrl() { + return url; + } + + public void consume() { + consumed=true; + } + + public boolean isConsumed() { + return consumed; + } +} diff --git a/grendel/sources/grendel/URL/URLRequestedListener.java b/grendel/sources/grendel/URL/URLRequestedListener.java new file mode 100644 index 000000000000..fe852f15ed79 --- /dev/null +++ b/grendel/sources/grendel/URL/URLRequestedListener.java @@ -0,0 +1,55 @@ +/* + * URLRequestedEvent.java + * + * Created on 07 September 2005, 20:52 + * + * ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Grendel mail/news client. + * + * The Initial Developer of the Original Code is + * Kieran Maclean. + * Portions created by the Initial Developer are Copyright (C) 2005 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +package grendel.URL; + +/** + * + * @author hash9 + */ +public interface URLRequestedListener { + + /** + * Called when a URL is reqested to be processed. + */ + public void URLRequested(URLRequestedEvent e); + +} diff --git a/grendel/sources/grendel/URL/attachment/AttachmentRequested.java b/grendel/sources/grendel/URL/attachment/AttachmentRequested.java new file mode 100644 index 000000000000..c03611892360 --- /dev/null +++ b/grendel/sources/grendel/URL/attachment/AttachmentRequested.java @@ -0,0 +1,53 @@ +/* + * AttachmentRequested.java + * + * Created on 07 September 2005, 21:46 + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package grendel.URL.attachment; + +import grendel.URL.URLRequestedEvent; +import grendel.URL.URLRequestedListener; +import grendel.messaging.ExceptionNotice; +import grendel.messaging.NoticeBoard; +import java.io.IOException; + +/** + * + * @author hash9 + */ +public class AttachmentRequested implements URLRequestedListener { + + /** Creates a new instance of AttachmentRequested */ + public AttachmentRequested() { + } + + public void URLRequested(URLRequestedEvent e) { + if (!e.isConsumed()) { + if (e.getUrl().getProtocol().equalsIgnoreCase("attachment")) { + if (! e.isConsumed()) { + // Wait incase some where else consumes the event + synchronized(this) { + try { + this.wait(50); + } catch (InterruptedException ex) { + ex.printStackTrace(); + } + } + if (! e.isConsumed()) { + try { + AttachmentURLConnection uca = (AttachmentURLConnection) e.getUrl().openConnection(); + e.consume(); + uca.save(); + } catch (IOException ioe) { + NoticeBoard.publish(new ExceptionNotice(ioe)); + } + } + } + } + } + } +} diff --git a/grendel/sources/grendel/renderer/URL/attachment/AttachmentURLConnection.java b/grendel/sources/grendel/URL/attachment/AttachmentURLConnection.java old mode 100755 new mode 100644 similarity index 99% rename from grendel/sources/grendel/renderer/URL/attachment/AttachmentURLConnection.java rename to grendel/sources/grendel/URL/attachment/AttachmentURLConnection.java index 6095e94d45b5..b795ec3f3c84 --- a/grendel/sources/grendel/renderer/URL/attachment/AttachmentURLConnection.java +++ b/grendel/sources/grendel/URL/attachment/AttachmentURLConnection.java @@ -38,7 +38,7 @@ * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ -package grendel.renderer.URL.attachment; +package grendel.URL.attachment; import grendel.renderer.Attachment; diff --git a/grendel/sources/grendel/renderer/URL/attachment/Handler.java b/grendel/sources/grendel/URL/attachment/Handler.java old mode 100755 new mode 100644 similarity index 98% rename from grendel/sources/grendel/renderer/URL/attachment/Handler.java rename to grendel/sources/grendel/URL/attachment/Handler.java index 8f450fb7c18d..8eb759b53331 --- a/grendel/sources/grendel/renderer/URL/attachment/Handler.java +++ b/grendel/sources/grendel/URL/attachment/Handler.java @@ -39,7 +39,7 @@ * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ -package grendel.renderer.URL.attachment; +package grendel.URL.attachment; import grendel.renderer.*; diff --git a/grendel/sources/grendel/renderer/URL/URLExtWrapper.java b/grendel/sources/grendel/URL/mailto/Handler.java old mode 100755 new mode 100644 similarity index 71% rename from grendel/sources/grendel/renderer/URL/URLExtWrapper.java rename to grendel/sources/grendel/URL/mailto/Handler.java index a042a7fc9530..eb8d0444e55f --- a/grendel/sources/grendel/renderer/URL/URLExtWrapper.java +++ b/grendel/sources/grendel/URL/mailto/Handler.java @@ -1,8 +1,8 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * URLExtWrapper.java +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * - * Created on 08 August 2005, 18:13 + * Handler.java + * + * Created on 08 August 2005, 17:15 * * ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 @@ -39,45 +39,27 @@ * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ -package grendel.renderer.URL; +package grendel.URL.mailto; + +import grendel.renderer.*; -import java.io.BufferedInputStream; import java.io.IOException; -import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.net.URLStreamHandler; +import java.util.WeakHashMap; + /** * * @author hash9 */ -public class URLExtWrapper +public class Handler extends URLStreamHandler { - private URL url; - - /** Creates a new instance of URLExtWrapper */ - public URLExtWrapper(URL url) + protected URLConnection openConnection(URL u) throws IOException { - this.url=url; - } - - public void openInBrowser() - { - try { - Process p=Runtime.getRuntime().exec("C:\\Program Files\\Mozilla Firefox\\firefox.exe "+ - url.toExternalForm()); - BufferedInputStream bis=new BufferedInputStream(p.getErrorStream()); - int i=0; - - while (i!=-1) { - i=bis.read(); - System.err.write(i); - } - } catch (IOException ioe) { - ioe.printStackTrace(); - } + return new MailToURLConnection(u); } } diff --git a/grendel/sources/grendel/URL/mailto/MailToURLConnection.java b/grendel/sources/grendel/URL/mailto/MailToURLConnection.java new file mode 100644 index 000000000000..ac9eef413905 --- /dev/null +++ b/grendel/sources/grendel/URL/mailto/MailToURLConnection.java @@ -0,0 +1,216 @@ +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* MailToURLConnection.java + * + * Created on 09 August 2005, 11:21 + * + * ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Grendel mail/news client. + * + * The Initial Developer of the Original Code is + * Kieran Maclean. + * Portions created by the Initial Developer are Copyright (C) 2005 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ +package grendel.URL.mailto; +import java.io.FilePermission; +import java.io.IOException; + +import java.net.URL; +import java.net.URLConnection; + +import java.security.Permission; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; + + +/** + * + * @author hash9 + */ +public class MailToURLConnection extends URLConnection { + + Map> requestProperties = new HashMap>(); + + + /** + * Constructs a URL connection to the specified URL. A connection to + * the object referenced by the URL is not created. + * + * @param url the specified URL. + */ + protected MailToURLConnection(URL url) { + super(url); + } + + /** + * + * Returns a permission object representing the permission + * necessary to make the connection represented by this + * object. This method returns null if no permission is + * required to make the connection. By default, this method + * returns java.security.AllPermission. Subclasses + * should override this method and return the permission + * that best represents the permission required to make a + * a connection to the URL. For example, a URLConnection + * representing a file: URL would return a + * java.io.FilePermission object. + * + *

The permission returned may dependent upon the state of the + * connection. For example, the permission before connecting may be + * different from that after connecting. For example, an HTTP + * sever, say foo.com, may redirect the connection to a different + * host, say bar.com. Before connecting the permission returned by + * the connection will represent the permission needed to connect + * to foo.com, while the permission returned after connecting will + * be to bar.com. + * + *

Permissions are generally used for two purposes: to protect + * caches of objects obtained through URLConnections, and to check + * the right of a recipient to learn about a particular URL. In + * the first case, the permission should be obtained + * after the object has been obtained. For example, in an + * HTTP connection, this will represent the permission to connect + * to the host from which the data was ultimately fetched. In the + * second case, the permission should be obtained and tested + * before connecting. + * + * + * @return the permission object representing the permission + * necessary to make the connection represented by this + * URLConnection. + * @exception IOException if the computation of the permission + * requires network or file I/O and an exception occurs while + * computing it. + */ + public Permission getPermission() throws IOException { + return new FilePermission(toString(), "write"); + } + + /** + * Opens a communications link to the resource referenced by this + * URL, if such a connection has not already been established. + *

+ * If the connect method is called when the connection + * has already been opened (indicated by the connected + * field having the value true), the call is ignored. + *

+ * URLConnection objects go through two phases: first they are + * created, then they are connected. After being created, and + * before being connected, various options can be specified + * (e.g., doInput and UseCaches). After connecting, it is an + * error to try to set them. Operations that depend on being + * connected, like getContentLength, will implicitly perform the + * connection, if necessary. + * + * + * @exception IOException if an I/O error occurs while opening the + * connection. + * @see java.net.URLConnection#connected + * @see #getConnectTimeout() + * @see #setConnectTimeout(int) + * @throws SocketTimeoutException if the timeout expires before + * the connection can be established + */ + public void connect() throws IOException { + connected = true; + // Open the compose window. + } + + /** + * Returns the value of the named general request property for this + * connection. + * + * + * @param key the keyword by which the request is known (e.g., "accept"). + * @return the value of the named general request property for this + * connection. If key is null, then null is returned. + * @see #setRequestProperty(java.lang.String, java.lang.String) + * @throws IllegalStateException if already connected + */ + public String getRequestProperty(String key) { + if (connected) + throw new IllegalStateException("Already connected"); + List l = requestProperties.get(key); + if ((l== null)||l.size()==0) { + return null; + } + return l.get(l.size()-1); + } + + /** + * Returns an unmodifiable Map of general request + * properties for this connection. The Map keys + * are Strings that represent the request-header + * field names. Each Map value is a unmodifiable List + * of Strings that represents the corresponding + * field values. + * + * + * @return a Map of the general request properties for this connection. + * @since 1.4 + * @throws IllegalStateException if already connected + */ + public java.util.Map> getRequestProperties() { + if (connected) + throw new IllegalStateException("Already connected"); + return requestProperties; + } + + /** + * Sets the general request property. If a property with the key already + * exists, overwrite its value with the new value. + * + *

NOTE: HTTP requires all request properties which can + * legally have multiple instances with the same key + * to use a comma-seperated list syntax which enables multiple + * properties to be appended into a single property. + * + * + * @param key the keyword by which the request is known + * (e.g., "accept"). + * @param value the value associated with it. + * @see #getRequestProperty(java.lang.String) + * @throws IllegalStateException if already connected + * @throws NullPointerException if key is null + */ + public void setRequestProperty(String key, String value) { + if (connected) + throw new IllegalStateException("Already connected"); + List l = requestProperties.get(key); + if (l==null) { + l = new ArrayList(); + requestProperties.put(key,l); + } + l.add(value); + } +}