Java Code Examples for javax.swing.text.html.HTMLEditorKit#ParserCallback

The following examples show how to use javax.swing.text.html.HTMLEditorKit#ParserCallback . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DodsURLExtractor.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Extract text content from the given URL and return in String
 */
public String getTextContent(String url) throws IOException {
  if (debug)
    System.out.println(" URL.getTextContent=" + url);

  baseURL = new URL(url);
  InputStream in = baseURL.openStream();
  InputStreamReader r = new InputStreamReader(filterTag(in), CDM.UTF8);
  HTMLEditorKit.ParserCallback callback = new CallerBacker();

  textBuffer = new StringBuffer(3000);
  wantURLS = false;
  wantText = true;
  parser.parse(r, callback, false);

  return textBuffer.toString();
}
 
Example 2
Source File: bug8005391.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    int N = 10;

    for (int i = 0; i < N; i++) {
        HTMLEditorKit kit = new HTMLEditorKit();
        Class c = Class.forName("javax.swing.text.html.parser.ParserDelegator");
        HTMLEditorKit.Parser parser = (HTMLEditorKit.Parser) c.newInstance();
        HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
        HTMLEditorKit.ParserCallback htmlReader = doc.getReader(0);
        parser.parse(new CharArrayReader(htmlDoc.toCharArray()), htmlReader, true);
        htmlReader.flush();
        CharArrayWriter writer = new CharArrayWriter(1000);
        kit.write(writer, doc, 0, doc.getLength());
        writer.flush();

        String result = writer.toString();
        if (!result.contains("<tt><a")) {
            throw new RuntimeException("The <a> and <tt> tags are swapped");
        }
    }
}
 
Example 3
Source File: bug8005391.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    int N = 10;

    for (int i = 0; i < N; i++) {
        HTMLEditorKit kit = new HTMLEditorKit();
        Class c = Class.forName("javax.swing.text.html.parser.ParserDelegator");
        HTMLEditorKit.Parser parser = (HTMLEditorKit.Parser) c.newInstance();
        HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
        HTMLEditorKit.ParserCallback htmlReader = doc.getReader(0);
        parser.parse(new CharArrayReader(htmlDoc.toCharArray()), htmlReader, true);
        htmlReader.flush();
        CharArrayWriter writer = new CharArrayWriter(1000);
        kit.write(writer, doc, 0, doc.getLength());
        writer.flush();

        String result = writer.toString();
        if (!result.contains("<tt><a")) {
            throw new RuntimeException("The <a> and <tt> tags are swapped");
        }
    }
}
 
Example 4
Source File: HTMLEditorKitWriterBug.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    String htmlDoc = "<pre><p> </pre>";
    try {
        HTMLEditorKit kit = new HTMLEditorKit();
        Class c = Class.forName(
                "javax.swing.text.html.parser.ParserDelegator");
        HTMLEditorKit.Parser parser = (HTMLEditorKit.Parser) c.newInstance();
        HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
        HTMLEditorKit.ParserCallback htmlReader = doc.getReader(0);
        parser.parse(new CharArrayReader(htmlDoc.toCharArray()),
                htmlReader, true);
        htmlReader.flush();
        CharArrayWriter writer = new CharArrayWriter(1000);
        kit.write(writer, doc, 0, doc.getLength());
        writer.flush();
    } catch (Exception ex) {
        throw new RuntimeException("Test Failed " + ex);
    }
}
 
Example 5
Source File: bug8005391.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    int N = 10;

    for (int i = 0; i < N; i++) {
        HTMLEditorKit kit = new HTMLEditorKit();
        Class c = Class.forName("javax.swing.text.html.parser.ParserDelegator");
        HTMLEditorKit.Parser parser = (HTMLEditorKit.Parser) c.newInstance();
        HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
        HTMLEditorKit.ParserCallback htmlReader = doc.getReader(0);
        parser.parse(new CharArrayReader(htmlDoc.toCharArray()), htmlReader, true);
        htmlReader.flush();
        CharArrayWriter writer = new CharArrayWriter(1000);
        kit.write(writer, doc, 0, doc.getLength());
        writer.flush();

        String result = writer.toString();
        if (!result.contains("<tt><a")) {
            throw new RuntimeException("The <a> and <tt> tags are swapped");
        }
    }
}
 
Example 6
Source File: bug8005391.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    int N = 10;

    for (int i = 0; i < N; i++) {
        HTMLEditorKit kit = new HTMLEditorKit();
        Class c = Class.forName("javax.swing.text.html.parser.ParserDelegator");
        HTMLEditorKit.Parser parser = (HTMLEditorKit.Parser) c.newInstance();
        HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
        HTMLEditorKit.ParserCallback htmlReader = doc.getReader(0);
        parser.parse(new CharArrayReader(htmlDoc.toCharArray()), htmlReader, true);
        htmlReader.flush();
        CharArrayWriter writer = new CharArrayWriter(1000);
        kit.write(writer, doc, 0, doc.getLength());
        writer.flush();

        String result = writer.toString();
        if (!result.contains("<tt><a")) {
            throw new RuntimeException("The <a> and <tt> tags are swapped");
        }
    }
}
 
Example 7
Source File: bug8005391.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    int N = 10;

    for (int i = 0; i < N; i++) {
        HTMLEditorKit kit = new HTMLEditorKit();
        Class c = Class.forName("javax.swing.text.html.parser.ParserDelegator");
        HTMLEditorKit.Parser parser = (HTMLEditorKit.Parser) c.newInstance();
        HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
        HTMLEditorKit.ParserCallback htmlReader = doc.getReader(0);
        parser.parse(new CharArrayReader(htmlDoc.toCharArray()), htmlReader, true);
        htmlReader.flush();
        CharArrayWriter writer = new CharArrayWriter(1000);
        kit.write(writer, doc, 0, doc.getLength());
        writer.flush();

        String result = writer.toString();
        if (!result.contains("<tt><a")) {
            throw new RuntimeException("The <a> and <tt> tags are swapped");
        }
    }
}
 
Example 8
Source File: bug8005391.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    int N = 10;

    for (int i = 0; i < N; i++) {
        HTMLEditorKit kit = new HTMLEditorKit();
        Class c = Class.forName("javax.swing.text.html.parser.ParserDelegator");
        HTMLEditorKit.Parser parser = (HTMLEditorKit.Parser) c.newInstance();
        HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
        HTMLEditorKit.ParserCallback htmlReader = doc.getReader(0);
        parser.parse(new CharArrayReader(htmlDoc.toCharArray()), htmlReader, true);
        htmlReader.flush();
        CharArrayWriter writer = new CharArrayWriter(1000);
        kit.write(writer, doc, 0, doc.getLength());
        writer.flush();

        String result = writer.toString();
        if (!result.contains("<tt><a")) {
            throw new RuntimeException("The <a> and <tt> tags are swapped");
        }
    }
}
 
Example 9
Source File: DocumentParser.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public void parse(Reader in,  HTMLEditorKit.ParserCallback callback, boolean ignoreCharSet) throws IOException {
    this.ignoreCharSet = ignoreCharSet;
    this.callback = callback;
    parse(in);
    // end of line
    callback.handleEndOfLineString(getEndOfLineString());
}
 
Example 10
Source File: DocumentParser.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void parse(Reader in,  HTMLEditorKit.ParserCallback callback, boolean ignoreCharSet) throws IOException {
    this.ignoreCharSet = ignoreCharSet;
    this.callback = callback;
    parse(in);
    // end of line
    callback.handleEndOfLineString(getEndOfLineString());
}
 
Example 11
Source File: DocumentParser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void parse(Reader in,  HTMLEditorKit.ParserCallback callback, boolean ignoreCharSet) throws IOException {
    this.ignoreCharSet = ignoreCharSet;
    this.callback = callback;
    parse(in);
    // end of line
    callback.handleEndOfLineString(getEndOfLineString());
}
 
Example 12
Source File: ParserDelegator.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void parse(Reader r, HTMLEditorKit.ParserCallback cb, boolean ignoreCharSet) throws IOException {
    new DocumentParser(getDefaultDTD()).parse(r, cb, ignoreCharSet);
}
 
Example 13
Source File: ParserDelegator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void parse(Reader r, HTMLEditorKit.ParserCallback cb, boolean ignoreCharSet) throws IOException {
    new DocumentParser(getDefaultDTD()).parse(r, cb, ignoreCharSet);
}
 
Example 14
Source File: ParserDelegator.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
public void parse(Reader r, HTMLEditorKit.ParserCallback cb, boolean ignoreCharSet) throws IOException {
    new DocumentParser(getDefaultDTD()).parse(r, cb, ignoreCharSet);
}
 
Example 15
Source File: ParserDelegator.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
public void parse(Reader r, HTMLEditorKit.ParserCallback cb, boolean ignoreCharSet) throws IOException {
    new DocumentParser(getDefaultDTD()).parse(r, cb, ignoreCharSet);
}
 
Example 16
Source File: ParserDelegator.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void parse(Reader r, HTMLEditorKit.ParserCallback cb, boolean ignoreCharSet) throws IOException {
    new DocumentParser(getDefaultDTD()).parse(r, cb, ignoreCharSet);
}
 
Example 17
Source File: ParserDelegator.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void parse(Reader r, HTMLEditorKit.ParserCallback cb, boolean ignoreCharSet) throws IOException {
    new DocumentParser(getDefaultDTD()).parse(r, cb, ignoreCharSet);
}
 
Example 18
Source File: ParserDelegator.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void parse(Reader r, HTMLEditorKit.ParserCallback cb, boolean ignoreCharSet) throws IOException {
    new DocumentParser(getDefaultDTD()).parse(r, cb, ignoreCharSet);
}
 
Example 19
Source File: ParserDelegator.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void parse(Reader r, HTMLEditorKit.ParserCallback cb, boolean ignoreCharSet) throws IOException {
    new DocumentParser(getDefaultDTD()).parse(r, cb, ignoreCharSet);
}
 
Example 20
Source File: DocumentParser.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * Parse an HTML stream, given a DTD.
 *
 * @param in the reader to read the source from
 * @param callback the callback
 * @param ignoreCharSet if {@code true} the charset is ignored
 * @throws IOException if an I/O error occurs
 */
public void parse(Reader in, HTMLEditorKit.ParserCallback callback, boolean ignoreCharSet) throws IOException {
    this.ignoreCharSet = ignoreCharSet;
    this.callback = callback;
    parse(in);
    // end of line
    callback.handleEndOfLineString(getEndOfLineString());
}