protected Pair < String , String > createPrefix ( Map < String , String > nss , String currentNamespace , String currentPrefix ) { if ( currentNamespace == null ) { return Pair . of ( null , null ) ; } String pf = nss . get ( currentNamespace ) ; if ( pf != null ) { return Pair . of ( pf , null ) ; } int nsc = 0 ; pf = currentPrefix ; if ( pf == null ) { pf = "ns" + nsc ; } outer : while ( ! Thread . currentThread ( ) . isInterrupted ( ) ) { for ( Map . Entry < String , String > e : nss . entrySet ( ) ) { if ( Objects . equals ( e . getValue ( ) , pf ) ) { nsc ++ ; pf = "ns" + nsc ; continue outer ; } } // if we get here, the prefix is not yet used break ; } nss . put ( currentNamespace , pf ) ; StringBuilder xmlns = new StringBuilder ( ) ; xmlns . append ( " xmlns" ) . append ( pf != null && pf . length ( ) > 0 ? ":" : "" ) . append ( pf != null && pf . length ( ) > 0 ? pf : "" ) . append ( "='" ) . append ( sanitize ( currentNamespace ) ) . append ( "'" ) ; ; return Pair . of ( pf , xmlns . toString ( ) ) ; }
Generate a new prefix if the current is empty or already exists but with a different URI .