Commits

Stephen McKamey committed 928269b

exposing interface for custom URL tranformation logic

  • Participants
  • Parent commits a31694d

Comments (0)

Files changed (4)

File duel/duel-compiler/src/main/java/org/duelengine/duel/codegen/CodeDOMBuilder.java

 		CodeExpression codeExpr = new CodeMethodInvokeExpression(
 			String.class,
 			new CodeThisReferenceExpression(),
-			"interceptLink",
+			"transformURL",
 			new CodeVariableReferenceExpression(DuelContext.class, "context"),
 			CodeDOMUtility.ensureString(new CodePrimitiveExpression(literal)));
 
 		codeExpr = new CodeMethodInvokeExpression(
 			String.class,
 			new CodeThisReferenceExpression(),
-			"interceptLink",
+			"transformURL",
 			new CodeVariableReferenceExpression(DuelContext.class, "context"),
 			CodeDOMUtility.ensureString(codeExpr));
 

File duel/duel-runtime/src/main/java/org/duelengine/duel/DuelContext.java

 
 	private Appendable output;
 	private ClientIDStrategy clientID;
+	private URLInterceptor interceptor;
 	private DataEncoder encoder;
 	private FormatPrefs format;
 
 		return this;
 	}
 
-	ClientIDStrategy getClientID() {
-		return this.clientID;
+	public DuelContext setURLInterceptor(URLInterceptor value) {
+		this.interceptor = value;
+
+		return this;
 	}
 
 	public DuelContext setClientID(ClientIDStrategy value) {
 		return this.clientID.nextID();
 	}
 
-	String interceptLink(String url) {
-		// TODO: build mechanism for exposing URL transformation
-		return url;
+	String transformURL(String url) {
+		if (this.interceptor == null) {
+			return url;
+		}
+
+		return this.interceptor.transformURL(url);
 	}
 }

File duel/duel-runtime/src/main/java/org/duelengine/duel/DuelView.java

 	 * @param url URL
 	 * @return transformed URL
 	 */
-	protected String interceptLink(DuelContext context, String url) {
-		return context.interceptLink(url);
+	protected String transformURL(DuelContext context, String url) {
+		return context.transformURL(url);
 	}
 
 	/**

File duel/duel-runtime/src/main/java/org/duelengine/duel/URLInterceptor.java

+package org.duelengine.duel;
+
+public interface URLInterceptor {
+
+	public String transformURL(String url);
+}