-
-
Notifications
You must be signed in to change notification settings - Fork 489
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
Update skin.xsl so that it works better in nojs mode. #7015
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4ab607f
Update skin so that it works better in nojs mode.
ianwallen ab4cb60
Merge branch 'main' of https://github.com/geonetwork/core-geonetwork …
ianwallen 072726d
Update web/src/main/webapp/xslt/skin/default/skin.xsl
ianwallen c573cda
Merge branch 'main' of https://github.com/geonetwork/core-geonetwork …
b09c7cc
Added logging and sample data that causes issues.
ianwallen 95e91f3
If no configuration has been setup then /root/request/ui will be null…
ianwallen 42ac3dc
Merge branch 'main' of https://github.com/geonetwork/core-geonetwork …
ianwallen ef58ccf
Update typo in comments
ianwallen 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
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 |
---|---|---|
|
@@ -25,13 +25,21 @@ | |
|
||
import org.fao.geonet.ApplicationContextHolder; | ||
import org.fao.geonet.kernel.SchemaManager; | ||
import org.fao.geonet.kernel.search.JSONLocCacheLoader; | ||
import org.fao.geonet.kernel.setting.SettingManager; | ||
import org.fao.geonet.utils.Xml; | ||
import org.jdom.Element; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.*; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.fao.geonet.api.records.formatters.SchemaLocalizations.loadSchemaLocalizations; | ||
|
||
|
@@ -51,6 +59,16 @@ | |
@Component | ||
public class XsltFormatter implements FormatterImpl { | ||
|
||
private final Map<String, Element> translationElements = new HashMap<>(); | ||
|
||
private final ConfigurableApplicationContext configurableApplicationContext; | ||
|
||
@Autowired | ||
public XsltFormatter(ConfigurableApplicationContext configurableApplicationContext) { | ||
this.configurableApplicationContext = configurableApplicationContext; | ||
} | ||
|
||
|
||
/** | ||
* @param schema Use all to return all schemas translations | ||
* @param schemasToLoadList | ||
|
@@ -97,16 +115,33 @@ public String format(FormatterParams fparams) throws Exception { | |
|
||
root.addContent(new Element("lang").setText(fparams.context.getLanguage())); | ||
root.addContent(new Element("url").setText(fparams.url)); | ||
// FIXME: This is a hack to mimic what Jeeves service are doing. | ||
// Some XSLT are used by both formatters and Jeeves and Spring MVC services | ||
Element translations = new Element("translations"); | ||
|
||
if (!translationElements.containsKey(fparams.context.getLanguage())) { | ||
// Get translation keys and add them to the cache | ||
Element translations = new Element("translations"); | ||
Map<String, String> translationMap = new JSONLocCacheLoader(configurableApplicationContext, fparams.context.getLanguage()).call(); | ||
for (Map.Entry<String, String> entry : translationMap.entrySet()) { | ||
// Skip keys that are not alpha numeric only including "." - otherwhise chars like : ? +... cause problem when creating element. | ||
if (entry.getKey().matches("[a-zA-Z0-9\\.]+")) { | ||
try { | ||
translations.addContent(new Element(entry.getKey()).setText(entry.getValue())); | ||
} catch (Exception e) { | ||
System.out.println("Failed to add translation key for \"" + entry.getKey() + "\"=\"" + entry.getValue() + "\". " + e.getMessage()); | ||
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. This should be changed to log the exception. 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. Changed to log the exception |
||
} | ||
} | ||
} | ||
|
||
translationElements.put(fparams.context.getLanguage(), translations); | ||
} | ||
root.addContent((Element)translationElements.get(fparams.context.getLanguage()).clone()); | ||
Element gui = new Element("gui"); | ||
String baseUrl = settingManager.getBaseURL(); | ||
String context = baseUrl.replace(settingManager.getServerURL(), ""); | ||
gui.addContent(new Element("url").setText( | ||
context.substring(0, context.length() - 1) | ||
)); | ||
gui.addContent(new Element("nodeUrl").setText(settingManager.getNodeURL())); | ||
gui.addContent(new Element("nodeId").setText(settingManager.getNodeId())); | ||
gui.addContent(new Element("baseUrl").setText(baseUrl)); | ||
gui.addContent(new Element("serverUrl").setText(settingManager.getServerURL())); | ||
gui.addContent(new Element("language").setText(fparams.context.getLanguage())); | ||
|
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
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.
Can you indicate some translation including such values in the keys?
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.
Updated comments to show some sample keys that cause issues.