spark.utils.SparkUtils Java Examples

The following examples show how to use spark.utils.SparkUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ParamsFactory.java    From spark-swagger with Apache License 2.0 6 votes vote down vote up
public static String formatPath(String pathUri) {
    StringBuilder formatted = new StringBuilder();

    List<String> uriParts = SparkUtils.convertRouteToList(pathUri);
    for (String uriPart : uriParts) {
        try {
            formatted.append("/");
            if (SparkUtils.isParam(uriPart)) {
                final String param = URLDecoder.decode(uriPart, "UTF-8");
                final String decodedParam = param.contains(":") ? param.substring(param.indexOf(":") + 1) : param;
                formatted.append("{").append(decodedParam).append("}");
            } else {
                formatted.append(uriPart);
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    String path = formatted.toString();
    return path.isEmpty() ? "/" : path;
}
 
Example #2
Source File: Spark.java    From webster with Apache License 2.0 6 votes vote down vote up
public static List<String> getSplat(List<String> request, List<String> matched) {
    int nbrOfRequestParts = request.size();
    int nbrOfMatchedParts = matched.size();

    boolean sameLength = (nbrOfRequestParts == nbrOfMatchedParts);

    List<String> splat = new ArrayList<>();

    for (int i = 0; (i < nbrOfRequestParts) && (i < nbrOfMatchedParts); i++) {
        String matchedPart = matched.get(i);

        if (SparkUtils.isSplat(matchedPart)) {

            StringBuilder splatParam = new StringBuilder(request.get(i));
            if (!sameLength && (i == (nbrOfMatchedParts - 1))) {
                for (int j = i + 1; j < nbrOfRequestParts; j++) {
                    splatParam.append("/");
                    splatParam.append(request.get(j));
                }
            }
            splat.add(splatParam.toString());
        }
    }
    return Collections.unmodifiableList(splat);
}
 
Example #3
Source File: Route.java    From webster with Apache License 2.0 5 votes vote down vote up
private Request requestWithPathParams(Request request, RouteMatch routeMatch) {
    List<String> requestList = SparkUtils.convertRouteToList(routeMatch.getRequestURI());
    List<String> matchList = SparkUtils.convertRouteToList(routeMatch.getMatchUri());
    Map<String, String> pathParams = Spark.getParams(requestList, matchList);
    List<String> splats = Spark.getSplat(requestList, matchList);
    return request.withSplatsAndPathParams(splats, pathParams);
}
 
Example #4
Source File: Spark.java    From webster with Apache License 2.0 5 votes vote down vote up
public static Map<String, String> getParams(List<String> request, List<String> matched) {
    Map<String, String> params = new HashMap<>();

    for (int i = 0; (i < request.size()) && (i < matched.size()); i++) {
        String matchedPart = matched.get(i);
        if (SparkUtils.isParam(matchedPart)) {
            params.put(matchedPart.toLowerCase(), request.get(i));
        }
    }
    return Collections.unmodifiableMap(params);
}
 
Example #5
Source File: RouteEntryRepresenter.java    From gocd with Apache License 2.0 4 votes vote down vote up
public static List<String> getParams(RouteEntry entry) {
    return SparkUtils.convertRouteToList(entry.getPath())
            .stream()
            .filter(SparkUtils::isParam)
            .collect(Collectors.toList());
}
 
Example #6
Source File: RouteEntryRepresenter.java    From gocd with Apache License 2.0 4 votes vote down vote up
public static List<String> getParams(RouteEntry entry) {
    return SparkUtils.convertRouteToList(entry.getPath())
        .stream()
        .filter(SparkUtils::isParam)
        .collect(Collectors.toList());
}