01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package javax.swing.text.html.parser;
18:
19: public final class Entity implements DTDConstants {
20: public String name;
21:
22: public int type;
23:
24: public char[] data;
25:
26: private final static int GENERAL_MASK = DTDConstants.GENERAL;
27:
28: private final static int PARAMETER_MASK = DTDConstants.PARAMETER;
29:
30: public Entity(final String name, final int type, final char[] data) {
31: this .name = name;
32: this .type = type;
33: this .data = data;
34: }
35:
36: Entity(final String name, final int type, final String data,
37: final boolean isGeneral, final boolean isParameter) {
38: this (
39: name,
40: (type | (isGeneral ? GENERAL_MASK : 0) | (isParameter ? PARAMETER_MASK
41: : 0)), data.toCharArray());
42: }
43:
44: Entity(final String name, final char ch) {
45: this (name, DTDConstants.CDATA | GENERAL_MASK, new char[] { ch });
46: }
47:
48: public String getString() {
49: return String.valueOf(data);
50: }
51:
52: public char[] getData() {
53: return data;
54: }
55:
56: public boolean isGeneral() {
57: return (type & GENERAL_MASK) != 0;
58: }
59:
60: public boolean isParameter() {
61: return (type & PARAMETER_MASK) != 0;
62: }
63:
64: public int getType() {
65: return type & 0xFFFF;
66: }
67:
68: public String getName() {
69: return name;
70: }
71:
72: public static int name2type(final String name) {
73: if (name.equals("PUBLIC")) {
74: return DTDConstants.PUBLIC;
75: } else if (name.equals("SDATA")) {
76: return DTDConstants.SDATA;
77: } else if (name.equals("PI")) {
78: return DTDConstants.PI;
79: } else if (name.equals("STARTTAG")) {
80: return DTDConstants.STARTTAG;
81: } else if (name.equals("ENDTAG")) {
82: return DTDConstants.ENDTAG;
83: } else if (name.equals("MS")) {
84: return DTDConstants.MS;
85: } else if (name.equals("MD")) {
86: return DTDConstants.MD;
87: } else if (name.equals("SYSTEM")) {
88: return DTDConstants.SYSTEM;
89: } else {
90: return DTDConstants.CDATA;
91: }
92: }
93: }
|