/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 8008738
* @summary checks that the mapping implemented by
* com.sun.org.apache.xml.internal.serializer.Encodings
* correctly identifies valid Charset names and
* correctly maps them to their preferred mime names.
* Also checks that the Encodings.properties resource file
* is consistent.
* @compile -XDignore.symbol.file CheckEncodingPropertiesFile.java
* @run main CheckEncodingPropertiesFile
* @author Daniel Fuchs
*/
public class CheckEncodingPropertiesFile {
private static final String ENCODINGS_FILE = "com/sun/org/apache/xml/internal/serializer/Encodings.properties";
try (InputStreamReader is = new InputStreamReader(ClassLoader.getSystemResourceAsStream(ENCODINGS_FILE))) {
}
//printAllCharsets();
}
private static final class CheckCharsetMapping {
/**
* A map that maps Java or XML name to canonical charset names.
* key: upper cased value of Java or XML name.
* value: case-sensitive canonical name of charset.
*/
/**
* Unresolved alias names.
* For a given set of names pointing to the same unresolved charset,
* this map will contain, for each alias in the set, a mapping
* with the alias.toUpperValue() as key and the set of known aliases
* as value.
*/
}
}
}
}
}
}
/**
* For each alias in aliases, attempt to find the canonical
* charset name.
* All names in aliases are supposed to point to the same charset.
* Names in aliases can be java names or XML names, indifferently.
* @param aliases list of names (aliases) for a given charset.
* @return The canonical name of the charset, if found, null otherwise.
*/
final String k = a.toUpperCase();
}
}
try {
}
res = a;
} else {
}
}
} catch (Exception x) {
continue;
}
}
}
/**
* Register a canonical charset name for a given set of aliases.
*
* @param charsetName the canonical charset name.
* @param aliases a list of aliases for the given charset.
*/
String k = a.toUpperCase();
csv = charsetName;
}
if (c != null) {
k = aa.toUpperCase();
unresolved.remove(k);
}
throw new MissingValidCharsetNameError(charsetName,c);
}
}
}
/**
* Register a set of aliases as being unresolved.
* @param names the list of names - this should be what is returned by
* nameSet.toArray(new String[nameSet.size()])
* @param nameSet the set of unresolved aliases.
*/
// This is not necessarily an error: it could happen that some
+ "' This is not necessarily an error "
+ "- this charset may not be supported on this platform.");
final String k = a.toUpperCase();
if (c != null) {
//System.out.println("Found: "+a+" -> "+c);
//System.out.println("\t merging "+ c + " with " + nameSet);
}
}
}
}
/**
* Add a new charset name mapping
* @param javaName the (supposedly) java name of the charset.
* @param xmlNames a list of corresponding XML names for that charset.
*/
}
}
} else {
}
}
/**
* Returns the canonical name of the charset for the given Java or XML
* alias name.
* @param alias the alias name
* @return the canonical charset name - or null if unknown.
*/
}
}
// First, build a mapping from the properties read from the resource
// file.
// We're going to check the consistency of the resource file
// while building this mapping, and throw errors if the file
// does not meet our assumptions.
//
}
// Then build maps of EncodingInfos, and print along debugging
// information that should help understand the content of the
// resource file and the mapping it defines.
//
if (charsetName == null) {
continue;
}
}
if (!javaInfos.containsKey(k)) {
if (!preferred.containsKey(k)) {
}
}
}
}
}
}
}
} else {
}
}
// Now we're going to verify that Encodings.java has done its job
// correctly. We're going to ask Encodings to convert java names to mime
// names and mime names to java names - and verify that the returned
// java names do map to recognized charsets.
//
// We're also going to verify that Encodings has recorded the preferred
// mime name correctly.
m.setAccessible(true);
}
if (javaCharsetName == null) continue;
}
}
}
}
final String jCharsetName;
try {
} catch (Exception x) {
throw new Error("Unrecognized charset returned by Encodings.convertMime2JavaEncoding(\""+xml+"\")", x);
}
System.out.println("Encodings.convertMime2JavaEncoding(\""+xml+"\") = \""+jName+"\" ("+jCharsetName+")");
return jName;
}
throws Exception {
} else {
}
}
if (pos < 0) {
}
//lastPrintable =
// Integer.decode(val.substring(pos).trim()).intValue();
while (st.hasMoreTokens()) {
}
return values;
}
// can be called in main() to help debugging.
// Prints out all available charsets and their recognized aliases
// as returned by the Charset API.
private static void printAllCharsets() {
}
}
}