6
|
1 |
/*
|
|
2 |
* reserved comment block
|
|
3 |
* DO NOT REMOVE OR ALTER!
|
|
4 |
*/
|
|
5 |
|
|
6 |
/*
|
|
7 |
* Copyright 2001-2004 The Apache Software Foundation.
|
|
8 |
*
|
|
9 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10 |
* you may not use this file except in compliance with the License.
|
|
11 |
* 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 |
* $Id: XSLTCSource.java,v 1.2.4.1 2005/09/06 12:43:28 pvedula Exp $
|
|
23 |
*/
|
|
24 |
|
|
25 |
package com.sun.org.apache.xalan.internal.xsltc.trax;
|
|
26 |
|
|
27 |
import javax.xml.transform.Source;
|
|
28 |
import javax.xml.transform.stream.StreamSource;
|
|
29 |
|
|
30 |
import com.sun.org.apache.xalan.internal.xsltc.DOM;
|
|
31 |
import com.sun.org.apache.xalan.internal.xsltc.StripFilter;
|
|
32 |
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
|
33 |
import com.sun.org.apache.xalan.internal.xsltc.dom.DOMWSFilter;
|
|
34 |
import com.sun.org.apache.xalan.internal.xsltc.dom.SAXImpl;
|
|
35 |
import com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager;
|
|
36 |
import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
|
|
37 |
|
|
38 |
import org.xml.sax.SAXException;
|
|
39 |
|
|
40 |
/**
|
|
41 |
* @author Morten Jorgensen
|
|
42 |
*/
|
|
43 |
public final class XSLTCSource implements Source {
|
|
44 |
|
|
45 |
private String _systemId = null;
|
|
46 |
private Source _source = null;
|
|
47 |
private ThreadLocal _dom = new ThreadLocal();
|
|
48 |
|
|
49 |
/**
|
|
50 |
* Create a new XSLTC-specific source from a system ID
|
|
51 |
*/
|
|
52 |
public XSLTCSource(String systemId)
|
|
53 |
{
|
|
54 |
_systemId = systemId;
|
|
55 |
}
|
|
56 |
|
|
57 |
/**
|
|
58 |
* Create a new XSLTC-specific source from a JAXP Source
|
|
59 |
*/
|
|
60 |
public XSLTCSource(Source source)
|
|
61 |
{
|
|
62 |
_source = source;
|
|
63 |
}
|
|
64 |
|
|
65 |
/**
|
|
66 |
* Implements javax.xml.transform.Source.setSystemId()
|
|
67 |
* Set the system identifier for this Source.
|
|
68 |
* This Source can get its input either directly from a file (in this case
|
|
69 |
* it will instanciate and use a JAXP parser) or it can receive it through
|
|
70 |
* ContentHandler/LexicalHandler interfaces.
|
|
71 |
* @param systemId The system Id for this Source
|
|
72 |
*/
|
|
73 |
public void setSystemId(String systemId) {
|
|
74 |
_systemId = systemId;
|
|
75 |
if (_source != null) {
|
|
76 |
_source.setSystemId(systemId);
|
|
77 |
}
|
|
78 |
}
|
|
79 |
|
|
80 |
/**
|
|
81 |
* Implements javax.xml.transform.Source.getSystemId()
|
|
82 |
* Get the system identifier that was set with setSystemId.
|
|
83 |
* @return The system identifier that was set with setSystemId,
|
|
84 |
* or null if setSystemId was not called.
|
|
85 |
*/
|
|
86 |
public String getSystemId() {
|
|
87 |
if (_source != null) {
|
|
88 |
return _source.getSystemId();
|
|
89 |
}
|
|
90 |
else {
|
|
91 |
return(_systemId);
|
|
92 |
}
|
|
93 |
}
|
|
94 |
|
|
95 |
/**
|
|
96 |
* Internal interface which returns a DOM for a given DTMManager and translet.
|
|
97 |
*/
|
|
98 |
protected DOM getDOM(XSLTCDTMManager dtmManager, AbstractTranslet translet)
|
|
99 |
throws SAXException
|
|
100 |
{
|
|
101 |
SAXImpl idom = (SAXImpl)_dom.get();
|
|
102 |
|
|
103 |
if (idom != null) {
|
|
104 |
if (dtmManager != null) {
|
|
105 |
idom.migrateTo(dtmManager);
|
|
106 |
}
|
|
107 |
}
|
|
108 |
else {
|
|
109 |
Source source = _source;
|
|
110 |
if (source == null) {
|
|
111 |
if (_systemId != null && _systemId.length() > 0) {
|
|
112 |
source = new StreamSource(_systemId);
|
|
113 |
}
|
|
114 |
else {
|
|
115 |
ErrorMsg err = new ErrorMsg(ErrorMsg.XSLTC_SOURCE_ERR);
|
|
116 |
throw new SAXException(err.toString());
|
|
117 |
}
|
|
118 |
}
|
|
119 |
|
|
120 |
DOMWSFilter wsfilter = null;
|
|
121 |
if (translet != null && translet instanceof StripFilter) {
|
|
122 |
wsfilter = new DOMWSFilter(translet);
|
|
123 |
}
|
|
124 |
|
|
125 |
boolean hasIdCall = (translet != null) ? translet.hasIdCall() : false;
|
|
126 |
|
|
127 |
if (dtmManager == null) {
|
|
128 |
dtmManager = XSLTCDTMManager.newInstance();
|
|
129 |
}
|
|
130 |
|
|
131 |
idom = (SAXImpl)dtmManager.getDTM(source, true, wsfilter, false, false, hasIdCall);
|
|
132 |
|
|
133 |
String systemId = getSystemId();
|
|
134 |
if (systemId != null) {
|
|
135 |
idom.setDocumentURI(systemId);
|
|
136 |
}
|
|
137 |
_dom.set(idom);
|
|
138 |
}
|
|
139 |
return idom;
|
|
140 |
}
|
|
141 |
|
|
142 |
}
|