KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xml > internal > utils > ElemDesc


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: ElemDesc.java,v 1.7 2004/02/17 04:21:14 minchau Exp $
18  */

19 package com.sun.org.apache.xml.internal.utils;
20
21 import java.util.Hashtable JavaDoc;
22
23 /**
24  * This class is in support of SerializerToHTML, and acts as a sort
25  * of element representative for HTML elements.
26  * @xsl.usage internal
27  */

28 class ElemDesc
29 {
30
31   /** Table of attributes for the element */
32   Hashtable JavaDoc m_attrs = null;
33
34   /** Element's flags, describing the role this element plays during
35    * formatting of the document. This is used as a bitvector; more than one flag
36    * may be set at a time, bitwise-ORed together. Mnemonic and bits
37    * have been assigned to the flag values. NOTE: Some bits are
38    * currently assigned multiple mnemonics; it is the caller's
39    * responsibility to disambiguate these if necessary. */

40   int m_flags;
41
42   /** Defines mnemonic and bit-value for the EMPTY flag */
43   static final int EMPTY = (1 << 1);
44
45   /** Defines mnemonic and bit-value for the FLOW flag */
46   static final int FLOW = (1 << 2);
47
48   /** Defines mnemonic and bit-value for the BLOCK flag */
49   static final int BLOCK = (1 << 3);
50
51   /** Defines mnemonic and bit-value for the BLOCKFORM flag */
52   static final int BLOCKFORM = (1 << 4);
53
54   /** Defines mnemonic and bit-value for the BLOCKFORMFIELDSET flag */
55   static final int BLOCKFORMFIELDSET = (1 << 5);
56
57   /** Defines mnemonic and bit-value for the CDATA flag */
58   static final int CDATA = (1 << 6);
59
60   /** Defines mnemonic and bit-value for the PCDATA flag */
61   static final int PCDATA = (1 << 7);
62
63   /** Defines mnemonic and bit-value for the RAW flag */
64   static final int RAW = (1 << 8);
65
66   /** Defines mnemonic and bit-value for the INLINE flag */
67   static final int INLINE = (1 << 9);
68
69   /** Defines mnemonic and bit-value for the INLINEA flag */
70   static final int INLINEA = (1 << 10);
71
72   /** Defines mnemonic and bit-value for the INLINELABEL flag */
73   static final int INLINELABEL = (1 << 11);
74
75   /** Defines mnemonic and bit-value for the FONTSTYLE flag */
76   static final int FONTSTYLE = (1 << 12);
77
78   /** Defines mnemonic and bit-value for the PHRASE flag */
79   static final int PHRASE = (1 << 13);
80
81   /** Defines mnemonic and bit-value for the FORMCTRL flag */
82   static final int FORMCTRL = (1 << 14);
83
84   /** Defines mnemonic and bit-value for the SPECIAL flag */
85   static final int SPECIAL = (1 << 15);
86
87   /** Defines mnemonic and bit-value for the ASPECIAL flag */
88   static final int ASPECIAL = (1 << 16);
89
90   /** Defines mnemonic and bit-value for the HEADMISC flag */
91   static final int HEADMISC = (1 << 17);
92
93   /** Defines mnemonic and bit-value for the HEAD flag */
94   static final int HEAD = (1 << 18);
95
96   /** Defines mnemonic and bit-value for the LIST flag */
97   static final int LIST = (1 << 19);
98
99   /** Defines mnemonic and bit-value for the PREFORMATTED flag */
100   static final int PREFORMATTED = (1 << 20);
101
102   /** Defines mnemonic and bit-value for the WHITESPACESENSITIVE flag */
103   static final int WHITESPACESENSITIVE = (1 << 21);
104
105   /** Defines mnemonic and bit-value for the ATTRURL flag */
106   static final int ATTRURL = (1 << 1);
107
108   /** Defines mnemonic and bit-value for the ATTREMPTY flag */
109   static final int ATTREMPTY = (1 << 2);
110
111   /**
112    * Construct an ElementDescription with an initial set of flags.
113    *
114    * @param flags Element flags
115    * @see m_flags
116    */

117   ElemDesc(int flags)
118   {
119     m_flags = flags;
120   }
121
122   /**
123    * "is (this element described by these flags)".
124    *
125    * This might more properly be called areFlagsSet(). It accepts an
126    * integer (being used as a bitvector) and checks whether all the
127    * corresponding bits are set in our internal flags. Note that this
128    * test is performed as a bitwise AND, not an equality test, so a
129    * 0 bit in the input means "don't test", not "must be set false".
130    *
131    * @param flags Vector of flags to compare against this element's flags
132    *
133    * @return true if the flags set in the parameter are also set in the
134    * element's stored flags.
135    *
136    * @see m_flags
137    * @see isAttrFlagSet
138    */

139   boolean is(int flags)
140   {
141     // int which = (m_flags & flags);
142
return (m_flags & flags) != 0;
143   }
144
145   /**
146    * Set a new attribute for this element
147    *
148    *
149    * @param name Attribute name
150    * @param flags Attibute flags
151    */

152   void setAttr(String JavaDoc name, int flags)
153   {
154
155     if (null == m_attrs)
156       m_attrs = new Hashtable JavaDoc();
157
158     m_attrs.put(name, new Integer JavaDoc(flags));
159   }
160
161   /**
162    * Find out if a flag is set in a given attribute of this element
163    *
164    *
165    * @param name Attribute name
166    * @param flags Flag to check
167    *
168    * @return True if the flag is set in the attribute. Returns false
169    * if the attribute is not found
170    * @see m_flags
171    */

172   boolean isAttrFlagSet(String JavaDoc name, int flags)
173   {
174
175     if (null != m_attrs)
176     {
177       Integer JavaDoc _flags = (Integer JavaDoc) m_attrs.get(name);
178
179       if (null != _flags)
180       {
181         return (_flags.intValue() & flags) != 0;
182       }
183     }
184
185     return false;
186   }
187 }
188
Popular Tags