* WidgetAccess array to loop through to find matching request.
* @return Return true if the request should be allowed based on WebWorks' config.xml; false otherwise.
*/
public WidgetAccess getElement( String request, WidgetAccess[] accessList ) {
try {
URI requestURI = URI.create( request.trim() );
// require absolute URI's
if( requestURI.isAbsolute() ) {
// Initialize authority collection if it does not yet exist
initializeAuthCollection( accessList );
// Start with the full authority path and check if a WidgetAccess set exists for that path
// If it does not exist, remove the first section of the authority path and try again
String authString = getAuthorityFromString( request );
String schemeString = getSchemeFromString( request );
// Check for an authority string that has an existing key
// Special case: Allow file protocol to proceed without an authority
// Special case: Allow local protocol which is always without an authority
// Special case: Allow data protocol which is always without an authority (let isMatch handle it)
authString = authorityCheck( schemeString, authString );
if( authString.equals( "" ) && !( schemeString.equals( "file" ) || schemeString.equals( "local" ) || schemeString.equals( "data" ) ) ) {
return null;
}
WidgetWebFolderAccess folderAccess;
WidgetAccess fetchedAccess = null;
// Retrieve WidgetAccess set for the specified authority
folderAccess = (WidgetWebFolderAccess) _authorityCollection.get( schemeString + "://" + authString );
// Special case: no access element was found for a file protocol request.
// This is added since file protocol was allowed through the above check
if( schemeString.equals( "file" ) && folderAccess == null ) {
return null;
}
// If no access element is found with local URI, use local access for this request
if ( schemeString.equals( "local" ) && folderAccess == null ) {
return _localAccess;
}
if(folderAccess != null) {
fetchedAccess = folderAccess.getWidgetAccess( requestURI.getPath() + parseNull( requestURI.getQuery() ) );
}
if( !isMatch( fetchedAccess, requestURI ) ) {
fetchedAccess = folderAccess.getWidgetAccess( requestURI.getPath() + "*" );
}
boolean failedToFindAccess = false;
// Make sure we've got the right one
while( fetchedAccess == null || !isMatch( fetchedAccess, requestURI ) ) {
// There was an auth url that matched, but didnt match the folder structure
// Try the next level up
authString = authString.substring( authString.indexOf( '.' ) + 1 );
// Check for an authority string that has an existing key
authString = authorityCheck( schemeString, authString );
if( authString.equals( "" ) ) {
failedToFindAccess = true;
break;
}
// Retrieve WidgetAccess set for the specified authority
folderAccess = (WidgetWebFolderAccess) _authorityCollection.get( schemeString + "://" + authString );
// Special case: no access element was found for a file protocol request.
// This is added since file protocol was allowed through the above check
if( schemeString.equals( "file" ) && folderAccess == null ) {
return null;
}
fetchedAccess = folderAccess.getWidgetAccess( requestURI.getPath() + parseNull( requestURI.getQuery() ) );
}
if( !failedToFindAccess ) {
return fetchedAccess;
} else if ( isMatch( _localAccess, requestURI ) ) {