1 /*
2 * reserved comment block
3 * DO NOT REMOVE OR ALTER!
4 */
5 /*
6 * Copyright 2001-2004 The Apache Software Foundation.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20 /*
21 * $Id: TemplatesHandlerImpl.java,v 1.2.4.1 2005/09/06 12:09:03 pvedula Exp $
22 */
23
24 package com.sun.org.apache.xalan.internal.xsltc.trax;
25
26 import javax.xml.XMLConstants;
27 import javax.xml.transform.Source;
28 import javax.xml.transform.Templates;
29 import javax.xml.transform.TransformerException;
30 import javax.xml.transform.URIResolver;
31 import javax.xml.transform.sax.TemplatesHandler;
32 import com.sun.org.apache.xalan.internal.XalanConstants;
33 import com.sun.org.apache.xalan.internal.xsltc.compiler.CompilerException;
34 import com.sun.org.apache.xalan.internal.xsltc.compiler.Parser;
35 import com.sun.org.apache.xalan.internal.xsltc.compiler.SourceLoader;
36 import com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet;
37 import com.sun.org.apache.xalan.internal.xsltc.compiler.SyntaxTreeNode;
38 import com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC;
39 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
40
41 import org.xml.sax.ContentHandler;
42 import org.xml.sax.InputSource;
43 import org.xml.sax.Locator;
44 import org.xml.sax.SAXException;
45 import org.xml.sax.Attributes;
46
47 import java.util.Vector;
48
49 /**
50 * Implementation of a JAXP1.1 TemplatesHandler
51 * @author Morten Jorgensen
52 * @author Santiago Pericas-Geertsen
53 */
54 public class TemplatesHandlerImpl
55 implements ContentHandler, TemplatesHandler, SourceLoader
56 {
57 /**
58 * System ID for this stylesheet.
59 */
60 private String _systemId;
61
62 /**
63 * Number of spaces to add for output indentation.
64 */
65 private int _indentNumber;
66
67 /**
252 stylesheet.translate();
253 }
254 }
255
256 if (!_parser.errorsFound()) {
257 // Check that the transformation went well before returning
258 final byte[][] bytecodes = xsltc.getBytecodes();
259 if (bytecodes != null) {
260 _templates =
261 new TemplatesImpl(xsltc.getBytecodes(), transletName,
262 _parser.getOutputProperties(), _indentNumber, _tfactory);
263
264 // Set URIResolver on templates object
265 if (_uriResolver != null) {
266 _templates.setURIResolver(_uriResolver);
267 }
268 }
269 }
270 else {
271 StringBuffer errorMessage = new StringBuffer();
272 Vector errors = _parser.getErrors();
273 final int count = errors.size();
274 for (int i = 0; i < count; i++) {
275 if (errorMessage.length() > 0)
276 errorMessage.append('\n');
277 errorMessage.append(errors.elementAt(i).toString());
278 }
279 throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, new TransformerException(errorMessage.toString()));
280 }
281 }
282 catch (CompilerException e) {
283 throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, e);
284 }
285 }
286
287 /**
288 * Just forward SAX2 event to parser object.
289 */
290 public void startPrefixMapping(String prefix, String uri) {
291 _parser.startPrefixMapping(prefix, uri);
292 }
293
294 /**
295 * Just forward SAX2 event to parser object.
296 */
297 public void endPrefixMapping(String prefix) {
|
1 /*
2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3 */
4 /*
5 * Copyright 2001-2004 The Apache Software Foundation.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20 package com.sun.org.apache.xalan.internal.xsltc.trax;
21
22 import javax.xml.XMLConstants;
23 import javax.xml.transform.Source;
24 import javax.xml.transform.Templates;
25 import javax.xml.transform.TransformerException;
26 import javax.xml.transform.URIResolver;
27 import javax.xml.transform.sax.TemplatesHandler;
28 import com.sun.org.apache.xalan.internal.XalanConstants;
29 import com.sun.org.apache.xalan.internal.xsltc.compiler.CompilerException;
30 import com.sun.org.apache.xalan.internal.xsltc.compiler.Parser;
31 import com.sun.org.apache.xalan.internal.xsltc.compiler.SourceLoader;
32 import com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet;
33 import com.sun.org.apache.xalan.internal.xsltc.compiler.SyntaxTreeNode;
34 import com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC;
35 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
36
37 import org.xml.sax.ContentHandler;
38 import org.xml.sax.InputSource;
39 import org.xml.sax.Locator;
40 import org.xml.sax.SAXException;
41 import org.xml.sax.Attributes;
42
43 import java.util.ArrayList;
44
45 /**
46 * Implementation of a JAXP1.1 TemplatesHandler
47 * @author Morten Jorgensen
48 * @author Santiago Pericas-Geertsen
49 */
50 public class TemplatesHandlerImpl
51 implements ContentHandler, TemplatesHandler, SourceLoader
52 {
53 /**
54 * System ID for this stylesheet.
55 */
56 private String _systemId;
57
58 /**
59 * Number of spaces to add for output indentation.
60 */
61 private int _indentNumber;
62
63 /**
248 stylesheet.translate();
249 }
250 }
251
252 if (!_parser.errorsFound()) {
253 // Check that the transformation went well before returning
254 final byte[][] bytecodes = xsltc.getBytecodes();
255 if (bytecodes != null) {
256 _templates =
257 new TemplatesImpl(xsltc.getBytecodes(), transletName,
258 _parser.getOutputProperties(), _indentNumber, _tfactory);
259
260 // Set URIResolver on templates object
261 if (_uriResolver != null) {
262 _templates.setURIResolver(_uriResolver);
263 }
264 }
265 }
266 else {
267 StringBuffer errorMessage = new StringBuffer();
268 ArrayList<ErrorMsg> errors = _parser.getErrors();
269 final int count = errors.size();
270 for (int i = 0; i < count; i++) {
271 if (errorMessage.length() > 0)
272 errorMessage.append('\n');
273 errorMessage.append(errors.get(i).toString());
274 }
275 throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, new TransformerException(errorMessage.toString()));
276 }
277 }
278 catch (CompilerException e) {
279 throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, e);
280 }
281 }
282
283 /**
284 * Just forward SAX2 event to parser object.
285 */
286 public void startPrefixMapping(String prefix, String uri) {
287 _parser.startPrefixMapping(prefix, uri);
288 }
289
290 /**
291 * Just forward SAX2 event to parser object.
292 */
293 public void endPrefixMapping(String prefix) {
|