Skip to content

Commit

Permalink
renaming URIMatch#baseName to #path
Browse files Browse the repository at this point in the history
for clarity.  baseName was a relic of an old, old version
  • Loading branch information
heinousjay committed Aug 16, 2014
1 parent 7603ebf commit 9f40f28
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private String massageURL(final String url) {
if (url.startsWith(URI_PREPEND)) {
String path = url.substring(URI_PREPEND.length());
URIMatch uriMatch = new URIMatch(path);
if (!uriMatch.versioned && uriMatch.baseName != null) {
if (!uriMatch.versioned && uriMatch.path != null) {
ServableResource resource = servables.loadResource(uriMatch);
if (resource != null && uriMatch.sha1 == null) {
return resource.serverPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public boolean isMatchingRequest(final URIMatch uriMatch) {

@Override
public StylesheetResource loadResource(final URIMatch match) {
return resourceFinder.loadResource(StylesheetResource.class, AppLocation.Base, match.baseName);
return resourceFinder.loadResource(StylesheetResource.class, AppLocation.Base, match.path);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void process() throws IOException {
@Override
public ScriptResource loadResource(final URIMatch match) {
ScriptResource result = null;
Matcher typeMatcher = TYPE_PATTERN.matcher(match.baseName);
Matcher typeMatcher = TYPE_PATTERN.matcher(match.path);
if (match.sha1 != null && typeMatcher.matches()) {

DocumentScriptEnvironment scriptEnvironment =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public RequestProcessor makeRequestProcessor(

} else {

preloadResources(request.uriMatch().baseName);
preloadResources(request.uriMatch().path);

result = parentInjector.createChildInjector(new AbstractModule() {

Expand All @@ -95,6 +95,6 @@ protected void configure() {

@Override
public DocumentScriptEnvironment loadResource(URIMatch match) {
return resourceFinder.loadResource(DocumentScriptEnvironment.class, AppLocation.Virtual, match.baseName);
return resourceFinder.loadResource(DocumentScriptEnvironment.class, AppLocation.Virtual, match.path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public RequestProcessor makeRequestProcessor(

@Override
public StaticResource loadResource(URIMatch match) {
return resourceFinder.loadResource(StaticResource.class, Base.and(Assets), match.baseName);
return resourceFinder.loadResource(StaticResource.class, Base.and(Assets), match.path);
}

}
12 changes: 8 additions & 4 deletions kernel/src/main/java/jj/http/uri/URIMatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ public class URIMatch {
/** the extension */
public final String extension;

/** name + '.' + extension */
public final String baseName;
/**
* the path from the public root, analogous to a resource name,
* although route matching rules may virtualize this.
* composed of name + '.' + extension. the initial / is not included
*/
public final String path;

/**
* true if considered to be versioned as detailed in the class comment
Expand All @@ -83,7 +87,7 @@ public URIMatch(final String uri) {
sha1 = shaCandidate;
name = nameCandidate;
extension = extensionCandidate;
baseName = name == null ? null : name + (extensionCandidate == null ? "" : "." + extensionCandidate);
path = name == null ? null : name + (extensionCandidate == null ? "" : "." + extensionCandidate);
versioned = sha1 != null || (nameCandidate != null && VERSION_PATTERN.matcher(nameCandidate).find());
}

Expand All @@ -99,7 +103,7 @@ public String toString() {
", sha1: " + sha1 +
", name: " + name +
", extension: " + extension +
", baseName: " + baseName +
", baseName: " + path +
", versioned: " + versioned + " }";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public class ResourceUrlDocumentFilterTest {
@Before
public void before() {
document = Jsoup.parse(
"<a href='" + m.cssUri.baseName + "'>" +
"<img src='" + m.staticUri.baseName + "'/>" +
"</a><link href='" + m.assetUri.baseName + "'/>");
"<a href='" + m.cssUri.path + "'>" +
"<img src='" + m.staticUri.path + "'/>" +
"</a><link href='" + m.assetUri.path + "'/>");
given(documentRequestProcessor.document()).willReturn(document);

filter = new ResourceUrlDocumentFilter(m.servables);
Expand Down
12 changes: 6 additions & 6 deletions kernel/src/test/java/jj/http/uri/URIMatchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void testVersioned() {
public void test() {
URIMatch match = new URIMatch("/be03b9352e1e254cae9a58cff2b20e0c8d513e47/jj.js");
assertThat(match.sha1, is("be03b9352e1e254cae9a58cff2b20e0c8d513e47"));
assertThat(match.baseName, is("jj.js"));
assertThat(match.path, is("jj.js"));
assertThat(match.name, is("jj"));
assertThat(match.extension, is("js"));
assertThat(match.versioned, is(true));
Expand All @@ -68,7 +68,7 @@ public void test() {
public void test2() {
URIMatch match = new URIMatch("/jj.js");
assertThat(match.sha1, is(nullValue()));
assertThat(match.baseName, is("jj.js"));
assertThat(match.path, is("jj.js"));
assertThat(match.name, is("jj"));
assertThat(match.extension, is("js"));
assertThat(match.versioned, is(false));
Expand All @@ -78,7 +78,7 @@ public void test2() {
public void test3() {
URIMatch match = new URIMatch("/be03b9352e1e254cae9a58cff2b20e0c8d547/jj.js");
assertThat(match.sha1, is(nullValue()));
assertThat(match.baseName, is("be03b9352e1e254cae9a58cff2b20e0c8d547/jj.js"));
assertThat(match.path, is("be03b9352e1e254cae9a58cff2b20e0c8d547/jj.js"));
assertThat(match.name, is("be03b9352e1e254cae9a58cff2b20e0c8d547/jj"));
assertThat(match.extension, is("js"));
assertThat(match.versioned, is(false));
Expand All @@ -88,7 +88,7 @@ public void test3() {
public void test4() {
URIMatch match = new URIMatch("/be03b9352e1e254cae9a58cff2b20e0c8d513e47/be03b9352e1e254cae9a58cff2b20e0c8d513e47/jj.js");
assertThat(match.sha1, is("be03b9352e1e254cae9a58cff2b20e0c8d513e47"));
assertThat(match.baseName, is("be03b9352e1e254cae9a58cff2b20e0c8d513e47/jj.js"));
assertThat(match.path, is("be03b9352e1e254cae9a58cff2b20e0c8d513e47/jj.js"));
assertThat(match.name, is("be03b9352e1e254cae9a58cff2b20e0c8d513e47/jj"));
assertThat(match.extension, is("js"));
assertThat(match.versioned, is(true));
Expand All @@ -98,7 +98,7 @@ public void test4() {
public void test5() {
URIMatch match = new URIMatch("/be03b9352e1e254cae9a58cff2b20e0c8d513e47/be03b9352e1e254cae9a58cff2b20e0c8d513e47/jj");
assertThat(match.sha1, is("be03b9352e1e254cae9a58cff2b20e0c8d513e47"));
assertThat(match.baseName, is("be03b9352e1e254cae9a58cff2b20e0c8d513e47/jj"));
assertThat(match.path, is("be03b9352e1e254cae9a58cff2b20e0c8d513e47/jj"));
assertThat(match.name, is("be03b9352e1e254cae9a58cff2b20e0c8d513e47/jj"));
assertThat(match.extension, is(nullValue()));
assertThat(match.versioned, is(true));
Expand All @@ -108,7 +108,7 @@ public void test5() {
public void test6() {
URIMatch match = new URIMatch("/jquery.fancybox.css");
assertThat(match.sha1, is(nullValue()));
assertThat(match.baseName, is("jquery.fancybox.css"));
assertThat(match.path, is("jquery.fancybox.css"));
assertThat(match.name, is("jquery.fancybox"));
assertThat(match.extension, is("css"));
assertThat(match.versioned, is(false));
Expand Down

0 comments on commit 9f40f28

Please sign in to comment.