blob: 7fd73d51524714c2080df35905b85fc624d2b597 [file] [log] [blame]
nitind958d79a2004-11-23 19:23:00 +00001/*******************************************************************************
amywu923ee602007-04-10 18:32:07 +00002 * Copyright (c) 2004, 2005 IBM Corporation and others.
nitind958d79a2004-11-23 19:23:00 +00003 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
amywu923ee602007-04-10 18:32:07 +00007 *
nitind958d79a2004-11-23 19:23:00 +00008 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
david_williams56777022005-04-11 06:21:55 +000011package org.eclipse.wst.html.core.internal.contentmodel;
nitind958d79a2004-11-23 19:23:00 +000012
13
14
david_williams4ad020f2005-04-18 08:00:30 +000015import org.eclipse.wst.html.core.internal.provisional.HTML40Namespace;
david_williamsc06c86f2005-03-18 18:23:41 +000016import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
17import org.eclipse.wst.xml.core.internal.contentmodel.CMGroup;
18import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
nitind958d79a2004-11-23 19:23:00 +000019
20/**
21 * for TABLE.
pavery1ffa69f2005-05-27 18:11:23 +000022 * (CAPTION?, (COL*|COLGROUP*), THEAD?, TFOOT?, TBODY+, TR+)
nitind958d79a2004-11-23 19:23:00 +000023 */
24final class CtdTable extends ComplexTypeDefinition {
25
26 /**
27 * @param elementCollection ElementCollection
28 */
29 public CtdTable(ElementCollection elementCollection) {
30 super(elementCollection);
31 primaryCandidateName = HTML40Namespace.ElementName.TBODY;
32 }
33
34 /**
35 * (CAPTION?, (COL*|COLGROUP*), THEAD?, TFOOT?, TBODY+)
pavery1ffa69f2005-05-27 18:11:23 +000036 * --> ((CAPTION)?, ((COL)* | (COLGROUP)*), (THEAD)?, (TFOOT)?, (TBODY)+, (TR)+)
nitind958d79a2004-11-23 19:23:00 +000037 */
38 protected void createContent() {
39 if (content != null)
40 return; // already created.
41 if (collection == null)
42 return;
43
44 // ( , , , ,)
45 content = new CMGroupImpl(CMGroup.SEQUENCE, 1, 1);
46
47 // (CAPTION)?
48 // ( )?
49 CMGroupImpl wrap = new CMGroupImpl(CMGroup.SEQUENCE, 0, 1);
50 if (wrap == null)
51 return;
52 content.appendChild(wrap);
53 // CAPTION
54 CMNode dec = collection.getNamedItem(HTML40Namespace.ElementName.CAPTION);
55 if (dec != null)
56 wrap.appendChild(dec);
57
58 // ((COL)* | (COLGROUP)*)
59 // ( | )
60 CMGroupImpl group = new CMGroupImpl(CMGroup.CHOICE, 1, 1);
61 if (group == null)
62 return;
63 content.appendChild(group);
64 // (COL)*
65 wrap = new CMGroupImpl(CMGroup.SEQUENCE, 0, CMContentImpl.UNBOUNDED);
66 if (wrap == null)
67 return;
68 group.appendChild(wrap);
69 dec = collection.getNamedItem(HTML40Namespace.ElementName.COL);
70 if (dec != null)
71 wrap.appendChild(dec);
72 // (COLGROUP)*
73 wrap = new CMGroupImpl(CMGroup.SEQUENCE, 0, CMContentImpl.UNBOUNDED);
74 if (wrap == null)
75 return;
76 group.appendChild(wrap);
77 dec = collection.getNamedItem(HTML40Namespace.ElementName.COLGROUP);
78 if (dec != null)
79 wrap.appendChild(dec);
80
81 // (THEAD)?
82 wrap = new CMGroupImpl(CMGroup.SEQUENCE, 0, 1);
83 if (wrap == null)
84 return;
85 content.appendChild(wrap);
86 dec = collection.getNamedItem(HTML40Namespace.ElementName.THEAD);
87 if (dec != null)
88 wrap.appendChild(dec);
89
90 // (TFOOT)?
91 wrap = new CMGroupImpl(CMGroup.SEQUENCE, 0, 1);
92 if (wrap == null)
93 return;
94 content.appendChild(wrap);
95 dec = collection.getNamedItem(HTML40Namespace.ElementName.TFOOT);
96 if (dec != null)
97 wrap.appendChild(dec);
98
99 // (TBODY)+
pavery1ffa69f2005-05-27 18:11:23 +0000100 // TBODY has optional start and end tags
101 wrap = new CMGroupImpl(CMGroup.SEQUENCE, 0, CMContentImpl.UNBOUNDED);
nitind958d79a2004-11-23 19:23:00 +0000102 if (wrap == null)
103 return;
104 content.appendChild(wrap);
105 dec = collection.getNamedItem(HTML40Namespace.ElementName.TBODY);
106 if (dec != null)
107 wrap.appendChild(dec);
pavery1ffa69f2005-05-27 18:11:23 +0000108
109 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=96101
110 // TBODY start and end tag are optional, so TR should be allowed here
111 // (TR)+
112 wrap = new CMGroupImpl(CMGroup.SEQUENCE, 1, CMContentImpl.UNBOUNDED);
113 if (wrap == null)
114 return;
115 content.appendChild(wrap);
116 dec = collection.getNamedItem(HTML40Namespace.ElementName.TR);
117 if (dec != null)
118 wrap.appendChild(dec);
nitind958d79a2004-11-23 19:23:00 +0000119 }
120
121 /**
122 * ((FRAMESET | FRAME)+ & NOFRAMES?)
123 * @return int; Should be one of ANY, EMPTY, ELEMENT, MIXED, PCDATA, CDATA,
124 * those are defined in CMElementDeclaration.
125 */
126 public int getContentType() {
127 return CMElementDeclaration.ELEMENT;
128 }
129
130 /**
131 * Name of complex type definition.
132 * Each singleton must know its own name.
133 * All names should be defined in
134 * {@link <code>ComplexTypeDefinitionFactory</code>} as constants.<br>
135 * @return java.lang.String
136 */
137 public String getTypeName() {
138 return ComplexTypeDefinitionFactory.CTYPE_TABLE;
139 }
pavery1ffa69f2005-05-27 18:11:23 +0000140}