-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
232 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
deployment/src/main/java/io/quarkiverse/jasperreports/deployment/XalanProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package io.quarkiverse.jasperreports.deployment; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
import io.quarkiverse.jasperreports.XalanTransformerFactory; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.builditem.nativeimage.ExcludeConfigBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBundleBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; | ||
|
||
class XalanNativeImageProcessor { | ||
private static final String TRANSFORMER_FACTORY_SERVICE_FILE_PATH = "META-INF/services/javax.xml.transform.TransformerFactory"; | ||
|
||
@BuildStep | ||
List<ReflectiveClassBuildItem> reflectiveClasses() { | ||
return Arrays.asList( | ||
ReflectiveClassBuildItem.builder(io.quarkiverse.jasperreports.XalanTransformerFactory.class.getName(), | ||
"org.apache.xalan.xsltc.dom.ObjectFactory", | ||
"org.apache.xalan.xsltc.dom.XSLTCDTMManager", | ||
"org.apache.xalan.xsltc.trax.ObjectFactory", | ||
"org.apache.xalan.xsltc.trax.TransformerFactoryImpl", | ||
"org.apache.xml.dtm.ObjectFactory", | ||
"org.apache.xml.dtm.ref.DTMManagerDefault", | ||
"org.apache.xml.serializer.OutputPropertiesFactory", | ||
"org.apache.xml.serializer.CharInfo", | ||
"org.apache.xml.utils.FastStringBuffer").methods().build(), | ||
ReflectiveClassBuildItem.builder("org.apache.xml.serializer.ToHTMLStream", | ||
"org.apache.xml.serializer.ToTextStream", | ||
"org.apache.xml.serializer.ToXMLStream").build()); | ||
} | ||
|
||
@BuildStep | ||
List<NativeImageResourceBundleBuildItem> resourceBundles() { | ||
return Arrays.asList( | ||
new NativeImageResourceBundleBuildItem("org.apache.xalan.xsltc.compiler.util.ErrorMessages"), | ||
new NativeImageResourceBundleBuildItem("org.apache.xml.serializer.utils.SerializerMessages"), | ||
new NativeImageResourceBundleBuildItem("org.apache.xml.serializer.XMLEntities"), | ||
new NativeImageResourceBundleBuildItem("org.apache.xml.res.XMLErrorResources")); | ||
} | ||
|
||
@BuildStep | ||
void resources(BuildProducer<NativeImageResourceBuildItem> resource) { | ||
|
||
Stream.of( | ||
"html", | ||
"text", | ||
"xml", | ||
"unknown") | ||
.map(s -> "org/apache/xml/serializer/output_" + s + ".properties") | ||
.map(NativeImageResourceBuildItem::new) | ||
.forEach(resource::produce); | ||
|
||
} | ||
|
||
@BuildStep | ||
void installTransformerFactory( | ||
BuildProducer<ExcludeConfigBuildItem> excludeConfig, | ||
BuildProducer<ServiceProviderBuildItem> serviceProvider) { | ||
|
||
excludeConfig | ||
.produce(new ExcludeConfigBuildItem("xalan\\.xalan-.*\\.jar", "/" + TRANSFORMER_FACTORY_SERVICE_FILE_PATH)); | ||
serviceProvider.produce(new ServiceProviderBuildItem("javax.xml.transform.TransformerFactory", | ||
XalanTransformerFactory.class.getName())); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
runtime/src/main/java/io/quarkiverse/jasperreports/XalanTransformerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package io.quarkiverse.jasperreports; | ||
|
||
import javax.xml.transform.ErrorListener; | ||
import javax.xml.transform.Source; | ||
import javax.xml.transform.Templates; | ||
import javax.xml.transform.Transformer; | ||
import javax.xml.transform.TransformerConfigurationException; | ||
import javax.xml.transform.TransformerException; | ||
import javax.xml.transform.TransformerFactory; | ||
import javax.xml.transform.URIResolver; | ||
import javax.xml.transform.sax.SAXTransformerFactory; | ||
import javax.xml.transform.sax.TemplatesHandler; | ||
import javax.xml.transform.sax.TransformerHandler; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.xml.sax.XMLFilter; | ||
|
||
/** | ||
* A {@link TransformerFactory} delegating to a {@link TransformerFactory} created via | ||
* {@code TransformerFactory.newInstance("org.apache.xalan.xsltc.trax.TransformerFactoryImpl", Thread.currentThread().getContextClassLoader())} | ||
*/ | ||
public final class XalanTransformerFactory extends SAXTransformerFactory { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(XalanTransformerFactory.class); | ||
|
||
private final SAXTransformerFactory delegate; | ||
|
||
public XalanTransformerFactory() { | ||
final SAXTransformerFactory factory = (SAXTransformerFactory) TransformerFactory.newInstance( | ||
"org.apache.xalan.xsltc.trax.TransformerFactoryImpl", | ||
Thread.currentThread().getContextClassLoader()); | ||
try { | ||
factory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true); | ||
} catch (TransformerException e) { | ||
LOGGER.warn("Unsupported TransformerFactory feature " + javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING); | ||
} | ||
|
||
this.delegate = factory; | ||
} | ||
|
||
@Override | ||
public Transformer newTransformer(Source source) throws TransformerConfigurationException { | ||
return delegate.newTransformer(source); | ||
} | ||
|
||
@Override | ||
public Transformer newTransformer() throws TransformerConfigurationException { | ||
return delegate.newTransformer(); | ||
} | ||
|
||
@Override | ||
public Templates newTemplates(Source source) throws TransformerConfigurationException { | ||
return delegate.newTemplates(source); | ||
} | ||
|
||
@Override | ||
public Source getAssociatedStylesheet(Source source, String media, String title, String charset) | ||
throws TransformerConfigurationException { | ||
return delegate.getAssociatedStylesheet(source, media, title, charset); | ||
} | ||
|
||
@Override | ||
public void setURIResolver(URIResolver resolver) { | ||
delegate.setURIResolver(resolver); | ||
} | ||
|
||
@Override | ||
public URIResolver getURIResolver() { | ||
return delegate.getURIResolver(); | ||
} | ||
|
||
@Override | ||
public void setFeature(String name, boolean value) throws TransformerConfigurationException { | ||
delegate.setFeature(name, value); | ||
} | ||
|
||
@Override | ||
public boolean getFeature(String name) { | ||
return delegate.getFeature(name); | ||
} | ||
|
||
@Override | ||
public void setAttribute(String name, Object value) { | ||
delegate.setAttribute(name, value); | ||
} | ||
|
||
@Override | ||
public Object getAttribute(String name) { | ||
return delegate.getAttribute(name); | ||
} | ||
|
||
@Override | ||
public void setErrorListener(ErrorListener listener) { | ||
delegate.setErrorListener(listener); | ||
} | ||
|
||
@Override | ||
public ErrorListener getErrorListener() { | ||
return delegate.getErrorListener(); | ||
} | ||
|
||
@Override | ||
public TransformerHandler newTransformerHandler(Source source) throws TransformerConfigurationException { | ||
return delegate.newTransformerHandler(source); | ||
} | ||
|
||
@Override | ||
public TransformerHandler newTransformerHandler(Templates templates) throws TransformerConfigurationException { | ||
return delegate.newTransformerHandler(templates); | ||
} | ||
|
||
@Override | ||
public TransformerHandler newTransformerHandler() throws TransformerConfigurationException { | ||
return delegate.newTransformerHandler(); | ||
} | ||
|
||
@Override | ||
public TemplatesHandler newTemplatesHandler() throws TransformerConfigurationException { | ||
return delegate.newTemplatesHandler(); | ||
} | ||
|
||
@Override | ||
public XMLFilter newXMLFilter(Source source) throws TransformerConfigurationException { | ||
return delegate.newXMLFilter(source); | ||
} | ||
|
||
@Override | ||
public XMLFilter newXMLFilter(Templates templates) throws TransformerConfigurationException { | ||
return delegate.newXMLFilter(templates); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
runtime/src/main/java/io/quarkiverse/jasperreports/graal/TemplatesImplSubstitution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.quarkiverse.jasperreports.graal; | ||
|
||
import com.oracle.svm.core.annotate.Substitute; | ||
import com.oracle.svm.core.annotate.TargetClass; | ||
|
||
@TargetClass(className = "org.apache.xalan.xsltc.trax.TemplatesImpl") | ||
final class TemplatesImplSubstitution { | ||
|
||
@TargetClass(className = "org.apache.xalan.xsltc.trax.TemplatesImpl", innerClass = "TransletClassLoader") | ||
static final class TransletClassLoader { | ||
@Substitute | ||
Class defineClass(final byte[] b) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
runtime/src/main/resources/META-INF/services/javax.xml.transform.TransformerFactory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.quarkiverse.jasperreports.XalanTransformerFactory |