2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
41
package org.netbeans.editor.ext.html.dtd;
46
/** The interface representing SGMLish Document Type Definition. There is separate
47
* instance for every DTD ID.
48
* The DTD in whole provides informations about Elements, Attributes, their types,
49
* possible Values, Character references and Content models.
51
* @author Petr Nejedly
54
public interface DTD {
56
/** Identify this instance of DTD
57
* @return the name under which should be this DTD registered in DTD registry.
59
public String getIdentifier();
61
/** Get List of all Elements whose names starts with given prefix
62
* @param prefix the prefix all returned Elements must start with. For empty
63
* string or <CODE>null</CODE>, List of all Elements from this DTD will be returned.
64
* The implementation <B>must</B> handle <CODE>null</CODE> correctly.
65
* @return List of all Elements from this DTD starting with <CODE>prefix</CODE>,
66
* or empty List if no such Element found. Never returns <CODE>null</CODE>.
68
public List getElementList( String prefix );
70
/** Get the Element of given name.
71
* @return DTD.Element for given name or <CODE>null</CODE>, if no such Element
74
public DTD.Element getElement( String name );
76
/** Get List of all CharRefs whose aliases starts with given prefix.
77
* @param prefix the requred prefix of CharRefs. For empty string
78
* or <CODE>null</CODE>, List of all CharRefs from this DTD is returned.
79
* The implementation <B>must</B> handle <CODE>null</CODE> correctly.
80
* @return List of all such CharRefs, maybe empty, never <CODE>null</CODE>.
82
public List getCharRefList( String prefix );
84
/** Get the CharRef of given name.
85
* @return DTD.CharRef for given name or <CODE>null</CODE>, if no such CharRef
88
public DTD.CharRef getCharRef( String name );
91
/** Element is the interface providing informations about HTML Element
92
* and its content model.
94
public static interface Element {
96
/** Get the name of this Element
98
public String getName();
100
/** Shorthand to resolving if content model of this Element is EMPTY
101
* @return true iff content model of this Element is EMPTY.
103
public boolean isEmpty();
105
/** Tells if this Element has optional Start Tag. */
106
public boolean hasOptionalStart();
108
/** Tells if this Element has optional End Tag. */
109
public boolean hasOptionalEnd();
111
/** Get the List of Attributes of this Element, which starts with
112
* given <CODE>prefix</CODE>.
113
* @param prefix the requred prefix of Attributes. For empty string
114
* or <CODE>null</CODE>, List of all Attributes of this Element is returned.
115
* The implementation <B>must</B> handle <CODE>null</CODE> correctly.
116
* @return List of all such Attributes, maybe empty, never <CODE>null</CODE>.
118
public List getAttributeList( String prefix );
120
/** Get the Attribute of given name.
121
* @return DTD.Attribute for given name or <CODE>null</CODE>, if no such
122
* Attribute exists in this Element.
124
public DTD.Attribute getAttribute( String name );
126
/** Get the content model of this Element */
127
public DTD.ContentModel getContentModel();
133
* Interface providing informations about one type of attribute.
134
* Every Element provides List of its' Attributes, which in turn provide.
135
* information about their types and possible values.
137
public static interface Attribute {
139
/** attribute of boolean type - the one which can't have "= smgt." after it */
140
public static final int TYPE_BOOLEAN = 0;
141
/** attribute of one-of-set type - the one which can complete value */
142
public static final int TYPE_SET = 1;
143
/** attribute of some base type like NUMBER, CDATA, ID, NAME,... */
144
public static final int TYPE_BASE = 2;
146
public static final String MODE_IMPLIED = "#IMPLIED"; // NOI18N
147
public static final String MODE_REQUIRED = "#REQUIRED"; // NOI18N
148
public static final String MODE_FIXED = "#FIXED"; // NOI18N
151
/** @return name of this attribute */
152
public String getName();
154
/** @return type of this attribute, could be TYPE_BOOLEAN,
155
* TYPE_SET or TYPE_BASE
157
public int getType();
159
/** The base type of this attribute. Used only for TYPE_BASE
161
* @return the base type, like CDATA, NUMBER, ID, if known
162
* (getType() == TYPE_BASE, null elsewhere.
164
public String getBaseType();
166
/** Only helper method, should return the last entity name through
167
* which was this Attribute's type defined. e.g. for color attrib in:
168
* <!ENTITY % Color "CDATA"> <ATTLIST FONT color %Color #IMPLIED>
169
* should this method return "Color".
170
* May return <CODE>null</CODE>.
172
public String getTypeHelper();
174
/** This method is used to obtain default value information.
175
* @returns the default value or one of MODE_IMPLIED, MODE_REQUIRED
176
* or MODE_FIXED constants.
178
public String getDefaultMode();
180
/** Shorthand for determining if defaultMode is "#REQUIRED" */
181
public boolean isRequired();
183
/** The way how to obtain possible values for TYPE_SET Attributes
184
* @param prefix required prefix, or <CODE>null</CODE>, if all
185
* possible values are required.
186
* @return List of Values starting with prefix, from this attribute
187
* if it is of TYPE_SET. For other types, it doesn't make a sense
190
public List getValueList( String prefix );
192
/** Get the value of given name.
194
public Value getValue( String name );
198
/* Simple shell for value, maybe there will be some additional info about
200
public static interface Value {
201
public String getName();
204
/** The interface representing Character reference. Provides its name
205
* and character it refers to
207
public static interface CharRef {
208
/** @return alias to this CharRef */
209
public String getName();
211
/** @return the character this alias is for */
212
public char getValue();
216
/** The interface representing Content model of an Element. Content model
217
* is based on expression matching some sequence of Elements (the Content)
218
* and Set of added and excluded Elements. The point of added and excluded
219
* Elements is that they are "sticky" - are propagated down the hierarchy
222
public static interface ContentModel {
224
/** @return the Content tree part of this model */
225
public Content getContent();
227
/** @return Set of Elements which are additionally possible anywhewe
228
* (recursively) in the content of the Element which has this
229
* ContentModel, unless explicitely excluded. Inclusion can not
230
* override explicit exclusion.
232
public Set getIncludes();
234
/** @return Set of Elements which are recursively excluded from
235
* ContentModel of all Elements inside the Element with this ContentModel.
236
* Exclusion overrieds inclusion, but not otherwise.
238
public Set getExcludes();
242
/** This interface represents an element of content tree. Its instances
243
* should be either instances of ContetLeaf or instances of ContentNode.
245
public static interface Content {
246
static class EmptyContent implements Content {
247
public boolean isDiscardable() { return true; }
248
public Content reduce( String name ) { return null; }
249
public Set getPossibleElements() { return new TreeSet(); }
252
public static Content EMPTY_CONTENT = new EmptyContent();
254
/* public static Content EMPTY_CONTENT = new Content() {
255
public boolean isDiscardable() { return true; }
256
public Content reduce( String name ) { return null; }
257
public Set getPossibleElements() { return new TreeSet(); }
260
/** Tells whether this content can be discarded - i.e. matches
261
* empty sequence of elements.
262
* @return true iff this Content matches empty sequence */
263
public boolean isDiscardable();
265
/** Make a left reduction of this Content. Match the given element
266
* and create a content model of the rest. Notify caller, when given
267
* element doesn't match this Content
268
* @return reduced Content, if element left-reduces the content,
269
* in the case the reduction lead to empty content, return
270
* <CODE>EMPTY_CONTENT</CODE>.
271
* If the element doesn't reduce the content, return <CODE>null</CODE>.
273
public Content reduce( String elementName );
275
/** Return the Set of all DTD.Elements that are permitted by this Content */
276
public Set getPossibleElements();
279
/** ContentLeaf is leaf of content tree, matches just one Element name (String)*/
280
public static interface ContentLeaf extends Content {
281
/** get the Element of this leaf Content */
282
public Element getElement();
285
/** ContentNode is node of content tree, contains one operator (either unary
286
* or n-ary) and sequence of elements on which this operator is applied.
288
public static interface ContentNode extends Content {
290
/** Get the operator for this node, could be unary ('+', '*', '?')
291
* or n-ary ('|', '&', ',')
293
public char getType();