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