Skip to content

Commit

Permalink
Documentation & Code cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael authored and guillaumebort committed Oct 20, 2010
1 parent 66eed57 commit 0006804
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 128 deletions.
6 changes: 3 additions & 3 deletions framework/src/play/CorePlugin.java
Expand Up @@ -48,7 +48,7 @@ public static String computeApplicationStatus(boolean json) {
}
return o.toString();
}
StringBuffer dump = new StringBuffer();
StringBuffer dump = new StringBuffer(16);
for (PlayPlugin plugin : Play.plugins) {
try {
String status = plugin.getStatus();
Expand All @@ -57,7 +57,7 @@ public static String computeApplicationStatus(boolean json) {
dump.append("\n");
}
} catch (Throwable e) {
dump.append(plugin.getClass().getName() + ".getStatus() has failed (" + e.getMessage() + ")");
dump.append(plugin.getClass().getName()).append(".getStatus() has failed (").append(e.getMessage()).append(")");
}
}
return dump.toString();
Expand Down Expand Up @@ -117,7 +117,7 @@ public String getStatus() {
out.println("~~~~~~~~~~~~~~~");
out.println("Version: " + Play.version);
out.println("Path: " + Play.frameworkPath);
out.println("ID: " + (Play.id == null || Play.id.equals("") ? "(not set)" : Play.id));
out.println("ID: " + (Play.id == null || Play.id.isEmpty() ? "(not set)" : Play.id));
out.println("Mode: " + Play.mode);
out.println("Tmp dir: " + (Play.tmpDir == null ? "(no tmp dir)" : Play.tmpDir));
out.println();
Expand Down
36 changes: 21 additions & 15 deletions framework/src/play/Play.java
Expand Up @@ -40,7 +40,14 @@ public class Play {
*/
public enum Mode {

DEV, PROD;
/**
* Enable development-specific features, e.g. view the documentation at the URL {@literal "/@documentation"}.
*/
DEV,
/**
* Disable development-specific features.
*/
PROD;

public boolean isDev() {
return this == DEV;
Expand Down Expand Up @@ -89,7 +96,7 @@ public boolean isProd() {
/**
* All paths to search for files
*/
public static List<VirtualFile> roots = new ArrayList<VirtualFile>();
public static List<VirtualFile> roots = new ArrayList<VirtualFile>(16);
/**
* All paths to search for Java files
*/
Expand Down Expand Up @@ -121,19 +128,19 @@ public boolean isProd() {
/**
* The list of supported locales
*/
public static List<String> langs = new ArrayList<String>();
public static List<String> langs = new ArrayList<String>(16);
/**
* The very secret key
*/
public static String secretKey;
/**
* Play plugins
*/
public static List<PlayPlugin> plugins = new ArrayList<PlayPlugin>();
public static List<PlayPlugin> plugins = new ArrayList<PlayPlugin>(16);
/**
* Modules
*/
public static Map<String, VirtualFile> modules = new HashMap<String, VirtualFile>();
public static Map<String, VirtualFile> modules = new HashMap<String, VirtualFile>(16);
/**
* Framework version
*/
Expand All @@ -142,7 +149,6 @@ public boolean isProd() {
* Context path (when several application are deployed on the same host)
*/
public static String ctxPath = "";
// pv
static boolean firstStart = true;
public static boolean usePrecompiled = false;
public static boolean forceProd = false;
Expand Down Expand Up @@ -232,19 +238,19 @@ public static void init(File root, String id) {
// Build basic java source path
VirtualFile appRoot = VirtualFile.open(applicationPath);
roots.add(appRoot);
javaPath = new ArrayList<VirtualFile>();
javaPath = new ArrayList<VirtualFile>(2);
javaPath.add(appRoot.child("app"));
javaPath.add(appRoot.child("conf"));

// Build basic templates path
templatesPath = new ArrayList<VirtualFile>();
templatesPath = new ArrayList<VirtualFile>(2);
templatesPath.add(appRoot.child("app/views"));

// Main route file
routes = appRoot.child("conf/routes");

// Plugin route files
modulesRoutes = new HashMap<String, VirtualFile>();
modulesRoutes = new HashMap<String, VirtualFile>(16);

// Load modules
loadModules();
Expand Down Expand Up @@ -320,7 +326,7 @@ static void readConfiguration() {
for (Object key : configuration.keySet()) {
String value = configuration.getProperty(key.toString());
Matcher matcher = pattern.matcher(value);
StringBuffer newValue = new StringBuffer();
StringBuffer newValue = new StringBuffer(100);
while (matcher.find()) {
String jp = matcher.group(1);
String r;
Expand All @@ -341,7 +347,7 @@ static void readConfiguration() {
configuration.setProperty(key.toString(), newValue.toString());
}
// Include
Map toInclude = new HashMap();
Map toInclude = new HashMap(16);
for (Object key : configuration.keySet()) {
if (key.toString().startsWith("@include.")) {
try {
Expand Down Expand Up @@ -373,7 +379,7 @@ public static synchronized void start() {
// Need a new classloader
classloader = new ApplicationClassloader();
// Reload plugins
List<PlayPlugin> newPlugins = new ArrayList<PlayPlugin>();
List<PlayPlugin> newPlugins = new ArrayList<PlayPlugin>(16);
for (PlayPlugin plugin : plugins) {
if (plugin.getClass().getClassLoader().getClass().equals(ApplicationClassloader.class)) {
PlayPlugin newPlugin = (PlayPlugin) classloader.loadClass(plugin.getClass().getName()).getConstructors()[0].newInstance();
Expand All @@ -395,16 +401,16 @@ public static synchronized void start() {

// Locales
langs = Arrays.asList(configuration.getProperty("application.langs", "").split(","));
if (langs.size() == 1 && langs.get(0).trim().equals("")) {
langs = new ArrayList<String>();
if (langs.size() == 1 && langs.get(0).trim().length() == 0) {
langs = new ArrayList<String>(16);
}

// Clean templates
TemplateLoader.cleanCompiledCache();

// SecretKey
secretKey = configuration.getProperty("application.secret", "").trim();
if (secretKey.equals("")) {
if (secretKey.length() == 0) {
Logger.warn("No secret key defined. Sessions will not be encrypted");
}

Expand Down
8 changes: 4 additions & 4 deletions framework/src/play/cache/CacheFor.java
Expand Up @@ -6,14 +6,14 @@
import java.lang.annotation.Target;

/**
* Cache an action's result
* Example: @CacheFor("1h")
* Cache an action's result.
*
* <p>If a time is not specified, the results will be cached for 1 hour by default.
*
* <p>Example: <code>@CacheFor("1h")</code>
*/

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface CacheFor {
String value() default "1h";
}

20 changes: 14 additions & 6 deletions framework/src/play/cache/EhCacheImpl.java
Expand Up @@ -2,17 +2,27 @@

import java.util.HashMap;
import java.util.Map;
import play.Logger;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import play.Logger;

/**
* EhCache implementation
* EhCache implementation.
*
* <p>Ehcache is an open source, standards-based cache used to boost performance,
* offload the database and simplify scalability. Ehcache is robust, proven and
* full-featured and this has made it the most widely-used Java-based cache.</p>
*
* @see http://ehcache.org/
*/
public class EhCacheImpl implements CacheImpl {

private static EhCacheImpl uniqueInstance;

CacheManager cacheManager;

net.sf.ehcache.Cache cache;

private EhCacheImpl() {
this.cacheManager = CacheManager.create();
this.cacheManager.addCache("play");
Expand All @@ -25,8 +35,6 @@ public static EhCacheImpl getInstance() {
}
return uniqueInstance;
}
CacheManager cacheManager;
net.sf.ehcache.Cache cache;

public void add(String key, Object value, int expiration) {
if (cache.get(key) != null) {
Expand Down Expand Up @@ -62,7 +70,7 @@ public Object get(String key) {
}

public Map<String, Object> get(String[] keys) {
Map<String, Object> result = new HashMap<String, Object>();
Map<String, Object> result = new HashMap<String, Object>(keys.length);
for (String key : keys) {
result.put(key, get(key));
}
Expand Down Expand Up @@ -138,4 +146,4 @@ public void set(String key, Object value, int expiration) {
public void stop() {
cache.removeAll();
}
}
}
11 changes: 6 additions & 5 deletions framework/src/play/cache/MemcachedImpl.java
Expand Up @@ -6,11 +6,10 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamClass;
import java.util.HashMap;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import net.spy.memcached.AddrUtil;
import net.spy.memcached.MemcachedClient;
import net.spy.memcached.transcoders.SerializingTranscoder;
Expand All @@ -25,14 +24,16 @@ public class MemcachedImpl implements CacheImpl {

private static MemcachedImpl uniqueInstance;

MemcachedClient client;

SerializingTranscoder tc;

public static MemcachedImpl getInstance() throws IOException {
if (uniqueInstance == null) {
uniqueInstance = new MemcachedImpl();
}
return uniqueInstance;
}
MemcachedClient client;
SerializingTranscoder tc;

private MemcachedImpl() throws IOException {
tc = new SerializingTranscoder() {
Expand Down Expand Up @@ -112,7 +113,7 @@ public Map<String, Object> get(String[] keys) {
} catch (Exception e) {
future.cancel(false);
}
return new HashMap<String, Object>();
return Collections.<String, Object>emptyMap();
}

public long incr(String key, int by) {
Expand Down
12 changes: 6 additions & 6 deletions framework/src/play/libs/Images.java
Expand Up @@ -42,7 +42,7 @@ public class Images {
* @param w The new width (or -1 to proportionally resize)
* @param h The new height (or -1 to proportionally resize)
*/
public static void resize(File originalImage, File to, Integer w, Integer h) {
public static void resize(File originalImage, File to, int w, int h) {
try {
BufferedImage source = ImageIO.read(originalImage);
int owidth = source.getWidth();
Expand Down Expand Up @@ -99,7 +99,7 @@ public static void resize(File originalImage, File to, Integer w, Integer h) {
* @param x2 The new x end
* @param y2 The new y end
*/
public static void crop(File originalImage, File to, Integer x1, Integer y1, Integer x2, Integer y2) {
public static void crop(File originalImage, File to, int x1, int y1, int x2, int y2) {
try {
BufferedImage source = ImageIO.read(originalImage);

Expand Down Expand Up @@ -165,8 +165,8 @@ public static class Captcha extends InputStream {
public BackgroundProducer background = new TransparentBackgroundProducer();
public GimpyRenderer gimpy = new RippleGimpyRenderer();
public Color textColor = Color.BLACK;
public List<Font> fonts = new ArrayList<Font>();
public int w, h;
public List<Font> fonts = new ArrayList<Font>(2);
public int w, h;
public Color noise = null;

public Captcha(int w, int h) {
Expand Down Expand Up @@ -209,7 +209,7 @@ public String getText(String color, int length) {
public String getText(int length, String chars) {
char[] charsArray = chars.toCharArray();
Random random = new Random(System.currentTimeMillis());
StringBuffer sb = new StringBuffer();
StringBuffer sb = new StringBuffer(length);
for (int i = 0; i < length; i++) {
sb.append(charsArray[random.nextInt(charsArray.length)]);
}
Expand Down Expand Up @@ -303,4 +303,4 @@ void check() {
}
}
}
}
}

0 comments on commit 0006804

Please sign in to comment.