You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2022/01/11 13:01:08 UTC
[sling-org-apache-sling-xss] branch master updated: SLING-10953 - Update dependency Antisamy version from 1.5.10 to 1.6.4 (#13)
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-xss.git
The following commit(s) were added to refs/heads/master by this push:
new c8fcb92 SLING-10953 - Update dependency Antisamy version from 1.5.10 to 1.6.4 (#13)
c8fcb92 is described below
commit c8fcb92c363905f0ba12425ec27208f30077526c
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Tue Jan 11 14:01:00 2022 +0100
SLING-10953 - Update dependency Antisamy version from 1.5.10 to 1.6.4 (#13)
Teach the embedded javax.xml.transform.FactoryFinder to load classes using the ServiceLoader mechanism. Otherwise our customer FactoryFinder is not used in OSGi environments.
---
bnd.bnd | 4 ++
.../java/javax/xml/transform/FactoryFinder.java | 56 +++++++++++++++++++++-
2 files changed, 59 insertions(+), 1 deletion(-)
diff --git a/bnd.bnd b/bnd.bnd
index be4bc68..45edbcb 100644
--- a/bnd.bnd
+++ b/bnd.bnd
@@ -28,7 +28,10 @@ Import-Package: !bsh, \
Private-Package: org.apache.sling.xss.impl, \
org.apache.batik.*, \
org.w3c.css.sac, \
+ org.apache.xalan.*, \
org.apache.xerces.*, \
+ org.apache.xml.*, \
+ org.apache.xpath.*, \
org.apache.xml.serialize, \
org.apache.xml.serializer.*, \
org.apache.commons.beanutils.*;-split-package:=merge-first, \
@@ -36,5 +39,6 @@ Private-Package: org.apache.sling.xss.impl, \
org.apache.commons.logging.impl, \
org.cyberneko.html.*, \
org.owasp.*, \
+ java_cup.runtime, \
javax.xml.parsers;-split-package:=merge-first, \
javax.xml.transform;-split-package:=merge-first
diff --git a/src/main/java/javax/xml/transform/FactoryFinder.java b/src/main/java/javax/xml/transform/FactoryFinder.java
index 5b0ee1d..7fee7be 100644
--- a/src/main/java/javax/xml/transform/FactoryFinder.java
+++ b/src/main/java/javax/xml/transform/FactoryFinder.java
@@ -19,6 +19,16 @@
package javax.xml.transform;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Optional;
+
+import org.apache.commons.io.IOUtils;
+
/**
* <p>This class is duplicated for each JAXP subpackage so keep it in
* sync. It is package private.
@@ -29,15 +39,21 @@ package javax.xml.transform;
* however that it must be compiled on a JDK version 1.2 or later system
* since it calls Thread#getContextClassLoader(). The code also runs both
* as part of an unbundled jar file and when bundled as part of the JDK.
+ *
+ * <p>This class does not support the full transformer factory lookup mechanism.
+ * It only supports lookups via the <tt>ServiceLoader</tt> mechanism. By virtue of the
+ * libraries embedded in the Sling XSS bundle, the fallback <tt>TransformerFactory</tt>
+ * implementation is the one provided by Xalan.</p>
*
* <p><strong>NOTE</strong>:
- * <p>This class is included in order to make sure that all {@code javax.xml.parsers} factories are the ones embedded by the bundle
+ * <p>This class is included in order to make sure that all {@code javax.xml.transform} factories are the ones embedded by the bundle
* and not the ones provided by the underlying JVM or platform.
*
* <p>For more details check the following issues:
* <ol>
* <li>https://issues.apache.org/jira/browse/SLING-8321</li>
* <li>https://issues.apache.org/jira/browse/SLING-8328</li>
+ * <li>https://issues.apache.org/jira/browse/SLING-10953</li>
* </ol>
*/
final class FactoryFinder {
@@ -154,10 +170,48 @@ final class FactoryFinder {
classLoader = FactoryFinder.class.getClassLoader();
}
+ Object instance = loadFactoryFromServiceFile(factoryId, classLoader);
+ if ( instance != null )
+ return instance;
+
if (debug) dPrint("loaded from fallback value: " + fallbackClassName);
return newInstance(fallbackClassName, classLoader, true);
}
+ private static Object loadFactoryFromServiceFile(String factoryId, ClassLoader classLoader) {
+ try {
+ Enumeration<URL> serviceFiles = classLoader.getResources("/META-INF/services/" + factoryId);
+ while ( serviceFiles.hasMoreElements() ) {
+ URL url = serviceFiles.nextElement();
+ if ( debug ) {
+ dPrint("Inspecting service file " + url );
+ }
+ try ( InputStream is = url.openStream() ) {
+ List<String> lines = IOUtils.readLines(is, StandardCharsets.UTF_8);
+ Optional<String> service = lines.stream()
+ .filter( s -> ! s.trim().startsWith("#") )
+ .filter( s -> ! s.trim().isEmpty())
+ .findFirst();
+
+ if ( service.isPresent() ) {
+ try {
+ return newInstance(service.get(), classLoader, true);
+ } catch (ConfigurationError e) {
+ // continue
+ }
+ }
+ }
+ }
+ } catch (IOException e) {
+ if (debug) {
+ dPrint("Failed loading service files " + e.getMessage());
+ e.printStackTrace(System.err);
+ }
+ }
+
+ return null;
+ }
+
static class ConfigurationError extends Error {
private Exception exception;