01: package net.sf.saxon.tree;
02:
03: /**
04: * System IDs are not held in nodes in the tree, because they are usually the same
05: * for a whole document.
06: * This class provides a map from element sequence numbers to System IDs: it is
07: * linked to the root node of the tree.
08: * Note that the System ID is not necessarily the same as the Base URI. The System ID relates
09: * to the external entity in which a node was physically located; this provides a default for
10: * the Base URI, but this may be modified by specifying an xml:base attribute
11: *
12: * @author Michael H. Kay
13: */
14:
15: public class SystemIdMap {
16:
17: private int[] sequenceNumbers;
18: private String[] uris;
19: private int allocated;
20:
21: public SystemIdMap() {
22: sequenceNumbers = new int[10];
23: uris = new String[10];
24: allocated = 0;
25: }
26:
27: /**
28: * Set the system ID corresponding to a given sequence number
29: */
30:
31: public void setSystemId(int sequence, String uri) {
32: // ignore it if same as previous
33: if (allocated > 0 && uri.equals(uris[allocated - 1])) {
34: return;
35: }
36: if (sequenceNumbers.length <= allocated + 1) {
37: int[] s = new int[allocated * 2];
38: String[] u = new String[allocated * 2];
39: System.arraycopy(sequenceNumbers, 0, s, 0, allocated);
40: System.arraycopy(uris, 0, u, 0, allocated);
41: sequenceNumbers = s;
42: uris = u;
43: }
44: sequenceNumbers[allocated] = sequence;
45: uris[allocated] = uri;
46: allocated++;
47: }
48:
49: /**
50: * Get the system ID corresponding to a given sequence number
51: */
52:
53: public String getSystemId(int sequence) {
54: if (allocated == 0)
55: return null;
56: // could use a binary chop, but it's not important
57: for (int i = 1; i < allocated; i++) {
58: if (sequenceNumbers[i] > sequence) {
59: return uris[i - 1];
60: }
61: }
62: return uris[allocated - 1];
63: }
64:
65: }
66:
67: //
68: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
69: // you may not use this file except in compliance with the License. You may obtain a copy of the
70: // License at http://www.mozilla.org/MPL/
71: //
72: // Software distributed under the License is distributed on an "AS IS" basis,
73: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
74: // See the License for the specific language governing rights and limitations under the License.
75: //
76: // The Original Code is: all this file.
77: //
78: // The Initial Developer of the Original Code is Michael H. Kay.
79: //
80: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
81: //
82: // Contributor(s): none.
83: //
|