Blog do projektu Open Source JavaHotel

sobota, 29 stycznia 2011

GWT, mail and RichText editor

I added mailing to my open source application ( Test demo ). The test is created inside Google App Engine environment.
For mailing I'm using standard JavaMail API. Look at the code. Because the Google App Engine provides Mail service there is a branch in the code:

String protocol = props.getProperty(PROTOCOL);
                if (protocol.equalsIgnoreCase(GAEMAIL)) {
                        Transport.send(msg);
                } else {

                        Transport transport = session.getTransport(props
                                        .getProperty(PROTOCOL)); .... }

If mail.transport.protocol property value is equal to "gae" then message is send directly. This way it is possible to keep consistent API for GAE and non-GAE mailing.

I also incorporated GWT RichTextArea widget - here for displaying and modifying mail content. As a RichText Toolbar (GWT does not provide it as a standard) I simply sucked in a toolbar from GWT samples. It required some modifications and needed also localization. Firstly I tried to use http://code.google.com/p/richtexttoolbar/ but I wasn't happy with it's look and feel.

For the time being attachment are not handled - may be I will add it in the future.

It is possible to have more than one mail account. For the test purpose mail account properties are looked for in resource directory. To my astonishment resource directory search works in the Google App Engine environment.
This code return path to the directory:


  public static File getResourceDir(Class cl) {
                String me = cl.getName().replace(".", "/") + ".class";
                URL u = cl.getClassLoader().getResource(me);
                String p = u.getFile();
                File f = new File(p);
                String s = f.getParent();
                return new File(s + File.separatorChar + "resources");
        }


And regular java code is looking for .properties file in this directory.

File f = FileUtil.getResourceDir(this.getClass());
FileFilter filter = new FileFilter() {
  public boolean accept(File pathname) {
     if (pathname.isDirectory()) {
     return false;
    }
    return pathname.getName().endsWith(".properties");
  }
};
File[] dir = f.listFiles(filter); 

..............

Brak komentarzy:

Prześlij komentarz