001    /*
002     * Copyright (c) 2007 Mozilla Foundation
003     *
004     * Permission is hereby granted, free of charge, to any person obtaining a 
005     * copy of this software and associated documentation files (the "Software"), 
006     * to deal in the Software without restriction, including without limitation 
007     * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
008     * and/or sell copies of the Software, and to permit persons to whom the 
009     * Software is furnished to do so, subject to the following conditions:
010     *
011     * The above copyright notice and this permission notice shall be included in 
012     * all copies or substantial portions of the Software.
013     *
014     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
015     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
016     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
017     * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
018     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
019     * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
020     * DEALINGS IN THE SOFTWARE.
021     */
022    
023    package org.whattf.datatype.test;
024    
025    import java.io.BufferedReader;
026    import java.io.IOException;
027    import java.io.InputStreamReader;
028    import java.net.URL;
029    
030    import org.relaxng.datatype.Datatype;
031    import org.relaxng.datatype.DatatypeException;
032    import org.whattf.datatype.Language;
033    
034    public class LanguageTester {
035    
036        private BufferedReader in;
037        private Datatype datatype;
038    
039        /**
040         * @throws IOException 
041         * 
042         */
043        public LanguageTester() throws IOException {
044            super();
045            URL url = new URL("http://unicode.org/cldr/data/tools/java/org/unicode/cldr/util/data/langtagTest.txt");
046            in = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
047            datatype = Language.THE_INSTANCE;
048        }
049    
050        /**
051         * @param args
052         * @throws IOException 
053         */
054        public static void main(String[] args) throws IOException {
055            new LanguageTester().run();
056        }
057    
058        private void run() throws IOException {
059            String line = null;
060            while ((line = in.readLine()) != null) {
061                test(line);
062            }
063        }
064    
065        private void test(String line) {
066            int hash = line.indexOf('#');
067            if (hash > -1) {
068                line = line.substring(0, hash);
069            }
070            line = line.trim();
071            try {
072                datatype.checkValid(line, null);
073                System.out.println(line + ": OK.");
074            } catch (DatatypeException e) {
075                System.out.println(line + ": " + e.getMessage());
076            }
077        }
078    
079    }