Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1026 → Rev 1085

/backpath/trunk/src/ak/backpath/BackPath.java
38,6 → 38,8
public static final char URL_PARAM_SEPARATOR = '&';
public static final char URL_PARAM_VALUE = '=';
public static final char URL_PARAM_VALUE_SEP = ',';
public static final String REQUEST_URI_ATTR = "javax.servlet.forward.request_uri";
public static final String REQUEST_PARAMS_ATTR = "javax.servlet.forward.query_string";
 
protected static final byte URL_DELIMITER = 0;
protected static final int BUFFER_SIZE = 1024;
305,45 → 307,73
decode(stack, request.getParameter(param), zip);
 
// add new
String url = (new URL(request.getRequestURL().toString())).getPath();
if(methodsToSaveParams.contains(request.getMethod())) {
// to ignore
Set ignore = new TreeSet();
if(ignoreParams != null) {
for(int i = 0; i < ignoreParams.length; i++)
ignore.add(ignoreParams[i]);
}
ignore.add(param);
String url = getOriginalURL(request);
if(url == null) url = getCurentURL(request);
stack.add(url);
}
catch(IOException ex) {
log.error("Cannot init", ex);
}
}
 
// form query string
StringBuffer query = new StringBuffer();
Map requestParams = request.getParameterMap();
for(Iterator i = requestParams.keySet().iterator(); i.hasNext(); ) {
String name = (String)i.next();
if(ignore.contains(name)) continue;
if(query.length() == 0)
query.append(URL_PARAM_START);
else
query.append(URL_PARAM_SEPARATOR);
/**
* If internal servlet forward is used try to find the original URL of client request
*
*/
protected String getOriginalURL(HttpServletRequest request)
{
String url = (String)request.getAttribute(REQUEST_URI_ATTR);
if(url == null) return null;
 
query.append(URLEncoder.encode(name, URL_CHARSET));
query.append(URL_PARAM_VALUE);
String[] values = (String[])requestParams.get(name);
for(int j = 0; j < values.length; j++) {
if(j > 0) query.append(URL_PARAM_VALUE_SEP);
query.append(URLEncoder.encode(values[j], URL_CHARSET));
}
}
String params = (String)request.getAttribute(REQUEST_PARAMS_ATTR);
if(params != null)
url += URL_PARAM_START + params;
 
// form url
if(query.length() > 0) url = query.insert(0, url).toString();
return url;
}
 
/**
* Get URL of client request if no internal servlet forward detected
*
*/
protected String getCurentURL(HttpServletRequest request)
throws IOException
{
String url = (new URL(request.getRequestURL().toString())).getPath();
if(methodsToSaveParams.contains(request.getMethod())) {
// to ignore
Set ignore = new TreeSet();
if(ignoreParams != null) {
for(int i = 0; i < ignoreParams.length; i++)
ignore.add(ignoreParams[i]);
}
ignore.add(param);
 
stack.add(url);
// form query string
StringBuffer query = new StringBuffer();
Map requestParams = request.getParameterMap();
for(Iterator i = requestParams.keySet().iterator(); i.hasNext(); ) {
String name = (String)i.next();
if(ignore.contains(name)) continue;
if(query.length() == 0)
query.append(URL_PARAM_START);
else
query.append(URL_PARAM_SEPARATOR);
 
query.append(URLEncoder.encode(name, URL_CHARSET));
query.append(URL_PARAM_VALUE);
String[] values = (String[])requestParams.get(name);
for(int j = 0; j < values.length; j++) {
if(j > 0) query.append(URL_PARAM_VALUE_SEP);
query.append(URLEncoder.encode(values[j], URL_CHARSET));
}
}
 
// form url
if(query.length() > 0) url = query.insert(0, url).toString();
}
catch(IOException ex) {
log.error("Cannot init", ex);
}
 
return url;
}
 
/**