Clean and usable URLs in Stripes

Cool URIs don’t change wrote Tim Berners-Lee more than a decade ago, URLs should be clean, usable and persistent. However, the biggest percentage of URLs around the web still are not clean and usable and even less persistent. There are lots of reasons that URLs are not persistent and most of the times it is not in the hands of the developer or webmasters, under certain circumstances some domains may not continue to be alive or they may change hands, anyway there isn’t much a framework can do about that. But for the URLs to be clean and usable is totally in the hands of the developers and webmasters. Unfortunately most web frameworks makes things even worse by not providing the mechanism to handle URLs or by making it really difficult to change the default behavior.

Stripes is not one of those frameworks and it really makes it easy to create clean URLs and provides a very flexible mechanism for handling them.

The simplest way to do it is using the @UrlBinding annotation. Let’s assume we have the following action bean:


package com.project.action;

import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;

/**
 * @author omer haderi
 * @version 1.0
 */
public class SimpleMathActionBean implements ActionBean {
	private static final String view = "/WEB-INF/jsp/index.jsp";

	private ActionBeanContext ctx;

	private double number;

	public ActionBeanContext getContext() {
		return ctx;
	}

	public void setContext(ActionBeanContext ctx) {
		this.ctx = ctx;
	}

	@DefaultHandler
	public Resolution view() {
		return new ForwardResolution(view);
	}

	public Resolution sqrt() {
		number = Math.sqrt(getNumber());
		return new ForwardResolution(view);
	}

	public double getNumber() {
		return number;
	}

	public void setNumber(double number) {
		this.number = number;
	}
}

The URL for this action bean to calculate the square root (assuming the default behavior) will be:
http://www.domain.com/SimpleMath.action?sqrt=&number=10

To simplify this we just need to mark the bean with the following annotation:
@UrlBinding(“/public/simple_math”)
after this the URL will be:
http://www.domain.com/public/simple_math?sqrt=&number=10

Of course the point is to remove the question mark, the ampersand and the equals sign. In the previews URL the [sqrt] is an event of the action bean as you can see from the action bean class. There is a special notation to identify the event in the UrlBinding which is {$event}, so we need to modify the annotation as follows:
@UrlBinding(“/public/simple_math/{$event}”)
after this the URL will be:
http://www.domain.com/public/simple_math/sqrt=&number=10

Let’s move on and remove the rest of symbols. In our URL the [number] is a parameter and just like the events it can be embedded in the UrlBinding as follows:
@UrlBinding(“/public/simple_math/{$event}/{number}”) and it can even have a default value
@UrlBinding(“/public/simple_math/{$event}/{number=5}”)
after this the URL will be:
http://www.domain.com/public/simple_math/sqrt/10/

That’s it just one annotation and the URL is simple, more readable and makes more sense.

This is how will the action bean class look like after marking it with the annotation that we just constructed:


/**
 * @author omer haderi
 * @version 1.0
 */
@UrlBinding("/public/simple_math/{$event}/{number=5}")
public class SimpleMathActionBean implements ActionBean {
...
}

Here are the two URLs:
before: http://www.domain.com/public/simple_math?sqrt=&number=10
after   : http://www.domain.com/public/simple_math/sqrt/10/
as you can see the later is much better.

You may be wondering what’s that /public over there!?
That’s the url-mapping in the servlet-mapping of the DispatcherServlet in the web.xml which can be anything that makes sence for your project:

<servlet-mapping>
	<servlet-name>DispatcherServlet</servlet-name>
	<url-pattern>/public/*</url-pattern>
</servlet-mapping>

When using UrlBinding annotation only the URL of those action beans that are marked by the annotation will change, the rest of the actions will still have the default URL binding as explained in the “URL Binding in Stripes“.

To change the default behavior to all Action Beans we would need to create a subclass of NameBaseActionResolver and override its methods:


package com.project.extensions;
/**
 * @author omer haderi
 * @version 1.0
 */
public class CustomActionResolver extends NameBasedActionResolver {
        // this is the url-pattern from the DispatcherServlet servlet-mapping in the web.xml
	private static final String URL_PATTERN = "/public";

	@Override
	protected String getBindingSuffix() {
		return "";
	}

	@Override
	protected String getUrlBinding(String actionBeanName) {
		String result = super.getUrlBinding(actionBeanName);
		result = separeteCamelCaseWithUnderscore(result).toLowerCase();

		return URL_PATTERN + result;
	}

	private static String separeteCamelCaseWithUnderscore(String s) {
		String pattern = "(?<=[A-Z])(?=[A-Z][a-z])|(?<=[^A-Z])(?=[A-Z])|(?<=[A-Za-z])(?=[^A-Za-z])";
		return s.replaceAll(pattern, "_");
	}
}

You need to add the extension package in the filter parameters in the web.xml see “URL Binding in Stripes” for more information.

From now on all the action beans will have this as default URL binding.

Advertisements

Type safe JPA queries

Quite often I find myself refactoring parts of my applications for different reasons and I am sure most developers do the same thing. Refactoring a java application is relatively easy since java is statically typed language and compiler will catch all type mismatches, moreover, modern IDEs like eclipse, intelij and netBeans provide all the necessary tools to accomplish this task as easily as possible. However, there is one part of the application that java compiler and IDE tools cannot do much. This part is the JPA queries which are String literals and there is no way for the compiler to catch any changes from the model. It seems that things will change with JPA 2.

JPA 2 introduces the Metamodel API (proposed by Gavin King) which is useful regardless of type safe queries. The metamodel exposes a set of interfaces which can be used to write  type safe queries with the new API. Other advantages of metamodel API besides the type safe queries are that it protects from SQL injection, auto-complete support through IDE, refactoring support.

Here is an example of how cool feature this is. Consider the following entities:


package org.chemistry.domain;

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class Substance {
	@Id
	private Long id;

	private String name;
	private String symbol;
	private double atomicWeight;
	private double grams;

	// getters and setters
	// ...
}

package org.chemistry.domain; import java.util.Set; import javax.persistence.Basic; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.OneToMany; @Entity public class Mixture { @Id private Long id; @Basic private String name; @OneToMany private Set<Substance> substances; // getters & setters // ... }

The metamodel classes for the entities will look like the following:


package org.chemistry.domain;

import javax.persistence.metamodel.*;

@TypesafeMetamodel
public class Substance_ {
	public static volatile Attribute<Substance, Long> id;
	public static volatile Attribute<Substance, String> name;
	public static volatile Attribute<Substance, String> symbol;
	public static volatile Attribute<Substance, Double> atomicWeight;
	public static volatile Attribute<Substance, Double> grams;
}

package org.chemistry.domain; import javax.persistence.metamodel.*; @TypesafeMetamodel public class Mixture_ { public static volatile Attribute<Mixture, Long> id; public static volatile Attribute<Mixture, String> name; public static volatile Set<Mixture, Substance> substances; }

Nothing impressive until now… the impressive part is how we can write the queries in a type safe way using the new criteria API. We can use the CriteriaQuery and the QueryBuilder to create the queries in the following way.


// get the entity manager
EntityManager em = ... ;

// JPQL
String query = "SELECT m.name FROM Mixture m JOIN m.substances s WHERE s.name = :name"
Query q = em.createQuery(query);
q.setParameter("name", "Beryllium");

// new query API
QueryBuilder qb = em.getQueryBuilder();
CriteriaQuery q = qb.create();
Root mixture = q.from(Mixture.class);
Join<Mixture, Substance> sub = mixture.join(Mixture_.substances);
q.where(qb.equals(sub.get(Substances_.name), "Beryllium")).select(mixture.get(Mixture_.name));

Now any refactoring in the Mixture or the Substance classes will immediately reflect the changes to the query. The metamodel classes are (or will be) auto generated by the time the entity class is compiled. So hopefully no more runtime exceptions because of domain model refactoring :)

This is JSR 317, here you can find all the necessary details about this cool API.

URL Binding in Stripes

The best thing about Stripes is that it follows the convention over configuration practice. One of the most convenient conventions is the automatic generation and binding of URLs to the action bean class names. During development this is very helpful since you don’t need to keep in sync a configuration file as you add or delete action beans. To generate the URLs Stripes follows certain rules, of course as with everything else in Stripes you can change the default rules if they don’t meet your needs.

First lets see the default rules and then I’ll discus  how to change them if needed.

Stripes will automatically load all your action beans at start up, but we need to tell Stripes where to start looking for action beans, we need to declare at least one root package. We can do this by specifying the ActionResolver.Packages init-param in the declaration of the StripesFilter in web.xml which is the only mandatory configuration parameter. If you keep your action beans in different packages you can add all of them separated by comma as shown in the following spinet.

<filter>
  <filter-name>StripesFilter</filter-name>
  <filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class>
  <init-param>
    <param-name>ActionResolver.Packages</param-name>
    <param-value>com.pk1.action,com.pk2.action</param-value>
  </init-param>
</filter>

Now that Stripes knows how to load the action beans lets see how the URLs are generated and bound to the action bean class names. Lets suppose we have the following action bean:


package com.action.test;

import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;

public class HelloActionBean implements ActionBean {
	private ActionBeanContext context;

    public ActionBeanContext getContext() {
        return context;
    }
    public void setContext(ActionBeanContext context) {
        this.context = context;
    }

    @DefaultHandler
    public Resolution view () {
	return new ForwardResolution("/WEB-INF/jsp/home.jsp");
    }
}

Our action bean class name is HelloActionBean and it’s located under the package com.action.test; to refere to this action in a jps we can use the following name /test/Hello.action.

As mentioned previously to generate the URLs Stripes follows certain rules.
1. It will remove the package name up to and including the the following names if present in the package [action, stripes, web, www]. That’s why we refer to the /test/Hello.action without the full package name since the package name of this bean includes the token action and is removed up to that token.
2. It will remove from the class name the following suffixes [ActionBean, Action or Bean]. That’s why we have the /test/Hello.action instead of /test/HelloActionBean.action.
3. It will convert package name and class names to paths and change all periods to forward slashes. Instead of [test.Hello.action] we have /test/Hello.action
4. It will append the .action to the end of the striped bean name.

Fast forward:
rule 1: from com.action.test.HelloActionBean we get test.HelloActionBean
rule 2: from test.HelloActionBean we get test.Hello
rule 3: from test.Hello we get /test/Hello
rule 4: from /test/Hello we get /test/Hello.action

Lets see some examples of how this works:
com.pk1.action.HelloActionBean –> /Hello.action
com.pk1.web.HelloAction –> /Hello.action
com.pk1.www.HelloBean –> /Hello.action
com.pk1.stripes.HelloActionBean –> Hello.action
com.pk2.module.HelloActionBean –> /com/pk2/module/Hello.action

Some controversial examples:
com.pk1.web.MyActionBeanX  –> /MyActionBeanX.action (the ActionBean is not removed since it is not at the end)
com.pk1.www.ActionBean –> /.action (the ActionBean is removed based on the rule number 2)
http://www.web.action.stripes.HelloBean –> /Hello.action (all package tokens are removed since they are in the list of rule number 1)

Now that we know the rules for generating the URLs, lets see how we can change them to meet our needs. This process is quite easy.
The class that implements the rules for URL binding is the NameBasedActionResolver. To change the rules for URL binding you just need to extend this class and override the getBasePackages() and/or getBindingSuffix(), (if you change the suffix do not forget to change url-pattern of the servlet mapping in the web.xml). You can change completely the behavior of URL binding by overriding the getUrlBinding(String). Your custom class for the URL bind rules should be registered as a Stripes extension.

Here is an example of how to change the suffix from [action] to [go]. As I said this is quite easy, it requires two steps:

1. Change the servlet mapping in web.xml


<servlet-mapping>
	<servlet-name>DispatcherServlet</servlet-name>
	<url-pattern>*.go</url-pattern>
</servlet-mapping>

2. Extend the NameBasedActionResolver and override the getBindingSuffix()


package com.ext;

import net.sourceforge.stripes.controller.NameBasedActionResolver;

public class CustomActionResolver extends NameBasedActionResolver {
	@Override
	protected String getBindingSuffix() {
		return ".go";
	}
}

Note that this is an extension and extensions are loaded automatically by Stripes but as with action beans we need to tell Stripes where to look for. To configure extensions we need to add another init-param to the StripesFilter as we did for the action beans. The parameter name for the extensions is [Extension.Packages].
Here is an example:


<init-param>
	<param-name>Extension.Packages</param-name>
	<param-value>com.ext</param-value>
</init-param>

Extending the NameBasedActionResolver we can tweak the URLs in any way we want and as you can see it is quite easy, an interesting tweak would be to implement clean URLs but that will be another post.

The Stripes framework

Choosing a java web framework is somehow a complex process, not because they are difficult to evaluate but because there are so many of them (in fact it seems that there are more java frameworks than java developers :) but having many frameworks is a good thing. It means that there is a lot of competition and the competition seems to be healthy since most of the frameworks are open source, so competition is based on quality and features instead of marketing and lobbing.

Different people have different criteria on selecting a framework and probably different needs, so I will list my criteria an the reasoning behind them for choosing Stripes.
(Disclaimer: this expresses only my views on what I expect from a framework, I don’t think there are good or bad frameworks, from my point of view there are only convenient frameworks – just trying to avoid flame war here, although flame wars entertains me a lot!).

I would like to start with what I consider the most annoying thing when working with a Java framework which is not other than XML configuration files. Having worked with JSF and Struts where you need to configure all your managed-beans/action-beans and pretty much everything else into an xml configuration file, which during development becomes a mess to keep it in sync, I enjoy that Stripes removes all this configuration hassle with autoloading feature. The only xml configuration file that you need is the web.xml but that is required by the Servlet specification. Configuration by exception (a.k.a convention over configuration) is the way to go, developers should focus on business solutions and not in framework configuration details that will just disturb the flow of thinking. Hopefully other framework will follow – or maybe some already does.

Testing is the most important part of development and therefore frameworks should come with a build-in support for testing to make this process easy. So Stripes comes with a set of mock objects that help developers to easily write unit tests.

Easy extension and customization. Stripes is designed in modular form it is quite easy to add a customization plugin to change the behavior of any part of the framework, because of this modular design the extensibility of Stripes is trivial. Actually This is one of the areas that the framework really make the difference.

I don’t think that there’s a need to explain why internationalization of web application is important, all frameworks need to have a built-in support for i18n. Stripes tags comes with a default bundle lookup strategy so that i18n is just a mutter of adding key/value pairs in the resource bundle.

Never trust the user input, therefore a strong and flexible validation mechanism is needed. Stripes provides a powerful validation mechanism which is based on annotations (remember there is no XML configuration).

When working with request parameters the most annoying process is converting Strings to objects and vise versa, the Stripes support for this process is just amazing. But it is not just conversion there is also support for formating an object to string and that’s as easy as the conversion process.

Stripes comes with a built in support for layouts, with three tags you can achieve pretty much everything. If the built in support for templating is not enough you can use freemarker.

Since we are talking about web framework and web applications it would be a pity to not take advantage of Ajax. Any Ajax framework can be used due to Stripes simple and transparent request/response nature.

These are some of the features that I like to see in a framework and surely you can find this features in most frameworks and probably more but the difference is that with Stripes is easy and development is fun again as the book of Frederic Daoud suggests and proves it.

If you want to learn Stripes I suggest the “Stripes … and Java web development is fun again” from The Pragmatic Programmers, in fact this is the only book about Stripes but even if there were more books I am totally sure that I would suggest this book again, it is very well written and it covers everything about Stripes.

The following is a quick list of Stripes features, which I will try to explain and give an example in future post for each one of them and link them back to this page:

URL Binding
Built in Validation
Custom Validation
Type Conversion
Formatting
Layouts
Using Freemarker
Localization
Exception Handling
Interceptors
URL Customization
Ajax Integration
Framework Extension
Framework Customization
Testing
Dependency Injection (Giuce/Spring)
JPA Integration
Security and Encryption
Cache-ing

The examples will be deployed on google app engine.

P.S: Now that the jsr 330 is approved maybe the next version of Stripes will come with build in Dependency Injection.

If you would like to start playing with Stripes and google app engine have a look at the following links:
https://110j.wordpress.com/2009/09/19/getting-started-with-stripes-google-app-engine/
https://110j.wordpress.com/2009/09/20/redoing-guestbook-example-with-stripes/

Stripes resources:
Stripes Home Page
Stripes … and Java development is fun again

Redoing Guestbook example with Stripes

Google has created an example on how to use google app engine with java. In this example they demonstrate the basic usage of Servlet API and JDO, it’s a simple example that stores, retrieves and renders entities in google app engine.
After the first tutorial on how to deploy Stripes in google app engine I decided to re-write this example using the Stripes framework of course.

Download the source code!

Steps:

1. Create a project and name it Guestbook

2. Follow the Getting started with Stripes and google app engine to configure Stripes

3. Add the JSTL jars (standard.jar and jstl.jar) in the lib directory

4. Create an ActionBean that will handle the greeting requests


package com.guestbook.action;

import java.util.Date;
import java.util.List;

import javax.jdo.PersistenceManager;

import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.guestbook.manager.PMF;
import com.guestbook.model.Greeting;

/**
 * @author 110j
 */
public class GreetingActionBean implements ActionBean {
	private static final String VIEW = "/guestbook.jsp";
	private ActionBeanContext ctx;
	private UserService userService = UserServiceFactory.getUserService();
	private Greeting greeting;

	@DefaultHandler
	public Resolution welcome() {
		return new ForwardResolution(VIEW);
	}

	public Resolution addGreeting() {
		if (greeting != null) {
			greeting.setAuthor(getUser());
			greeting.setDate(new Date());

			PersistenceManager pm = PMF.get().getPersistenceManager();
	        try {
	            pm.makePersistent(greeting);
	        } finally {
	            pm.close();
	        }
		}
		return new ForwardResolution(VIEW);
	}

	public Resolution signin() {
		ForwardResolution fd = new ForwardResolution(VIEW);
		if (!userService.isUserLoggedIn())
			fd = new ForwardResolution(userService.createLoginURL("/Greeting.action"));
		return fd;
	}

	public Resolution signout() {
		ForwardResolution ForwardResolution ">fd = new ForwardResolution(VIEW);
		if (userService.isUserLoggedIn())
			fd = new ForwardResolution(userService.createLogoutURL("/Greeting.action"));
		return fd;
	}

	@SuppressWarnings("unchecked")
	public List getGreetings() {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		String query = "select from " + Greeting.class.getName() + " order by date desc range 0,5";
	    return (List) pm.newQuery(query).execute();
	}

	public Greeting getGreeting() {
		return greeting;
	}

	public void setGreeting(Greeting greeting) {
		this.greeting = greeting;
	}

	public User getUser() {
		return userService.getCurrentUser();
	}

	public ActionBeanContext getContext() {
		return this.ctx;
	}

	public void setContext(ActionBeanContext ctx) {
		this.ctx = ctx;
	}
}

5. Create the model class called Greeting (as described in the google example, no changes here!)


package com.guestbook.model;

import java.util.Date;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import com.google.appengine.api.users.User;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Greeting {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long id;

    @Persistent
    private User author;

    @Persistent
    private String content;

    @Persistent
    private Date date;

    public Greeting() {}

    public Greeting(User author, String content, Date date) {
        this.author = author;
        this.content = content;
        this.date = date;
    }

    public Long getId() {
        return id;
    }

    public User getAuthor() {
        return author;
    }

    public String getContent() {
        return content;
    }

    public Date getDate() {
        return date;
    }

    public void setAuthor(User author) {
        this.author = author;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public void setDate(Date date) {
        this.date = date;
    }
}

6. Create the utility class that will instantiate the EntityManager (no changes here also!)

package com.guestbook.manager;
import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManagerFactory;

public final class PMF {
    private static final PersistenceManagerFactory pmfInstance =
        JDOHelper.getPersistenceManagerFactory("transactions-optional");

    private PMF() {}

    public static PersistenceManagerFactory get() {
        return pmfInstance;
    }
}

7. Modify the guestbook.jsp, there are a lot of changes here since in their example google uses scriptlets, I have replaced the scriptlets with jstl tags and Stripes tags, all the logic has moved to the ActionBean.

8. Modify the welcome file list in the web.xml and set as welcome file the Greeting.action

Download the source code!

Getting started with Stripes & Google App Engine

This is a basic example of using Stripes Framework with the cloud infrastructure of Google. I am using Stripes in one of my projects that I am thinking to move it to google app engine so I decided to experiment before the migration. More posts will follow in this topic as I progress with it. The first objective is to create the basic project structure, configure and deploy, well… a hello world web application. This is a trivial application but there are some limitations using google app engine so trying to use the framework as is will fail with some non-sense stack traces.

The following is a list of things that we will be need to complete this application:
1. Stripes Framework (home page: http://www.stripesframework.org/display/stripes/Home )
2. Google app engine sdk – if you use eclipse and google plugin the sdk is included in the plugin.
3. Eclipse (you can use whatever IDE or environment you like, it’s not mandatory to use eclipse, it’s just easier).

Note: For information on how to install the google plugin visit http://code.google.com/appengine/docs/java/tools/eclipse.html

I assume you are familiar with java web frameworks and that you will use eclipse with the google plugin.

The first step is to create a project in the eclipse IDE:

Give a name to the project and an initial package name. For the moment we do not need GWT so just deselect it.

After pressing finish we have the following project structure.

Before continuing copy the Stripes jars in the the lib directory under hello_project/web/WEB_INF/lib and add them to the project’s build path by selecting them, right click-> Build Path -> Add to Build Path. Also copy and paste the StripesResources.properties in the directory “src” (not in a package).

By default the google plugin will generate a servlet for us, under the package name that we entered in the previews step. It will also generate the following configuration files:
Servlet spec requirement:
1. web.xml (this is the well known deployment descriptor required by the servlet specification)

Google App engine specific (we will not use them for this application):
1. appengine-web.xml
2. jdoconfig.xml

Logging property files:
1. log4j.properties
2. logging.properties

For the purpose of this trivial application we will only need to edit the web.xml (a.k.a Deployment Descriptor so from know on I will call it DD).
By default the plugin registers the generated servlet in the DD, so open the DD and delete the servlet and servlet-mapping it’s not needed.

The following is the generated DD that need to be edited:

The following is the new and final DD containing the Stripes filter and dispatcher servlet:

Note that the web-app tag version has changed from 2.5 to 2.4 there are some jsp exceptions with the 2.5.

The Stripes filter includes two initial parameters the ActionResolver.Packages which tells Stripes where to find the ActionBeans (more on this in next post or in Stripes documentation) and the MultipartWrapperFactory.Class, a factory class used to upload files, but uploading files is not supported by google app engine and the Stripes filter will fail to initialize. Therefore we need to disable this by providing an empty configuration.

The first step to disable file uploading is to add MultipartWrapperFactory.Class initial parameter to the Stripes filter as shown in the DD and the second step is to create the appropriate class. So create a package in the project (I created the com.helloworld.exclude but you can create anything that make sense for your project) and add the following class:


import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

import net.sourceforge.stripes.config.Configuration;
import net.sourceforge.stripes.controller.FileUploadLimitExceededException;
import net.sourceforge.stripes.controller.multipart.MultipartWrapper;
import net.sourceforge.stripes.config.ConfigurableComponent;
import net.sourceforge.stripes.controller.multipart.MultipartWrapperFactory;

/**
 * GAE does not support file uploading so we need to disable this feature from Stripes.
 *
 * @author 110j
 */
public class EmptyMultipartWapper implements ConfigurableComponent, MultipartWrapperFactory {

	/**
	 * @see net.sourceforge.stripes.config.ConfigurableComponent#init(net.sourceforge.stripes.config.Configuration)
	 */
	public void init(Configuration conf) throws Exception {
	}

	/**
	 * @see net.sourceforge.stripes.controller.multipart.MultipartWrapperFactory#wrap(javax.servlet.http.HttpServletRequest)
	 */
	public MultipartWrapper wrap(HttpServletRequest request) throws IOException, FileUploadLimitExceededException {
		return null;
	}
}

Now that we disabled the file uploading lets create an ActionBean that will handle our request. Create a package in the project called com.helloworld.action and add the following class:


package com.helloworld.action;

import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;

/**
 * The action bean that will handle the our simple request.
 *
 * @author 110j
 */
public class EasyActionBean implements ActionBean {
	private static final String VIEW = "/WEB-INF/jsp/hello_world.jsp";
	private static final String MY_MESSAGE = "hello world";
	private ActionBeanContext ctx;

	private String message;

	@DefaultHandler
	public Resolution showMe() {
		this.setMessage(MY_MESSAGE);
		return new ForwardResolution(VIEW);
	}

	/**
	 * @see net.sourceforge.stripes.action.ActionBean#getContext()
	 */
	public ActionBeanContext getContext() {
		return this.ctx;
	}

	/**
	 * @see net.sourceforge.stripes.action.ActionBean#setContext(ActionBeanContext)
	 */
	public void setContext(ActionBeanContext ctx) {
		this.ctx = ctx;
	}

	/**
	 * @return the message
	 */
	public String getMessage() {
		return message;
	}

	/**
	 * @param message the message to set
	 */
	public void setMessage(String message) {
		this.message = message;
	}
}

Next lets create a jsp file that will render the response, create the hello_world.jsp under WEB_INF/jsp/ and add the following content:

Finally create a welcome file called index.jsp if it does not exist or rename the index.html to index.jsp and add just a forward to the action:

You can delete the servlet generated by the google plugin there is no need for it.

In order to test it you just need to run the hello_world in the Run history of eclipse as the google plugin will create one for us, or under the run button in the toolbar, and then visit the address localhost:8080

NOTE: if your application require session you need to enable it in the appengine-web.xml since it is disabled by default (but keep in mind the implication it may have in a distributed environment such as google app engine, maybe your attributes will need to implement the HttpSessionActivationListener if you plan to add them in the session).

You can upload your application by using eclipse or the command line tool, for more information visit http://code.google.com/appengine/docs/java/gettingstarted/uploading.html

To be continued!

tail the log file inside eclipse

Most common tool to follow the logs of the application is tail at least under unix, linux and probably mac osx operating systems. So we just need to open a console and type tail -f path/app.log. Fairly simple but it would be nice to have it inside eclipse, which turns out to be also very simple to configure it with the external tools of eclipse.

Open External Tools Configurations:

External tool configuration

External tool configuration

Hit Run and that’s it. Windows users should install a tail for windows first!

Enjoy!

image-a-nation challenge – using Java

Interesting challenge from google image team… here’s an attempt to create the image using java,
(more work is needed to make it more resposive while reading the image files, also reading the clues directly from the web would be better! :)

Screenshot

Screenshot

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;

import javax.imageio.ImageIO;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

@SuppressWarnings("serial")
public class GoogleImageBuilder extends JComponent {

	private static final String GOOGLE_URL = "http://google.com/images?q=tbn:";
    private static BufferedImage picture = null;

    public GoogleImageBuilder() {
    	setPreferredSize(new Dimension(16 * 32, 16 * 32));
    }

    public void paintComponent(Graphics g) {
    	Map clues = HardCodedClues.getClues();
    	SortedSet keys = new TreeSet(clues.keySet());

        int x = 0;
        int y = 0;

        for (Integer key : keys) {
			try {
				URL url = new URL(GOOGLE_URL  + clues.get(key));
				System.out.println("reading: " + url.toString());
				URLConnection uc = url.openConnection();
				picture = ImageIO.read(uc.getInputStream());

			} catch (MalformedURLException e) {
				System.out.println("The following error occured!: " + e);
	            System.exit(0);

			} catch (IOException e) {
				System.out.println("The following error occured!: " + e);
	            System.exit(0);
			}

			x = (key % 16) * 32;
            y = (key / 16) * 32;

			g.drawImage(picture, x, y, 32, 32, null);
		}
    }

    private static void createAndShowGUI() {
        JFrame f = new JFrame("Google images");
        f.setLayout(new BorderLayout());
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        GoogleImageBuilder test = new GoogleImageBuilder();
        f.add(test);
        f.validate();
        f.pack();
        f.setVisible(true);
    }

    public static void main(String args[]) {
        Runnable doCreateAndShowGUI = new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        };
        SwingUtilities.invokeLater(doCreateAndShowGUI);
    }
}

Here are the clues hardcoded:

import java.util.HashMap;
import java.util.Map;

public class HardCodedClues {
	private static final int RADIX_16 = 16;

    public static Map getClues() {
    	String [] clues = {
			 "28:Kx7vy-VBtpYJ", "7B:PyDg0PjbgxkJ", "F3:Rd1xXw4alLkJ", "31:FeaBmsxfey8J",

			  "20:YsNAjeTGJVEJ", "A9:leYDU1RuuwIJ", "81:jufN-4x1RnAJ", "CB:IhifTIhRpmoJ",

			  "87:8Maz8upc508J", "FA:5dh9_zqVdkIJ", "BA:xyZftsH8RFsJ", "50:L_zmPN_48bMJ",

			  "49:iLtQE1Q7CWMJ", "D6:TuKm3fTasSYJ", "FE:pls5MhpkpK8J", "60:thDCBIkyQ2EJ",

			  "85:CizK2j2yCBIJ", "23:IkmAcC6lNjIJ", "F8:kRRYwomQWhIJ", "8E:_v-YolETks4J",

			  "E1:Bf8Ltpee0v4J", "D0:0YM5CoDmx8MJ", "92:D9zUj4QVc2sJ", "0C:FsKZkZ1R7t4J",

			  "45:NVX4OCi9WXAJ", "A7:aQAFb1464l4J", "68:aej8Xg6iVhkJ", "A5:EHkO0tMtSN4J",

			  "F6:49-gxPeD0IwJ", "5E:bpLwYqr-990J", "C0:mawuaWJa1boJ", "00:NEU6wRmGVq4J",

			  "28:Kx7vy-VBtpYJ", "7B:PyDg0PjbgxkJ", "F3:Rd1xXw4alLkJ", "31:FeaBmsxfey8J",

			  "20:YsNAjeTGJVEJ", "A9:leYDU1RuuwIJ", "81:jufN-4x1RnAJ", "CB:IhifTIhRpmoJ",

			  "87:8Maz8upc508J", "FA:5dh9_zqVdkIJ", "BA:xyZftsH8RFsJ", "50:L_zmPN_48bMJ",

			  "49:iLtQE1Q7CWMJ", "D6:TuKm3fTasSYJ", "FE:pls5MhpkpK8J", "60:thDCBIkyQ2EJ",

			  "85:CizK2j2yCBIJ", "23:IkmAcC6lNjIJ", "F8:kRRYwomQWhIJ", "8E:_v-YolETks4J",

			  "E1:Bf8Ltpee0v4J", "D0:0YM5CoDmx8MJ", "92:D9zUj4QVc2sJ", "0C:FsKZkZ1R7t4J",

			  "45:NVX4OCi9WXAJ", "A7:aQAFb1464l4J", "68:aej8Xg6iVhkJ", "A5:EHkO0tMtSN4J",

			  "F6:49-gxPeD0IwJ", "5E:bpLwYqr-990J", "C0:mawuaWJa1boJ", "00:NEU6wRmGVq4J",

			  "84:h5LxuUdV03oJ", "D9:-Eup1YnE6-0J", "FC:7fjrc7LzjskJ", "03:LJouzaZ6nakJ",

			  "C3:3cyoIZdesRYJ", "EB:GumIzK6Xwv8J", "12:KYkKkVzbW-UJ", "AB:EHkO0tMtSN4J",

			  "30:vrZQ1rXJEg4J", "CE:AbXWG_eCFZYJ", "6B:EOhnwwtJMz4J", "5F:PyDg0PjbgxkJ",

			  "62:zzxVlWrc94AJ", "F2:CwpwlljQ5RUJ", "7F:9aqBJNfDaUEJ", "EE:CWVFy5sgo9MJ",

			  "4C:JDNgZADQwGkJ", "58:uJB16vUcH38J", "3D:Jij2JFUry5gJ", "C8:v7juRN1cZ4EJ",

			  "1E:16e59DDxd1QJ", "69:y1f3FuaNqhEJ", "B0:4cYEeKseVRYJ", "37:Hnm8AysFIvgJ",

			  "1D:qFpNdOAQ868J", "21:Ypml6jLyoaEJ", "34:UhJBrAWg8MAJ", "A0:xTaArVPF51IJ",

			  "EF:14kwBS4zH4kJ", "ED:eUzfBgFaYAYJ", "51:1RWzov84HGsJ", "72:WRUq1C2UF7YJ",

			  "28:Kx7vy-VBtpYJ", "7B:PyDg0PjbgxkJ", "F3:Rd1xXw4alLkJ", "31:FeaBmsxfey8J",

			  "20:YsNAjeTGJVEJ", "A9:leYDU1RuuwIJ", "81:jufN-4x1RnAJ", "CB:IhifTIhRpmoJ",

			  "87:8Maz8upc508J", "FA:5dh9_zqVdkIJ", "BA:xyZftsH8RFsJ", "50:L_zmPN_48bMJ",

			  "49:iLtQE1Q7CWMJ", "D6:TuKm3fTasSYJ", "FE:pls5MhpkpK8J", "60:thDCBIkyQ2EJ",

			  "85:CizK2j2yCBIJ", "23:IkmAcC6lNjIJ", "F8:kRRYwomQWhIJ", "8E:_v-YolETks4J",

			  "E1:Bf8Ltpee0v4J", "D0:0YM5CoDmx8MJ", "92:D9zUj4QVc2sJ", "0C:FsKZkZ1R7t4J",

			  "45:NVX4OCi9WXAJ", "A7:aQAFb1464l4J", "68:aej8Xg6iVhkJ", "A5:EHkO0tMtSN4J",

			  "F6:49-gxPeD0IwJ", "5E:bpLwYqr-990J", "C0:mawuaWJa1boJ", "00:NEU6wRmGVq4J",

			  "84:h5LxuUdV03oJ", "D9:-Eup1YnE6-0J", "FC:7fjrc7LzjskJ", "03:LJouzaZ6nakJ",

			  "C3:3cyoIZdesRYJ", "EB:GumIzK6Xwv8J", "12:KYkKkVzbW-UJ", "AB:EHkO0tMtSN4J",

			  "30:vrZQ1rXJEg4J", "CE:AbXWG_eCFZYJ", "6B:EOhnwwtJMz4J", "5F:PyDg0PjbgxkJ",

			  "62:zzxVlWrc94AJ", "F2:CwpwlljQ5RUJ", "7F:9aqBJNfDaUEJ", "EE:CWVFy5sgo9MJ",

			  "4C:JDNgZADQwGkJ", "58:uJB16vUcH38J", "3D:Jij2JFUry5gJ", "C8:v7juRN1cZ4EJ",

			  "1E:16e59DDxd1QJ", "69:y1f3FuaNqhEJ", "B0:4cYEeKseVRYJ", "37:Hnm8AysFIvgJ",

			  "1D:qFpNdOAQ868J", "21:Ypml6jLyoaEJ", "34:UhJBrAWg8MAJ", "A0:xTaArVPF51IJ",

			  "EF:14kwBS4zH4kJ", "ED:eUzfBgFaYAYJ", "51:1RWzov84HGsJ", "72:WRUq1C2UF7YJ",

			  "24:TkF3I-3AqsoJ", "6E:Cxb4nb_-6wQJ", "CC:Cfwjydcm5VUJ", "94:3V77coCFoyUJ",

			  "0E:lfqBck_AckoJ", "C7:qTuFDoAZZAIJ", "E4:X9O9H0rf7UwJ", "A1:dh_aVJQg-fQJ",

			  "1B:SSUHFP88ICIJ", "9A:8LRpia1kQyoJ", "A8:6OB8e96ajfIJ", "8D:sekIn_D0FY4J",

			  "9D:sQbLyZCjcMwJ", "9C:at2mlybzsckJ", "2D:gagHFe3EgRcJ", "7C:sbERUkuwrgkJ",

			  "DF:jIbY1S4jGOQJ", "15:sQ5gc2skXDoJ", "B5:qpQ_jThwIfwJ", "E7:bujGGLRs6f8J",

			  "B9:FC8WDc6FfQAJ", "AC:7PqlCpunKtMJ", "90:6bCXBm-ZoeMJ", "05:kUDeAWh_o54J",

			  "46:BTA_qt_HhUkJ", "3E:3fscTyozTmYJ", "14:dsppEkkJ6vIJ", "AA:q8Xw6c1aDJQJ",

			  "5C:1Yy-Elilf_wJ", "67:sYb7HA_7lCwJ", "99:kPiuzGwRUKIJ", "E2:3NCEoBX-P-gJ",

			  "28:Kx7vy-VBtpYJ", "7B:PyDg0PjbgxkJ", "F3:Rd1xXw4alLkJ", "31:FeaBmsxfey8J",

			  "20:YsNAjeTGJVEJ", "A9:leYDU1RuuwIJ", "81:jufN-4x1RnAJ", "CB:IhifTIhRpmoJ",

			  "87:8Maz8upc508J", "FA:5dh9_zqVdkIJ", "BA:xyZftsH8RFsJ", "50:L_zmPN_48bMJ",

			  "49:iLtQE1Q7CWMJ", "D6:TuKm3fTasSYJ", "FE:pls5MhpkpK8J", "60:thDCBIkyQ2EJ",

			  "85:CizK2j2yCBIJ", "23:IkmAcC6lNjIJ", "F8:kRRYwomQWhIJ", "8E:_v-YolETks4J",

			  "E1:Bf8Ltpee0v4J", "D0:0YM5CoDmx8MJ", "92:D9zUj4QVc2sJ", "0C:FsKZkZ1R7t4J",

			  "45:NVX4OCi9WXAJ", "A7:aQAFb1464l4J", "68:aej8Xg6iVhkJ", "A5:EHkO0tMtSN4J",

			  "F6:49-gxPeD0IwJ", "5E:bpLwYqr-990J", "C0:mawuaWJa1boJ", "00:NEU6wRmGVq4J",

			  "84:h5LxuUdV03oJ", "D9:-Eup1YnE6-0J", "FC:7fjrc7LzjskJ", "03:LJouzaZ6nakJ",

			  "C3:3cyoIZdesRYJ", "EB:GumIzK6Xwv8J", "12:KYkKkVzbW-UJ", "AB:EHkO0tMtSN4J",

			  "30:vrZQ1rXJEg4J", "CE:AbXWG_eCFZYJ", "6B:EOhnwwtJMz4J", "5F:PyDg0PjbgxkJ",

			  "62:zzxVlWrc94AJ", "F2:CwpwlljQ5RUJ", "7F:9aqBJNfDaUEJ", "EE:CWVFy5sgo9MJ",

			  "4C:JDNgZADQwGkJ", "58:uJB16vUcH38J", "3D:Jij2JFUry5gJ", "C8:v7juRN1cZ4EJ",

			  "1E:16e59DDxd1QJ", "69:y1f3FuaNqhEJ", "B0:4cYEeKseVRYJ", "37:Hnm8AysFIvgJ",

			  "1D:qFpNdOAQ868J", "21:Ypml6jLyoaEJ", "34:UhJBrAWg8MAJ", "A0:xTaArVPF51IJ",

			  "EF:14kwBS4zH4kJ", "ED:eUzfBgFaYAYJ", "51:1RWzov84HGsJ", "72:WRUq1C2UF7YJ",

			  "24:TkF3I-3AqsoJ", "6E:Cxb4nb_-6wQJ", "CC:Cfwjydcm5VUJ", "94:3V77coCFoyUJ",

			  "0E:lfqBck_AckoJ", "C7:qTuFDoAZZAIJ", "E4:X9O9H0rf7UwJ", "A1:dh_aVJQg-fQJ",

			  "1B:SSUHFP88ICIJ", "9A:8LRpia1kQyoJ", "A8:6OB8e96ajfIJ", "8D:sekIn_D0FY4J",

			  "9D:sQbLyZCjcMwJ", "9C:at2mlybzsckJ", "2D:gagHFe3EgRcJ", "7C:sbERUkuwrgkJ",

			  "DF:jIbY1S4jGOQJ", "15:sQ5gc2skXDoJ", "B5:qpQ_jThwIfwJ", "E7:bujGGLRs6f8J",

			  "B9:FC8WDc6FfQAJ", "AC:7PqlCpunKtMJ", "90:6bCXBm-ZoeMJ", "05:kUDeAWh_o54J",

			  "46:BTA_qt_HhUkJ", "3E:3fscTyozTmYJ", "14:dsppEkkJ6vIJ", "AA:q8Xw6c1aDJQJ",

			  "5C:1Yy-Elilf_wJ", "67:sYb7HA_7lCwJ", "99:kPiuzGwRUKIJ", "E2:3NCEoBX-P-gJ",

			  "7D:gOHngHfzX8YJ", "2C:1j66DXvpuf8J", "07:rWnu8lphvZcJ", "CA:PFnVqjCPIKIJ",

			  "D7:ydg0kWMXDeoJ", "5A:n33l1U6zbEIJ", "57:hKzAPG_v3g4J", "3F:XGwx9FgVixQJ",

			  "36:abLa4yOIyW4J", "10:sMDENsqLts0J", "D2:gJsgjLw3nSQJ", "E0:Z_K4hdZq7h8J",

			  "75:3C-XszC6kyMJ", "77:rtHRfe9A27YJ", "97:-eflxIU8g04J", "F0:SwVcyzirnnQJ",

			  "65:7-hjyVDnHjEJ", "A3:hruuOW22_L8J", "F9:lEPeKx6ket4J", "88:M3DdYOcDTWwJ",

			  "FD:Cfwjydcm5VUJ", "42:HNXS6FBy7AUJ", "4A:-n4dEXmbmyMJ", "F7:IPDuatbjjRoJ",

			  "52:2xrwdGDvyaEJ", "5B:vEMG_nMaZygJ", "27:hfidgDDREMsJ", "70:DJ1-bAcdQE8J",

			  "78:aej8Xg6iVhkJ", "61:4SHBf-6ctTQJ", "BF:oJWMF8g4n98J", "3C:wbyliY5Fw7cJ",

			  "28:Kx7vy-VBtpYJ", "7B:PyDg0PjbgxkJ", "F3:Rd1xXw4alLkJ", "31:FeaBmsxfey8J",

			  "20:YsNAjeTGJVEJ", "A9:leYDU1RuuwIJ", "81:jufN-4x1RnAJ", "CB:IhifTIhRpmoJ",

			  "87:8Maz8upc508J", "FA:5dh9_zqVdkIJ", "BA:xyZftsH8RFsJ", "50:L_zmPN_48bMJ",

			  "49:iLtQE1Q7CWMJ", "D6:TuKm3fTasSYJ", "FE:pls5MhpkpK8J", "60:thDCBIkyQ2EJ",

			  "85:CizK2j2yCBIJ", "23:IkmAcC6lNjIJ", "F8:kRRYwomQWhIJ", "8E:_v-YolETks4J",

			  "E1:Bf8Ltpee0v4J", "D0:0YM5CoDmx8MJ", "92:D9zUj4QVc2sJ", "0C:FsKZkZ1R7t4J",

			  "45:NVX4OCi9WXAJ", "A7:aQAFb1464l4J", "68:aej8Xg6iVhkJ", "A5:EHkO0tMtSN4J",

			  "F6:49-gxPeD0IwJ", "5E:bpLwYqr-990J", "C0:mawuaWJa1boJ", "00:NEU6wRmGVq4J",

			  "84:h5LxuUdV03oJ", "D9:-Eup1YnE6-0J", "FC:7fjrc7LzjskJ", "03:LJouzaZ6nakJ",

			  "C3:3cyoIZdesRYJ", "EB:GumIzK6Xwv8J", "12:KYkKkVzbW-UJ", "AB:EHkO0tMtSN4J",

			  "30:vrZQ1rXJEg4J", "CE:AbXWG_eCFZYJ", "6B:EOhnwwtJMz4J", "5F:PyDg0PjbgxkJ",

			  "62:zzxVlWrc94AJ", "F2:CwpwlljQ5RUJ", "7F:9aqBJNfDaUEJ", "EE:CWVFy5sgo9MJ",

			  "4C:JDNgZADQwGkJ", "58:uJB16vUcH38J", "3D:Jij2JFUry5gJ", "C8:v7juRN1cZ4EJ",

			  "1E:16e59DDxd1QJ", "69:y1f3FuaNqhEJ", "B0:4cYEeKseVRYJ", "37:Hnm8AysFIvgJ",

			  "1D:qFpNdOAQ868J", "21:Ypml6jLyoaEJ", "34:UhJBrAWg8MAJ", "A0:xTaArVPF51IJ",

			  "EF:14kwBS4zH4kJ", "ED:eUzfBgFaYAYJ", "51:1RWzov84HGsJ", "72:WRUq1C2UF7YJ",

			  "24:TkF3I-3AqsoJ", "6E:Cxb4nb_-6wQJ", "CC:Cfwjydcm5VUJ", "94:3V77coCFoyUJ",

			  "0E:lfqBck_AckoJ", "C7:qTuFDoAZZAIJ", "E4:X9O9H0rf7UwJ", "A1:dh_aVJQg-fQJ",

			  "1B:SSUHFP88ICIJ", "9A:8LRpia1kQyoJ", "A8:6OB8e96ajfIJ", "8D:sekIn_D0FY4J",

			  "9D:sQbLyZCjcMwJ", "9C:at2mlybzsckJ", "2D:gagHFe3EgRcJ", "7C:sbERUkuwrgkJ",

			  "DF:jIbY1S4jGOQJ", "15:sQ5gc2skXDoJ", "B5:qpQ_jThwIfwJ", "E7:bujGGLRs6f8J",

			  "B9:FC8WDc6FfQAJ", "AC:7PqlCpunKtMJ", "90:6bCXBm-ZoeMJ", "05:kUDeAWh_o54J",

			  "46:BTA_qt_HhUkJ", "3E:3fscTyozTmYJ", "14:dsppEkkJ6vIJ", "AA:q8Xw6c1aDJQJ",

			  "5C:1Yy-Elilf_wJ", "67:sYb7HA_7lCwJ", "99:kPiuzGwRUKIJ", "E2:3NCEoBX-P-gJ",

			  "7D:gOHngHfzX8YJ", "2C:1j66DXvpuf8J", "07:rWnu8lphvZcJ", "CA:PFnVqjCPIKIJ",

			  "D7:ydg0kWMXDeoJ", "5A:n33l1U6zbEIJ", "57:hKzAPG_v3g4J", "3F:XGwx9FgVixQJ",

			  "36:abLa4yOIyW4J", "10:sMDENsqLts0J", "D2:gJsgjLw3nSQJ", "E0:Z_K4hdZq7h8J",

			  "75:3C-XszC6kyMJ", "77:rtHRfe9A27YJ", "97:-eflxIU8g04J", "F0:SwVcyzirnnQJ",

			  "65:7-hjyVDnHjEJ", "A3:hruuOW22_L8J", "F9:lEPeKx6ket4J", "88:M3DdYOcDTWwJ",

			  "FD:Cfwjydcm5VUJ", "42:HNXS6FBy7AUJ", "4A:-n4dEXmbmyMJ", "F7:IPDuatbjjRoJ",

			  "52:2xrwdGDvyaEJ", "5B:vEMG_nMaZygJ", "27:hfidgDDREMsJ", "70:DJ1-bAcdQE8J",

			  "78:aej8Xg6iVhkJ", "61:4SHBf-6ctTQJ", "BF:oJWMF8g4n98J", "3C:wbyliY5Fw7cJ",

			  "BD:dyCQwPoi_QoJ", "6D:ROtjpJaaM3AJ", "D1:u77vCPi7NX4J", "DA:jr7lZOIXHE4J",

			  "80:hvDWT2JOOHIJ", "48:hfidgDDREMsJ", "8B:TMDNdWekwlEJ", "73:13SgY09fd9QJ",

			  "7E:tx3mt6GYR5oJ", "B3:JTLUoSksUFAJ", "63:DyaRtEUhtg4J", "0B:1q-lkiRNa7kJ",

			  "93:L3R7clDgu44J", "F5:o-lzUg48_5UJ", "01:6YJy7S3OGt8J", "26:vs3cbrj7Bi0J",

			  "7A:C6L9XGQS6i8J", "A4:iMWi3RNzLHUJ", "8F:2ELg7mGC5yUJ", "1A:rZEfAj2wHgYJ",

			  "A6:kP-bP5hmF9cJ", "18:KcznZAsaAk0J", "FF:kp-fx5_9CzsJ", "6C:5I-cinT_0_4J",

			  "8C:zaUGihUPAJwJ", "0F:AIt7UQkMmZkJ", "9B:FYtibg-zD20J", "B7:A2SiPb4NwWQJ",

			  "89:isoWmMm2QssJ", "C5:CibMCkpl2kAJ", "0D:g9lghtXOAFMJ", "38:gWcquZBJFPIJ",

			  "28:Kx7vy-VBtpYJ", "7B:PyDg0PjbgxkJ", "F3:Rd1xXw4alLkJ", "31:FeaBmsxfey8J",

			  "20:YsNAjeTGJVEJ", "A9:leYDU1RuuwIJ", "81:jufN-4x1RnAJ", "CB:IhifTIhRpmoJ",

			  "87:8Maz8upc508J", "FA:5dh9_zqVdkIJ", "BA:xyZftsH8RFsJ", "50:L_zmPN_48bMJ",

			  "49:iLtQE1Q7CWMJ", "D6:TuKm3fTasSYJ", "FE:pls5MhpkpK8J", "60:thDCBIkyQ2EJ",

			  "85:CizK2j2yCBIJ", "23:IkmAcC6lNjIJ", "F8:kRRYwomQWhIJ", "8E:_v-YolETks4J",

			  "E1:Bf8Ltpee0v4J", "D0:0YM5CoDmx8MJ", "92:D9zUj4QVc2sJ", "0C:FsKZkZ1R7t4J",

			  "45:NVX4OCi9WXAJ", "A7:aQAFb1464l4J", "68:aej8Xg6iVhkJ", "A5:EHkO0tMtSN4J",

			  "F6:49-gxPeD0IwJ", "5E:bpLwYqr-990J", "C0:mawuaWJa1boJ", "00:NEU6wRmGVq4J",

			  "84:h5LxuUdV03oJ", "D9:-Eup1YnE6-0J", "FC:7fjrc7LzjskJ", "03:LJouzaZ6nakJ",

			  "C3:3cyoIZdesRYJ", "EB:GumIzK6Xwv8J", "12:KYkKkVzbW-UJ", "AB:EHkO0tMtSN4J",

			  "30:vrZQ1rXJEg4J", "CE:AbXWG_eCFZYJ", "6B:EOhnwwtJMz4J", "5F:PyDg0PjbgxkJ",

			  "62:zzxVlWrc94AJ", "F2:CwpwlljQ5RUJ", "7F:9aqBJNfDaUEJ", "EE:CWVFy5sgo9MJ",

			  "4C:JDNgZADQwGkJ", "58:uJB16vUcH38J", "3D:Jij2JFUry5gJ", "C8:v7juRN1cZ4EJ",

			  "1E:16e59DDxd1QJ", "69:y1f3FuaNqhEJ", "B0:4cYEeKseVRYJ", "37:Hnm8AysFIvgJ",

			  "1D:qFpNdOAQ868J", "21:Ypml6jLyoaEJ", "34:UhJBrAWg8MAJ", "A0:xTaArVPF51IJ",

			  "EF:14kwBS4zH4kJ", "ED:eUzfBgFaYAYJ", "51:1RWzov84HGsJ", "72:WRUq1C2UF7YJ",

			  "24:TkF3I-3AqsoJ", "6E:Cxb4nb_-6wQJ", "CC:Cfwjydcm5VUJ", "94:3V77coCFoyUJ",

			  "0E:lfqBck_AckoJ", "C7:qTuFDoAZZAIJ", "E4:X9O9H0rf7UwJ", "A1:dh_aVJQg-fQJ",

			  "1B:SSUHFP88ICIJ", "9A:8LRpia1kQyoJ", "A8:6OB8e96ajfIJ", "8D:sekIn_D0FY4J",

			  "9D:sQbLyZCjcMwJ", "9C:at2mlybzsckJ", "2D:gagHFe3EgRcJ", "7C:sbERUkuwrgkJ",

			  "DF:jIbY1S4jGOQJ", "15:sQ5gc2skXDoJ", "B5:qpQ_jThwIfwJ", "E7:bujGGLRs6f8J",

			  "B9:FC8WDc6FfQAJ", "AC:7PqlCpunKtMJ", "90:6bCXBm-ZoeMJ", "05:kUDeAWh_o54J",

			  "46:BTA_qt_HhUkJ", "3E:3fscTyozTmYJ", "14:dsppEkkJ6vIJ", "AA:q8Xw6c1aDJQJ",

			  "5C:1Yy-Elilf_wJ", "67:sYb7HA_7lCwJ", "99:kPiuzGwRUKIJ", "E2:3NCEoBX-P-gJ",

			  "7D:gOHngHfzX8YJ", "2C:1j66DXvpuf8J", "07:rWnu8lphvZcJ", "CA:PFnVqjCPIKIJ",

			  "D7:ydg0kWMXDeoJ", "5A:n33l1U6zbEIJ", "57:hKzAPG_v3g4J", "3F:XGwx9FgVixQJ",

			  "36:abLa4yOIyW4J", "10:sMDENsqLts0J", "D2:gJsgjLw3nSQJ", "E0:Z_K4hdZq7h8J",

			  "75:3C-XszC6kyMJ", "77:rtHRfe9A27YJ", "97:-eflxIU8g04J", "F0:SwVcyzirnnQJ",

			  "65:7-hjyVDnHjEJ", "A3:hruuOW22_L8J", "F9:lEPeKx6ket4J", "88:M3DdYOcDTWwJ",

			  "FD:Cfwjydcm5VUJ", "42:HNXS6FBy7AUJ", "4A:-n4dEXmbmyMJ", "F7:IPDuatbjjRoJ",

			  "52:2xrwdGDvyaEJ", "5B:vEMG_nMaZygJ", "27:hfidgDDREMsJ", "70:DJ1-bAcdQE8J",

			  "78:aej8Xg6iVhkJ", "61:4SHBf-6ctTQJ", "BF:oJWMF8g4n98J", "3C:wbyliY5Fw7cJ",

			  "BD:dyCQwPoi_QoJ", "6D:ROtjpJaaM3AJ", "D1:u77vCPi7NX4J", "DA:jr7lZOIXHE4J",

			  "80:hvDWT2JOOHIJ", "48:hfidgDDREMsJ", "8B:TMDNdWekwlEJ", "73:13SgY09fd9QJ",

			  "7E:tx3mt6GYR5oJ", "B3:JTLUoSksUFAJ", "63:DyaRtEUhtg4J", "0B:1q-lkiRNa7kJ",

			  "93:L3R7clDgu44J", "F5:o-lzUg48_5UJ", "01:6YJy7S3OGt8J", "26:vs3cbrj7Bi0J",

			  "7A:C6L9XGQS6i8J", "A4:iMWi3RNzLHUJ", "8F:2ELg7mGC5yUJ", "1A:rZEfAj2wHgYJ",

			  "A6:kP-bP5hmF9cJ", "18:KcznZAsaAk0J", "FF:kp-fx5_9CzsJ", "6C:5I-cinT_0_4J",

			  "8C:zaUGihUPAJwJ", "0F:AIt7UQkMmZkJ", "9B:FYtibg-zD20J", "B7:A2SiPb4NwWQJ",

			  "89:isoWmMm2QssJ", "C5:CibMCkpl2kAJ", "0D:g9lghtXOAFMJ", "38:gWcquZBJFPIJ",

			  "11:_TotMQXuZdgJ", "6A:24tx-mIpwmwJ", "8A:-FAi_YRhbrgJ", "1F:kQEIlYRdi2QJ",

			  "41:FoWhbx2IxiUJ", "4E:XFlq06C_YeMJ", "13:vKSdbEgs9aoJ", "D5:m415gDZ2B-UJ",

			  "AD:hWBrF9YLK78J", "2B:HqEtb7AADmMJ", "DE:eCFYrqg0WsEJ", "16:QLTeOYg-yB8J",

			  "BB:jk-d_Ua8BtIJ", "C9:u0J9izcWwvAJ", "91:NM3JgAgreZQJ", "04:sYb7HA_7lCwJ",

			  "08:VwTb3zO7tL8J", "DD:kwlsYdonpIgJ", "F4:_LIV45PtumsJ", "EC:rpMyxZmO6LwJ",

			  "54:bDNO5Nsce9EJ", "2A:XFgcPHiQ6SYJ", "71:b8UD6gHfO6IJ", "9E:rwusJNoWjiQJ",

			  "FB:c-wHLtEdkf0J", "AE:brdZuMrvAMQJ", "E8:mzaxbrVLBOUJ", "4B:6ye4zJaCE_oJ",

			  "22:6fwxGNK3bJgJ", "B8:jwvALeEfsbcJ", "33:Yqx6f_8RvNgJ", "C2:sxB_6QG_Qb4J",

			  "28:Kx7vy-VBtpYJ", "7B:PyDg0PjbgxkJ", "F3:Rd1xXw4alLkJ", "31:FeaBmsxfey8J",

			  "20:YsNAjeTGJVEJ", "A9:leYDU1RuuwIJ", "81:jufN-4x1RnAJ", "CB:IhifTIhRpmoJ",

			  "87:8Maz8upc508J", "FA:5dh9_zqVdkIJ", "BA:xyZftsH8RFsJ", "50:L_zmPN_48bMJ",

			  "49:iLtQE1Q7CWMJ", "D6:TuKm3fTasSYJ", "FE:pls5MhpkpK8J", "60:thDCBIkyQ2EJ",

			  "85:CizK2j2yCBIJ", "23:IkmAcC6lNjIJ", "F8:kRRYwomQWhIJ", "8E:_v-YolETks4J",

			  "E1:Bf8Ltpee0v4J", "D0:0YM5CoDmx8MJ", "92:D9zUj4QVc2sJ", "0C:FsKZkZ1R7t4J",

			  "45:NVX4OCi9WXAJ", "A7:aQAFb1464l4J", "68:aej8Xg6iVhkJ", "A5:EHkO0tMtSN4J",

			  "F6:49-gxPeD0IwJ", "5E:bpLwYqr-990J", "C0:mawuaWJa1boJ", "00:NEU6wRmGVq4J",

			  "84:h5LxuUdV03oJ", "D9:-Eup1YnE6-0J", "FC:7fjrc7LzjskJ", "03:LJouzaZ6nakJ",

			  "C3:3cyoIZdesRYJ", "EB:GumIzK6Xwv8J", "12:KYkKkVzbW-UJ", "AB:EHkO0tMtSN4J",

			  "30:vrZQ1rXJEg4J", "CE:AbXWG_eCFZYJ", "6B:EOhnwwtJMz4J", "5F:PyDg0PjbgxkJ",

			  "62:zzxVlWrc94AJ", "F2:CwpwlljQ5RUJ", "7F:9aqBJNfDaUEJ", "EE:CWVFy5sgo9MJ",

			  "4C:JDNgZADQwGkJ", "58:uJB16vUcH38J", "3D:Jij2JFUry5gJ", "C8:v7juRN1cZ4EJ",

			  "1E:16e59DDxd1QJ", "69:y1f3FuaNqhEJ", "B0:4cYEeKseVRYJ", "37:Hnm8AysFIvgJ",

			  "1D:qFpNdOAQ868J", "21:Ypml6jLyoaEJ", "34:UhJBrAWg8MAJ", "A0:xTaArVPF51IJ",

			  "EF:14kwBS4zH4kJ", "ED:eUzfBgFaYAYJ", "51:1RWzov84HGsJ", "72:WRUq1C2UF7YJ",

			  "24:TkF3I-3AqsoJ", "6E:Cxb4nb_-6wQJ", "CC:Cfwjydcm5VUJ", "94:3V77coCFoyUJ",

			  "0E:lfqBck_AckoJ", "C7:qTuFDoAZZAIJ", "E4:X9O9H0rf7UwJ", "A1:dh_aVJQg-fQJ",

			  "1B:SSUHFP88ICIJ", "9A:8LRpia1kQyoJ", "A8:6OB8e96ajfIJ", "8D:sekIn_D0FY4J",

			  "9D:sQbLyZCjcMwJ", "9C:at2mlybzsckJ", "2D:gagHFe3EgRcJ", "7C:sbERUkuwrgkJ",

			  "DF:jIbY1S4jGOQJ", "15:sQ5gc2skXDoJ", "B5:qpQ_jThwIfwJ", "E7:bujGGLRs6f8J",

			  "B9:FC8WDc6FfQAJ", "AC:7PqlCpunKtMJ", "90:6bCXBm-ZoeMJ", "05:kUDeAWh_o54J",

			  "46:BTA_qt_HhUkJ", "3E:3fscTyozTmYJ", "14:dsppEkkJ6vIJ", "AA:q8Xw6c1aDJQJ",

			  "5C:1Yy-Elilf_wJ", "67:sYb7HA_7lCwJ", "99:kPiuzGwRUKIJ", "E2:3NCEoBX-P-gJ",

			  "7D:gOHngHfzX8YJ", "2C:1j66DXvpuf8J", "07:rWnu8lphvZcJ", "CA:PFnVqjCPIKIJ",

			  "D7:ydg0kWMXDeoJ", "5A:n33l1U6zbEIJ", "57:hKzAPG_v3g4J", "3F:XGwx9FgVixQJ",

			  "36:abLa4yOIyW4J", "10:sMDENsqLts0J", "D2:gJsgjLw3nSQJ", "E0:Z_K4hdZq7h8J",

			  "75:3C-XszC6kyMJ", "77:rtHRfe9A27YJ", "97:-eflxIU8g04J", "F0:SwVcyzirnnQJ",

			  "65:7-hjyVDnHjEJ", "A3:hruuOW22_L8J", "F9:lEPeKx6ket4J", "88:M3DdYOcDTWwJ",

			  "FD:Cfwjydcm5VUJ", "42:HNXS6FBy7AUJ", "4A:-n4dEXmbmyMJ", "F7:IPDuatbjjRoJ",

			  "52:2xrwdGDvyaEJ", "5B:vEMG_nMaZygJ", "27:hfidgDDREMsJ", "70:DJ1-bAcdQE8J",

			  "78:aej8Xg6iVhkJ", "61:4SHBf-6ctTQJ", "BF:oJWMF8g4n98J", "3C:wbyliY5Fw7cJ",

			  "BD:dyCQwPoi_QoJ", "6D:ROtjpJaaM3AJ", "D1:u77vCPi7NX4J", "DA:jr7lZOIXHE4J",

			  "80:hvDWT2JOOHIJ", "48:hfidgDDREMsJ", "8B:TMDNdWekwlEJ", "73:13SgY09fd9QJ",

			  "7E:tx3mt6GYR5oJ", "B3:JTLUoSksUFAJ", "63:DyaRtEUhtg4J", "0B:1q-lkiRNa7kJ",

			  "93:L3R7clDgu44J", "F5:o-lzUg48_5UJ", "01:6YJy7S3OGt8J", "26:vs3cbrj7Bi0J",

			  "7A:C6L9XGQS6i8J", "A4:iMWi3RNzLHUJ", "8F:2ELg7mGC5yUJ", "1A:rZEfAj2wHgYJ",

			  "A6:kP-bP5hmF9cJ", "18:KcznZAsaAk0J", "FF:kp-fx5_9CzsJ", "6C:5I-cinT_0_4J",

			  "8C:zaUGihUPAJwJ", "0F:AIt7UQkMmZkJ", "9B:FYtibg-zD20J", "B7:A2SiPb4NwWQJ",

			  "89:isoWmMm2QssJ", "C5:CibMCkpl2kAJ", "0D:g9lghtXOAFMJ", "38:gWcquZBJFPIJ",

			  "11:_TotMQXuZdgJ", "6A:24tx-mIpwmwJ", "8A:-FAi_YRhbrgJ", "1F:kQEIlYRdi2QJ",

			  "41:FoWhbx2IxiUJ", "4E:XFlq06C_YeMJ", "13:vKSdbEgs9aoJ", "D5:m415gDZ2B-UJ",

			  "AD:hWBrF9YLK78J", "2B:HqEtb7AADmMJ", "DE:eCFYrqg0WsEJ", "16:QLTeOYg-yB8J",

			  "BB:jk-d_Ua8BtIJ", "C9:u0J9izcWwvAJ", "91:NM3JgAgreZQJ", "04:sYb7HA_7lCwJ",

			  "08:VwTb3zO7tL8J", "DD:kwlsYdonpIgJ", "F4:_LIV45PtumsJ", "EC:rpMyxZmO6LwJ",

			  "54:bDNO5Nsce9EJ", "2A:XFgcPHiQ6SYJ", "71:b8UD6gHfO6IJ", "9E:rwusJNoWjiQJ",

			  "FB:c-wHLtEdkf0J", "AE:brdZuMrvAMQJ", "E8:mzaxbrVLBOUJ", "4B:6ye4zJaCE_oJ",

			  "22:6fwxGNK3bJgJ", "B8:jwvALeEfsbcJ", "33:Yqx6f_8RvNgJ", "C2:sxB_6QG_Qb4J",

			  "C1:RDCyEcRfSgYJ", "AF:crKfJjXw_5MJ", "53:0DMvhUWTKb8J", "DC:e91ckrM89cEJ",

			  "B4:WDoT2alpGIUJ", "4D:bFmzm_4qu2kJ", "C4:0vD_dZABzHMJ", "1C:sz33mz3wOUQJ",

			  "C6:E7OZk_UQ4CkJ", "98:cLfnrVphpKwJ", "06:oZjZXvq5HtcJ", "64:iVU_MpjctIIJ",

			  "9F:X-bZvp5icB4J", "95:fNZpE0lgEn8J", "A2:RxHFAXHJtyAJ", "E3:6HrAalsLflAJ",

			  "3B:KqNbjwDqqCMJ", "BE:0RUKM-BlaPsJ", "0A:1q-lkiRNa7kJ", "76:m1ROBo00yiEJ",

			  "32:SkX0iYQQY_AJ", "40:vl95ZOX_Q4IJ", "09:ep_I291MX2cJ", "2F:2H1dZ2lZ248J",

			  "D4:N-GQv-Nx1z8J", "19:f561wYNWgkEJ", "D3:UON-_Wr60O8J", "74:KQJPHtyNoj4J",

			  "3A:lzls7PYvd34J", "F1:yQFSR4MaUpwJ", "CF:oRRo9yGdXSQJ", "4F:W6-iAz1ZqaUJ",

			  "28:Kx7vy-VBtpYJ", "7B:PyDg0PjbgxkJ", "F3:Rd1xXw4alLkJ", "31:FeaBmsxfey8J",

			  "20:YsNAjeTGJVEJ", "A9:leYDU1RuuwIJ", "81:jufN-4x1RnAJ", "CB:IhifTIhRpmoJ",

			  "87:8Maz8upc508J", "FA:5dh9_zqVdkIJ", "BA:xyZftsH8RFsJ", "50:L_zmPN_48bMJ",

			  "49:iLtQE1Q7CWMJ", "D6:TuKm3fTasSYJ", "FE:pls5MhpkpK8J", "60:thDCBIkyQ2EJ",

			  "85:CizK2j2yCBIJ", "23:IkmAcC6lNjIJ", "F8:kRRYwomQWhIJ", "8E:_v-YolETks4J",

			  "E1:Bf8Ltpee0v4J", "D0:0YM5CoDmx8MJ", "92:D9zUj4QVc2sJ", "0C:FsKZkZ1R7t4J",

			  "45:NVX4OCi9WXAJ", "A7:aQAFb1464l4J", "68:aej8Xg6iVhkJ", "A5:EHkO0tMtSN4J",

			  "F6:49-gxPeD0IwJ", "5E:bpLwYqr-990J", "C0:mawuaWJa1boJ", "00:NEU6wRmGVq4J",

			  "84:h5LxuUdV03oJ", "D9:-Eup1YnE6-0J", "FC:7fjrc7LzjskJ", "03:LJouzaZ6nakJ",

			  "C3:3cyoIZdesRYJ", "EB:GumIzK6Xwv8J", "12:KYkKkVzbW-UJ", "AB:EHkO0tMtSN4J",

			  "30:vrZQ1rXJEg4J", "CE:AbXWG_eCFZYJ", "6B:EOhnwwtJMz4J", "5F:PyDg0PjbgxkJ",

			  "62:zzxVlWrc94AJ", "F2:CwpwlljQ5RUJ", "7F:9aqBJNfDaUEJ", "EE:CWVFy5sgo9MJ",

			  "4C:JDNgZADQwGkJ", "58:uJB16vUcH38J", "3D:Jij2JFUry5gJ", "C8:v7juRN1cZ4EJ",

			  "1E:16e59DDxd1QJ", "69:y1f3FuaNqhEJ", "B0:4cYEeKseVRYJ", "37:Hnm8AysFIvgJ",

			  "1D:qFpNdOAQ868J", "21:Ypml6jLyoaEJ", "34:UhJBrAWg8MAJ", "A0:xTaArVPF51IJ",

			  "EF:14kwBS4zH4kJ", "ED:eUzfBgFaYAYJ", "51:1RWzov84HGsJ", "72:WRUq1C2UF7YJ",

			  "24:TkF3I-3AqsoJ", "6E:Cxb4nb_-6wQJ", "CC:Cfwjydcm5VUJ", "94:3V77coCFoyUJ",

			  "0E:lfqBck_AckoJ", "C7:qTuFDoAZZAIJ", "E4:X9O9H0rf7UwJ", "A1:dh_aVJQg-fQJ",

			  "1B:SSUHFP88ICIJ", "9A:8LRpia1kQyoJ", "A8:6OB8e96ajfIJ", "8D:sekIn_D0FY4J",

			  "9D:sQbLyZCjcMwJ", "9C:at2mlybzsckJ", "2D:gagHFe3EgRcJ", "7C:sbERUkuwrgkJ",

			  "DF:jIbY1S4jGOQJ", "15:sQ5gc2skXDoJ", "B5:qpQ_jThwIfwJ", "E7:bujGGLRs6f8J",

			  "B9:FC8WDc6FfQAJ", "AC:7PqlCpunKtMJ", "90:6bCXBm-ZoeMJ", "05:kUDeAWh_o54J",

			  "46:BTA_qt_HhUkJ", "3E:3fscTyozTmYJ", "14:dsppEkkJ6vIJ", "AA:q8Xw6c1aDJQJ",

			  "5C:1Yy-Elilf_wJ", "67:sYb7HA_7lCwJ", "99:kPiuzGwRUKIJ", "E2:3NCEoBX-P-gJ",

			  "7D:gOHngHfzX8YJ", "2C:1j66DXvpuf8J", "07:rWnu8lphvZcJ", "CA:PFnVqjCPIKIJ",

			  "D7:ydg0kWMXDeoJ", "5A:n33l1U6zbEIJ", "57:hKzAPG_v3g4J", "3F:XGwx9FgVixQJ",

			  "36:abLa4yOIyW4J", "10:sMDENsqLts0J", "D2:gJsgjLw3nSQJ", "E0:Z_K4hdZq7h8J",

			  "75:3C-XszC6kyMJ", "77:rtHRfe9A27YJ", "97:-eflxIU8g04J", "F0:SwVcyzirnnQJ",

			  "65:7-hjyVDnHjEJ", "A3:hruuOW22_L8J", "F9:lEPeKx6ket4J", "88:M3DdYOcDTWwJ",

			  "FD:Cfwjydcm5VUJ", "42:HNXS6FBy7AUJ", "4A:-n4dEXmbmyMJ", "F7:IPDuatbjjRoJ",

			  "52:2xrwdGDvyaEJ", "5B:vEMG_nMaZygJ", "27:hfidgDDREMsJ", "70:DJ1-bAcdQE8J",

			  "78:aej8Xg6iVhkJ", "61:4SHBf-6ctTQJ", "BF:oJWMF8g4n98J", "3C:wbyliY5Fw7cJ",

			  "BD:dyCQwPoi_QoJ", "6D:ROtjpJaaM3AJ", "D1:u77vCPi7NX4J", "DA:jr7lZOIXHE4J",

			  "80:hvDWT2JOOHIJ", "48:hfidgDDREMsJ", "8B:TMDNdWekwlEJ", "73:13SgY09fd9QJ",

			  "7E:tx3mt6GYR5oJ", "B3:JTLUoSksUFAJ", "63:DyaRtEUhtg4J", "0B:1q-lkiRNa7kJ",

			  "93:L3R7clDgu44J", "F5:o-lzUg48_5UJ", "01:6YJy7S3OGt8J", "26:vs3cbrj7Bi0J",

			  "7A:C6L9XGQS6i8J", "A4:iMWi3RNzLHUJ", "8F:2ELg7mGC5yUJ", "1A:rZEfAj2wHgYJ",

			  "A6:kP-bP5hmF9cJ", "18:KcznZAsaAk0J", "FF:kp-fx5_9CzsJ", "6C:5I-cinT_0_4J",

			  "8C:zaUGihUPAJwJ", "0F:AIt7UQkMmZkJ", "9B:FYtibg-zD20J", "B7:A2SiPb4NwWQJ",

			  "89:isoWmMm2QssJ", "C5:CibMCkpl2kAJ", "0D:g9lghtXOAFMJ", "38:gWcquZBJFPIJ",

			  "11:_TotMQXuZdgJ", "6A:24tx-mIpwmwJ", "8A:-FAi_YRhbrgJ", "1F:kQEIlYRdi2QJ",

			  "41:FoWhbx2IxiUJ", "4E:XFlq06C_YeMJ", "13:vKSdbEgs9aoJ", "D5:m415gDZ2B-UJ",

			  "AD:hWBrF9YLK78J", "2B:HqEtb7AADmMJ", "DE:eCFYrqg0WsEJ", "16:QLTeOYg-yB8J",

			  "BB:jk-d_Ua8BtIJ", "C9:u0J9izcWwvAJ", "91:NM3JgAgreZQJ", "04:sYb7HA_7lCwJ",

			  "08:VwTb3zO7tL8J", "DD:kwlsYdonpIgJ", "F4:_LIV45PtumsJ", "EC:rpMyxZmO6LwJ",

			  "54:bDNO5Nsce9EJ", "2A:XFgcPHiQ6SYJ", "71:b8UD6gHfO6IJ", "9E:rwusJNoWjiQJ",

			  "FB:c-wHLtEdkf0J", "AE:brdZuMrvAMQJ", "E8:mzaxbrVLBOUJ", "4B:6ye4zJaCE_oJ",

			  "22:6fwxGNK3bJgJ", "B8:jwvALeEfsbcJ", "33:Yqx6f_8RvNgJ", "C2:sxB_6QG_Qb4J",

			  "C1:RDCyEcRfSgYJ", "AF:crKfJjXw_5MJ", "53:0DMvhUWTKb8J", "DC:e91ckrM89cEJ",

			  "B4:WDoT2alpGIUJ", "4D:bFmzm_4qu2kJ", "C4:0vD_dZABzHMJ", "1C:sz33mz3wOUQJ",

			  "C6:E7OZk_UQ4CkJ", "98:cLfnrVphpKwJ", "06:oZjZXvq5HtcJ", "64:iVU_MpjctIIJ",

			  "9F:X-bZvp5icB4J", "95:fNZpE0lgEn8J", "A2:RxHFAXHJtyAJ", "E3:6HrAalsLflAJ",

			  "3B:KqNbjwDqqCMJ", "BE:0RUKM-BlaPsJ", "0A:1q-lkiRNa7kJ", "76:m1ROBo00yiEJ",

			  "32:SkX0iYQQY_AJ", "40:vl95ZOX_Q4IJ", "09:ep_I291MX2cJ", "2F:2H1dZ2lZ248J",

			  "D4:N-GQv-Nx1z8J", "19:f561wYNWgkEJ", "D3:UON-_Wr60O8J", "74:KQJPHtyNoj4J",

			  "3A:lzls7PYvd34J", "F1:yQFSR4MaUpwJ", "CF:oRRo9yGdXSQJ", "4F:W6-iAz1ZqaUJ",

			  "29:C-dd67rIqqwJ", "66:GO4Tc1u-ugYJ", "DB:eC0ElD1t9J0J", "43:d6NIXjVJ7KUJ",

			  "82:Io93RHeLXQEJ", "CD:NXjNyJgzy4IJ", "25:_n6PawUEkHcJ", "B2:Lc1qYSv3UhUJ",

			  "BC:I-13107CCxIJ", "83:Y61PENPCqEkJ", "EA:9TqNFzh4Z_oJ", "47:NwDZxatOEc4J",

			  "B1:B-TsYBhWagAJ", "6F:fHVktF7dziUJ", "D8:xzpGFu00WYwJ", "35:9Rk1mF1piREJ",

			  "E9:JFkbdecjI8MJ", "96:CBItbsrnoXMJ", "55:noMLzjxCNboJ", "86:sKdRXX1_KzwJ",

			  "B6:VUPwfdt9GXQJ", "39:rCHm8PFbAI8J", "5D:4NwxRMobURQJ", "79:kiWLB6a7E5MJ",

			  "02:wS3Nm-eK00cJ", "E5:eRnVynYCgSsJ", "2E:Pus5p0uY2KkJ", "17:tOuRl4j_h8EJ",

			  "56:YmAwCsJOu2kJ", "59:zl6uZ0sBNPkJ", "E6:gDEADZ7sg_4J", "44:IrzQsQh4XsIJ",

			};

		Map entries = new HashMap();
		for (String clue : clues) {
			String key = clue.substring(0, clue.indexOf(':'));
			String val = clue.substring(clue.indexOf(':') + 1, clue.length());

			entries.put(Integer.parseInt(key, RADIX_16), val);
		}
		return entries;
    }
}

Enjoy!

Setting up logging mechanism in Django

Coming from a Java world where projects and libraries without logging are unheard, it was a big surprise to see that all django apps that I have downloaded so far do not include logging, even though Python has a very good support for logging, it was inspired by the log4j. For a reason that I do not know they choose not to log, I suppose it is a kind of situation where everyone else knows but me!

So as a java developer used to work with a lot of logging I decided to put in place a logging mechanism for my django project and fortunately python has great support for that:
1. create a logging.conf file for the logging options
2. configuring the logging module
3. using the logger in my modules

So here is my simple set up:
1. create a logging.conf file for the logging options with the following content:

[loggers]
keys=root,core_view_logger

[handlers]
keys=consoleHandler,core_view_handler

[formatters]
keys=simpleFormatter

[logger_root]
level=NOTSET
handlers=consoleHandler

[logger_core_view_logger]
level=DEBUG
handlers=core_view_handler
qualname=core_view_logger
propagate=0

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=simpleFormatter
args=(sys.stdout,)

[handler_core_view_handler]
class=handlers.RotatingFileHandler
level=DEBUG
formatter=simpleFormatter
args=('logs/core_logger.log', 'a', 1000000, 4)

[formatter_simpleFormatter]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
datefmt=

2. configuring the logging module in the settings.py

import logging
import logging.config

LOGGING_CONFIG = 'logging.conf' # logging configuration file
logging.config.fileConfig(LOGGING_CONFIG)

3.use the logger in your modules

import logging 

logger = logging.getLogger('core_view_logger');

def doSomething(request):
    logger.debug('This is a debug message')
    logger.info('This is an info message')
    logger.warning('This is a warning message')
    logger.error('This is an error message')
    logger.critical('Yes it is so simple :)')

That’s all folks!
But of course this is a simple set up and you can do more much more:

  • Logging to multiple destinations
  • Adding contextual information to the output
  • Send and receive logging information across network
  • Send logging information through email

Check the python official documentation for all the options http://docs.python.org/library/logging.html

Enjoy!

Organize django applications in packages and modules

When you create a django application you have one module to add your model classes the models.py and one module to add your views the views.py (also called actions in other web frameworks), and there are possibly other modules like forms.py and admin.py. This is perfectly fine when you have a small application with a couple of classes in your models.py and few functions  in your views.py. However, this files start to become unmanageable when adding more and more code. For example, in one of my projects the views.py is more than 600 lines and the models.py contains more than 20 classes. For that reason I decided to split the models.py and put each class in its won module, and also organize the views.py in more modules depending on related functionality.

To split the views.py in more modules it’s a no brain task, it is simply a python module and there is nothing that can prevent you from doing so. However, the models.py needs more attention and few more steps to accomplish the task since this module is used by the manage.py module.

Lets take an example and organize the code so it is more manageable.
Here’s how my application looks like at first, there is only one module for all model classes and one module for all views (actions):

This is how the models.py looks like
Note that the code example is from the book “Learning Website Development with Django”:

from django.db import models
from django.contrib.auth.models import User

class Link(models.Model):
    url = models.URLField(unique = True)

    def __str__(self):
        return self.url

class Bookmark(models.Model):
    title = models.CharField(max_length = 200)
    user = models.ForeignKey(User)
    link = models.ForeignKey(Link)

    def __str(self):
        return "%s, %s" % (self.user.username, self.link.url)

class Tag(models.Model):
    name = models.CharField(max_length = 64, unique = True)
    bookmarks = models.ManyToManyField(Bookmark)

    def __str__(self):
        return self.name

class SharedBookmark(models.Model):
    bookmark    = models.ForeignKey(Bookmark, unique = True)
    date        = models.DateTimeField(auto_now_add = True)
    votes       = models.IntegerField(default = 1)
    users_voted = models.ManyToManyField(User)

    def __str__(self):
        return '%s, %s' % self.bookmark, self.votes

This is only a small part of the views.py module, in the real example there are more than 200 lines of code:

from django.core.exceptions import ObjectDoesNotExist
from django.template import Context
from django.template import RequestContext
from django.template.loader import get_template
from django.http import HttpResponse, Http404, HttpResponseRedirect
from django.contrib.auth import logout
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from django.shortcuts import render_to_response
from django.shortcuts import get_object_or_404
from bookmarks.forms import *
from bookmarks.models import * 

def main_page(request):
    shared_bookmarks = SharedBookmark.objects.order_by('-date')[:10]
    variables = RequestContext(request,
                {'shared_bookmarks': shared_bookmarks})
    return render_to_response('main_page.html', variables)

@login_required()
def user_page(request, username):
    user = get_object_or_404(User, username=username)
    bookmarks = user.bookmark_set.order_by('-id')
    variables = RequestContext(request,
                {'bookmarks': bookmarks,
                 'username': username,
                 'show_tags': True,
                 'show_edit': username == request.user.username, })
    return render_to_response('user_page.html', variables)

def logout_page(request):
    logout(request)
    return HttpResponseRedirect('/')

def register_page(request):
    form = RegistrationForm(request.GET)
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
    if form.is_valid():
        user = User.objects.create_user(username=form.cleaned_data['username'],
                                        password=form.cleaned_data['password1'],
                                        email=form.cleaned_data['email'])
        return HttpResponseRedirect('/register/success/')
    else:
        form = RegistrationForm()
        variables = RequestContext(request, {'form': form})
    return render_to_response('registration/register.html', variables)

So I will take a more Java approach and create two packages one for the model and one for the views:

As I said, there is no problem whatsoever to organize the views.py into more modules, the authentication.py module is an example of the separated functionality:

from django.template import RequestContext
from django.template.loader import get_template
from django.http import HttpResponse, Http404, HttpResponseRedirect
from django.contrib.auth import logout
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from django.shortcuts import render_to_response
from django.shortcuts import get_object_or_404

@login_required()
def user_page(request, username):
    user = get_object_or_404(User, username=username)
    bookmarks = user.bookmark_set.order_by('-id')
    variables = RequestContext(request,
                {'bookmarks': bookmarks,
                 'username': username,
                 'show_tags': True,
                 'show_edit': username == request.user.username,})
    return render_to_response('user_page.html', variables)

def logout_page(request):
    logout(request)
    return HttpResponseRedirect('/')

Separating model classes and placing them into their won module follows, for brevity only the Bookmark class will be shown but all the other classes are separated in similar way. The difference now is that we have added a class inside Bookmark class called Meta with the field called app_label where we define the name of the application, if you do not add this field then the separation will not work, there is a workaround which requires to modify the the manage.py. Note that the Meta class can be used for a lot more things, like the ordering of objects for example. Here is the bookmark module:

from django.db import models
from django.contrib.auth.models import User

from media.bookmarks import *

class Bookmark(models.Model):
    title = models.CharField(max_length = 200)
    user = models.ForeignKey(User)
    link = models.ForeignKey(Link)

    def __str(self):
        return "%s, %s" % (self.user.username, self.link.url)

    class Meta:
        app_label = 'bookmarks'

Another thing that should be done is to add the following import lines in the __init__.py, this way the manage.py can find your classes and you can import your model classes as you did previously:

from bookmarks import Bookmark
from link import Link
from sharedbookmark import SharedBookmark
from tag import Tag

The same for the views, I use the * here since I want to import every function from the modules but you can define the function names there:

from authentication import *
from registration import *
from search import *

Of course the admin.py and the forms.py modules can be organized in the same way.

The concept of django applications is to be small and focused on certain and related functionality so that they can be plugged in different projects without tweaking and maybe that is the reason that the code is organized in a simple modules instead of packages.  But I think this way the application looks cleaner and more manageable even for the small ones, or maybe I have been exposed to Java for a long time and it looks more like a Java application…

Enjoy!