
org.swisspush.reststorage.UrlParser Maven / Gradle / Ivy
package org.swisspush.reststorage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class UrlParser {
private static final Logger log = LoggerFactory.getLogger(UrlParser.class);
public static RestStorageHandler.OffsetLimit offsetLimit(String offsetFromUrl, String limitFromUrl) {
RestStorageHandler.OffsetLimit offsetValues = new RestStorageHandler.OffsetLimit(0, -1);
if ((offsetFromUrl == null) && (limitFromUrl == null)) {
return offsetValues;
}
int limit = -1;
int offset = 0;
if(offsetFromUrl != null) {
try {
offset = Integer.parseInt(offsetFromUrl);
offset = Math.max(offset, 0);
} catch (Exception e) {
// do nothing here
}
}
if(limitFromUrl != null) {
try {
limit = Integer.parseInt(limitFromUrl);
limit = Math.max(limit, -1);
} catch (Exception ex) {
log.debug("TODO error handling", ex);
}
}
offsetValues.offset = offset;
offsetValues.limit = limit;
return offsetValues;
}
static String path(String uri) {
int i = uri.indexOf("://");
if (i == -1) {
i = 0;
} else {
i = uri.indexOf('/', i + 3);
if (i == -1) {
// contains no /
return "/";
}
}
int queryStart = uri.indexOf('?', i);
if (queryStart == -1) {
queryStart = uri.length();
}
return uri.substring(i, queryStart);
}
static String query(String uri) {
int i = uri.indexOf('?');
if (i == -1) {
return null;
} else {
return uri.substring(i + 1 , uri.length());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy