001: /*
002: * Sun Public License Notice
003: *
004: * The contents of this file are subject to the Sun Public License
005: * Version 1.0 (the "License"). You may not use this file except in
006: * compliance with the License. A copy of the License is available at
007: * http://www.sun.com/
008: *
009: * The Original Code is NetBeans. The Initial Developer of the Original
010: * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
011: * Microsystems, Inc. All Rights Reserved.
012: */
013: package org.netbeans.editor.ext.html.dtd;
014:
015: import java.util.List;
016: import java.util.Set;
017: import java.util.TreeSet;
018:
019: /**
020: * The interface representing SGMLish Document Type Definition. There is
021: * separate instance for every DTD ID. The DTD in whole provides informations
022: * about Elements, Attributes, their types, possible Values, Character
023: * references and Content models.
024: *
025: * @author Petr Nejedly
026: * @version 1.0
027: */
028: public interface DTD {
029:
030: /**
031: * Identify this instance of DTD
032: *
033: * @return the name under which should be this DTD registered in DTD
034: * registry.
035: */
036: public String getIdentifier();
037:
038: /**
039: * Get List of all Elements whose names starts with given prefix
040: *
041: * @param prefix
042: * the prefix all returned Elements must start with. For empty
043: * string or <CODE>null</CODE>, List of all Elements from this
044: * DTD will be returned. The implementation <B>must</B> handle
045: * <CODE>null</CODE> correctly.
046: * @return List of all Elements from this DTD starting with <CODE>prefix</CODE>,
047: * or empty List if no such Element found. Never returns <CODE>null</CODE>.
048: */
049: public List getElementList(String prefix);
050:
051: /**
052: * Get the Element of given name.
053: *
054: * @return DTD.Element for given name or <CODE>null</CODE>, if no such
055: * Element exists in this DTD.
056: */
057: public DTD.Element getElement(String name);
058:
059: /**
060: * Get List of all CharRefs whose aliases starts with given prefix.
061: *
062: * @param prefix
063: * the requred prefix of CharRefs. For empty string or <CODE>null</CODE>,
064: * List of all CharRefs from this DTD is returned. The
065: * implementation <B>must</B> handle <CODE>null</CODE>
066: * correctly.
067: * @return List of all such CharRefs, maybe empty, never <CODE>null</CODE>.
068: */
069: public List getCharRefList(String prefix);
070:
071: /**
072: * Get the CharRef of given name.
073: *
074: * @return DTD.CharRef for given name or <CODE>null</CODE>, if no such
075: * CharRef exists in this DTD.
076: */
077: public DTD.CharRef getCharRef(String name);
078:
079: /**
080: * Element is the interface providing informations about HTML Element and
081: * its content model.
082: */
083: public static interface Element {
084:
085: /**
086: * Get the name of this Element
087: */
088: public String getName();
089:
090: /**
091: * Shorthand to resolving if content model of this Element is EMPTY
092: *
093: * @return true iff content model of this Element is EMPTY.
094: */
095: public boolean isEmpty();
096:
097: /** Tells if this Element has optional Start Tag. */
098: public boolean hasOptionalStart();
099:
100: /** Tells if this Element has optional End Tag. */
101: public boolean hasOptionalEnd();
102:
103: /**
104: * Get the List of Attributes of this Element, which starts with given
105: * <CODE>prefix</CODE>.
106: *
107: * @param prefix
108: * the requred prefix of Attributes. For empty string or
109: * <CODE>null</CODE>, List of all Attributes of this
110: * Element is returned. The implementation <B>must</B>
111: * handle <CODE>null</CODE> correctly.
112: * @return List of all such Attributes, maybe empty, never <CODE>null</CODE>.
113: */
114: public List getAttributeList(String prefix);
115:
116: /**
117: * Get the Attribute of given name.
118: *
119: * @return DTD.Attribute for given name or <CODE>null</CODE>, if no
120: * such Attribute exists in this Element.
121: */
122: public DTD.Attribute getAttribute(String name);
123:
124: /** Get the content model of this Element */
125: public DTD.ContentModel getContentModel();
126:
127: }
128:
129: /**
130: * Interface providing informations about one type of attribute. Every
131: * Element provides List of its' Attributes, which in turn provide.
132: * information about their types and possible values.
133: */
134: public static interface Attribute {
135:
136: /**
137: * attribute of boolean type - the one which can't have "= smgt." after
138: * it
139: */
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;
145:
146: public static final String MODE_IMPLIED = "#IMPLIED";
147: public static final String MODE_REQUIRED = "#REQUIRED";
148: public static final String MODE_FIXED = "#FIXED";
149:
150: /** @return name of this attribute */
151: public String getName();
152:
153: /**
154: * @return type of this attribute, could be TYPE_BOOLEAN, TYPE_SET or
155: * TYPE_BASE
156: */
157: public int getType();
158:
159: /**
160: * The base type of this attribute. Used only for TYPE_BASE attributes.
161: *
162: * @return the base type, like CDATA, NUMBER, ID, if known (getType() ==
163: * TYPE_BASE, null elsewhere.
164: */
165: public String getBaseType();
166:
167: /**
168: * Only helper method, should return the last entity name through which
169: * was this Attribute's type defined. e.g. for color attrib in: <!ENTITY %
170: * Color "CDATA"> <ATTLIST FONT color %Color #IMPLIED> should this
171: * method return "Color". May return <CODE>null</CODE>.
172: */
173: public String getTypeHelper();
174:
175: /**
176: * This method is used to obtain default value information.
177: *
178: * @returns the default value or one of MODE_IMPLIED, MODE_REQUIRED or
179: * MODE_FIXED constants.
180: */
181: public String getDefaultMode();
182:
183: /** Shorthand for determining if defaultMode is "#REQUIRED" */
184: public boolean isRequired();
185:
186: /**
187: * The way how to obtain possible values for TYPE_SET Attributes
188: *
189: * @param prefix
190: * required prefix, or <CODE>null</CODE>, if all possible
191: * values are required.
192: * @return List of Values starting with prefix, from this attribute if
193: * it is of TYPE_SET. For other types, it doesn't make a sense
194: * and returns null.
195: */
196: public List getValueList(String prefix);
197:
198: /**
199: * Get the value of given name.
200: */
201: public Value getValue(String name);
202:
203: }
204:
205: /*
206: * Simple shell for value, maybe there will be some additional info about
207: * value in future
208: */
209: public static interface Value {
210: public String getName();
211: }
212:
213: /**
214: * The interface representing Character reference. Provides its name and
215: * character it refers to
216: */
217: public static interface CharRef {
218: /** @return alias to this CharRef */
219: public String getName();
220:
221: /** @return the character this alias is for */
222: public char getValue();
223: }
224:
225: /**
226: * The interface representing Content model of an Element. Content model is
227: * based on expression matching some sequence of Elements (the Content) and
228: * Set of added and excluded Elements. The point of added and excluded
229: * Elements is that they are "sticky" - are propagated down the hierarchy of
230: * Elements.
231: */
232: public static interface ContentModel {
233:
234: /** @return the Content tree part of this model */
235: public Content getContent();
236:
237: /**
238: * @return Set of Elements which are additionally possible anywhewe
239: * (recursively) in the content of the Element which has this
240: * ContentModel, unless explicitely excluded. Inclusion can not
241: * override explicit exclusion.
242: */
243: public Set getIncludes();
244:
245: /**
246: * @return Set of Elements which are recursively excluded from
247: * ContentModel of all Elements inside the Element with this
248: * ContentModel. Exclusion overrieds inclusion, but not
249: * otherwise.
250: */
251: public Set getExcludes();
252:
253: }
254:
255: /**
256: * This interface represents an element of content tree. Its instances
257: * should be either instances of ContetLeaf or instances of ContentNode.
258: */
259: public static interface Content {
260: static class EmptyContent implements Content {
261: public boolean isDiscardable() {
262: return true;
263: }
264:
265: public Content reduce(String name) {
266: return null;
267: }
268:
269: public Set getPossibleElements() {
270: return new TreeSet();
271: }
272: }
273:
274: public static Content EMPTY_CONTENT = new EmptyContent();
275:
276: /*
277: * public static Content EMPTY_CONTENT = new Content() { public boolean
278: * isDiscardable() { return true; } public Content reduce( String name ) {
279: * return null; } public Set getPossibleElements() { return new
280: * TreeSet(); } };
281: */
282: /**
283: * Tells whether this content can be discarded - i.e. matches empty
284: * sequence of elements.
285: *
286: * @return true iff this Content matches empty sequence
287: */
288: public boolean isDiscardable();
289:
290: /**
291: * Make a left reduction of this Content. Match the given element and
292: * create a content model of the rest. Notify caller, when given element
293: * doesn't match this Content
294: *
295: * @return reduced Content, if element left-reduces the content, in the
296: * case the reduction lead to empty content, return <CODE>EMPTY_CONTENT</CODE>.
297: * If the element doesn't reduce the content, return <CODE>null</CODE>.
298: */
299: public Content reduce(String elementName);
300:
301: /** Return the Set of all DTD.Elements that are permitted by this Content */
302: public Set getPossibleElements();
303: }
304:
305: /**
306: * ContentLeaf is leaf of content tree, matches just one Element name
307: * (String)
308: */
309: public static interface ContentLeaf extends Content {
310: /** get the Element of this leaf Content */
311: public Element getElement();
312: }
313:
314: /**
315: * ContentNode is node of content tree, contains one operator (either unary
316: * or n-ary) and sequence of elements on which this operator is applied.
317: */
318: public static interface ContentNode extends Content {
319:
320: /**
321: * Get the operator for this node, could be unary ('+', '*', '?') or
322: * n-ary ('|', '&', ',')
323: */
324: public char getType();
325: }
326: }
|