All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cat.inspiracio.orange.OrangeServlet Maven / Gradle / Ivy

Go to download

Orange Servlet provides HTML templating with server-side Java. OrangeServlet is a servlet that is registered on *.html. It reads the html file at the right location according to URL. It renders the file as html, executing some scripting: * data-if="E" attributes for server-side conditional, * data-for="T x : E" attributes for server-side loops, * data-import="C" attributes for server-side class imports, * data-substitute="file.html" substitute an element with the processed contents of a file, * ${expressions} in element bodies and attribute values.

There is a newer version: 5.0.0
Show newest version
package cat.inspiracio.orange;

import java.io.IOException;

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

import cat.inspiracio.servlet.jsp.ServletPageContext;
import cat.inspiracio.util.Timber;

/** For requests to orange templates. */
public class OrangeServlet extends HttpServlet{
	private static final long serialVersionUID = -1871765722924200945L;

	@Override protected void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
		try{
			response.setContentType("text/html; charset=utf-8");
			
			Template t=template(request, response);	
			t.write();//Exception, may be anything from the Java-islands
			
			String timber=Timber.string();
			if(0");
		}
		
		catch(ClassNotFoundException e){
			error(request, 404, e);
			response.sendError(404);
		}
		
		catch(Exception e){
			error(request, 500, e);
			response.sendError(500);
		}
		
	}

	// helpers ---------------------------------------------------------
	
	private Template template(HttpServletRequest request, HttpServletResponse response) throws ClassNotFoundException, InstantiationException, IllegalAccessException{
	
		//Get reflection out of request time: can we cache this?
		String fqcn=fully(request);
		@SuppressWarnings("unchecked")
		Class