Logo Search packages:      
Sourcecode: josm-plugins version File versions  Download package

static void org::openstreetmap::josm::plugins::validator::tests::SpellCheck::initializeSpellCheck (  )  throws FileNotFoundException, IOException [inline, static, private]

Reads the spellcheck file into a HashMap.

The data file is a list of words, beginning with +/-. If it starts with +, the word is valid, but if it starts with -, the word should be replaced by the nearest + word before this.

Exceptions:
FileNotFoundException 
IOException 

Definition at line 132 of file SpellCheck.java.

References PREF_SOURCES, SPELLCHECK_DATA_FILE, and spellCheckKeyData.

      {
            spellCheckKeyData = new HashMap<String, String>();
        String sources = Main.pref.get( PREF_SOURCES );
        if( sources == null || sources.length() == 0)
            sources = SPELLCHECK_DATA_FILE;
        
        StringTokenizer st = new StringTokenizer(sources, ";");
        StringBuilder errorSources = new StringBuilder();
        while (st.hasMoreTokens())
        {
            String source = st.nextToken();
            File sourceFile = Util.mirror(new URL(source), Util.getPluginDir(), -1);
            if( sourceFile == null || !sourceFile.exists() )
            {
                errorSources.append(source).append("\n");
                continue;
            }
            
            BufferedReader reader = new BufferedReader(new FileReader(sourceFile));

            String okValue = null;
            do
            {
                  String line = reader.readLine();
                if( line == null || line.length() == 0 )
                    break;
                if( line.startsWith("#") )
                    continue;
    
                  if( line.charAt(0) == '+' )
                  {
                        okValue = line.substring(1);
                  }
                  else if( line.charAt(0) == '-' && okValue != null )
                  {
                        spellCheckKeyData.put(line.substring(1), okValue);
                  }
                  else
                  {
                        System.err.println("Invalid spellcheck line:" + line);
                  }
            }
            while( true );
        }

        if( errorSources.length() > 0 )
            throw new IOException( tr("Could not download spellcheck data file:\n {0}", errorSources) );

      }


Generated by  Doxygen 1.6.0   Back to index