JAL-4026 update the viewport’s wrapped width after calculating it
[jalview.git] / utils / HelpLinksChecker.java
index 9463758..dee5322 100644 (file)
@@ -1,5 +1,23 @@
-
-
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * 
+ * This file is part of Jalview.
+ * 
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *  
+ * Jalview 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 for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileReader;
@@ -16,7 +34,7 @@ import java.util.Map;
  * @author gmcarstairs
  *
  */
-public class HelpLinksChecker
+public class HelpLinksChecker implements BufferedLineReader.LineCleaner
 {
   private static final String HELP_HS = "help.hs";
 
@@ -159,9 +177,8 @@ public class HelpLinksChecker
         unusedTargets.remove(image);
         if (!tocTargets.containsKey(image))
         {
-          log(String.format(
-                  "Invalid image '%s' at line %d of %s", image, lineNo,
-                  HELP_HS));
+          log(String.format("Invalid image '%s' at line %d of %s", image,
+                  lineNo, HELP_HS));
           invalidImageCount++;
         }
       }
@@ -184,23 +201,18 @@ public class HelpLinksChecker
     log(unusedTargets.size() + " unused targets");
     for (String target : unusedTargets.keySet())
     {
-      log(String.format("    %s: %s", target,
-              unusedTargets.get(target)));
+      log(String.format("    %s: %s", target, unusedTargets.get(target)));
     }
     log(invalidMapUrlCount + " invalid map urls");
     log(invalidImageCount + " invalid image attributes");
-    log(String.format(
-            "%d internal href links (%d with anchors)", internalHrefCount,
-            anchorRefCount));
-    log(invalidInternalHrefCount
-            + " invalid internal href links");
-    log(invalidAnchorRefCount
-            + " invalid internal anchor links");
+    log(String.format("%d internal href links (%d with anchors)",
+            internalHrefCount, anchorRefCount));
+    log(invalidInternalHrefCount + " invalid internal href links");
+    log(invalidAnchorRefCount + " invalid internal anchor links");
     log(externalHrefCount + " external href links");
     if (internetAvailable)
     {
-      log(invalidExternalHrefCount
-              + " invalid external href links");
+      log(invalidExternalHrefCount + " invalid external href links");
     }
     else
     {
@@ -270,9 +282,10 @@ public class HelpLinksChecker
         else
         {
           internalHrefCount++;
+          String relFile = System.getProperty("os.name").indexOf("Win") > -1 ? href.replace("/", File.separator) : href;
           File hrefFile = href.equals("") ? htmlFile : new File(htmlFolder,
                   href);
-          if (hrefFile != htmlFile && !fileExists(hrefFile, href))
+          if (hrefFile != htmlFile && !fileExists(hrefFile, relFile))
           {
             badLink = true;
             invalidInternalHrefCount++;
@@ -284,9 +297,8 @@ public class HelpLinksChecker
             {
               if (!checkAnchorExists(hrefFile, anchor))
               {
-                log(String.format(
-                        "Invalid anchor: %s at line %d of %s", anchor,
-                        lineNo, getPath(htmlFile)));
+                log(String.format("Invalid anchor: %s at line %d of %s",
+                        anchor, lineNo, getPath(htmlFile)));
                 invalidAnchorRefCount++;
               }
             }
@@ -294,9 +306,8 @@ public class HelpLinksChecker
         }
         if (badLink)
         {
-          log(String.format(
-                  "Invalid href %s at line %d of %s", href, lineNo,
-                  getPath(htmlFile)));
+          log(String.format("Invalid href %s at line %d of %s", href,
+                  lineNo, getPath(htmlFile)));
         }
       }
       data = br.readLine();
@@ -322,11 +333,11 @@ public class HelpLinksChecker
      * On Mac or Windows, file.exists() is not case sensitive, so do an
      * additional check with case sensitivity 
      */
-    int slashPos = href.lastIndexOf("/");
+    int slashPos = href.lastIndexOf(File.separator);
     String expectedFileName = slashPos == -1 ? href : href
             .substring(slashPos + 1);
     String cp = hrefFile.getCanonicalPath();
-    slashPos = cp.lastIndexOf("/");
+    slashPos = cp.lastIndexOf(File.separator);
     String actualFileName = slashPos == -1 ? cp : cp
             .substring(slashPos + 1);
 
@@ -348,7 +359,8 @@ public class HelpLinksChecker
     try
     {
       BufferedReader br = new BufferedReader(new FileReader(hrefFile));
-      String data = br.readLine();
+      BufferedLineReader blr = new BufferedLineReader(br, 3, this);
+      String data = blr.read();
       while (data != null)
       {
         if (data.contains(nameAnchor) || data.contains(idAnchor))
@@ -356,7 +368,7 @@ public class HelpLinksChecker
           found = true;
           break;
         }
-        data = br.readLine();
+        data = blr.read();
       }
       br.close();
     } catch (IOException e)
@@ -455,9 +467,8 @@ public class HelpLinksChecker
         }
         if (!new File(helpFolder, url).exists())
         {
-          log(String.format(
-                  "Invalid url path '%s' at line %d of %s", url, lineNo,
-                  HELP_JHM));
+          log(String.format("Invalid url path '%s' at line %d of %s", url,
+                  lineNo, HELP_JHM));
           invalidMapUrlCount++;
         }
       }
@@ -498,9 +509,8 @@ public class HelpLinksChecker
         unusedTargets.remove(target);
         if (!tocTargets.containsKey(target))
         {
-          log(String.format(
-                  "Invalid target '%s' at line %d of %s", target, lineNo,
-                  HELP_TOC_XML));
+          log(String.format("Invalid target '%s' at line %d of %s", target,
+                  lineNo, HELP_TOC_XML));
           invalidTargetCount++;
         }
       }
@@ -536,4 +546,14 @@ public class HelpLinksChecker
     }
     return value;
   }
+
+  /**
+   * Trim whitespace from concatenated lines but preserve one space for valid
+   * parsing
+   */
+  @Override
+  public String cleanLine(String l)
+  {
+    return l.trim() + " ";
+  }
 }