/** * Returns the namespace URI to use for serialization for a given namespace alias, possibly using * a predictable made-up namespace URI if the alias is not recognized. * * <p> * Specifically, if the namespace alias is not recognized, the namespace URI returned will be * {@code "http://unknown/"} plus the alias, unless {@code errorOnUnknown} is {@code true} in * which case it will throw an {@link IllegalArgumentException}. * </p> * * @param errorOnUnknown whether to thrown an exception if the namespace alias is not recognized * @param alias namespace alias * @return namespace URI, using a predictable made-up namespace URI if the namespace alias is not * recognized * @throws IllegalArgumentException if the namespace alias is not recognized and {@code * errorOnUnkown} is {@code true} */ String getNamespaceUriForAliasHandlingUnknown(boolean errorOnUnknown, String alias) { String result = getUriForAlias(alias); if (result == null) { Preconditions.checkArgument( !errorOnUnknown, "unrecognized alias: %s", alias.length() == 0 ? "(default)" : alias); return "http://unknown/" + alias; } return result; }
while (namespaceDictionary.getUriForAlias(alias) != null) { suffix++; alias = originalAlias + suffix;