Java Swing HTML findElementUp(final String name1, final String name2, final Element start)

Here you can find the source of findElementUp(final String name1, final String name2, final Element start)

Description

find the first occurrence of an Element in the element tree above a given Element

License

Open Source License

Parameter

Parameter Description
name1 the primary name of the <code>Element</code> to search for
name2 an alternative name for the <code>Element</code> to search for
start the <code>Element</code> to start looking

Return

the found Element or null if none is found

Declaration

public static Element findElementUp(final String name1, final String name2, final Element start) 

Method Source Code

//package com.java2s;
/*/*from w  ww.j ava  2 s .  c om*/
 * 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.Element;

public class Main {
    /**
     * find the first occurrence of an <code>Element</code> in the
     * element tree above a given <code>Element</code>
     *
     * @param name the name of the <code>Element</code> to search for
     * @param start the <code>Element</code> to start looking
     *
     * @return the found <code>Element</code> or null if none is found
     */
    public static Element findElementUp(final String name, final Element start) {
        Element elem = start;
        while (elem != null && !elem.getName().equalsIgnoreCase(name)) {
            elem = elem.getParentElement();
        }
        return elem;
    }

    /**
     * find the first occurrence of an <code>Element</code> in the
     * element tree above a given <code>Element</code>
     *
     * @param name1 the primary name of the <code>Element</code> to search for
     * @param name2 an alternative name for the <code>Element</code> to search for
     * @param start the <code>Element</code> to start looking
     *
     * @return the found <code>Element</code> or null if none is found
     */
    public static Element findElementUp(final String name1, final String name2, final Element start) {
        Element elem = start;
        while (elem != null
                && !(elem.getName().equalsIgnoreCase(name1) || elem.getName().equalsIgnoreCase(name2))) {
            elem = elem.getParentElement();
        }
        return elem;
    }
}

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. findLinkElementUp(Element elem)
  5. findLinkUp(Element elem)
  6. getHTMLFromXML(String xml, URL xsl)
  7. getImgs(final String html)