001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements. See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership. The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the  "License");
007     * you may not use this file except in compliance with the License.
008     * You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    /*
019     * $Id: ElemDesc.java 468654 2006-10-28 07:09:23Z minchau $
020     */
021    package org.apache.xml.serializer;
022    
023    import org.apache.xml.serializer.utils.StringToIntTable;
024    
025    /**
026     * This class has a series of flags (bit values) that describe an HTML element
027     * <p>
028     * This class is not a public API.
029     * It is public because it is used outside of this package.
030     * 
031     * @xsl.usage internal
032     */
033    public final class ElemDesc
034    {
035        /** Bit flags to tell about this element type. */
036        private int m_flags;
037    
038        /**
039         * Table of attribute names to integers, which contain bit flags telling about
040         *  the attributes.
041         */
042        private StringToIntTable m_attrs = null;
043    
044        /** Bit position if this element type is empty. */
045        static final int EMPTY = (1 << 1);
046    
047        /** Bit position if this element type is a flow. */
048        private static final int FLOW = (1 << 2);
049    
050        /** Bit position if this element type is a block. */
051        static final int BLOCK = (1 << 3);
052    
053        /** Bit position if this element type is a block form. */
054        static final int BLOCKFORM = (1 << 4);
055    
056        /** Bit position if this element type is a block form field set. */
057        static final int BLOCKFORMFIELDSET = (1 << 5);
058    
059        /** Bit position if this element type is CDATA. */
060        private static final int CDATA = (1 << 6);
061    
062        /** Bit position if this element type is PCDATA. */
063        private static final int PCDATA = (1 << 7);
064    
065        /** Bit position if this element type is should be raw characters. */
066        static final int RAW = (1 << 8);
067    
068        /** Bit position if this element type should be inlined. */
069        private static final int INLINE = (1 << 9);
070    
071        /** Bit position if this element type is INLINEA. */
072        private static final int INLINEA = (1 << 10);
073    
074        /** Bit position if this element type is an inline label. */
075        static final int INLINELABEL = (1 << 11);
076    
077        /** Bit position if this element type is a font style. */
078        static final int FONTSTYLE = (1 << 12);
079    
080        /** Bit position if this element type is a phrase. */
081        static final int PHRASE = (1 << 13);
082    
083        /** Bit position if this element type is a form control. */
084        static final int FORMCTRL = (1 << 14);
085    
086        /** Bit position if this element type is ???. */
087        static final int SPECIAL = (1 << 15);
088    
089        /** Bit position if this element type is ???. */
090        static final int ASPECIAL = (1 << 16);
091    
092        /** Bit position if this element type is an odd header element. */
093        static final int HEADMISC = (1 << 17);
094    
095        /** Bit position if this element type is a head element (i.e. H1, H2, etc.) */
096        static final int HEAD = (1 << 18);
097    
098        /** Bit position if this element type is a list. */
099        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         */
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         */
138        private boolean is(int flags)
139        {
140    
141            // int which = (m_flags & flags);
142            return (m_flags & flags) != 0;
143        }
144    
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         */
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         */
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    }