Java Swing HTML findLinkUp(Element elem)

Here you can find the source of findLinkUp(Element elem)

Description

find the next link attribute from a given element upwards through the element hierarchy

License

Open Source License

Parameter

Parameter Description
elem the element to start looking at

Return

the link attribute found, or null, if none was found

Declaration

public static Object findLinkUp(Element elem) 

Method Source Code

//package com.java2s;
/*//ww  w .  j a v  a 2  s  .  c o  m
 * SimplyHTML, a word processor based on Java, HTML and CSS
 * Copyright (C) 2002 Ulrich Hilger
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

import javax.swing.text.AttributeSet;
import javax.swing.text.Element;

import javax.swing.text.html.HTML;

public class Main {
    /**
     * find the next link attribute from a given element upwards
     * through the element hierarchy
     *
     * @param elem  the element to start looking at
     *
     * @return the link attribute found, or null, if none was found
     */
    public static Object findLinkUp(Element elem) {
        //Element elem = ((SHTMLDocument) doc).getCharacterElement(selStart);
        Object linkAttr = null; //elem.getAttributes().getAttribute(HTML.Tag.A);
        Object href = null;
        while ((elem != null) && (linkAttr == null)) {
            linkAttr = elem.getAttributes().getAttribute(HTML.Tag.A);
            if (linkAttr != null) {
                href = ((AttributeSet) linkAttr).getAttribute(HTML.Attribute.HREF);
            }
            elem = elem.getParentElement();
        }
        if (linkAttr != null && href != null) {
            return linkAttr;
        } else {
            return null;
        }
    }
}

Related

  1. addToContentModels(DTD dtd, Element existing, Element alt)
  2. containsAttribute(Element element, Object name, Object value)
  3. findElementDown(final String name, final Element parent)
  4. findElementUp(final String name1, final String name2, final Element start)
  5. findLinkElementUp(Element elem)
  6. getHTMLFromXML(String xml, URL xsl)
  7. getImgs(final String html)
  8. getRowIndex(final Element cell)
  9. hasClass(AttributeSet attr, String className)