tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject git commit: TAP5-1477: Stack assets should return 404 in stead of exception if they don't exist
Date Mon, 04 Nov 2013 22:58:42 GMT
Updated Branches:
  refs/heads/master c4ecab24f -> cf0485ec6


TAP5-1477: Stack assets should return 404 in stead of exception if they don't exist


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/cf0485ec
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/cf0485ec
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/cf0485ec

Branch: refs/heads/master
Commit: cf0485ec6c59021781a8e4eb7664a33f469e19cd
Parents: c4ecab2
Author: Howard M. Lewis Ship <hlship@apache.org>
Authored: Mon Nov 4 14:58:34 2013 -0800
Committer: Howard M. Lewis Ship <hlship@apache.org>
Committed: Mon Nov 4 14:58:34 2013 -0800

----------------------------------------------------------------------
 .../assets/JavaScriptStackAssembler.java        |  4 ++--
 .../assets/StackAssetRequestHandler.java        | 13 +++++++++++-
 .../javascript/JavaScriptStackSourceImpl.java   | 17 ++++++++++-----
 .../javascript/JavaScriptStackSource.java       | 22 +++++++++++++-------
 4 files changed, 41 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/cf0485ec/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/JavaScriptStackAssembler.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/JavaScriptStackAssembler.java
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/JavaScriptStackAssembler.java
index d63d71c..aa51c92 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/JavaScriptStackAssembler.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/JavaScriptStackAssembler.java
@@ -29,9 +29,9 @@ import java.io.IOException;
 public interface JavaScriptStackAssembler
 {
     /**
-     * Obtains th {@link org.apache.tapestry5.services.javascript.JavaScriptStack} by name,
and then
+     * Obtains the {@link org.apache.tapestry5.services.javascript.JavaScriptStack} by name,
and then
      * uses the {@link org.apache.tapestry5.services.assets.StreamableResourceSource} service
to
-     * obtain the assets, which are combined togethers.
+     * obtain the assets, which are combined together.
      * <p/>
      * Expects the {@linkplain org.apache.tapestry5.services.LocalizationSetter#setNonPersistentLocaleFromLocaleName(String)
non-persistent locale} to be set before invoking!
      */

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/cf0485ec/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java
index 614cf73..487fcf1 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java
@@ -23,6 +23,7 @@ import org.apache.tapestry5.services.Request;
 import org.apache.tapestry5.services.Response;
 import org.apache.tapestry5.services.assets.AssetRequestHandler;
 import org.apache.tapestry5.services.assets.StreamableResource;
+import org.apache.tapestry5.services.javascript.JavaScriptStackSource;
 import org.slf4j.Logger;
 
 import java.io.IOException;
@@ -46,18 +47,21 @@ public class StackAssetRequestHandler implements AssetRequestHandler
 
     private final JavaScriptStackAssembler javaScriptStackAssembler;
 
+    private final JavaScriptStackSource stackSource;
     private final Request request;
 
     public StackAssetRequestHandler(Logger logger, LocalizationSetter localizationSetter,
                                     ResourceStreamer resourceStreamer,
                                     OperationTracker tracker,
-                                    JavaScriptStackAssembler javaScriptStackAssembler, Request
request)
+                                    JavaScriptStackAssembler javaScriptStackAssembler,
+                                    JavaScriptStackSource stackSource, Request request)
     {
         this.logger = logger;
         this.localizationSetter = localizationSetter;
         this.resourceStreamer = resourceStreamer;
         this.tracker = tracker;
         this.javaScriptStackAssembler = javaScriptStackAssembler;
+        this.stackSource = stackSource;
         this.request = request;
     }
 
@@ -88,6 +92,13 @@ public class StackAssetRequestHandler implements AssetRequestHandler
         String localeName = matcher.group(2);
         final String stackName = matcher.group(3);
 
+        if (stackSource.findStack(stackName) == null)
+        {
+            logger.warn(String.format("JavaScript stack '%s' not found.", stackName));
+            return false;
+        }
+
+
         // Yes, I have a big regret that the JavaScript stack stuff relies on this global,
rather than
         // having it passed around properly.
 

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/cf0485ec/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/JavaScriptStackSourceImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/JavaScriptStackSourceImpl.java
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/JavaScriptStackSourceImpl.java
index 9c95703..a859a4d 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/JavaScriptStackSourceImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/JavaScriptStackSourceImpl.java
@@ -1,4 +1,4 @@
-// Copyright 2010 The Apache Software Foundation
+// Copyright 2010-2013 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -14,15 +14,15 @@
 
 package org.apache.tapestry5.internal.services.javascript;
 
-import java.util.List;
-import java.util.Map;
-
 import org.apache.tapestry5.func.F;
 import org.apache.tapestry5.ioc.util.AvailableValues;
 import org.apache.tapestry5.ioc.util.UnknownValueException;
 import org.apache.tapestry5.services.javascript.JavaScriptStack;
 import org.apache.tapestry5.services.javascript.JavaScriptStackSource;
 
+import java.util.List;
+import java.util.Map;
+
 public class JavaScriptStackSourceImpl implements JavaScriptStackSource
 {
     private final Map<String, JavaScriptStack> configuration;
@@ -34,15 +34,22 @@ public class JavaScriptStackSourceImpl implements JavaScriptStackSource
 
     public JavaScriptStack getStack(String name)
     {
-        JavaScriptStack stack = configuration.get(name);
+        JavaScriptStack stack = findStack(name);
 
         if (stack == null)
+        {
             throw new UnknownValueException(String.format("No JavaScriptStack with name '%s'.",
name),
                     new AvailableValues("Configured JavaScript stacks", configuration));
+        }
 
         return stack;
     }
 
+    public JavaScriptStack findStack(String name)
+    {
+        return configuration.get(name);
+    }
+
     public List<String> getStackNames()
     {
         return F.flow(configuration.keySet()).sort().toList();

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/cf0485ec/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptStackSource.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptStackSource.java
b/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptStackSource.java
index 54157de..f0b0684 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptStackSource.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptStackSource.java
@@ -1,4 +1,4 @@
-// Copyright 2010 The Apache Software Foundation
+// Copyright 2010-2013 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -14,14 +14,14 @@
 
 package org.apache.tapestry5.services.javascript;
 
-import java.util.List;
-
 import org.apache.tapestry5.ioc.annotations.UsesMappedConfiguration;
 import org.apache.tapestry5.ioc.util.UnknownValueException;
 
+import java.util.List;
+
 /**
  * Manages the available {@link JavaScriptStack}s, each of which has a unique name.
- * 
+ *
  * @since 5.2.0
  */
 @UsesMappedConfiguration(JavaScriptStack.class)
@@ -29,16 +29,24 @@ public interface JavaScriptStackSource
 {
     /**
      * Gets a stack by name (ignoring case).
-     * 
+     *
      * @return named stack
      * @throws UnknownValueException
-     *             if no such stack
+     *         if no such stack
      */
     JavaScriptStack getStack(String name);
 
     /**
+     * Gets a stack by name (ignoring case).
+     *
+     * @return named stack, or null if not found
+     * @since 5.4
+     */
+    JavaScriptStack findStack(String name);
+
+    /**
      * Returns the names of all stacks, in sorted order.
-     * 
+     *
      * @since 5.2.1
      */
     List<String> getStackNames();


Mime
View raw message