Here you can find the source of getAncesters(Node node)
Parameter | Description |
---|---|
node | a parameter |
private static List getAncesters(Node node)
//package com.java2s; /******************************************************************************* * Copyright (c) 2006 Sybase, Inc. and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*ww w . j av a 2 s .co m*/ * Sybase, Inc. - initial API and implementation *******************************************************************************/ import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.w3c.dom.Document; import org.w3c.dom.Node; public class Main { /** * Get a list of ancester nodes starting from the Document till the node. * * @param node * @return */ private static List getAncesters(Node node) { List list = new ArrayList(); while (node != null) { list.add(node); if (node instanceof Document) { break; } node = node.getParentNode(); } if (node == null) { // if part ==null, means we didn't find a DocumentEditPart, // something must be wrong. return null; } // reverse to make it starting from the docuemnteditpart node. Collections.reverse(list); list.add(null); // add an null terminator. return list; } }