Methods Summary |
---|
public static java.lang.String | escapeXml(java.lang.String buffer)Performs the following substring replacements
(to facilitate output to XML/HTML pages):
& -> &
< -> <
> -> >
" -> "
' -> '
See also OutSupport.writeEscapedXml().
taken from org.apache.taglibs.standard.tag.common.core.Util
int start = 0;
int length = buffer.length();
char[] arrayBuffer = buffer.toCharArray();
StringBuffer escapedBuffer = null;
for (int i = 0; i < length; i++) {
char c = arrayBuffer[i];
if (c <= HIGHEST_SPECIAL) {
char[] escaped = specialCharactersRepresentation[c];
if (escaped != null) {
// create StringBuffer to hold escaped xml string
if (start == 0) {
escapedBuffer = new StringBuffer(length + 5);
}
// add unescaped portion
if (start < i) {
escapedBuffer.append(arrayBuffer,start,i-start);
}
start = i + 1;
// add escaped xml
escapedBuffer.append(escaped);
}
}
}
// no xml escaping was necessary
if (start == 0) {
return buffer;
}
// add rest of unescaped portion
if (start < length) {
escapedBuffer.append(arrayBuffer,start,length-start);
}
return escapedBuffer.toString();
|
public static java.lang.String | getContentTypeAttribute(java.lang.String input, java.lang.String name)Get the value associated with a content-type attribute.
Syntax defined in RFC 2045, section 5.1.
taken from org.apache.taglibs.standard.tag.common.core.Util
int begin;
int end;
int index = input.toUpperCase().indexOf(name.toUpperCase());
if (index == -1) return null;
index = index + name.length(); // positioned after the attribute name
index = input.indexOf('=", index); // positioned at the '='
if (index == -1) return null;
index += 1; // positioned after the '='
input = input.substring(index).trim();
if (input.charAt(0) == '"") {
// attribute value is a quoted string
begin = 1;
end = input.indexOf('"", begin);
if (end == -1) return null;
} else {
begin = 0;
end = input.indexOf(';");
if (end == -1) end = input.indexOf(' ");
if (end == -1) end = input.length();
}
return input.substring(begin, end).trim();
|
public static int | getScope(java.lang.String scope)Converts the given string description of a scope to the corresponding
PageContext constant.
The validity of the given scope has already been checked by the
appropriate TLV.
specialCharactersRepresentation['&"] = "&".toCharArray();
specialCharactersRepresentation['<"] = "<".toCharArray();
specialCharactersRepresentation['>"] = ">".toCharArray();
specialCharactersRepresentation['""] = """.toCharArray();
specialCharactersRepresentation['\'"] = "'".toCharArray();
int ret = PageContext.PAGE_SCOPE;
if("request".equalsIgnoreCase(scope)){
ret = PageContext.REQUEST_SCOPE;
}else if("session".equalsIgnoreCase(scope)){
ret = PageContext.SESSION_SCOPE;
}else if("application".equalsIgnoreCase(scope)){
ret = PageContext.APPLICATION_SCOPE;
}
return ret;
|
public static boolean | isAbsoluteUrl(java.lang.String url)Returns true if our current URL is absolute,
false otherwise.
taken from org.apache.taglibs.standard.tag.common.core.ImportSupport
if(url == null){
return false;
}
int colonPos = url.indexOf(":");
if(colonPos == -1){
return false;
}
for(int i=0;i<colonPos;i++){
if(VALID_SCHEME_CHAR.indexOf(url.charAt(i)) == -1){
return false;
}
}
return true;
|
public static java.lang.String | resolveUrl(java.lang.String url, java.lang.String context, javax.servlet.jsp.PageContext pageContext)Utility methods
taken from org.apache.taglibs.standard.tag.common.core.UrlSupport
// don't touch absolute URLs
if (isAbsoluteUrl(url))
return url;
// normalize relative URLs against a context root
HttpServletRequest request =
(HttpServletRequest) pageContext.getRequest();
if (context == null) {
if (url.startsWith("/"))
return (request.getContextPath() + url);
else
return url;
} else {
if (!context.startsWith("/") || !url.startsWith("/")) {
throw new JspTagException(
"In URL tags, when the \"context\" attribute is specified, values of both \"context\" and \"url\" must start with \"/\".");
}
if (context.equals("/")) {
// Don't produce string starting with '//', many
// browsers interpret this as host name, not as
// path on same host.
return url;
} else {
return (context + url);
}
}
|
public static java.lang.String | stripSession(java.lang.String url)Strips a servlet session ID from url. The session ID
is encoded as a URL "path parameter" beginning with "jsessionid=".
We thus remove anything we find between ";jsessionid=" (inclusive)
and either EOS or a subsequent ';' (exclusive).
taken from org.apache.taglibs.standard.tag.common.core.ImportSupport
StringBuffer u = new StringBuffer(url);
int sessionStart;
while ((sessionStart = u.toString().indexOf(";" + Constants.SESSION_PARAMETER_NAME + "=")) != -1) {
int sessionEnd = u.toString().indexOf(";", sessionStart + 1);
if (sessionEnd == -1)
sessionEnd = u.toString().indexOf("?", sessionStart + 1);
if (sessionEnd == -1) // still
sessionEnd = u.length();
u.delete(sessionStart, sessionEnd);
}
return u.toString();
|