labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simo...@apache.org
Subject svn commit: r793007 - in /labs/magma/trunk/foundation-website/src/main: java/org/apache/magma/website/ java/org/apache/magma/website/templating/ java/org/apache/magma/website/utils/ resources/org/apache/magma/website/
Date Fri, 10 Jul 2009 16:09:23 GMT
Author: simoneg
Date: Fri Jul 10 16:09:23 2009
New Revision: 793007

URL: http://svn.apache.org/viewvc?rev=793007&view=rev
Log:
LABS-386 : Nice exception display

Added:
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/NiceExceptionDisplay.aj
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/ExceptionProducer.java
    labs/magma/trunk/foundation-website/src/main/resources/org/apache/magma/website/exceptions.css
Modified:
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/templating/DefaultTemplate.java

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/NiceExceptionDisplay.aj
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/NiceExceptionDisplay.aj?rev=793007&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/NiceExceptionDisplay.aj
(added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/NiceExceptionDisplay.aj
Fri Jul 10 16:09:23 2009
@@ -0,0 +1,50 @@
+package org.apache.magma.website;
+
+import org.apache.magma.website.templating.Template;
+import org.apache.magma.website.utils.ExceptionProducer;
+
+public privileged aspect NiceExceptionDisplay {
+
+	//declare precedence : *, NiceExceptionDisplay;
+	
+	HtmlProducer around() : 
+			execution(public HtmlProducer+ WebHandler+.do*(..)) ||
+			execution(public HtmlProducer+ WebHandler+.hidden*(..))
+		{
+		
+		//try {
+			return proceed();
+		//} catch (Throwable t) {
+		//	ExceptionProducer ep = new ExceptionProducer();
+		//	ep.setException(t);
+		//	return ep;
+		//}
+		
+	}
+	/*
+    Producer around() :
+		execution(protected Producer Dispatch.findProducer(..))
+		{
+		//try {
+		return proceed();
+	//} catch (Throwable t) {
+	//	ExceptionProducer ep = new ExceptionProducer();
+	//	ep.setException(t);
+	//	return ep;
+	//}
+	    	
+	}
+	*/
+    	
+	void around(Template tpl) :
+		execution(public void Template+.layout*()) && this(tpl)
+	{
+		//try {
+			proceed(tpl);
+		//} catch (Throwable t) {
+		//	ExceptionProducer ep = new ExceptionProducer();
+		//	ep.setException(t);
+		//	tpl.always(ep);
+		//}
+	}
+}

Modified: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/templating/DefaultTemplate.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/templating/DefaultTemplate.java?rev=793007&r1=793006&r2=793007&view=diff
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/templating/DefaultTemplate.java
(original)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/templating/DefaultTemplate.java
Fri Jul 10 16:09:23 2009
@@ -18,8 +18,10 @@
 
 import java.io.IOException;
 import java.io.OutputStreamWriter;
+import java.lang.reflect.Method;
 
 import org.apache.magma.website.HtmlProducer;
+import org.apache.magma.website.WebHandler;
 
 
 public class DefaultTemplate extends Template {
@@ -54,8 +56,25 @@
 	@Override
 	protected void openWrapper(String zone, HtmlProducer producer, OutputStreamWriter osw) throws
IOException {
 		String clazz = "";
-		if (zone.equals("Right") || zone.equals("Left")) clazz = " boxes";
-		osw.write("<div id=\"" + producer.getCreatingHandler().getClass().getSimpleName() +
"-" + producer.getCreatingMethod().getName() + "\" class=\"" + producer.getCreatingHandler().getClass().getSimpleName()
+ clazz + "\">");
+		String generatedId = "";
+		WebHandler handler = producer.getCreatingHandler();
+		if (handler != null) {
+			generatedId += handler.getClass().getSimpleName() + "-";
+			clazz += handler.getClass().getSimpleName() + " ";
+		}
+		Method method = producer.getCreatingMethod();
+		if (method != null) {
+			generatedId += method.getName();
+		} else if (handler != null) {
+			generatedId = generatedId.substring(0, generatedId.length() - 1);
+		}
+		
+		
+		if (zone.equals("Right") || zone.equals("Left")) clazz += "boxes ";
+		
+		
+		
+		osw.write("<div id=\"" + generatedId + "\" class=\"" + clazz + "\">");
 		osw.write("<div>");
 	}
 	

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/ExceptionProducer.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/ExceptionProducer.java?rev=793007&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/ExceptionProducer.java
(added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/ExceptionProducer.java
Fri Jul 10 16:09:23 2009
@@ -0,0 +1,54 @@
+package org.apache.magma.website.utils;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.Writer;
+
+import org.apache.magma.basics.LocalizableString;
+import org.apache.magma.settings.Settings;
+import org.apache.magma.website.Head;
+import org.apache.magma.website.HtmlProducer;
+
+public class ExceptionProducer extends HtmlProducer {
+
+	private Throwable exception = null;
+	
+	@Override
+	public void head(Head head) {
+		head.addCss("magma:/common/exceptions.css");
+	}
+
+	@Override
+	public void produce(Writer writer) throws IOException {
+		writer.append("<div class=\"MagmaException\">");
+		writer.append("<h3>");
+		writer.append(new LocalizableString("An error has occurred"));
+		writer.append("</h3>");
+		writer.append("<p>");
+		writer.append(new LocalizableString("We are working to resolve the problem you encountered."));
+		writer.append("</p>");
+		if (Settings.isDeveloperEnv()) {
+			writer.append("<div class=\"stacktrace\">\n");			
+		} else {
+			writer.append("<!--\n");
+		}
+		PrintWriter pw = new PrintWriter(writer);
+		exception.printStackTrace(pw);
+		pw.flush();
+		if (Settings.isDeveloperEnv()) {
+			writer.append("\n</div>");			
+		} else {
+			writer.append("\n-->");
+		}		
+		writer.append("</div>");			
+	}
+
+	public Throwable getException() {
+		return exception;
+	}
+
+	public void setException(Throwable exc) {
+		this.exception = exc;
+	}
+
+}

Added: labs/magma/trunk/foundation-website/src/main/resources/org/apache/magma/website/exceptions.css
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/resources/org/apache/magma/website/exceptions.css?rev=793007&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/resources/org/apache/magma/website/exceptions.css
(added)
+++ labs/magma/trunk/foundation-website/src/main/resources/org/apache/magma/website/exceptions.css
Fri Jul 10 16:09:23 2009
@@ -0,0 +1,24 @@
+.MagmaException {
+	color: black;
+	border: 1px solid red;
+	background: #FFEEEE;
+}
+.MagmaException .stacktrace {
+	height: 1em;
+	overflow: hidden;
+	font-size: x-small;
+	border: 1px solid gray;
+	text-align: left;
+	text-decoration: none;
+	color: black;
+}
+
+.MagmaException .stacktrace:hover {
+	position: absolute;
+	background: #FFEEEE;
+	font-size: x-small;
+	white-space: pre;
+	z-index: 3000;
+	height: auto;
+	width: auto;
+}
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org


Mime
View raw message