Skip to main content
summaryrefslogtreecommitdiffstats
blob: 97991e448c90710abd31a172d23a168b81cad675 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
 * Copyright (c) 2008 Oracle Corporation 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:
 *    Oracle Corporation - initial API and implementation
 */
package org.eclipse.jst.jsf.apache.trinidad.tagsupport;

import org.w3c.dom.Node;

/**
 * Utility class for the Trinidad Tag Support plug-in.
 *
 * @author Ian Trimble - Oracle
 */
public class TrinidadUtils {

	private static final String KEY_CURRENT_CHILD_INDEX =
		"KEY_CURRENT_CHILD_INDEX"; //$NON-NLS-1$

	/**
	 * Sets the index of the Node instance's "current" child as user data on
	 * the Node instance.
	 * 
	 * @param node Node instance on which to set index.
	 * @param index Index of node's "current" child.
	 * @return true if index has changed, else false.
	 */
	public static boolean setCurrentChildIndex(Node node, int index) {
		boolean indexChanged = false;
		if (node != null) {
			int currentIndex = getCurrentChildIndex(node);
			if (currentIndex != index) {
				node.setUserData(
						KEY_CURRENT_CHILD_INDEX,
						new Integer(index),
						null);
				indexChanged = true;
			}
		}
		return indexChanged;
	}

	/**
	 * Gets the index of the Node instance's "current" child from user data on
	 * the Node instance.
	 * 
	 * @param node Node instance from which to get index.
	 * @return Index of node's "current" child. A value of -1 indicates
	 * inability to get index from node.
	 */
	public static int getCurrentChildIndex(Node node) {
		int index = -1;
		if (node != null) {
			Object obj = node.getUserData(KEY_CURRENT_CHILD_INDEX);
			if (obj instanceof Integer) {
				index = ((Integer)obj).intValue();
			}
		}
		return index;
	}

}

Back to the top