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: c71b4e050fb5ccfbe0339633c12159b147958a26 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*******************************************************************************
 * Copyright (c) 2004 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
 *******************************************************************************/
package org.eclipse.wst.html.core.internal.modelquery;


import org.eclipse.wst.html.core.internal.contentmodel.HTMLCMDocumentFactory;
import org.eclipse.wst.html.core.internal.provisional.HTMLCMProperties;
import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
import org.eclipse.wst.xml.core.internal.contentmodel.CMContent;
import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType;
import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap;
import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
import org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMDocType;

/**
 */
class CMElementDeclarationBuddySystem extends CMNodeBuddySystem implements CMElementDeclaration {


	private static CMDocument htmlcm = HTMLCMDocumentFactory.getCMDocument(CMDocType.HTML_DOC_TYPE);

	private static CMElementDeclaration getHTMLCMElemDecl(CMElementDeclaration original) {
		CMElementDeclaration buddy = null;
		if (htmlcm != null) {
			CMNamedNodeMap elems = htmlcm.getElements();
			if (elems != null) {
				buddy = (CMElementDeclaration) elems.getNamedItem(original.getElementName());
			}
		}
		return buddy;
	}

	private class Attrs extends CMNamedNodeMapForBuddySystem {
		private CMNamedNodeMap buddyAttrs = null;

		public Attrs(CMNamedNodeMap attrs, CMNamedNodeMap buddyAttrs, boolean isXHTML) {
			super(isXHTML);
			this.buddyAttrs = buddyAttrs;
			makeBuddySystem(attrs);
		}

		protected String getKeyName(CMNode original) {
			CMAttributeDeclaration adecl = getDecl(original);
			if (adecl == null)
				return null;
			return adecl.getAttrName();
		}

		protected CMNode createBuddySystem(CMNode original) {
			CMAttributeDeclaration adecl = getDecl(original);
			if (adecl == null)
				return null;
			CMAttributeDeclaration buddy = null;
			if (buddyAttrs != null) {
				buddy = (CMAttributeDeclaration) buddyAttrs.getNamedItem(adecl.getAttrName());
			}
			return new CMAttributeDeclarationBuddySystem(adecl, buddy, isXHTML());
		}

		private CMAttributeDeclaration getDecl(CMNode cmnode) {
			if (cmnode == null)
				return null;
			if (cmnode.getNodeType() != CMNode.ATTRIBUTE_DECLARATION)
				return null;
			return (CMAttributeDeclaration) cmnode;
		}
	}

	private Attrs attributes = null;

	public CMElementDeclarationBuddySystem(CMElementDeclaration self, boolean isXHTML) {
		super(self, getHTMLCMElemDecl(self), isXHTML);
	}

	/*
	 * @see CMElementDeclaration#getAttributes()
	 */
	public CMNamedNodeMap getAttributes() {
		if (attributes != null)
			return attributes;
		CMElementDeclaration edecl = getSelf();
		if (edecl == null)
			return null;
		CMElementDeclaration htmlDecl = getBuddy();
		CMNamedNodeMap htmlAttrs = (htmlDecl == null) ? null : htmlDecl.getAttributes();
		attributes = new Attrs(edecl.getAttributes(), htmlAttrs, isXHTML);
		return attributes;
	}

	/*
	 * @see CMElementDeclaration#getContent()
	 */
	public CMContent getContent() {
		CMElementDeclaration edecl = getSelf();
		if (edecl == null)
			return null;
		return edecl.getContent();
	}

	/*
	 * @see CMElementDeclaration#getContentType()
	 */
	public int getContentType() {
		CMElementDeclaration edecl = getSelf();
		if (edecl == null)
			return CMElementDeclaration.ANY;
		return edecl.getContentType();
	}

	/*
	 * @see CMElementDeclaration#getElementName()
	 */
	public String getElementName() {
		CMElementDeclaration edecl = getSelf();
		if (edecl == null)
			return null;
		return edecl.getElementName();
	}

	/*
	 * @see CMElementDeclaration#getDataType()
	 */
	public CMDataType getDataType() {
		CMElementDeclaration edecl = getSelf();
		if (edecl == null)
			return null;
		return edecl.getDataType();
	}

	/*
	 * @see CMElementDeclaration#getLocalElements()
	 */
	public CMNamedNodeMap getLocalElements() {
		CMElementDeclaration edecl = getSelf();
		if (edecl == null)
			return null;
		return edecl.getLocalElements();
	}

	/*
	 * @see CMContent#getMaxOccur()
	 */
	public int getMaxOccur() {
		CMElementDeclaration edecl = getSelf();
		if (edecl == null)
			return -1;
		return edecl.getMaxOccur();
	}

	/*
	 * @see CMContent#getMinOccur()
	 */
	public int getMinOccur() {
		CMElementDeclaration edecl = getSelf();
		if (edecl == null)
			return -1;
		return edecl.getMinOccur();
	}

	/*
	 * @see CMNode#supports(String)
	 */
	public boolean supports(String propertyName) {
		if (isXHTML && propertyName.equals(HTMLCMProperties.OMIT_TYPE))
			return true;
		return super.supports(propertyName);
	}

	/*
	 * @see CMNode#getProperty(String)
	 */
	public Object getProperty(String propertyName) {
		if (isXHTML && propertyName.equals(HTMLCMProperties.OMIT_TYPE))
			return HTMLCMProperties.Values.OMIT_NONE;
		return super.getProperty(propertyName);
	}

	private CMElementDeclaration getSelf() {
		if (self.getNodeType() != CMNode.ELEMENT_DECLARATION)
			return null;
		return (CMElementDeclaration) self;
	}

	private CMElementDeclaration getBuddy() {
		if (buddy == null)
			return null;
		if (buddy.getNodeType() != CMNode.ELEMENT_DECLARATION)
			return null;
		return (CMElementDeclaration) buddy;
	}
}

Back to the top