1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xalan" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, Lotus
  53. * Development Corporation., http://www.lotus.com. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package org.apache.xml.utils;
  58. import java.util.Hashtable;
  59. /**
  60. * <meta name="usage" content="internal"/>
  61. * This class is in support of SerializerToHTML, and acts as a sort
  62. * of element representative for HTML elements.
  63. */
  64. class ElemDesc
  65. {
  66. /** Table of attributes for the element */
  67. Hashtable m_attrs = null;
  68. /** Element's flags, describing the role this element plays during
  69. * formatting of the document. This is used as a bitvector; more than one flag
  70. * may be set at a time, bitwise-ORed together. Mnemonic and bits
  71. * have been assigned to the flag values. NOTE: Some bits are
  72. * currently assigned multiple mnemonics; it is the caller's
  73. * responsibility to disambiguate these if necessary. */
  74. int m_flags;
  75. /** Defines mnemonic and bit-value for the EMPTY flag */
  76. static final int EMPTY = (1 << 1);
  77. /** Defines mnemonic and bit-value for the FLOW flag */
  78. static final int FLOW = (1 << 2);
  79. /** Defines mnemonic and bit-value for the BLOCK flag */
  80. static final int BLOCK = (1 << 3);
  81. /** Defines mnemonic and bit-value for the BLOCKFORM flag */
  82. static final int BLOCKFORM = (1 << 4);
  83. /** Defines mnemonic and bit-value for the BLOCKFORMFIELDSET flag */
  84. static final int BLOCKFORMFIELDSET = (1 << 5);
  85. /** Defines mnemonic and bit-value for the CDATA flag */
  86. static final int CDATA = (1 << 6);
  87. /** Defines mnemonic and bit-value for the PCDATA flag */
  88. static final int PCDATA = (1 << 7);
  89. /** Defines mnemonic and bit-value for the RAW flag */
  90. static final int RAW = (1 << 8);
  91. /** Defines mnemonic and bit-value for the INLINE flag */
  92. static final int INLINE = (1 << 9);
  93. /** Defines mnemonic and bit-value for the INLINEA flag */
  94. static final int INLINEA = (1 << 10);
  95. /** Defines mnemonic and bit-value for the INLINELABEL flag */
  96. static final int INLINELABEL = (1 << 11);
  97. /** Defines mnemonic and bit-value for the FONTSTYLE flag */
  98. static final int FONTSTYLE = (1 << 12);
  99. /** Defines mnemonic and bit-value for the PHRASE flag */
  100. static final int PHRASE = (1 << 13);
  101. /** Defines mnemonic and bit-value for the FORMCTRL flag */
  102. static final int FORMCTRL = (1 << 14);
  103. /** Defines mnemonic and bit-value for the SPECIAL flag */
  104. static final int SPECIAL = (1 << 15);
  105. /** Defines mnemonic and bit-value for the ASPECIAL flag */
  106. static final int ASPECIAL = (1 << 16);
  107. /** Defines mnemonic and bit-value for the HEADMISC flag */
  108. static final int HEADMISC = (1 << 17);
  109. /** Defines mnemonic and bit-value for the HEAD flag */
  110. static final int HEAD = (1 << 18);
  111. /** Defines mnemonic and bit-value for the LIST flag */
  112. static final int LIST = (1 << 19);
  113. /** Defines mnemonic and bit-value for the PREFORMATTED flag */
  114. static final int PREFORMATTED = (1 << 20);
  115. /** Defines mnemonic and bit-value for the WHITESPACESENSITIVE flag */
  116. static final int WHITESPACESENSITIVE = (1 << 21);
  117. /** Defines mnemonic and bit-value for the ATTRURL flag */
  118. static final int ATTRURL = (1 << 1);
  119. /** Defines mnemonic and bit-value for the ATTREMPTY flag */
  120. static final int ATTREMPTY = (1 << 2);
  121. /**
  122. * Construct an ElementDescription with an initial set of flags.
  123. *
  124. * @param flags Element flags
  125. * @see m_flags
  126. */
  127. ElemDesc(int flags)
  128. {
  129. m_flags = flags;
  130. }
  131. /**
  132. * "is (this element described by these flags)".
  133. *
  134. * This might more properly be called areFlagsSet(). It accepts an
  135. * integer (being used as a bitvector) and checks whether all the
  136. * corresponding bits are set in our internal flags. Note that this
  137. * test is performed as a bitwise AND, not an equality test, so a
  138. * 0 bit in the input means "don't test", not "must be set false".
  139. *
  140. * @param flags Vector of flags to compare against this element's flags
  141. *
  142. * @return true if the flags set in the parameter are also set in the
  143. * element's stored flags.
  144. *
  145. * @see m_flags
  146. * @see isAttrFlagSet
  147. */
  148. boolean is(int flags)
  149. {
  150. // int which = (m_flags & flags);
  151. return (m_flags & flags) != 0;
  152. }
  153. /**
  154. * Set a new attribute for this element
  155. *
  156. *
  157. * @param name Attribute name
  158. * @param flags Attibute flags
  159. */
  160. void setAttr(String name, int flags)
  161. {
  162. if (null == m_attrs)
  163. m_attrs = new Hashtable();
  164. m_attrs.put(name, new Integer(flags));
  165. }
  166. /**
  167. * Find out if a flag is set in a given attribute of this element
  168. *
  169. *
  170. * @param name Attribute name
  171. * @param flags Flag to check
  172. *
  173. * @return True if the flag is set in the attribute. Returns false
  174. * if the attribute is not found
  175. * @see m_flags
  176. */
  177. boolean isAttrFlagSet(String name, int flags)
  178. {
  179. if (null != m_attrs)
  180. {
  181. Integer _flags = (Integer) m_attrs.get(name);
  182. if (null != _flags)
  183. {
  184. return (_flags.intValue() & flags) != 0;
  185. }
  186. }
  187. return false;
  188. }
  189. }