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

  1. !!Script
  2. // Copyright ⌐ 1999 - Modelworks Software
  3.  
  4. /**
  5. @Tool: createJavaHtmlView~creates a HTML file version of
  6. the active editor
  7. @EndTool: 
  8. @Summary: reateJavaHtmlView~creates a HTML file view
  9. */
  10.  
  11. var gOutput = getOutput();
  12. var gStyleHanderMap;
  13. var gTabSpaces = "";
  14.  
  15. function DoCommand()
  16. {
  17.     var editor = getActiveEditor();
  18.     if (editor)
  19.     {
  20.         for (var i = 0; i < editor.tabWidth; i++)
  21.         {
  22.             gTabSpaces += " ";
  23.         }
  24.  
  25.         DefineStyleHandlerMap();
  26.         var htmlOut = newEditor(".html", true);
  27.         WriteHeader(htmlOut, editor.path);
  28.         var range = newRange(0,0,0,0);
  29.         var lineCount = editor.getLineCount();
  30.         for (var lineIndex = 0; lineIndex < lineCount; lineIndex++)
  31.         {
  32.             var lineLength = editor.getLineLength(lineIndex);
  33.             var charIndex = 0;
  34.             while (charIndex < lineLength)
  35.             {
  36.                 var style = editor.getSyntaxColorStyle(lineIndex, charIndex, range);
  37.                 charIndex = range.endCharIndex + 1;
  38.                 ProcessRange(htmlOut, style, range, editor);
  39.             }
  40.             WriteNewLine(htmlOut);
  41.         }
  42.         WriteTrailer(htmlOut);
  43.         htmlOut.setActive(); // make it visible if it is not already visible
  44.     }
  45. }
  46.  
  47. function ProcessRange(htmlOut, style, range, editor)
  48. {
  49.     var handler = gStyleHanderMap.lookup(style);
  50.     if (handler)
  51.     {
  52.         //gOutput.writeLine("Processing style: " + style);
  53.         handler(htmlOut, style, range, editor);
  54.     }
  55.     else
  56.     {
  57.         WritePlainText(htmlOut, style, range, editor);
  58.     }
  59. }
  60.  
  61.  
  62. // Handler map
  63. function DefineStyleHandlerMap()
  64. {
  65.     gStyleHanderMap = newMap();
  66.     
  67.     // Headers
  68.     gStyleHanderMap.add("plain text", WritePlainText);
  69.     gStyleHanderMap.add("quoted string", WriteStringText);
  70.     gStyleHanderMap.add("comment", WriteItalic);
  71.     gStyleHanderMap.add("line comment", WriteItalic);
  72.     
  73.     gStyleHanderMap.add("java awt classes", WriteBold);
  74.     gStyleHanderMap.add("java data types", WriteBold);
  75.     gStyleHanderMap.add("java interfaces", WriteBold);
  76.     gStyleHanderMap.add("java preprocessor", WriteBold);
  77.     gStyleHanderMap.add("java reserved methods", WriteBold);
  78.     gStyleHanderMap.add("java reserved words", WriteBold);
  79.     gStyleHanderMap.add("java swing classes", WriteBold);
  80.     gStyleHanderMap.add("java util classes", WriteBold);
  81. }
  82.  
  83. function WritePlainText(htmlOut, style, range, editor)
  84. {
  85.     var text = EncodeText(editor.copy(range));
  86.     htmlOut.append(text);
  87. }
  88.  
  89. function WriteStringText(htmlOut, style, range, editor)
  90. {
  91.     var text = EncodeText(editor.copy(range));
  92.     htmlOut.append("<i><b>" + text + "</b></i>");
  93. }
  94.  
  95. function WriteBold(htmlOut, style, range, editor)
  96. {
  97.     var text = EncodeText(editor.copy(range));
  98.     htmlOut.append("<b>" + text + "</b>");
  99. }
  100.  
  101. function WriteItalic(htmlOut, style, range, editor)
  102. {
  103.     var text = EncodeText(editor.copy(range));
  104.     htmlOut.append("<i>" + text + "</i>");
  105. }
  106.  
  107. function WriteHeader(htmlOut, name)
  108. {
  109.     htmlOut.append("<html>\n");
  110.     htmlOut.append("<head>\n");
  111.     htmlOut.append("<meta name=\"generator\" content=\"Modelworks IDE\">\n");
  112.     htmlOut.append("<title>" + name +"</title>\n");
  113.     htmlOut.append("</head>\n");
  114.     htmlOut.append("<body bgcolor=\"#ffffff\">\n");
  115.     htmlOut.append("<pre>\n");
  116. }
  117.  
  118. function WriteNewLine(htmlOut)
  119. {
  120.     htmlOut.append("\n");
  121. }
  122.  
  123. function WriteTrailer(htmlOut)
  124. {
  125.     htmlOut.append("</pre>\n");
  126.     htmlOut.append("</body>\n");
  127.     htmlOut.append("</html>\n");
  128. }
  129.  
  130. function EncodeText(text)
  131. {
  132.     var index = text.indexOf('\t');
  133.     while (index > -1)
  134.     {
  135.         text = replaceInString(text, index, 1, gTabSpaces);
  136.         index = text.indexOf('\t');
  137.     }
  138.  
  139.     var index = text.indexOf('<');
  140.     while (index > -1)
  141.     {
  142.         text = replaceInString(text, index, 1, "<");
  143.         index = text.indexOf('<');
  144.     }
  145.     
  146.     var index = text.indexOf('>');
  147.     while (index > -1)
  148.     {
  149.         text = replaceInString(text, index, 1, ">");
  150.         index = text.indexOf('>');
  151.     }
  152.     
  153.     return text;
  154. }
  155.  
  156.  
  157. !!/Script
  158.  
  159.