|
1 | 1 | package org.jvnet.jaxb2_commons.xjc; |
2 | 2 |
|
3 | | -import java.io.File; |
4 | | -import java.lang.reflect.Field; |
5 | | - |
6 | 3 | import org.apache.tools.ant.BuildException; |
7 | | -import org.apache.tools.ant.types.Path; |
8 | 4 |
|
9 | 5 | public class XJC2Task extends com.sun.tools.xjc.XJC2Task { |
10 | 6 |
|
11 | | - @Override |
12 | | - public void execute() throws BuildException { |
| 7 | + private boolean disableXmlSecurity = true; |
13 | 8 |
|
14 | | - hack(); |
15 | | - super.execute(); |
| 9 | + public void setDisableXmlSecurity(boolean disableXmlSecurity) { |
| 10 | + this.disableXmlSecurity = disableXmlSecurity; |
16 | 11 | } |
17 | 12 |
|
18 | | - protected void hack() { |
19 | | - try { |
20 | | - final Field declaredField = getClass().getSuperclass() |
21 | | - .getDeclaredField("classpath"); |
22 | | - declaredField.setAccessible(true); |
23 | | - final Path path = (Path) declaredField.get(this); |
24 | | - if (path != null) { |
25 | | - for (String pathElement : path.list()) { |
26 | | - options.classpaths.add(new File(pathElement).toURI() |
27 | | - .toURL()); |
28 | | - } |
29 | | - } |
30 | | - } catch (Exception ex) { |
31 | | - throw new BuildException(ex); |
| 13 | + private String accessExternalSchema = "all"; |
| 14 | + |
| 15 | + public void setAccessExternalSchema(String accessExternalSchema) { |
| 16 | + this.accessExternalSchema = accessExternalSchema; |
| 17 | + } |
| 18 | + |
| 19 | + private String accessExternalDTD = "all"; |
| 20 | + |
| 21 | + public void setAccessExternalDTD(String accessExternalDTD) { |
| 22 | + this.accessExternalDTD = accessExternalDTD; |
| 23 | + } |
| 24 | + |
| 25 | + @Override |
| 26 | + public void execute() throws BuildException { |
| 27 | + this.options.disableXmlSecurity = this.disableXmlSecurity; |
| 28 | + if (accessExternalSchema != null) { |
| 29 | + System.setProperty("javax.xml.accessExternalSchema", |
| 30 | + accessExternalSchema); |
32 | 31 | } |
| 32 | + if (accessExternalDTD != null) { |
| 33 | + System.setProperty("javax.xml.accessExternalDTD", accessExternalDTD); |
| 34 | + } |
| 35 | + super.execute(); |
33 | 36 | } |
| 37 | + |
34 | 38 | } |
0 commit comments