-
Notifications
You must be signed in to change notification settings - Fork 13
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
MCR-2966 move saxon compatible stylesheets to folder xslt #1964
Merged
Merged
Changes from 7 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
6aef2a6
MCR-2966 xslt folder
8647253
MCR-2966 xslt folder
847a36a
MCR-2966 xslt folder
216fbad
MCR-2966 xslt folder
4c42163
MCR-2966 xslt folder
ad1d02e
MCR-2966 xslt folder
28603e1
MCR-2966 xslt folder
0ff95fa
MCR-2966 xslt folder
3e5389a
MCR-2966 xslt folder
79f37ba
Merge remote-tracking branch 'origin/main' into issues/MCR-2966-xslt-…
85fdc2d
MCR-2966 xslt folder
27999f6
MCR-2966 xslt folder
c90f88b
MCR-2966 xslt folder
0473146
MCR-2966 xslt folder
9fc32c5
MCR-2966 xslt folder
1560f3e
MCR-2966 xslt folder
6c97723
MCR-2966 xslt folder
d579af3
MCR-2966 xslt folder
c05e7c4
MCR-2966 xslt folder
49ad890
Merge remote-tracking branch 'origin/issues/MCR-2966-xslt-folder' int…
ffe1dbf
Merge remote-tracking branch 'origin/main' into issues/MCR-2966-xslt-…
42b4bab
MCR-2966 xslt folder
d04ab82
Merge remote-tracking branch 'origin/main' into issues/MCR-2966-xslt-…
0ddd2cf
Merge remote-tracking branch 'origin/main' into issues/MCR-2966-xslt-…
9127faf
MCR-2966 xslt folder
e9b3e0e
Merge remote-tracking branch 'origin/main' into issues/MCR-2966-xslt-…
1eafc4a
Merge remote-tracking branch 'origin/main' into issues/MCR-2966-xslt-…
fb8c445
MCR-2966 xslt folder
12346d8
Merge remote-tracking branch 'origin/main' into issues/MCR-2966-xslt-…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
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
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 |
---|---|---|
|
@@ -57,6 +57,7 @@ | |
import javax.xml.transform.stream.StreamSource; | ||
import javax.xml.xpath.XPathExpressionException; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.http.client.cache.HttpCacheContext; | ||
import org.apache.http.client.config.RequestConfig; | ||
import org.apache.http.client.methods.CloseableHttpResponse; | ||
|
@@ -233,6 +234,7 @@ private HashMap<String, URIResolver> getResolverMapping() { | |
supportedSchemes.put("catchEx", new MCRExceptionAsXMLResolver()); | ||
supportedSchemes.put("notnull", new MCRNotNullResolver()); | ||
supportedSchemes.put("xslStyle", new MCRXslStyleResolver()); | ||
supportedSchemes.put("xslStyleXEditor", new MCRXslStyleXEditorResolver()); | ||
supportedSchemes.put("xslTransform", new MCRLayoutTransformerResolver()); | ||
supportedSchemes.put("xslInclude", new MCRXslIncludeResolver()); | ||
supportedSchemes.put("xslImport", new MCRXslImportResolver()); | ||
|
@@ -266,7 +268,8 @@ private HashMap<String, URIResolver> getResolverMapping() { | |
static String getParentDirectoryResourceURI(String base) { | ||
if (base == null) { | ||
// the file was not included from another file, so we need to use the default resource directory | ||
return "resource:xsl/"; | ||
final String xslFolder = MCRConfiguration2.getStringOrThrow("MCR.Layout.Transformer.Factory.XSLFolder"); | ||
return "resource:" + xslFolder + "/"; | ||
} else { | ||
String resolvingBase = null; | ||
|
||
|
@@ -370,7 +373,9 @@ private Source tryResolveXSL(String href, String base) throws TransformerExcepti | |
} | ||
|
||
// new relative include did not work, now fall back to old behaviour and print a warning if it works | ||
Source oldResolveMethodResult = SUPPORTED_SCHEMES.get("resource").resolve("resource:xsl/" + href, base); | ||
final String xslFolder = MCRConfiguration2.getStringOrThrow("MCR.Layout.Transformer.Factory.XSLFolder"); | ||
Source oldResolveMethodResult = SUPPORTED_SCHEMES.get("resource") | ||
.resolve("resource:" + xslFolder + "/" + href, base); | ||
if (oldResolveMethodResult != null) { | ||
LOGGER.warn("The Stylesheet {} has include {} which only works with an old absolute include " + | ||
"mechanism. Please change the include to relative!", base, href); | ||
|
@@ -1217,7 +1222,19 @@ public Source resolve(String href, String base) throws TransformerException { | |
} | ||
} | ||
|
||
private MCRXSLTransformer getTransformer(String... stylesheet) { | ||
protected MCRXSLTransformer getTransformer(String... stylesheet) { | ||
final String xslFolder = MCRConfiguration2.getStringOrThrow("MCR.Layout.Transformer.Factory.XSLFolder"); | ||
String[] stylesheets = new String[stylesheet.length]; | ||
for (int i = 0; i < stylesheets.length; i++) { | ||
stylesheets[i] = xslFolder + "/" + stylesheet[i] + ".xsl"; | ||
} | ||
return MCRXSLTransformer.getInstance(stylesheets); | ||
} | ||
} | ||
|
||
private static class MCRXslStyleXEditorResolver extends MCRXslStyleResolver { | ||
@Override | ||
protected MCRXSLTransformer getTransformer(String... stylesheet) { | ||
String[] stylesheets = new String[stylesheet.length]; | ||
for (int i = 0; i < stylesheets.length; i++) { | ||
stylesheets[i] = "xsl/" + stylesheet[i] + ".xsl"; | ||
|
@@ -1329,10 +1346,12 @@ public Source resolve(String href, String base) { | |
.orElseGet(Collections::emptyList); | ||
} | ||
|
||
final String xslFolder = MCRConfiguration2.getStringOrThrow("MCR.Layout.Transformer.Factory.XSLFolder"); | ||
for (String include : propValue) { | ||
// create a new include element | ||
Element includeElement = new Element("include", xslNamespace); | ||
includeElement.setAttribute("href", include.contains(":") ? include : "resource:xsl/" + include); | ||
includeElement.setAttribute("href", | ||
include.contains(":") ? include : "resource:" + xslFolder + "/" + include); | ||
root.addContent(includeElement); | ||
LOGGER.debug("Resolved XSL include: {}", include); | ||
} | ||
|
@@ -1357,7 +1376,30 @@ private static class MCRXslImportResolver implements URIResolver { | |
|
||
@Override | ||
public Source resolve(String href, String base) throws TransformerException { | ||
String importXSL = MCRXMLFunctions.nextImportStep(href.substring(href.indexOf(':') + 1)); | ||
final String baseURI = getParentDirectoryResourceURI(base); | ||
// set xslt folder | ||
final String xslFolder; | ||
if (StringUtils.contains(baseURI, "/xsl/")) { | ||
xslFolder = "xsl"; | ||
} else { | ||
xslFolder = "xslt"; | ||
} | ||
|
||
// check for old import format: xslImport:property:current.xsl and issue a warning | ||
final String importXSL; | ||
final String importPart = StringUtils.substringAfter(href, ":"); | ||
if (StringUtils.contains(importPart, ":")) { | ||
final String propertyPart = StringUtils.substringBefore(importPart, ":"); | ||
LOGGER.warn("{} is in old import format change to xslImport:{}!", href, propertyPart); | ||
|
||
importXSL = MCRXMLFunctions.nextImportStep(importPart); | ||
} else { | ||
final String selfName = StringUtils.substringAfter(baseURI, xslFolder + "/") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe more secure to use baseURI.substring(xslFolder.length+1) |
||
+ StringUtils.substringAfterLast(base, "/"); | ||
|
||
importXSL = MCRXMLFunctions.nextImportStep(importPart, selfName); | ||
} | ||
|
||
if (importXSL.isEmpty()) { | ||
LOGGER.debug("End of import queue: {}", href); | ||
Namespace xslNamespace = Namespace.getNamespace("xsl", "http://www.w3.org/1999/XSL/Transform"); | ||
|
@@ -1366,7 +1408,8 @@ public Source resolve(String href, String base) throws TransformerException { | |
return new JDOMSource(root); | ||
} | ||
LOGGER.debug("xslImport importing {}", importXSL); | ||
return fallback.resolve("resource:xsl/" + importXSL, base); | ||
|
||
return fallback.resolve("resource:" + xslFolder + "/" + importXSL, base); | ||
} | ||
} | ||
|
||
|
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
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | ||
<!-- test XSL file for MCRURIResolverTest#testImportFromSameDirectory --> | ||
<xsl:import href="xslImport:xsl-import:xsl-1.xsl"/> | ||
</xsl:stylesheet> |
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,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | ||
<!-- test XSL file for MCRURIResolverTest#testImportFromSameDirectory --> | ||
<xsl:import href="xslImport:xsl-import:xsl-2.xsl"/> | ||
</xsl:stylesheet> |
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,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | ||
<!-- test XSL file for MCRURIResolverTest#testImportFromSameDirectory --> | ||
<xsl:import href="xslImport:xsl-import:xsl-1.xsl"/> | ||
</xsl:stylesheet> |
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,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | ||
<!-- test XSL file for MCRURIResolverTest#testImportFromSameDirectory --> | ||
<xsl:import href="xslImport:xsl-import:xsl-2.xsl"/> | ||
</xsl:stylesheet> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
baseURI.startswith would work more secure
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.
If I understand this correctly, getParentDirectoryResourceURI always returns a string starting with resource (https://github.com/MyCoRe-Org/mycore/blob/2022.06.x/mycore-base/src/main/java/org/mycore/common/xml/MCRURIResolver.java#L293)
e.g.:
base: jar:file:/home/musiclpz/production/build/webapps/WEB-INF/lib/mycore-solr-2023.08-SNAPSHOT.jar!/xslt/solr/indexing/mycoreobject-dynamicfields.xsl
baseuri: resource:xslt/solr/indexing/
so startsWith resource:xsl/ should be feasible.
However, in some edge cases getParentDirectoryResourceURI returns the given base. In these cases, this would not work. But I am not totally aware if in these cases something else goes wrong. If we can ignore these edge cases, we can test on startsWith resource:xsl/
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.
Yes you are right.
I think in the edge cases the property should be used. So check for startsWith resource:xsl/ or resource:xslt/ and if both false than use the property.
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.
Changed to startsWith resource:xsl/ / resource:xslt/
I had to rollback the changes in nextImportStep, since it produced errors when using the proposed new xslImport syntax (without selfname). This resulted in errors because xsl:import href="xslImport:xxx" was included more than once and ultimately failed with a stylesheet including itself. I was not able to fix this and, thus. would suggest to postpone the syntax change to a later point.