// Add one JspPropertyGroup for each URL Pattern. This makes // the matching logic easier. for (String urlPattern : urlPatterns) {
String path = null;
String extension = null;
if (urlPattern.indexOf('*') < 0) { // Exact match
path = urlPattern;
} else { int i = urlPattern.lastIndexOf('/');
String file; if (i >= 0) {
path = urlPattern.substring(0,i+1);
file = urlPattern.substring(i+1);
} else {
file = urlPattern;
}
// pattern must be "*", or of the form "*.jsp" if (file.equals("*")) {
extension = "*";
} elseif (file.startsWith("*.")) {
extension = file.substring(file.indexOf('.')+1);
}
// The url patterns are reconstructed as the following: // path != null, extension == null: / or /foo/bar.ext // path == null, extension != null: *.ext // path != null, extension == "*": /foo/* boolean isStar = "*".equals(extension); if ((path == null && (extension == null || isStar))
|| (path != null && !isStar)) { if (log.isWarnEnabled()) {
log.warn(Localizer.getMessage( "jsp.warning.bad.urlpattern.propertygroup",
urlPattern));
} continue;
}
}
JspPropertyGroup propertyGroup = new JspPropertyGroup(path, extension, property);
/** *Selectthepropertygroupthathasmorerestrictiveurl-pattern. *Incaseoftie,selectthefirst.
*/
@SuppressWarnings("null") // NPE not possible private JspPropertyGroup selectProperty(JspPropertyGroup prev,
JspPropertyGroup curr) { if (prev == null) { return curr;
} if (prev.getExtension() == null) { // exact match return prev;
} if (curr.getExtension() == null) { // exact match return curr;
}
String prevPath = prev.getPath();
String currPath = curr.getPath(); if (prevPath == null && currPath == null) { // Both specifies a *.ext, keep the first one return prev;
} if (prevPath == null && currPath != null) { return curr;
} if (prevPath != null && currPath == null) { return prev;
} if (prevPath.length() >= currPath.length()) { return prev;
} return curr;
}
/** *Findapropertythatbestmatchesthesuppliedresource. *@paramuritheresourcesupplied. *@returnaJspPropertyindicatingthebestmatch,orsomedefault.
*/ public JspProperty findJspProperty(String uri) {
init();
// JSP Configuration settings do not apply to tag files if (jspProperties == null || uri.endsWith(".tag")
|| uri.endsWith(".tagx")) { return defaultJspProperty;
}
String uriPath = null; int index = uri.lastIndexOf('/'); if (index >=0 ) {
uriPath = uri.substring(0, index+1);
}
String uriExtension = null;
index = uri.lastIndexOf('.'); if (index >=0) {
uriExtension = uri.substring(index+1);
}
Collection<String> includePreludes = new ArrayList<>();
Collection<String> includeCodas = new ArrayList<>();
for (JspPropertyGroup jpg : jspProperties) {
JspProperty jp = jpg.getJspProperty();
// (arrays will be the same length)
String extension = jpg.getExtension();
String path = jpg.getPath();
if (extension == null) { // exact match pattern: /a/foo.jsp if (!uri.equals(path)) { // not matched; continue;
}
} else { // Matching patterns *.ext or /p/* if (path != null && uriPath != null &&
! uriPath.startsWith(path)) { // not matched continue;
} if (!extension.equals("*") &&
!extension.equals(uriExtension)) { // not matched continue;
}
} // We have a match // Add include-preludes and include-codas if (jp.getIncludePrelude() != null) {
includePreludes.addAll(jp.getIncludePrelude());
} if (jp.getIncludeCoda() != null) {
includeCodas.addAll(jp.getIncludeCoda());
}
// If there is a previous match for the same property, remember // the one that is more restrictive. if (jp.isXml() != null) {
isXmlMatch = selectProperty(isXmlMatch, jpg);
} if (jp.isELIgnored() != null) {
elIgnoredMatch = selectProperty(elIgnoredMatch, jpg);
} if (jp.getErrorOnELNotFound() != null) {
errorOnELNotFoundMatch = selectProperty(errorOnELNotFoundMatch, jpg);
} if (jp.isScriptingInvalid() != null) {
scriptingInvalidMatch =
selectProperty(scriptingInvalidMatch, jpg);
} if (jp.getPageEncoding() != null) {
pageEncodingMatch = selectProperty(pageEncodingMatch, jpg);
} if (jp.isDeferedSyntaxAllowedAsLiteral() != null) {
deferedSyntaxAllowedAsLiteralMatch =
selectProperty(deferedSyntaxAllowedAsLiteralMatch, jpg);
} if (jp.isTrimDirectiveWhitespaces() != null) {
trimDirectiveWhitespacesMatch =
selectProperty(trimDirectiveWhitespacesMatch, jpg);
} if (jp.getDefaultContentType() != null) {
defaultContentTypeMatch =
selectProperty(defaultContentTypeMatch, jpg);
} if (jp.getBuffer() != null) {
bufferMatch = selectProperty(bufferMatch, jpg);
} if (jp.isErrorOnUndeclaredNamespace() != null) {
errorOnUndeclaredNamespaceMatch =
selectProperty(errorOnUndeclaredNamespaceMatch, jpg);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.