StringBuffer attrName = new StringBuffer();
char quote = '\0';
StringBuffer attrVal = new StringBuffer();
boolean doName = true;
boolean doVal = false;
CaseInsensitiveMap a = new CaseInsensitiveMap();
for (int i = 0; i < attrs.length(); i++) {
char ch = attrs.charAt(i);
if (ch == '\'' && quote == '\0') {
quote = '\'';
} else if (ch == '"' && quote == '\0') {
quote = '"';
// } else if (((doName && (ch == '\r' || ch == '\n')) || (doVal && ( i == attrs.length() - 1 ) ) || (doVal && ch == ' ' && quote == ' ' && attrVal.length() > 0)
// || (doVal && ch == '\'' && quote == '\'') || (doVal && ch == '\"' && quote == '\"'))) {
} else if (doVal && ( ch == quote || ( quote == '\0' && ch == ' ' ) || i == ( attrs.length() - 1 ) ) ) {
if(quote == '\0') {
attrVal.append(ch);
}
quote = '\0';
String an = attrName.toString();
if (!an.equals("")) {
a.put(attrName.toString(), attrVal.toString());
}
attrName.setLength(0);
attrVal.setLength(0);
doVal = false;
doName = true;
} else if (ch == '=' && doName) {
doName = false;
doVal = true;
} else {
if (doName) {
if ((ch != ' ' && ch != '\r' && ch != '\n') || attrName.length() > 0) {
attrName.append(ch);
}
} else if (doVal) {
attrVal.append(ch);
}
}
}
StringBuffer buf = new StringBuffer("<form");
String sslexUrl = context.toExternalForm();
if (a.containsKey("action")) {
try {
String contextPath = context.toExternalForm();
if (contextPath.endsWith("/")) {
contextPath = contextPath.substring(0, contextPath.length() - 1);
}
String originalAction = a.get("action").toString();
try {
sslexUrl = new URL(originalAction).toExternalForm();
}
catch(MalformedURLException murle) {
/**
* LDP - Bug fix: the commented out code causes problems with relative
* URLs used in the action parameter of a form
*
* Example:
*
* Context URL:
* http://foobar/OA_HTML/AppsLocalLogin.jsp
*
* Action:
* fndvald.jsp
*
* Results In:
*
* http://foobar/OA_HTML/AppsLocalLogin.jsp/fndvald.jsp
*
* Fixed code results in:
*
* http://foobar/OA_HTML/fndvald.jsp
*
* Slash should not be a problem because URL is intelligent enough to work out that
* the slash means from the root of the URL. I have tested this case and it does indeed
* work the same way regardless of the value of originalAction, in fact originalAction
* can be a completely different URL for example http://localhost/fndvald.jsp
*
* Here are the test cases:
*
* new URL("http://foobar/OA_HTML/AppsLocalLogin.jsp/fndvald.jsp", "fndvald.jsp").toExternalForm();
* == http://foobar/OA_HTML/AppsLocalLogin.jsp/fndvald.jsp
*
* new URL("http://foobar/OA_HTML/AppsLocalLogin.jsp/fndvald.jsp", "/fndvald.jsp").toExternalForm();
* == http://foobar/fndvald.jsp
*
* new URL("http://foobar/OA_HTML/AppsLocalLogin.jsp/fndvald.jsp", "http://localhost/fndvald.jsp").toExternalForm();
* == http://localhost/fndvald.jsp
*/
//if(originalAction.startsWith("/")) {
sslexUrl = new URL(context, originalAction).toExternalForm();
//}
//else {
// sslexUrl = new URL(DAVUtilities.concatenatePaths(contextPath, originalAction)).toExternalForm();
//}
}
} catch (MalformedURLException e) {
log.error("Failed to process FORM action", e);
}
}
a.put("action", "/replacementProxyEngine/" + ticket + "/" + Util.urlEncode(Utils.htmlunescape(sslexUrl)) );
for (Iterator i = a.entrySet().iterator(); i.hasNext();) {
buf.append(" ");
Map.Entry entry = (Map.Entry) i.next();
buf.append(entry.getKey().toString());
buf.append("=\"");
buf.append(entry.getValue());