Repository: incubator-juneau Updated Branches: refs/heads/master ce0b41c52 -> 304421ccb
Fix javadocs Project: http://git-wip-us.apache.org/repos/asf/incubator-juneau/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-juneau/commit/304421cc Tree: http://git-wip-us.apache.org/repos/asf/incubator-juneau/tree/304421cc Diff: http://git-wip-us.apache.org/repos/asf/incubator-juneau/diff/304421cc Branch: refs/heads/master Commit: 304421ccbcd7ca42bf320626f1b704ad71d207cb Parents: ce0b41c Author: JamesBognar <[email protected]> Authored: Tue Jul 4 12:32:05 2017 -0400 Committer: JamesBognar <[email protected]> Committed: Tue Jul 4 12:32:05 2017 -0400 ---------------------------------------------------------------------- .../org/apache/juneau/parser/ParserGroup.java | 3 +++ .../java/org/apache/juneau/parser/package.html | 19 +++++++++++----- .../juneau/serializer/SerializerGroup.java | 12 +--------- .../org/apache/juneau/serializer/package.html | 23 ++++++++++++++------ 4 files changed, 34 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/304421cc/juneau-core/src/main/java/org/apache/juneau/parser/ParserGroup.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/parser/ParserGroup.java b/juneau-core/src/main/java/org/apache/juneau/parser/ParserGroup.java index 1a1a258..846ebcb 100644 --- a/juneau-core/src/main/java/org/apache/juneau/parser/ParserGroup.java +++ b/juneau-core/src/main/java/org/apache/juneau/parser/ParserGroup.java @@ -112,6 +112,9 @@ public final class ParserGroup { /** * Searches the group for a parser that can handle the specified <l>Content-Type</l> header value. * + * <p> + * The returned object includes both the parser and media type that matched. + * * @param contentTypeHeader The HTTP <l>Content-Type</l> header value. * @return The parser and media type that matched the content type header, or <jk>null</jk> if no match was made. */ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/304421cc/juneau-core/src/main/java/org/apache/juneau/parser/package.html ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/parser/package.html b/juneau-core/src/main/java/org/apache/juneau/parser/package.html index 142ac00..f3203e9 100644 --- a/juneau-core/src/main/java/org/apache/juneau/parser/package.html +++ b/juneau-core/src/main/java/org/apache/juneau/parser/package.html @@ -119,12 +119,21 @@ The following example shows a simple parser that converts input streams to images using standard JRE classes. </p> <p class='bcode'> + <jd>/** Parser for converting byte streams to images */</jd> <ja>@Consumes</ja>(<js>"image/png,image/jpeg"</js>) - <jk>public static class</jk> ImageParser <jk>extends</jk> InputStreamParser { - <ja>@Override</ja> - <jk>public</jk> <T> T parse(InputStream in, ClassMeta<T> type, ParserSession session) <jk>throws</jk> ParseException, IOException { - BufferedImage image = ImageIO.<jsm>read</jsm>(in); - <jk>return</jk> (T)image; + <jk>public class</jk> ImageParser <jk>extends</jk> InputStreamParser { + + <jd>/** + * Constructor. + * <ja>@param</ja> propertyStore The property store containing all the settings for this object. + */</jd> + <jk>public</jk> ImageParser(PropertyStore propertyStore) { + <jk>super</jk>(propertyStore); + } + + <ja>@Override</ja> <jc>/* Parser */</jc> + <jk>protected</jk> <T> T doParse(ParserSession session, ClassMeta<T> type) <jk>throws</jk> Exception { + <jk>return</jk> (T)ImageIO.<jsm>read</jsm>(session.getInputStream()); } } </p> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/304421cc/juneau-core/src/main/java/org/apache/juneau/serializer/SerializerGroup.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/serializer/SerializerGroup.java b/juneau-core/src/main/java/org/apache/juneau/serializer/SerializerGroup.java index 80fc063..f8e192b 100644 --- a/juneau-core/src/main/java/org/apache/juneau/serializer/SerializerGroup.java +++ b/juneau-core/src/main/java/org/apache/juneau/serializer/SerializerGroup.java @@ -124,17 +124,7 @@ public final class SerializerGroup { * </p> * * <p> - * The general idea behind having the serializer resolution be a two-step process is so that the matched media type - * can be passed in to the {@link WriterSerializer#doSerialize(SerializerSession, Object)} method. - * <br>For example... - * <p class='bcode'> - * String acceptHeaderValue = request.getHeader(<js>"Accept"</js>); - * String matchingMediaType = group.findMatch(acceptHeaderValue); - * if (matchingMediaType == <jk>null</jk>) - * <jk>throw new</jk> RestException(<jsf>SC_NOT_ACCEPTABLE</jsf>); - * WriterSerializer s = (WriterSerializer)group.getSerializer(matchingMediaType); - * s.serialize(getPojo(), response.getWriter(), response.getProperties(), matchingMediaType); - * </p> + * The returned object includes both the serializer and media type that matched. * * @param acceptHeader The HTTP <l>Accept</l> header string. * @return The serializer and media type that matched the accept header, or <jk>null</jk> if no match was made. http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/304421cc/juneau-core/src/main/java/org/apache/juneau/serializer/package.html ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/serializer/package.html b/juneau-core/src/main/java/org/apache/juneau/serializer/package.html index ac50911..0057ce8 100644 --- a/juneau-core/src/main/java/org/apache/juneau/serializer/package.html +++ b/juneau-core/src/main/java/org/apache/juneau/serializer/package.html @@ -122,15 +122,24 @@ classes. </p> <p class='bcode'> + <jd>/** Serializer for converting images to byte streams */</jd> <ja>@Produces</ja>(<js>"image/png,image/jpeg"</js>) - <jk>public static class</jk> ImageSerializer <jk>extends</jk> OutputStreamSerializer { - <ja>@Override</ja> - <jk>public void</jk> serialize(Object o, OutputStream out, SerializerSession session) - <jk>throws</jk> IOException, SerializeException { + <jk>public class</jk> ImageSerializer <jk>extends</jk> OutputStreamSerializer { + + <jd>/** + * Constructor. + * <ja>@param</ja> propertyStore The property store containing all the settings for this object. + */</jd> + <jk>public</jk> ImageSerializer(PropertyStore propertyStore) { + <jk>super</jk>(propertyStore); + } + + <ja>@Override</ja> <jc>/* Serializer */</jc> + <jk>protected void</jk> doSerialize(SerializerSession session, Object o) <jk>throws</jk> Exception { RenderedImage image = (RenderedImage)o; - String mediaType = ctx.getMediaType(); - ImageIO.<jsm>write</jsm>(image, mediaType.substring(mediaType.indexOf(<js>'/'</js>)+1), out); - } + String mediaType = session.getProperty(<js>"mediaType"</js>); + ImageIO.<jsm>write</jsm>(image, mediaType.substring(mediaType.indexOf(<js>'/'</js>)+1), session.getOutputStream()); + } } </p> <p>
