Add @RestResource.pageTitle/pageText/pageLinks annotations. Project: http://git-wip-us.apache.org/repos/asf/incubator-juneau/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-juneau/commit/703cadd2 Tree: http://git-wip-us.apache.org/repos/asf/incubator-juneau/tree/703cadd2 Diff: http://git-wip-us.apache.org/repos/asf/incubator-juneau/diff/703cadd2
Branch: refs/heads/master Commit: 703cadd2d9c0ccd68cefb13e078b8efd86e8636a Parents: a058007 Author: JamesBognar <[email protected]> Authored: Fri Mar 31 18:42:46 2017 -0400 Committer: JamesBognar <[email protected]> Committed: Fri Mar 31 18:42:46 2017 -0400 ---------------------------------------------------------------------- .../java/org/apache/juneau/jena/package.html | 16 +- .../apache/juneau/dto/jsonschema/package.html | 6 +- .../apache/juneau/html/HtmlDocSerializer.java | 2 +- .../juneau/html/HtmlDocSerializerContext.java | 49 ++- .../juneau/html/HtmlDocSerializerSession.java | 14 +- .../java/org/apache/juneau/json/package.html | 16 +- .../apache/juneau/serializer/StringObject.java | 92 ------ .../juneau/serializer/WriterSerializer.java | 1 + .../java/org/apache/juneau/uon/package.html | 16 +- .../org/apache/juneau/urlencoding/package.html | 16 +- .../org/apache/juneau/utils/StringMessage.java | 76 +++++ .../org/apache/juneau/utils/StringObject.java | 93 ++++++ .../java/org/apache/juneau/xml/package.html | 16 +- juneau-core/src/main/javadoc/overview.html | 151 +++++---- .../juneau/examples/rest/AtomFeedResource.java | 11 +- .../examples/rest/CodeFormatterResource.java | 10 +- .../juneau/examples/rest/DirectoryResource.java | 2 +- .../examples/rest/DockerRegistryResource.java | 6 +- .../examples/rest/HelloWorldResource.java | 10 +- .../examples/rest/JsonSchemaResource.java | 13 +- .../examples/rest/MethodExampleResource.java | 6 +- .../juneau/examples/rest/PhotosResource.java | 16 +- .../examples/rest/RequestEchoResource.java | 14 +- .../juneau/examples/rest/RootResources.java | 9 +- .../examples/rest/SampleRemoteableServlet.java | 7 +- .../juneau/examples/rest/SqlQueryResource.java | 13 +- .../examples/rest/SystemPropertiesResource.java | 4 +- .../juneau/examples/rest/TempDirResource.java | 8 +- .../examples/rest/TumblrParserResource.java | 14 +- .../examples/rest/UrlEncodedFormResource.java | 9 +- .../rest/addressbook/AddressBookResource.java | 2 +- .../rest/nls/AtomFeedResource.properties | 21 -- .../rest/nls/CodeFormatterResource.properties | 18 -- .../rest/nls/HelloWorldResource.properties | 19 -- .../rest/nls/JsonSchemaResource.properties | 20 -- .../examples/rest/nls/PhotosResource.properties | 24 -- .../rest/nls/RequestEchoResource.properties | 19 -- .../examples/rest/nls/RootResources.properties | 18 -- .../rest/nls/SampleRemoteableServlet.properties | 17 -- .../examples/rest/nls/SourceResource.properties | 19 -- .../rest/nls/SqlQueryResource.properties | 19 -- .../rest/nls/TempDirResource.properties | 18 -- .../rest/nls/TumblrParserResource.properties | 19 -- .../rest/nls/UrlEncodedFormResource.properties | 2 - .../apache/juneau/microservice/Resource.java | 2 +- .../juneau/microservice/ResourceGroup.java | 6 +- .../juneau/microservice/ResourceJena.java | 6 +- .../org/apache/juneau/microservice/package.html | 4 +- .../microservice/resources/ConfigResource.java | 5 +- .../resources/DirectoryResource.java | 2 +- .../microservice/resources/LogsResource.java | 9 +- .../rest/test/HtmlPropertiesResource.java | 305 +++++++++++++++++++ .../java/org/apache/juneau/rest/test/Root.java | 1 + .../rest/test/HtmlPropertiesResource.properties | 37 +++ .../juneau/rest/test/HtmlPropertiesTest.java | 286 +++++++++++++++++ .../java/org/apache/juneau/rest/CallMethod.java | 28 +- .../org/apache/juneau/rest/ReaderResource.java | 4 +- .../java/org/apache/juneau/rest/RestConfig.java | 47 ++- .../org/apache/juneau/rest/RestContext.java | 42 ++- .../java/org/apache/juneau/rest/RestLogger.java | 2 +- .../org/apache/juneau/rest/RestRequest.java | 56 +++- .../org/apache/juneau/rest/RestResponse.java | 66 +++- .../apache/juneau/rest/RestServletDefault.java | 13 +- .../juneau/rest/annotation/RestMethod.java | 15 +- .../juneau/rest/annotation/RestResource.java | 105 ++++++- .../rest/jena/RestServletJenaDefault.java | 13 +- .../java/org/apache/juneau/rest/package.html | 50 +-- 67 files changed, 1419 insertions(+), 636 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/juneau-core-rdf/src/main/java/org/apache/juneau/jena/package.html ---------------------------------------------------------------------- diff --git a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/package.html b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/package.html index 5f1d7aa..095dc7e 100644 --- a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/package.html +++ b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/package.html @@ -1060,14 +1060,14 @@ // Consists of an in-memory address book repository.</jc> <ja>@RestResource</ja>( messages=<js>"nls/AddressBookResource"</js>, + title=<js>"$L{title}"</js>, + description=<js>"$L{description}"</js>, + pageLinks=<js>"{options:'?method=OPTIONS',doc:'doc'}"</js>, properties={ <ja>@Property</ja>(name=RdfProperties.<jsf>RDF_rdfxml_tab</jsf>, value=<js>"3"</js>), <ja>@Property</ja>(name=RdfSerializerContext.<jsf>RDF_addRootProperty</jsf>, value=<js>"true"</js>), <ja>@Property</ja>(name=SerializerContext.<jsf>SERIALIZER_quoteChar</jsf>, value=<js>"'"</js>), - <ja>@Property</ja>(name=HtmlSerializerContext.<jsf>HTML_uriAnchorText</jsf>, value=<jsf>TO_STRING</jsf>), - <ja>@Property</ja>(name=HtmlDocSerializerContext.<jsf>HTMLDOC_title</jsf>, value=<js>"$L{title}"</js>), - <ja>@Property</ja>(name=HtmlDocSerializerContext.<jsf>HTMLDOC_description</jsf>, value=<js>"$L{description}"</js>), - <ja>@Property</ja>(name=HtmlDocSerializerContext.<jsf>HTMLDOC_links</jsf>, value=<js>"{options:'?method=OPTIONS',doc:'doc'}"</js>) + <ja>@Property</ja>(name=HtmlSerializerContext.<jsf>HTML_uriAnchorText</jsf>, value=<jsf>TO_STRING</jsf>) }, encoders=GzipEncoder.<jk>class</jk> ) @@ -1097,8 +1097,8 @@ <p class='bcode'> <jc>// GET person request handler</jc> <ja>@RestMethod</ja>(name=<js>"GET"</js>, path=<js>"/people/{id}/*"</js>, rc={200,404}) - <jk>public</jk> Person getPerson(RestRequest req, <ja>@Path</ja> <jk>int</jk> id) throws Exception { - properties.put(HtmlDocSerializerContext.<jsf>HTMLDOC_title</jsf>, req.getPathInfo()); + <jk>public</jk> Person getPerson(RestRequest req, RestResponse res, <ja>@Path</ja> <jk>int</jk> id) throws Exception { + res.setPageTitle(req.getPathInfo()); <jk>return</jk> findPerson(id); } @@ -1160,8 +1160,8 @@ <ja>@Property</ja>(name=SerializerContext.<jsf>SERIALIZER_quoteChar</jsf>, value=<js>"'"</js>) } ) - <jk>public</jk> Person getPerson(RestRequest req, <ja>@Path</ja> <jk>int</jk> id) throws Exception { - properties.put(HtmlDocSerializerContext.<jsf>HTMLDOC_title</jsf>, req.getPathInfo()); + <jk>public</jk> Person getPerson(RestRequest req, RestResponse res, <ja>@Path</ja> <jk>int</jk> id) throws Exception { + res.setPageTitle(req.getPathInfo()); <jk>return</jk> findPerson(id); } </p> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/juneau-core/src/main/java/org/apache/juneau/dto/jsonschema/package.html ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/dto/jsonschema/package.html b/juneau-core/src/main/java/org/apache/juneau/dto/jsonschema/package.html index 77b0b5f..8353a46 100644 --- a/juneau-core/src/main/java/org/apache/juneau/dto/jsonschema/package.html +++ b/juneau-core/src/main/java/org/apache/juneau/dto/jsonschema/package.html @@ -406,10 +406,8 @@ <ja>@RestResource</ja>( path=<js>"/jsonSchema"</js>, messages=<js>"nls/JsonSchemaResource"</js>, - properties={ - <ja>@Property</ja>(name=HtmlDocSerializerContext.<jsf>HTMLDOC_title</jsf>, value=<js>"Sample JSON-Schema document"</js>), - <ja>@Property</ja>(name=HtmlDocSerializerContext.<jsf>HTMLDOC_links</jsf>, value=<js>"{options:'?method=OPTIONS'}"</js>) - } + title=<js>"Sample JSON-Schema document"</js>, + pageLinks=<js>"{options:'?method=OPTIONS'}"</js> ) <jk>public class</jk> JsonSchemaResource <jk>extends</jk> RestServletJenaDefault { http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/juneau-core/src/main/java/org/apache/juneau/html/HtmlDocSerializer.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/html/HtmlDocSerializer.java b/juneau-core/src/main/java/org/apache/juneau/html/HtmlDocSerializer.java index 03ca0ec..b7030e5 100644 --- a/juneau-core/src/main/java/org/apache/juneau/html/HtmlDocSerializer.java +++ b/juneau-core/src/main/java/org/apache/juneau/html/HtmlDocSerializer.java @@ -112,7 +112,7 @@ public class HtmlDocSerializer extends HtmlStrippedDocSerializer { String title = s.getTitle(); if (title == null && isOptionsPage) title = "Options"; - String description = s.getDescription(); + String description = s.getText(); if (title != null) w.oTag(1, "h3").attr("class", "title").append('>').text(title).eTag("h3").nl(); if (description != null) http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/juneau-core/src/main/java/org/apache/juneau/html/HtmlDocSerializerContext.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/html/HtmlDocSerializerContext.java b/juneau-core/src/main/java/org/apache/juneau/html/HtmlDocSerializerContext.java index 1849755..4101832 100644 --- a/juneau-core/src/main/java/org/apache/juneau/html/HtmlDocSerializerContext.java +++ b/juneau-core/src/main/java/org/apache/juneau/html/HtmlDocSerializerContext.java @@ -35,6 +35,18 @@ import org.apache.juneau.*; * <jk>public class</jk> AddressBookResource <jk>extends</jk> RestServletJenaDefault { * </p> * <p> + * Note that shortcut annotations are also provided for these particular settings: + * <p class='bcode'> + * <ja>@RestResource</ja>( + * messages=<js>"nls/AddressBookResource"</js>, + * title=<js>"$L{title}"</js>, <jc>// or pageTitle</jc> + * description=<js>"$L{description}"</js>, <jc>// or pageText</jc> + * pageLinks=<js>"{options:'?method=OPTIONS',doc:'doc'}"</js> + * ) + * <jk>public class</jk> AddressBookResource <jk>extends</jk> RestServletJenaDefault { + * </p> + * + * <p> * The <code>$L{...}</code> variable represent localized strings pulled from the resource bundle identified by the <code>messages</code> annotation. * These variables are replaced at runtime based on the HTTP request locale. * Several built-in runtime variable types are defined, and the API can be extended to include user-defined variables. @@ -86,6 +98,15 @@ public final class HtmlDocSerializerContext extends HtmlSerializerContext { * ...to produce this title on the HTML page... * </p> * <img class='bordered' src='doc-files/HTML_TITLE.png'> + * <p> + * Shortcuts on <ja>@RestResource</ja> are also provided for this setting: + * <p class='bcode'> + * <ja>@RestResource</ja>( + * messages=<js>"nls/AddressBookResource"</js>, + * title=<js>"My title"</js>, <jc>// or pageTitle</jc> + * ) + * <jk>public class</jk> AddressBookResource <jk>extends</jk> RestServletJenaDefault { + * </p> */ public static final String HTMLDOC_title = "HtmlSerializer.title"; @@ -108,7 +129,7 @@ public final class HtmlDocSerializerContext extends HtmlSerializerContext { * <ja>@RestResource</ja>( * messages=<js>"nls/AddressBookResource"</js>, * properties={ - * <ja>@Property</ja>(name=HtmlDocSerializerContext.<jsf>HTMLDOC_description</jsf>, value=<js>"description"</js>, type=<jsf>NLS</jsf>) + * <ja>@Property</ja>(name=HtmlDocSerializerContext.<jsf>HTMLDOC_description</jsf>, value=<js>"My description"</js>) * } * ) * <jk>public class</jk> AddressBookResource <jk>extends</jk> RestServletJenaDefault { @@ -123,8 +144,17 @@ public final class HtmlDocSerializerContext extends HtmlSerializerContext { * ...to produce this description on the HTML page... * </p> * <img class='bordered' src='doc-files/HTML_DESCRIPTION.png'> + * <p> + * Shortcuts on <ja>@RestResource</ja> are also provided for this setting: + * <p class='bcode'> + * <ja>@RestResource</ja>( + * messages=<js>"nls/AddressBookResource"</js>, + * description=<js>"My description"</js>, <jc>// or pageText</jc> + * ) + * <jk>public class</jk> AddressBookResource <jk>extends</jk> RestServletJenaDefault { + * </p> */ - public static final String HTMLDOC_description = "HtmlSerializer.description"; + public static final String HTMLDOC_text = "HtmlSerializer.description"; /** * <b>Configuration property:</b> Page links. @@ -165,6 +195,15 @@ public final class HtmlDocSerializerContext extends HtmlSerializerContext { * ...to produce this list of links on the HTML page... * </p> * <img class='bordered' src='doc-files/HTML_LINKS.png'> + * <p> + * A shortcut on <ja>@RestResource</ja> is also provided for this setting: + * <p class='bcode'> + * <ja>@RestResource</ja>( + * messages=<js>"nls/AddressBookResource"</js>, + * pageLinks=<js>"{options:'?method=OPTIONS',doc:'doc'}"</js> + * ) + * <jk>public class</jk> AddressBookResource <jk>extends</jk> RestServletJenaDefault { + * </p> */ public static final String HTMLDOC_links = "HtmlDocSerializer.links.map"; @@ -225,7 +264,7 @@ public final class HtmlDocSerializerContext extends HtmlSerializerContext { final String[] cssImports; final Map<String,String> links; - final String title, description, cssUrl; + final String title, text, cssUrl; final boolean nowrap; /** @@ -239,7 +278,7 @@ public final class HtmlDocSerializerContext extends HtmlSerializerContext { super(ps); cssImports = ps.getProperty(HTMLDOC_cssImports, String[].class, new String[0]); title = ps.getProperty(HTMLDOC_title, String.class, null); - description = ps.getProperty(HTMLDOC_description, String.class, null); + text = ps.getProperty(HTMLDOC_text, String.class, null); cssUrl = ps.getProperty(HTMLDOC_cssUrl, String.class, null); nowrap = ps.getProperty(HTMLDOC_nowrap, boolean.class, false); links = ps.getMap(HTMLDOC_links, String.class, String.class, Collections.<String,String>emptyMap()); @@ -251,7 +290,7 @@ public final class HtmlDocSerializerContext extends HtmlSerializerContext { .append("HtmlDocSerializerContext", new ObjectMap() .append("cssImports", cssImports) .append("title", title) - .append("description", description) + .append("text", text) .append("cssUrl", cssUrl) .append("nowrap", nowrap) .append("links", links) http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/juneau-core/src/main/java/org/apache/juneau/html/HtmlDocSerializerSession.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/html/HtmlDocSerializerSession.java b/juneau-core/src/main/java/org/apache/juneau/html/HtmlDocSerializerSession.java index 94666f8..440c80b 100644 --- a/juneau-core/src/main/java/org/apache/juneau/html/HtmlDocSerializerSession.java +++ b/juneau-core/src/main/java/org/apache/juneau/html/HtmlDocSerializerSession.java @@ -31,7 +31,7 @@ import org.apache.juneau.serializer.*; */ public final class HtmlDocSerializerSession extends HtmlSerializerSession { - private final String title, description, cssUrl; + private final String title, text, cssUrl; private final String[] cssImports; private final Map<String,String> links; private final boolean nowrap; @@ -56,14 +56,14 @@ public final class HtmlDocSerializerSession extends HtmlSerializerSession { super(ctx, op, output, javaMethod, locale, timeZone, mediaType); if (op == null || op.isEmpty()) { title = ctx.title; - description = ctx.description; + text = ctx.text; links = ctx.links; cssUrl = ctx.cssUrl; cssImports = ctx.cssImports; nowrap = ctx.nowrap; } else { title = op.getString(HTMLDOC_title, ctx.title); - description = op.getString(HTMLDOC_description, ctx.description); + text = op.getString(HTMLDOC_text, ctx.text); links = new LinkedHashMap(op.getMap(HTMLDOC_links, ctx.links)); cssUrl = op.getString(HTMLDOC_cssUrl, ctx.cssUrl); cssImports = StringUtils.split(op.getString(HTMLDOC_cssImports, null), ','); @@ -81,12 +81,12 @@ public final class HtmlDocSerializerSession extends HtmlSerializerSession { } /** - * Returns the {@link HtmlDocSerializerContext#HTMLDOC_description} setting value in this context. + * Returns the {@link HtmlDocSerializerContext#HTMLDOC_text} setting value in this context. * - * @return The {@link HtmlDocSerializerContext#HTMLDOC_description} setting value in this context. + * @return The {@link HtmlDocSerializerContext#HTMLDOC_text} setting value in this context. */ - public final String getDescription() { - return description; + public final String getText() { + return text; } /** http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/juneau-core/src/main/java/org/apache/juneau/json/package.html ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/json/package.html b/juneau-core/src/main/java/org/apache/juneau/json/package.html index f302ec9..b6decc1 100644 --- a/juneau-core/src/main/java/org/apache/juneau/json/package.html +++ b/juneau-core/src/main/java/org/apache/juneau/json/package.html @@ -1002,12 +1002,12 @@ // Consists of an in-memory address book repository.</jc> <ja>@RestResource</ja>( messages=<js>"nls/AddressBookResource"</js>, + title=<js>"$L{title}"</js>, + description=<js>"$L{description}"</js>, + pageLinks=<js>"{options:'?method=OPTIONS',doc:'doc'}"</js>, properties={ <ja>@Property</ja>(name=SerializerContext.<jsf>SERIALIZER_quoteChar</jsf>, value=<js>"'"</js>), - <ja>@Property</ja>(name=HtmlSerializerContext.<jsf>HTML_uriAnchorText</jsf>, value=<jsf>TO_STRING</jsf>), - <ja>@Property</ja>(name=HtmlDocSerializerContext.<jsf>HTMLDOC_title</jsf>, value=<js>"$L{title}"</js>), - <ja>@Property</ja>(name=HtmlDocSerializerContext.<jsf>HTMLDOC_description</jsf>, value=<js>"$L{description}"</js>), - <ja>@Property</ja>(name=HtmlDocSerializerContext.<jsf>HTMLDOC_links</jsf>, value=<js>"{options:'?method=OPTIONS',doc:'doc'}"</js>) + <ja>@Property</ja>(name=HtmlSerializerContext.<jsf>HTML_uriAnchorText</jsf>, value=<jsf>TO_STRING</jsf>) }, encoders=GzipEncoder.<jk>class</jk> ) @@ -1036,8 +1036,8 @@ <p class='bcode'> <jc>// GET person request handler</jc> <ja>@RestMethod</ja>(name=<js>"GET"</js>, path=<js>"/people/{id}/*"</js>, rc={200,404}) - <jk>public</jk> Person getPerson(RestRequest req, <ja>@Path</ja> <jk>int</jk> id) throws Exception { - properties.put(HtmlDocSerializerContext.<jsf>HTMLDOC_title</jsf>, req.getPathInfo()); + <jk>public</jk> Person getPerson(RestRequest req, RestResponse res, <ja>@Path</ja> <jk>int</jk> id) throws Exception { + res.setPageTitle(req.getPathInfo()); <jk>return</jk> findPerson(id); } @@ -1096,8 +1096,8 @@ <ja>@Property</ja>(name=SerializerContext.<jsf>SERIALIZER_quoteChar</jsf>, value=<js>"'"</js>) } ) - <jk>public</jk> Person getPerson(RestRequest req, <ja>@Path</ja> <jk>int</jk> id) throws Exception { - properties.put(HtmlDocSerializerContext.<jsf>HTMLDOC_title</jsf>, req.getPathInfo()); + <jk>public</jk> Person getPerson(RestRequest req, RestResponse res, <ja>@Path</ja> <jk>int</jk> id) throws Exception { + res.setPageTitle(req.getPathInfo()); <jk>return</jk> findPerson(id); } </p> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/juneau-core/src/main/java/org/apache/juneau/serializer/StringObject.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/serializer/StringObject.java b/juneau-core/src/main/java/org/apache/juneau/serializer/StringObject.java deleted file mode 100644 index 81ae833..0000000 --- a/juneau-core/src/main/java/org/apache/juneau/serializer/StringObject.java +++ /dev/null @@ -1,92 +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.serializer; - -import java.io.*; - -import org.apache.juneau.*; -import org.apache.juneau.json.*; - -/** - * A serializer/object pair used for delayed object serialization. - * <p> - * Useful in certain conditions such as logging when you don't want to needlessly serialize objects. - * <p> - * Instances of this method are created by the {@link WriterSerializer#toStringObject(Object)} method. - * - * <h5 class='section'>Example:</h5> - * <p class='bcode'> - * <jc>// The POJO will not be serialized unless DEBUG is enabled.</jc> - * logger.log(<jsf>DEBUG</jsf>, <js>"Object contents are: {0}"</js>, JsonSerializer.<jsf>DEFAULT</jsf>.toObjectString(myPojo)); - * </p> - */ -public class StringObject implements CharSequence, Writable { - - private final WriterSerializer s; - private final Object o; - private String results; - - /** - * Constructor. - * @param s The serializer to use to serialize the object. - * @param o The object to be serialized. - */ - public StringObject(WriterSerializer s, Object o) { - this.s = s; - this.o = o; - } - - /** - * Constructor with default serializer {@link JsonSerializer#DEFAULT_LAX} - * @param o The object to be serialized. - */ - public StringObject(Object o) { - this(JsonSerializer.DEFAULT_LAX, o); - } - - @Override /* Object */ - public String toString() { - if (results == null) - results = s.toString(o); - return results; - } - - @Override /* CharSequence */ - public int length() { - return toString().length(); - } - - @Override /* CharSequence */ - public char charAt(int index) { - return toString().charAt(index); - } - - @Override /* CharSequence */ - public CharSequence subSequence(int start, int end) { - return toString().subSequence(start, end); - } - - @Override /* Writable */ - public void writeTo(Writer w) throws IOException { - try { - s.serialize(o, w); - } catch (SerializeException e) { - throw new IOException(e); - } - } - - @Override /* Writable */ - public MediaType getMediaType() { - return s.getMediaTypes()[0]; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/juneau-core/src/main/java/org/apache/juneau/serializer/WriterSerializer.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/serializer/WriterSerializer.java b/juneau-core/src/main/java/org/apache/juneau/serializer/WriterSerializer.java index e84e593..9a5c79e 100644 --- a/juneau-core/src/main/java/org/apache/juneau/serializer/WriterSerializer.java +++ b/juneau-core/src/main/java/org/apache/juneau/serializer/WriterSerializer.java @@ -18,6 +18,7 @@ import java.util.*; import org.apache.juneau.*; import org.apache.juneau.annotation.*; +import org.apache.juneau.utils.*; /** * Subclass of {@link Serializer} for character-based serializers. http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/juneau-core/src/main/java/org/apache/juneau/uon/package.html ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/uon/package.html b/juneau-core/src/main/java/org/apache/juneau/uon/package.html index 6c2c6ca..1794466 100644 --- a/juneau-core/src/main/java/org/apache/juneau/uon/package.html +++ b/juneau-core/src/main/java/org/apache/juneau/uon/package.html @@ -986,11 +986,11 @@ // Consists of an in-memory address book repository.</jc> <ja>@RestResource</ja>( messages=<js>"nls/AddressBookResource"</js>, + title=<js>"$L{title}"</js>, + description=<js>"$L{description}"</js>, + pageLinks=<js>"{options:'?method=OPTIONS',doc:'doc'}"</js>, properties={ - <ja>@Property</ja>(name=SerializerContext.<jsf>SERIALIZER_useWhitespace</jsf>, value=<js>"true"</js>), - <ja>@Property</ja>(name=HtmlDocSerializerContext.<jsf>HTMLDOC_title</jsf>, value=<js>"$L{title}"</js>), - <ja>@Property</ja>(name=HtmlDocSerializerContext.<jsf>HTMLDOC_description</jsf>, value=<js>"$L{description}"</js>), - <ja>@Property</ja>(name=HtmlDocSerializerContext.<jsf>HTMLDOC_links</jsf>, value=<js>"{options:'?method=OPTIONS',doc:'doc'}"</js>) + <ja>@Property</ja>(name=SerializerContext.<jsf>SERIALIZER_useWhitespace</jsf>, value=<js>"true"</js>) }, encoders=GzipEncoder.<jk>class</jk> ) @@ -1019,8 +1019,8 @@ <p class='bcode'> <jc>// GET person request handler</jc> <ja>@RestMethod</ja>(name=<js>"GET"</js>, path=<js>"/people/{id}/*"</js>, rc={200,404}) - <jk>public</jk> Person getPerson(RestRequest req, <ja>@Path</ja> <jk>int</jk> id) throws Exception { - properties.put(HtmlDocSerializerContext.<jsf>HTMLDOC_title</jsf>, req.getPathInfo()); + <jk>public</jk> Person getPerson(RestRequest req, RestResponse res, <ja>@Path</ja> <jk>int</jk> id) throws Exception { + res.setPageTitle(req.getPathInfo()); <jk>return</jk> findPerson(id); } @@ -1079,8 +1079,8 @@ <ja>@Property</ja>(name=SerializerContext.<jsf>SERIALIZER_useWhitespace</jsf>, value=<js>"true"</js>) } ) - <jk>public</jk> Person getPerson(RestRequest req, <ja>@Path</ja> <jk>int</jk> id) throws Exception { - properties.put(HtmlDocSerializerContext.<jsf>HTMLDOC_title</jsf>, req.getPathInfo()); + <jk>public</jk> Person getPerson(RestRequest req, RestResponse res, <ja>@Path</ja> <jk>int</jk> id) throws Exception { + res.setPageTitle(req.getPathInfo()); <jk>return</jk> findPerson(id); } </p> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/juneau-core/src/main/java/org/apache/juneau/urlencoding/package.html ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/urlencoding/package.html b/juneau-core/src/main/java/org/apache/juneau/urlencoding/package.html index ddb09b2..ce7f90e 100644 --- a/juneau-core/src/main/java/org/apache/juneau/urlencoding/package.html +++ b/juneau-core/src/main/java/org/apache/juneau/urlencoding/package.html @@ -986,11 +986,11 @@ // Consists of an in-memory address book repository.</jc> <ja>@RestResource</ja>( messages=<js>"nls/AddressBookResource"</js>, + title=<js>"$L{title}"</js>, + description=<js>"$L{description}"</js>, + pageLinks=<js>"{options:'?method=OPTIONS',doc:'doc'}"</js>, properties={ - <ja>@Property</ja>(name=SerializerContext.<jsf>SERIALIZER_useWhitespace</jsf>, value=<js>"true"</js>), - <ja>@Property</ja>(name=HtmlDocSerializerContext.<jsf>HTMLDOC_title</jsf>, value=<js>"$L{title}"</js>), - <ja>@Property</ja>(name=HtmlDocSerializerContext.<jsf>HTMLDOC_description</jsf>, value=<js>"$L{description}"</js>), - <ja>@Property</ja>(name=HtmlDocSerializerContext.<jsf>HTMLDOC_links</jsf>, value=<js>"{options:'?method=OPTIONS',doc:'doc'}"</js>) + <ja>@Property</ja>(name=SerializerContext.<jsf>SERIALIZER_useWhitespace</jsf>, value=<js>"true"</js>) }, encoders=GzipEncoder.<jk>class</jk> ) @@ -1019,8 +1019,8 @@ <p class='bcode'> <jc>// GET person request handler</jc> <ja>@RestMethod</ja>(name=<js>"GET"</js>, path=<js>"/people/{id}/*"</js>, rc={200,404}) - <jk>public</jk> Person getPerson(RestRequest req, <ja>@Path</ja> <jk>int</jk> id) throws Exception { - properties.put(HtmlDocSerializerContext.<jsf>HTMLDOC_title</jsf>, req.getPathInfo()); + <jk>public</jk> Person getPerson(RestRequest req, RestResponse res, <ja>@Path</ja> <jk>int</jk> id) throws Exception { + res.setPageTitle(req.getPathInfo()); <jk>return</jk> findPerson(id); } @@ -1079,8 +1079,8 @@ <ja>@Property</ja>(name=SerializerContext.<jsf>SERIALIZER_useWhitespace</jsf>, value=<js>"true"</js>) } ) - <jk>public</jk> Person getPerson(RestRequest req, <ja>@Path</ja> <jk>int</jk> id) throws Exception { - properties.put(HtmlDocSerializerContext.<jsf>HTMLDOC_title</jsf>, req.getPathInfo()); + <jk>public</jk> Person getPerson(RestRequest req, RestResponse res, <ja>@Path</ja> <jk>int</jk> id) throws Exception { + res.setPageTitle(req.getPathInfo()); <jk>return</jk> findPerson(id); } </p> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/juneau-core/src/main/java/org/apache/juneau/utils/StringMessage.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/utils/StringMessage.java b/juneau-core/src/main/java/org/apache/juneau/utils/StringMessage.java new file mode 100644 index 0000000..f7403f1 --- /dev/null +++ b/juneau-core/src/main/java/org/apache/juneau/utils/StringMessage.java @@ -0,0 +1,76 @@ +// *************************************************************************************************************************** +// * 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.utils; + +import java.io.*; +import java.text.*; + +import org.apache.juneau.*; + +/** + * An encapsulated MessageFormat-style string and arguments. + * <p> + * Useful for delayed serialization of arguments for logging. + * Message string will not be constructed until the <code>toString()</code> method is called. + */ +public class StringMessage implements CharSequence, Writable { + + private final String pattern; + private final Object[] args; + private String results; + + /** + * Constructor. + * + * @param pattern {@link MessageFormat}-style pattern. + * @param args Message arguments. + */ + public StringMessage(String pattern, Object...args) { + this.pattern = pattern; + this.args = args; + } + + @Override /* Writable */ + public void writeTo(Writer w) throws IOException { + w.write(toString()); + + } + + @Override /* Writable */ + public MediaType getMediaType() { + // TODO Auto-generated method stub + return null; + } + + @Override /* CharSequence */ + public char charAt(int index) { + return toString().charAt(index); + } + + @Override /* CharSequence */ + public int length() { + return toString().length(); + } + + @Override /* CharSequence */ + public CharSequence subSequence(int start, int end) { + return toString().subSequence(start, end); + } + + @Override /* Object */ + public String toString() { + if (results == null) + results = (args.length == 0 ? pattern : MessageFormat.format(pattern, args)); + return results; + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/juneau-core/src/main/java/org/apache/juneau/utils/StringObject.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/utils/StringObject.java b/juneau-core/src/main/java/org/apache/juneau/utils/StringObject.java new file mode 100644 index 0000000..04b7c99 --- /dev/null +++ b/juneau-core/src/main/java/org/apache/juneau/utils/StringObject.java @@ -0,0 +1,93 @@ +// *************************************************************************************************************************** +// * 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.utils; + +import java.io.*; + +import org.apache.juneau.*; +import org.apache.juneau.json.*; +import org.apache.juneau.serializer.*; + +/** + * A serializer/object pair used for delayed object serialization. + * <p> + * Useful in certain conditions such as logging when you don't want to needlessly serialize objects. + * <p> + * Instances of this method are created by the {@link WriterSerializer#toStringObject(Object)} method. + * + * <h5 class='section'>Example:</h5> + * <p class='bcode'> + * <jc>// The POJO will not be serialized unless DEBUG is enabled.</jc> + * logger.log(<jsf>DEBUG</jsf>, <js>"Object contents are: {0}"</js>, JsonSerializer.<jsf>DEFAULT</jsf>.toObjectString(myPojo)); + * </p> + */ +public class StringObject implements CharSequence, Writable { + + private final WriterSerializer s; + private final Object o; + private String results; + + /** + * Constructor. + * @param s The serializer to use to serialize the object. + * @param o The object to be serialized. + */ + public StringObject(WriterSerializer s, Object o) { + this.s = s; + this.o = o; + } + + /** + * Constructor with default serializer {@link JsonSerializer#DEFAULT_LAX} + * @param o The object to be serialized. + */ + public StringObject(Object o) { + this(JsonSerializer.DEFAULT_LAX, o); + } + + @Override /* Object */ + public String toString() { + if (results == null) + results = s.toString(o); + return results; + } + + @Override /* CharSequence */ + public int length() { + return toString().length(); + } + + @Override /* CharSequence */ + public char charAt(int index) { + return toString().charAt(index); + } + + @Override /* CharSequence */ + public CharSequence subSequence(int start, int end) { + return toString().subSequence(start, end); + } + + @Override /* Writable */ + public void writeTo(Writer w) throws IOException { + try { + s.serialize(o, w); + } catch (SerializeException e) { + throw new IOException(e); + } + } + + @Override /* Writable */ + public MediaType getMediaType() { + return s.getMediaTypes()[0]; + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/juneau-core/src/main/java/org/apache/juneau/xml/package.html ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/xml/package.html b/juneau-core/src/main/java/org/apache/juneau/xml/package.html index 4c0fbeb..eb6377b 100644 --- a/juneau-core/src/main/java/org/apache/juneau/xml/package.html +++ b/juneau-core/src/main/java/org/apache/juneau/xml/package.html @@ -2921,12 +2921,12 @@ // Consists of an in-memory address book repository.</jc> <ja>@RestResource</ja>( messages=<js>"nls/AddressBookResource"</js>, + title=<js>"$L{title}"</js>, + description=<js>"$L{description}"</js>, + pageLinks=<js>"{options:'?method=OPTIONS',doc:'doc'}"</js>, properties={ <ja>@Property</ja>(name=SerializerContext.<jsf>SERIALIZER_quoteChar</jsf>, value=<js>"'"</js>), - <ja>@Property</ja>(name=HtmlSerializerContext.<jsf>HTML_uriAnchorText</jsf>, value=<jsf>TO_STRING</jsf>), - <ja>@Property</ja>(name=HtmlDocSerializerContext.<jsf>HTMLDOC_title</jsf>, value=<js>"$L{title}"</js>), - <ja>@Property</ja>(name=HtmlDocSerializerContext.<jsf>HTMLDOC_description</jsf>, value=<js>"$L{description}"</js>), - <ja>@Property</ja>(name=HtmlDocSerializerContext.<jsf>HTMLDOC_links</jsf>, value=<js>"{options:'?method=OPTIONS',doc:'doc'}"</js>) + <ja>@Property</ja>(name=HtmlSerializerContext.<jsf>HTML_uriAnchorText</jsf>, value=<jsf>TO_STRING</jsf>) }, encoders=GzipEncoder.<jk>class</jk> ) @@ -2955,8 +2955,8 @@ <p class='bcode'> <jc>// GET person request handler</jc> <ja>@RestMethod</ja>(name=<js>"GET"</js>, path=<js>"/people/{id}/*"</js>, rc={200,404}) - <jk>public</jk> Person getPerson(RestRequest req, <ja>@Path</ja> <jk>int</jk> id) throws Exception { - properties.put(HtmlDocSerializerContext.<jsf>HTMLDOC_title</jsf>, req.getPathInfo()); + <jk>public</jk> Person getPerson(RestRequest req, RestResponse res, <ja>@Path</ja> <jk>int</jk> id) throws Exception { + res.setPageTitle(req.getPathInfo()); <jk>return</jk> findPerson(id); } @@ -3015,8 +3015,8 @@ <ja>@Property</ja>(name=SerializerContext.<jsf>SERIALIZER_quoteChar</jsf>, value=<js>"'"</js>) } ) - <jk>public</jk> Person getPerson(RestRequest req, <ja>@Path</ja> <jk>int</jk> id) throws Exception { - properties.put(HtmlDocSerializerContext.<jsf>HTMLDOC_title</jsf>, req.getPathInfo()); + <jk>public</jk> Person getPerson(RestRequest req, RestRequest res, <ja>@Path</ja> <jk>int</jk> id) throws Exception { + res.setPageTitle(req.getPathInfo()); <jk>return</jk> findPerson(id); } </p> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/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 3b99922..f5353a1 100644 --- a/juneau-core/src/main/javadoc/overview.html +++ b/juneau-core/src/main/javadoc/overview.html @@ -1957,9 +1957,9 @@ path=<js>"/systemProperties"</js>, title=<js>"System properties resource"</js>, description=<js>"REST interface for performing CRUD operations on system properties."</js>, + pageLinks=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS'}"</js>, properties={ - <ja>@Property</ja>(name=<jsf>SERIALIZER_quoteChar</jsf>, value=<js>"'"</js>), - <ja>@Property</ja>(name=<jsf>HTMLDOC_links</jsf>, value=<js>"{up:'$R{requestParentURI}',options:'$R{servletURI}?method=OPTIONS'}"</js>), + <ja>@Property</ja>(name=<jsf>SERIALIZER_quoteChar</jsf>, value=<js>"'"</js>) }, stylesheet=<js>"styles/devops.css"</js>, encoders=GzipEncoder.<jk>class</jk>, @@ -2623,9 +2623,7 @@ <ja>@RestResource</ja>( path=<js>"/"</js>, messages=<js>"nls/RootResources"</js>, - properties={ - <ja>@Property</ja>(name=<jsf>HTMLDOC_links</jsf>, value=<js>"{options:'$R{servletURI}?method=OPTIONS',source:'$R{servletURI}/source?classes=(org.apache.juneau.rest.samples.RootResources)'}"</js>) - }, + pageLinks=<js>"{options:'?method=OPTIONS'}"</js>, children={ HelloWorldResource.<jk>class</jk>, MethodExampleResource.<jk>class</jk>, @@ -2717,9 +2715,7 @@ <ja>@RestResource</ja>( messages=<js>"nls/HelloWorldResource"</js>, path=<js>"/helloWorld"</js>, - properties={ - <ja>@Property</ja>(name=HTMLDOC_links, value=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS'}"</js>) - } + pageLinks=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS'}"</js> ) <jk>public class</jk> HelloWorldResource <jk>extends</jk> Resource { <jk>private static final long</jk> <jsf>serialVersionUID</jsf> = 1L; @@ -2794,9 +2790,7 @@ <ja>@RestResource</ja>( path=<js>"/methodExample"</js>, messages=<js>"nls/MethodExampleResource"</js>, - properties={ - <ja>@Property</ja>(name=<jsf>HTMLDOC_links</jsf>, value=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.MethodExampleResource)'}"</js>) - } + pageLinks=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS'}"</js> ) <jk>public class</jk> MethodExampleResource <jk>extends</jk> Resource { <jk>private static final long</jk> <jsf>serialVersionUID</jsf> = 1L; @@ -2938,9 +2932,7 @@ </p> <p class='bcode'> <ja>@RestResource</ja>( - properties={ - <ja>@Property</ja>(name=<jsf>HTMLDOC_links</jsf>, value=<js>"{options:'?method=OPTIONS'}"</js>) - } + pageLinks=<js>"{options:'?method=OPTIONS'}"</js> ) </p> <p> @@ -3205,10 +3197,10 @@ <ja>@RestResource</ja>( path=<js>"/echo"</js>, messages=<js>"nls/RequestEchoResource"</js>, + pageLinks=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS'}"</js>, properties={ <ja>@Property</ja>(name=<jsf>SERIALIZER_maxDepth</jsf>, value=<js>"10"</js>), - <ja>@Property</ja>(name=<jsf>SERIALIZER_detectRecursions</jsf>, value=<js>"true"</js>), - <ja>@Property</ja>(name=<jsf>HTMLDOC_links</jsf>, value=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.RequestEchoResource)'}"</js>) + <ja>@Property</ja>(name=<jsf>SERIALIZER_detectRecursions</jsf>, value=<js>"true"</js>) }, beanFilters={ <jc>// Interpret these as their parent classes, not subclasses</jc> @@ -3223,10 +3215,9 @@ <jd>/** GET request handler */</jd> <ja>@RestMethod</ja>(name=<js>"GET"</js>, path=<js>"/*"</js>, converters={Queryable.<jk>class</jk>,Traversable.<jk>class</jk>}) - <jk>public</jk> HttpServletRequest doGet(RestRequest req, <ja>@Properties</ja> ObjectMap properties) { + <jk>public</jk> HttpServletRequest doGet(RestRequest req, RestResponse res, <ja>@Properties</ja> ObjectMap properties) { <jc>// Set the HtmlDocSerializer title programmatically. - // This sets the value for this request only.</jc> - properties.put(<jsf>HTMLDOC_title</jsf>, <js>"Contents of HttpServletRequest object"</js>); + res.setPageTitle(req.getPathInfo()); <jc>// Just echo the request back as the response.</jc> <jk>return</jk> req; @@ -3264,7 +3255,7 @@ .addPojoSwaps(EnumerationSwap.<jk>class</jk>) .setProperty(<jsf>SERIALIZER_maxDepth</jsf>, 10) .setProperty(<jsf>SERIALIZER_detectRecursions</jsf>, <jk>true</jk>) - .property(<jsf>HTMLDOC_links</jsf>, <js>"{...}"</js>); + .setPageLinks(<js>"{...}"</js>); <jc>// Don't forget to call this!</jc> <jk>super</jk>.init(config); @@ -3661,13 +3652,13 @@ <ja>@RestResource</ja>( path=<js>"/addressBook"</js>, messages=<js>"nls/AddressBookResource"</js>, + pageLinks=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS'}"</js>, properties={ <ja>@Property</ja>(name=<jsf>REST_allowMethodParam</jsf>, value=<js>"*"</js>), <ja>@Property</ja>(name=<jsf>HTML_uriAnchorText</jsf>, value=<jsf>TO_STRING</jsf>), <ja>@Property</ja>(name=<jsf>SERIALIZER_quoteChar</jsf>, value=<js>"'"</js>), <ja>@Property</ja>(name=<jsf>RDF_rdfxml_tab</jsf>, value=<js>"5"</js>), <ja>@Property</ja>(name=<jsf>RDF_addRootProperty</jsf>, value=<js>"true"</js>), - <ja>@Property</ja>(name=<jsf>HTMLDOC_links</jsf>, value=<js>"{up:'$R{requestParentURI}',options:'$R{servletURI}?method=OPTIONS',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.addressbook.AddressBookResource,org.apache.juneau.examples.addressbook.Address,org.apache.juneau.examples.addressbook.AddressBook,org.apache.juneau.examples.addressbook.CreateAddress,org.apache.juneau.examples.addressbook.CreatePerson,org.apache.juneau.examples.addressbook.IAddressBook,org.apache.juneau.examples.addressbook.Person)'}"</js>), <jc>// Resolve all relative URIs so that they're relative to this servlet!</jc> <ja>@Property</ja>(name=<jsf>SERIALIZER_relativeUriBase</jsf>, value=<js>"$R{servletURI}"</js>), }, @@ -4310,10 +4301,10 @@ <ja>@RestResource</ja>( path=<js>"/remoteable"</js>, messages=<js>"nls/SampleRemoteableServlet"</js>, + title=<js>"Remoteable Service Proxy API"</js>, + description=<js>"Sample class showing how to use remoteable proxies. The list below are exposed services that can be retrieved using RestClient.getProxyInterface(Class)."</js>, + pageLinks=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS'}"</js>, properties={ - <ja>@Property</ja>(name=<jsf>HTMLDOC_title</jsf>, value=<js>"Remoteable Service Proxy API"</js>), - <ja>@Property</ja>(name=<jsf>HTMLDOC_description</jsf>, value=<js>"Sample class showing how to use remoteable proxies. The list below are exposed services that can be retrieved using RestClient.getProxyInterface(Class)."</js>), - <ja>@Property</ja>(name=<jsf>HTMLDOC_links</jsf>, value=<js>"{up:'$R{requestParentURI}',options:'$R{servletURI}?method=OPTIONS',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.SampleRemoteableServlet)'}"</js>), <jc>// Allow us to use method=POST from a browser.</jc> <ja>@Property</ja>(name=<jsf>REST_allowMethodParam</jsf>, value=<js>"*"</js>) } @@ -4417,12 +4408,12 @@ <ja>@RestResource</ja>( path=<js>"/tempDir"</js>, messages=<js>"nls/TempDirResource"</js>, + pageLinks=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS',upload:'upload'}"</js>, properties={ <ja>@Property</ja>(name=<js>"DirectoryResource.rootDir"</js>, value=<js>"$S{java.io.tmpdir}"</js>), <ja>@Property</ja>(name=<js>"DirectoryResource.allowViews"</js>, value=<js>"true"</js>), <ja>@Property</ja>(name=<js>"DirectoryResource.allowDeletes"</js>, value=<js>"true"</js>), - <ja>@Property</ja>(name=<js>"DirectoryResource.allowPuts"</js>, value=<js>"false"</js>), - <ja>@Property</ja>(name=HTMLDOC_links, value=<js>"{up:'$R{requestParentURI}',options:'$R{servletURI}?method=OPTIONS',upload:'upload',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.TempDirResource,org.apache.juneau.rest.samples.DirectoryResource)'}"</js>), + <ja>@Property</ja>(name=<js>"DirectoryResource.allowPuts"</js>, value=<js>"false"</js>) }, stylesheet=<js>"styles/devops.css"</js> ) @@ -4535,11 +4526,11 @@ <ja>@RestResource</ja>( path=<js>"/atom"</js>, messages=<js>"nls/AtomFeedResource"</js>, + pageLinks=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS'}"</js>, properties={ <ja>@Property</ja>(name=<jsf>SERIALIZER_quoteChar</jsf>, value=<js>"'"</js>), <ja>@Property</ja>(name=<jsf>RDF_rdfxml_tab</jsf>, value=<js>"5"</js>), - <ja>@Property</ja>(name=<jsf>RDF_addRootProperty</jsf>, value=<js>"true"</js>), - <ja>@Property</ja>(name=<jsf>HTMLDOC_links</jsf>, value=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.AtomFeedResource)'}"</js>) + <ja>@Property</ja>(name=<jsf>RDF_addRootProperty</jsf>, value=<js>"true"</js>) }, encoders=GzipEncoder.<jk>class</jk> ) @@ -4643,9 +4634,7 @@ <ja>@RestResource</ja>( path=<js>"/docker"</js>, title=<js>"Sample Docker resource"</js>, - properties={ - <ja>@Property</ja>(name=<jsf>HTMLDOC_links</jsf>, value=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.AtomFeedResource)'}"</js>) - } + pageLinks=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS'}"</js> ) <jk>public class</jk> DockerRegistryResource <jk>extends</jk> Resource { <jk>private static final long</jk> <jsf>serialVersionUID</jsf> = 1L; @@ -4724,11 +4713,9 @@ <ja>@RestResource</ja>( path=<js>"/tumblrParser"</js>, messages=<js>"nls/TumblrParserResource"</js>, - properties={ - <ja>@Property</ja>(name=<jsf>HTMLDOC_links</jsf>, value=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.TumblrParserResource)'}"</js>), - <ja>@Property</ja>(name=<jsf>HTMLDOC_title</jsf>, value=<js>"Tumblr parser service"</js>), - <ja>@Property</ja>(name=<jsf>HTMLDOC_description</jsf>, value=<js>"Specify a URL to a Tumblr blog and parse the results."</js>) - } + title=<js>"Tumblr parser service"</js>, + description=<js>"Specify a URL to a Tumblr blog and parse the results."</js>, + pageLinks=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS'}"</js> ) <jk>public class</jk> TumblrParserResource <jk>extends</jk> Resource { <jk>private static final long</jk> <jsf>serialVersionUID</jsf> = 1L; @@ -4808,11 +4795,9 @@ <ja>@RestResource</ja>( path=<js>"/photos"</js>, messages=<js>"nls/PhotosResource"</js>, - properties={ - <ja>@Property</ja>(name=HtmlDocSerializerContext.<jsf>HTMLDOC_links</jsf>, value=<js>"{options:'?method=OPTIONS'}"</js>), - <ja>@Property</ja>(name=HtmlDocSerializerContext.<jsf>HTMLDOC_title</jsf>, value=<js>"Photo REST service"</js>), - <ja>@Property</ja>(name=HtmlDocSerializerContext.<jsf>HTMLDOC_description</jsf>, value=<js>"Use a tool like Poster to upload and retrieve jpeg and png images."</js>) - } + title=<js>"Photo REST service"</js>, + description=<js>"Use a tool like Poster to upload and retrieve jpeg and png images."</js>, + pageLinks=<js>"{options:'?method=OPTIONS'}"</js> ) <jk>public class</jk> PhotosResource <jk>extends</jk> RestServletDefault { @@ -4854,8 +4839,8 @@ <jd>/** GET request handler for list of all photos */</jd> <ja>@RestMethod</ja>(name=<js>"GET"</js>, path=<js>"/"</js>) <jk>public</jk> Collection<Photo> getAllPhotos(RestRequest req, RestResponse res) <jk>throws</jk> Exception { - res.setProperty(HtmlDocSerializerContext.<jsf>HTMLDOC_title</jsf>, <js>"Photo REST service"</js>); - res.setProperty(HtmlDocSerializerContext.<jsf>HTMLDOC_description</jsf>, <js>"Use a tool like Poster to upload and retrieve jpeg and png images."</js>); + res.setPageTitle(<js>"Photo REST service"</js>); + res.setPageText(<js>"Use a tool like Poster to upload and retrieve jpeg and png images."</js>); <jk>return</jk> photos.values(); } @@ -4950,10 +4935,8 @@ <ja>@RestResource</ja>( path=<js>"/jsonSchema"</js>, messages=<js>"nls/JsonSchemaResource"</js>, - properties={ - <ja>@Property</ja>(name=<jsf>HTMLDOC_title</jsf>, value=<js>"Sample JSON-Schema document"</js>), - <ja>@Property</ja>(name=<jsf>HTMLDOC_links</jsf>, value=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.JsonSchemaResource)'}"</js>) - } + title=<js>"Sample JSON-Schema document"</js>, + pageLinks=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS'}"</js> ) <jk>public class</jk> JsonSchemaResource <jk>extends</jk> ResourceJena { <jk>private static final long</jk> <jsf>serialVersionUID</jsf> = 1L; @@ -5032,11 +5015,9 @@ <ja>@RestResource</ja>( path=<js>"/sqlQuery"</js>, messages=<js>"nls/SqlQueryResource"</js>, - properties={ - <ja>@Property</ja>(name=<jsf>HTMLDOC_title</jsf>, value=<js>"SQL query service"</js>), - <ja>@Property</ja>(name=<jsf>HTMLDOC_description</jsf>, value=<js>"Executes queries against the local derby '$C{SqlQueryResource/connectionUrl}' database"</js>), - <ja>@Property</ja>(name=<jsf>HTMLDOC_links</jsf>, value=<js>"{up:'$R{requestParentURI}',options:'$R{servletURI}?method=OPTIONS',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.SqlQueryResource)'}"</js>), - } + title=<js>"SQL query service"</js>, + description=<js>"Executes queries against the local derby '$C{SqlQueryResource/connectionUrl}' database"</js>, + pageLinks=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS'}"</js> ) <jk>public class</jk> SqlQueryResource <jk>extends</jk> Resource { <jk>private static final long</jk> <jsf>serialVersionUID</jsf> = 1L; @@ -5223,9 +5204,7 @@ path=<js>"/config"</js>, title=<js>"Configuration"</js>, description=<js>"Contents of configuration file."</js>, - properties={ - <ja>@Property</ja>(name=<jsf>HTMLDOC_links</jsf>, value=<js>"{up:'$R{requestParentURI}',options:'$R{servletURI}?method=OPTIONS',edit:'$R{servletURI}/edit'}"</js>), - } + pageLinks=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS',edit:'edit'}"</js> ) <jk>public class</jk> ConfigResource <jk>extends</jk> Resource { <jk>private static final long</jk> <jsf>serialVersionUID</jsf> = 1L; @@ -5729,6 +5708,7 @@ <li>{@link org.apache.juneau.serializer.SerializerGroupBuilder} <li>{@link org.apache.juneau.parser.ParserGroupBuilder} <li>{@link org.apache.juneau.encoders.EncoderGroupBuilder} + </ul> <li>Revamped the config file API to use a build: {@link org.apache.juneau.ini.ConfigFileBuilder}. <li>Removed the <code><del>Lockable</del></code> interface. <li>New <code>addBeanTypeProperties</code> setting added to serializers to override the @@ -5805,16 +5785,54 @@ </ul> <li>New annotations added to {@link org.apache.juneau.rest.annotation.RestResource @RestResource} to allow non-<code>RestServlet</code> resources to do the same as subclassing directly from <code>RestServlet</code>: - <ul> - <li>{@link org.apache.juneau.rest.annotation.RestResource#resourceResolver() resourceResolver()} - - Specify a {@link org.apache.juneau.rest.RestResourceResolver} class for resolving child resources. - <li>{@link org.apache.juneau.rest.annotation.RestResource#callHandler() callHandler()} - - Specify a {@link org.apache.juneau.rest.RestCallHandler} class for handling the lifecycle of a REST call. - <li>{@link org.apache.juneau.rest.annotation.RestResource#infoProvider() infoProvider()} - - Specify a {@link org.apache.juneau.rest.RestInfoProvider} class for customizing title/description/Swagger information on a REST resource. - <li>{@link org.apache.juneau.rest.annotation.RestResource#logger() logger()} - - Specify a {@link org.apache.juneau.rest.RestLogger} class for handling logging. - </ul> + <ul> + <li>{@link org.apache.juneau.rest.annotation.RestResource#resourceResolver() resourceResolver()} + - Specify a {@link org.apache.juneau.rest.RestResourceResolver} class for resolving child resources. + <li>{@link org.apache.juneau.rest.annotation.RestResource#callHandler() callHandler()} + - Specify a {@link org.apache.juneau.rest.RestCallHandler} class for handling the lifecycle of a REST call. + <li>{@link org.apache.juneau.rest.annotation.RestResource#infoProvider() infoProvider()} + - Specify a {@link org.apache.juneau.rest.RestInfoProvider} class for customizing title/description/Swagger information on a REST resource. + <li>{@link org.apache.juneau.rest.annotation.RestResource#logger() logger()} + - Specify a {@link org.apache.juneau.rest.RestLogger} class for handling logging. + </ul> + <li>New annotations added to {@link org.apache.juneau.rest.annotation.RestResource @RestResource} and {@link org.apache.juneau.rest.annotation.RestMethod @RestMethod} + to simplify defining page title, text, and links on HTML views: + <ul> + <li>{@link org.apache.juneau.rest.annotation.RestResource#pageTitle() @RestResource.pageTitle()} + <li>{@link org.apache.juneau.rest.annotation.RestMethod#pageTitle() @RestMethod.pageTitle()} + <li>{@link org.apache.juneau.rest.annotation.RestResource#pageText() @RestResource.pageText()} + <li>{@link org.apache.juneau.rest.annotation.RestMethod#pageText() @RestMethod.pageText()} + <li>{@link org.apache.juneau.rest.annotation.RestResource#pageLinks() @RestResource.pageLinks()} + <li>{@link org.apache.juneau.rest.annotation.RestMethod#pageLinks() @RestMethod.pageLinks()} + </ul> + <p class='bcode'> + <jc>// Old method</jc> + <ja>@RestResource</ja>( + properties={ + <ja>@Property</ja>(name=<jsf>HTMLDOC_title</jsf>, value=<js>"System properties resource"</js>), + <ja>@Property</ja>(name=<jsf>HTMLDOC_description</jsf>, value=<js>"REST interface for performing CRUD operations on system properties."</js>), + <ja>@Property</ja>(name=<jsf>HTMLDOC_links</jsf>, value=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS'}"</js>) + } + ) + + <jc>// New method</jc> + <ja>@RestResource</ja>( + pageTitle=<js>"System properties resource"</js>, + pageDescription=<js>"REST interface for performing CRUD operations on system properties."</js>, + pageLinks=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS'}"</js> + ) + </p> + <p> + Typically you're going to simply want to use the <code>title</code> and <code>description</code> annotations + which apply to both the page title/text and the swagger doc: + </p> + <p class='bcode'> + <ja>@RestResource</ja>( + title=<js>"System properties resource"</js>, + description=<js>"REST interface for performing CRUD operations on system properties."</js>, + pageLinks=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS'}"</js> + ) + </p> <li>{@link org.apache.juneau.rest.annotation.RestResource#stylesheet()} can now take in a comma-delimited list of stylesheet paths. <li>{@link org.apache.juneau.rest.StreamResource} can now contain multiple sources from a variety of source types (e.g. <code><jk>byte</jk>[]</code> arrays, <code>InputStreams</code>, <code>Files</code>, etc...) and is now immutable. It also includes a new {@link org.apache.juneau.rest.StreamResource.Builder} class. @@ -5858,6 +5876,7 @@ <li>{@link org.apache.juneau.rest.client.RestClientBuilder#debug(boolean)} now adds a <code>Debug: true</code> header on all requests. </ul> <li>New doc: <a class='doclink' href='org/apache/juneau/rest/client/package-summary.html#Debugging'>1.5 - Debugging</a> + <li>{@link org.apache.juneau.rest.annotation.RestMethod#name() @RestMethod.name()} annotation is now optional. Defaults to <js>"GET"</js>. </ul> <h6 class='topic'>org.apache.juneau.microservice</h6> @@ -6434,7 +6453,7 @@ <ul> <li>{@link org.apache.juneau.Streamable} interface for identifying objects that can be serialized directly to an output stream. <li>{@link org.apache.juneau.Writable} interface for identifying objects that can be serialized directly to a writer. - <li>{@link org.apache.juneau.serializer.StringObject} class that can be used for delayed object serialization. + <li><code><del>StringObject</del></code> class that can be used for delayed object serialization. <li>{@link org.apache.juneau.internal.ByteArrayCache} <li>{@link org.apache.juneau.internal.ByteArrayInOutStream} <li>{@link org.apache.juneau.internal.FileUtils} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/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 54e7937..0d0f884 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 @@ -29,12 +29,13 @@ import org.apache.juneau.rest.annotation.*; */ @RestResource( path="/atom", - messages="nls/AtomFeedResource", + title="Sample ATOM feed resource", + description="Sample resource that shows how to render ATOM feeds", + pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/AtomFeedResource.java'}", properties={ @Property(name=SERIALIZER_quoteChar, value="'"), @Property(name=RDF_rdfxml_tab, value="5"), - @Property(name=RDF_addRootProperty, value="true"), - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/AtomFeedResource.java'}") + @Property(name=RDF_addRootProperty, value="true") }, encoders=GzipEncoder.class ) @@ -86,7 +87,7 @@ public class AtomFeedResource extends ResourceJena { /** * GET request handler */ - @RestMethod(name="GET", path="/") + @RestMethod(name="GET", path="/", summary="Get the sample ATOM feed") public Feed getFeed() throws Exception { return feed; } @@ -95,7 +96,7 @@ public class AtomFeedResource extends ResourceJena { * PUT request handler. * Replaces the feed with the specified content, and then mirrors it as the response. */ - @RestMethod(name="PUT", path="/") + @RestMethod(name="PUT", path="/", summary="Overwrite the sample ATOM feed") public Feed setFeed(@Body Feed feed) throws Exception { this.feed = feed; return feed; http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/CodeFormatterResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/CodeFormatterResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/CodeFormatterResource.java index de9df31..10a0b07 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/CodeFormatterResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/CodeFormatterResource.java @@ -12,8 +12,6 @@ // *************************************************************************************************************************** package org.apache.juneau.examples.rest; -import static org.apache.juneau.html.HtmlDocSerializerContext.*; - import java.io.*; import org.apache.juneau.microservice.*; @@ -27,11 +25,9 @@ import org.apache.juneau.rest.annotation.*; @RestResource( path="/codeFormatter", messages="nls/CodeFormatterResource", - properties={ - @Property(name=HTMLDOC_title, value="Code Formatter"), - @Property(name=HTMLDOC_description, value="Add syntax highlighting tags to source code"), - @Property(name=HTMLDOC_links, value="{options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/CodeFormatterResource.java'}"), - } + title="Code Formatter", + description="Utility for generating HTML code-formatted source code", + pageLinks="{options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/CodeFormatterResource.java'}" ) @SuppressWarnings({"serial"}) public class CodeFormatterResource extends Resource { http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/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 f0b6a3d..9c3919f 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 @@ -35,9 +35,9 @@ import org.apache.juneau.utils.*; */ @RestResource( messages="nls/DirectoryResource", + pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/DirectoryResource.java'}", properties={ @Property(name=HTML_uriAnchorText, value=PROPERTY_NAME), - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/DirectoryResource.java'}"), @Property(name=REST_allowMethodParam, value="*"), @Property(name="rootDir", value="$S{java.io.tmpdir}"), @Property(name="allowViews", value="false"), http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/DockerRegistryResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/DockerRegistryResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/DockerRegistryResource.java index 00bc907..61192f0 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/DockerRegistryResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/DockerRegistryResource.java @@ -12,8 +12,6 @@ // *************************************************************************************************************************** package org.apache.juneau.examples.rest; -import static org.apache.juneau.html.HtmlDocSerializerContext.*; - import java.util.*; import org.apache.juneau.ini.*; @@ -29,9 +27,7 @@ import org.apache.juneau.rest.labels.*; @RestResource( path="/docker", title="Sample Docker resource", - properties={ - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/DockerRegistryResource.java'}") - } + pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/DockerRegistryResource.java'}" ) public class DockerRegistryResource extends Resource { private static final long serialVersionUID = 1L; http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/HelloWorldResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/HelloWorldResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/HelloWorldResource.java index 5b5fae8..935989b 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/HelloWorldResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/HelloWorldResource.java @@ -12,8 +12,6 @@ // *************************************************************************************************************************** package org.apache.juneau.examples.rest; -import static org.apache.juneau.html.HtmlDocSerializerContext.*; - import org.apache.juneau.microservice.*; import org.apache.juneau.rest.annotation.*; @@ -22,16 +20,16 @@ import org.apache.juneau.rest.annotation.*; */ @RestResource( messages="nls/HelloWorldResource", + title="Hello World sample resource", + description="Simplest possible resource", path="/helloWorld", - properties={ - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/HelloWorldResource.java'}") - } + pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/HelloWorldResource.java'}" ) public class HelloWorldResource extends Resource { private static final long serialVersionUID = 1L; /** GET request handler */ - @RestMethod(name="GET", path="/*") + @RestMethod(name="GET", path="/*", summary="Responds with \"Hello world!\"") public String sayHello() { return "Hello world!"; } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/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 ae17734..d4a6c90 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 @@ -12,8 +12,6 @@ // *************************************************************************************************************************** package org.apache.juneau.examples.rest; -import static org.apache.juneau.html.HtmlDocSerializerContext.*; - import org.apache.juneau.dto.jsonschema.*; import org.apache.juneau.microservice.*; import org.apache.juneau.rest.annotation.*; @@ -24,10 +22,9 @@ import org.apache.juneau.rest.annotation.*; @RestResource( path="/jsonSchema", messages="nls/JsonSchemaResource", - properties={ - @Property(name=HTMLDOC_title, value="Sample JSON-Schema document"), - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/JsonSchemaResource.java'}") - } + title="Sample JSON-Schema document", + description="Sample resource that shows how to generate JSON-Schema documents", + pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/JsonSchemaResource.java'}" ) public class JsonSchemaResource extends ResourceJena { private static final long serialVersionUID = 1L; @@ -57,7 +54,7 @@ public class JsonSchemaResource extends ResourceJena { } /** GET request handler */ - @RestMethod(name="GET", path="/") + @RestMethod(name="GET", path="/", summary="Get the JSON-Schema document") public Schema getSchema() throws Exception { return schema; } @@ -66,7 +63,7 @@ public class JsonSchemaResource extends ResourceJena { * PUT request handler. * Replaces the schema document with the specified content, and then mirrors it as the response. */ - @RestMethod(name="PUT", path="/") + @RestMethod(name="PUT", path="/", summary="Overwrite the JSON-Schema document") public Schema setSchema(@Body Schema schema) throws Exception { this.schema = schema; return schema; http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/MethodExampleResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/MethodExampleResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/MethodExampleResource.java index ee0a0b9..1d06a5a 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/MethodExampleResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/MethodExampleResource.java @@ -12,8 +12,6 @@ // *************************************************************************************************************************** package org.apache.juneau.examples.rest; -import static org.apache.juneau.html.HtmlDocSerializerContext.*; - import java.util.*; import org.apache.juneau.microservice.*; @@ -26,9 +24,7 @@ import org.apache.juneau.rest.annotation.*; @RestResource( path="/methodExample", messages="nls/MethodExampleResource", - properties={ - @Property(name=HTMLDOC_links, value="{up:'$R{servletParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/MethodExampleResource.java'}") - } + pageLinks="{up:'$R{servletParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/MethodExampleResource.java'}" ) public class MethodExampleResource extends Resource { private static final long serialVersionUID = 1L; http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PhotosResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PhotosResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PhotosResource.java index ff5c242..b5dace5 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PhotosResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PhotosResource.java @@ -37,10 +37,10 @@ import org.apache.juneau.serializer.*; @RestResource( path="/photos", messages="nls/PhotosResource", + title="Photo REST service", + description="Sample resource that allows images to be uploaded and retrieved.", + pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/PhotosResource.java'}", properties={ - @Property(name=HTMLDOC_title, value="Photo REST service"), - @Property(name=HTMLDOC_description, value="Use a tool like Poster to upload and retrieve jpeg and png images."), - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'$R{servletURI}?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/PhotosResource.java'}"), // Resolve all relative URIs so that they're relative to this servlet! @Property(name=SERIALIZER_relativeUriBase, value="$R{servletURI}"), } @@ -80,13 +80,13 @@ public class PhotosResource extends Resource { } /** GET request handler for list of all photos */ - @RestMethod(name="GET", path="/") + @RestMethod(name="GET", path="/", summary="Show the list of all currently loaded photos") public Collection<Photo> getAllPhotos() throws Exception { return photos.values(); } /** GET request handler for single photo */ - @RestMethod(name="GET", path="/{id}", serializers=ImageSerializer.class) + @RestMethod(name="GET", path="/{id}", serializers=ImageSerializer.class, summary="Get a photo by ID") public BufferedImage getPhoto(@Path int id) throws Exception { Photo p = photos.get(id); if (p == null) @@ -95,14 +95,14 @@ public class PhotosResource extends Resource { } /** PUT request handler */ - @RestMethod(name="PUT", path="/{id}", parsers=ImageParser.class) + @RestMethod(name="PUT", path="/{id}", parsers=ImageParser.class, summary="Add a photo") public String addPhoto(@Path int id, @Body BufferedImage image) throws Exception { photos.put(id, new Photo(id, image)); return "OK"; } /** POST request handler */ - @RestMethod(name="POST", path="/", parsers=ImageParser.class) + @RestMethod(name="POST", path="/", parsers=ImageParser.class, summary="Overwrite a photo by ID") public Photo setPhoto(@Body BufferedImage image) throws Exception { int id = photos.size(); Photo p = new Photo(id, image); @@ -111,7 +111,7 @@ public class PhotosResource extends Resource { } /** DELETE request handler */ - @RestMethod(name="DELETE", path="/{id}") + @RestMethod(name="DELETE", path="/{id}", summary="Delete a photo by ID") public String deletePhoto(@Path int id) throws Exception { Photo p = photos.remove(id); if (p == null) http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/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 5cbd34f..244f6a0 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 @@ -29,11 +29,12 @@ import org.apache.juneau.transforms.*; */ @RestResource( path="/echo", - messages="nls/RequestEchoResource", + title="Request echo service", + description="Echos the current HttpServletRequest object back to the browser.", + pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/RequestEchoResource.java'}", properties={ @Property(name=SERIALIZER_maxDepth, value="5"), - @Property(name=SERIALIZER_detectRecursions, value="true"), - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/RequestEchoResource.java'}") + @Property(name=SERIALIZER_detectRecursions, value="true") }, beanFilters={ // Interpret these as their parent classes, not subclasses @@ -48,11 +49,10 @@ public class RequestEchoResource extends Resource { private static final long serialVersionUID = 1L; /** GET request handler */ - @RestMethod(name="GET", path="/*", converters={Traversable.class,Queryable.class}) - public HttpServletRequest doGet(RestRequest req, @Properties ObjectMap properties) { + @RestMethod(name="GET", path="/*", converters={Traversable.class,Queryable.class}, summary="Serializes the incoming HttpServletRequest object.") + public HttpServletRequest doGet(RestRequest req, RestResponse res, @Properties ObjectMap properties) { // Set the HtmlDocSerializer title programmatically. - // This sets the value for this request only. - properties.put(HTMLDOC_title, "Contents of HttpServletRequest object"); + res.setPageTitle("Contents of HttpServletRequest object"); // Just echo the request back as the response. return req; http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/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 ce51c81..6ce7e38 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 @@ -12,8 +12,6 @@ // *************************************************************************************************************************** package org.apache.juneau.examples.rest; -import static org.apache.juneau.html.HtmlDocSerializerContext.*; - import org.apache.juneau.examples.rest.addressbook.*; import org.apache.juneau.microservice.*; import org.apache.juneau.microservice.resources.*; @@ -24,10 +22,9 @@ import org.apache.juneau.rest.annotation.*; */ @RestResource( path="/", - messages="nls/RootResources", - properties={ - @Property(name=HTMLDOC_links, value="{options:'$R{servletURI}?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/RootResources.java'}") - }, + title="Root resources", + description="This is an example of a router resource that is used to access other resources.", + pageLinks="{options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/RootResources.java'}", children={ HelloWorldResource.class, SystemPropertiesResource.class, http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SampleRemoteableServlet.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SampleRemoteableServlet.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SampleRemoteableServlet.java index 4173623..b581e18 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SampleRemoteableServlet.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SampleRemoteableServlet.java @@ -12,7 +12,6 @@ // *************************************************************************************************************************** package org.apache.juneau.examples.rest; -import static org.apache.juneau.html.HtmlDocSerializerContext.*; import static org.apache.juneau.rest.RestContext.*; import java.util.*; @@ -28,10 +27,10 @@ import org.apache.juneau.rest.remoteable.*; @RestResource( path="/remoteable", messages="nls/SampleRemoteableServlet", + title="Remoteable Service Proxy API", + description="Sample class showing how to use remoteable proxies. The list below are exposed services that can be retrieved using RestClient.getProxyInterface(Class).", + pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/SampleRemoteableServlet.java'}", properties={ - @Property(name=HTMLDOC_title, value="Remoteable Service Proxy API"), - @Property(name=HTMLDOC_description, value="Sample class showing how to use remoteable proxies. The list below are exposed services that can be retrieved using RestClient.getProxyInterface(Class)."), - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'$R{servletURI}?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/SampleRemoteableServlet.java'}"), // Allow us to use method=POST from a browser. @Property(name=REST_allowMethodParam, value="*") }, http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/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 e32d302..5be1140 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 @@ -14,7 +14,6 @@ package org.apache.juneau.examples.rest; import static javax.servlet.http.HttpServletResponse.*; import static org.apache.juneau.dto.html5.HtmlBuilder.*; -import static org.apache.juneau.html.HtmlDocSerializerContext.*; import java.sql.*; import java.util.*; @@ -34,11 +33,9 @@ import org.apache.juneau.rest.annotation.Body; @RestResource( path="/sqlQuery", messages="nls/SqlQueryResource", - properties={ - @Property(name=HTMLDOC_title, value="SQL query service"), - @Property(name=HTMLDOC_description, value="Executes queries against the local derby '$C{SqlQueryResource/connectionUrl}' database"), - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'$R{servletURI}?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/SqlQueryResource.java'}"), - } + title="SQL query service", + description="Executes queries against the local derby '$C{SqlQueryResource/connectionUrl}' database", + pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/SqlQueryResource.java'}" ) public class SqlQueryResource extends Resource { private static final long serialVersionUID = 1L; @@ -65,7 +62,7 @@ public class SqlQueryResource extends Resource { } /** GET request handler - Display the query entry page. */ - @RestMethod(name="GET", path="/") + @RestMethod(name="GET", path="/", summary="Display the query entry page") public Div doGet(RestRequest req) { return div( script("text/javascript", @@ -108,7 +105,7 @@ public class SqlQueryResource extends Resource { } /** POST request handler - Execute the query. */ - @RestMethod(name="POST", path="/") + @RestMethod(name="POST", path="/", summary="Execute one or more queries") public List<Object> doPost(@Body PostInput in) throws Exception { List<Object> results = new LinkedList<Object>(); http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/703cadd2/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 538ac73..8cb843e 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 @@ -30,9 +30,9 @@ import org.apache.juneau.rest.annotation.Body; path="/systemProperties", title="System properties resource", description="REST interface for performing CRUD operations on system properties.", + pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS',form:'formPage',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/SystemPropertiesResource.java'}", properties={ - @Property(name=SERIALIZER_quoteChar, value="'"), - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'$R{servletURI}?method=OPTIONS',form:'formPage',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/SystemPropertiesResource.java'}"), + @Property(name=SERIALIZER_quoteChar, value="'") }, stylesheet="styles/devops.css", encoders=GzipEncoder.class,
