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

XWIKI-20462: Add support for content coming from a different source in the code macro

* add missing exception causes
* improve javadoc
* use the already resolved DocumentReference for better performances
parent 352fd923
No related branches found
No related tags found
No related merge requests found
...@@ -86,7 +86,7 @@ public CodeMacroSource getContent(CodeMacroSourceReference reference, MacroTrans ...@@ -86,7 +86,7 @@ public CodeMacroSource getContent(CodeMacroSourceReference reference, MacroTrans
this.authorization.checkAccess(Right.VIEW, xcontext.getAuthorReference(), documentReference); this.authorization.checkAccess(Right.VIEW, xcontext.getAuthorReference(), documentReference);
} catch (AccessDeniedException e) { } catch (AccessDeniedException e) {
throw new MacroExecutionException( throw new MacroExecutionException(
"Current author is not allowed to access document [" + documentReference + "]"); "Current author is not allowed to access document [" + documentReference + "]", e);
} }
// Current user must have view right on the document // Current user must have view right on the document
...@@ -98,9 +98,9 @@ public CodeMacroSource getContent(CodeMacroSourceReference reference, MacroTrans ...@@ -98,9 +98,9 @@ public CodeMacroSource getContent(CodeMacroSourceReference reference, MacroTrans
// Get the content // Get the content
XWikiDocument document; XWikiDocument document;
try { try {
document = xcontext.getWiki().getDocument(entityReference, xcontext); document = xcontext.getWiki().getDocument(documentReference, xcontext);
} catch (XWikiException e) { } catch (XWikiException e) {
throw new MacroExecutionException("Failed to load document [" + documentReference + "]"); throw new MacroExecutionException("Failed to load document [" + documentReference + "]", e);
} }
// Get the current translation // Get the current translation
...@@ -109,7 +109,7 @@ public CodeMacroSource getContent(CodeMacroSourceReference reference, MacroTrans ...@@ -109,7 +109,7 @@ public CodeMacroSource getContent(CodeMacroSourceReference reference, MacroTrans
document = document.getTranslatedDocument(xcontext); document = document.getTranslatedDocument(xcontext);
} catch (XWikiException e) { } catch (XWikiException e) {
throw new MacroExecutionException( throw new MacroExecutionException(
"Failed to load document translation for reference [" + documentReference + "]"); "Failed to load document translation for reference [" + documentReference + "]", e);
} }
} }
...@@ -132,7 +132,7 @@ private CodeMacroSource getContent(XWikiDocument document, EntityReference entit ...@@ -132,7 +132,7 @@ private CodeMacroSource getContent(XWikiDocument document, EntityReference entit
this.componentManager.getInstance(EntityCodeMacroSourceLoader.class, entityReference.getType().name()); this.componentManager.getInstance(EntityCodeMacroSourceLoader.class, entityReference.getType().name());
} catch (ComponentLookupException e) { } catch (ComponentLookupException e) {
throw new MacroExecutionException("Unexpected error when initializing the content loader for entity type [" throw new MacroExecutionException("Unexpected error when initializing the content loader for entity type ["
+ entityReference.getType() + "]"); + entityReference.getType() + "]", e);
} }
return loader.load(document, entityReference, reference, xcontext); return loader.load(document, entityReference, reference, xcontext);
......
...@@ -44,7 +44,7 @@ public class CodeMacroSource ...@@ -44,7 +44,7 @@ public class CodeMacroSource
/** /**
* @param reference the reference of the content * @param reference the reference of the content
* @param content the content to highlight * @param content the content to highlight
* @param language the language of the content * @param language the language of the content if known, null otherwise
*/ */
public CodeMacroSource(CodeMacroSourceReference reference, String content, String language) public CodeMacroSource(CodeMacroSourceReference reference, String content, String language)
{ {
...@@ -70,7 +70,7 @@ public String getContent() ...@@ -70,7 +70,7 @@ public String getContent()
} }
/** /**
* @return the language of the content * @return the language of the content if known, null otherwise
*/ */
public String getLanguage() public String getLanguage()
{ {
......
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