1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the  "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 /*
19  * $Id: ElemDesc.java 468654 2006-10-28 07:09:23Z minchau $
20  */
21 package org.apache.xml.serializer;
22 
23 import org.apache.xml.serializer.utils.StringToIntTable;
24 
25 /**
26  * This class has a series of flags (bit values) that describe an HTML element
27  * <p>
28  * This class is not a public API.
29  * It is public because it is used outside of this package.
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     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