|
49 | 49 | import org.springframework.messaging.Message;
|
50 | 50 | import org.springframework.messaging.MessagingException;
|
51 | 51 | import org.springframework.util.Assert;
|
| 52 | +import org.springframework.util.ClassUtils; |
52 | 53 | import org.springframework.util.ObjectUtils;
|
53 | 54 | import org.springframework.util.PatternMatchUtils;
|
54 | 55 | import org.springframework.util.StringUtils;
|
@@ -225,24 +226,39 @@ protected void onInit() {
|
225 | 226 | super.onInit();
|
226 | 227 | this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory());
|
227 | 228 | if (this.templates == null) {
|
228 |
| - TransformerFactory transformerFactory; |
229 |
| - if (this.transformerFactoryClassName != null) { |
230 |
| - transformerFactory = TransformerFactory.newInstance(this.transformerFactoryClassName, this.classLoader); |
231 |
| - } |
232 |
| - else { |
233 |
| - transformerFactory = TransformerFactoryUtils.newInstance(); |
234 |
| - } |
235 |
| - transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); |
236 |
| - transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "file,jar:file"); |
237 | 229 | try {
|
| 230 | + TransformerFactory transformerFactory = createTransformerFactory(); |
238 | 231 | this.templates = transformerFactory.newTemplates(createStreamSourceOnResource(this.xslResource));
|
239 | 232 | }
|
240 |
| - catch (TransformerConfigurationException | IOException e) { |
| 233 | + catch (ClassNotFoundException | TransformerConfigurationException | IOException e) { |
241 | 234 | throw new IllegalStateException(e);
|
242 | 235 | }
|
243 | 236 | }
|
244 | 237 | }
|
245 | 238 |
|
| 239 | + private TransformerFactory createTransformerFactory() throws ClassNotFoundException { |
| 240 | + TransformerFactory transformerFactory; |
| 241 | + if (this.transformerFactoryClassName != null) { |
| 242 | + @SuppressWarnings("unchecked") |
| 243 | + Class<TransformerFactory> transformerFactoryClass = |
| 244 | + (Class<TransformerFactory>) ClassUtils.forName(this.transformerFactoryClassName, this.classLoader); |
| 245 | + transformerFactory = TransformerFactoryUtils.newInstance(transformerFactoryClass); |
| 246 | + } |
| 247 | + else { |
| 248 | + transformerFactory = TransformerFactoryUtils.newInstance(); |
| 249 | + } |
| 250 | + try { |
| 251 | + transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "file,jar:file"); |
| 252 | + } |
| 253 | + catch (IllegalArgumentException ex) { |
| 254 | + if (logger.isInfoEnabled()) { |
| 255 | + logger.info("The '" + XMLConstants.ACCESS_EXTERNAL_STYLESHEET + "' property is not supported by " |
| 256 | + + transformerFactory.getClass().getCanonicalName()); |
| 257 | + } |
| 258 | + } |
| 259 | + return transformerFactory; |
| 260 | + } |
| 261 | + |
246 | 262 | @Override
|
247 | 263 | protected Object doTransform(Message<?> message) throws Exception {
|
248 | 264 | Transformer transformer = buildTransformer(message);
|
|
0 commit comments