KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > xmlc > html > HTMLProprietaryTags


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: HTMLProprietaryTags.java,v 1.2 2005/01/26 08:29:24 jkjome Exp $
22  */

23
24 package org.enhydra.xml.xmlc.html;
25
26 import java.util.Enumeration JavaDoc;
27 import java.util.Hashtable JavaDoc;
28
29 import org.enhydra.xml.xmlc.XMLCException;
30
31 //FIXME: is this still used???
32

33 /**
34  * Table of proprietary tags and attributes for the HTML parser.
35  */

36 public class HTMLProprietaryTags {
37     /**
38      * Abobe CyberStudio proprietary tag set name.
39      */

40     public static final String JavaDoc TAG_SET_CYBER_STUDIO = "cyberstudio";
41
42     /**
43      * Empty tag content model.
44      */

45     public static final int TAG_CM_EMPTY = 0x01;
46
47     /**
48      * Inline tag content model.
49      */

50     public static final int TAG_CM_INLINE = 0x02;
51
52     /**
53      * Block tag content model.
54      */

55     public static final int TAG_CM_BLOCK = 0x04;
56
57     /**
58      * Closing tag is optional.
59      */

60     public static final int TAG_CM_OPT = 0x08;
61
62     /**
63      * Class used to record an tag with its content model.
64      */

65     public class Tag {
66         /**
67          * Upper-case tag name.
68          */

69         public final String JavaDoc tagName;
70
71         /**
72          * Content model the tag is associated with. (TAG_CM_*).
73          */

74         public final int contentModel;
75         
76         /**
77          * The tag set this tag is associated with, or null if it was
78          * not added as part of a tag set.
79          */

80         public final String JavaDoc tagSet;
81
82         /**
83          * Create a new tag.
84          */

85         protected Tag(String JavaDoc tagName,
86                       int contentModel) {
87             this.tagName = tagName;
88             this.contentModel = contentModel;
89             this.tagSet = null;
90         }
91
92         /**
93          * Create a new tag.
94          */

95         protected Tag(String JavaDoc tagName,
96                       int contentModel,
97                       String JavaDoc tagSet) {
98             this.tagName = tagName;
99             this.contentModel = contentModel;
100             this.tagSet = tagSet;
101         }
102     }
103
104     /**
105      * Hash table of tags that have been specified to their content model.
106      */

107     private Hashtable JavaDoc tags = new Hashtable JavaDoc();
108
109     /**
110      * Hash table of attributes that have been specified. Hash is used
111      * to prevent duplicates.
112      */

113     private Hashtable JavaDoc attributes = new Hashtable JavaDoc();
114     
115     /**
116      * Hash table of tag sets that have been defined.
117      */

118     private Hashtable JavaDoc tagSets = new Hashtable JavaDoc();
119
120     /**
121      * Specify one of the pre-defined sets of proprietary tags that the parser
122      * should accept. If the parser is able to handle arbitrary tags, this
123      * should be ignored. If the parser can only parse valid HTML, an error
124      * should be generated.
125      *
126      * @param tagSetName One of the predefined tag set names. An error is
127      * generated if its illegal.
128      */

129     public void addTagSet(String JavaDoc tagSetName) throws XMLCException {
130         if (tagSetName.equalsIgnoreCase(TAG_SET_CYBER_STUDIO)) {
131             if (!tagSets.containsKey(TAG_SET_CYBER_STUDIO)) {
132                 registerCyberStudioTags();
133                 tagSets.put(TAG_SET_CYBER_STUDIO, TAG_SET_CYBER_STUDIO);
134             }
135         } else {
136             throw new XMLCException ("Unknown proprietary tag set: \""
137                                      + tagSetName + "\", valid sets are: "
138                                      + TAG_SET_CYBER_STUDIO);
139         }
140     }
141
142     /**
143      * Get an enumeration of the tag sets that have been defined.
144      */

145     public Enumeration JavaDoc getTagSets() {
146         return tagSets.elements();
147     }
148
149     /**
150      * Add a proprietary tag to the set of allowed tags.
151      *
152      * @param tagName The name of the tag. The name is case insensitive.
153      * @param contentModel A bit set of the <CODE>TAG_CM_*</CODE> constants.
154      */

155     public void addTag(String JavaDoc tagName,
156                        int contentModel) throws XMLCException {
157         tagName = tagName.toUpperCase();
158         tags.put(tagName, new Tag(tagName,
159                                   contentModel));
160     }
161     
162     /**
163      * Get an enumeration of the proprietary Tag objects.
164      */

165     public Enumeration JavaDoc getTags() {
166         return tags.elements();
167     }
168
169     /**
170      * Add a proprietary attribute to the set of allowed attributes.
171      *
172      * @param attributeName The attribute name. The name is case insensitive.
173      */

174     public void addAttribute(String JavaDoc attributeName) throws XMLCException {
175         attributeName = attributeName.toUpperCase();
176         attributes.put(attributeName, attributeName);
177     }
178
179     /**
180      * Get an enumeration of the Tag objects for the proprietary tags.
181      */

182     public Enumeration JavaDoc getAttributes() {
183         return attributes.elements();
184     }
185
186     /**
187      * Add a proprietary tag from a tagset.
188      */

189     public void addTag(String JavaDoc tagName,
190                        int contentModel,
191                        String JavaDoc tagSet) {
192         tagName = tagName.toUpperCase();
193         tags.put(tagName, new Tag(tagName, contentModel, tagSet));
194     }
195     
196     /**
197      * Register Abobe CyberStudioTags.
198      */

199     private void registerCyberStudioTags() throws XMLCException {
200         String JavaDoc[] csBlockTags = {
201             "csactionclass", "csactiondict", "csactionitem",
202             "csactionparam", "csactions", "csgroup",
203             "csimport", "csmagic", "cspart",
204             "csscriptdict", "cssequence", "cssequencer",
205             "cstrack"
206         };
207         for (int i = 0; i < csBlockTags.length; i++) {
208             addTag(csBlockTags[i], TAG_CM_BLOCK, TAG_SET_CYBER_STUDIO);
209         }
210
211         addTag("csobj", TAG_CM_BLOCK|TAG_CM_INLINE, TAG_SET_CYBER_STUDIO);
212
213         String JavaDoc[] csEmptyTags = {
214             "csbrowser", "csaction", "csactioncntl",
215             "csactionenum", "csgeneric", "csseqaction"
216         };
217         for (int i = 0; i < csEmptyTags.length; i++) {
218             addTag(csEmptyTags[i], TAG_CM_INLINE|TAG_CM_EMPTY|TAG_CM_OPT,
219                    TAG_SET_CYBER_STUDIO);
220         }
221     }
222 }
223
Popular Tags