/** * Configuration property: Resource path. * * <p> * Identifies the URL subpath relative to the parent resource. * * <h5 class='section'>See Also:</h5> * <ul> * <li class='jf'>{@link RestContext#REST_path} * </ul> * * @param value The new value for this setting. * @return This object (for method chaining). */ public RestContextBuilder path(String value) { if (startsWith(value, '/')) value = value.substring(1); this.path = value; return this; }
/** * Configuration property: Resource path. * * <p> * Identifies the URL subpath relative to the parent resource. * * <h5 class='section'>See Also:</h5> * <ul> * <li class='jf'>{@link RestContext#REST_path} * </ul> * * @param value The new value for this setting. * @return This object (for method chaining). */ public RestContextBuilder path(String value) { if (startsWith(value, '/')) value = value.substring(1); this.path = value; return this; }
/** * Configuration property: Resource path. * * <p> * Identifies the URL subpath relative to the parent resource. * * <h5 class='section'>See Also:</h5> * <ul> * <li class='jf'>{@link RestContext#REST_path} * </ul> * * @param value The new value for this setting. * @return This object (for method chaining). */ public RestContextBuilder path(String value) { if (startsWith(value, '/')) value = value.substring(1); this.path = value; return this; }
private static List<String> breakUpTokens(String s) { // Get rid of whitespace in "123 - 456" s = s.replaceAll("(-?\\d+)\\s*-\\s*(-?\\d+)", "$1-$2"); // Get rid of whitespace in ">= 123" s = s.replaceAll("([<>]=?)\\s+(-?\\d+)", "$1$2"); // Get rid of whitespace in "! 123" s = s.replaceAll("(!)\\s+(-?\\d+)", "$1$2"); // Replace all commas with whitespace // Allows for alternate notation of: 123,456... s = s.replaceAll(",", " "); String[] s2 = s.split("\\s+"); // Make all tokens 'ORed'. There is no way to AND numeric tokens. for (int i = 0; i < s2.length; i++) if (! startsWith(s2[i], '!')) s2[i] = "^"+s2[i]; List<String> l = new LinkedList<>(); l.addAll(Arrays.asList(s2)); return l; }
private static List<String> breakUpTokens(String s) { // Get rid of whitespace in "123 - 456" s = s.replaceAll("(-?\\d+)\\s*-\\s*(-?\\d+)", "$1-$2"); // Get rid of whitespace in ">= 123" s = s.replaceAll("([<>]=?)\\s+(-?\\d+)", "$1$2"); // Get rid of whitespace in "! 123" s = s.replaceAll("(!)\\s+(-?\\d+)", "$1$2"); // Replace all commas with whitespace // Allows for alternate notation of: 123,456... s = s.replaceAll(",", " "); String[] s2 = s.split("\\s+"); // Make all tokens 'ORed'. There is no way to AND numeric tokens. for (int i = 0; i < s2.length; i++) if (! startsWith(s2[i], '!')) s2[i] = "^"+s2[i]; List<String> l = new LinkedList<>(); l.addAll(Arrays.asList(s2)); return l; }
Builder(String patternString) { if (! startsWith(patternString, '/')) patternString = '/' + patternString; if (patternString.equals("/*")) { isOnlyDotAll = true; return; } if (patternString.endsWith("/*")) isDotAll = true; // Find all {xxx} variables. Pattern p = Pattern.compile("\\{([^\\}]+)\\}"); Matcher m = p.matcher(patternString); while (m.find()) vars.add(m.group(1)); patternString = patternString.replaceAll("\\{[^\\}]+\\}", "([^\\/]+)"); patternString = patternString.replaceAll("\\/\\*$", "((?:)|(?:\\/.*))"); pattern = Pattern.compile(patternString); } }
private static List<String> breakUpTokens(String s) { // Get rid of whitespace in "123 - 456" s = s.replaceAll("(-?\\d+)\\s*-\\s*(-?\\d+)", "$1-$2"); // Get rid of whitespace in ">= 123" s = s.replaceAll("([<>]=?)\\s+(-?\\d+)", "$1$2"); // Get rid of whitespace in "! 123" s = s.replaceAll("(!)\\s+(-?\\d+)", "$1$2"); // Replace all commas with whitespace // Allows for alternate notation of: 123,456... s = s.replaceAll(",", " "); String[] s2 = s.split("\\s+"); // Make all tokens 'ORed'. There is no way to AND numeric tokens. for (int i = 0; i < s2.length; i++) if (! startsWith(s2[i], '!')) s2[i] = "^"+s2[i]; List<String> l = new LinkedList<>(); l.addAll(Arrays.asList(s2)); return l; }
Builder(String patternString) { if (! startsWith(patternString, '/')) patternString = '/' + patternString; if (patternString.equals("/*")) { isOnlyDotAll = true; return; } if (patternString.endsWith("/*")) isDotAll = true; // Find all {xxx} variables. Pattern p = Pattern.compile("\\{([^\\}]+)\\}"); Matcher m = p.matcher(patternString); while (m.find()) vars.add(m.group(1)); patternString = patternString.replaceAll("\\{[^\\}]+\\}", "([^\\/]+)"); patternString = patternString.replaceAll("\\/\\*$", "((?:)|(?:\\/.*))"); pattern = Pattern.compile(patternString); } }
Builder(String patternString) { if (! startsWith(patternString, '/')) patternString = '/' + patternString; if (patternString.equals("/*")) { isOnlyDotAll = true; return; } if (patternString.endsWith("/*")) isDotAll = true; // Find all {xxx} variables. Pattern p = Pattern.compile("\\{([^\\}]+)\\}"); Matcher m = p.matcher(patternString); while (m.find()) vars.add(m.group(1)); patternString = patternString.replaceAll("\\{[^\\}]+\\}", "([^\\/]+)"); patternString = patternString.replaceAll("\\/\\*$", "((?:)|(?:\\/.*))"); pattern = Pattern.compile(patternString); } }
private String findPath() { List<RestResource> rrc = ReflectionUtils.findAnnotations(RestResource.class, getClass()); for (RestResource rc : rrc) { String p = rc.path(); if (StringUtils.startsWith(p, '/')) p = p.substring(1); if (! p.isEmpty()) return p; } return null; }
/** * Constructor. * * @param patternString The raw pattern string from the {@link RestMethod#path()} annotation. */ public UrlPathPattern(String patternString) { this.patternString = patternString; if (! StringUtils.startsWith(patternString, '/')) patternString = '/' + patternString; if (patternString.equals("/*")) { isOnlyDotAll = true; return; } if (patternString.endsWith("/*")) isDotAll = true; // Find all {xxx} variables. Pattern p = Pattern.compile("\\{([^\\}]+)\\}"); List<String> vl = new LinkedList<String>(); Matcher m = p.matcher(patternString); while (m.find()) vl.add(m.group(1)); this.vars = vl.toArray(new String[vl.size()]); patternString = patternString.replaceAll("\\{[^\\}]+\\}", "([^\\/]+)"); patternString = patternString.replaceAll("\\/\\*$", "((?:)|(?:\\/.*))"); pattern = Pattern.compile(patternString); }
while (! argList.isEmpty()) { String s = argList.get(0); if (startsWith(s,'-')) break; put(i.toString(), argList.remove(0)); while (! argList.isEmpty()) { String s = argList.remove(0); if (startsWith(s, '-')) { key = s.substring(1); if (key.matches("\\d*"))
@Test public void testStartsWith() throws Exception { assertFalse(startsWith(null, 'a')); assertFalse(startsWith("", 'a')); assertTrue(startsWith("a", 'a')); assertTrue(startsWith("ab", 'a')); }
/** * Returns a resolved URL. * <p> * <ul class='spaced-list'> * <li>Fully-qualified absolute URLs (e.g. <js>"http://..."</js>, <js>"https://"</js>) are simply converted to a URL. * <li>Absolute URLs (e.g. <js>"/foo/..."</js>) are interpreted as relative to the server hostname. * <li>Relative URLs (e.g. <js>"foo/..."</js>) are interpreted as relative to this servlet path. * </ul> * * @param path The URL path to resolve. * @return The resolved URL. * @throws MalformedURLException If path is not a valid URL component. */ public URL getURL(String path) throws MalformedURLException { if (path.startsWith("http://") || path.startsWith("https://")) return new URL(path); if (StringUtils.startsWith(path, '/')) return new URL(getScheme(), getLocalName(), getLocalPort(), path); return new URL(getScheme(), getLocalName(), getLocalPort(), getContextPath() + getServletPath() + (StringUtils.isEmpty(path) ? "" : ('/' + path))); }
private String resolve(Object uri, UriResolution res) { String s = asString(uri); if (isAbsoluteUri(s)) return hasDotSegments(s) && res != NONE ? normalize(s) : s; if (res == ROOT_RELATIVE && startsWith(s, '/')) return hasDotSegments(s) ? normalize(s) : s; if (res == NONE && ! isSpecialUri(s)) return s; return append(new StringBuilder(), s).toString(); }
private String resolve(Object uri, UriResolution res) { String s = asString(uri); if (isAbsoluteUri(s)) return hasDotSegments(s) && res != NONE ? normalize(s) : s; if (res == ROOT_RELATIVE && startsWith(s, '/')) return hasDotSegments(s) ? normalize(s) : s; if (res == NONE && ! isSpecialUri(s)) return s; return append(new StringBuilder(), s).toString(); }
private String resolve(Object uri, UriResolution res) { String s = asString(uri); if (isAbsoluteUri(s)) return hasDotSegments(s) && res != NONE ? normalize(s) : s; if (res == ROOT_RELATIVE && startsWith(s, '/')) return hasDotSegments(s) ? normalize(s) : s; if (res == NONE && ! isSpecialUri(s)) return s; return append(new StringBuilder(), s).toString(); }
HttpPartSchemaBuilder apply(Path a) { name(a.value()); name(a.name()); type(a.type()); format(a.format()); items(a.items()); allowEmptyValue(a.allowEmptyValue()); collectionFormat(a.collectionFormat()); maximum(HttpPartSchema.toNumber(a.maximum())); exclusiveMaximum(a.exclusiveMaximum()); minimum(HttpPartSchema.toNumber(a.minimum())); exclusiveMinimum(a.exclusiveMinimum()); maxLength(a.maxLength()); minLength(a.minLength()); pattern(a.pattern()); maxItems(a.maxItems()); minItems(a.minItems()); uniqueItems(a.uniqueItems()); _enum(HttpPartSchema.toSet(a._enum())); multipleOf(HttpPartSchema.toNumber(a.multipleOf())); parser(a.parser()); serializer(a.serializer()); // Path remainder always allows empty value. if (startsWith(name, '/')) allowEmptyValue(); else required(true); return this; }
HttpPartSchemaBuilder apply(Path a) { name(a.value()); name(a.name()); type(a.type()); format(a.format()); items(a.items()); allowEmptyValue(a.allowEmptyValue()); collectionFormat(a.collectionFormat()); maximum(HttpPartSchema.toNumber(a.maximum())); exclusiveMaximum(a.exclusiveMaximum()); minimum(HttpPartSchema.toNumber(a.minimum())); exclusiveMinimum(a.exclusiveMinimum()); maxLength(a.maxLength()); minLength(a.minLength()); pattern(a.pattern()); maxItems(a.maxItems()); minItems(a.minItems()); uniqueItems(a.uniqueItems()); _enum(HttpPartSchema.toSet(a._enum())); multipleOf(HttpPartSchema.toNumber(a.multipleOf())); parser(a.parser()); serializer(a.serializer()); // Path remainder always allows empty value. if (startsWith(name, '/')) allowEmptyValue(); else required(true); return this; }
HttpPartSchemaBuilder apply(Path a) { name(a.value()); name(a.name()); type(a.type()); format(a.format()); items(a.items()); allowEmptyValue(a.allowEmptyValue()); collectionFormat(a.collectionFormat()); maximum(HttpPartSchema.toNumber(a.maximum())); exclusiveMaximum(a.exclusiveMaximum()); minimum(HttpPartSchema.toNumber(a.minimum())); exclusiveMinimum(a.exclusiveMinimum()); maxLength(a.maxLength()); minLength(a.minLength()); pattern(a.pattern()); maxItems(a.maxItems()); minItems(a.minItems()); uniqueItems(a.uniqueItems()); _enum(HttpPartSchema.toSet(a._enum())); multipleOf(HttpPartSchema.toNumber(a.multipleOf())); parser(a.parser()); serializer(a.serializer()); // Path remainder always allows empty value. if (startsWith(name, '/')) allowEmptyValue(); else required(true); return this; }