nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
amywu | 923ee60 | 2007-04-10 18:32:07 +0000 | [diff] [blame] | 2 | * Copyright (c) 2004, 2005 IBM Corporation and others. |
nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 3 | * 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 |
amywu | 923ee60 | 2007-04-10 18:32:07 +0000 | [diff] [blame] | 7 | * |
nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 8 | * Contributors: |
| 9 | * IBM Corporation - initial API and implementation |
| 10 | *******************************************************************************/ |
david_williams | 5677702 | 2005-04-11 06:21:55 +0000 | [diff] [blame] | 11 | package org.eclipse.wst.html.core.internal.contentmodel; |
nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 12 | |
| 13 | |
| 14 | |
david_williams | 4ad020f | 2005-04-18 08:00:30 +0000 | [diff] [blame] | 15 | import org.eclipse.wst.html.core.internal.provisional.HTML40Namespace; |
david_williams | c06c86f | 2005-03-18 18:23:41 +0000 | [diff] [blame] | 16 | import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; |
| 17 | import org.eclipse.wst.xml.core.internal.contentmodel.CMGroup; |
| 18 | import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; |
nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 19 | |
| 20 | /** |
| 21 | * for TABLE. |
pavery | 1ffa69f | 2005-05-27 18:11:23 +0000 | [diff] [blame] | 22 | * (CAPTION?, (COL*|COLGROUP*), THEAD?, TFOOT?, TBODY+, TR+) |
nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 23 | */ |
| 24 | final 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+) |
pavery | 1ffa69f | 2005-05-27 18:11:23 +0000 | [diff] [blame] | 36 | * --> ((CAPTION)?, ((COL)* | (COLGROUP)*), (THEAD)?, (TFOOT)?, (TBODY)+, (TR)+) |
nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 37 | */ |
| 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)+ |
pavery | 1ffa69f | 2005-05-27 18:11:23 +0000 | [diff] [blame] | 100 | // TBODY has optional start and end tags |
| 101 | wrap = new CMGroupImpl(CMGroup.SEQUENCE, 0, CMContentImpl.UNBOUNDED); |
nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 102 | if (wrap == null) |
| 103 | return; |
| 104 | content.appendChild(wrap); |
| 105 | dec = collection.getNamedItem(HTML40Namespace.ElementName.TBODY); |
| 106 | if (dec != null) |
| 107 | wrap.appendChild(dec); |
pavery | 1ffa69f | 2005-05-27 18:11:23 +0000 | [diff] [blame] | 108 | |
| 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); |
nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 119 | } |
| 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 | } |
pavery | 1ffa69f | 2005-05-27 18:11:23 +0000 | [diff] [blame] | 140 | } |