2006/unicorn/src/org/w3c/unicorn/action ObserveAction.java,NONE,1.1.2.1 Error404Action.java,NONE,1.1.2.1 Action.java,NONE,1.1.2.1 IndexAction.java,NONE,1.1.2.1 RedirectAction.java,NONE,1.1.2.1

Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/action
In directory hutz:/tmp/cvs-serv19002/src/org/w3c/unicorn/action

Added Files:
      Tag: dev2
	ObserveAction.java Error404Action.java Action.java 
	IndexAction.java RedirectAction.java 
Log Message:
New project

--- NEW FILE: IndexAction.java ---
package org.w3c.unicorn.action;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Writer;
import java.nio.CharBuffer;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.app.VelocityEngine;
import org.eclipse.jdt.internal.compiler.codegen.CharArrayCache;
import org.w3c.unicorn.language.LanguageNegociator;
import org.w3c.unicorn.util.Property;

public class IndexAction extends Action{

	private static final long serialVersionUID = 1L;
	private static Logger logger = Logger.getLogger("Index");
	private VelocityContext velocityContext;
	
	@Override
	public void init() throws ServletException {
		super.init();
		velocityContext = new VelocityContext();
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		resp.setContentType("text/html");
		
		// Language negotiation ?
		String lang = req.getParameter("lang");
		if (lang == null) 
			lang = LanguageNegociator.negociate(req.getLocales());	
		velocityContext.put("lang", lang);

		
		// Contains a message ?
		
		// Is response cached ?
		File cachedIndex = new File(Property.get("PATH_TO_CACHE") + "index/index." + lang + ".html");
		logger.info(cachedIndex.getPath());
		logger.info("exists ?"+cachedIndex.exists());
		if (cachedIndex.exists()) {
			FileReader fr = new FileReader(cachedIndex);
			PrintWriter writer = resp.getWriter();
			char[] chararray = new char[8192];
			int readLength = 0;
			while((readLength = fr.read(chararray, 0, 8192)) > -1) {
				writer.write(chararray, 0, readLength);
			}
			fr.close();
			writer.close();
			//Writer writer = resp.getWriter();
			//FileReader fr = new FileReader(cachedIndex);
			//CharBuffer buffer = new Buffer;
			//char[] buffer = new CharA;
			//fr.read(buffer);
			//fr.close();
			//writer.write(buffer.toString());
		}
		
		// Else generate response
		/*Writer writer = resp.getWriter();
		
		IndexGenerator.aVelocityContext = new VelocityContext();
		
		aProperties.load(
				Property.getPropertyFileURL("velocity.properties").openStream()
		);

		aProperties.put(Velocity.FILE_RESOURCE_LOADER_PATH, Property
				.get("PATH_TO_TEMPLATES"));
		
		engine.init(aProperties);
		



		private static VelocityEngine engine = new VelocityEngine();*/
		
		
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}

	@Override
	protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}

--- NEW FILE: ObserveAction.java ---
package org.w3c.unicorn.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ObserveAction extends Action {

	public ObserveAction() {
		// TODO Auto-generated constructor stub
	}

	//@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub

	}

}

--- NEW FILE: Action.java ---
package org.w3c.unicorn.action;

import javax.servlet.http.HttpServlet;

public abstract class Action extends HttpServlet {
	
	private static final long serialVersionUID = 1L;

	/*public abstract void execute(HttpServletRequest request, HttpServletResponse response);*/
	
	/*public static Map<String, Class<Action>> actions;*/
	
	/*public static boolean isAction(String action) {
		if (actions.containsKey(action))
			return true;
		return false;
	}*/
	
	/*public static Action getAction(String action) {
		try {
			return actions.get(action).newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}*/

	//public abstract ResponsePage execute();
}

--- NEW FILE: Error404Action.java ---
package org.w3c.unicorn.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Error404Action extends Action {

	public Error404Action() {
		// TODO Auto-generated constructor stub
	}

	//@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub

	}

}

--- NEW FILE: RedirectAction.java ---
package org.w3c.unicorn.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RedirectAction extends Action {
	
	public RedirectAction(HttpServletRequest request) {
		
	}

	//@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		
	}
}

Received on Wednesday, 5 August 2009 10:38:34 UTC