1 /*
2  * reserved comment block
3  * DO NOT REMOVE OR ALTER!
4  */
5 /*
6  * Licensed to the Apache Software Foundation (ASF) under one or more
7  * contributor license agreements.  See the NOTICE file distributed with
8  * this work for additional information regarding copyright ownership.
9  * The ASF licenses this file to You under the Apache License, Version 2.0
10  * (the "License"); you may not use this file except in compliance with
11  * the License.  You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 package com.sun.org.apache.xml.internal.serializer;
23 
24 import com.sun.org.apache.xml.internal.serializer.utils.StringToIntTable;
25 
26 /**
27  * This class has a series of flags (bit values) that describe an HTML element
28  *
29  * This class is public because XSLTC uses it, it is not a public API.
30  *
31  * @xsl.usage internal
32  */
33 public final class ElemDesc
34 {
35     /** Bit flags to tell about this element type. */
36     private int m_flags;
37 
38     /**
39      * Table of attribute names to integers, which contain bit flags telling about
40      *  the attributes.
41      */
42     private StringToIntTable m_attrs = null;
43 
44     /** Bit position if this element type is empty. */
45     static final int EMPTY = (1 << 1);
46 
47     /** Bit position if this element type is a flow. */
48     private static final int FLOW = (1 << 2);
49 
50     /** Bit position if this element type is a block. */
51     static final int BLOCK = (1 << 3);
52 
53     /** Bit position if this element type is a block form. */
54     static final int BLOCKFORM = (1 << 4);
55 
56     /** Bit position if this element type is a block form field set. */
57     static final int BLOCKFORMFIELDSET = (1 << 5);
58 
59     /** Bit position if this element type is CDATA. */
60     private static final int CDATA = (1 << 6);
61 
62     /** Bit position if this element type is PCDATA. */
63     private static final int PCDATA = (1 << 7);
64 
65     /** Bit position if this element type is should be raw characters. */
66     static final int RAW = (1 << 8);
67 
68     /** Bit position if this element type should be inlined. */
69     private static final int INLINE = (1 << 9);
70 
71     /** Bit position if this element type is INLINEA. */
72     private static final int INLINEA = (1 << 10);
73 
74     /** Bit position if this element type is an inline label. */
75     static final int INLINELABEL = (1 << 11);
76 
77     /** Bit position if this element type is a font style. */
78     static final int FONTSTYLE = (1 << 12);
79 
80     /** Bit position if this element type is a phrase. */
81     static final int PHRASE = (1 << 13);
82 
83     /** Bit position if this element type is a form control. */
84     static final int FORMCTRL = (1 << 14);
85 
86     /** Bit position if this element type is ???. */
87     static final int SPECIAL = (1 << 15);
88 
89     /** Bit position if this element type is ???. */
90     static final int ASPECIAL = (1 << 16);
91 
92     /** Bit position if this element type is an odd header element. */
93     static final int HEADMISC = (1 << 17);
94 
95     /** Bit position if this element type is a head element (i.e. H1, H2, etc.) */
96     static final int HEAD = (1 << 18);
97 
98     /** Bit position if this element type is a list. */
99     static final int LIST = (1 << 19);
100 
101     /** Bit position if this element type is a preformatted type. */
102     static final int PREFORMATTED = (1 << 20);
103 
104     /** Bit position if this element type is whitespace sensitive. */
105     static final int WHITESPACESENSITIVE = (1 << 21);
106 
107     /** Bit position if this element type is a header element (i.e. HEAD). */
108     static final int HEADELEM = (1 << 22);
109 
110     /** Bit position if this element is the "HTML" element */
111     private static final int HTMLELEM = (1 << 23);
112 
113     /** Bit position if this attribute type is a URL. */
114     public static final int ATTRURL = (1 << 1);
115 
116     /** Bit position if this attribute type is an empty type. */
117     public static final int ATTREMPTY = (1 << 2);
118 
119     /**
120      * Construct an ElemDesc from a set of bit flags.
121      *
122      *
123      * @param flags Bit flags that describe the basic properties of this element type.
124      */
ElemDesc(int flags)125     ElemDesc(int flags)
126     {
127         m_flags = flags;
128     }
129 
130     /**
131      * Tell if this element type has the basic bit properties that are passed
132      * as an argument.
133      *
134      * @param flags Bit flags that describe the basic properties of interest.
135      *
136      * @return true if any of the flag bits are true.
137      */
is(int flags)138     private boolean is(int flags)
139     {
140 
141         // int which = (m_flags & flags);
142         return (m_flags & flags) != 0;
143     }
144 
getFlags()145     int getFlags() {
146         return m_flags;
147     }
148 
149     /**
150      * Set an attribute name and it's bit properties.
151      *
152      *
153      * @param name non-null name of attribute, in upper case.
154      * @param flags flag bits.
155      */
setAttr(String name, int flags)156     void setAttr(String name, int flags)
157     {
158 
159         if (null == m_attrs)
160             m_attrs = new StringToIntTable();
161 
162         m_attrs.put(name, flags);
163     }
164 
165     /**
166      * Tell if any of the bits of interest are set for a named attribute type.
167      *
168      * @param name non-null reference to attribute name, in any case.
169      * @param flags flag mask.
170      *
171      * @return true if any of the flags are set for the named attribute.
172      */
isAttrFlagSet(String name, int flags)173     public boolean isAttrFlagSet(String name, int flags)
174     {
175         return (null != m_attrs)
176             ? ((m_attrs.getIgnoreCase(name) & flags) != 0)
177             : false;
178     }
179 }
180