commit: UI improved

changeset:   1218:e20155e77a9b
user:        Thomas Gambet <tgambet@w3.org>
date:        Sat Jun 12 23:39:33 2010 -0400
files:       src/org/w3c/unicorn/action/InitAction.java
description:
UI improved


diff -r 7241f9c88845 -r e20155e77a9b src/org/w3c/unicorn/action/InitAction.java
--- a/src/org/w3c/unicorn/action/InitAction.java	Sat Jun 12 23:39:11 2010 -0400
+++ b/src/org/w3c/unicorn/action/InitAction.java	Sat Jun 12 23:39:33 2010 -0400
@@ -2,15 +2,20 @@
 
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.util.ArrayList;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.velocity.VelocityContext;
 import org.w3c.unicorn.Framework;
 import org.w3c.unicorn.exceptions.InitializationFailedException;
-import org.w3c.unicorn.util.Property;
+import org.w3c.unicorn.util.Language;
+import org.w3c.unicorn.util.Templates;
+
+import com.ibm.icu.util.ULocale;
 
 /**
  * Servlet implementation class InitAction
@@ -30,14 +35,23 @@
 	 */
 	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 		
-		// If PROPERTY_INIT_ACTION is not set or set to true, InitAction is only accessible from localhost.
-		// If PROPERTY_INIT_ACTION is set to false, any IP can initialize Unicorn. This should not be set in production environment.
-		String isProtected = Property.get("PROTECT_INIT_ACTION");
-		if ((isProtected == null || isProtected.equals("true")) && (request.getRemoteAddr().equals("0:0:0:0:0:0:0:1") || request.getRemoteAddr().equals("127.0.0.1"))
-				|| (isProtected != null && isProtected.equals("false"))) {
+		String task = request.getParameter("task"); 
+		PrintWriter out = response.getWriter();
+		
+		if (task == null) {
+			response.setContentType("text/html; charset=UTF-8");
+			VelocityContext velocityContext = new VelocityContext(Language.getContext(Language.getDefaultLocale()));
+			velocityContext.put("baseUri", "./");
+			velocityContext.put("user", request.getRemoteUser());
+			ArrayList<ULocale> languages = new ArrayList<ULocale>();
+			languages.add(Language.getDefaultLocale());
+			velocityContext.put("languages", languages);
+			
+			Templates.write("init.vm", velocityContext, out);
+		} else {
 			response.setContentType("text/plain");
-			PrintWriter out = response.getWriter();
-			String task = request.getParameter("task"); 
+			
+			
 			
 			if (task == null || task.equals("all")) {
 				
@@ -165,8 +179,5 @@
 			
 			out.close();
 		}
-		else
-			response.sendError(403, "You are not allowed to execute this action.");
 	}
-	
 }

Received on Monday, 14 June 2010 13:25:15 UTC