private int getLastPathParameterIndex(String name, UriTemplate t) { int i = 0; int pIndex = -1; for (String parameterName : t.getTemplateVariables()) { if (parameterName.equals(name)) { pIndex = i; } i++; } return pIndex; } }
/** * Create new instance using existing Client instance, and the URI from which the parameters will be extracted * */ public PathIdVersioningConfiguration( com.sun.jersey.api.client.Client client, URI uri ) { _client = client; StringBuilder template = new StringBuilder( BASE_URI.toString() ); if ( template.charAt( ( template.length() - 1 ) ) != '/' ) { template.append( "/pur-repository-plugin/api/revision/{pathId}/versioningConfiguration" ); } else { template.append( "pur-repository-plugin/api/revision/{pathId}/versioningConfiguration" ); } _uriBuilder = UriBuilder.fromPath( template.toString() ); _templateAndMatrixParameterValues = new HashMap<String, Object>(); com.sun.jersey.api.uri.UriTemplate uriTemplate = new com.sun.jersey.api.uri.UriTemplate( template.toString() ); HashMap<String, String> parameters = new HashMap<String, String>(); uriTemplate.match( uri.toString(), parameters ); _templateAndMatrixParameterValues.putAll( parameters ); }
private void addRule(final String path, final Object o) { final PathPattern p = getPattern(path, o.getClass()); if (isPatternValid(p, o.getClass())) { rules.put(p, new RightHandPathRule( resourceConfig.getFeature(ResourceConfig.FEATURE_REDIRECT), p.getTemplate().endsWithSlash(), new ResourceObjectRule(p.getTemplate(), o))); } }
+ "The URI template %s for sub-resource locator %s " + "and the URI template %s transform to the same regular expression %s", p.getTemplate().getTemplate(), locator.getMethod(), conflict.getTemplate().getTemplate(), p)); continue; new RightHandPathRule( resourceConfig.getFeature(ResourceConfig.FEATURE_REDIRECT), p.getTemplate().endsWithSlash(), r));
/** * Create a URI by substituting any template variables * for corresponding template values. * <p> * A URI template varibale without a value will be substituted by the * empty string. * * @param values the array of template values. The values will be * substituted in order of occurence of unique template variables. * @return the URI. */ public final String createURI(String... values) { return createURI(values, 0, values.length); }
int i = o2.getNumberOfExplicitCharacters() - o1.getNumberOfExplicitCharacters(); if (i != 0) return i; i = o2.getNumberOfTemplateVariables() - o1.getNumberOfTemplateVariables(); if (i != 0) return i; i = o2.getNumberOfExplicitRegexes() - o1.getNumberOfExplicitRegexes(); if (i != 0) return i;
/** * Construct a URI from the component parts each of which may contain * template variables. * * @param scheme the URI scheme component * @param userInfo the URI user info component * @param host the URI host component * @param port the URI port component * @param path the URI path component * @param query the URI query componnet * @param fragment the URI fragment component * @param values the array of template values * @param encode if true encode a template value according to the correspond * component type of the associated template variable, otherwise * contextually encode the template value * @return a URI */ public final static String createURIWithStringValues(final String scheme, final String userInfo, final String host, final String port, final String path, final String query, final String fragment, final String[] values, final boolean encode) { return createURIWithStringValues( scheme, null, userInfo, host, port, path, query, fragment, values, encode); }
offset = createURIComponent(UriComponent.Type.SCHEME, scheme, values, offset, false, mapValues, sb); sb.append(':'); offset = createURIComponent(UriComponent.Type.USER_INFO, userInfo, values, offset, encode, mapValues, sb); sb.append('@'); offset = createURIComponent(UriComponent.Type.HOST, host, values, offset, encode, mapValues, sb); offset = createURIComponent(UriComponent.Type.PORT, port, values, offset, false, mapValues, sb); sb.append("//"); offset = createURIComponent(UriComponent.Type.AUTHORITY, authority, values, offset, encode, mapValues, sb); offset = createURIComponent(UriComponent.Type.PATH, path, values, offset, encode, mapValues, sb); offset = createURIComponent(UriComponent.Type.QUERY_PARAM, query, values, offset, encode, mapValues, sb); offset = createURIComponent(UriComponent.Type.FRAGMENT, fragment, values, offset, encode, mapValues, sb);
/** * Add a rule that matches a 'from' url pattern to a destination (to) url pattern. * @param from The UriTemplate that the route matches on * @param to The UriTemplate that describes the destination url * @param httpVerbs The http verbs that the rule applies to */ public Builder addRule(String from, String to, List<String> httpVerbs) { urlRouteRules.add(new UrlRouteRule(new UriTemplate(from), new UriTemplate(to), httpVerbs, PASS_UNMAPPED)); return this; }
/** * Construct a new URI template. * <p> * The template will be parsed to extract template variables. * <p> * A specific regular expression will be generated from the template * to match URIs according to the template and map template variables to * template values. * <p> * @param templateParser the parser to parse the template. * @throws PatternSyntaxException if the specified * regular expression could not be generated * @throws IllegalArgumentException if the template is null or * an empty string. */ protected UriTemplate(UriTemplateParser templateParser) throws PatternSyntaxException, IllegalArgumentException { this.template = templateParser.getTemplate(); this.normalizedTemplate = templateParser.getNormalizedTemplate(); this.pattern = createUriPattern(templateParser); this.numOfExplicitRegexes = templateParser.getNumberOfExplicitRegexes(); this.numOfCharacters = templateParser.getNumberOfLiteralCharacters(); this.endsWithSlash = template.charAt(template.length() - 1) == '/'; this.templateVariables = Collections.unmodifiableList(templateParser.getNames()); }
/** * Create a URI by substituting any template variables * for corresponding template values. * <p> * A URI template varibale without a value will be substituted by the * empty string. * * @param values the array of template values. The values will be * substituted in order of occurence of unique template variables. * @return the URI. */ public final String createURI(String... values) { return createURI(values, 0, values.length); }
int i = o2.getNumberOfExplicitCharacters() - o1.getNumberOfExplicitCharacters(); if (i != 0) return i; i = o2.getNumberOfTemplateVariables() - o1.getNumberOfTemplateVariables(); if (i != 0) return i; i = o2.getNumberOfExplicitRegexes() - o1.getNumberOfExplicitRegexes(); if (i != 0) return i;
+ "The URI template %s for sub-resource locator %s " + "and the URI template %s transform to the same regular expression %s", p.getTemplate().getTemplate(), locator.getMethod(), conflict.getTemplate().getTemplate(), p)); continue; new RightHandPathRule( resourceConfig.getFeature(ResourceConfig.FEATURE_REDIRECT), p.getTemplate().endsWithSlash(), r));
/** * Construct a URI from the component parts each of which may contain * template variables. * <p> * A template value is an Object instance that MUST support the toString() * method to convert the template value to a String instance. * * @param scheme the URI scheme component * @param authority the URI authority info component * @param userInfo the URI user info component * @param host the URI host component * @param port the URI port component * @param path the URI path component * @param query the URI query componnet * @param fragment the URI fragment component * @param values the template variable to value map * @param encode if true encode a template value according to the correspond * component type of the associated template variable, otherwise * contextually encode the template value * @return a URI */ public final static String createURIWithStringValues( final String scheme, final String authority, final String userInfo, final String host, final String port, final String path, final String query, final String fragment, final Map<String, ? extends Object> values, final boolean encode) { return createURIWithStringValues(scheme, authority, userInfo, host, port, path, query, fragment, EMPTY_VALUES, encode, (Map<String, Object>) values); }
offset = createURIComponent(UriComponent.Type.SCHEME, scheme, values, offset, false, mapValues, sb); sb.append(':'); offset = createURIComponent(UriComponent.Type.USER_INFO, userInfo, values, offset, encode, mapValues, sb); sb.append('@'); offset = createURIComponent(UriComponent.Type.HOST, host, values, offset, encode, mapValues, sb); offset = createURIComponent(UriComponent.Type.PORT, port, values, offset, false, mapValues, sb); sb.append("//"); offset = createURIComponent(UriComponent.Type.AUTHORITY, authority, values, offset, encode, mapValues, sb); offset = createURIComponent(UriComponent.Type.PATH, path, values, offset, encode, mapValues, sb); offset = createURIComponent(UriComponent.Type.QUERY_PARAM, query, values, offset, encode, mapValues, sb); offset = createURIComponent(UriComponent.Type.FRAGMENT, fragment, values, offset, encode, mapValues, sb);
/** * Add a rule that matches a 'from' url pattern to a destination (to) url pattern. * @param from The UriTemplate that the route matches on * @param to The UriTemplate that describes the destination url * @param httpVerbs The http verbs that the rule applies to * @param routePredicate The route predicate that determines if the route should match */ public Builder addRule(String from, String to, List<String> httpVerbs, RoutePredicate routePredicate) { urlRouteRules.add(new UrlRouteRule(new UriTemplate(from), new UriTemplate(to), httpVerbs, PASS_UNMAPPED, routePredicate)); return this; }
/** * Construct a new URI template. * <p> * The template will be parsed to extract template variables. * <p> * A specific regular expression will be generated from the template * to match URIs according to the template and map template variables to * template values. * <p> * @param templateParser the parser to parse the template. * @throws PatternSyntaxException if the specified * regular expression could not be generated * @throws IllegalArgumentException if the template is null or * an empty string. */ protected UriTemplate(UriTemplateParser templateParser) throws PatternSyntaxException, IllegalArgumentException { this.template = templateParser.getTemplate(); this.normalizedTemplate = templateParser.getNormalizedTemplate(); this.pattern = createUriPattern(templateParser); this.numOfExplicitRegexes = templateParser.getNumberOfExplicitRegexes(); this.numOfCharacters = templateParser.getNumberOfLiteralCharacters(); this.endsWithSlash = template.charAt(template.length() - 1) == '/'; this.templateVariables = Collections.unmodifiableList(templateParser.getNames()); }
/** * Construct a URI from the component parts each of which may contain * template variables. * <p> * A template values is an Object instance MUST support the toString() * method to convert the template value to a String instance. * * @param scheme the URI scheme component * @param userInfo the URI user info component * @param host the URI host component * @param port the URI port component * @param path the URI path component * @param query the URI query componnet * @param fragment the URI fragment component * @param values the template variable to value map * @param encode if true encode a template value according to the correspond * component type of the associated template variable, otherwise * contextually encode the template value * @return a URI */ public final static String createURI(final String scheme, final String userInfo, final String host, final String port, final String path, final String query, final String fragment, final Map<String, ? extends Object> values, final boolean encode) { return createURI(scheme, null, userInfo, host, port, path, query, fragment, values, encode); }
/** * Push match to the provided context. * @param context The URI rule context */ protected final void pushMatch(final UriRuleContext context) { context.pushMatch( template, template.getTemplateVariables() ); }
new RightHandPathRule( resourceConfig.getFeature(ResourceConfig.FEATURE_REDIRECT), p.getTemplate().endsWithSlash(), new HttpMethodRule(rmm, true, dispatchingListener)));