public ComponentViewResolver() { super(); // Create templates for the REST URIs that are supported by this view resolver. Previously this was done using the // spring-surf-config.xml file but made little sense because to change the URI templates required changing the Spring Surf // configuration, the Spring Bean configuration and providing a new view resolver. It is simpler to define new templates // just through a new view resolver that is provided to support those templates. ArrayList<UriTemplate> uriTemplates = new ArrayList<UriTemplate>(); uriTemplates.add(new UriTemplate("/regionId/{regionId}")); uriTemplates.add(new UriTemplate("/scope/{scopeId}/regionId/{regionId}/sourceId/{sourceId}")); uriTemplates.add(new UriTemplate("/mode/{mode}/focus/{focus}/scope/{scopeId}/regionId/{regionId}/sourceId/{sourceId}")); uriTemplates.add(new UriTemplate("/focus/{focus}/scope/{scopeId}/regionId/{regionId}/sourceId/{sourceId}")); uriTemplates.add(new UriTemplate("/mode/{mode}/scope/{scopeId}/regionId/{regionId}/sourceId/{sourceId}")); setUriTemplateIndex(new UriTemplateListIndex(uriTemplates)); // Populate the prefixes List with the 2 prefixes that we need to initially support. This code block // can be removed if we decide to allow prefixes to be specified via Spring property injection. addPrefix(URI_PREFIX_COMPONENT_SHORT); addPrefix(URI_PREFIX_COMPONENT_FULL); // NOTE: There are no request parameters to add as these are not currently used to identify component views. }
/** * Search the URI index to locale a match for the specified URI. * If found, return the args that represent the matched URI pattern tokens * and the values as per the supplied URI value. * * @param uri URI to match against the URI Templates in the index * * @return Map of token args to values or null if no match was found. */ public Map<String, String> findMatch(String uri) { Map<String, String> match = null; for (UriTemplate template : this.uriTemplates) { match = template.match(uri); if (match != null) { break; } } return match; } }
/** * Construct * * @param method http method * @param template uri template * @param includeExtension include uri extension in index * @param script associated web script */ IndexEntry(String method, UriTemplate template, boolean includeExtension, WebScript script) { this.method = method.toUpperCase(); this.template = template; this.includeExtension = includeExtension; this.script = script; this.key = template.getRegex() + ":" + this.method; int firstTokenIdx = template.getTemplate().indexOf('{'); this.staticTemplate = (firstTokenIdx == -1) ? template.getTemplate() : template.getTemplate().substring(0, firstTokenIdx); }
public void testParseTemplate() { UriTemplate i1 = new UriTemplate("/"); assertEquals("/", i1.getTemplate()); assertEquals("/", i1.getRegex().pattern()); assertEquals(1, i1.getStaticCharCount()); assertEquals(0, i1.getVariableNames().length); UriTemplate i2 = new UriTemplate("/a/{a1}/b{b1}b/{c_c}"); assertEquals("/a/{a1}/b{b1}b/{c_c}", i2.getTemplate()); assertEquals("/a/(.*?)/b(.*?)b/(.*?)", i2.getRegex().pattern()); assertEquals(7, i2.getStaticCharCount()); assertEquals(3, i2.getVariableNames().length); assertEquals("a1", i2.getVariableNames()[0]); assertEquals("b1", i2.getVariableNames()[1]); assertEquals("c_c", i2.getVariableNames()[2]); }
int i = o2.getTemplate().getStaticCharCount() - o1.getTemplate().getStaticCharCount(); if (i != 0) i = o2.getTemplate().getVariableNames().length - o1.getTemplate().getVariableNames().length; if (i != 0) i = o2.getTemplate().getRegex().pattern().compareTo(o1.getTemplate().getRegex().pattern()); if (i != 0)
public void testTemplateDotMatch() { UriTemplate i1 = new UriTemplate("/a/b/{b}/c"); Map<String, String> values1 = i1.match("/a/b/x/y/z.ext/c"); assertEquals(1, values1.size()); assertEquals("x/y/z.ext", values1.get("b")); }
Map<String, String> vars = entry.getTemplate().match(test); if (vars != null) if (entry.getMethod().equals(method)) scriptMatch = new Match(entry.getTemplate().getTemplate(), vars, entry.getStaticTemplate(), entry.getScript()); break; scriptMatch = new Match(pathMatch.getTemplate().getTemplate(), varsMatch, pathMatch.getStaticTemplate());
charCnt += appendTemplate(template, start, end, templateRegex); templateRegex.append(VARIABLE_REGEX); String name = matcher.group(1); start = matcher.end(); charCnt += appendTemplate(template, start, template.length(), templateRegex);
int i = o2.getTemplate().getStaticCharCount() - o1.getTemplate().getStaticCharCount(); if (i != 0) i = o2.getTemplate().getVariableNames().length - o1.getTemplate().getVariableNames().length; if (i != 0) i = o2.getTemplate().getRegex().pattern().compareTo(o1.getTemplate().getRegex().pattern()); if (i != 0)
UriTemplate i1 = new UriTemplate("/a/{a1}/b/b{b1}b"); assertNull(i1.match("/")); assertNull(i1.match("/a")); assertNull(i1.match("/a/1/b")); assertNull(i1.match("/a/1/b/2")); assertNull(i1.match("/a/1/b/b2")); assertNull(i1.match("/a/1/b/b2b/")); Map<String, String> values1 = i1.match("/a/1/b/b2b"); assertNotNull(values1); assertEquals(2, values1.size()); UriTemplate i2 = new UriTemplate("/a/{a1}/b/{b1}"); Map<String, String> values2 = i2.match("/a/1/b/2/3"); assertNotNull(values2); assertEquals(2, values2.size()); UriTemplate i3 = new UriTemplate("/a/{a1}/b/{a1}"); Map<String, String> values3 = i3.match("/a/1/b/2"); assertNull(values3); UriTemplate i4 = new UriTemplate("/a/b{b}/{c}"); Map<String, String> values4 = i4.match("/a/b/c"); assertEquals(2, values4.size()); assertEquals("", values4.get("b")); assertEquals("c", values4.get("c")); UriTemplate i5 = new UriTemplate("/a/b{b}/{c}"); Map<String, String> values5 = i5.match("/a/bb/c");
Map<String, String> vars = entry.getTemplate().match(test); if (vars != null) if (entry.getMethod().equals(method)) scriptMatch = new Match(entry.getTemplate().getTemplate(), vars, entry.getStaticTemplate(), entry.getScript()); break; scriptMatch = new Match(pathMatch.getTemplate().getTemplate(), varsMatch, pathMatch.getStaticTemplate());
charCnt += appendTemplate(template, start, end, templateRegex); templateRegex.append(VARIABLE_REGEX); String name = matcher.group(1); start = matcher.end(); charCnt += appendTemplate(template, start, template.length(), templateRegex);
public ComponentViewResolver() { super(); // Create templates for the REST URIs that are supported by this view resolver. Previously this was done using the // spring-surf-config.xml file but made little sense because to change the URI templates required changing the Spring Surf // configuration, the Spring Bean configuration and providing a new view resolver. It is simpler to define new templates // just through a new view resolver that is provided to support those templates. ArrayList<UriTemplate> uriTemplates = new ArrayList<UriTemplate>(); uriTemplates.add(new UriTemplate("/regionId/{regionId}")); uriTemplates.add(new UriTemplate("/scope/{scopeId}/regionId/{regionId}/sourceId/{sourceId}")); uriTemplates.add(new UriTemplate("/mode/{mode}/focus/{focus}/scope/{scopeId}/regionId/{regionId}/sourceId/{sourceId}")); uriTemplates.add(new UriTemplate("/focus/{focus}/scope/{scopeId}/regionId/{regionId}/sourceId/{sourceId}")); uriTemplates.add(new UriTemplate("/mode/{mode}/scope/{scopeId}/regionId/{regionId}/sourceId/{sourceId}")); setUriTemplateIndex(new UriTemplateListIndex(uriTemplates)); // Populate the prefixes List with the 2 prefixes that we need to initially support. This code block // can be removed if we decide to allow prefixes to be specified via Spring property injection. addPrefix(URI_PREFIX_COMPONENT_SHORT); addPrefix(URI_PREFIX_COMPONENT_FULL); // NOTE: There are no request parameters to add as these are not currently used to identify component views. }
int i = o2.getTemplate().getStaticCharCount() - o1.getTemplate().getStaticCharCount(); if (i != 0) i = o2.getTemplate().getVariableNames().length - o1.getTemplate().getVariableNames().length; if (i != 0) i = o2.getTemplate().getRegex().pattern().compareTo(o1.getTemplate().getRegex().pattern()); if (i != 0)
Map<String, String> vars = entry.getTemplate().match(test); if (vars != null) if (entry.getMethod().equals(method)) scriptMatch = new Match(entry.getTemplate().getTemplate(), vars, entry.getStaticTemplate(), entry.getScript()); break; scriptMatch = new Match(pathMatch.getTemplate().getTemplate(), varsMatch, pathMatch.getStaticTemplate());
/** * Search the URI index to locale a match for the specified URI. * If found, return the args that represent the matched URI pattern tokens * and the values as per the supplied URI value. * * @param uri URI to match against the URI Templates in the index * * @return Map of token args to values or null if no match was found. */ public Map<String, String> findMatch(String uri) { Map<String, String> match = null; for (UriTemplate template : this.uriTemplates) { match = template.match(uri); if (match != null) { break; } } return match; } }
/** * Construct * * @param method http method * @param template uri template * @param includeExtension include uri extension in index * @param script associated web script */ IndexEntry(String method, UriTemplate template, boolean includeExtension, WebScript script) { this.method = method.toUpperCase(); this.template = template; this.includeExtension = includeExtension; this.script = script; this.key = template.getRegex() + ":" + this.method; int firstTokenIdx = template.getTemplate().indexOf('{'); this.staticTemplate = (firstTokenIdx == -1) ? template.getTemplate() : template.getTemplate().substring(0, firstTokenIdx); }
charCnt += appendTemplate(template, start, end, templateRegex); templateRegex.append(VARIABLE_REGEX); String name = matcher.group(1); start = matcher.end(); charCnt += appendTemplate(template, start, template.length(), templateRegex);
public RegionViewResolver() { super(); // Create templates for the REST URIs that are supported by this view resolver. Previously this was done using the // spring-surf-config.xml file but made little sense because to change the URI templates required changing the Spring Surf // configuration, the Spring Bean configuration and providing a new view resolver. It is simpler to define new templates // just through a new view resolver that is provided to support those templates. ArrayList<UriTemplate> uriTemplates = new ArrayList<UriTemplate>(); uriTemplates.add(new UriTemplate("/regionId/{regionId}")); uriTemplates.add(new UriTemplate("/scope/{scopeId}/regionId/{regionId}/sourceId/{sourceId}")); setUriTemplateIndex(new UriTemplateListIndex(uriTemplates)); // Populate the prefixes List with the 2 prefixes that we need to initially support. This code block // can be removed if we decide to allow prefixes to be specified via Spring property injection. addPrefix(URI_PREFIX_REGION_SHORT); addPrefix(URI_PREFIX_REGION_FULL); // NOTE: There are no request parameters to add as these are not currently used to identify region views. }
/** * Search the URI index to locale a match for the specified URI. * If found, return the args that represent the matched URI pattern tokens * and the values as per the supplied URI value. * * @param uri URI to match against the URI Templates in the index * * @return Map of token args to values or null if no match was found. */ public Map<String, String> findMatch(String uri) { for (UriTemplate template : this.mappings.keySet()) { Map<String, String> match = template.match(uri); if (match != null) { return match; } } // if we get here, no match was found return null; } }