Repository: incubator-juneau Updated Branches: refs/heads/master ffda0552d -> 5845d893b
General improvements to Widgets support. Project: http://git-wip-us.apache.org/repos/asf/incubator-juneau/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-juneau/commit/5845d893 Tree: http://git-wip-us.apache.org/repos/asf/incubator-juneau/tree/5845d893 Diff: http://git-wip-us.apache.org/repos/asf/incubator-juneau/diff/5845d893 Branch: refs/heads/master Commit: 5845d893bcf8d287c6b8503cb79f95f2c512239f Parents: ffda055 Author: JamesBognar <[email protected]> Authored: Mon Jul 10 11:24:18 2017 -0400 Committer: JamesBognar <[email protected]> Committed: Mon Jul 10 11:24:18 2017 -0400 ---------------------------------------------------------------------- juneau-core/src/main/javadoc/overview.html | 19 +++--- .../juneau/examples/rest/AtomFeedResource.java | 12 ++-- .../juneau/examples/rest/DirectoryResource.java | 12 ++-- .../examples/rest/JsonSchemaResource.java | 12 ++-- .../juneau/examples/rest/PetStoreResource.java | 31 +++++----- .../examples/rest/RequestEchoResource.java | 12 ++-- .../juneau/examples/rest/RootResources.java | 16 ++--- .../juneau/examples/rest/SqlQueryResource.java | 6 +- .../examples/rest/SystemPropertiesResource.java | 25 ++++---- .../juneau/examples/rest/TempDirResource.java | 12 ++-- .../examples/rest/UrlEncodedFormResource.java | 6 +- .../rest/addressbook/AddressBookResource.java | 47 +++++++------- .../java/org/apache/juneau/rest/CallMethod.java | 14 ++--- .../java/org/apache/juneau/rest/RestConfig.java | 11 ++-- .../org/apache/juneau/rest/RestContext.java | 15 +++-- .../apache/juneau/rest/annotation/HtmlDoc.java | 10 +++ .../juneau/rest/annotation/RestMethod.java | 10 --- .../juneau/rest/annotation/RestResource.java | 30 +++------ .../org/apache/juneau/rest/vars/UrlVar.java | 5 +- .../org/apache/juneau/rest/vars/WidgetVar.java | 5 +- .../juneau/rest/widget/ContentTypeMenuItem.java | 16 ++--- .../juneau/rest/widget/PoweredByApache.java | 57 +++++++++++++++++ .../rest/widget/PoweredByApacheWidget.java | 65 -------------------- .../juneau/rest/widget/PoweredByJuneau.java | 56 +++++++++++++++++ .../rest/widget/PoweredByJuneauWidget.java | 63 ------------------- .../juneau/rest/widget/QueryMenuItem.java | 16 ++--- .../juneau/rest/widget/StyleMenuItem.java | 16 ++--- .../org/apache/juneau/rest/widget/Widget.java | 23 ++++--- 28 files changed, 289 insertions(+), 333 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/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 5e65ea2..4d612fe 100644 --- a/juneau-core/src/main/javadoc/overview.html +++ b/juneau-core/src/main/javadoc/overview.html @@ -6938,8 +6938,8 @@ links=<js>"{"</js> + <js>"up:'request:/..',"</js> + <js>"options:'servlet:/?method=OPTIONS',"</js> - + <js>"contentTypes:'$W{contentTypeMenuItem}',"</js> - + <js>"styles:'$W{styleMenuItem}',"</js> + + <js>"contentTypes:'$W{ContentTypeMenuItem}',"</js> + + <js>"styles:'$W{StyleMenuItem}',"</js> + <js>"source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/PetStoreResource.java'"</js> + <js>"}"</js> ) @@ -6949,8 +6949,8 @@ links={ <js>"up: request:/.."</js>, <js>"options: servlet:/?method=OPTIONS"</js>, - <js>"$W{contentTypeMenuItem}"</js>, - <js>"$W{styleMenuItem}"</js>, + <js>"$W{ContentTypeMenuItem}"</js>, + <js>"$W{StyleMenuItem}"</js>, <js>"source: $C{Source/gitHub}/org/apache/juneau/examples/rest/PetStoreResource.java"</js> } ) @@ -6979,6 +6979,11 @@ </ul> </li> <li> + Declaration of widgets moved to {@link org.apache.juneau.rest.annotation.HtmlDoc#widgets() @HtmlDoc.widgets()} + 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. + <li> New {@link org.apache.juneau.rest.widget.MenuItemWidget} can be used to create pull-down menu items. <li> New {@link org.apache.juneau.rest.widget.ContentTypeMenuItem} widget that provides a pull-down menu @@ -7336,14 +7341,14 @@ <ul> <li>{@link org.apache.juneau.rest.annotation.RestResource#serializerListener() serializerListener()} <li>{@link org.apache.juneau.rest.annotation.RestResource#parserListener() parserListener()} - <li>{@link org.apache.juneau.rest.annotation.RestResource#widgets() widgets()} + <li><code><del>widgets()</del></code> <li>{@link org.apache.juneau.rest.annotation.RestResource#swagger() swagger()} <li>{@link org.apache.juneau.rest.annotation.RestResource#htmldoc() htmldoc()} </ul> <li> New attributes on {@link org.apache.juneau.rest.annotation.RestMethod @RestMethod}: <ul> - <li>{@link org.apache.juneau.rest.annotation.RestMethod#widgets() widgets()} + <li><code><del>widgets()</del></code> <li>{@link org.apache.juneau.rest.annotation.RestMethod#swagger() swagger()} <li>{@link org.apache.juneau.rest.annotation.RestMethod#htmldoc() htmldoc()} </ul> @@ -7370,7 +7375,7 @@ <li>{@link org.apache.juneau.rest.RestConfig#setHtmlNoResultsMessage(String) setHtmlNoResultsMessage(String)} <li>{@link org.apache.juneau.rest.RestConfig#setHtmlTemplate(Class) setHtmlTemplate(Class)} <li>{@link org.apache.juneau.rest.RestConfig#setHtmlTemplate(HtmlDocTemplate) setHtmlTemplate(HtmlDocTemplate)} - <li>{@link org.apache.juneau.rest.RestConfig#addWidget(Class) addWidget(Class)} + <li><code><del>addWidget(Class)</del></code> </ul> <li> New methods on {@link org.apache.juneau.rest.RestResponse}: http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/AtomFeedResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/AtomFeedResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/AtomFeedResource.java index 9033b3a..89da0d9 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/AtomFeedResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/AtomFeedResource.java @@ -32,16 +32,16 @@ import org.apache.juneau.rest.widget.*; path="/atom", title="Sample ATOM feed resource", description="Sample resource that shows how to render ATOM feeds", - widgets={ - ContentTypeMenuItem.class, - StyleMenuItem.class - }, htmldoc=@HtmlDoc( + widgets={ + ContentTypeMenuItem.class, + StyleMenuItem.class + }, links={ "up: request:/..", "options: servlet:/?method=OPTIONS", - "$W{contentTypeMenuItem}", - "$W{styleMenuItem}", + "$W{ContentTypeMenuItem}", + "$W{StyleMenuItem}", "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/AtomFeedResource.java" } ), http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/DirectoryResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/DirectoryResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/DirectoryResource.java index 779db36..a7ea144 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/DirectoryResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/DirectoryResource.java @@ -36,16 +36,16 @@ import org.apache.juneau.utils.*; */ @RestResource( messages="nls/DirectoryResource", - widgets={ - ContentTypeMenuItem.class, - StyleMenuItem.class - }, htmldoc=@HtmlDoc( + widgets={ + ContentTypeMenuItem.class, + StyleMenuItem.class + }, links={ "up: request:/..", "options: servlet:/?method=OPTIONS", - "$W{contentTypeMenuItem}", - "$W{styleMenuItem}", + "$W{ContentTypeMenuItem}", + "$W{StyleMenuItem}", "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/DirectoryResource.java" } ), http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/JsonSchemaResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/JsonSchemaResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/JsonSchemaResource.java index 6f628c4..e0dd71b 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/JsonSchemaResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/JsonSchemaResource.java @@ -25,16 +25,16 @@ import org.apache.juneau.rest.widget.*; messages="nls/JsonSchemaResource", title="Sample JSON-Schema document", description="Sample resource that shows how to generate JSON-Schema documents", - widgets={ - ContentTypeMenuItem.class, - StyleMenuItem.class - }, htmldoc=@HtmlDoc( + widgets={ + ContentTypeMenuItem.class, + StyleMenuItem.class + }, links={ "up: request:/..", "options: servlet:/?method=OPTIONS", - "$W{contentTypeMenuItem}", - "$W{styleMenuItem}", + "$W{ContentTypeMenuItem}", + "$W{StyleMenuItem}", "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/JsonSchemaResource.java" }, aside={ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PetStoreResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PetStoreResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PetStoreResource.java index 1be06ba..84e6b26 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PetStoreResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PetStoreResource.java @@ -35,16 +35,16 @@ import org.apache.juneau.transforms.*; title="Pet Store", description="An example of a typical REST resource where beans are rendered in summary and details views.", path="/petstore", - widgets={ - ContentTypeMenuItem.class, - StyleMenuItem.class - }, htmldoc=@HtmlDoc( + widgets={ + ContentTypeMenuItem.class, + StyleMenuItem.class + }, links={ "up: request:/..", "options: servlet:/?method=OPTIONS", - "$W{contentTypeMenuItem}", - "$W{styleMenuItem}", + "$W{ContentTypeMenuItem}", + "$W{StyleMenuItem}", "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/PetStoreResource.java" }, aside={ @@ -77,23 +77,24 @@ public class PetStoreResource extends ResourceJena { summary="The complete list of pets in the store", bpExcludes="{Pet:'breed,getsAlongWith'}", - // Add 'query' and 'content-types' menu items. - widgets={ - QueryMenuItem.class, - ContentTypeMenuItem.class, - }, - // Add our converter for POJO query support. converters=Queryable.class, // Add our menu items in the nav links. htmldoc=@HtmlDoc( + + widgets={ + QueryMenuItem.class, + ContentTypeMenuItem.class, + StyleMenuItem.class + }, + links={ "up: request:/..", "options: servlet:/?method=OPTIONS", - "$W{queryMenuItem}", - "$W{contentTypeMenuItem}", - "$W{styleMenuItem}", + "$W{QueryMenuItem}", + "$W{ContentTypeMenuItem}", + "$W{StyleMenuItem}", "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/PetStoreResource.java" } ) http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/RequestEchoResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/RequestEchoResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/RequestEchoResource.java index 57a30f6..41ed920 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/RequestEchoResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/RequestEchoResource.java @@ -32,16 +32,16 @@ import org.apache.juneau.transforms.*; path="/echo", title="Request echo service", description="Echos the current HttpServletRequest object back to the browser.", - widgets={ - ContentTypeMenuItem.class, - StyleMenuItem.class - }, htmldoc=@HtmlDoc( + widgets={ + ContentTypeMenuItem.class, + StyleMenuItem.class + }, links={ "up: request:/..", "options: servlet:/?method=OPTIONS", - "$W{contentTypeMenuItem}", - "$W{styleMenuItem}", + "$W{ContentTypeMenuItem}", + "$W{StyleMenuItem}", "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/RequestEchoResource.java" }, aside={ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/RootResources.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/RootResources.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/RootResources.java index 4944856..4c64913 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/RootResources.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/RootResources.java @@ -25,16 +25,16 @@ import org.apache.juneau.rest.widget.*; path="/", title="Root resources", description="Example of a router resource page.", - widgets={ - PoweredByApacheWidget.class, - ContentTypeMenuItem.class, - StyleMenuItem.class - }, htmldoc=@HtmlDoc( + widgets={ + PoweredByApache.class, + ContentTypeMenuItem.class, + StyleMenuItem.class + }, links={ "options: ?method=OPTIONS", - "$W{contentTypeMenuItem}", - "$W{styleMenuItem}", + "$W{ContentTypeMenuItem}", + "$W{StyleMenuItem}", "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/RootResources.java" }, aside={ @@ -47,7 +47,7 @@ import org.apache.juneau.rest.widget.*; " <p>Other features (such as this aside) are added through annotations.</p>", "</div>" }, - footer="$W{poweredByApache}" + footer="$W{PoweredByApache}" ), children={ HelloWorldResource.class, http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SqlQueryResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SqlQueryResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SqlQueryResource.java index 1b16716..e0f4435 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SqlQueryResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SqlQueryResource.java @@ -36,12 +36,14 @@ import org.apache.juneau.rest.widget.*; messages="nls/SqlQueryResource", title="SQL query service", description="Executes queries against the local derby '$C{SqlQueryResource/connectionUrl}' database", - widgets={ StyleMenuItem.class }, htmldoc=@HtmlDoc( + widgets={ + StyleMenuItem.class + }, links={ "up: request:/..", "options: servlet:/..", - "$W{stylesMenuItem}", + "$W{StyleMenuItem}", "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/SqlQueryResource.java" }, aside={ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SystemPropertiesResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SystemPropertiesResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SystemPropertiesResource.java index 3414948..103dec9 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SystemPropertiesResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SystemPropertiesResource.java @@ -34,25 +34,24 @@ import org.apache.juneau.rest.widget.*; title="System properties resource", description="REST interface for performing CRUD operations on system properties.", - // Widget used for content-type pull-down menu. - widgets={ - ContentTypeMenuItem.class, - StyleMenuItem.class - }, - - // Links on the HTML rendition page. - // "request:/..." URIs are relative to the request URI. - // "servlet:/..." URIs are relative to the servlet URI. - // "$C{...}" variables are pulled from the config file. htmldoc=@HtmlDoc( - // Custom navigation links. + // Widget used for content-type and styles pull-down menus. + widgets={ + ContentTypeMenuItem.class, + StyleMenuItem.class + }, + + // Links on the HTML rendition page. + // "request:/..." URIs are relative to the request URI. + // "servlet:/..." URIs are relative to the servlet URI. + // "$C{...}" variables are pulled from the config file. links={ "up: request:/..", "options: servlet:/?method=OPTIONS", "form: servlet:/formPage", - "$W{contentTypeMenuItem}", - "$W{styleMenuItem}", + "$W{ContentTypeMenuItem}", + "$W{StyleMenuItem}", "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/SystemPropertiesResource.java" }, http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/TempDirResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/TempDirResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/TempDirResource.java index 8d62db0..4818ba0 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/TempDirResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/TempDirResource.java @@ -31,17 +31,17 @@ import org.apache.juneau.utils.*; path="/tempDir", title="Temp Directory View Service", description="View and download files in the '$S{java.io.tmpdir}' directory.", - widgets={ - ContentTypeMenuItem.class, - StyleMenuItem.class - }, htmldoc=@HtmlDoc( + widgets={ + ContentTypeMenuItem.class, + StyleMenuItem.class + }, links={ "up: request:/..", "options: servlet:/?method=OPTIONS", "upload: servlet:/upload", - "$W{contentTypeMenuItem}", - "$W{styleMenuItem}", + "$W{ContentTypeMenuItem}", + "$W{StyleMenuItem}", "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/TempDirResource.java" }, aside={ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/UrlEncodedFormResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/UrlEncodedFormResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/UrlEncodedFormResource.java index 331196b..2ce350a 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/UrlEncodedFormResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/UrlEncodedFormResource.java @@ -32,11 +32,13 @@ import org.apache.juneau.transforms.*; path="/urlEncodedForm", messages="nls/UrlEncodedFormResource", title="URL-Encoded form example", - widgets={ StyleMenuItem.class }, htmldoc=@HtmlDoc( + widgets={ + StyleMenuItem.class + }, links={ "up: request:/..", - "$W{styleMenuItem}", + "$W{StyleMenuItem}", "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/UrlEncodedFormResource.java" }, aside={ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/addressbook/AddressBookResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/addressbook/AddressBookResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/addressbook/AddressBookResource.java index 9c15644..61325ec 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/addressbook/AddressBookResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/addressbook/AddressBookResource.java @@ -43,26 +43,29 @@ import org.apache.juneau.utils.*; path="/addressBook", messages="nls/AddressBookResource", - // Widgets for $W variables above. - widgets={ - PoweredByJuneauWidget.class, - ContentTypeMenuItem.class, - QueryMenuItem.class, - StyleMenuItem.class - }, - - // Links on the HTML rendition page. - // "request:/..." URIs are relative to the request URI. - // "servlet:/..." URIs are relative to the servlet URI. - // "$C{...}" variables are pulled from the config file. htmldoc=@HtmlDoc( + + // Widgets for $W variables. + widgets={ + PoweredByJuneau.class, + ContentTypeMenuItem.class, + QueryMenuItem.class, + StyleMenuItem.class + }, + + // Links on the HTML rendition page. + // "request:/..." URIs are relative to the request URI. + // "servlet:/..." URIs are relative to the servlet URI. + // "$C{...}" variables are pulled from the config file. links={ "up: request:/..", "options: servlet:/?method=OPTIONS", "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/addressbook/AddressBookResource.java", - "$W{contentTypeMenuItem}", - "$W{styleMenuItem}" + "$W{ContentTypeMenuItem}", + "$W{StyleMenuItem}" }, + + // Arbitrary HTML message on the left side of the page. aside={ "<div style='max-width:400px;min-width:200px'>", " <p>Proof-of-concept resource that shows off the capabilities of working with POJO resources.</p>", @@ -74,7 +77,9 @@ import org.apache.juneau.utils.*; " </ul>", "</div>" }, - footer="$W{poweredByJuneau}" + + // Juneau icon added to footer. + footer="$W{PoweredByJuneau}" ), // Properties that get applied to all serializers and parsers. @@ -157,9 +162,9 @@ public class AddressBookResource extends ResourceJena { links={ "up: request:/..", "options: servlet:/?method=OPTIONS", - "$W{queryMenuItem}", - "$W{contentTypeMenuItem}", - "$W{styleMenuItem}", + "$W{QueryMenuItem}", + "$W{ContentTypeMenuItem}", + "$W{StyleMenuItem}", "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/addressbook/AddressBookResource.java" } ) @@ -191,9 +196,9 @@ public class AddressBookResource extends ResourceJena { links={ "up: request:/..", "options: servlet:/?method=OPTIONS", - "$W{queryMenuItem}", - "$W{contentTypeMenuItem}", - "$W{styleMenuItem}", + "$W{QueryMenuItem}", + "$W{ContentTypeMenuItem}", + "$W{StyleMenuItem}", "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/addressbook/AddressBookResource.java" } ) http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/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 4fab1b1..3de1cb8 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 @@ -119,7 +119,7 @@ class CallMethod implements Comparable<CallMethod> { this.htmlNoWrap = b.htmlNoWrap; this.htmlTemplate = b.htmlTemplate; this.htmlNoResultsMessage = b.htmlNoResultsMessage; - this.widgets = Collections.unmodifiableMap(b.widgets); + this.widgets = Collections.unmodifiableMap(b.htmlWidgets); } private static class Builder { @@ -145,7 +145,7 @@ class CallMethod implements Comparable<CallMethod> { private Integer priority; private org.apache.juneau.rest.annotation.Parameter[] parameters; private Response[] responses; - private Map<String,Widget> widgets; + private Map<String,Widget> htmlWidgets; @SuppressWarnings({ "unchecked", "rawtypes" }) private Builder(Object servlet, java.lang.reflect.Method method, RestContext context) throws RestServletException { @@ -176,13 +176,13 @@ class CallMethod implements Comparable<CallMethod> { beanContext = context.getBeanContext(); encoders = context.getEncoders(); properties = context.getProperties(); - widgets = new HashMap<String,Widget>(context.getWidgets()); - for (Class<? extends Widget> wc : m.widgets()) { - Widget w = ClassUtils.newInstance(Widget.class, wc); - widgets.put(w.getName(), w); - } HtmlDoc hd = m.htmldoc(); + htmlWidgets = new HashMap<String,Widget>(context.getHtmlWidgets()); + for (Class<? extends Widget> wc : hd.widgets()) { + Widget w = ClassUtils.newInstance(Widget.class, wc); + htmlWidgets.put(w.getName(), w); + } htmlTitle = hd.title().isEmpty() ? context.getHtmlTitle() : hd.title(); htmlDescription = hd.description().isEmpty() ? context.getHtmlDescription() : hd.description(); htmlBranding = hd.branding().length == 0 ? context.getHtmlBranding() : join(hd.branding(), '\n'); http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/juneau-rest/src/main/java/org/apache/juneau/rest/RestConfig.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/RestConfig.java b/juneau-rest/src/main/java/org/apache/juneau/rest/RestConfig.java index 0ad162b..7034a71 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/RestConfig.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/RestConfig.java @@ -126,7 +126,7 @@ public class RestConfig implements ServletConfig { Object htmlTemplate = HtmlDocTemplateBasic.class; Class<?> resourceClass; - Map<String,Widget> widgets = new HashMap<String,Widget>(); + Map<String,Widget> htmlWidgets = new HashMap<String,Widget>(); /** * Constructor. @@ -220,10 +220,9 @@ public class RestConfig implements ServletConfig { if (r.infoProvider() != RestInfoProvider.class) setInfoProvider(r.infoProvider()); - for (Class<? extends Widget> cw : r.widgets()) - addWidget(cw); - HtmlDoc hd = r.htmldoc(); + for (Class<? extends Widget> cw : hd.widgets()) + addHtmlWidget(cw); if (! hd.title().isEmpty()) setHtmlTitle(hd.title()); if (! hd.description().isEmpty()) @@ -1510,9 +1509,9 @@ public class RestConfig implements ServletConfig { * @param value The widget class to add. * @return This object (for method chaining). */ - public RestConfig addWidget(Class<? extends Widget> value) { + public RestConfig addHtmlWidget(Class<? extends Widget> value) { Widget w = ClassUtils.newInstance(Widget.class, value); - this.widgets.put(w.getName(), w); + this.htmlWidgets.put(w.getName(), w); return this; } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/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 51d10f2..631e93d 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 @@ -365,7 +365,7 @@ public final class RestContext extends Context { htmlLinks; private final boolean htmlNoWrap; private final HtmlDocTemplate htmlTemplate; - private final Map<String,Widget> widgets; + private final Map<String,Widget> htmlWidgets; private final Set<String> allowMethodParams; @@ -464,8 +464,8 @@ public final class RestContext extends Context { this.childResources = Collections.synchronizedMap(new LinkedHashMap<String,RestContext>()); // Not unmodifiable on purpose so that children can be replaced. this.logger = b.logger; this.fullPath = b.fullPath; - this.widgets = Collections.unmodifiableMap(b.widgets); + this.htmlWidgets = Collections.unmodifiableMap(b.htmlWidgets); this.htmlTitle = b.htmlTitle; this.htmlDescription = b.htmlDescription; this.htmlBranding = b.htmlBranding; @@ -674,7 +674,7 @@ public final class RestContext extends Context { Set<String> allowMethodParams = new LinkedHashSet<String>(); RestLogger logger; String fullPath; - Map<String,Widget> widgets; + Map<String,Widget> htmlWidgets; @SuppressWarnings("unchecked") private Builder(Object resource, RestConfig sc) throws Exception { @@ -786,8 +786,7 @@ public final class RestContext extends Context { fullPath = (sc.parentContext == null ? "" : (sc.parentContext.fullPath + '/')) + sc.path; - widgets = sc.widgets; - + htmlWidgets = sc.htmlWidgets; htmlTitle = sc.htmlTitle; htmlDescription = sc.htmlDescription; htmlBranding = sc.htmlBranding; @@ -1175,12 +1174,12 @@ public final class RestContext extends Context { * The widgets used for resolving <js>"$W{...}"<js> variables. * * <p> - * Defined by the {@link RestResource#widgets()} annotation or {@link RestConfig#addWidget(Class)} method. + * Defined by the {@link HtmlDoc#widgets()} annotation or {@link RestConfig#addHtmlWidget(Class)} method. * * @return The var resolver widgets as a map with keys being the name returned by {@link Widget#getName()}. */ - public Map<String,Widget> getWidgets() { - return widgets; + public Map<String,Widget> getHtmlWidgets() { + return htmlWidgets; } /** http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/HtmlDoc.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/HtmlDoc.java b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/HtmlDoc.java index eef9227..9d2ccf3 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/HtmlDoc.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/HtmlDoc.java @@ -15,6 +15,7 @@ package org.apache.juneau.rest.annotation; import org.apache.juneau.*; import org.apache.juneau.html.*; import org.apache.juneau.rest.*; +import org.apache.juneau.rest.widget.*; /** * Contains all the configurable annotations for the {@link HtmlDocSerializer}. @@ -501,4 +502,13 @@ public @interface HtmlDoc { * {@link RestConfig#setHtmlTemplate(Class)}/{@link RestResponse#setHtmlTemplate(Class)} methods. */ Class<? extends HtmlDocTemplate> template() default HtmlDocTemplate.class; + + /** + * Defines widgets that can be used in conjunction with string variables of the form <js>"$W{name}"</js>to quickly + * generate arbitrary replacement HTML. + * + * <p> + * Widgets are inherited from parent to child, but can be overridden by reusing the widget name. + */ + Class<? extends Widget>[] widgets() default {}; } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestMethod.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestMethod.java b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestMethod.java index 62a63d4..9758cfd 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestMethod.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestMethod.java @@ -22,7 +22,6 @@ import org.apache.juneau.encoders.*; import org.apache.juneau.parser.*; import org.apache.juneau.remoteable.*; import org.apache.juneau.rest.*; -import org.apache.juneau.rest.widget.*; import org.apache.juneau.serializer.*; /** @@ -602,15 +601,6 @@ public @interface RestMethod { String clientVersion() default ""; /** - * Defines widgets that can be used in conjunction with string variables of the form <js>"$W{name}"</js>to quickly - * generate arbitrary replacement text. - * - * <p> - * Widgets are inherited from parent to child, but can be overridden by reusing the widget name. - */ - Class<? extends Widget>[] widgets() default {}; - - /** * Provides swagger-specific metadata on this method. */ MethodSwagger swagger() default @MethodSwagger; http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/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 98e3788..3ea1389 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 @@ -26,7 +26,6 @@ import org.apache.juneau.jena.*; import org.apache.juneau.json.*; import org.apache.juneau.parser.*; import org.apache.juneau.rest.*; -import org.apache.juneau.rest.widget.*; import org.apache.juneau.serializer.*; import org.apache.juneau.transform.*; import org.apache.juneau.utils.*; @@ -650,18 +649,6 @@ public @interface RestResource { Class<? extends ParserListener> parserListener() default ParserListener.class; /** - * Defines widgets that can be used in conjunction with string variables of the form <js>"$W{name}"</js>to quickly - * generate arbitrary replacement text. - * - * <p> - * Widgets are inherited from parent to child, but can be overridden by reusing the widget name. - * - * <p> - * See {@link #htmldoc()} for an example of usage. - */ - Class<? extends Widget>[] widgets() default {}; - - /** * Provides swagger-specific metadata on this resource. * * <p> @@ -700,6 +687,11 @@ public @interface RestResource { * // "servlet:/..." URIs are relative to the servlet URI. * // "$C{...}" variables are pulled from the config file.</jc> * htmldoc=<ja>@HtmlDoc</ja>( + * <jc>// Widgets for $W variables.</jc> + * widgets={ + * PoweredByJuneau.<jk>class</jk>, + * ContentTypeLinks.<jk>class</jk> + * } * links={ * <js>"up: request:/.."</js>, * <js>"options: servlet:/?method=OPTIONS"</js>, @@ -715,17 +707,11 @@ public @interface RestResource { * <js>" <li>Widgets"</js>, * <js>" </ul>"</js>, * <js>" <p style='text-weight:bold;text-decoration:underline;'>Available Content Types</p>"</js>, - * <js>" $W{contentTypeLinks}"</js>, + * <js>" $W{ContentTypeLinks}"</js>, * <js>"</div>"</js> * }, - * footer=<js>"$W{poweredByJuneau}"</js> - * ), - * - * <jc>// Widgets for $W variables above.</jc> - * widgets={ - * PoweredByJuneauWidget.<jk>class</jk>, - * ContentTypeLinksWidget.<jk>class</jk> - * } + * footer=<js>"$W{PoweredByJuneau}"</js> + * ) * ) * </p> */ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/juneau-rest/src/main/java/org/apache/juneau/rest/vars/UrlVar.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/vars/UrlVar.java b/juneau-rest/src/main/java/org/apache/juneau/rest/vars/UrlVar.java index 843180d..8ac9b2e 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/vars/UrlVar.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/vars/UrlVar.java @@ -27,9 +27,8 @@ import org.apache.juneau.svl.*; * <p> * See {@link UriResolver} for the kinds of URIs that can be resolved. * <ul> - * <li>{@link RestResource#widgets() @RestResource.widgets()} - * <li>{@link RestMethod#widgets() @RestMethod.widgets()} - * <li>{@link RestConfig#addWidget(Class)} + * <li>{@link HtmlDoc#widgets() @HtmlDoc.widgets()} + * <li>{@link RestConfig#addHtmlWidget(Class)} * </ul> * * <p> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/juneau-rest/src/main/java/org/apache/juneau/rest/vars/WidgetVar.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/vars/WidgetVar.java b/juneau-rest/src/main/java/org/apache/juneau/rest/vars/WidgetVar.java index f43b059..715ff9a 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/vars/WidgetVar.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/vars/WidgetVar.java @@ -26,9 +26,8 @@ import org.apache.juneau.svl.*; * <p> * They're registered via the following mechanisms: * <ul> - * <li>{@link RestResource#widgets() @RestResource.widgets()} - * <li>{@link RestMethod#widgets() @RestMethod.widgets()} - * <li>{@link RestConfig#addWidget(Class)} + * <li>{@link HtmlDoc#widgets() @HtmlDoc.widgets()} + * <li>{@link RestConfig#addHtmlWidget(Class)} * </ul> * * @see org.apache.juneau.svl http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/juneau-rest/src/main/java/org/apache/juneau/rest/widget/ContentTypeMenuItem.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/widget/ContentTypeMenuItem.java b/juneau-rest/src/main/java/org/apache/juneau/rest/widget/ContentTypeMenuItem.java index b1bf483..195c7a6 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/widget/ContentTypeMenuItem.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/widget/ContentTypeMenuItem.java @@ -23,7 +23,7 @@ import org.apache.juneau.utils.*; * Widget that returns back a list of hyperlinks for rendering the contents of a page in a variety of content types. * * <p> - * The variable it resolves is <js>"$W{contentTypeMenuItem}"</js>. + * The variable it resolves is <js>"$W{ContentTypeMenuItem}"</js>. * * <p> * An example of this widget can be found in the <code>PetStoreResource</code> in the examples that provides @@ -39,9 +39,9 @@ import org.apache.juneau.utils.*; * links={ * <js>"up: ..."</js>, * <js>"options: ..."</js>, - * <js>"$W{queryMenuItem}"</js>, - * <js>"$W{contentTypeMenuItem}"</js>, - * <js>"$W{styleMenuItem}"</js>, + * <js>"$W{QueryMenuItem}"</js>, + * <js>"$W{ContentTypeMenuItem}"</js>, + * <js>"$W{StyleMenuItem}"</js>, * <js>"source: ..."</js> * } * ) @@ -56,14 +56,6 @@ import org.apache.juneau.utils.*; public class ContentTypeMenuItem extends MenuItemWidget { /** - * Returns <js>"contentTypeMenuItem"</js>. - */ - @Override /* Widget */ - public String getName() { - return "contentTypeMenuItem"; - } - - /** * Looks at the supported media types from the request and constructs a list of hyperlinks to render the data * as plain-text. */ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/juneau-rest/src/main/java/org/apache/juneau/rest/widget/PoweredByApache.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/widget/PoweredByApache.java b/juneau-rest/src/main/java/org/apache/juneau/rest/widget/PoweredByApache.java new file mode 100644 index 0000000..c4a88ac --- /dev/null +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/widget/PoweredByApache.java @@ -0,0 +1,57 @@ +// *************************************************************************************************************************** +// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * +// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * +// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * +// * with the License. You may obtain a copy of the License at * +// * * +// * http://www.apache.org/licenses/LICENSE-2.0 * +// * * +// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * +// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * +// * specific language governing permissions and limitations under the License. * +// *************************************************************************************************************************** +package org.apache.juneau.rest.widget; + +import org.apache.juneau.*; +import org.apache.juneau.rest.*; + +/** + * Widget that places a powered-by-Apache message on the page. + * + * <p> + * The variable it resolves is <js>"$W{PoweredByApache}"</js>. + * + * <p> + * It produces a simple Apache icon floating on the right. + * Typically it's used in the footer of the page, as shown below in the <code>RootResources</code> from the examples: + * + * <p class='bcode'> + * <ja>@RestResource</ja>( + * path=<js>"/"</js>, + * title=<js>"Root resources"</js>, + * description=<js>"Example of a router resource page."</js>, + * widgets={ + * PoweredByApache.<jk>class</jk> + * }, + * htmldoc=<ja>@HtmlDoc</ja>( + * footer=<js>"$W{PoweredByApache}"</js> + * ) + * </p> + * + * <p> + * It renders the following image: + * <img class='bordered' src='doc-files/PoweredByApacheWidget.png'> + */ +public class PoweredByApache extends Widget { + + /** + * Returns an Apache image tag hyperlinked to <js>"http://apache.org"</js> + */ + @Override /* Widget */ + public String getHtml(RestRequest req) throws Exception { + UriResolver r = req.getUriResolver(); + return "<a href='http://apache.org'><img style='float:right;padding-right:20px;height:32px' src='"+r.resolve("servlet:/htdocs/asf.png")+"'>"; + } +} + + http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/juneau-rest/src/main/java/org/apache/juneau/rest/widget/PoweredByApacheWidget.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/widget/PoweredByApacheWidget.java b/juneau-rest/src/main/java/org/apache/juneau/rest/widget/PoweredByApacheWidget.java deleted file mode 100644 index cd6da66..0000000 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/widget/PoweredByApacheWidget.java +++ /dev/null @@ -1,65 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest.widget; - -import org.apache.juneau.*; -import org.apache.juneau.rest.*; - -/** - * Widget that places a powered-by-Apache message on the page. - * - * <p> - * The variable it resolves is <js>"$W{poweredByApache}"</js>. - * - * <p> - * It produces a simple Apache icon floating on the right. - * Typically it's used in the footer of the page, as shown below in the <code>RootResources</code> from the examples: - * - * <p class='bcode'> - * <ja>@RestResource</ja>( - * path=<js>"/"</js>, - * title=<js>"Root resources"</js>, - * description=<js>"Example of a router resource page."</js>, - * widgets={ - * PoweredByApacheWidget.<jk>class</jk> - * }, - * htmldoc=<ja>@HtmlDoc</ja>( - * footer=<js>"$W{poweredByApache}"</js> - * ) - * </p> - * - * <p> - * It renders the following image: - * <img class='bordered' src='doc-files/PoweredByApacheWidget.png'> - */ -public class PoweredByApacheWidget extends Widget { - - /** - * Returns <js>"poweredByApache"</js>. - */ - @Override /* Widget */ - public String getName() { - return "poweredByApache"; - } - - /** - * Returns an Apache image tag hyperlinked to <js>"http://apache.org"</js> - */ - @Override /* Widget */ - public String getHtml(RestRequest req) throws Exception { - UriResolver r = req.getUriResolver(); - return "<a href='http://apache.org'><img style='float:right;padding-right:20px;height:32px' src='"+r.resolve("servlet:/htdocs/asf.png")+"'>"; - } -} - - http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/juneau-rest/src/main/java/org/apache/juneau/rest/widget/PoweredByJuneau.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/widget/PoweredByJuneau.java b/juneau-rest/src/main/java/org/apache/juneau/rest/widget/PoweredByJuneau.java new file mode 100644 index 0000000..19542df --- /dev/null +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/widget/PoweredByJuneau.java @@ -0,0 +1,56 @@ +// *************************************************************************************************************************** +// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * +// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * +// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * +// * with the License. You may obtain a copy of the License at * +// * * +// * http://www.apache.org/licenses/LICENSE-2.0 * +// * * +// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * +// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * +// * specific language governing permissions and limitations under the License. * +// *************************************************************************************************************************** +package org.apache.juneau.rest.widget; + +import org.apache.juneau.*; +import org.apache.juneau.rest.*; + +/** + * Widget that places a powered-by-Juneau message on the page. + * + * <p> + * The variable it resolves is <js>"$W{PoweredByJuneau}"</js>. + * + * <p> + * It produces a simple Apache Juneau icon floating on the right. + * Typically it's used in the footer of the page, as shown below in the <code>AddressBookResource</code> from the examples: + * + * <p class='bcode'> + * <ja>@RestResource</ja>( + * path=<js>"/addressBook"</js>, + * widgets={ + * PoweredByJuneau.<jk>class</jk> + * }, + * htmldoc=<ja>@HtmlDoc</ja>( + * footer=<js>"$W{PoweredByJuneau}"</js> + * ) + * </p> + * + * <p> + * It renders the following image: + * <img class='bordered' src='doc-files/PoweredByJuneauWidget.png'> + */ +public class PoweredByJuneau extends Widget { + + + /** + * Returns an Apache Juneau image tag hyperlinked to <js>"http://juneau.apache.org"</js> + */ + @Override /* Widget */ + public String getHtml(RestRequest req) throws Exception { + UriResolver r = req.getUriResolver(); + return "<a href='http://juneau.apache.org'><img style='float:right;padding-right:20px;height:32px' src='"+r.resolve("servlet:/htdocs/juneau.png")+"'>"; + } +} + + http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/juneau-rest/src/main/java/org/apache/juneau/rest/widget/PoweredByJuneauWidget.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/widget/PoweredByJuneauWidget.java b/juneau-rest/src/main/java/org/apache/juneau/rest/widget/PoweredByJuneauWidget.java deleted file mode 100644 index 55c339b..0000000 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/widget/PoweredByJuneauWidget.java +++ /dev/null @@ -1,63 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest.widget; - -import org.apache.juneau.*; -import org.apache.juneau.rest.*; - -/** - * Widget that places a powered-by-Juneau message on the page. - * - * <p> - * The variable it resolves is <js>"$W{poweredByJuneau}"</js>. - * - * <p> - * It produces a simple Apache Juneau icon floating on the right. - * Typically it's used in the footer of the page, as shown below in the <code>AddressBookResource</code> from the examples: - * - * <p class='bcode'> - * <ja>@RestResource</ja>( - * path=<js>"/addressBook"</js>, - * widgets={ - * PoweredByJuneauWidget.<jk>class</jk> - * }, - * htmldoc=<ja>@HtmlDoc</ja>( - * footer=<js>"$W{poweredByJuneau}"</js> - * ) - * </p> - * - * <p> - * It renders the following image: - * <img class='bordered' src='doc-files/PoweredByJuneauWidget.png'> - */ -public class PoweredByJuneauWidget extends Widget { - - /** - * Returns <js>"poweredByJuneau"</js>. - */ - @Override /* Widget */ - public String getName() { - return "poweredByJuneau"; - } - - /** - * Returns an Apache Juneau image tag hyperlinked to <js>"http://juneau.apache.org"</js> - */ - @Override /* Widget */ - public String getHtml(RestRequest req) throws Exception { - UriResolver r = req.getUriResolver(); - return "<a href='http://juneau.apache.org'><img style='float:right;padding-right:20px;height:32px' src='"+r.resolve("servlet:/htdocs/juneau.png")+"'>"; - } -} - - http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/juneau-rest/src/main/java/org/apache/juneau/rest/widget/QueryMenuItem.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/widget/QueryMenuItem.java b/juneau-rest/src/main/java/org/apache/juneau/rest/widget/QueryMenuItem.java index 341cd0f..4a71f8b 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/widget/QueryMenuItem.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/widget/QueryMenuItem.java @@ -19,7 +19,7 @@ import org.apache.juneau.rest.converters.*; * Widget that returns a menu-item drop-down form for entering search/view/sort arguments. * * <p> - * The variable it resolves is <js>"$W{queryMenuItem}"</js>. + * The variable it resolves is <js>"$W{QueryMenuItem}"</js>. * * <p> * This widget is designed to be used in conjunction with the {@link Queryable} converter, although implementations @@ -40,9 +40,9 @@ import org.apache.juneau.rest.converters.*; * links={ * <js>"up: ..."</js>, * <js>"options: ..."</js>, - * <js>"$W{queryMenuItem}"</js>, - * <js>"$W{contentTypeMenuItem}"</js>, - * <js>"$W{styleMenuItem}"</js>, + * <js>"$W{QueryMenuItem}"</js>, + * <js>"$W{ContentTypeMenuItem}"</js>, + * <js>"$W{StyleMenuItem}"</js>, * <js>"source: ..."</js> * } * ), @@ -67,14 +67,6 @@ import org.apache.juneau.rest.converters.*; public class QueryMenuItem extends MenuItemWidget { /** - * Returns <js>"queryMenuItem"</js>. - */ - @Override /* Widget */ - public String getName() { - return "queryMenuItem"; - } - - /** * Returns CSS for the tooltips. */ @Override http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/juneau-rest/src/main/java/org/apache/juneau/rest/widget/StyleMenuItem.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/widget/StyleMenuItem.java b/juneau-rest/src/main/java/org/apache/juneau/rest/widget/StyleMenuItem.java index 1afaee0..c173829 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/widget/StyleMenuItem.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/widget/StyleMenuItem.java @@ -19,7 +19,7 @@ import org.apache.juneau.utils.*; * Widget that returns back a list of hyperlinks for rendering the contents of a page in the various default styles. * * <p> - * The variable it resolves is <js>"$W{styleMenuItem}"</js>. + * The variable it resolves is <js>"$W{StyleMenuItem}"</js>. * * <p> * An example of this widget can be found in the <code>PetStoreResource</code> in the examples that provides @@ -35,9 +35,9 @@ import org.apache.juneau.utils.*; * links={ * <js>"up: ..."</js>, * <js>"options: ..."</js>, - * <js>"$W{queryMenuItem}"</js>, - * <js>"$W{contentTypeMenuItem}"</js>, - * <js>"$W{styleMenuItem}"</js>, + * <js>"$W{QueryMenuItem}"</js>, + * <js>"$W{ContentTypeMenuItem}"</js>, + * <js>"$W{StyleMenuItem}"</js>, * <js>"source: ..."</js> * } * ) @@ -50,14 +50,6 @@ public class StyleMenuItem extends MenuItemWidget { private static final String[] BUILT_IN_STYLES = {"devops", "light", "original"}; /** - * Returns <js>"styleMenuItem"</js>. - */ - @Override /* Widget */ - public String getName() { - return "styleMenuItem"; - } - - /** * Looks at the supported media types from the request and constructs a list of hyperlinks to render the data * as plain-text. */ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/5845d893/juneau-rest/src/main/java/org/apache/juneau/rest/widget/Widget.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/widget/Widget.java b/juneau-rest/src/main/java/org/apache/juneau/rest/widget/Widget.java index 0d81e19..c08fee8 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/widget/Widget.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/widget/Widget.java @@ -25,9 +25,8 @@ import org.apache.juneau.utils.*; * <p> * Widgets are associated with resources through the following * <ul> - * <li>{@link RestResource#widgets() @RestResource.widgets} - * <li>{@link RestMethod#widgets() @RestMethod.widgets} - * <li>{@link RestConfig#addWidget(Class)} + * <li>{@link HtmlDoc#widgets() @HtmlDoc.widgets} + * <li>{@link RestConfig#addHtmlWidget(Class)} * </ul> * * <p> @@ -50,10 +49,10 @@ import org.apache.juneau.utils.*; * } * htmldoc=<ja>@HtmlDoc</ja>( * links={ - * <js>"$W{myWidget}"</js> + * <js>"$W{MyWidget}"</js> * }, * aside={ - * <js>"Check out this widget: $W{myWidget}"</js> + * <js>"Check out this widget: $W{MyWidget}"</js> * } * ) * ) @@ -66,11 +65,6 @@ import org.apache.juneau.utils.*; * <jk>public class</jk> MyWidget <jk>extends</jk> Widget { * * <ja>@Override</ja> - * <jk>public</jk> String getName(RestRequest req) { - * return <js>"myWidget"</js>; - * } - * - * <ja>@Override</ja> * <jk>public</jk> String getHtml(RestRequest req) <jk>throws</jk> Exception { * UriResolver r = req.getUriResolver(); * <jk>return</jk> <js>"<img class='myimage' onclick='myalert(this)' src='"</js>+r.resolve(<js>"servlet:/htdocs/myimage.png"</js>)+<js>"'>"</js>; @@ -125,14 +119,19 @@ public abstract class Widget { * The widget key. * * <p> - * (i.e. The contents of the <js>"$W{...}"</js> variable). + * (i.e. The variable name inside the <js>"$W{...}"</js> variable). * * <p> * The returned value must not be <jk>null</jk>. * + * <p> + * If not overridden, the default value is the class simple name. + * * @return The widget key. */ - public abstract String getName(); + public String getName() { + return getClass().getSimpleName(); + } /** * Resolves the HTML content for this widget.
