Skip to content
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

API / XSL / Use XSL output configuration (formatter, editor). #7929

Merged
merged 4 commits into from
Apr 24, 2024

Conversation

fxprunayre
Copy link
Member

@fxprunayre fxprunayre commented Apr 5, 2024

Formatter API was using an XMLOutputter overriding all configuration made in xsl:output. This was producing "invalid" HTML and some workaround were used so far.

Now, return the output produced by saxon XMLIndenter or HTMLIndenter directly.

A good config for HTML output:

<xsl:output omit-xml-declaration="yes" method="html" doctype-system="html" indent="yes"
                     encoding="UTF-8"/>

It was only affecting the formatter API using the XML.getString which was doing the prettyPrint.

For schema plugin maintainer, this change requires to check plugin formatter which may export HTML, XML or Text output. Adjust the xsl:output configuration if needed.

Also do not force editor API to output XML. It outputs HTML and XML view may contains a properly formatted XML snippet.

Checklist

  • I have read the contribution guidelines
  • Pull request provided for main branch, backports managed with label
  • Good housekeeping of code, cleaning up comments, tests, and documentation
  • Clean commit history broken into understandable chucks, avoiding big commits with hundreds of files, cautious of reformatting and whitespace changes
  • Clean commit messages, longer verbose messages are encouraged
  • API Changes are identified in commit messages
  • Testing provided for features or enhancements using automatic tests
  • User documentation provided for new features or enhancements in manual
  • Build documentation provided for development instructions in README.md files
  • Library management using pom.xml dependency management. Update build documentation with intended library use and library tutorials or documentation

@fxprunayre fxprunayre added this to the 4.4.4 milestone Apr 5, 2024
Formatter API was using an XMLOutputter formatter overriding all
configuration made in `xsl:output`. This was producing "invalid" HTML
and some workaround were used so far.

Now, return the output produced by saxon XMLIndenter or HTMLIndenter
directly.
@fxprunayre fxprunayre force-pushed the 44-formatter-output-based-on-xsl-configuration branch from 1d86f2e to d111f72 Compare April 5, 2024 06:56
@fxprunayre fxprunayre added the schema plugin change Indicate that this work introduces a schema plugin change. label Apr 5, 2024
The editor is an HTML page so don't use an XML formatter for the output.
To format the XML in XML view, saxon is taking care of it using
serialize and default-indent-mode. Use an HTML `pre` element which is
not formatted by HTMLIndenter.
Copy link

sonarcloud bot commented Apr 5, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarCloud

@fxprunayre fxprunayre modified the milestones: 4.4.4, 4.4.5 Apr 15, 2024
Copy link
Member

@josegar74 josegar74 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request seems working fine producing correct HTML. See questions added.

The pull request title seems a bit unclear, it seems only affects the formatters, but also affects the metadata editor (which is fine).

From the pull request description:

Also do not force editor API to output XML. It outputs HTML and XML view may contains a properly formatted XML snippet.

I guess this is related to this change https://github.com/geonetwork/core-geonetwork/pull/7929/files#diff-6619510098f17f2c27d668ff5572c83cb1e954ea115469baddc12f9bcb9667e2R42? Can you elaborate it a bit more?

@@ -688,7 +688,8 @@ private void buildEditorForm(String tab, HttpSession session, Map<String, String
GeonetworkDataDirectory dataDirectory = applicationContext.getBean(GeonetworkDataDirectory.class);
Path xslt = dataDirectory.getWebappDir()
.resolve(isEmbedded ? "xslt/ui-metadata/edit/edit-embedded.xsl" : "xslt/ui-metadata/edit/edit.xsl");
Xml.transformXml(root, xslt, response.getOutputStream());

Xml.transform(root, xslt, response.getOutputStream());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, calling Xml.transformXml was setting geonet-force-xml, that had executed some specific logic in https://github.com/geonetwork/core-geonetwork/pull/7929/files#diff-0e73f2dd016775585aabf4911d02c93bae066b3463da113616eb91a08c4c87c7R488

I guess as maybe relies now in xsl:output in xslt files?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes the editor is an HTML page so using the geonet-force-xml workaround was producing "wrong" HTML.
I think the workaround idea was to fix the XML view in order to indent the XML in the editor but https://github.com/geonetwork/core-geonetwork/pull/7929/files#diff-6619510098f17f2c27d668ff5572c83cb1e954ea115469baddc12f9bcb9667e2R45 was doing it well as far as the XML is in an HTML pre element (which is not formatted by the Saxon HTMLIndenter).

@@ -30,11 +30,6 @@
<xsl:include href="../base-layout-cssjs-loader.xsl"/>
<xsl:include href="../skin/default/skin.xsl"/>

<xsl:output omit-xml-declaration="yes"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this removed due to be imported this xslt in another that includes xsl:output?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fxprunayre fxprunayre changed the title API / Formatter / Use XSL output configuration. API / XSL / Use XSL output configuration (formatter, editor). Apr 23, 2024
@josegar74 josegar74 merged commit e3f69f2 into main Apr 24, 2024
6 of 10 checks passed
@geonetworkbuild
Copy link
Collaborator

The backport to 4.2.x failed:

The process '/usr/bin/git' failed with exit code 1
stderr
error: could not apply d111f72613... API / Formatter / Use XSL output configuration.
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".

stdout
Auto-merging schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/citation/common.xsl
CONFLICT (content): Merge conflict in schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/citation/common.xsl
CONFLICT (modify/delete): services/src/test/resources/org/fao/geonet/api/records/formatters/iso19115-3.2018-citation-html.html deleted in HEAD and modified in d111f72613 (API / Formatter / Use XSL output configuration.).  Version d111f72613 (API / Formatter / Use XSL output configuration.) of services/src/test/resources/org/fao/geonet/api/records/formatters/iso19115-3.2018-citation-html.html left in tree.
CONFLICT (modify/delete): services/src/test/resources/org/fao/geonet/api/records/formatters/iso19139-citation-html.html deleted in HEAD and modified in d111f72613 (API / Formatter / Use XSL output configuration.).  Version d111f72613 (API / Formatter / Use XSL output configuration.) of services/src/test/resources/org/fao/geonet/api/records/formatters/iso19139-citation-html.html left in tree.

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-4.2.x 4.2.x
# Navigate to the new working tree
cd .worktrees/backport-4.2.x
# Create a new branch
git switch --create backport-7929-to-4.2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick d111f726135af61fb7ec5e270c9abaa8f6c89604,36d3f44d29b4893c6b2adb531b0b6a257147a951,5e51ed2fdb0b0e4995539ad309135aee350db13e,847f105c8925fe9a83164e6f604a554de4168dc7
# Push it to GitHub
git push --set-upstream origin backport-7929-to-4.2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-4.2.x

Then, create a pull request where the base branch is 4.2.x and the compare/head branch is backport-7929-to-4.2.x.

@fxprunayre fxprunayre deleted the 44-formatter-output-based-on-xsl-configuration branch April 24, 2024 12:57
fxprunayre added a commit that referenced this pull request Apr 29, 2024
@fxprunayre fxprunayre mentioned this pull request Apr 29, 2024
10 tasks
josegar74 pushed a commit that referenced this pull request Apr 29, 2024
* Test / Fix formatter test.

Related to #7929.

* Prettier.

* Test / Fix formatter test / Citation common may be embedded in other formatter. Only set xsl:output in the citation entry point.
@josegar74 josegar74 mentioned this pull request May 6, 2024
10 tasks
josegar74 pushed a commit that referenced this pull request May 28, 2024
* API / Formatter / Use XSL output configuration.

Formatter API was using an XMLOutputter formatter overriding all
configuration made in `xsl:output`. This was producing "invalid" HTML
and some workaround were used so far.

Now, return the output produced by saxon XMLIndenter or HTMLIndenter
directly.

* Editor / Fix formatting.

The editor is an HTML page so don't use an XML formatter for the output.
To format the XML in XML view, saxon is taking care of it using
serialize and default-indent-mode. Use an HTML `pre` element which is
not formatted by HTMLIndenter.

* Formatter / Fix conflicting output when citation is used in xsl-view.

* API / Formatter / iText for PDF expect xhtml document. If HTML, complains about not closed tags like links.
josegar74 pushed a commit that referenced this pull request May 28, 2024
* Test / Fix formatter test.

Related to #7929.

* Prettier.

* Test / Fix formatter test / Citation common may be embedded in other formatter. Only set xsl:output in the citation entry point.
josegar74 added a commit that referenced this pull request Jun 17, 2024
… editor) (#8104)

* API / XSL / Use XSL output configuration (formatter, editor). (#7929)

* API / Formatter / Use XSL output configuration.

Formatter API was using an XMLOutputter formatter overriding all
configuration made in `xsl:output`. This was producing "invalid" HTML
and some workaround were used so far.

Now, return the output produced by saxon XMLIndenter or HTMLIndenter
directly.

* Editor / Fix formatting.

The editor is an HTML page so don't use an XML formatter for the output.
To format the XML in XML view, saxon is taking care of it using
serialize and default-indent-mode. Use an HTML `pre` element which is
not formatted by HTMLIndenter.

* Formatter / Fix conflicting output when citation is used in xsl-view.

* API / Formatter / iText for PDF expect xhtml document. If HTML, complains about not closed tags like links.

* Test / Fix formatter test. (#7993)

* Test / Fix formatter test.

Related to #7929.

* Prettier.

* Test / Fix formatter test / Citation common may be embedded in other formatter. Only set xsl:output in the citation entry point.

* API / XSL / Use XSL output configuration - formatter update for Java 8

---------

Co-authored-by: François Prunayre <fx.prunayre@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 4.2.x failed backport schema plugin change Indicate that this work introduces a schema plugin change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants