labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simo...@apache.org
Subject svn commit: r747999 - in /labs/magma/trunk: foundation-website/src/main/java/org/apache/magma/website/ foundation-website/src/main/java/org/apache/magma/website/producers/ foundation-website/src/main/java/org/apache/magma/website/utils/ foundation-webs...
Date Thu, 26 Feb 2009 04:07:20 GMT
Author: simoneg
Date: Thu Feb 26 04:07:20 2009
New Revision: 747999

URL: http://svn.apache.org/viewvc?rev=747999&view=rev
Log:
LABS-301 : new on demand binder

Added:
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/OnDemandBinder.java
Modified:
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/HandlerSetup.aj
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ProducerParameters.java
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/DefaultExpectations.java
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/WebHandlerCycleTest.java
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/templating/TemplatingTest.java
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/SimpleWebHandler.java
    labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/SmartList.java
    labs/magma/trunk/website-developer/src/main/java/org/apache/magma/website/developer/DeveloperHandler.java

Modified: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/HandlerSetup.aj
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/HandlerSetup.aj?rev=747999&r1=747998&r2=747999&view=diff
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/HandlerSetup.aj
(original)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/HandlerSetup.aj
Thu Feb 26 04:07:20 2009
@@ -16,11 +16,13 @@
  */
 package org.apache.magma.website;
 
-import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
 import org.apache.commons.fileupload.FileItem;
 import org.apache.commons.fileupload.FileItemFactory;
 import org.apache.commons.fileupload.FileUploadException;
@@ -28,16 +30,11 @@
 import org.apache.commons.fileupload.servlet.ServletFileUpload;
 import org.apache.magma.basics.MagmaException;
 import org.apache.magma.beans.MagmaBeanSupport;
-import org.apache.magma.conversion.Converter;
-import org.apache.magma.conversion.Converters;
-import org.apache.magma.website.utils.Binder;
+import org.apache.magma.website.utils.OnDemandBinder;
+import org.apache.magma.website.utils.OnDemandBinder.Interaction;
+import org.aspectj.lang.reflect.FieldSignature;
 import org.apache.magma.website.context.Contextualizer;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.aspectj.lang.reflect.MethodSignature;
-
 
 public aspect HandlerSetup percflow(inRequest()) {
 
@@ -47,20 +44,18 @@
 
 	public pointcut inRequest() : execution(public void Dispatch+.doGet(..)) || execution(public
void Dispatch+.doPost(..)); 
 	
-	private HttpServletRequest request = null;
-	private HttpServletResponse response = null;
-	private Map<String, FileItem[]> uploads = null;
+	private OnDemandBinder binder = null;
 	
 	before(HttpServletRequest req, HttpServletResponse resp) : 
 		inRequest() &&
 		args(req, resp) {
-		this.request = req;
-		if (ServletFileUpload.isMultipartContent(request)) {
+		Map<String, FileItem[]> uploads = null;
+		if (ServletFileUpload.isMultipartContent(req)) {
 			FileItemFactory factory = new DiskFileItemFactory();
 			ServletFileUpload upload = new ServletFileUpload(factory);
 			List<FileItem> uploaditems;
 			try {
-				uploaditems = upload.parseRequest(request);
+				uploaditems = upload.parseRequest(req);
 			} catch (FileUploadException e) {
 				throw new MagmaException(e, "Error while parsing uploaded files");
 			}
@@ -79,17 +74,44 @@
 					}
 				}
 			}
-		}		
-		this.response = resp;
+		}
+		binder = new OnDemandBinder(req, resp, uploads);
 	}
 	
-	private boolean WebHandler.inuse = false;
-	private boolean WebHandler.inited = false;
-	
 	public pointcut subHandle(WebHandler h) : execution(public WebHandler+ WebHandler+.handle*(..))
&& this(h);
 	public pointcut doMethod(WebHandler h) : execution(public Producer+ WebHandler+.do*(..))
&& this(h);
 	public pointcut hiddenMethod(WebHandler h) : execution(public Producer+ WebHandler+.hidden*(..))
&& this(h);
 	
+	pointcut fetching(WebHandler h) : 
+		(get(private * WebHandler+.*) || get(protected * WebHandler+.*)) 
+		&& target(h)
+		&& !withincode(WebHandler+.new(..));
+	
+	Object around(WebHandler h) : fetching(h) {
+		FieldSignature sign = (FieldSignature)thisJoinPointStaticPart.getSignature();
+		String element = sign.getName();
+		Interaction inter = OnDemandBinder.interactsWith(element);
+		if (inter == null) return proceed(h);
+		Class type = sign.getFieldType();
+		String unique = Integer.toString(h.getRelativePath().hashCode());
+		return binder.fetch(element, type, inter, unique);
+	}
+	
+	pointcut storing(WebHandler h, Object value) : 
+		(set(private * WebHandler+.*) || set(protected * WebHandler+.*)) 
+		&& target(h)
+		&& args(value)
+		&& !withincode(WebHandler+.new(..));		
+	
+	after(WebHandler h, Object value) : storing(h, value) {
+		String element = thisJoinPointStaticPart.getSignature().getName();
+		Interaction inter = OnDemandBinder.interactsWith(element);
+		if (inter == null) return;
+		String unique = Integer.toString(h.getRelativePath().hashCode());
+		binder.store(element, value, inter, unique);		
+	}
+	
+	/*
 	Object around (WebHandler h) : (doMethod(h) || subHandle(h) || hiddenMethod(h)) {
 		Object retObj = null;
 		if (!h.inited) {
@@ -117,6 +139,6 @@
 		}
 		return retObj;
 	}
-
+	*/
 		
 }

Modified: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ProducerParameters.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ProducerParameters.java?rev=747999&r1=747998&r2=747999&view=diff
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ProducerParameters.java
(original)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ProducerParameters.java
Thu Feb 26 04:07:20 2009
@@ -16,16 +16,12 @@
  */
 package org.apache.magma.website.producers;
 
-import org.apache.magma.beans.BeanData;
-import org.apache.magma.beans.BeanHandler;
-import org.apache.magma.beans.PropertyInfo;
-import org.apache.magma.website.WebHandler;
-
 import java.beans.Introspector;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Set;
+
+import org.apache.magma.website.WebHandler;
 
 public class ProducerParameters {
 
@@ -54,18 +50,7 @@
 	}
 	
 	public void setHandler(WebHandler h) {
-		BeanHandler bh = h.handler();
-		BeanData bd = h.beanData();
-		
-		Set<String> names = bd.getPropertyNames();
-		for (String name : names) {
-			PropertyInfo pi = bd.getProperty(name);
-			if (pi.isReadable()) {
-				Object value = bh.getValue(name);
-				parameters.put(name, value);
-			}
-		}
-		
+		addParameter("magmaHandler", h);
 	}	
 	
 	

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/OnDemandBinder.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/OnDemandBinder.java?rev=747999&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/OnDemandBinder.java
(added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/OnDemandBinder.java
Thu Feb 26 04:07:20 2009
@@ -0,0 +1,267 @@
+package org.apache.magma.website.utils;
+
+import java.beans.Introspector;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.apache.commons.fileupload.FileItem;
+import org.apache.magma.conversion.Converter;
+import org.apache.magma.conversion.Converters;
+
+public class OnDemandBinder {
+
+	private HttpServletRequest req;
+	private HttpServletResponse resp;
+	private Map<String, FileItem[]> uploads;
+	
+	private HttpSession session;
+	private Cookie[] cookies;
+	private Set<String> cleanedCookies = null;
+	
+	private Map<String, Object> unconvertedSession = new HashMap<String, Object>();
+	
+	public enum Interaction {
+		session,
+		request,
+		header,
+		cookie,
+		param,
+		allParams
+	}
+	
+	public OnDemandBinder(HttpServletRequest req, HttpServletResponse resp, Map<String, FileItem[]>
uploads) {
+		this.req = req;
+		this.resp = resp;
+		this.uploads = uploads;
+	}
+
+	public Object fetch(String element, Class type, Interaction interaction, String unique)
{
+		String rawname = fromJavaName(element, interaction.name().length(), unique);
+		switch (interaction) {
+		case session:
+			return fetchSession(rawname, type);
+		case cookie:
+			return fetchCookie(rawname, type);
+		case header:
+			return fetchHeader(rawname, type);
+		case param:
+			return fetchParam(rawname, type);
+		case request:
+			return fetchRequest(rawname, type);
+		case allParams:
+			return fetchAllParams();
+		default:
+			throw new IllegalArgumentException("Not an HTTP context field");
+		}
+	}
+
+	private Object fetchAllParams() {
+		if (uploads == null) {
+			return req.getParameterMap();
+		} else {
+			Map<String, String[]> params = new HashMap<String, String[]>();
+			for (Map.Entry<String, FileItem[]> entry : uploads.entrySet()) {
+				FileItem[] items = entry.getValue();
+				if (items[0].isFormField()) {
+					String[] vals = new String[items.length];
+					for (int i = 0; i < vals.length; i++) {
+						//try {
+							vals[i] = items[i].getString();
+						//} catch (UnsupportedEncodingException e) {}
+					}
+					params.put(entry.getKey(), vals);
+				}
+			}
+			return params;
+		}
+	}
+
+	private Object fetchRequest(String rawname, Class type) {
+		return req.getAttribute(rawname);
+	}
+
+	private Object fetchParam(String rawname, Class type) {
+		if (uploads != null) {
+			FileItem[] item = uploads.get(rawname);
+			if (item != null) {
+				if (item[0].isFormField()) {
+					return convertFetch(item[0].getString(), type);
+				} else {
+					return item[0];
+				}
+			} else {
+				return null;
+			}
+		} else {
+			return convertFetch(req.getParameter(rawname), type);
+		}
+	}
+
+	private Object fetchHeader(String rawname, Class type) {
+		return convertFetch(req.getHeader(rawname), type);
+	}
+
+	private Object fetchCookie(String rawname, Class type) {
+		if (cleanedCookies != null && cleanedCookies.contains(rawname)) return null;
+		
+		if (cookies == null)
+			cookies = req.getCookies();
+		if (cookies == null) return null;
+		
+		for (Cookie cookie : cookies) {
+			if (cookie.getName().equals(rawname)) {
+				return convertFetch(cookie.getValue(), type);
+			}
+		}
+		return null;
+	}
+
+	public Object fetchSession(String rawname, Class type) {
+		if (session == null) {
+			session = req.getSession();
+		}
+		if (session == null) return null;
+		Object ret = unconvertedSession.get(rawname);
+		if (ret != null) return ret;
+		ret = convertFetch(session.getAttribute(rawname), type);
+		unconvertedSession.put(rawname, ret);
+		return ret;
+	}
+
+	public static Interaction interactsWith(String element) {
+		for (Interaction ele : Interaction.values()) {
+			if (element.startsWith(ele.name())) return ele;
+		}
+		return null;
+	}
+	
+	private Object convertFetch(Object value, Class type) {
+		if (value != null && value instanceof String) {
+			Converter converter = Converters.getConverterFor(type);
+			if (converter != null) {
+				value = converter.fromString((String)value);
+			}
+		}		
+		return value;
+	}
+	
+	public String fromJavaName(String jn, int prefix, String unique) {
+		jn = jn.substring(prefix);
+		if (unique != null && jn.startsWith("Reserved")) {
+			jn = jn.substring(8);
+			jn = unique + jn;
+		}
+		if (!jn.startsWith("_")) {
+			jn = Introspector.decapitalize(jn);
+		} else {
+			jn = jn.substring(1);
+		}
+		jn = jn.replaceAll("__", "-");
+		return jn;
+	}
+	
+	public void store(String element, Object value, Interaction interaction, String unique)
{
+		String rawname = fromJavaName(element, interaction.name().length(), unique);
+		switch (interaction) {
+		case session:
+			storeSession(rawname, value);
+			return;
+		case cookie:
+			storeCookie(rawname, value);
+			return;
+		case header:
+			storeHeader(rawname, value);
+			return;
+		case param:
+			throw new IllegalArgumentException("Cannot store a param");
+		case request:
+			storeRequest(rawname, value);
+			return;
+		case allParams:
+			throw new IllegalArgumentException("Cannot store all params");
+		default:
+			throw new IllegalArgumentException("Not an HTTP context field");
+		}
+	}
+
+	private void storeRequest(String rawname, Object value) {
+		if (value != null) {
+			req.setAttribute(rawname, value);
+		} else {
+			req.removeAttribute(rawname);
+		}
+	}
+
+	private void storeHeader(String rawname, Object value) {
+		if (value != null) {
+			resp.setHeader(rawname, (String) convertStore(value));
+		}
+	}
+
+	private void storeCookie(String rawname, Object value) {
+		if (cookies == null)
+			cookies = req.getCookies();
+
+		if (cleanedCookies != null && cleanedCookies.contains(rawname)) {
+			cleanedCookies.remove(rawname);
+		}
+		
+		boolean found = false;
+		if (cookies != null) {		
+			for (Cookie cookie : cookies) {
+				if (cookie.getName().equals(rawname)) {
+					found = true;
+					break;
+				}
+			}
+		}
+		if (value != null) {
+			Cookie ncookie = new Cookie(rawname,(String) convertStore(value));
+			ncookie.setMaxAge(2592000);
+			ncookie.setPath("/");
+			resp.addCookie(ncookie);
+		} else if (found && value == null) {
+			Cookie ncookie = new Cookie(rawname,"");
+			ncookie.setMaxAge(0);
+			ncookie.setPath("/");
+			if (cleanedCookies == null) cleanedCookies = new HashSet<String>();
+			cleanedCookies.add(rawname);
+			resp.addCookie(ncookie);					
+		}
+	}
+
+	private void storeSession(String rawname, Object value) {
+		if (session == null) {
+			session = req.getSession(true);
+		}
+		if (session == null) return;
+		
+		if (value == null) {
+			unconvertedSession.remove(rawname);
+			session.removeAttribute(rawname);
+		} else {
+			unconvertedSession.put(rawname, value);
+			session.setAttribute(rawname, convertStore(value));
+		}
+	}
+	
+	private Object convertStore(Object value) {
+		if (value != null && !(value instanceof String)) {
+			Converter converter = Converters.getConverterFor(value.getClass());
+			if (converter != null) {
+				value = converter.toString(value);
+			}
+		}		
+		return value;
+	}
+	
+	
+	
+}

Modified: labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/DefaultExpectations.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/DefaultExpectations.java?rev=747999&r1=747998&r2=747999&view=diff
==============================================================================
--- labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/DefaultExpectations.java
(original)
+++ labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/DefaultExpectations.java
Thu Feb 26 04:07:20 2009
@@ -42,6 +42,7 @@
 		atMost(1).of(req).getContextPath(); will(returnValue(""));
 		atMost(1).of(req).getServletPath(); will(returnValue(""));
 		allowing(req).getSession(); will(returnValue(session));
+		allowing(req).getSession(true); will(returnValue(session));
 		allowing(req).getCookies(); will(returnValue(cookies));
 		allowing(req).getAttribute("cookieInvalidloggedIn"); will(returnValue(null));
 		one(req).setAttribute("__magma_url",path);
@@ -70,6 +71,7 @@
 		one(req).getContextPath(); will(returnValue(""));
 		one(req).getServletPath(); will(returnValue(""));			
 		allowing(req).getSession(); will(returnValue(session));
+		allowing(req).getSession(true); will(returnValue(session));
 		allowing(req).getAttribute("__magma_url"); will(returnValue(path));
 		one(req).setAttribute("__magma_url",path);
 		atMost(1).of(session).getAttribute("__magma_lastmain"); will(returnValue(null));						

Modified: labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/WebHandlerCycleTest.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/WebHandlerCycleTest.java?rev=747999&r1=747998&r2=747999&view=diff
==============================================================================
--- labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/WebHandlerCycleTest.java
(original)
+++ labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/WebHandlerCycleTest.java
Thu Feb 26 04:07:20 2009
@@ -62,10 +62,11 @@
 		assertSame(def.person, params[4]);
 		
 		ProducerParameters parameters = prod.getHPParameters();
-		Map<String, Object> parmap = parameters.getParameters();
-		assertTrue(parmap.containsKey("sessionName"));
-		assertTrue(parmap.containsKey("requestUser"));
-		assertTrue(parmap.containsKey("header_User__Agent"));
+		// This feature has been disabled, see LABS-301
+		//Map<String, Object> parmap = parameters.getParameters();
+		//assertTrue(parmap.containsKey("sessionName"));
+		//assertTrue(parmap.containsKey("requestUser"));
+		//assertTrue(parmap.containsKey("header_User__Agent"));
 		
 		assertTrue("Producer.isFrom is not returning true for the correct handler", prod.isFrom(SimpleWebHandler.class));
 		assertTrue("Producer.isFrom is not returning true for the root handler", prod.isFrom(RootWebHandler.class));
@@ -105,10 +106,11 @@
 		assertSame(def.person, params[4]);
 		
 		ProducerParameters parameters = prod.getHPParameters();
-		Map<String, Object> parmap = parameters.getParameters();
-		assertTrue(parmap.containsKey("sessionName"));
-		assertTrue(parmap.containsKey("requestUser"));
-		assertTrue(parmap.containsKey("header_User__Agent"));
+		// This feature has been disabled, see LABS-301
+//		Map<String, Object> parmap = parameters.getParameters();
+//		assertTrue(parmap.containsKey("sessionName"));
+//		assertTrue(parmap.containsKey("requestUser"));
+//		assertTrue(parmap.containsKey("header_User__Agent"));
 		
 		assertEquals("report", parameters.getTemplateName());
 	}
@@ -122,10 +124,6 @@
 		DefaultExpectations def = new DefaultExpectations() {{
 			one(session).setAttribute("__magma_lastmain","/test/report");
 			one(session).setAttribute("name", "resend2");
-			one(session).setAttribute("name", "test name");
-			allowing(resp).setHeader("User-Agent", "Mozilla");
-			allowing(resp).addCookie(with(any(Cookie.class)));
-			allowing(req).setAttribute("user", person);			
 		}};
 		def.setupDefaults("/test/resend2");
 		Dispatch disp = def.start();
@@ -146,12 +144,13 @@
 		assertEquals(1, ((Integer)params[2]).intValue());
 		assertEquals("yesterday", params[3]);
 		assertSame(def.person, params[4]);
-		
+	
 		ProducerParameters parameters = prod.getHPParameters();
-		Map<String, Object> parmap = parameters.getParameters();
-		assertTrue(parmap.containsKey("sessionName"));
-		assertTrue(parmap.containsKey("requestUser"));
-		assertTrue(parmap.containsKey("header_User__Agent"));
+		// This feature has been disabled, see LABS-301		
+//		Map<String, Object> parmap = parameters.getParameters();
+//		assertTrue(parmap.containsKey("sessionName"));
+//		assertTrue(parmap.containsKey("requestUser"));
+//		assertTrue(parmap.containsKey("header_User__Agent"));
 		
 		assertEquals("report", parameters.getTemplateName());
 	}
@@ -172,7 +171,7 @@
 		DefaultExpectations def = new DefaultExpectations() {{
 			one(session).removeAttribute("name");
 			never(resp).setHeader(with(equal("User-Agent")), with(any(String.class)));
-			one(req).setAttribute("cookieInvalidloggedIn", true);			
+			one(resp).addCookie((Cookie)with(allOf(hasProperty("name", equalTo("loggedIn")), hasProperty("maxAge",
equalTo(0)))));
 			one(req).removeAttribute("user");
 		}};
 		def.setupDefaults("/test/remove");
@@ -255,7 +254,6 @@
 	public void sessionConversion() throws Exception {
 		DefaultExpectations def = new DefaultExpectations() {{
 			one(session).setAttribute("user", "Simone");
-			one(session).getAttribute("user"); will(returnValue("Massimo"));			
 		}};
 		def.setupMinimal("/testSession/setUser");
 		Dispatch disp = def.start();		
@@ -277,8 +275,6 @@
 	@Test
 	public void compounding() throws Exception {
 		DefaultExpectations def = new DefaultExpectations() {{
-			one(session).setAttribute("user", "Massimo");
-			one(session).getAttribute("user"); will(returnValue("Massimo"));						
 		}};
 		def.setupMinimal("/testSession/compound");
 		Dispatch disp = def.start();		
@@ -299,8 +295,6 @@
 	@Test
 	public void resendLinks() throws Exception {
 		DefaultExpectations def = new DefaultExpectations() {{
-			one(session).setAttribute("user", "Massimo");
-			one(session).getAttribute("user"); will(returnValue("Massimo"));						
 		}};
 		UnitTestDispatch disp = new UnitTestDispatch();
 		disp.setTemplate(new SimpleTemplate());

Modified: labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/templating/TemplatingTest.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/templating/TemplatingTest.java?rev=747999&r1=747998&r2=747999&view=diff
==============================================================================
--- labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/templating/TemplatingTest.java
(original)
+++ labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/templating/TemplatingTest.java
Thu Feb 26 04:07:20 2009
@@ -43,7 +43,6 @@
 	public void simpleTemplateClean() throws Exception {
 		DefaultExpectations def = new DefaultExpectations() {{
 			one(session).setAttribute("user", "Simone");
-			one(session).getAttribute("user"); will(returnValue("Massimo"));						
 		}};
 		UnitTestDispatch disp = new UnitTestDispatch();
 		disp.setTemplate(new SimpleTemplate());
@@ -60,7 +59,6 @@
 	public void simpleTemplateI18n() throws Exception {
 		DefaultExpectations def = new DefaultExpectations() {{
 			one(session).setAttribute("user", "Simone");
-			one(session).getAttribute("user"); will(returnValue("Massimo"));						
 		}};
 		UnitTestDispatch disp = new UnitTestDispatch();
 		disp.setTemplate(new SimpleTemplate());
@@ -77,7 +75,6 @@
 		DefaultExpectations def = new DefaultExpectations() {{
 			one(session).getAttribute("__magma_lasttemplate"); will(returnValue(SimpleSecondTemplate.class));
 			one(session).setAttribute("user", "Simone");
-			one(session).getAttribute("user"); will(returnValue("Massimo"));						
 		}};
 		UnitTestDispatch disp = new UnitTestDispatch();
 		disp.setTemplate(new SimpleTemplate());
@@ -94,7 +91,6 @@
 			one(session).getAttribute("__magma_lasttemplate"); will(returnValue(SimpleSecondTemplate.class));
 			one(session).getAttribute("__magma_lastmain"); will(returnValue("/testSession/setUser"));
 			one(session).setAttribute("user", "Simone");
-			one(session).getAttribute("user"); will(returnValue("Massimo"));						
 		}};
 		UnitTestDispatch disp = new UnitTestDispatch();
 		disp.setTemplate(new SimpleTemplate());
@@ -111,7 +107,6 @@
 		DefaultExpectations def = new DefaultExpectations() {{
 			one(session).getAttribute("__magma_lastmain"); will(returnValue("/testSession/setUser"));
 			one(session).setAttribute("user", "Simone");
-			one(session).getAttribute("user"); will(returnValue("Massimo"));						
 		}};
 		UnitTestDispatch disp = new UnitTestDispatch();
 		disp.setTemplate(new SimpleTemplate());
@@ -125,8 +120,6 @@
 	@Test
 	public void simpleTemplateWithSideCompound() throws Exception {
 		DefaultExpectations def = new DefaultExpectations() {{
-			one(session).setAttribute("user", "Massimo");
-			one(session).getAttribute("user"); will(returnValue("Massimo"));						
 		}};
 		UnitTestDispatch disp = new UnitTestDispatch();
 		disp.setTemplate(new SimpleTemplate());

Modified: labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/SimpleWebHandler.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/SimpleWebHandler.java?rev=747999&r1=747998&r2=747999&view=diff
==============================================================================
--- labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/SimpleWebHandler.java
(original)
+++ labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/SimpleWebHandler.java
Thu Feb 26 04:07:20 2009
@@ -22,61 +22,28 @@
 public class SimpleWebHandler extends WebHandler {
 
 	private String sessionName;
-	private String headerUser_Agent;
+	private String header_User__Agent;
 	private int paramPage;
 	private String cookieLoggedIn;
-	private Person user;
-	
-	public String getSessionName() {
-		return sessionName;
-	}
-	public void setSessionName(String sessionName) {
-		this.sessionName = sessionName;
-	}
-	public String getHeader_User__Agent() {
-		return headerUser_Agent;
-	}
-	public void setHeader_User__Agent(String headerUser_Agent) {
-		this.headerUser_Agent = headerUser_Agent;
-	}
-	
-	public void setParamPage(int page) {
-		this.paramPage = page;
-	}
-	
-	public void setCookieLoggedIn(String li) {
-		this.cookieLoggedIn = li;
-	}
-	
-	public String getCookieLoggedIn() {
-		return cookieLoggedIn;
-	}
-	
-	public Person getRequestUser() {
-		return user;
-	}
-	public void setRequestUser(Person user) {
-		this.user = user;
-	}
-	
+	private Person requestUser;
 	
 	public HtmlProducer doReport() {
-		return new FakeHtmlProducer(sessionName, headerUser_Agent, paramPage, cookieLoggedIn, user);
+		return new FakeHtmlProducer(sessionName, header_User__Agent, paramPage, cookieLoggedIn,
requestUser);
 	}
 	
 	public HtmlProducer doChange() {
 		this.cookieLoggedIn = "loggedout";
-		this.headerUser_Agent = "M$IE";
+		this.header_User__Agent = "M$IE";
 		this.sessionName = "another name";
-		this.user = Person.getPerson("Massimo");
+		this.requestUser = Person.getPerson("Massimo");
 		return new FakeHtmlProducer();
 	}
 	
 	public HtmlProducer doRemove() {
 		this.cookieLoggedIn = null;
-		this.headerUser_Agent = null;
+		this.header_User__Agent = null;
 		this.sessionName = null;
-		this.user = null;
+		this.requestUser = null;
 		return new FakeHtmlProducer();
 	}
 	
@@ -86,7 +53,7 @@
 	}
 	
 	public HtmlProducer doUserEntered(Person user) {
-		this.user = user;
+		this.requestUser = user;
 		return new FakeHtmlProducer();
 	}
 	

Modified: labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/SmartList.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/SmartList.java?rev=747999&r1=747998&r2=747999&view=diff
==============================================================================
--- labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/SmartList.java
(original)
+++ labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/SmartList.java
Thu Feb 26 04:07:20 2009
@@ -39,8 +39,8 @@
 	private int start = 0;
 	private int len = 10;
 	
-	private String sorting = null;
-	private boolean desc = false;
+	private String sessionReservedSorting = null;
+	private boolean sessionReservedDesc = false;
 	
 	private String defaultSorting = null;
 	private boolean defaultDesc = false;
@@ -106,14 +106,14 @@
 		}
 		
 		StringBuilder acquery = new StringBuilder(this.query);
-		if (sorting == null && defaultSorting != null) {
-			sorting = defaultSorting;
-			desc = defaultDesc;
+		if (sessionReservedSorting == null && defaultSorting != null) {
+			sessionReservedSorting = defaultSorting;
+			sessionReservedDesc = defaultDesc;
 		}
-		if (sorting != null && (sortables != null && sortables.contains(sorting)))
{
+		if (sessionReservedSorting != null && (sortables != null && sortables.contains(sessionReservedSorting)))
{
 			BeanData bd = BeanData.getFor(this.myclass);
 			Node root = bd.getViewListTree(this.filter);
-			Node subnode = root.findById(sorting);
+			Node subnode = root.findById(sessionReservedSorting);
 			if (subnode != null && subnode instanceof FieldNode) {
 				String fieldJqlId = "x.";
 				List<PropertyInfo> parents = ((FieldNode)subnode).getLogicalPropertyParents();
@@ -125,7 +125,7 @@
 				fieldJqlId += ((FieldNode)subnode).getProperty().getName();
 				acquery.append(" ORDER BY ");
 				acquery.append(fieldJqlId);
-				if (desc) acquery.append(" DESC");
+				if (sessionReservedDesc) acquery.append(" DESC");
 			}
 		}
 		List list = db.query(myclass, start, len, acquery.toString(), this.queryParams);
@@ -135,8 +135,8 @@
 		producer.setLen(len);
 		producer.setStart(start);
 		producer.setCount(count);
-		producer.setSorting(sorting);
-		producer.setDesc(desc);
+		producer.setSorting(sessionReservedSorting);
+		producer.setDesc(sessionReservedDesc);
 		producer.setSortables(sortables);
 		producer.setLink("../" + this.linkUrl);
 		producer.setFilter(filter);
@@ -173,8 +173,8 @@
 
 	public HtmlProducer doSort(boolean desc, String field) {
 		field = field.replace('/', '-');
-		this.sorting = field;
-		this.desc = desc;
+		this.sessionReservedSorting = field;
+		this.sessionReservedDesc = desc;
 		return doShow();
 	}
 	
@@ -217,32 +217,12 @@
 		return this;
 	}
 	
-	public void setSessionReservedSorting(String sorting) {
-		this.sorting = sorting;
-	}
-	
-	public String getSessionReservedSorting() {
-		return this.sorting;
-	}
-	
 	public SmartList setSortingField(String field, boolean desc) {
 		this.defaultSorting = field;
 		this.defaultDesc = desc;
 		return this;
 	}
 	
-	public void setSessionReservedDesc(Boolean desc) {
-		if (desc == null) {
-			this.desc = false;
-		} else {
-			this.desc = desc;
-		}
-	}
-	
-	public Boolean getSessionReservedDesc() {
-		return this.desc;
-	}
-	
 	public SmartList setElementsPerPage(int len) {
 		this.len = len;
 		return this;

Modified: labs/magma/trunk/website-developer/src/main/java/org/apache/magma/website/developer/DeveloperHandler.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/website-developer/src/main/java/org/apache/magma/website/developer/DeveloperHandler.java?rev=747999&r1=747998&r2=747999&view=diff
==============================================================================
--- labs/magma/trunk/website-developer/src/main/java/org/apache/magma/website/developer/DeveloperHandler.java
(original)
+++ labs/magma/trunk/website-developer/src/main/java/org/apache/magma/website/developer/DeveloperHandler.java
Thu Feb 26 04:07:20 2009
@@ -49,12 +49,8 @@
 
 public class DeveloperHandler extends WebHandler {
 
-	private String url = null;
-	private Map<Long, BasicTracer> traces;
-	
-	public void setParamUrl(String url) {
-		this.url = url;
-	}
+	private String paramUrl = null;
+	private Map<Long, BasicTracer> sessionTraces;
 	
 	public I18nHandler handleI18n() {
 		return new I18nHandler();
@@ -72,27 +68,27 @@
 	}
 	
 	public HtmlProducer doShowSettings() {
-		if (!SettingsStats.contains(url)) {
-			throw new MagmaException("The url {0} is not in settings", url);
+		if (!SettingsStats.contains(paramUrl)) {
+			throw new MagmaException("The url {0} is not in settings", paramUrl);
 		}
 		InputStream instr = null;
-		boolean isxml = url.endsWith(".xml");
+		boolean isxml = paramUrl.endsWith(".xml");
 		try {
-			if (url.startsWith("URL ")) {
+			if (paramUrl.startsWith("URL ")) {
 				try {
-					URL rurl = new URL(url.substring(4));
+					URL rurl = new URL(paramUrl.substring(4));
 					instr = rurl.openStream();
 				} catch (MalformedURLException e) {
-					throw new MagmaException(e, "The url {0} is not valid", url);
+					throw new MagmaException(e, "The url {0} is not valid", paramUrl);
 				} catch (IOException e) {
-					throw new MagmaException(e, "Cannot open {0}", url);
+					throw new MagmaException(e, "Cannot open {0}", paramUrl);
 				}
-			} else if (url.startsWith("FILE ")) {
-				File f = new File(url.substring(5));
+			} else if (paramUrl.startsWith("FILE ")) {
+				File f = new File(paramUrl.substring(5));
 				try {
 					instr = new FileInputStream(f);
 				} catch (FileNotFoundException e) {
-					throw new MagmaException(e, "The file {0} does not exists", url);
+					throw new MagmaException(e, "The file {0} does not exists", paramUrl);
 				}
 			}
 			Properties prop = new Properties();
@@ -103,11 +99,11 @@
 					prop.load(instr);
 				}
 			} catch (InvalidPropertiesFormatException e) {
-				throw new MagmaException(e, "Invalid properties format in {0}", url);
+				throw new MagmaException(e, "Invalid properties format in {0}", paramUrl);
 			} catch (IOException e) {
-				throw new MagmaException(e, "Error reading from {0}", url);
+				throw new MagmaException(e, "Error reading from {0}", paramUrl);
 			}
-			return new VelocityHtmlProducer(prop, url);
+			return new VelocityHtmlProducer(prop, paramUrl);
 		} finally {
 			if (instr != null) {
 				try {
@@ -133,14 +129,6 @@
 		return new VelocityHtmlProducer(nd);
 	}
 	
-	public void setSessionTraces(Map<Long, BasicTracer> map) {
-		this.traces = map;
-	}
-	
-	public Map<Long, BasicTracer> getSessionTraces() {
-		return this.traces;
-	}
-	
 	public HtmlProducer doPanel() {
 		long traceid = installTrace();
 		VelocityHtmlProducer ret = new VelocityHtmlProducer();
@@ -152,18 +140,18 @@
 		TracingRequests tr = TracingRequests.aspectOf();
 		if (tr == null) return 0;
 		BasicTracer tracer = tr.getTracer();
-		if (this.traces == null) {
-			this.traces = new HashMap<Long, BasicTracer>();
+		if (this.sessionTraces == null) {
+			this.sessionTraces = new HashMap<Long, BasicTracer>();
 		}
 		long handle = System.currentTimeMillis();
-		while (this.traces.containsKey(handle)) handle++;
-		this.traces.put(handle, tracer);
-		if (this.traces.size() > 40) {
-			List<Long> ids = new ArrayList<Long>(this.traces.keySet());
+		while (this.sessionTraces.containsKey(handle)) handle++;
+		this.sessionTraces.put(handle, tracer);
+		if (this.sessionTraces.size() > 40) {
+			List<Long> ids = new ArrayList<Long>(this.sessionTraces.keySet());
 			Collections.sort(ids);
 			while (ids.size() > 30) {
 				Long id = ids.remove(0);
-				this.traces.remove(id);
+				this.sessionTraces.remove(id);
 			}
 		}
 		return handle;
@@ -171,7 +159,7 @@
 	
 	public HtmlProducer doShowTrace(long id) {
 		BasicTracer tracer = null;
-		if (this.traces != null) tracer = this.traces.get(id);
+		if (this.sessionTraces != null) tracer = this.sessionTraces.get(id);
 		if (tracer == null) return new StringHtmlProducer("The requested trace is not available");
 		tracer.reorder();
 		VelocityHtmlProducer ret = new VelocityHtmlProducer();



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


Mime
View raw message