12005
|
1 |
/*
|
|
2 |
* reserved comment block
|
|
3 |
* DO NOT REMOVE OR ALTER!
|
|
4 |
*/
|
|
5 |
/*
|
|
6 |
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
7 |
* contributor license agreements. See the NOTICE file distributed with
|
|
8 |
* this work for additional information regarding copyright ownership.
|
|
9 |
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
10 |
* (the "License"); you may not use this file except in compliance with
|
|
11 |
* the License. You may obtain a copy of the License at
|
|
12 |
*
|
|
13 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
14 |
*
|
|
15 |
* Unless required by applicable law or agreed to in writing, software
|
|
16 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18 |
* See the License for the specific language governing permissions and
|
|
19 |
* limitations under the License.
|
|
20 |
*/
|
|
21 |
|
|
22 |
package com.sun.org.apache.xerces.internal.util;
|
|
23 |
|
|
24 |
|
|
25 |
import java.util.Collections;
|
|
26 |
import java.util.Enumeration;
|
|
27 |
import java.util.List;
|
|
28 |
import java.util.TreeSet;
|
|
29 |
import java.util.Vector;
|
|
30 |
|
|
31 |
import javax.xml.XMLConstants;
|
|
32 |
|
|
33 |
import com.sun.org.apache.xerces.internal.xni.NamespaceContext;
|
|
34 |
|
|
35 |
/**
|
|
36 |
* <p>A read-only XNI wrapper around a JAXP NamespaceContext.</p>
|
|
37 |
*
|
|
38 |
* @author Michael Glavassevich, IBM
|
|
39 |
*
|
|
40 |
*/
|
|
41 |
public final class JAXPNamespaceContextWrapper implements NamespaceContext {
|
|
42 |
|
|
43 |
private javax.xml.namespace.NamespaceContext fNamespaceContext;
|
|
44 |
private SymbolTable fSymbolTable;
|
|
45 |
private List fPrefixes;
|
|
46 |
private final Vector fAllPrefixes = new Vector();
|
|
47 |
|
|
48 |
private int[] fContext = new int[8];
|
|
49 |
private int fCurrentContext;
|
|
50 |
|
|
51 |
public JAXPNamespaceContextWrapper(SymbolTable symbolTable) {
|
|
52 |
setSymbolTable(symbolTable);
|
|
53 |
}
|
|
54 |
|
|
55 |
public void setNamespaceContext(javax.xml.namespace.NamespaceContext context) {
|
|
56 |
fNamespaceContext = context;
|
|
57 |
}
|
|
58 |
|
|
59 |
public javax.xml.namespace.NamespaceContext getNamespaceContext() {
|
|
60 |
return fNamespaceContext;
|
|
61 |
}
|
|
62 |
|
|
63 |
public void setSymbolTable(SymbolTable symbolTable) {
|
|
64 |
fSymbolTable = symbolTable;
|
|
65 |
}
|
|
66 |
|
|
67 |
public SymbolTable getSymbolTable() {
|
|
68 |
return fSymbolTable;
|
|
69 |
}
|
|
70 |
|
|
71 |
public void setDeclaredPrefixes(List prefixes) {
|
|
72 |
fPrefixes = prefixes;
|
|
73 |
}
|
|
74 |
|
|
75 |
public List getDeclaredPrefixes() {
|
|
76 |
return fPrefixes;
|
|
77 |
}
|
|
78 |
|
|
79 |
/*
|
|
80 |
* NamespaceContext methods
|
|
81 |
*/
|
|
82 |
|
|
83 |
public String getURI(String prefix) {
|
|
84 |
if (fNamespaceContext != null) {
|
|
85 |
String uri = fNamespaceContext.getNamespaceURI(prefix);
|
|
86 |
if (uri != null && !XMLConstants.NULL_NS_URI.equals(uri)) {
|
|
87 |
return (fSymbolTable != null) ? fSymbolTable.addSymbol(uri) : uri.intern();
|
|
88 |
}
|
|
89 |
}
|
|
90 |
return null;
|
|
91 |
}
|
|
92 |
|
|
93 |
public String getPrefix(String uri) {
|
|
94 |
if (fNamespaceContext != null) {
|
|
95 |
if (uri == null) {
|
|
96 |
uri = XMLConstants.NULL_NS_URI;
|
|
97 |
}
|
|
98 |
String prefix = fNamespaceContext.getPrefix(uri);
|
|
99 |
if (prefix == null) {
|
|
100 |
prefix = XMLConstants.DEFAULT_NS_PREFIX;
|
|
101 |
}
|
|
102 |
return (fSymbolTable != null) ? fSymbolTable.addSymbol(prefix) : prefix.intern();
|
|
103 |
}
|
|
104 |
return null;
|
|
105 |
}
|
|
106 |
|
|
107 |
public Enumeration getAllPrefixes() {
|
|
108 |
// There may be duplicate prefixes in the list so we
|
|
109 |
// first transfer them to a set to ensure uniqueness.
|
|
110 |
return Collections.enumeration(new TreeSet(fAllPrefixes));
|
|
111 |
}
|
|
112 |
|
|
113 |
public void pushContext() {
|
|
114 |
// extend the array, if necessary
|
|
115 |
if (fCurrentContext + 1 == fContext.length) {
|
|
116 |
int[] contextarray = new int[fContext.length * 2];
|
|
117 |
System.arraycopy(fContext, 0, contextarray, 0, fContext.length);
|
|
118 |
fContext = contextarray;
|
|
119 |
}
|
|
120 |
// push context
|
|
121 |
fContext[++fCurrentContext] = fAllPrefixes.size();
|
|
122 |
if (fPrefixes != null) {
|
|
123 |
fAllPrefixes.addAll(fPrefixes);
|
|
124 |
}
|
|
125 |
}
|
|
126 |
|
|
127 |
public void popContext() {
|
|
128 |
fAllPrefixes.setSize(fContext[fCurrentContext--]);
|
|
129 |
}
|
|
130 |
|
|
131 |
public boolean declarePrefix(String prefix, String uri) {
|
|
132 |
return true;
|
|
133 |
}
|
|
134 |
|
|
135 |
public int getDeclaredPrefixCount() {
|
|
136 |
return (fPrefixes != null) ? fPrefixes.size() : 0;
|
|
137 |
}
|
|
138 |
|
|
139 |
public String getDeclaredPrefixAt(int index) {
|
|
140 |
return (String) fPrefixes.get(index);
|
|
141 |
}
|
|
142 |
|
|
143 |
public void reset() {
|
|
144 |
fCurrentContext = 0;
|
|
145 |
fContext[fCurrentContext] = 0;
|
|
146 |
fAllPrefixes.clear();
|
|
147 |
}
|
|
148 |
|
|
149 |
} // JAXPNamespaceContextWrapper
|