KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > editor > ext > html > dtd > DTD


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.editor.ext.html.dtd;
20
21
22 import java.util.*;
23
24 /** The interface representing SGMLish Document Type Definition. There is separate
25  * instance for every DTD ID.
26  * The DTD in whole provides informations about Elements, Attributes, their types,
27  * possible Values, Character references and Content models.
28  *
29  * @author Petr Nejedly
30  * @version 1.0
31  */

32 public interface DTD {
33
34     /** Identify this instance of DTD
35      * @return the name under which should be this DTD registered in DTD registry.
36      */

37     public String JavaDoc getIdentifier();
38     
39     /** Get List of all Elements whose names starts with given prefix
40      * @param prefix the prefix all returned Elements must start with. For empty
41      * string or <CODE>null</CODE>, List of all Elements from this DTD will be returned.
42      * The implementation <B>must</B> handle <CODE>null</CODE> correctly.
43      * @return List of all Elements from this DTD starting with <CODE>prefix</CODE>,
44      * or empty List if no such Element found. Never returns <CODE>null</CODE>.
45      */

46     public List getElementList( String JavaDoc prefix );
47     
48     /** Get the Element of given name.
49      * @return DTD.Element for given name or <CODE>null</CODE>, if no such Element
50      * exists in this DTD.
51      */

52     public DTD.Element getElement( String JavaDoc name );
53     
54     /** Get List of all CharRefs whose aliases starts with given prefix.
55      * @param prefix the requred prefix of CharRefs. For empty string
56      * or <CODE>null</CODE>, List of all CharRefs from this DTD is returned.
57      * The implementation <B>must</B> handle <CODE>null</CODE> correctly.
58      * @return List of all such CharRefs, maybe empty, never <CODE>null</CODE>.
59      */

60     public List getCharRefList( String JavaDoc prefix );
61     
62    /** Get the CharRef of given name.
63     * @return DTD.CharRef for given name or <CODE>null</CODE>, if no such CharRef
64     * exists in this DTD.
65     */

66     public DTD.CharRef getCharRef( String JavaDoc name );
67     
68     
69     /** Element is the interface providing informations about HTML Element
70      * and its content model.
71      */

72     public static interface Element {
73         
74         /** Get the name of this Element
75          */

76         public String JavaDoc getName();
77         
78         /** Shorthand to resolving if content model of this Element is EMPTY
79          * @return true iff content model of this Element is EMPTY.
80          */

81         public boolean isEmpty();
82         
83         /** Tells if this Element has optional Start Tag. */
84         public boolean hasOptionalStart();
85         
86         /** Tells if this Element has optional End Tag. */
87         public boolean hasOptionalEnd();
88         
89         /** Get the List of Attributes of this Element, which starts with
90          * given <CODE>prefix</CODE>.
91          * @param prefix the requred prefix of Attributes. For empty string
92          * or <CODE>null</CODE>, List of all Attributes of this Element is returned.
93          * The implementation <B>must</B> handle <CODE>null</CODE> correctly.
94          * @return List of all such Attributes, maybe empty, never <CODE>null</CODE>.
95          */

96         public List getAttributeList( String JavaDoc prefix );
97         
98         /** Get the Attribute of given name.
99          * @return DTD.Attribute for given name or <CODE>null</CODE>, if no such
100          * Attribute exists in this Element.
101          */

102         public DTD.Attribute getAttribute( String JavaDoc name );
103         
104         /** Get the content model of this Element */
105         public DTD.ContentModel getContentModel();
106         
107     }
108     
109     
110     /**
111      * Interface providing informations about one type of attribute.
112      * Every Element provides List of its' Attributes, which in turn provide.
113      * information about their types and possible values.
114      */

115     public static interface Attribute {
116         
117         /** attribute of boolean type - the one which can't have "= smgt." after it */
118         public static final int TYPE_BOOLEAN = 0;
119         /** attribute of one-of-set type - the one which can complete value */
120         public static final int TYPE_SET = 1;
121         /** attribute of some base type like NUMBER, CDATA, ID, NAME,... */
122         public static final int TYPE_BASE = 2;
123         
124         public static final String JavaDoc MODE_IMPLIED = "#IMPLIED"; // NOI18N
125
public static final String JavaDoc MODE_REQUIRED = "#REQUIRED"; // NOI18N
126
public static final String JavaDoc MODE_FIXED = "#FIXED"; // NOI18N
127

128         
129         /** @return name of this attribute */
130         public String JavaDoc getName();
131         
132         /** @return type of this attribute, could be TYPE_BOOLEAN,
133          * TYPE_SET or TYPE_BASE
134          */

135         public int getType();
136         
137         /** The base type of this attribute. Used only for TYPE_BASE
138          * attributes.
139          * @return the base type, like CDATA, NUMBER, ID, if known
140          * (getType() == TYPE_BASE, null elsewhere.
141          */

142         public String JavaDoc getBaseType();
143         
144         /** Only helper method, should return the last entity name through
145          * which was this Attribute's type defined. e.g. for color attrib in:
146          * <!ENTITY % Color "CDATA"> <ATTLIST FONT color %Color #IMPLIED>
147          * should this method return "Color".
148          * May return <CODE>null</CODE>.
149          */

150         public String JavaDoc getTypeHelper();
151         
152         /** This method is used to obtain default value information.
153          * @returns the default value or one of MODE_IMPLIED, MODE_REQUIRED
154          * or MODE_FIXED constants.
155          */

156         public String JavaDoc getDefaultMode();
157         
158         /** Shorthand for determining if defaultMode is "#REQUIRED" */
159         public boolean isRequired();
160         
161         /** The way how to obtain possible values for TYPE_SET Attributes
162          * @param prefix required prefix, or <CODE>null</CODE>, if all
163          * possible values are required.
164          * @return List of Values starting with prefix, from this attribute
165          * if it is of TYPE_SET. For other types, it doesn't make a sense
166          * and returns null.
167          */

168         public List getValueList( String JavaDoc prefix );
169         
170         /** Get the value of given name.
171          */

172         public Value getValue( String JavaDoc name );
173         
174     }
175     
176     /* Simple shell for value, maybe there will be some additional info about
177      * value in future */

178     public static interface Value {
179         public String JavaDoc getName();
180     }
181     
182     /** The interface representing Character reference. Provides its name
183      * and character it refers to
184      */

185     public static interface CharRef {
186         /** @return alias to this CharRef */
187         public String JavaDoc getName();
188         
189         /** @return the character this alias is for */
190         public char getValue();
191     }
192     
193     
194     /** The interface representing Content model of an Element. Content model
195      * is based on expression matching some sequence of Elements (the Content)
196      * and Set of added and excluded Elements. The point of added and excluded
197      * Elements is that they are "sticky" - are propagated down the hierarchy
198      * of Elements.
199      */

200     public static interface ContentModel {
201         
202         /** @return the Content tree part of this model */
203         public Content getContent();
204         
205         /** @return Set of Elements which are additionally possible anywhewe
206          * (recursively) in the content of the Element which has this
207          * ContentModel, unless explicitely excluded. Inclusion can not
208          * override explicit exclusion.
209          */

210         public Set getIncludes();
211         
212         /** @return Set of Elements which are recursively excluded from
213          * ContentModel of all Elements inside the Element with this ContentModel.
214          * Exclusion overrieds inclusion, but not otherwise.
215          */

216         public Set getExcludes();
217         
218     }
219     
220     /** This interface represents an element of content tree. Its instances
221      * should be either instances of ContetLeaf or instances of ContentNode.
222      */

223     public static interface Content {
224         static class EmptyContent implements Content {
225             public boolean isDiscardable() { return true; }
226             public Content reduce( String JavaDoc name ) { return null; }
227             public Set getPossibleElements() { return new TreeSet(); }
228         }
229         
230         public static Content EMPTY_CONTENT = new EmptyContent();
231         
232 /* public static Content EMPTY_CONTENT = new Content() {
233             public boolean isDiscardable() { return true; }
234             public Content reduce( String name ) { return null; }
235             public Set getPossibleElements() { return new TreeSet(); }
236         };
237 */

238         /** Tells whether this content can be discarded - i.e. matches
239          * empty sequence of elements.
240          * @return true iff this Content matches empty sequence */

241         public boolean isDiscardable();
242         
243         /** Make a left reduction of this Content. Match the given element
244          * and create a content model of the rest. Notify caller, when given
245          * element doesn't match this Content
246          * @return reduced Content, if element left-reduces the content,
247          * in the case the reduction lead to empty content, return
248          * <CODE>EMPTY_CONTENT</CODE>.
249          * If the element doesn't reduce the content, return <CODE>null</CODE>.
250          */

251         public Content reduce( String JavaDoc elementName );
252
253         /** Return the Set of all DTD.Elements that are permitted by this Content */
254         public Set getPossibleElements();
255     }
256     
257     /** ContentLeaf is leaf of content tree, matches just one Element name (String)*/
258     public static interface ContentLeaf extends Content {
259         /** get the Element of this leaf Content */
260         public Element getElement();
261     }
262     
263     /** ContentNode is node of content tree, contains one operator (either unary
264      * or n-ary) and sequence of elements on which this operator is applied.
265      */

266     public static interface ContentNode extends Content {
267
268         /** Get the operator for this node, could be unary ('+', '*', '?')
269          * or n-ary ('|', '&', ',')
270          */

271         public char getType();
272     }
273 }
274
Popular Tags