|
16 | 16 | import java.util.Collections; |
17 | 17 | import java.util.HashMap; |
18 | 18 | import java.util.Map; |
| 19 | +import javax.xml.XMLConstants; |
19 | 20 | import javax.xml.transform.TransformerConfigurationException; |
20 | 21 | import javax.xml.transform.TransformerFactory; |
21 | 22 |
|
@@ -88,18 +89,51 @@ public static Builder builder() { |
88 | 89 | } |
89 | 90 |
|
90 | 91 | /** |
91 | | - * The default instance which disables DTD loading but still |
| 92 | + * The default instance which disables DTD loading and extension functions but still |
92 | 93 | * allows loading of external stylesheets. |
93 | 94 | */ |
94 | 95 | public static final TransformerFactoryConfigurer Default = builder() |
95 | 96 | .withDTDLoadingDisabled() |
| 97 | + .withExtensionFunctionsDisabled() |
| 98 | + .build(); |
| 99 | + |
| 100 | + /** |
| 101 | + * The instance which enables secure processing thus disables all external access as well as execution of extension |
| 102 | + * functions. |
| 103 | + * |
| 104 | + * @since XMLUnit 2.10.0 |
| 105 | + */ |
| 106 | + public static final TransformerFactoryConfigurer SecureProcessing = builder() |
| 107 | + .withSecureProcessingEnabled() |
96 | 108 | .build(); |
97 | 109 |
|
98 | 110 | /** |
99 | 111 | * The instance which disables DTD loading as well as loading of |
100 | | - * external stylesheets. |
| 112 | + * external stylesheets or extension functions. |
101 | 113 | */ |
102 | 114 | public static final TransformerFactoryConfigurer NoExternalAccess = builder() |
| 115 | + .withDTDLoadingDisabled() |
| 116 | + .withExternalStylesheetLoadingDisabled() |
| 117 | + .withExtensionFunctionsDisabled() |
| 118 | + .build(); |
| 119 | + |
| 120 | + /** |
| 121 | + * The instance which disables DTD loading but still |
| 122 | + * allows loading of external stylesheets and extension functions. |
| 123 | + * |
| 124 | + * @since XMLUnit 2.10.0 |
| 125 | + */ |
| 126 | + public static final TransformerFactoryConfigurer NoDtdButExtensionFunctions = builder() |
| 127 | + .withDTDLoadingDisabled() |
| 128 | + .build(); |
| 129 | + |
| 130 | + /** |
| 131 | + * The instance which disables DTD loading as well as loading of |
| 132 | + * external stylesheets but allows extension functions. |
| 133 | + * |
| 134 | + * @since XMLUnit 2.10.0 |
| 135 | + */ |
| 136 | + public static final TransformerFactoryConfigurer NoExternalAccessButExtensionFunctions = builder() |
103 | 137 | .withDTDLoadingDisabled() |
104 | 138 | .withExternalStylesheetLoadingDisabled() |
105 | 139 | .build(); |
@@ -192,5 +226,27 @@ public Builder withExternalStylesheetLoadingDisabled() { |
192 | 226 | // XMLConstants.ACCESS_EXTERNAL_STYLESHEET is not available in Java 6 |
193 | 227 | return withSafeAttribute("http://javax.xml.XMLConstants/property/accessExternalStylesheet", ""); |
194 | 228 | } |
| 229 | + |
| 230 | + /** |
| 231 | + * Configures the factory to not enable extension functions. |
| 232 | + * @return this |
| 233 | + * |
| 234 | + * @since XMLUnit 2.10.0 |
| 235 | + */ |
| 236 | + public Builder withExtensionFunctionsDisabled() { |
| 237 | + return withSafeAttribute("jdk.xml.enableExtensionFunctions", "false"); |
| 238 | + } |
| 239 | + |
| 240 | + /** |
| 241 | + * Configures the factory to enable secure processing which disables all external access as well as execution of |
| 242 | + * extension functions. |
| 243 | + * @return this |
| 244 | + * |
| 245 | + * @since XMLUnit 2.10.0 |
| 246 | + */ |
| 247 | + public Builder withSecureProcessingEnabled() { |
| 248 | + return withFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); |
| 249 | + } |
| 250 | + |
195 | 251 | } |
196 | 252 | } |
0 commit comments