labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simo...@apache.org
Subject svn commit: r762847 - in /labs/magma/trunk: foundation-website/src/main/java/org/apache/magma/website/ foundation-website/src/test/java/org/apache/magma/website/templating/ website-dojo-pack/src/main/java/org/apache/magma/dojo/ website-jquery/src/main/...
Date Tue, 07 Apr 2009 16:53:16 GMT
Author: simoneg
Date: Tue Apr  7 16:53:15 2009
New Revision: 762847

URL: http://svn.apache.org/viewvc?rev=762847&view=rev
Log:
LABS-336 : Expires is now in Producer

Modified:
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Dispatch.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Producer.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/ResourceProducer.java
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/templating/TemplatingTest.java
    labs/magma/trunk/website-dojo-pack/src/main/java/org/apache/magma/dojo/DojoWebHandler.java
    labs/magma/trunk/website-jquery/src/main/java/org/apache/magma/jquery/JQueryWebHandler.java

Modified: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Dispatch.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Dispatch.java?rev=762847&r1=762846&r2=762847&view=diff
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Dispatch.java
(original)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Dispatch.java
Tue Apr  7 16:53:15 2009
@@ -157,6 +157,9 @@
 	}
 	
 	public void handleAJAX(HtmlProducer producer, HttpServletRequest req, HttpServletResponse
resp) {
+		long expiry = producer.getExpires();
+		if (expiry == -1) expiry = 0;
+		resp.setDateHeader("Expires", System.currentTimeMillis() + expiry);
 		String contentType = producer.getMimeType();
 		if (contentType == null) contentType = "application/octet-stream";
 		if (contentType.startsWith("text")) {
@@ -245,10 +248,9 @@
 	}
 
 	public void handleRAW(Producer producer, HttpServletRequest req, HttpServletResponse resp)
{
-		if (producer instanceof ResourceProducer) {
-			long expiry = ((ResourceProducer)producer).expires();
-			resp.setDateHeader("Expires", System.currentTimeMillis() + expiry);
-		}
+		long expiry = producer.getExpires();
+		if (expiry == -1) expiry = 0;
+		resp.setDateHeader("Expires", System.currentTimeMillis() + expiry);
 		String contentType = producer.getMimeType();
 		if (contentType == null) contentType = "application/octet-stream";
 		if (contentType.startsWith("text")) {

Modified: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Producer.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Producer.java?rev=762847&r1=762846&r2=762847&view=diff
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Producer.java
(original)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Producer.java
Tue Apr  7 16:53:15 2009
@@ -25,6 +25,26 @@
 
 public abstract class Producer implements ContextOwner {
 
+	public static long
+	EXPIRES_UNSET = -1,
+	EXPIRES_NOW = 0,
+	EXPIRES_1_MIN = 60000,
+	EXPIRES_5_MIN = EXPIRES_1_MIN * 5,
+	EXPIRES_30_MIN = EXPIRES_1_MIN * 30,
+	EXPIRES_TOMORROW = EXPIRES_30_MIN * 48,
+	EXPIRES_1_WEEK = EXPIRES_TOMORROW * 7,
+	EXPIRES_NEVER = EXPIRES_TOMORROW * 1095;
+	
+	protected long expires = EXPIRES_UNSET;
+	
+	public long getExpires() {
+		return expires;
+	}
+	public void setExpires(long expires) {
+		this.expires = expires;
+	}
+		
+	
 	public Method getCreatingMethod() {
 		return RunningContext.get().getPreviousMethod();
 	}
@@ -37,6 +57,7 @@
 	
 	public abstract String getMimeType();
 	
+	
 	public boolean isFrom(Class<? extends WebHandler> handlerClass) {
 		WebHandler ach = this.getCreatingHandler();
 		while (ach != null) {

Modified: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/ResourceProducer.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/ResourceProducer.java?rev=762847&r1=762846&r2=762847&view=diff
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/ResourceProducer.java
(original)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/ResourceProducer.java
Tue Apr  7 16:53:15 2009
@@ -24,27 +24,16 @@
 
 public class ResourceProducer extends StreamProducer {
 
-	public static long
-	EXPIRES_NOW = 0,
-	EXPIRES_1_MIN = 60000,
-	EXPIRES_5_MIN = EXPIRES_1_MIN * 5,
-	EXPIRES_30_MIN = EXPIRES_1_MIN * 30,
-	EXPIRES_TOMORROW = EXPIRES_30_MIN * 48,
-	EXPIRES_1_WEEK = EXPIRES_TOMORROW * 7,
-	EXPIRES_NEVER = EXPIRES_TOMORROW * 1095;
-	
-	private long expires = EXPIRES_NOW;
-	
 	public ResourceProducer(String fileName) {
 		this.fileName = fileName;
 		URL url = getCreatingHandler().getClass().getResource(fileName);
 		if (url != null) {
 			if (url.toExternalForm().indexOf(".jar") != -1) {
-				setExpiry(EXPIRES_5_MIN);
+				setExpires(EXPIRES_5_MIN);
 			}
 		}
 		if (Settings.isProductionEnv()) {
-			setExpiry(EXPIRES_TOMORROW);			
+			setExpires(EXPIRES_TOMORROW);			
 		}
 	}
 	
@@ -52,13 +41,6 @@
 		return getCreatingHandler().getClass().getResource(fileName) != null; 
 	}
 
-	public long expires() {
-		return expires;
-	}
-	public void setExpiry(long expires) {
-		this.expires = expires;
-	}
-	
 	@Override
 	public void produce(OutputStream out) {
 		stream = getCreatingHandler().getClass().getResourceAsStream(fileName);

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=762847&r1=762846&r2=762847&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
Tue Apr  7 16:53:15 2009
@@ -18,6 +18,7 @@
 
 import static org.apache.magma.website.AssertStringStructure.assertStructure;
 
+import java.util.Date;
 import java.util.Locale;
 
 import org.apache.magma.website.DefaultExpectations;
@@ -57,6 +58,7 @@
 	public void simpleAjax() throws Exception {
 		DefaultExpectations def = new DefaultExpectations() {{
 			one(session).setAttribute("user", "Simone");
+			one(resp).setDateHeader(with(equal("Expires")), with(any(Long.class)));
 		}};
 		UnitTestDispatch disp = new UnitTestDispatch();
 		disp.setTemplate(new SimpleTemplate());

Modified: labs/magma/trunk/website-dojo-pack/src/main/java/org/apache/magma/dojo/DojoWebHandler.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/website-dojo-pack/src/main/java/org/apache/magma/dojo/DojoWebHandler.java?rev=762847&r1=762846&r2=762847&view=diff
==============================================================================
--- labs/magma/trunk/website-dojo-pack/src/main/java/org/apache/magma/dojo/DojoWebHandler.java
(original)
+++ labs/magma/trunk/website-dojo-pack/src/main/java/org/apache/magma/dojo/DojoWebHandler.java
Tue Apr  7 16:53:15 2009
@@ -1,7 +1,6 @@
 package org.apache.magma.dojo;
 
 import org.apache.magma.website.Producer;
-import org.apache.magma.website.ResourceProducer;
 import org.apache.magma.website.WebHandler;
 
 public class DojoWebHandler extends WebHandler {
@@ -10,9 +9,7 @@
 	public Producer doResource(String fileName) {
 		fileName = "/dojo-1.2.0/" + fileName;
 		Producer res = super.doResource(fileName);
-		if (res instanceof ResourceProducer) {
-			((ResourceProducer)res).setExpiry(ResourceProducer.EXPIRES_TOMORROW);
-		}
+		res.setExpires(Producer.EXPIRES_TOMORROW);
 		return res;
 	}
 	

Modified: labs/magma/trunk/website-jquery/src/main/java/org/apache/magma/jquery/JQueryWebHandler.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/website-jquery/src/main/java/org/apache/magma/jquery/JQueryWebHandler.java?rev=762847&r1=762846&r2=762847&view=diff
==============================================================================
--- labs/magma/trunk/website-jquery/src/main/java/org/apache/magma/jquery/JQueryWebHandler.java
(original)
+++ labs/magma/trunk/website-jquery/src/main/java/org/apache/magma/jquery/JQueryWebHandler.java
Tue Apr  7 16:53:15 2009
@@ -2,7 +2,6 @@
 
 import org.apache.magma.settings.Settings;
 import org.apache.magma.website.Producer;
-import org.apache.magma.website.ResourceProducer;
 import org.apache.magma.website.WebHandler;
 
 public class JQueryWebHandler extends WebHandler {
@@ -14,9 +13,7 @@
 			fileName += ".min";
 		}
 		Producer res = super.doResource(fileName);
-		if (res instanceof ResourceProducer) {
-			((ResourceProducer)res).setExpiry(ResourceProducer.EXPIRES_TOMORROW);
-		}
+		res.setExpires(Producer.EXPIRES_TOMORROW);
 		return res;
 	}	
 	



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


Mime
View raw message