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