Commits

Stephen McKamey  committed 628a36f

adding constructor which takes ResourceBundle rather than Map<String, String>

  • Participants
  • Parent commits d4772ff

Comments (0)

Files changed (1)

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

 
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.util.Map;
+import java.util.*;
 import java.util.logging.Logger;
 
 public class CDNLinkInterceptor implements LinkInterceptor {
 	 * @param isDevMode uses normal paths unless compacted form has a dev form (e.g., "/foo.js" => "/foo.min.js" => "/foo.test.js", else "/foo.js")
 	 * @throws URISyntaxException
 	 */
+	public CDNLinkInterceptor(String cdnHost, ResourceBundle cdnBundle, boolean isDevMode) throws URISyntaxException {
+		this(cdnHost, bundleAsMap(cdnBundle), isDevMode);
+	}
+
+	/**
+	 * @param cdnHost the CDN server hostname (e.g., "cdn.example.com")
+	 * @param cdnMap a mapping of paths to their compacted form (e.g., "/foo.js" => "/foo.min.js")
+	 * @param isDevMode uses normal paths unless compacted form has a dev form (e.g., "/foo.js" => "/foo.min.js" => "/foo.test.js", else "/foo.js")
+	 * @throws URISyntaxException
+	 */
 	public CDNLinkInterceptor(String cdnHost, Map<String, String> cdnMap, boolean isDevMode) throws URISyntaxException {
 
 		this.isDevMode = isDevMode;
 		// CDN resources are compacted and optionally served from a differen host
 		return this.cdnHost + cdnURL;
 	}
+
+	/**
+	 * Converts ResourceBundle to a Map<String, String>
+	 * @param cdnBundle
+	 * @return
+	 */
+	private static Map<String, String> bundleAsMap(ResourceBundle cdnBundle) {
+		Set<String> keys = cdnBundle.keySet();
+		Map<String, String> cdnMap = new HashMap<String, String>(keys.size());
+		for (String key : keys) {
+			cdnMap.put(key, cdnBundle.getString(key));
+		}
+		return cdnMap;
+	}
 }