Java Swing HTML findLinkElementUp(Element elem)

Here you can find the source of findLinkElementUp(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 Element findLinkElementUp(Element elem) 

Method Source Code

//package com.java2s;
/*/* w  w w. j ava  2s.  co m*/
 * This file is part of the Scriba source distribution. This is free, open-source 
 * software. For full licensing information, please see the LicensingInformation file
 * at the root level of the distribution.
 *
 * Copyright (c) 2006-2007 Kobrix Software, Inc.
 */

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 Element findLinkElementUp(Element elem) {
        Element e = null;
        Object linkAttr = null;
        Object href = null;
        while ((elem != null) && (linkAttr == null)) {
            e = elem;
            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 e;
        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. findLinkUp(Element elem)
  6. getHTMLFromXML(String xml, URL xsl)
  7. getImgs(final String html)
  8. getRowIndex(final Element cell)