IndexServlet: Stop using deprecated SoyMapData
Per the deprecation notices, users of these classes should use normal List and Map instead. The Soy rendering APIs can automatically handle conversion of native Java types. Change-Id: Iafc723a6a642d550be2ab91f144abc8c65e4ef79
This commit is contained in:
@@ -18,17 +18,18 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_OK;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.io.Resources;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.template.soy.SoyFileSet;
|
||||
import com.google.template.soy.data.SanitizedContent;
|
||||
import com.google.template.soy.data.SoyMapData;
|
||||
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer;
|
||||
import com.google.template.soy.tofu.SoyTofu;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -74,8 +75,8 @@ public class IndexServlet extends HttpServlet {
|
||||
return uri.getPath().replaceAll("/$", "");
|
||||
}
|
||||
|
||||
static SoyMapData getTemplateData(String canonicalURL, String cdnPath, String faviconPath)
|
||||
throws URISyntaxException {
|
||||
static Map<String, Object> getTemplateData(
|
||||
String canonicalURL, String cdnPath, String faviconPath) throws URISyntaxException {
|
||||
String canonicalPath = computeCanonicalPath(canonicalURL);
|
||||
|
||||
String staticPath = "";
|
||||
@@ -91,9 +92,16 @@ public class IndexServlet extends HttpServlet {
|
||||
UnsafeSanitizedContentOrdainer.ordainAsSafe(
|
||||
staticPath, SanitizedContent.ContentKind.TRUSTED_RESOURCE_URI);
|
||||
|
||||
return new SoyMapData(
|
||||
"canonicalPath", canonicalPath,
|
||||
"staticResourcePath", sanitizedStaticPath,
|
||||
"faviconPath", faviconPath);
|
||||
ImmutableMap.Builder<String, Object> data = ImmutableMap.builder();
|
||||
if (canonicalPath != null) {
|
||||
data.put("canonicalPath", canonicalPath);
|
||||
}
|
||||
if (sanitizedStaticPath != null) {
|
||||
data.put("staticResourcePath", sanitizedStaticPath);
|
||||
}
|
||||
if (faviconPath != null) {
|
||||
data.put("faviconPath", faviconPath);
|
||||
}
|
||||
return data.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.gerrit.testing.GerritBaseTests;
|
||||
import com.google.template.soy.data.SoyMapData;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Map;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IndexServletTest extends GerritBaseTests {
|
||||
@@ -38,35 +38,34 @@ public class IndexServletTest extends GerritBaseTests {
|
||||
|
||||
@Test
|
||||
public void noPathAndNoCDN() throws URISyntaxException {
|
||||
SoyMapData data = IndexServlet.getTemplateData("http://example.com/", null, null);
|
||||
assertThat(data.getSingle("canonicalPath").stringValue()).isEqualTo("");
|
||||
assertThat(data.getSingle("staticResourcePath").stringValue()).isEqualTo("");
|
||||
Map<String, Object> data = IndexServlet.getTemplateData("http://example.com/", null, null);
|
||||
assertThat(data.get("canonicalPath")).isEqualTo("");
|
||||
assertThat(data.get("staticResourcePath").toString()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pathAndNoCDN() throws URISyntaxException {
|
||||
SoyMapData data = IndexServlet.getTemplateData("http://example.com/gerrit/", null, null);
|
||||
assertThat(data.getSingle("canonicalPath").stringValue()).isEqualTo("/gerrit");
|
||||
assertThat(data.getSingle("staticResourcePath").stringValue()).isEqualTo("/gerrit");
|
||||
Map<String, Object> data =
|
||||
IndexServlet.getTemplateData("http://example.com/gerrit/", null, null);
|
||||
assertThat(data.get("canonicalPath")).isEqualTo("/gerrit");
|
||||
assertThat(data.get("staticResourcePath").toString()).isEqualTo("/gerrit");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noPathAndCDN() throws URISyntaxException {
|
||||
SoyMapData data =
|
||||
Map<String, Object> data =
|
||||
IndexServlet.getTemplateData("http://example.com/", "http://my-cdn.com/foo/bar/", null);
|
||||
assertThat(data.getSingle("canonicalPath").stringValue()).isEqualTo("");
|
||||
assertThat(data.getSingle("staticResourcePath").stringValue())
|
||||
.isEqualTo("http://my-cdn.com/foo/bar/");
|
||||
assertThat(data.get("canonicalPath")).isEqualTo("");
|
||||
assertThat(data.get("staticResourcePath").toString()).isEqualTo("http://my-cdn.com/foo/bar/");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pathAndCDN() throws URISyntaxException {
|
||||
SoyMapData data =
|
||||
Map<String, Object> data =
|
||||
IndexServlet.getTemplateData(
|
||||
"http://example.com/gerrit", "http://my-cdn.com/foo/bar/", null);
|
||||
assertThat(data.getSingle("canonicalPath").stringValue()).isEqualTo("/gerrit");
|
||||
assertThat(data.getSingle("staticResourcePath").stringValue())
|
||||
.isEqualTo("http://my-cdn.com/foo/bar/");
|
||||
assertThat(data.get("canonicalPath")).isEqualTo("/gerrit");
|
||||
assertThat(data.get("staticResourcePath").toString()).isEqualTo("http://my-cdn.com/foo/bar/");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user