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