KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xml > internal > serializer > 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.4 2004/02/17 04:18:19 minchau Exp $
18  */

19 package com.sun.org.apache.xml.internal.serializer;
20
21 import com.sun.org.apache.xml.internal.utils.StringToIntTable;
22
23 /**
24  * This class has a series of flags (bit values) that describe an HTML element
25  */

26 public final class ElemDesc
27 {
28     /** Bit flags to tell about this element type. */
29     int m_flags;
30
31     /**
32      * Table of attribute names to integers, which contain bit flags telling about
33      * the attributes.
34      */

35     StringToIntTable m_attrs = null;
36
37     /** Bit position if this element type is empty. */
38     public static final int EMPTY = (1 << 1);
39
40     /** Bit position if this element type is a flow. */
41     public static final int FLOW = (1 << 2);
42
43     /** Bit position if this element type is a block. */
44     public static final int BLOCK = (1 << 3);
45
46     /** Bit position if this element type is a block form. */
47     public static final int BLOCKFORM = (1 << 4);
48
49     /** Bit position if this element type is a block form field set (?? -sb). */
50     public static final int BLOCKFORMFIELDSET = (1 << 5);
51
52     /** Bit position if this element type is CDATA. */
53     public static final int CDATA = (1 << 6);
54
55     /** Bit position if this element type is PCDATA. */
56     public static final int PCDATA = (1 << 7);
57
58     /** Bit position if this element type is should be raw characters. */
59     public static final int RAW = (1 << 8);
60
61     /** Bit position if this element type should be inlined. */
62     public static final int INLINE = (1 << 9);
63
64     /** Bit position if this element type is INLINEA (?? -sb). */
65     public static final int INLINEA = (1 << 10);
66
67     /** Bit position if this element type is an inline label. */
68     public static final int INLINELABEL = (1 << 11);
69
70     /** Bit position if this element type is a font style. */
71     public static final int FONTSTYLE = (1 << 12);
72
73     /** Bit position if this element type is a phrase. */
74     public static final int PHRASE = (1 << 13);
75
76     /** Bit position if this element type is a form control. */
77     public static final int FORMCTRL = (1 << 14);
78
79     /** Bit position if this element type is ???. */
80     public static final int SPECIAL = (1 << 15);
81
82     /** Bit position if this element type is ???. */
83     public static final int ASPECIAL = (1 << 16);
84
85     /** Bit position if this element type is an odd header element. */
86     public static final int HEADMISC = (1 << 17);
87
88     /** Bit position if this element type is a head element (i.e. H1, H2, etc.) */
89     public static final int HEAD = (1 << 18);
90
91     /** Bit position if this element type is a list. */
92     public static final int LIST = (1 << 19);
93
94     /** Bit position if this element type is a preformatted type. */
95     public static final int PREFORMATTED = (1 << 20);
96
97     /** Bit position if this element type is whitespace sensitive. */
98     public static final int WHITESPACESENSITIVE = (1 << 21);
99
100     /** Bit position if this element type is a header element (i.e. HEAD). */
101     public static final int HEADELEM = (1 << 22);
102
103     /** Bit position if this attribute type is a URL. */
104     public static final int ATTRURL = (1 << 1);
105
106     /** Bit position if this attribute type is an empty type. */
107     public static final int ATTREMPTY = (1 << 2);
108
109     /**
110      * Construct an ElemDesc from a set of bit flags.
111      *
112      *
113      * @param flags Bit flags that describe the basic properties of this element type.
114      */

115     public ElemDesc(int flags)
116     {
117         m_flags = flags;
118     }
119
120     /**
121      * Tell if this element type has the basic bit properties that are passed
122      * as an argument.
123      *
124      * @param flags Bit flags that describe the basic properties of interest.
125      *
126      * @return true if any of the flag bits are true.
127      */

128     public boolean is(int flags)
129     {
130
131         // int which = (m_flags & flags);
132
return (m_flags & flags) != 0;
133     }
134
135     public int getFlags() {
136         return m_flags;
137     }
138
139     /**
140      * Set an attribute name and it's bit properties.
141      *
142      *
143      * @param name non-null name of attribute, in upper case.
144      * @param flags flag bits.
145      */

146     public void setAttr(String JavaDoc name, int flags)
147     {
148
149         if (null == m_attrs)
150             m_attrs = new StringToIntTable();
151
152         m_attrs.put(name, flags);
153     }
154
155     /**
156      * Tell if any of the bits of interest are set for a named attribute type.
157      *
158      * @param name non-null reference to attribute name, in any case.
159      * @param flags flag mask.
160      *
161      * @return true if any of the flags are set for the named attribute.
162      */

163     public boolean isAttrFlagSet(String JavaDoc name, int flags)
164     {
165         return (null != m_attrs)
166             ? ((m_attrs.getIgnoreCase(name) & flags) != 0)
167             : false;
168     }
169 }
170
Popular Tags