Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9af78c671d14e2c9f432e43863f6f21902ed4b47 (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
/*******************************************************************************
 * Copyright (c) 2004, 2005 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.contentmodel.chtml;



import java.util.Arrays;

import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
import org.eclipse.wst.xml.core.internal.contentmodel.CMGroup;
import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;

/**
 * Complex type definition for the head content.
 * Content Model: (TITLE & ISINDEX? & BASE?)
 */
final class CtdHead extends ComplexTypeDefinition {

	/**
	 */
	public CtdHead(ElementCollection elementCollection) {
		super(elementCollection);
		primaryCandidateName = CHTMLNamespace.ElementName.TITLE;
	}

	/**
	 * for HEAD.
	 * To avoid using inclusion, the content model comes from the XHTML 1.0.
	 *
	 * (%head.misc;, ((title, %head.misc;, (base, %head.misc;)?) | (base, %head.misc;, (title, %head.misc;))))
	 * And %head.misc; is:
	 * (script|style|meta|link|object|isindex)*
	 *
	 * 0: (%head.misc, A)
	 * A: (B | C)
	 * B: (title, %head.misc;, D)
	 * C: (base, %head.misc;, E)
	 * D: (base, %head.misc;)?
	 * E: (title, %head.misc;)
	 */
	protected void createContent() {
		if (content != null)
			return; // already created.
		if (collection == null)
			return;

		// At 1st, create %head.misc; content.
		// %head.misc;
		//   ( | )*
		CMGroupImpl misc = new CMGroupImpl(CMGroup.CHOICE, 0, CMContentImpl.UNBOUNDED);
		if (misc == null)
			return;
		String[] names = {CHTMLNamespace.ElementName.META,};
		collection.getDeclarations(misc, Arrays.asList(names).iterator());
		// 2nd, get a title
		CMNode title = collection.getNamedItem(CHTMLNamespace.ElementName.TITLE);
		// 3rd, get a base
		CMNode base = collection.getNamedItem(CHTMLNamespace.ElementName.BASE);
		if (title == null || base == null)
			return;

		// Top level content is a sequence of %head.misc; and A.
		// 0: (%head.misc;, A)
		//   create a sequence
		content = new CMGroupImpl(CMGroup.SEQUENCE, 1, 1);
		if (content == null)
			return;
		//   append %head.misc;
		content.appendChild(misc);
		//   create A and append it to the top level.
		{
			// A is a choice of B and C.
			// A: (B | C)
			//   create a choice
			CMGroupImpl gA = new CMGroupImpl(CMGroup.CHOICE, 1, 1);
			if (gA == null)
				return;
			//   append A to the top level.
			content.appendChild(gA);

			// create B and append it to A
			{
				// B is a sequence of title, %head.misc;, and D.
				// B: (title, %head.misc;, D)
				//   create a sequence
				CMGroupImpl gB = new CMGroupImpl(CMGroup.SEQUENCE, 1, 1);
				if (gB == null)
					return;
				//   append B to A.
				gA.appendChild(gB);

				//   append title to B
				gB.appendChild(title);
				//   append %head.misc; to B
				gB.appendChild(misc);
				//   create D and append it to B.
				{
					// D is a sequence of base, %head.misc;.
					// D: (base, %head.misc;)?
					//   create a sequence
					CMGroupImpl gD = new CMGroupImpl(CMGroup.SEQUENCE, 0, 1);
					if (gD == null)
						return;
					//   append D to B.
					gB.appendChild(gD);

					//   append base to D
					gD.appendChild(base);
					//   append %head.misc; to D.
					gD.appendChild(misc);
				}
			}
			// create C and append it to A
			{
				// C is a sequence of base, %head.misc;, and E
				// C: (base, %head.misc;, E)
				//   create a sequence
				CMGroupImpl gC = new CMGroupImpl(CMGroup.SEQUENCE, 1, 1);
				if (gC == null)
					return;
				//   append C to A.
				gA.appendChild(gC);

				//   append base to C
				gC.appendChild(base);
				//   append %head.misc; to C
				gC.appendChild(misc);

				//   create E and append it to C.
				{
					// E is a sequence of title and %head.misc;.
					// E: (title, %head.misc;)
					//   create a sequence
					CMGroupImpl gE = new CMGroupImpl(CMGroup.SEQUENCE, 1, 1);
					if (gE == null)
						return;
					//   append E to C.
					gC.appendChild(gE);

					//   append title to E
					gE.appendChild(title);
					//   append %head.misc; to E.
					gE.appendChild(misc);
				}
			}
		}
	}

	/**
	 * Element content.<br>
	 */
	public int getContentType() {
		return CMElementDeclaration.ELEMENT;
	}

	/**
	 * Name of complex type definition.
	 * Each singleton must know its own name.
	 * All names should be defined in
	 * {@link <code>ComplexTypeDefinitionFactory</code>} as constants.<br>
	 * @return java.lang.String
	 */
	public String getTypeName() {
		return ComplexTypeDefinitionFactory.CTYPE_HEAD;
	}
}

Back to the top