private String generatePrefix ( String namespace ) { // assert namespace == namespace.intern(); while ( true ) { ++ autoDeclaredPrefixes ; // fast lookup uses table that was pre-initialized in static{} .... final String prefix = autoDeclaredPrefixes < precomputedPrefixes . length ? precomputedPrefixes [ autoDeclaredPrefixes ] : ( "n" + autoDeclaredPrefixes ) . intern ( ) ; // make sure this prefix is not declared in any scope (avoid hiding // in-scope prefixes)! for ( int i = namespaceEnd - 1 ; i >= 0 ; -- i ) { if ( prefix == namespacePrefix [ i ] ) { continue ; // prefix is already declared - generate new and // try again } } // declare prefix if ( namespaceEnd >= namespacePrefix . length ) { ensureNamespacesCapacity ( ) ; } namespacePrefix [ namespaceEnd ] = prefix ; namespaceUri [ namespaceEnd ] = namespace ; ++ namespaceEnd ; return prefix ; } }
Generate prefix .