]> source.dussan.org Git - vaadin-framework.git/commitdiff
Rename DependencyResource to PublishedFile (#10224) 00/300/3
authorLeif Åstrand <leif@vaadin.com>
Tue, 20 Nov 2012 13:24:46 +0000 (15:24 +0200)
committerLeif Åstrand <leif@vaadin.com>
Wed, 21 Nov 2012 08:45:02 +0000 (10:45 +0200)
Change-Id: I18bd5fbaba7d443cab0626ddd477626995b5f16a

client/src/com/vaadin/client/ApplicationConnection.java
server/src/com/vaadin/annotations/JavaScript.java
server/src/com/vaadin/annotations/StyleSheet.java
server/src/com/vaadin/server/AbstractCommunicationManager.java
server/src/com/vaadin/server/ServletPortletHelper.java
server/src/com/vaadin/server/VaadinPortlet.java
server/src/com/vaadin/server/VaadinServlet.java
shared/src/com/vaadin/shared/ApplicationConstants.java

index 4c3eaff6aa2f050c0916991007bab16e444162ba..4357e431b35b56cc3aeba21e9b38a1e7b4d5f86e 100644 (file)
@@ -2765,14 +2765,14 @@ public class ApplicationConnection {
             uidlUri = themeUri + uidlUri.substring(7);
         }
 
-        if (uidlUri.startsWith(ApplicationConstants.DEPENDENCY_PROTOCOL_PREFIX)) {
+        if (uidlUri.startsWith(ApplicationConstants.PUBLISHED_PROTOCOL_PREFIX)) {
             // getAppUri *should* always end with /
-            // substring *should* always start with / (dependency:///foo.bar
-            // without dependency://)
+            // substring *should* always start with / (published:///foo.bar
+            // without published://)
             uidlUri = ApplicationConstants.APP_PROTOCOL_PREFIX
-                    + ApplicationConstants.DEPENDENCY_RESOURCE_PREFIX
+                    + ApplicationConstants.PUBLISHED_FILE_PATH
                     + uidlUri
-                            .substring(ApplicationConstants.DEPENDENCY_PROTOCOL_PREFIX
+                            .substring(ApplicationConstants.PUBLISHED_PROTOCOL_PREFIX
                                     .length());
             // Let translation of app:// urls take care of the rest
         }
index 1a2fdf7583b18e180cc56932156cc1c66eccf2bb..95e74ddc1a1597979bee1172eb669b2afc64583e 100644 (file)
@@ -29,7 +29,7 @@ import com.vaadin.server.ClientConnector;
  * method for the corresponding client-side connector is invoked.
  * <p>
  * Absolute URLs including protocol and host are used as is on the client-side.
- * Relative urls are mapped to APP/CONNECTOR/[url] which are by default served
+ * Relative urls are mapped to APP/PUBLISHED/[url] which are by default served
  * from the classpath relative to the class where the annotation is defined.
  * <p>
  * Example: {@code @JavaScript( "http://host.com/file1.js", "file2.js"})} on the
index e1a9efd6964a24ef0e2863fc64d55a00a48e0024..18e78f3530c04b8968691b2089f97da6af229c17 100644 (file)
@@ -28,6 +28,10 @@ import com.vaadin.server.ClientConnector;
  * framework ensures the referenced style sheets are loaded before the init
  * method for the corresponding client-side connector is invoked.
  * <p>
+ * Absolute URLs including protocol and host are used as is on the client-side.
+ * Relative urls are mapped to APP/PUBLISHED/[url] which are by default served
+ * from the classpath relative to the class where the annotation is defined.
+ * <p>
  * Example: {@code @StyleSheet( "http://host.com/file1.css", "file2.css"})} on
  * the class com.example.MyConnector would load the file
  * http://host.com/file1.css as is and file2.css from /com/example/file2.css on
index b0199a3886289f31205fb4d091d9eb63842e9f03..731d83067e1de523a8ae0aa8b86c33b94d399fd3 100644 (file)
@@ -163,7 +163,7 @@ public abstract class AbstractCommunicationManager implements Serializable {
 
     private ClientConnector highlightedConnector;
 
-    private Map<String, Class<?>> dependencyResourceContexts = new HashMap<String, Class<?>>();
+    private Map<String, Class<?>> publishedFileContexts = new HashMap<String, Class<?>>();
 
     private Map<String, Map<String, StreamVariable>> pidToNameToStreamVariable;
 
@@ -1196,18 +1196,16 @@ public abstract class AbstractCommunicationManager implements Serializable {
                 JavaScript jsAnnotation = class1
                         .getAnnotation(JavaScript.class);
                 if (jsAnnotation != null) {
-                    for (String resource : jsAnnotation.value()) {
-                        scriptDependencies.add(registerDependency(resource,
-                                class1));
+                    for (String uri : jsAnnotation.value()) {
+                        scriptDependencies.add(registerDependency(uri, class1));
                     }
                 }
 
                 StyleSheet styleAnnotation = class1
                         .getAnnotation(StyleSheet.class);
                 if (styleAnnotation != null) {
-                    for (String resource : styleAnnotation.value()) {
-                        styleDependencies.add(registerDependency(resource,
-                                class1));
+                    for (String uri : styleAnnotation.value()) {
+                        styleDependencies.add(registerDependency(uri, class1));
                     }
                 }
             }
@@ -1286,18 +1284,18 @@ public abstract class AbstractCommunicationManager implements Serializable {
             URI uri = new URI(resourceUri);
             String protocol = uri.getScheme();
 
-            if (ApplicationConstants.DEPENDENCY_PROTOCOL_NAME.equals(protocol)) {
+            if (ApplicationConstants.PUBLISHED_PROTOCOL_NAME.equals(protocol)) {
                 // Strip initial slash
                 String resourceName = uri.getPath().substring(1);
-                return registerDependencyResource(resourceName, context);
+                return registerPublishedFile(resourceName, context);
             }
 
             if (protocol != null || uri.getHost() != null) {
                 return resourceUri;
             }
 
-            // Bare path interpreted as dependency resource
-            return registerDependencyResource(resourceUri, context);
+            // Bare path interpreted as published file
+            return registerPublishedFile(resourceUri, context);
         } catch (URISyntaxException e) {
             getLogger().log(Level.WARNING,
                     "Could not parse resource url " + resourceUri, e);
@@ -1305,24 +1303,23 @@ public abstract class AbstractCommunicationManager implements Serializable {
         }
     }
 
-    private String registerDependencyResource(String name, Class<?> context) {
-        synchronized (dependencyResourceContexts) {
-            // Add to map of names accepted by serveDependencyResource
-            if (dependencyResourceContexts.containsKey(name)) {
-                Class<?> oldContext = dependencyResourceContexts.get(name);
+    private String registerPublishedFile(String name, Class<?> context) {
+        synchronized (publishedFileContexts) {
+            // Add to map of names accepted by servePublishedFile
+            if (publishedFileContexts.containsKey(name)) {
+                Class<?> oldContext = publishedFileContexts.get(name);
                 if (oldContext != context) {
                     getLogger().warning(
-                            "Dependency " + name + " defined by both "
-                                    + context + " and " + oldContext
-                                    + ". Dependency from " + oldContext
+                            name + " published by both " + context + " and "
+                                    + oldContext + ". File from " + oldContext
                                     + " will be used.");
                 }
             } else {
-                dependencyResourceContexts.put(name, context);
+                publishedFileContexts.put(name, context);
             }
         }
 
-        return ApplicationConstants.DEPENDENCY_PROTOCOL_PREFIX + "/" + name;
+        return ApplicationConstants.PUBLISHED_PROTOCOL_PREFIX + "/" + name;
     }
 
     /**
@@ -2623,64 +2620,64 @@ public abstract class AbstractCommunicationManager implements Serializable {
     /**
      * Serve a connector resource from the classpath if the resource has
      * previously been registered by calling
-     * {@link #registerDependency(String, Class)}. Sending arbitrary files from
-     * the classpath is prevented by only accepting resource names that have
-     * explicitly been registered. Resources can currently only be registered by
-     * including a {@link JavaScript} or {@link StyleSheet} annotation on a
-     * Connector class.
+     * {@link #registerPublishedFile(String, Class)}. Sending arbitrary files
+     * from the classpath is prevented by only accepting resource names that
+     * have explicitly been registered. Resources can currently only be
+     * registered by including a {@link JavaScript} or {@link StyleSheet}
+     * annotation on a Connector class.
      * 
      * @param request
      * @param response
      * 
      * @throws IOException
      */
-    public void serveDependencyResource(VaadinRequest request,
+    public void servePublishedFile(VaadinRequest request,
             VaadinResponse response) throws IOException {
 
         String pathInfo = request.getPathInfo();
         // + 2 to also remove beginning and ending slashes
-        String resourceName = pathInfo
-                .substring(ApplicationConstants.DEPENDENCY_RESOURCE_PREFIX
+        String fileName = pathInfo
+                .substring(ApplicationConstants.PUBLISHED_FILE_PATH
                         .length() + 2);
 
-        final String mimetype = response.getService().getMimeType(resourceName);
+        final String mimetype = response.getService().getMimeType(fileName);
 
         // Security check: avoid accidentally serving from the UI of the
         // classpath instead of relative to the context class
-        if (resourceName.startsWith("/")) {
+        if (fileName.startsWith("/")) {
             getLogger().warning(
-                    "Dependency resource request starting with / rejected: "
-                            + resourceName);
-            response.sendError(HttpServletResponse.SC_NOT_FOUND, resourceName);
+                    "Published file request starting with / rejected: "
+                            + fileName);
+            response.sendError(HttpServletResponse.SC_NOT_FOUND, fileName);
             return;
         }
 
         // Check that the resource name has been registered
         Class<?> context;
-        synchronized (dependencyResourceContexts) {
-            context = dependencyResourceContexts.get(resourceName);
+        synchronized (publishedFileContexts) {
+            context = publishedFileContexts.get(fileName);
         }
 
         // Security check: don't serve resource if the name hasn't been
         // registered in the map
         if (context == null) {
             getLogger().warning(
-                    "Dependency resource request for unknown resource rejected: "
-                            + resourceName);
-            response.sendError(HttpServletResponse.SC_NOT_FOUND, resourceName);
+                    "Rejecting published file request for file that has not been published: "
+                            + fileName);
+            response.sendError(HttpServletResponse.SC_NOT_FOUND, fileName);
             return;
         }
 
         // Resolve file relative to the location of the context class
-        InputStream in = context.getResourceAsStream(resourceName);
+        InputStream in = context.getResourceAsStream(fileName);
         if (in == null) {
             getLogger().warning(
-                    resourceName + " defined by " + context.getName()
+                    fileName + " published by " + context.getName()
                             + " not found. Verify that the file "
                             + context.getPackage().getName().replace('.', '/')
-                            + '/' + resourceName
+                            + '/' + fileName
                             + " is available on the classpath.");
-            response.sendError(HttpServletResponse.SC_NOT_FOUND, resourceName);
+            response.sendError(HttpServletResponse.SC_NOT_FOUND, fileName);
             return;
         }
 
index 07218f9abd9fe23fd624531d560d1033f889b817..00fdccdeb7f508d8653dcb806136230d88a0f3c2 100644 (file)
@@ -100,9 +100,9 @@ class ServletPortletHelper implements Serializable {
         return hasPathPrefix(request, UPLOAD_URL_PREFIX);
     }
 
-    public static boolean isDependencyResourceRequest(VaadinRequest request) {
+    public static boolean isPublishedFileRequest(VaadinRequest request) {
         return hasPathPrefix(request,
-                ApplicationConstants.DEPENDENCY_RESOURCE_PREFIX + "/");
+                ApplicationConstants.PUBLISHED_FILE_PATH + "/");
     }
 
     public static boolean isUIDLRequest(VaadinRequest request) {
index caa15b7ffdb47063d5a183ed09734430a8c42713..ac2d81b202dc36aded0b718a29b243ab83ea4059 100644 (file)
@@ -311,7 +311,7 @@ public class VaadinPortlet extends GenericPortlet implements Constants {
      */
     @Deprecated
     protected enum RequestType {
-        FILE_UPLOAD, UIDL, RENDER, STATIC_FILE, APP, DUMMY, EVENT, ACTION, UNKNOWN, BROWSER_DETAILS, DEPENDENCY_RESOURCE, HEARTBEAT;
+        FILE_UPLOAD, UIDL, RENDER, STATIC_FILE, APP, DUMMY, EVENT, ACTION, UNKNOWN, BROWSER_DETAILS, PUBLISHED_FILE, HEARTBEAT;
     }
 
     /**
@@ -334,8 +334,8 @@ public class VaadinPortlet extends GenericPortlet implements Constants {
             } else if (ServletPortletHelper.isFileUploadRequest(vaadinRequest)) {
                 return RequestType.FILE_UPLOAD;
             } else if (ServletPortletHelper
-                    .isDependencyResourceRequest(vaadinRequest)) {
-                return RequestType.DEPENDENCY_RESOURCE;
+                    .isPublishedFileRequest(vaadinRequest)) {
+                return RequestType.PUBLISHED_FILE;
             } else if (ServletPortletHelper.isAppRequest(vaadinRequest)) {
                 return RequestType.APP;
             } else if (ServletPortletHelper.isHeartbeatRequest(vaadinRequest)) {
@@ -427,8 +427,8 @@ public class VaadinPortlet extends GenericPortlet implements Constants {
                     PortletCommunicationManager communicationManager = (PortletCommunicationManager) vaadinSession
                             .getCommunicationManager();
 
-                    if (requestType == RequestType.DEPENDENCY_RESOURCE) {
-                        communicationManager.serveDependencyResource(
+                    if (requestType == RequestType.PUBLISHED_FILE) {
+                        communicationManager.servePublishedFile(
                                 vaadinRequest, vaadinResponse);
                         return;
                     } else if (requestType == RequestType.HEARTBEAT) {
index 47c2944b10500637512d137384289c9635c10351..60f2fed123b231cf90b54d7ff563cd998cf28bc3 100644 (file)
@@ -301,8 +301,8 @@ public class VaadinServlet extends HttpServlet implements Constants {
             CommunicationManager communicationManager = (CommunicationManager) vaadinSession
                     .getCommunicationManager();
 
-            if (requestType == RequestType.DEPENDENCY_RESOURCE) {
-                communicationManager.serveDependencyResource(request, response);
+            if (requestType == RequestType.PUBLISHED_FILE) {
+                communicationManager.servePublishedFile(request, response);
                 return;
             } else if (requestType == RequestType.HEARTBEAT) {
                 communicationManager.handleHeartbeatRequest(request, response,
@@ -1085,7 +1085,7 @@ public class VaadinServlet extends HttpServlet implements Constants {
      */
     @Deprecated
     protected enum RequestType {
-        FILE_UPLOAD, BROWSER_DETAILS, UIDL, OTHER, STATIC_FILE, APP, DEPENDENCY_RESOURCE, HEARTBEAT;
+        FILE_UPLOAD, BROWSER_DETAILS, UIDL, OTHER, STATIC_FILE, APP, PUBLISHED_FILE, HEARTBEAT;
     }
 
     /**
@@ -1098,8 +1098,8 @@ public class VaadinServlet extends HttpServlet implements Constants {
     protected RequestType getRequestType(VaadinServletRequest request) {
         if (ServletPortletHelper.isFileUploadRequest(request)) {
             return RequestType.FILE_UPLOAD;
-        } else if (ServletPortletHelper.isDependencyResourceRequest(request)) {
-            return RequestType.DEPENDENCY_RESOURCE;
+        } else if (ServletPortletHelper.isPublishedFileRequest(request)) {
+            return RequestType.PUBLISHED_FILE;
         } else if (isBrowserDetailsRequest(request)) {
             return RequestType.BROWSER_DETAILS;
         } else if (ServletPortletHelper.isUIDLRequest(request)) {
index a5eb109cb6488ed4cdf3148189422b9a3f7c111c..61bb33521d197db8c26812df2c8b08b69ea2a493 100644 (file)
@@ -26,12 +26,12 @@ public class ApplicationConstants {
 
     public static final String HEARTBEAT_REQUEST_PATH = "HEARTBEAT/";
 
-    public static final String DEPENDENCY_RESOURCE_PREFIX = APP_REQUEST_PATH
-            + '/' + "DEPENDENCY";
+    public static final String PUBLISHED_FILE_PATH = APP_REQUEST_PATH
+            + '/' + "PUBLISHED";
 
     public static final String APP_PROTOCOL_PREFIX = "app://";
-    public static final String DEPENDENCY_PROTOCOL_NAME = "dependency";
-    public static final String DEPENDENCY_PROTOCOL_PREFIX = DEPENDENCY_PROTOCOL_NAME
+    public static final String PUBLISHED_PROTOCOL_NAME = "published";
+    public static final String PUBLISHED_PROTOCOL_PREFIX = PUBLISHED_PROTOCOL_NAME
             + "://";
     public static final String UIDL_SECURITY_TOKEN_ID = "Vaadin-Security-Key";