12005
|
1 |
/*
|
47312
|
2 |
* Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* @LastModified: Sep 2017
|
12005
|
4 |
*/
|
|
5 |
/*
|
33349
|
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
|
12005
|
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: Include.java,v 1.8 2007/04/09 21:30:41 joehw Exp $
|
|
23 |
*/
|
|
24 |
|
|
25 |
package com.sun.org.apache.xalan.internal.xsltc.compiler;
|
|
26 |
|
17534
|
27 |
import com.sun.org.apache.xalan.internal.XalanConstants;
|
|
28 |
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
|
29 |
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
|
30 |
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
|
31 |
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
|
|
32 |
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
|
|
33 |
import com.sun.org.apache.xml.internal.utils.SystemIDResolver;
|
33349
|
34 |
import java.util.Iterator;
|
17534
|
35 |
import javax.xml.XMLConstants;
|
47312
|
36 |
import jdk.xml.internal.SecuritySupport;
|
12005
|
37 |
import org.xml.sax.InputSource;
|
|
38 |
import org.xml.sax.XMLReader;
|
|
39 |
|
|
40 |
/**
|
|
41 |
* @author Jacek Ambroziak
|
|
42 |
* @author Morten Jorgensen
|
|
43 |
* @author Erwin Bolwidt <ejb@klomp.org>
|
|
44 |
* @author Gunnlaugur Briem <gthb@dimon.is>
|
|
45 |
*/
|
|
46 |
final class Include extends TopLevelElement {
|
|
47 |
|
|
48 |
private Stylesheet _included = null;
|
|
49 |
|
|
50 |
public Stylesheet getIncludedStylesheet() {
|
|
51 |
return _included;
|
|
52 |
}
|
|
53 |
|
|
54 |
public void parseContents(final Parser parser) {
|
|
55 |
XSLTC xsltc = parser.getXSLTC();
|
|
56 |
Stylesheet context = parser.getCurrentStylesheet();
|
|
57 |
|
|
58 |
String docToLoad = getAttribute("href");
|
|
59 |
try {
|
|
60 |
if (context.checkForLoop(docToLoad)) {
|
|
61 |
final ErrorMsg msg = new ErrorMsg(ErrorMsg.CIRCULAR_INCLUDE_ERR,
|
|
62 |
docToLoad, this);
|
|
63 |
parser.reportError(Constants.FATAL, msg);
|
|
64 |
return;
|
|
65 |
}
|
|
66 |
|
|
67 |
InputSource input = null;
|
|
68 |
XMLReader reader = null;
|
|
69 |
String currLoadedDoc = context.getSystemId();
|
|
70 |
SourceLoader loader = context.getSourceLoader();
|
|
71 |
|
|
72 |
// Use SourceLoader if available
|
|
73 |
if (loader != null) {
|
|
74 |
input = loader.loadSource(docToLoad, currLoadedDoc, xsltc);
|
|
75 |
if (input != null) {
|
|
76 |
docToLoad = input.getSystemId();
|
|
77 |
reader = xsltc.getXMLReader();
|
|
78 |
} else if (parser.errorsFound()) {
|
|
79 |
return;
|
|
80 |
}
|
|
81 |
}
|
|
82 |
|
|
83 |
// No SourceLoader or not resolved by SourceLoader
|
|
84 |
if (input == null) {
|
|
85 |
docToLoad = SystemIDResolver.getAbsoluteURI(docToLoad, currLoadedDoc);
|
17534
|
86 |
String accessError = SecuritySupport.checkAccess(docToLoad,
|
20968
|
87 |
(String)xsltc.getProperty(XMLConstants.ACCESS_EXTERNAL_STYLESHEET),
|
17534
|
88 |
XalanConstants.ACCESS_EXTERNAL_ALL);
|
|
89 |
|
|
90 |
if (accessError != null) {
|
|
91 |
final ErrorMsg msg = new ErrorMsg(ErrorMsg.ACCESSING_XSLT_TARGET_ERR,
|
|
92 |
SecuritySupport.sanitizePath(docToLoad), accessError,
|
|
93 |
this);
|
|
94 |
parser.reportError(Constants.FATAL, msg);
|
|
95 |
return;
|
|
96 |
}
|
12005
|
97 |
input = new InputSource(docToLoad);
|
|
98 |
}
|
|
99 |
|
|
100 |
// Return if we could not resolve the URL
|
|
101 |
if (input == null) {
|
|
102 |
final ErrorMsg msg =
|
|
103 |
new ErrorMsg(ErrorMsg.FILE_NOT_FOUND_ERR, docToLoad, this);
|
|
104 |
parser.reportError(Constants.FATAL, msg);
|
|
105 |
return;
|
|
106 |
}
|
|
107 |
|
|
108 |
final SyntaxTreeNode root;
|
|
109 |
if (reader != null) {
|
|
110 |
root = parser.parse(reader,input);
|
|
111 |
}
|
|
112 |
else {
|
|
113 |
root = parser.parse(input);
|
|
114 |
}
|
|
115 |
|
|
116 |
if (root == null) return;
|
|
117 |
_included = parser.makeStylesheet(root);
|
|
118 |
if (_included == null) return;
|
|
119 |
|
|
120 |
_included.setSourceLoader(loader);
|
|
121 |
_included.setSystemId(docToLoad);
|
|
122 |
_included.setParentStylesheet(context);
|
|
123 |
_included.setIncludingStylesheet(context);
|
|
124 |
_included.setTemplateInlining(context.getTemplateInlining());
|
|
125 |
|
|
126 |
// An included stylesheet gets the same import precedence
|
|
127 |
// as the stylesheet that included it.
|
|
128 |
final int precedence = context.getImportPrecedence();
|
|
129 |
_included.setImportPrecedence(precedence);
|
|
130 |
parser.setCurrentStylesheet(_included);
|
|
131 |
_included.parseContents(parser);
|
|
132 |
|
33349
|
133 |
final Iterator<SyntaxTreeNode> elements = _included.elements();
|
12005
|
134 |
final Stylesheet topStylesheet = parser.getTopLevelStylesheet();
|
33349
|
135 |
while (elements.hasNext()) {
|
|
136 |
final Object element = elements.next();
|
12005
|
137 |
if (element instanceof TopLevelElement) {
|
|
138 |
if (element instanceof Variable) {
|
|
139 |
topStylesheet.addVariable((Variable) element);
|
|
140 |
}
|
|
141 |
else if (element instanceof Param) {
|
|
142 |
topStylesheet.addParam((Param) element);
|
|
143 |
}
|
|
144 |
else {
|
|
145 |
topStylesheet.addElement((TopLevelElement) element);
|
|
146 |
}
|
|
147 |
}
|
|
148 |
}
|
|
149 |
}
|
|
150 |
catch (Exception e) {
|
|
151 |
e.printStackTrace();
|
|
152 |
}
|
|
153 |
finally {
|
|
154 |
parser.setCurrentStylesheet(context);
|
|
155 |
}
|
|
156 |
}
|
|
157 |
|
|
158 |
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
|
|
159 |
return Type.Void;
|
|
160 |
}
|
|
161 |
|
|
162 |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
|
163 |
// do nothing
|
|
164 |
}
|
|
165 |
}
|