Search in sources :

Example 1 with Element

use of javax.swing.text.html.parser.Element in project jdk8u_jdk by JetBrains.

the class Test8017492 method main.

public static void main(String[] args) throws Exception {
    Runnable task = new Runnable() {

        @Override
        public void run() {
            try {
                SunToolkit.createNewAppContext();
                DTD dtd = DTD.getDTD("dtd");
                dtd.elements = new Vector<Element>() {

                    @Override
                    public synchronized int size() {
                        return Integer.MAX_VALUE;
                    }
                };
                dtd.getElement("element");
            } catch (Exception exception) {
                throw new Error("unexpected", exception);
            }
        }
    };
    // run task with different AppContext
    Thread thread = new Thread(new ThreadGroup("$$$"), task);
    thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread thread, Throwable throwable) {
            throwable.printStackTrace();
            System.exit(1);
        }
    });
    thread.start();
    thread.join();
    // add error handling
    HTMLDocument document = new HTMLDocument() {

        @Override
        public HTMLEditorKit.ParserCallback getReader(int pos) {
            return getReader(pos, 0, 0, null);
        }

        @Override
        public HTMLEditorKit.ParserCallback getReader(int pos, int popDepth, int pushDepth, HTML.Tag insertTag) {
            return new HTMLDocument.HTMLReader(pos, popDepth, pushDepth, insertTag) {

                @Override
                public void handleError(String error, int pos) {
                    throw new Error(error);
                }
            };
        }
    };
    // run parser
    new HTMLEditorKit().insertHTML(document, 0, "<html><body>text", 0, 0, null);
}
Also used : HTMLDocument(javax.swing.text.html.HTMLDocument) Element(javax.swing.text.html.parser.Element) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) DTD(javax.swing.text.html.parser.DTD)

Example 2 with Element

use of javax.swing.text.html.parser.Element in project jdk8u_jdk by JetBrains.

the class bug8074956 method main.

public static void main(String[] args) throws Exception {
    final DTD html32 = DTD.getDTD("html32");
    ContentModel contentModel = new ContentModel('&', new ContentModel());
    Element elem1 = html32.getElement("html-element");
    contentModel.first(elem1);
    Element elem2 = html32.getElement("test-element");
    // Shouldn't throw ArrayIndexOutOfBoundsException
    contentModel.first(elem2);
}
Also used : ContentModel(javax.swing.text.html.parser.ContentModel) DTD(javax.swing.text.html.parser.DTD) Element(javax.swing.text.html.parser.Element)

Aggregations

DTD (javax.swing.text.html.parser.DTD)2 Element (javax.swing.text.html.parser.Element)2 HTMLDocument (javax.swing.text.html.HTMLDocument)1 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)1 ContentModel (javax.swing.text.html.parser.ContentModel)1