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 2004/02/17 04:21:14 minchau Exp $
018: */
019: package org.apache.xml.utils;
020:
021: import java.util.Hashtable;
022:
023: /**
024: * This class is in support of SerializerToHTML, and acts as a sort
025: * of element representative for HTML elements.
026: * @xsl.usage internal
027: */
028: class ElemDesc {
029:
030: /** Table of attributes for the element */
031: Hashtable m_attrs = null;
032:
033: /** Element's flags, describing the role this element plays during
034: * formatting of the document. This is used as a bitvector; more than one flag
035: * may be set at a time, bitwise-ORed together. Mnemonic and bits
036: * have been assigned to the flag values. NOTE: Some bits are
037: * currently assigned multiple mnemonics; it is the caller's
038: * responsibility to disambiguate these if necessary. */
039: int m_flags;
040:
041: /** Defines mnemonic and bit-value for the EMPTY flag */
042: static final int EMPTY = (1 << 1);
043:
044: /** Defines mnemonic and bit-value for the FLOW flag */
045: static final int FLOW = (1 << 2);
046:
047: /** Defines mnemonic and bit-value for the BLOCK flag */
048: static final int BLOCK = (1 << 3);
049:
050: /** Defines mnemonic and bit-value for the BLOCKFORM flag */
051: static final int BLOCKFORM = (1 << 4);
052:
053: /** Defines mnemonic and bit-value for the BLOCKFORMFIELDSET flag */
054: static final int BLOCKFORMFIELDSET = (1 << 5);
055:
056: /** Defines mnemonic and bit-value for the CDATA flag */
057: static final int CDATA = (1 << 6);
058:
059: /** Defines mnemonic and bit-value for the PCDATA flag */
060: static final int PCDATA = (1 << 7);
061:
062: /** Defines mnemonic and bit-value for the RAW flag */
063: static final int RAW = (1 << 8);
064:
065: /** Defines mnemonic and bit-value for the INLINE flag */
066: static final int INLINE = (1 << 9);
067:
068: /** Defines mnemonic and bit-value for the INLINEA flag */
069: static final int INLINEA = (1 << 10);
070:
071: /** Defines mnemonic and bit-value for the INLINELABEL flag */
072: static final int INLINELABEL = (1 << 11);
073:
074: /** Defines mnemonic and bit-value for the FONTSTYLE flag */
075: static final int FONTSTYLE = (1 << 12);
076:
077: /** Defines mnemonic and bit-value for the PHRASE flag */
078: static final int PHRASE = (1 << 13);
079:
080: /** Defines mnemonic and bit-value for the FORMCTRL flag */
081: static final int FORMCTRL = (1 << 14);
082:
083: /** Defines mnemonic and bit-value for the SPECIAL flag */
084: static final int SPECIAL = (1 << 15);
085:
086: /** Defines mnemonic and bit-value for the ASPECIAL flag */
087: static final int ASPECIAL = (1 << 16);
088:
089: /** Defines mnemonic and bit-value for the HEADMISC flag */
090: static final int HEADMISC = (1 << 17);
091:
092: /** Defines mnemonic and bit-value for the HEAD flag */
093: static final int HEAD = (1 << 18);
094:
095: /** Defines mnemonic and bit-value for the LIST flag */
096: static final int LIST = (1 << 19);
097:
098: /** Defines mnemonic and bit-value for the PREFORMATTED flag */
099: static final int PREFORMATTED = (1 << 20);
100:
101: /** Defines mnemonic and bit-value for the WHITESPACESENSITIVE flag */
102: static final int WHITESPACESENSITIVE = (1 << 21);
103:
104: /** Defines mnemonic and bit-value for the ATTRURL flag */
105: static final int ATTRURL = (1 << 1);
106:
107: /** Defines mnemonic and bit-value for the ATTREMPTY flag */
108: static final int ATTREMPTY = (1 << 2);
109:
110: /**
111: * Construct an ElementDescription with an initial set of flags.
112: *
113: * @param flags Element flags
114: * @see m_flags
115: */
116: ElemDesc(int flags) {
117: m_flags = flags;
118: }
119:
120: /**
121: * "is (this element described by these flags)".
122: *
123: * This might more properly be called areFlagsSet(). It accepts an
124: * integer (being used as a bitvector) and checks whether all the
125: * corresponding bits are set in our internal flags. Note that this
126: * test is performed as a bitwise AND, not an equality test, so a
127: * 0 bit in the input means "don't test", not "must be set false".
128: *
129: * @param flags Vector of flags to compare against this element's flags
130: *
131: * @return true if the flags set in the parameter are also set in the
132: * element's stored flags.
133: *
134: * @see m_flags
135: * @see isAttrFlagSet
136: */
137: boolean is(int flags) {
138: // int which = (m_flags & flags);
139: return (m_flags & flags) != 0;
140: }
141:
142: /**
143: * Set a new attribute for this element
144: *
145: *
146: * @param name Attribute name
147: * @param flags Attibute flags
148: */
149: void setAttr(String name, int flags) {
150:
151: if (null == m_attrs)
152: m_attrs = new Hashtable();
153:
154: m_attrs.put(name, new Integer(flags));
155: }
156:
157: /**
158: * Find out if a flag is set in a given attribute of this element
159: *
160: *
161: * @param name Attribute name
162: * @param flags Flag to check
163: *
164: * @return True if the flag is set in the attribute. Returns false
165: * if the attribute is not found
166: * @see m_flags
167: */
168: boolean isAttrFlagSet(String name, int flags) {
169:
170: if (null != m_attrs) {
171: Integer _flags = (Integer) m_attrs.get(name);
172:
173: if (null != _flags) {
174: return (_flags.intValue() & flags) != 0;
175: }
176: }
177:
178: return false;
179: }
180: }
|