Here you can find the source of findLinkUp(Element elem)
Parameter | Description |
---|---|
elem | the element to start looking at |
public static Object findLinkUp(Element elem)
//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; } } }