home *** CD-ROM | disk | FTP | other *** search
/ PC User 2001 August / APC_Aug2001_CD2.iso / features / web_dev / files / mwjpp516.exe / %MAINDIR% / Tools / Html / indexHtml.script < prev    next >
Encoding:
Text File  |  2001-06-19  |  3.2 KB  |  136 lines

  1. !!Script
  2. // Copyright ⌐ 1997-1998 - Modelworks Software
  3.  
  4. /**
  5. @Tool: indexHtml~creates an index of a directory of HTML files for 
  6. all anchors with a name property. The results are sent to the Output panel. 
  7. @Tip: To capture the output in a file create an Output file. 
  8. @EndTip:
  9. @EndTool: 
  10. @Summary: indexHtml~creates an index of a directory
  11. */
  12.  
  13. var output = getOutput();
  14. var nameList = newList();
  15.  
  16. function getTargetName(name)
  17. {
  18.     var suffix = name.lastIndexOf("_");
  19.     if (suffix != -1)
  20.     {
  21.         return name.substring(0, suffix);
  22.     }
  23.     
  24.     return name;
  25. }
  26.  
  27. // This function is where we analize an anchor tag.
  28. // If we find a NAME attribute, we add a record to the nameList
  29.  
  30. function AnalyizeHtmlTag(editorPath, relativePath, fileName, lineIndex, bot)
  31. {
  32.     var position = bot.getHeadPosition();
  33.     while (position.valid)
  34.     {
  35.         // attribute.key and attribute.value are a Token objects
  36.         var attribute = bot.getNext(position);
  37.         if (attribute)
  38.         {
  39.             if (attribute.key.string.toLowerCase() == "name") 
  40.             {
  41.                 var value = relativePath + "#" + attribute.value.string;
  42.                 
  43.                 // Add the same information to the nameList
  44.                 var indexEntry = newAssociation();
  45.                 indexEntry.key = getTargetName(attribute.value.string);
  46.                 indexEntry.value = value;
  47.                 
  48.                 nameList.addTail(indexEntry);
  49.                 
  50.                 break;
  51.             }
  52.         }
  53.     }
  54. }
  55.  
  56. // The is the comparison function for sorting the list
  57. function compare(itemA, itemB)
  58. {
  59.     if (itemA.value < itemB.value)
  60.     return -1;
  61.     if (itemA.value == itemB.value)
  62.     return 0;
  63.     
  64.     return 1;
  65. }
  66.  
  67. //
  68. // Start Script
  69. //
  70.  
  71. var directoryPath = chooseDirectory("Choose directory to index");
  72.  
  73. if (directoryPath)
  74. {
  75.     var files = getDirectoryFiles(directoryPath, "*.html", true);
  76.     output.clear();
  77.     output.writeLine("Indexing files: ");
  78.     if (files)
  79.     {
  80.         var count = files.getCount();
  81.         var position = files.getHeadPosition();
  82.         while (position.valid)
  83.         {
  84.             var file = files.getNext(position);
  85.             
  86.             output.writeLine("Processing file: " + file.path);
  87.             
  88.             var editor = openEditor(file.path);   
  89.             if (editor)
  90.             {
  91.                 var findData = editor.findFirst("<a", 0, 0, true, false);
  92.                 if (findData)
  93.                 {
  94.                     while (findData.found)
  95.                     {
  96.                         var bot = editor.getHtmlTag(findData.range.startLineIndex, findData.range.startCharIndex);
  97.                         if (bot)
  98.                         {
  99.                             var relativePath = editor.getRelativePath(directoryPath);
  100.                             AnalyizeHtmlTag(editor.path, relativePath, editor.name, 
  101.                             findData.range.startLineIndex, bot);
  102.                         }       
  103.                         editor.findNext(findData);
  104.                     }
  105.                 }
  106.             }
  107.         }
  108.     }
  109.     
  110.     var items = nameList.getCount();
  111.     if (items > 0)
  112.     {   
  113.         output.writeLine("Sorting Anchors");
  114.         nameList.sort();
  115.         
  116.         var position = nameList.getHeadPosition();
  117.         while(position.valid)
  118.         {
  119.             var association = nameList.getNext(position);
  120.             var info = association.value;
  121.             var infoIndex = info.indexOf(".");
  122.             if (infoIndex > -1)
  123.             {
  124.                 info = info.substring(0, infoIndex);
  125.             }
  126.             output.writeLine("<a href=\"" + association.value + "\">" + 
  127.             association.key + "</a> - " + info +  "<br>");  
  128.         }
  129.     }
  130. }
  131.  
  132. output.writeLine("Report completed");
  133. output.writeLine("Total name anchors: " + nameList.getCount());
  134.  
  135. !!/Script
  136.