Skip to main content
summaryrefslogtreecommitdiffstats
blob: 1eb009d3a4d39149ff5f28ae5935356824cbc5e3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*******************************************************************************
 * Copyright (c) 2001, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.wst.dtd.core.internal.saxparser;

public class ExternalID {
	private static final int T_SYSTEM = 0;
	private static final int T_PUBLIC = 1;

	int type = T_PUBLIC;
	String publicID = null;
	String systemID = null;

	/**
	 * Constructor for system IDs.
	 * 
	 * @param systemID
	 *            URI, which may be used to retrieve an external entity's
	 *            content.
	 */
	public ExternalID(String systemID) {
		this.type = T_SYSTEM;
		this.publicID = null;
		this.systemID = systemID;
	}

	/**
	 * Constructor for public and system IDs.
	 * 
	 * @param publicID
	 *            Identifier to be used to try to generate an alternative URI
	 *            in order to retrieve the external entity's content, or
	 *            <var>null</var> if a system identitier is to be
	 *            constructed.
	 * @param systemID
	 *            URI, which may be used to retrieve an external entity's
	 *            content.
	 */
	public ExternalID(String publicID, String systemID) {
		this.type = T_PUBLIC;
		this.publicID = publicID;
		this.systemID = systemID;
		if (null == this.publicID)
			this.type = T_SYSTEM;
	}

	/**
	 * Returns if this external ID is a system ID (or public ID).
	 * 
	 * @return System ID=true, Public ID=false.
	 * @see #isPublic
	 */
	public boolean isSystem() {
		return this.type == T_SYSTEM;
	}

	/**
	 * Returns if this external ID is a public ID (or system ID).
	 * 
	 * @return Public ID=true, System ID=false.
	 * @see #isSystem
	 */
	public boolean isPublic() {
		return this.type == T_PUBLIC;
	}

	/**
	 * Returns the system identifier of this external ID. A system identifier
	 * is a URI, which may be used to retrieve an external entity's content.
	 * 
	 * @return The system identifier, or <var>null</var> if the identifier is
	 *         not defined.
	 * @see #getPubidLiteral
	 */
	public String getSystemLiteral() {
		return this.systemID;
	}

	/**
	 * Returns the public identifier of this external ID. This value is only
	 * valid if the identifier is defined as <var>public</var> (as opposed to
	 * <var>system</var>). Public identifiers may be used to try to generate
	 * an alternative URI in order to retrieve an external entity's content.
	 * If retrieval fails using the public identifier, an attempt must be made
	 * to retrieve content using the system identifier.
	 * 
	 * @return The public identifier, or <var>null</var> if the identifier is
	 *         not defined.
	 * @see #getSystemLiteral
	 */
	public String getPubIdLiteral() {
		return this.publicID;
	}

	/**
	 * Returns this external ID in the format it was declared: <CODE>SYSTEM
	 * &quot;<VAR>systemID</VAR>&quot;</CODE> or <CODE>PUBLIC &quot;<VAR>publicID</VAR>&quot;
	 * &quot;<VAR>systemID</VAR>&quot;</CODE>.
	 * 
	 * @return XML string representing the content of the external ID (never
	 *         <var>null</var>).
	 */
	public String toString() {
		String ret;
		if (isSystem()) {
			ret = "SYSTEM \"" + getSystemLiteral() + "\""; //$NON-NLS-1$ //$NON-NLS-2$
		}
		else if (null != getSystemLiteral()) {
			ret = "PUBLIC \"" + getPubIdLiteral() + "\" \"" + getSystemLiteral() + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		}
		else {
			ret = "PUBLIC \"" + getPubIdLiteral() + "\""; // for NOTATION //$NON-NLS-1$ //$NON-NLS-2$
		}
		return ret;
	}

	/**
	 * 
	 */
	public boolean equals(Object obj) {
		if (obj == null)
			return false;
		if (!(obj instanceof ExternalID))
			return false;
		ExternalID eid = (ExternalID) obj;
		if (!((eid.publicID == null && this.publicID == null) || eid.publicID != null && eid.publicID.equals(this.publicID)))
			return false;
		if (!((eid.systemID == null && this.systemID == null) || eid.systemID != null && eid.systemID.equals(this.systemID)))
			return false;
		return true;
	}


	/**
	 * 
	 */
	public int hashCode() {
		int retval = 0;
		if (publicID != null)
			retval = publicID.hashCode();
		if (systemID != null)
			retval += systemID.hashCode();
		return retval;
	}

}

Back to the top