Skip to content

Instantly share code, notes, and snippets.

/**
* Copyright (C) 2011 Marko Lavikainen
*
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@contextfw
contextfw / JsTemplateProcessor.java
Created July 31, 2011 12:05
JsTemplateProcessor
import java.util.List;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.Text;
public class JsTemplateProcessor {
@contextfw
contextfw / MathQuestion.java
Created June 28, 2011 07:03
Example: Math question
public class MathQuestion extends Component {
@Element
private SimpleLabel answer = new SimpleLabel();
enum Operation {
ADDITION("+") {
@Override
public long calculate(long val1, long val2) {
@contextfw
contextfw / gist:1049718
Created June 27, 2011 20:12
Secure way to recover password
// NOTE. This example is extremely simplified and shows only the idea.
public interface AuthService {
boolean login(String username, String password);
/**
* 1. Generates random key
* 2. Sends key to given email if it was registered
* 3. Returns the generated key
@contextfw
contextfw / Chat.java
Created April 26, 2011 15:53
Example: Chat
public class Chat extends Component implements ChatServiceClient {
@Inject
private ChatService service;
private long lastAccess = -1;
@Element
public List<ChatMsg> messages() {
return service.getMessages();
@contextfw
contextfw / Chart.java
Created April 26, 2011 15:44
Example: Chart
public class Chart extends Component {
@Attribute
private String key1 = "Example 1";
@Attribute
private String key2 = "Example 2";
@Attribute
private int value1 = 100;
@Attribute
private int value2 = 200;
@contextfw
contextfw / EchoWriter.java
Created April 23, 2011 10:30
Example: Echo Write
public class EchoWriter extends Component {
@Inject
@Element
private SimpleLabel echo;
@ScriptElement(onUpdate=false)
public JsInit jsInit() {
return new JsInit(this);
}
@contextfw
contextfw / gist:883737
Created March 23, 2011 19:09
Idea for dynamic domain model in Java
public interface Struct {
<T> T get(FieldType<T> type);
<T> void set(FieldType<T> type, T value);
}
///////////////////////////////////////
public interface FieldType<T> {
String getFieldName();
Class<T> getType();
import scala.collection.mutable.MultiMap
import java.net.URLEncoder
import scala.collection.mutable.{HashMap, StringBuilder, HashSet}
import scala.collection.mutable.StringBuilder;
class LinkBuilder(path : String) {
private var attributes = new collection.mutable.HashMap[String, collection.mutable.Set[String]]() with collection.mutable.MultiMap[String, String];
override def toString() : String = {