Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 4b930350cdeb9dd18906fde539c1d72b7770ecf3 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*******************************************************************************
 * Copyright (c) 2002, 2006 IBM 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:
 *     IBM Corporation - initial API and implementation
 *     Jens Lukowski/Innoopract - initial renaming/restructuring
 *     
 *******************************************************************************/
package org.eclipse.wst.xml.core.internal.contentmodel.annotation;

import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import com.ibm.icu.util.StringTokenizer;
import java.util.Vector;

import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
import org.eclipse.wst.xml.core.internal.contentmodel.internal.annotation.AnnotationFileInfo;
import org.eclipse.wst.xml.core.internal.contentmodel.internal.annotation.AnnotationFileParser;


/**
 * AnnotationMap
 */
public class AnnotationMap {
	protected List list = new Vector();
	protected Hashtable hashtable = new Hashtable();
	protected boolean isCaseSensitive = true;

	public AnnotationMap() {
	}

	public void setCaseSensitive(boolean isCaseSensitive) {
		this.isCaseSensitive = isCaseSensitive;
	}

	public void addAnnotation(Annotation annotation) {
		String spec = annotation.getSpec();
		if (spec != null) {
			list.add(annotation);
			StringTokenizer st = new StringTokenizer(spec, "[]|\t\n\r\f "); //$NON-NLS-1$
			while (st.hasMoreTokens()) {
				String cmNodeSpec = st.nextToken();
				addAnnotationForCMNodeSpec(cmNodeSpec, annotation);
			}
		}
	}

	protected void addAnnotationForCMNodeSpec(String cmNodeSpec, Annotation annotation) {
		String key = isCaseSensitive ? cmNodeSpec : cmNodeSpec.toLowerCase();
		List list = (List) hashtable.get(key);
		if (list == null) {
			list = new Vector();

			hashtable.put(key, list);
		}
		list.add(annotation);
	}

	public String getProperty(String cmNodeSpec, String propertyName) {
		String result = null;
		String key = isCaseSensitive ? cmNodeSpec : cmNodeSpec.toLowerCase();
		List annotationList = (List) hashtable.get(key);
		if (annotationList != null) {
			for (Iterator i = annotationList.iterator(); i.hasNext();) {
				Annotation annotation = (Annotation) i.next();
				result = annotation.getProperty(propertyName);
				if (result != null) {
					break;
				}
			}
		}
		return result;
	}

	public String getProperty(CMNode cmNode, String propertyName) {
		String result = null;
		String cmNodeSpec = (String) cmNode.getProperty("spec"); //$NON-NLS-1$
		if (cmNodeSpec == null) {
			cmNodeSpec = cmNode.getNodeName();
		}
		if (cmNodeSpec != null) {
			result = getProperty(cmNodeSpec, propertyName);
		}
		return result;
	}

	public List getAnnotations() {
		return list;
	}

	public void load(String uri, String bundleId) throws Exception {
		AnnotationFileParser parser = new AnnotationFileParser();
		AnnotationFileInfo fileInfo = new AnnotationFileInfo(uri, bundleId);
		parser.parse(this, fileInfo);
	}
}

Back to the top