Java 类javax.swing.text.ElementIterator 实例源码

项目:balloonist    文件:HypertextFrame.java   
public static boolean usesHtmlFrames(HTMLDocument doc)
{
    // TODO ensure that page has fully loaded, somehow. this is surprisingly hard to do statelessly

    ElementIterator walk = new ElementIterator(doc);
    Element item = null;

    while ((item = walk.next()) != null)
    {
        Object nameTag = item.getAttributes().getAttribute(StyleConstants.NameAttribute);

        // System.out.println("nameTag="+nameTag);

        if (HTML.Tag.FRAME==nameTag || HTML.Tag.FRAMESET==nameTag)
            return true;
    }

    return false;
}
项目:javify    文件:HTMLDocument.java   
/**
 * Finds the named frame inside this document.
 *
 * @param target the name to look for
 *
 * @return the frame if there is a matching frame, <code>null</code>
 *         otherwise
 */
private Element findFrame(String target)
{
  ElementIterator i = new ElementIterator(this);
  Element next = null;
  while ((next = i.next()) != null)
    {
      AttributeSet atts = next.getAttributes();
      if (atts.getAttribute(StyleConstants.NameAttribute) == HTML.Tag.FRAME)
        {
          String name = (String) atts.getAttribute(HTML.Attribute.NAME);
          if (name != null && name.equals(target))
            break;
        }
    }
  return next;
}
项目:javify    文件:FormView.java   
/**
 * Resets the form data to their initial state.
 */
private void resetForm()
{
  Element form = getFormElement();
  if (form != null)
    {
      ElementIterator iter = new ElementIterator(form);
      Element next;
      while ((next = iter.next()) != null)
        {
          if (next.isLeaf())
            {
              AttributeSet atts = next.getAttributes();
              Object m = atts.getAttribute(StyleConstants.ModelAttribute);
              if (m instanceof ResetableModel)
                ((ResetableModel) m).reset();
            }
        }
    }
}
项目:jvm-stm    文件:HTMLDocument.java   
/**
 * Finds the named frame inside this document.
 *
 * @param target the name to look for
 *
 * @return the frame if there is a matching frame, <code>null</code>
 *         otherwise
 */
private Element findFrame(String target)
{
  ElementIterator i = new ElementIterator(this);
  Element next = null;
  while ((next = i.next()) != null)
    {
      AttributeSet atts = next.getAttributes();
      if (atts.getAttribute(StyleConstants.NameAttribute) == HTML.Tag.FRAME)
        {
          String name = (String) atts.getAttribute(HTML.Attribute.NAME);
          if (name != null && name.equals(target))
            break;
        }
    }
  return next;
}
项目:jvm-stm    文件:FormView.java   
/**
 * Resets the form data to their initial state.
 */
private void resetForm()
{
  Element form = getFormElement();
  if (form != null)
    {
      ElementIterator iter = new ElementIterator(form);
      Element next;
      while ((next = iter.next()) != null)
        {
          if (next.isLeaf())
            {
              AttributeSet atts = next.getAttributes();
              Object m = atts.getAttribute(StyleConstants.ModelAttribute);
              if (m instanceof ResetableModel)
                ((ResetableModel) m).reset();
            }
        }
    }
}
项目:InuktitutComputing    文件:NRC_HTMLDocument.java   
public Object findWord(String word) {
    ElementIterator it = new ElementIterator(this);
    boolean trouve = false;
    javax.swing.text.Element element = null;
    javax.swing.text.Element elem = null;
    String texte;

    // Ensuite, chercher le mot s�lectionn� parmi les �l�ments
    // de texte.
    while (!trouve && (elem = it.next()) != null) {
        if (elem.getName().equals("content")) {
            int deb = elem.getStartOffset();
            int fin = elem.getEndOffset();
            try {
                texte = getText(deb, fin - deb);
            } catch (BadLocationException e) {
                texte = "";
            }
            if (texte.indexOf(word) != -1) {
                trouve = true;
                element = elem;
            }
        }
    }
    return element;
}
项目:paint    文件:HtmlDoc.java   
/**
 * Return the element with specified offset.
 * @param _offset   the offset.
 * @return          the element with specified offset.
 */
public final Element getCurrentElement(final int _offset) {
    ElementIterator ei = new ElementIterator(hl);
    Element elem, currentElem = null;
    int elemLength = Integer.MAX_VALUE;

    while ((elem = ei.next()) != null) { //looking for closest element
        int start = elem.getStartOffset(),
                end = elem.getEndOffset(), len = end - start;
        if (elem.isLeaf() 
                || elem.getName().equals("html")) {
            continue;
        }
        if (start <= _offset && _offset < end && len <= elemLength) {
            currentElem = elem;
            elemLength = len;
        }
    }

    return currentElem;
}
项目:JamVM-PH    文件:HTMLDocument.java   
/**
 * Finds the named frame inside this document.
 *
 * @param target the name to look for
 *
 * @return the frame if there is a matching frame, <code>null</code>
 *         otherwise
 */
private Element findFrame(String target)
{
  ElementIterator i = new ElementIterator(this);
  Element next = null;
  while ((next = i.next()) != null)
    {
      AttributeSet atts = next.getAttributes();
      if (atts.getAttribute(StyleConstants.NameAttribute) == HTML.Tag.FRAME)
        {
          String name = (String) atts.getAttribute(HTML.Attribute.NAME);
          if (name != null && name.equals(target))
            break;
        }
    }
  return next;
}
项目:JamVM-PH    文件:FormView.java   
/**
 * Resets the form data to their initial state.
 */
private void resetForm()
{
  Element form = getFormElement();
  if (form != null)
    {
      ElementIterator iter = new ElementIterator(form);
      Element next;
      while ((next = iter.next()) != null)
        {
          if (next.isLeaf())
            {
              AttributeSet atts = next.getAttributes();
              Object m = atts.getAttribute(StyleConstants.ModelAttribute);
              if (m instanceof ResetableModel)
                ((ResetableModel) m).reset();
            }
        }
    }
}
项目:classpath    文件:HTMLDocument.java   
public LeafIterator (HTML.Tag t, HTMLDocument d)
{
  doc = d;
  tag = t;
  it = new ElementIterator(doc);
}
项目:classpath    文件:HTMLDocument.java   
/**
 * Finds the named frame inside this document.
 *
 * @param target the name to look for
 *
 * @return the frame if there is a matching frame, <code>null</code>
 *         otherwise
 */
private Element findFrame(String target)
{
  ElementIterator i = new ElementIterator(this);
  Element next = null;
  while ((next = i.next()) != null)
    {
      AttributeSet atts = next.getAttributes();
      if (atts.getAttribute(StyleConstants.NameAttribute) == HTML.Tag.FRAME)
        {
          String name = (String) atts.getAttribute(HTML.Attribute.NAME);
          if (name != null && name.equals(target))
            break;
        }
    }
  return next;
}
项目:classpath    文件:FormView.java   
/**
 * Resets the form data to their initial state.
 */
private void resetForm()
{
  Element form = getFormElement();
  if (form != null)
    {
      ElementIterator iter = new ElementIterator(form);
      Element next;
      while ((next = iter.next()) != null)
        {
          if (next.isLeaf())
            {
              AttributeSet atts = next.getAttributes();
              Object m = atts.getAttribute(StyleConstants.ModelAttribute);
              if (m instanceof ResetableModel)
                ((ResetableModel) m).reset();
            }
        }
    }
}
项目:javify    文件:MinimalHTMLWriter.java   
/**
 * Writes the body of the HTML document.
 */
protected void writeBody() throws IOException, BadLocationException
{
  writeStartTag("<body>");

  ElementIterator ei = getElementIterator();
  Element e = ei.first();
  boolean inParagraph = false;
  do
    {
      if( e.isLeaf() )
        {
          boolean hasNL = (getText(e).indexOf(NEWLINE) != -1);
          if( !inParagraph && hasText( e ) )
            {
              writeStartParagraph(e);
              inParagraph = true;
            }

          if( hasText( e ) )
            writeContent(e, true);

          if( hasNL && inParagraph )
            {
              writeEndParagraph();
              inParagraph = false;
            }
          else
            endOpenTags();
        }
    }
  while((e = ei.next()) != null);

  writeEndTag("</body>");
}
项目:javify    文件:FormView.java   
/**
 * Determines the form data that is about to be submitted.
 *
 * @return the form data
 */
private String getFormData()
{
  Element form = getFormElement();
  StringBuilder b = new StringBuilder();
  if (form != null)
    {
      ElementIterator i = new ElementIterator(form);
      Element next;
      while ((next = i.next()) != null)
        {
          if (next.isLeaf())
            {
              AttributeSet atts = next.getAttributes();
              String type = (String) atts.getAttribute(HTML.Attribute.TYPE);
              if (type != null && type.equals("submit")
                  && next != getElement())
                {
                  // Skip this. This is not the actual submit trigger.
                }
              else if (type == null || ! type.equals("image"))
                {
                  getElementFormData(next, b);
                }
            }
        }
    }
  return b.toString();
}
项目:jvm-stm    文件:MinimalHTMLWriter.java   
/**
  * Writes the body of the HTML document.
  */ 
 protected void writeBody() throws IOException, BadLocationException
 {
   writeStartTag("<body>");

   ElementIterator ei = getElementIterator();
   Element e = ei.first();
   boolean inParagraph = false;
   do
     {
if( e.isLeaf() )
  {
    boolean hasNL = (getText(e).indexOf(NEWLINE) != -1);
    if( !inParagraph && hasText( e ) )
      {
    writeStartParagraph(e);
    inParagraph = true;
      }

    if( hasText( e ) )
      writeContent(e, true);

    if( hasNL && inParagraph )
      {
    writeEndParagraph();
    inParagraph = false;
      }
    else
      endOpenTags();
  }
     } 
   while((e = ei.next()) != null);

   writeEndTag("</body>");
 }
项目:jvm-stm    文件:FormView.java   
/**
 * Determines the form data that is about to be submitted.
 *
 * @return the form data
 */
private String getFormData()
{
  Element form = getFormElement();
  StringBuilder b = new StringBuilder();
  if (form != null)
    {
      ElementIterator i = new ElementIterator(form);
      Element next;
      while ((next = i.next()) != null)
        {
          if (next.isLeaf())
            {
              AttributeSet atts = next.getAttributes();
              String type = (String) atts.getAttribute(HTML.Attribute.TYPE);
              if (type != null && type.equals("submit")
                  && next != getElement())
                {
                  // Skip this. This is not the actual submit trigger.
                }
              else if (type == null || ! type.equals("image"))
                {
                  getElementFormData(next, b);
                }
            }
        }
    }
  return b.toString();
}
项目:InuktitutComputing    文件:NRC_HTMLDocument.java   
public String[] getWords() {
    Vector words = new Vector();
    ElementIterator iterator = new ElementIterator(this);
    javax.swing.text.Element elem;
    Pattern p = Pattern.compile("([a-z&]+)");
    while ((elem = iterator.next()) != null) {
        if (elem.getName().equals("content")) {
            NRC_HTMLDocument.TexteHTML texteHTML = texteEnInuktitut(elem);
            if (texteHTML != null) {
                texteHTML.transliterer();
                Vector morceaux = texteHTML.getMorphParts();
                String s = "";
                for (int i = 0; i < morceaux.size(); i++)
                    s = s
                            + ((Inuktitut.MorceauTexte) morceaux.get(i))
                                    .getTexte();
                Matcher m = p.matcher(s);
                while (m.find()) {
                    String word = m.group();
                    if (!words.contains(word))
                        words.add(word);
                }
            }
        }
    }
    String[] wordsArray = (String[]) words.toArray(new String[] {});
    Arrays.sort(wordsArray);
    return wordsArray;
}
项目:cn1    文件:HTMLDocument.java   
public Element getElement(final Element e, final Object attribute,
                          final Object value) {
    final ElementIterator it = new ElementIterator(e);
    while (it.next() != null) {
        final Element current = it.current();
        if (current.getAttributes().containsAttribute(attribute, value)) {
            return current;
        }
    }
    return null;
}
项目:JamVM-PH    文件:MinimalHTMLWriter.java   
/**
  * Writes the body of the HTML document.
  */ 
 protected void writeBody() throws IOException, BadLocationException
 {
   writeStartTag("<body>");

   ElementIterator ei = getElementIterator();
   Element e = ei.first();
   boolean inParagraph = false;
   do
     {
if( e.isLeaf() )
  {
    boolean hasNL = (getText(e).indexOf(NEWLINE) != -1);
    if( !inParagraph && hasText( e ) )
      {
    writeStartParagraph(e);
    inParagraph = true;
      }

    if( hasText( e ) )
      writeContent(e, true);

    if( hasNL && inParagraph )
      {
    writeEndParagraph();
    inParagraph = false;
      }
    else
      endOpenTags();
  }
     } 
   while((e = ei.next()) != null);

   writeEndTag("</body>");
 }
项目:JamVM-PH    文件:FormView.java   
/**
 * Determines the form data that is about to be submitted.
 *
 * @return the form data
 */
private String getFormData()
{
  Element form = getFormElement();
  StringBuilder b = new StringBuilder();
  if (form != null)
    {
      ElementIterator i = new ElementIterator(form);
      Element next;
      while ((next = i.next()) != null)
        {
          if (next.isLeaf())
            {
              AttributeSet atts = next.getAttributes();
              String type = (String) atts.getAttribute(HTML.Attribute.TYPE);
              if (type != null && type.equals("submit")
                  && next != getElement())
                {
                  // Skip this. This is not the actual submit trigger.
                }
              else if (type == null || ! type.equals("image"))
                {
                  getElementFormData(next, b);
                }
            }
        }
    }
  return b.toString();
}
项目:classpath    文件:MinimalHTMLWriter.java   
/**
 * Writes the body of the HTML document.
 */
protected void writeBody() throws IOException, BadLocationException
{
  writeStartTag("<body>");

  ElementIterator ei = getElementIterator();
  Element e = ei.first();
  boolean inParagraph = false;
  do
    {
      if( e.isLeaf() )
        {
          boolean hasNL = (getText(e).indexOf(NEWLINE) != -1);
          if( !inParagraph && hasText( e ) )
            {
              writeStartParagraph(e);
              inParagraph = true;
            }

          if( hasText( e ) )
            writeContent(e, true);

          if( hasNL && inParagraph )
            {
              writeEndParagraph();
              inParagraph = false;
            }
          else
            endOpenTags();
        }
    }
  while((e = ei.next()) != null);

  writeEndTag("</body>");
}
项目:classpath    文件:FormView.java   
/**
 * Determines the form data that is about to be submitted.
 *
 * @return the form data
 */
private String getFormData()
{
  Element form = getFormElement();
  StringBuilder b = new StringBuilder();
  if (form != null)
    {
      ElementIterator i = new ElementIterator(form);
      Element next;
      while ((next = i.next()) != null)
        {
          if (next.isLeaf())
            {
              AttributeSet atts = next.getAttributes();
              String type = (String) atts.getAttribute(HTML.Attribute.TYPE);
              if (type != null && type.equals("submit")
                  && next != getElement())
                {
                  // Skip this. This is not the actual submit trigger.
                }
              else if (type == null || ! type.equals("image"))
                {
                  getElementFormData(next, b);
                }
            }
        }
    }
  return b.toString();
}
项目:freeVM    文件:HTMLDocument.java   
public Element getElement(final Element e, final Object attribute,
                          final Object value) {
    final ElementIterator it = new ElementIterator(e);
    while (it.next() != null) {
        final Element current = it.current();
        if (current.getAttributes().containsAttribute(attribute, value)) {
            return current;
        }
    }
    return null;
}
项目:freeVM    文件:HTMLDocument.java   
public Element getElement(final Element e, final Object attribute,
                          final Object value) {
    final ElementIterator it = new ElementIterator(e);
    while (it.next() != null) {
        final Element current = it.current();
        if (current.getAttributes().containsAttribute(attribute, value)) {
            return current;
        }
    }
    return null;
}
项目:javify    文件:HTMLDocument.java   
public LeafIterator (HTML.Tag t, HTMLDocument d)
{
  doc = d;
  tag = t;
  it = new ElementIterator(doc);
}
项目:jvm-stm    文件:HTMLDocument.java   
public LeafIterator (HTML.Tag t, HTMLDocument d)
{
  doc = d;
  tag = t;
  it = new ElementIterator(doc);
}
项目:cn1    文件:HTMLWriter.java   
public void write() throws IOException, BadLocationException {
    if (elemsStack == null) {
        elemsStack = new Stack();
    }
    ElementIterator it = getElementIterator();

    Element e;
    while ((e = it.next()) != null) {
        if (!elemsStack.isEmpty()) {
            while (!elemsStack.isEmpty()
                    && elemsStack.peek() != e.getParentElement()) {
                if (!synthesizedElement((Element)elemsStack.peek())) {
                    decrIndent();
                }
                if (!preformatted && getCurrentLineLength() != 0) {
                    writeLineSeparator();
                }
                endTag((Element)elemsStack.pop());
            }
        }

        if (isEmptyTag(getHTMLTag(e.getAttributes()))) {
            emptyTag(e);
        } else if (matchNameAttribute(e.getAttributes(), HTML.Tag.TITLE)) {
            continue;
        } else {
            if (getCurrentLineLength() != 0 && getCanWrapLines()) {
                writeLineSeparator();
            }
            startTag(e);
            elemsStack.push(e);
            if (!synthesizedElement(e)) {
                incrIndent();
            }
            indentEmptyTag = !preformatted;
            if (matchNameAttribute(e.getAttributes(), HTML.Tag.HEAD)) {
                writeDocumentProperties();
            }
        }
    }

    while (!elemsStack.isEmpty()) {
        if (!synthesizedElement((Element)elemsStack.peek())) {
            decrIndent();
        }
        if (!preformatted && getCurrentLineLength() != 0) {
            writeLineSeparator();
        }
        endTag((Element)elemsStack.pop());
    }

    writeAdditionalComment();
}
项目:cn1    文件:TagIterator.java   
public TagIterator(final Tag tag, final Document document) {
    this.tag = tag;
    it = new ElementIterator(document);
    next();
}
项目:JamVM-PH    文件:HTMLDocument.java   
public LeafIterator (HTML.Tag t, HTMLDocument d)
{
  doc = d;
  tag = t;
  it = new ElementIterator(doc);
}
项目:freeVM    文件:HTMLWriter.java   
public void write() throws IOException, BadLocationException {
    if (elemsStack == null) {
        elemsStack = new Stack();
    }
    ElementIterator it = getElementIterator();

    Element e;
    while ((e = it.next()) != null) {
        if (!elemsStack.isEmpty()) {
            while (!elemsStack.isEmpty()
                    && elemsStack.peek() != e.getParentElement()) {
                if (!synthesizedElement((Element)elemsStack.peek())) {
                    decrIndent();
                }
                if (!preformatted && getCurrentLineLength() != 0) {
                    writeLineSeparator();
                }
                endTag((Element)elemsStack.pop());
            }
        }

        if (isEmptyTag(getHTMLTag(e.getAttributes()))) {
            emptyTag(e);
        } else if (matchNameAttribute(e.getAttributes(), HTML.Tag.TITLE)) {
            continue;
        } else {
            if (getCurrentLineLength() != 0 && getCanWrapLines()) {
                writeLineSeparator();
            }
            startTag(e);
            elemsStack.push(e);
            if (!synthesizedElement(e)) {
                incrIndent();
            }
            indentEmptyTag = !preformatted;
            if (matchNameAttribute(e.getAttributes(), HTML.Tag.HEAD)) {
                writeDocumentProperties();
            }
        }
    }

    while (!elemsStack.isEmpty()) {
        if (!synthesizedElement((Element)elemsStack.peek())) {
            decrIndent();
        }
        if (!preformatted && getCurrentLineLength() != 0) {
            writeLineSeparator();
        }
        endTag((Element)elemsStack.pop());
    }

    writeAdditionalComment();
}
项目:freeVM    文件:TagIterator.java   
public TagIterator(final Tag tag, final Document document) {
    this.tag = tag;
    it = new ElementIterator(document);
    next();
}
项目:freeVM    文件:HTMLWriter.java   
public void write() throws IOException, BadLocationException {
    if (elemsStack == null) {
        elemsStack = new Stack();
    }
    ElementIterator it = getElementIterator();

    Element e;
    while ((e = it.next()) != null) {
        if (!elemsStack.isEmpty()) {
            while (!elemsStack.isEmpty()
                    && elemsStack.peek() != e.getParentElement()) {
                if (!synthesizedElement((Element)elemsStack.peek())) {
                    decrIndent();
                }
                if (!preformatted && getCurrentLineLength() != 0) {
                    writeLineSeparator();
                }
                endTag((Element)elemsStack.pop());
            }
        }

        if (isEmptyTag(getHTMLTag(e.getAttributes()))) {
            emptyTag(e);
        } else if (matchNameAttribute(e.getAttributes(), HTML.Tag.TITLE)) {
            continue;
        } else {
            if (getCurrentLineLength() != 0 && getCanWrapLines()) {
                writeLineSeparator();
            }
            startTag(e);
            elemsStack.push(e);
            if (!synthesizedElement(e)) {
                incrIndent();
            }
            indentEmptyTag = !preformatted;
            if (matchNameAttribute(e.getAttributes(), HTML.Tag.HEAD)) {
                writeDocumentProperties();
            }
        }
    }

    while (!elemsStack.isEmpty()) {
        if (!synthesizedElement((Element)elemsStack.peek())) {
            decrIndent();
        }
        if (!preformatted && getCurrentLineLength() != 0) {
            writeLineSeparator();
        }
        endTag((Element)elemsStack.pop());
    }

    writeAdditionalComment();
}
项目:freeVM    文件:TagIterator.java   
public TagIterator(final Tag tag, final Document document) {
    this.tag = tag;
    it = new ElementIterator(document);
    next();
}