001: /*
002: * Copyright 1999-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: /*
017: * $Id: ElemDesc.java,v 1.7 2005/04/07 04:29:03 minchau Exp $
018: */
019: package org.apache.xml.serializer;
020:
021: import org.apache.xml.serializer.utils.StringToIntTable;
022:
023: /**
024: * This class has a series of flags (bit values) that describe an HTML element
025: *
026: * This class is public because XSLTC uses it, it is not a public API.
027: *
028: * @xsl.usage internal
029: */
030: public final class ElemDesc {
031: /** Bit flags to tell about this element type. */
032: private int m_flags;
033:
034: /**
035: * Table of attribute names to integers, which contain bit flags telling about
036: * the attributes.
037: */
038: private StringToIntTable m_attrs = null;
039:
040: /** Bit position if this element type is empty. */
041: static final int EMPTY = (1 << 1);
042:
043: /** Bit position if this element type is a flow. */
044: private static final int FLOW = (1 << 2);
045:
046: /** Bit position if this element type is a block. */
047: static final int BLOCK = (1 << 3);
048:
049: /** Bit position if this element type is a block form. */
050: static final int BLOCKFORM = (1 << 4);
051:
052: /** Bit position if this element type is a block form field set. */
053: static final int BLOCKFORMFIELDSET = (1 << 5);
054:
055: /** Bit position if this element type is CDATA. */
056: private static final int CDATA = (1 << 6);
057:
058: /** Bit position if this element type is PCDATA. */
059: private static final int PCDATA = (1 << 7);
060:
061: /** Bit position if this element type is should be raw characters. */
062: static final int RAW = (1 << 8);
063:
064: /** Bit position if this element type should be inlined. */
065: private static final int INLINE = (1 << 9);
066:
067: /** Bit position if this element type is INLINEA. */
068: private static final int INLINEA = (1 << 10);
069:
070: /** Bit position if this element type is an inline label. */
071: static final int INLINELABEL = (1 << 11);
072:
073: /** Bit position if this element type is a font style. */
074: static final int FONTSTYLE = (1 << 12);
075:
076: /** Bit position if this element type is a phrase. */
077: static final int PHRASE = (1 << 13);
078:
079: /** Bit position if this element type is a form control. */
080: static final int FORMCTRL = (1 << 14);
081:
082: /** Bit position if this element type is ???. */
083: static final int SPECIAL = (1 << 15);
084:
085: /** Bit position if this element type is ???. */
086: static final int ASPECIAL = (1 << 16);
087:
088: /** Bit position if this element type is an odd header element. */
089: static final int HEADMISC = (1 << 17);
090:
091: /** Bit position if this element type is a head element (i.e. H1, H2, etc.) */
092: static final int HEAD = (1 << 18);
093:
094: /** Bit position if this element type is a list. */
095: static final int LIST = (1 << 19);
096:
097: /** Bit position if this element type is a preformatted type. */
098: static final int PREFORMATTED = (1 << 20);
099:
100: /** Bit position if this element type is whitespace sensitive. */
101: static final int WHITESPACESENSITIVE = (1 << 21);
102:
103: /** Bit position if this element type is a header element (i.e. HEAD). */
104: static final int HEADELEM = (1 << 22);
105:
106: /** Bit position if this element is the "HTML" element */
107: private static final int HTMLELEM = (1 << 23);
108:
109: /** Bit position if this attribute type is a URL. */
110: public static final int ATTRURL = (1 << 1);
111:
112: /** Bit position if this attribute type is an empty type. */
113: public static final int ATTREMPTY = (1 << 2);
114:
115: /**
116: * Construct an ElemDesc from a set of bit flags.
117: *
118: *
119: * @param flags Bit flags that describe the basic properties of this element type.
120: */
121: ElemDesc(int flags) {
122: m_flags = flags;
123: }
124:
125: /**
126: * Tell if this element type has the basic bit properties that are passed
127: * as an argument.
128: *
129: * @param flags Bit flags that describe the basic properties of interest.
130: *
131: * @return true if any of the flag bits are true.
132: */
133: private boolean is(int flags) {
134:
135: // int which = (m_flags & flags);
136: return (m_flags & flags) != 0;
137: }
138:
139: int getFlags() {
140: return m_flags;
141: }
142:
143: /**
144: * Set an attribute name and it's bit properties.
145: *
146: *
147: * @param name non-null name of attribute, in upper case.
148: * @param flags flag bits.
149: */
150: void setAttr(String name, int flags) {
151:
152: if (null == m_attrs)
153: m_attrs = new StringToIntTable();
154:
155: m_attrs.put(name, flags);
156: }
157:
158: /**
159: * Tell if any of the bits of interest are set for a named attribute type.
160: *
161: * @param name non-null reference to attribute name, in any case.
162: * @param flags flag mask.
163: *
164: * @return true if any of the flags are set for the named attribute.
165: */
166: public boolean isAttrFlagSet(String name, int flags) {
167: return (null != m_attrs) ? ((m_attrs.getIgnoreCase(name) & flags) != 0)
168: : false;
169: }
170: }
|