⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tohtml.java

📁 it is a basic java browser
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                if (styleSheet != null){                    bteOut.print("<%bte.tpl name=styleSheet %>" + styleSheet + "<%/bte.tpl%>\n");                }                bteOut.print("<%bte.tpl name=highlightedDocument %>");                writeHTMLFragment(lexer, bteOut);                bteOut.print("<%/bte.tpl%>\n");                bteOut.print("<%/bte.doc%>\n");                bteOut.close();                Reader bteIn = circularBuffer.getReader();                compiler.compile(bteIn, out);            }         } catch (NoClassDefFoundError x){             noBTE = true;        }        if (noBTE){                      PrintWriter out = this.out;            out.println("<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>");            out.println("<html>");            out.println("<head>");            if (title != null){                out.println("<title>" + title + "</title>");            }            out.println("<meta http-equiv='content-type' content='text/html;charset=ISO-8859-1'>");                        if (styleSheet != null){                out.println("<link rel='stylesheet' title='Syntax Highlighting' href='" + styleSheet + "' type='text/css'>");            }            out.println("</head>");            out.println("<body>");            writeHTMLFragment(lexer, out);            out.println("<div style='border: thin black ridge;padding:1cm;'>");            out.println("<!--");            out.println("To customize the appearance of the html that is emitted you must install");            out.println("the BTE template system from:");            out.println("http://ostermiller.org/bte/");            out.println("-->");            out.println("Syntax Highlighting created using the ");            out.println("<a href='http://ostermiller.org/syntax/'>com.Ostermiller.Syntax</a> package.<br>");            out.println(dateFormat.format(new Date()));            out.println("</div>");            out.println("</body>");            out.println("</html>");        }                 out.flush();     }        /**     * Set the URL of the BTE template file which should used.     * For more information on BTE templates please      * see the <a href="http://ostermiller.org/bte/">BTE website</a>.     *     * @param bteSuper url of the bte template file.     */    public void setTemplate(String bteSuper){        this.bteSuper = bteSuper;    }        /**     * Set the file extension to be used for the document.     * <p>     * The type of syntax highlighting to use will depend on     * the lexerType that is set, the mime type that is given,     * and the file extension that is given.     * If a lexer is explicitly given, it is used, otherwise     * if the mime type is recognized, an appropriate style      * for that mime type is used, otherwise if the file extension     * is recognized, an appropriate style for that extension is     * used, otherwise, no style is given.     *      * @param mimeType the mimeType of the document or null to clear.     */    public void setFileExt(String fileExt){        this.fileExt = fileExt;    }        /**     * Set the name of this document (minus any file extension).     * <p>     * This name will be reported to html template.     *      * @param docName Name of the document.     */    public void setDocName(String docName){        this.docName = docName;    }        /**     * Set the lexer to be used for the document.     * <p>     * The type of syntax highlighting to use will depend on     * the lexerType that is set, the mime type that is given,     * and the file extension that is given.     * If a lexer is explicitly given, it is used, otherwise     * if the mime type is recognized, an appropriate style      * for that mime type is used, otherwise if the file extension     * is recognized, an appropriate style for that extension is     * used, otherwise, no style is given.     *      * @param full java name of the lexer to use.     */    public void setLexerType(String lexerType){        this.lexerType = lexerType;    }        /**     * Set the lexer to be used for the document.     */    private void setLexer(Lexer lexer){        saveLexer(lexer);        this.lexer = lexer;    }        /**     * Set the mime type of the document.     * <p>     * The type of syntax highlighting to use will depend on     * the lexerType that is set, the mime type that is given,     * and the file extension that is given.     * If a lexer is explicitly given, it is used, otherwise     * if the mime type is recognized, an appropriate style      * for that mime type is used, otherwise if the file extension     * is recognized, an appropriate style for that extension is     * used, otherwise, no style is given.     *      * @param mimeType the mimeType of the document or null to clear.     */    public void setMimeType(String mimeType){        this.mimeType = mimeType;    }        /**     * Get the mime type of the document.     *      * @return the mimeType of the document or null if none.     */    public String getMimeType(){        return mimeType;    }        /**     * Set the output stream.     *      * @param out new output stream.     */    public void setOutput(Writer out){                 this.out = new PrintWriter(out);    }        /**     * Set the output stream.     *      * @param out new output stream.     */    public void setOutput(PrintWriter out){        this.out = out;    }        /**     * Set the output to the given file.     *      * @param f file to which to write.     * @throws IOException if the file cannot be opened.     */    public void setOutput(File f) throws IOException {        setOutput(new FileWriter(f));    }        /**     * Set the input to the given file.     *      * @param f file from which to read.     * @throws IOException if the file cannot be opened.     */    public void setInput(File f) throws IOException {        setInput(new FileReader(f));    }        /**     * Set the input stream.     *      * @param in new input stream.     */    public void setInput(Reader in){        this.in = in;    }        /**     * Link the html document to the style sheet at the     * given URL.       *     * @param link stylesheet URL to use, or null to none.     */    public void setStyleSheet(String styleSheet){        this.styleSheet = styleSheet;    }         /**     * Use the given title for the html document.     *     * @param title document title, or null to use none.     */    public void setTitle(String title){        this.title = title;    }         /**     * Get the URL of the linked style sheet.       *     * @return stylesheet URL to used, or null if none.     */    public String getStyleSheet(){        return styleSheet;    }         /**     * Get the title used for the html document.     *     * @return document title, or null if none.     */    public String getTitle(){        return title;    }         /**     * Adds the specified style to be ignored if it     * is not already present.     * Ignored styles will not have a span associated with     * them in the output.  This can be used to make the     * resulting files smaller.  It is suggested to     * ignore "whitespace" as it probably won't look any different     * with an associated style.     * <p>     * If styles have been translated, then the translated style      * should be the one to be ignored.     *     * @param style the name of the style to be ignored.     * @return true if the style was not already being ignored.     */    public boolean addIgnoreStyle(String style){        return ignoreStyles.add(style);    }        /**     * No longer ignore the given style.     *     * @param style the name of the style to no longer be ignored.     * @return true if the style was being ignored.     */    public boolean removeIgnoreStyle(String style){        return ignoreStyles.remove(style);    }        /**     * Rename a style.  Useful for working with style sheets that     * expect certain names or for saving space by providing shorter     * names.  The name of the style will only be changed in the html     * document.  You must edit the CSS stylesheet or provide a custom     * CSS stylesheet with this option as the default stylesheet will     * use canonical style names.     *     * @param canonicalStyle the canonical (default) name of the style.     * @param style the new name of the style.     * @return previous translation of the canonicalStyle.     */    public String translateStyle(String canonicalStyle, String style){        if (canonicalStyle == null || style == null) throw new NullPointerException();        String value = (String)translateStyles.put(canonicalStyle, style);        if (value == null) return canonicalStyle;        return value;    }        /**     * No longer ignore the given style.     *     * @param canonicalStyle the canonical (default) name of the style.     * @return previous translation of the canonicalStyle.     */    public String removeTranslation(String canonicalStyle){        String value = (String)translateStyles.remove(canonicalStyle);        if (value == null) return canonicalStyle;        return value;    }    private static String version = "1.1.1";    /**     * Locale specific strings displayed to the user.     */ 	protected static ResourceBundle labels = ResourceBundle.getBundle("com.Ostermiller.Syntax.ToHTML",  Locale.getDefault());	/**	 * Program to add syntax highlighting to source files.     * Execute <b>java&nbsp;com.Ostermiller.Syntax.ToHTML&nbsp;--help</b>     * for more details.	 */ 	public static void main(String[] args){                  // create the command line options that we are looking for        LongOpt[] longopts = {            new LongOpt(labels.getString("help.option"), LongOpt.NO_ARGUMENT, null, 1),            new LongOpt(labels.getString("version.option"), LongOpt.NO_ARGUMENT, null, 2),            new LongOpt(labels.getString("about.option"), LongOpt.NO_ARGUMENT, null, 3),            new LongOpt(labels.getString("m.option"), LongOpt.REQUIRED_ARGUMENT, null, 'm'),                        new LongOpt(labels.getString("l.option"), LongOpt.REQUIRED_ARGUMENT, null, 'l'),                        new LongOpt(labels.getString("T.option"), LongOpt.REQUIRED_ARGUMENT, null, 'T'),                        new LongOpt(labels.getString("i.option"), LongOpt.REQUIRED_ARGUMENT, null, 'i'),                        new LongOpt(labels.getString("t.option"), LongOpt.REQUIRED_ARGUMENT, null, 't'),                          new LongOpt(labels.getString("s.option"), LongOpt.REQUIRED_ARGUMENT, null, 's'),                        new LongOpt(labels.getString("o.option"), LongOpt.REQUIRED_ARGUMENT, null, 'o'),                       new LongOpt(labels.getString("f.option"), LongOpt.NO_ARGUMENT, null, 'f'),                        new LongOpt(labels.getString("r.option"), LongOpt.REQUIRED_ARGUMENT, null, 'r'),         };                String oneLetterOptions = "m:l:T:i:t:s:o:fr:";        Getopt opts = new Getopt(labels.getString("tohtml"), args, oneLetterOptions, longopts);                ToHTML toHTML = new ToHTML();        toHTML.setTemplate(ClassLoader.getSystemResource("com/Ostermiller/Syntax/page.bte").toString());         toHTML.setStyleSheet("syntax.css");         String output = null;        String title = null;        boolean force = false;        int c;        while ((c = opts.getopt()) != -1){            switch(c){          		case 1:{                    // print out the help message                    String[] helpFlags = new String[]{                        "--" + labels.getString("help.option"),                        "--" + labels.getString("version.option"),                        "--" + labels.getString("about.option"),                        "-m --" + labels.getString("m.option") + " <" + labels.getString("type") + ">",                        "-l --" + labels.getString("l.option") + " <" + labels.getString("class") + ">",                        "-T --" + labels.getString("T.option") + " <" + labels.getString("title") + ">",                        "-i --" + labels.getString("i.option") + " <" + labels.getString("class") + ">",                        "-t --" + labels.getString("t.option") + " <" + labels.getString("url") + "|" + labels.getString("file") + ">",                        "-s --" + labels.getString("s.option") + " <" + labels.getString("url") + ">",                        "-o --" + labels.getString("o.option") + " <" + labels.getString("file") + ">",                        "-f --" + labels.getString("f.option"),

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -