blob: 3ea87e67e431334d037a8b5de00aa65229de43c7 (
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
/*
* Copyright (c) 2002 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - 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 java.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.*;
/**
* 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) throws Exception
{
AnnotationFileParser parser = new AnnotationFileParser();
parser.parse(this, uri);
}
}
|