You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2017/05/26 13:37:29 UTC

incubator-juneau git commit: UriContext support.

Repository: incubator-juneau
Updated Branches:
  refs/heads/master f2fafd3ef -> 3e04f73b9


UriContext 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/3e04f73b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-juneau/tree/3e04f73b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-juneau/diff/3e04f73b

Branch: refs/heads/master
Commit: 3e04f73b96817710e08c4b62422ec0a251024afd
Parents: f2fafd3
Author: JamesBognar <ja...@apache.org>
Authored: Fri May 26 09:37:26 2017 -0400
Committer: JamesBognar <ja...@apache.org>
Committed: Fri May 26 09:37:26 2017 -0400

----------------------------------------------------------------------
 .../main/java/org/apache/juneau/UriContext.java | 11 +++++++
 .../juneau/serializer/SerializerContext.java    | 31 ++++++++++++++------
 .../juneau/serializer/SerializerSession.java    |  8 +----
 3 files changed, 34 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/3e04f73b/juneau-core/src/main/java/org/apache/juneau/UriContext.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/UriContext.java b/juneau-core/src/main/java/org/apache/juneau/UriContext.java
index 35e7678..2756111 100644
--- a/juneau-core/src/main/java/org/apache/juneau/UriContext.java
+++ b/juneau-core/src/main/java/org/apache/juneau/UriContext.java
@@ -18,6 +18,8 @@ import static org.apache.juneau.UriRelativity.*;
 
 import java.io.*;
 
+import org.apache.juneau.annotation.*;
+
 /**
  * Represents a URL broken into authority/context-root/servlet-path/path-info parts.
  * <p>
@@ -49,8 +51,16 @@ import java.io.*;
  *
  * The following class shows how
  */
+@Bean
 public class UriContext {
 
+	/**
+	 * Default URI context.
+	 * No URI resolution occurs.
+	 * No information about authority, servlet-root, context-root, or path-info is known.
+	 */
+	public static final UriContext DEFAULT = new UriContext(UriResolution.NONE, UriRelativity.PATH_INFO, null, null, null, null);
+
 	private final String authority, contextRoot, servletPath, pathInfo, parentPath;
 
 	private final UriResolution resolution;
@@ -74,6 +84,7 @@ public class UriContext {
 	 * @param servletPath - The servlet path (e.g. <js>"/servlet-path"</js>, or <js>"servlet-path"</js>)
 	 * @param pathInfo - The path info (e.g. <js>"/path-info"</js>, or <js>"path-info"</js>)
 	 */
+	@BeanConstructor(properties="resolution,relativity,authority,contextRoot,servletPath,pathInfo")
 	public UriContext(UriResolution resolution, UriRelativity relativity, String authority, String contextRoot, String servletPath, String pathInfo) {
 		this.resolution = resolution;
 		this.relativity = relativity;

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/3e04f73b/juneau-core/src/main/java/org/apache/juneau/serializer/SerializerContext.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/serializer/SerializerContext.java b/juneau-core/src/main/java/org/apache/juneau/serializer/SerializerContext.java
index 31dc2e8..fd890f9 100644
--- a/juneau-core/src/main/java/org/apache/juneau/serializer/SerializerContext.java
+++ b/juneau-core/src/main/java/org/apache/juneau/serializer/SerializerContext.java
@@ -286,9 +286,25 @@ public class SerializerContext extends BeanContext {
 	 */
 	public static final String SERIALIZER_absolutePathUriBase = "Serializer.absolutePathUriBase";
 
-	public static final String SERIALIZER_uriResolution = "Serializer.uriResolution";
-
-	public static final String SERIALIZER_uriRelativity = "Serializer.uriRelativity";
+	/**
+	 * <b>Configuration property:</b>  URI context bean.
+	 * <p>
+	 * <ul>
+	 * 	<li><b>Name:</b> <js>"Serializer.uriContext"</js>
+	 * 	<li><b>Data type:</b> {@link UriContext}
+	 * 	<li><b>Default:</b> {@link UriContext#DEFAULT}
+	 * 	<li><b>Session-overridable:</b> <jk>true</jk>
+	 * </ul>
+	 * <p>
+	 * Bean used for resolution of URIs to absolute or root-relative form.
+	 * <p>
+	 * For example, to define a URI context that causes relative URIs to be converted to root-relative form and
+	 * assumes relative URIs are relative to the servlet path:
+	 * <p class='bcode'>
+	 * 	<js>"{resolution:'ROOT_RELATIVE',relativity:'RESOURCE',contextRoot:'/myContext',servletPath:'/myServlet'}"</js>
+	 * </p>
+	 */
+	public static final String SERIALIZER_uriContext = "Serializer.uriContext";
 
 	/**
 	 * <b>Configuration property:</b>  Sort arrays and collections alphabetically.
@@ -353,8 +369,7 @@ public class SerializerContext extends BeanContext {
 		abridged;
 	final char quoteChar;
 	final String relativeUriBase, absolutePathUriBase;
-	final UriResolution uriResolution;
-	final UriRelativity uriRelativity;
+	final UriContext uriContext;
 
 	/**
 	 * Constructor.
@@ -379,8 +394,7 @@ public class SerializerContext extends BeanContext {
 		quoteChar = ps.getProperty(SERIALIZER_quoteChar, String.class, "\"").charAt(0);
 		relativeUriBase = resolveRelativeUriBase(ps.getProperty(SERIALIZER_relativeUriBase, String.class, ""));
 		absolutePathUriBase = resolveAbsolutePathUriBase(ps.getProperty(SERIALIZER_absolutePathUriBase, String.class, ""));
-		uriResolution = ps.getProperty(SERIALIZER_uriResolution, UriResolution.class, UriResolution.ROOT_RELATIVE);
-		uriRelativity = ps.getProperty(SERIALIZER_uriRelativity, UriRelativity.class, UriRelativity.RESOURCE);
+		uriContext = ps.getProperty(SERIALIZER_uriContext, UriContext.class, UriContext.DEFAULT);
 	}
 
 	private static String resolveRelativeUriBase(String s) {
@@ -421,8 +435,7 @@ public class SerializerContext extends BeanContext {
 				.append("quoteChar", quoteChar)
 				.append("relativeUriBase", relativeUriBase)
 				.append("absolutePathUriBase", absolutePathUriBase)
-				.append("uriResolution", uriResolution)
-				.append("uriRelativity", uriRelativity)
+				.append("uriContext", uriContext)
 			);
 	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/3e04f73b/juneau-core/src/main/java/org/apache/juneau/serializer/SerializerSession.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/serializer/SerializerSession.java b/juneau-core/src/main/java/org/apache/juneau/serializer/SerializerSession.java
index dd563c9..d89203b 100644
--- a/juneau-core/src/main/java/org/apache/juneau/serializer/SerializerSession.java
+++ b/juneau-core/src/main/java/org/apache/juneau/serializer/SerializerSession.java
@@ -102,8 +102,7 @@ public class SerializerSession extends BeanSession {
 		super(ctx, op, locale, timeZone, mediaType);
 		this.javaMethod = javaMethod;
 		this.output = output;
-		UriResolution uriResolution = null;
-		UriRelativity uriRelativity = null;
+		this.uriContext = (uriContext != null ? uriContext : ctx.uriContext);
 		if (op == null || op.isEmpty()) {
 			maxDepth = ctx.maxDepth;
 			initialDepth = ctx.initialDepth;
@@ -121,8 +120,6 @@ public class SerializerSession extends BeanSession {
 			sortCollections = ctx.sortCollections;
 			sortMaps = ctx.sortMaps;
 			abridged = ctx.abridged;
-			uriResolution =  ctx.uriResolution;
-			uriRelativity = ctx.uriRelativity;
 		} else {
 			maxDepth = op.getInt(SERIALIZER_maxDepth, ctx.maxDepth);
 			initialDepth = op.getInt(SERIALIZER_initialDepth, ctx.initialDepth);
@@ -140,10 +137,7 @@ public class SerializerSession extends BeanSession {
 			sortCollections = op.getBoolean(SERIALIZER_sortCollections, ctx.sortMaps);
 			sortMaps = op.getBoolean(SERIALIZER_sortMaps, ctx.sortMaps);
 			abridged = op.getBoolean(SERIALIZER_abridged, ctx.abridged);
-			uriResolution = op.get(UriResolution.class, SERIALIZER_uriResolution, ctx.uriResolution);
-			uriRelativity = op.get(UriRelativity.class, SERIALIZER_uriRelativity, ctx.uriRelativity);
 		}
-		this.uriContext = uriContext != null ? uriContext : new UriContext(uriResolution, uriRelativity, null, null, null, null);
 
 		this.indent = initialDepth;
 		if (detectRecursions || isDebug()) {