/** * {@inheritDoc} */ @Override protected String encodeLiteralCharacters(final String literalCharacters) { return UriComponent.contextualEncode( literalCharacters, UriComponent.Type.PATH ); } }
/** * Public constructor. * @param template The template */ public PathPattern(final UriTemplate template) { super( PathPattern.postfixWithCapturingGroup(template.getPattern().getRegex()), PathPattern.indexCapturingGroup(template.getPattern().getGroupIndexes()) ); this.template = template; }
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; } }
MultivaluedMapImpl createMultivalueMap( String paramName, String paramValue ) { MultivaluedMapImpl queryParams = new MultivaluedMapImpl(); queryParams.add( paramName, UriComponent.encode( paramValue, UriComponent.Type.QUERY_PARAM ) ); return queryParams; }
@Override public List<String> getMatchedURIs(boolean decode) { List<String> result; if (decode) { result = new ArrayList<String>(paths.size()); for (String path : paths) { result.add(UriComponent.decode( path, UriComponent.Type.PATH)); } } else { result = paths; } return Collections.unmodifiableList(result); }
/** * 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 ); }
@Override public MultivaluedMap<String, String> getQueryParameters(boolean decode) { if (decode) { if (decodedQueryParameters != null) return decodedQueryParameters; return decodedQueryParameters = UriComponent.decodeQuery( getRequestUri(), true); } else { if (encodedQueryParameters != null) return encodedQueryParameters; return encodedQueryParameters = UriComponent.decodeQuery( getRequestUri(), false); } }
@Override public List<PathSegment> getPathSegments(boolean decode) { if (decode) { if (decodedPathSegments != null) return decodedPathSegments; return decodedPathSegments = UriComponent.decodePath(getPath(false), true); } else { if (encodedPathSegments != null) return encodedPathSegments; return encodedPathSegments = UriComponent.decodePath(getPath(false), false); } }
public void onConflict(PathPattern p1, PathPattern p2) { Errors.error(String.format("Conflicting URI templates. " + "The URI templates %s and %s for root resource classes " + "transform to the same regular expression %s", p1.getTemplate().getTemplate(), p2.getTemplate().getTemplate(), p1)); } });
@Override public String toString() { if (target.hasValue()) { return "ARC(" + new String(code) + ") --> " + target.getPattern().getRegex(); } else { return "ARC(" + new String(code) + ") --> null"; } }
/** * Public ctor. * @param template The template * @param rightHandSide Right hand side of the template */ public PathPattern(final UriTemplate template, final String rightHandSide) { super( PathPattern.postfixWithCapturingGroup( template.getPattern().getRegex(), rightHandSide ), PathPattern.indexCapturingGroup(template.getPattern().getGroupIndexes()) ); this.template = template; }
@Override public String getPath(boolean decode) { if (decode) { if (decodedPath != null) return decodedPath; return decodedPath = UriComponent.decode( getEncodedPath(), UriComponent.Type.PATH); } else { return getEncodedPath(); } }
/** * Create new instance using existing Client instance, and the URI from which the parameters will be extracted * */ public PathIdPurge( 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/purge/{pathId : .+}/purge" ); } else { template.append( "pur-repository-plugin/api/purge/{pathId : .+}/purge" ); } _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 <T> void encodeKeys(Map<String, T> map) { Map<String, T> tempMap = new HashMap<String, T>(); for(Map.Entry<String, T> entry : map.entrySet()) tempMap.put(UriComponent.contextualEncode(entry.getKey(), UriComponent.Type.PATH_SEGMENT), entry.getValue()); map.clear(); map.putAll(tempMap); }
/** * Push match to the provided context. * @param context The URI rule context */ protected final void pushMatch(final UriRuleContext context) { context.pushMatch( template, template.getTemplateVariables() ); }
public void onConflict(PathPattern p1, PathPattern p2) { Errors.error(String.format("Conflicting URI templates. " + "The URI templates %s and %s for sub-resource methods " + "and/or sub-resource locators of resource class %s " + "transform to the same regular expression %s", p1.getTemplate().getTemplate(), p2.getTemplate().getTemplate(), resource.getResourceClass().getName(), p1)); } });
@Override public void pushMatch(UriTemplate template, List<String> names) { matchResults.addFirst(matchResult); templates.addFirst(template); if (encodedTemplateValues == null) { encodedTemplateValues = new MultivaluedMapImpl(); } int i = 1; for (String name : names) { final String value = matchResult.group(i++); encodedTemplateValues.addFirst(name, value); if (decodedTemplateValues != null) { decodedTemplateValues.addFirst( UriComponent.decode(name, UriComponent.Type.PATH_SEGMENT), UriComponent.decode(value, UriComponent.Type.PATH)); } } }
/** * Create new instance using existing Client instance, and the URI from which the parameters will be extracted * */ public PathIdRevisions( 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 : .+}/revisions" ); } else { template.append( "pur-repository-plugin/api/revision/{pathId : .+}/revisions" ); } _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 trace(Object resource, Object subResource, UriRuleContext context) { final String prevPath = context.getUriInfo().getMatchedURIs().get(1); final String currentPath = context.getUriInfo().getMatchedURIs().get(0); context.trace( String.format("accept sub-resource locator: \"%s\" : \"%s\" -> @Path(\"%s\") " + "%s = %s", prevPath, currentPath.substring(prevPath.length()), getTemplate().getTemplate(), ReflectionHelper.methodInstanceToString(resource, m), subResource)); }
/** * Trie initialization */ private TrieNode<R> initTrie(List<PatternRulePair<R>> rules) { TrieNode<R> a = new TrieNode<R>(); for (PatternRulePair<R> prp : rules) { if (prp.p instanceof PathPattern) { PathPattern p = (PathPattern)prp.p; a.add(p.getTemplate().getTemplate(), prp.r, prp.p); } else { throw new IllegalArgumentException( "The automata matching algorithm currently only works" + "for UriPattern instance that are instances of " + "PathPattern"); } } a.pack(); return a; }