-
Notifications
You must be signed in to change notification settings - Fork 74
MLE-21420 Refactor: Consolidated TransformerFactory construction #1787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This refactors all direct TransformerFactory instantiations to use a centralized XmlFactories.makeNewTransformerFactory()
method, ensuring consistent secure configuration and simplifying future connector work.
- Centralized TransformerFactory creation into
XmlFactories
- Updated all test and source code to replace
TransformerFactory.newInstance()
calls - Removed duplicate secure configuration logic in
SourceHandle
andInputSourceHandle
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
marklogic-client-api/src/test/java/com/marklogic/client/test/rows/RowManagerTest.java | Swapped direct TF instantiation to XmlFactories |
marklogic-client-api/src/test/java/com/marklogic/client/test/XMLDocumentTest.java | Replaced TransformerFactory.newInstance() with XmlFactories |
marklogic-client-api/src/test/java/com/marklogic/client/test/HandleAsTest.java | Repointed to centralized XmlFactories for transformers |
marklogic-client-api/src/main/java/com/marklogic/client/io/SourceHandle.java | Removed local factory builder, now delegates to XmlFactories |
marklogic-client-api/src/main/java/com/marklogic/client/io/InputSourceHandle.java | Same consolidation for SAXSource transforms |
marklogic-client-api/src/main/java/com/marklogic/client/impl/XmlFactories.java | New centralized factory with secure defaults and logging |
marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/functionaltest/BasicJavaClientREST.java | Switched to XmlFactories for all transformer uses |
marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/fastfunctest/TestTransformXMLWithXSLT.java | Same consolidation for XSLT tests |
marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/fastfunctest/TestDocumentEncoding.java | Consolidated transformer instantiation |
marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/fastfunctest/TestBulkWriteWithTransformations.java | Replaced TF instantiation |
try { | ||
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); | ||
} catch (TransformerConfigurationException e) { | ||
LoggerFactory.getLogger(XmlFactories.class).warn("Unable to set secure processing feature on TransformerFactory; cause: {}", e.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Define a private static final Logger at the top of XmlFactories and reuse it in the catch block instead of calling LoggerFactory.getLogger(...) each time to reduce repeated lookups and improve readability.
LoggerFactory.getLogger(XmlFactories.class).warn("Unable to set secure processing feature on TransformerFactory; cause: {}", e.getMessage()); | |
logger.warn("Unable to set secure processing feature on TransformerFactory; cause: {}", e.getMessage()); |
Copilot uses AI. Check for mistakes.
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); | ||
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap the setAttribute calls for ACCESS_EXTERNAL_DTD and ACCESS_EXTERNAL_STYLESHEET in try-catch blocks to gracefully handle IllegalArgumentException when a TransformerFactory implementation does not support those attributes.
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); | |
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, ""); | |
try { | |
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); | |
} catch (IllegalArgumentException e) { | |
LoggerFactory.getLogger(XmlFactories.class).warn("Unable to set ACCESS_EXTERNAL_DTD attribute on TransformerFactory; cause: {}", e.getMessage()); | |
} | |
try { | |
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, ""); | |
} catch (IllegalArgumentException e) { | |
LoggerFactory.getLogger(XmlFactories.class).warn("Unable to set ACCESS_EXTERNAL_STYLESHEET attribute on TransformerFactory; cause: {}", e.getMessage()); | |
} |
Copilot uses AI. Check for mistakes.
aaa9804
to
8ca1afd
Compare
No effect on behavior here. This is just to help with an issue in the Spark connector, where the Saxon-HE TransformerFactory is being used. Having all TransformerFactory.newInstance() calls in one place makes it easier to think about how it's used in the Java Client. Also good from a security perspective - i.e. all uses of TF are being configured with the necessary precautions.
8ca1afd
to
2905c8b
Compare
No effect on behavior here. This is just to help with an issue in the Spark connector, where the Saxon-HE TransformerFactory is being used. Having all TransformerFactory.newInstance() calls in one place makes it easier to think about how it's used in the Java Client.
Also good from a security perspective - i.e. all uses of TF are being configured with the necessary precautions.