Example usage for javax.swing.text ElementIterator next

List of usage examples for javax.swing.text ElementIterator next

Introduction

In this page you can find the example usage for javax.swing.text ElementIterator next.

Prototype

public Element next() 

Source Link

Document

Fetches the next Element .

Usage

From source file:forge.screens.deckeditor.DeckImport.java

private void readInput() {
    this.tokens.clear();
    final ElementIterator it = new ElementIterator(this.txtInput.getDocument().getDefaultRootElement());
    Element e;//  w  w w.j a  v  a2  s  .com

    DeckRecognizer recognizer = new DeckRecognizer(newEditionCheck.isSelected(), onlyCoreExpCheck.isSelected(),
            FModel.getMagicDb().getCommonCards());
    if (dateTimeCheck.isSelected()) {
        recognizer.setDateConstraint(monthDropdown.getSelectedIndex(),
                (Integer) yearDropdown.getSelectedItem());
    }
    while ((e = it.next()) != null) {
        if (!e.isLeaf()) {
            continue;
        }
        final int rangeStart = e.getStartOffset();
        final int rangeEnd = e.getEndOffset();
        try {
            final String line = this.txtInput.getText(rangeStart, rangeEnd - rangeStart);
            this.tokens.add(recognizer.recognizeLine(line));
        } catch (final BadLocationException ex) {
        }
    }
}

From source file:com.hexidec.ekit.EkitCore.java

public void removeEmptyLists() {
    javax.swing.text.ElementIterator ei = new javax.swing.text.ElementIterator(htmlDoc);
    Element ele;//from  w  ww.  ja  va 2s. co  m
    while ((ele = ei.next()) != null) {
        if (ele.getName().equals("ul") || ele.getName().equals("ol")) {
            int listChildren = 0;
            for (int i = 0; i < ele.getElementCount(); i++) {
                if (ele.getElement(i).getName().equals("li")) {
                    listChildren++;
                }
            }
            if (listChildren <= 0) {
                htmlUtilities.removeTag(ele, true);
            }
        }
    }
    refreshOnUpdate();
}

From source file:org.deegree.tools.metadata.InspireValidator.java

/**
 * parse INSPIRE metadata validator response and print out result onto the console
 * //from  w  ww  .j  av  a 2  s.co m
 * @param response
 * @throws IOException
 * @throws IllegalStateException
 */
private void parseServiceResponse(HttpResponse response) throws Exception {
    String s = FileUtils.readTextFile(((BasicHttpResponse) response).getEntity().getContent()).toString();
    if (response.getStatusLine().getStatusCode() != 200) {
        outputWriter.println(s);
        outputWriter.println();
        return;
    }
    s = "<html><head></head><body>" + s + "</body></html>";
    BufferedReader br = new BufferedReader(new StringReader(s));

    HTMLEditorKit htmlKit = new HTMLEditorKit();
    HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();
    HTMLEditorKit.Parser parser = new ParserDelegator();
    HTMLEditorKit.ParserCallback callback = htmlDoc.getReader(0);
    parser.parse(br, callback, true);

    // Parse
    ElementIterator iterator = new ElementIterator(htmlDoc);
    Element element;
    while ((element = iterator.next()) != null) {
        AttributeSet attributes = element.getAttributes();
        Object name = attributes.getAttribute(StyleConstants.NameAttribute);
        if ((name instanceof HTML.Tag) && ((name == HTML.Tag.IMPLIED))) {
            // Build up content text as it may be within multiple elements
            StringBuffer text = new StringBuffer();
            int count = element.getElementCount();
            for (int i = 0; i < count; i++) {
                Element child = element.getElement(i);
                AttributeSet childAttributes = child.getAttributes();
                if (childAttributes.getAttribute(StyleConstants.NameAttribute) == HTML.Tag.CONTENT) {
                    int startOffset = child.getStartOffset();
                    int endOffset = child.getEndOffset();
                    int length = endOffset - startOffset;
                    text.append(htmlDoc.getText(startOffset, length));
                }
            }
            outputWriter.println(text.toString());
        }
    }
    outputWriter.println("---------------------------------------------------------------------");
    outputWriter.println();
}