Skip to main content
summaryrefslogtreecommitdiffstats
blob: 190d9a31b66fc3cc13ef59d3b534b7877222a420 (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
/*******************************************************************************
 * 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:
 *     Sybase, Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.pagedesigner.css2.marker;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * @author mengbo
 */
public abstract class EnumerableCounter implements ICounter {
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jst.pagedesigner.css2.list.ICounter#getNextObject(org.w3c.dom.Element,
	 *      java.lang.String)
	 */
	public Object getNextObject(Element element, int type) {
		int index = calculateIndex(element);
		return getNextString(index, type);
	}

	public int calculateIndex(Element element) {
		String tag = element.getLocalName();
		Node parent = element.getParentNode();
		NodeList children = parent.getChildNodes();
		int index = 1;
		for (int i = 0; i < children.getLength(); i++) {
			Node child = children.item(i);
			if (child == element) {
				break;
			}
			if (child.getLocalName().equalsIgnoreCase(tag)) {
				index++;
			}
		}
		return index;
	}

	public abstract String getNextString(int index, int type);
}

Back to the top