Skip to content
Snippets Groups Projects
Commit c08952fe authored by Thomas Mortagne's avatar Thomas Mortagne
Browse files

[misc] Bulletproofing

parent 8c9c6857
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,7 @@
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
......@@ -218,10 +219,14 @@ public String get(String key, Object... params)
*/
protected List<String> getDocumentBundleNames()
{
List<String> docNamesList;
XWikiContext context = getXWikiContext();
if (context == null) {
return Collections.emptyList();
}
List<String> docNamesList;
String docNames = context.getWiki().getXWikiPreference(KEY, context);
if (docNames == null || "".equals(docNames)) {
docNames = context.getWiki().Param("xwiki." + KEY);
......@@ -244,6 +249,10 @@ public List<XWikiDocument> getDocumentBundles()
{
XWikiContext context = getXWikiContext();
if (context == null) {
return Collections.emptyList();
}
String defaultLanguage = context.getWiki().getDefaultLanguage(context);
List<XWikiDocument> result = new ArrayList<XWikiDocument>();
for (String docName : getDocumentBundleNames()) {
......@@ -281,17 +290,17 @@ public List<XWikiDocument> getDocumentBundles()
*/
public XWikiDocument getDocumentBundle(String documentName)
{
XWikiDocument docBundle;
XWikiDocument docBundle = null;
if (documentName.length() == 0) {
docBundle = null;
} else {
if (!documentName.isEmpty()) {
try {
XWikiContext context = getXWikiContext();
// First, looks for a document suffixed by the language
docBundle = context.getWiki().getDocument(documentName, context);
docBundle = docBundle.getTranslatedDocument(context);
if (context != null) {
// First, looks for a document suffixed by the language
docBundle = context.getWiki().getDocument(documentName, context);
docBundle = docBundle.getTranslatedDocument(context);
}
} catch (XWikiException e) {
// Error while loading the document.
// TODO: A runtime exception should be thrown that will bubble up till the
......@@ -321,17 +330,18 @@ public List<XWikiDocument> getDocumentBundles(String documentName, String defaul
try {
XWikiContext context = getXWikiContext();
// First, looks for a document suffixed by the language
XWikiDocument docBundle = context.getWiki().getDocument(documentName, context);
XWikiDocument tdocBundle = docBundle.getTranslatedDocument(context);
list.add(tdocBundle);
if (!tdocBundle.getRealLanguage().equals(defaultLanguage)) {
XWikiDocument defdocBundle = docBundle.getTranslatedDocument(defaultLanguage, context);
if (tdocBundle != defdocBundle) {
list.add(defdocBundle);
if (context != null) {
// First, looks for a document suffixed by the language
XWikiDocument docBundle = context.getWiki().getDocument(documentName, context);
XWikiDocument tdocBundle = docBundle.getTranslatedDocument(context);
list.add(tdocBundle);
if (!tdocBundle.getRealLanguage().equals(defaultLanguage)) {
XWikiDocument defdocBundle = docBundle.getTranslatedDocument(defaultLanguage, context);
if (tdocBundle != defdocBundle) {
list.add(defdocBundle);
}
}
}
} catch (XWikiException e) {
// Error while loading the document.
// TODO: A runtime exception should be thrown that will bubble up till the
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment