public boolean covers ( String uri ) { // any namspace covers only the any namespace uri // no wildcard ("") requires equality between namespaces. if ( ANY_NAMESPACE . equals ( ns ) || "" . equals ( wildcard ) ) { return ns . equals ( uri ) ; } String [ ] parts = split ( ns , wildcard ) ; // no wildcard if ( parts . length == 1 ) { return ns . equals ( uri ) ; } // at least one wildcard, we need to check that the start and end are the same // then we get to match a string against a pattern like *p1*...*pn* if ( ! uri . startsWith ( parts [ 0 ] ) ) { return false ; } if ( ! uri . endsWith ( parts [ parts . length - 1 ] ) ) { return false ; } // Check that all remaining parts match the remaining URI. int start = parts [ 0 ] . length ( ) ; int end = uri . length ( ) - parts [ parts . length - 1 ] . length ( ) ; for ( int i = 1 ; i < parts . length - 1 ; i ++ ) { if ( start > end ) { return false ; } int match = uri . indexOf ( parts [ i ] , start ) ; if ( match == - 1 || match + parts [ i ] . length ( ) > end ) { return false ; } start = match + parts [ i ] . length ( ) ; } return true ; }
Checks if a namespace specification covers a specified URI . any namespace pattern covers only the any namespace uri .