Revision: 7277
          
http://languagetool.svn.sourceforge.net/languagetool/?rev=7277&view=rev
Author:   milek_pl
Date:     2012-06-07 09:18:34 +0000 (Thu, 07 Jun 2012)
Log Message:
-----------
fix bug with improper conversion of URLs to paths

Modified Paths:
--------------
    
trunk/JLanguageTool/src/java/org/languagetool/rules/spelling/hunspell/HunspellRule.java

Modified: 
trunk/JLanguageTool/src/java/org/languagetool/rules/spelling/hunspell/HunspellRule.java
===================================================================
--- 
trunk/JLanguageTool/src/java/org/languagetool/rules/spelling/hunspell/HunspellRule.java
     2012-06-07 08:09:19 UTC (rev 7276)
+++ 
trunk/JLanguageTool/src/java/org/languagetool/rules/spelling/hunspell/HunspellRule.java
     2012-06-07 09:18:34 UTC (rev 7277)
@@ -24,6 +24,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
@@ -120,28 +121,33 @@
   }
 
   private void init() throws IOException {
-    final String langCountry = language.getShortName()
-            + "_"
-            + language.getCountryVariants()[0];
-    final String shortDicPath = "/"
-            + language.getShortName()
-            + "/hunspell/"
-            + langCountry
-            + ".dic";
-    String wordChars = "";
-    // set dictionary only if there are dictionary files:
-    if (JLanguageTool.getDataBroker().resourceExists(shortDicPath)) {
-      dictionary = Hunspell.getInstance().
-              getDictionary(getDictionaryPath(langCountry, shortDicPath));
+      final String langCountry = language.getShortName()
+              + "_"
+              + language.getCountryVariants()[0];
+      final String shortDicPath = "/"
+              + language.getShortName()
+              + "/hunspell/"
+              + langCountry
+              + ".dic";
+      String wordChars = "";
+      // set dictionary only if there are dictionary files:
+      if (JLanguageTool.getDataBroker().resourceExists(shortDicPath)) {
+          final String path = getDictionaryPath(langCountry, shortDicPath);
+          if ("".equals(path)) {
+              dictionary = null;
+          } else {
+              dictionary = Hunspell.getInstance().
+                      getDictionary(path);
 
-      if (!"".equals(dictionary.getWordChars())) {
-        wordChars = "(?![" + dictionary.getWordChars().replace("-", "\\-") + 
"])";
+              if (!"".equals(dictionary.getWordChars())) {
+                  wordChars = "(?![" + dictionary.getWordChars().replace("-", 
"\\-") + "])";
+              }
+
+              dictionary.addWord("LanguageTool"); // to make demo text check 4 
times faster...
+          }
       }
-      
-      dictionary.addWord("LanguageTool"); // to make demo text check 4 times 
faster...
-    }
-    nonWordPattern = Pattern.compile(wordChars + NON_ALPHABETIC);
-    needsInit = false;
+      nonWordPattern = Pattern.compile(wordChars + NON_ALPHABETIC);
+      needsInit = false;
   }
 
   private String getDictionaryPath(final String dicName,
@@ -167,8 +173,13 @@
       dictionaryPath = tempDir.getAbsolutePath() + "/" + dicName;
     } else {
       final int suffixLength = ".dic".length();
-      dictionaryPath = dictionaryPath.substring(0, dictionaryPath.length() - 
suffixLength);
+      try {
+        dictionaryPath = new File(dictURL.toURI()).getAbsolutePath();
+        dictionaryPath = dictionaryPath.substring(0, dictionaryPath.length() - 
suffixLength);
+    } catch (URISyntaxException e) {
+       return "";
     }
+    }
     return dictionaryPath;
   }
 

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Languagetool-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/languagetool-cvs

Reply via email to