01: package net.sf.saxon.event;
02:
03: import net.sf.saxon.om.NamePool;
04: import net.sf.saxon.trans.XPathException;
05:
06: /**
07: * This class is a filter that passes all Receiver events through unchanged,
08: * except that it changes namecodes to allow for the source and the destination
09: * using different NamePools. This is necessary when a stylesheet has been constructed
10: * as a general document (e.g. as the result of a transformation) and is passed to
11: * newTemplates() to be compiled as a stylesheet.
12: *
13: * @author Michael Kay
14: */
15:
16: public class NamePoolConverter extends ProxyReceiver {
17:
18: NamePool oldPool;
19: NamePool newPool;
20:
21: /**
22: * Constructor
23: */
24:
25: public NamePoolConverter(NamePool oldPool, NamePool newPool) {
26: this .oldPool = oldPool;
27: this .newPool = newPool;
28: }
29:
30: /**
31: * Set the underlying emitter. This call is mandatory before using the Emitter.
32: * This version is modified from that of the parent class to avoid setting the namePool
33: * of the destination Receiver.
34: */
35:
36: public void setUnderlyingReceiver(Receiver receiver) {
37: nextReceiver = receiver;
38: }
39:
40: /**
41: * Output element start tag
42: */
43:
44: public void startElement(int nameCode, int typeCode,
45: int locationId, int properties) throws XPathException {
46: int nc = newPool.allocate(oldPool.getPrefix(nameCode), oldPool
47: .getURI(nameCode), oldPool.getLocalName(nameCode));
48: super .startElement(nc, typeCode, locationId, properties);
49: }
50:
51: /**
52: * Handle a namespace
53: */
54:
55: public void namespace(int namespaceCode, int properties)
56: throws XPathException {
57: int nc = newPool.allocateNamespaceCode(oldPool
58: .getPrefixFromNamespaceCode(namespaceCode), oldPool
59: .getURIFromNamespaceCode(namespaceCode));
60: super .namespace(nc, properties);
61: }
62:
63: /**
64: * Handle an attribute
65: */
66:
67: public void attribute(int nameCode, int typeCode,
68: CharSequence value, int locationId, int properties)
69: throws XPathException {
70: int nc = newPool.allocate(oldPool.getPrefix(nameCode), oldPool
71: .getURI(nameCode), oldPool.getLocalName(nameCode));
72: super .attribute(nc, typeCode, value, locationId, properties);
73: }
74:
75: };
76:
77: //
78: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
79: // you may not use this file except in compliance with the License. You may obtain a copy of the
80: // License at http://www.mozilla.org/MPL/
81: //
82: // Software distributed under the License is distributed on an "AS IS" basis,
83: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
84: // See the License for the specific language governing rights and limitations under the License.
85: //
86: // The Original Code is: all this file.
87: //
88: // The Initial Developer of the Original Code is Michael H. Kay
89: //
90: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
91: //
92: // Contributor(s): none.
93: //
|