Repository: incubator-juneau
Updated Branches:
  refs/heads/master 5845d893b -> 82f0bd8ed


Add @RestResource.siteName() annotation

Project: http://git-wip-us.apache.org/repos/asf/incubator-juneau/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-juneau/commit/82f0bd8e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-juneau/tree/82f0bd8e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-juneau/diff/82f0bd8e

Branch: refs/heads/master
Commit: 82f0bd8ed299a72104549db69b153b1e48faddc2
Parents: 5845d89
Author: JamesBognar <[email protected]>
Authored: Mon Jul 10 11:39:37 2017 -0400
Committer: JamesBognar <[email protected]>
Committed: Mon Jul 10 11:39:37 2017 -0400

----------------------------------------------------------------------
 juneau-core/src/main/javadoc/overview.html      | 10 +++++-
 .../java/org/apache/juneau/rest/CallMethod.java |  2 ++
 .../org/apache/juneau/rest/RestContext.java     | 12 +++++++
 .../apache/juneau/rest/RestInfoProvider.java    | 37 +++++++++++++++++++-
 .../org/apache/juneau/rest/RestRequest.java     | 12 +++++++
 .../juneau/rest/annotation/RestResource.java    | 15 ++++++++
 6 files changed, 86 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/82f0bd8e/juneau-core/src/main/javadoc/overview.html
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/javadoc/overview.html 
b/juneau-core/src/main/javadoc/overview.html
index 4d612fe..a4e6420 100644
--- a/juneau-core/src/main/javadoc/overview.html
+++ b/juneau-core/src/main/javadoc/overview.html
@@ -6983,6 +6983,13 @@
                                                instead of separately on 
<ja>@RestResource</ja> and <ja>@RestMethod</ja> annotations.
                                        <li>
                                                {@link 
org.apache.juneau.rest.widget.Widget#getName()} now defaults to the simple 
class name.
+                                               <br>So now you can just refer 
to the class name: <js>"$W{ContentTypeMenuItem}"</js>.
+                                       <li>
+                                               Renamed widgets:
+                                               <ul>
+                                                       
<li><code>PoweredByApacheWidget</code> -&lt; <code>PoweredByApache</code>  
+                                                       
<li><code>PoweredByJuneauWidget</code> -&lt; <code>PoweredByJuneau</code>  
+                                               </ul>
                                        <li>
                                                New {@link 
org.apache.juneau.rest.widget.MenuItemWidget} can be used to create pull-down 
menu items.
                                        <li>
@@ -7021,6 +7028,7 @@
                        <li>
                                Annotations added:
                                <ul>
+                                       <li>{@link 
org.apache.juneau.rest.annotation.RestResource#siteName()}
                                        <li>{@link 
org.apache.juneau.rest.annotation.RestResource#flags()}
                                        <li>{@link 
org.apache.juneau.rest.annotation.RestMethod#flags()}
                                </ul>
@@ -7401,7 +7409,7 @@
                                New classes for widget support:
                                <ul>
                                        <li>{@link 
org.apache.juneau.rest.widget.Widget}
-                                       <li>{@link 
org.apache.juneau.rest.widget.PoweredByJuneauWidget}
+                                       
<li><code><del>PoweredByJuneauWidget</del></code>
                                        
<li><code><del>ContentTypeLinksColumnWidget</del></code>
                                        
<li><code><del>ContentTypeLinksRowWidget</del></code>
                                        <li><code><del>QueryWidget</del></code>

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/82f0bd8e/juneau-rest/src/main/java/org/apache/juneau/rest/CallMethod.java
----------------------------------------------------------------------
diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/CallMethod.java 
b/juneau-rest/src/main/java/org/apache/juneau/rest/CallMethod.java
index 3de1cb8..21c148c 100644
--- a/juneau-rest/src/main/java/org/apache/juneau/rest/CallMethod.java
+++ b/juneau-rest/src/main/java/org/apache/juneau/rest/CallMethod.java
@@ -894,6 +894,8 @@ class CallMethod implements Comparable<CallMethod>  {
                                                return req.getRequestURI();
                                        if (k.equals(REST_method))
                                                return req.getMethod();
+                                       if (k.equals(REST_siteName))
+                                               return req.getSiteName();
                                        if (k.equals(REST_servletTitle))
                                                return req.getServletTitle();
                                        if (k.equals(REST_servletDescription))

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/82f0bd8e/juneau-rest/src/main/java/org/apache/juneau/rest/RestContext.java
----------------------------------------------------------------------
diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/RestContext.java 
b/juneau-rest/src/main/java/org/apache/juneau/rest/RestContext.java
index 631e93d..f21d364 100644
--- a/juneau-rest/src/main/java/org/apache/juneau/rest/RestContext.java
+++ b/juneau-rest/src/main/java/org/apache/juneau/rest/RestContext.java
@@ -290,6 +290,18 @@ public final class RestContext extends Context {
        public static final String REST_method = "RestServlet.method";
 
        /**
+        * The localized site name.
+        *
+        * <p>
+        * Automatically added to properties returned by {@link 
SerializerSession#getProperty(String)} and
+        * {@link ParserSession#getProperty(String)}.
+        *
+        * <p>
+        * Equivalent to the value returned by {@link RestRequest#getSiteName()}
+        */
+       public static final String REST_siteName = "RestServlet.siteName";
+
+       /**
         * The localized servlet title.
         *
         * <p>

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/82f0bd8e/juneau-rest/src/main/java/org/apache/juneau/rest/RestInfoProvider.java
----------------------------------------------------------------------
diff --git 
a/juneau-rest/src/main/java/org/apache/juneau/rest/RestInfoProvider.java 
b/juneau-rest/src/main/java/org/apache/juneau/rest/RestInfoProvider.java
index 2b506f9..83818ef 100644
--- a/juneau-rest/src/main/java/org/apache/juneau/rest/RestInfoProvider.java
+++ b/juneau-rest/src/main/java/org/apache/juneau/rest/RestInfoProvider.java
@@ -45,6 +45,7 @@ public class RestInfoProvider {
 
        private final RestContext context;
        private final String
+               siteName,
                title,
                description,
                termsOfService,
@@ -64,6 +65,7 @@ public class RestInfoProvider {
                this.context = context;
 
                Builder b = new Builder(context);
+               this.siteName = b.siteName;
                this.title = b.title;
                this.description = b.description;
                this.termsOfService = b.termsOfService;
@@ -76,6 +78,7 @@ public class RestInfoProvider {
 
        private static class Builder {
                private String
+                       siteName,
                        title,
                        description,
                        termsOfService,
@@ -90,6 +93,8 @@ public class RestInfoProvider {
                        LinkedHashMap<Class<?>,RestResource> 
restResourceAnnotationsParentFirst = 
findAnnotationsMapParentFirst(RestResource.class, 
context.getResource().getClass());
 
                        for (RestResource r : 
restResourceAnnotationsParentFirst.values()) {
+                               if (! r.siteName().isEmpty())
+                                       siteName = r.siteName();
                                if (! r.title().isEmpty())
                                        title = r.title();
                                if (! r.description().isEmpty())
@@ -237,6 +242,36 @@ public class RestInfoProvider {
        }
 
        /**
+        * Returns the localized site name of this REST resource.
+        *
+        * <p>
+        * Subclasses can override this method to provide their own site name.
+        *
+        * <p>
+        * The default implementation returns the description from the 
following locations (whichever matches first):
+        * <ol>
+        *      <li>{@link RestResource#siteName() @RestResource.siteName()} 
annotation on this class, and then any parent classes.
+        *      <li><ck>[ClassName].siteName</ck> property in resource bundle 
identified by
+        *              {@link RestResource#messages() 
@ResourceBundle.messages()} annotation for this class, then any parent
+        *              classes.
+        *      <li><ck>siteName</ck> in resource bundle identified by {@link 
RestResource#messages() @RestResource.messages()}
+        *              annotation for this class, then any parent classes.
+        * </ol>
+        *
+        * @param req The current request.
+        * @return The localized description of this REST resource, or 
<jk>null</jk> if no resource description was found.
+        */
+       public String getSiteName(RestRequest req) {
+               VarResolverSession vr = req.getVarResolverSession();
+               if (this.siteName != null)
+                       return vr.resolve(this.siteName);
+               String siteName = 
context.getMessages().findFirstString(req.getLocale(), "siteName");
+               if (siteName != null)
+                       return vr.resolve(siteName);
+               return null;
+       }
+
+       /**
         * Returns the localized title of this REST resource.
         *
         * <p>
@@ -245,7 +280,7 @@ public class RestInfoProvider {
         * <p>
         * The default implementation returns the description from the 
following locations (whichever matches first):
         * <ol>
-        *      <li>{@link RestResource#title() @RestResourcel.title()} 
annotation on this class, and then any parent classes.
+        *      <li>{@link RestResource#title() @RestResource.title()} 
annotation on this class, and then any parent classes.
         *      <li><ck>[ClassName].title</ck> property in resource bundle 
identified by
         *              {@link RestResource#messages() 
@ResourceBundle.messages()} annotation for this class, then any parent
         *              classes.

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/82f0bd8e/juneau-rest/src/main/java/org/apache/juneau/rest/RestRequest.java
----------------------------------------------------------------------
diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/RestRequest.java 
b/juneau-rest/src/main/java/org/apache/juneau/rest/RestRequest.java
index 07a73aa..59b0d86 100644
--- a/juneau-rest/src/main/java/org/apache/juneau/rest/RestRequest.java
+++ b/juneau-rest/src/main/java/org/apache/juneau/rest/RestRequest.java
@@ -579,6 +579,18 @@ public final class RestRequest extends 
HttpServletRequestWrapper {
        
//--------------------------------------------------------------------------------
 
        /**
+        * Returns the localized site name.
+        *
+        * <p>
+        * Equivalent to calling {@link 
RestInfoProvider#getSiteName(RestRequest)} with this object.
+        *
+        * @return The localized servlet label.
+        */
+       public String getSiteName() {
+               return context.getInfoProvider().getSiteName(this);
+       }
+
+       /**
         * Returns the localized servlet title.
         *
         * <p>

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/82f0bd8e/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestResource.java
----------------------------------------------------------------------
diff --git 
a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestResource.java 
b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestResource.java
index 3ea1389..ec2d91c 100644
--- 
a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestResource.java
+++ 
b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestResource.java
@@ -419,6 +419,21 @@ public @interface RestResource {
        String path() default "";
 
        /**
+        * Optional site name.
+        *
+        * <p>
+        * Used as a label for the overall site.
+        * This value can be retrieved programmatically through the {@link 
RestRequest#getSiteName()} method.
+        *
+        * <p>
+        * This field can contain variables (e.g. "$L{my.localized.variable}").
+        *
+        * <p>
+        * The programmatic equivalent to this annotation is the {@link 
RestInfoProvider#getSiteName(RestRequest)} method.
+        */
+       String siteName() default "";
+
+       /**
         * Optional servlet title.
         *
         * <p>

Reply via email to