use of org.xwiki.display.internal.DocumentDisplayerParameters in project xwiki-platform by xwiki.
the class DisplayScriptService method title.
/**
* Displays the document title. If a title has not been provided through the title field, it looks for a section
* title in the document's content and if not found return the page name. The returned title is also interpreted
* which means it's allowed to use Velocity, Groovy, etc. syntax within a title.
*
* @param document the document whose title is displayed
* @param parameters the display parameters
* @return the result of displaying the title of the given document
*/
public String title(Document document, Map<String, Object> parameters) {
Map<String, Object> actualParameters = new HashMap<String, Object>(parameters);
DocumentDisplayerParameters displayerParameters = (DocumentDisplayerParameters) parameters.get(DISPLAYER_PARAMETERS_KEY);
if (displayerParameters == null) {
displayerParameters = new DocumentDisplayerParameters();
// Default title display parameters.
displayerParameters.setExecutionContextIsolated(true);
} else if (!displayerParameters.isTitleDisplayed()) {
// Clone because we have to enforce title display.
displayerParameters = displayerParameters.clone();
}
// Ensure the title is displayed.
displayerParameters.setTitleDisplayed(true);
Syntax outputSyntax = getOutputSyntax(parameters);
displayerParameters.setTargetSyntax(outputSyntax);
actualParameters.put(DISPLAYER_PARAMETERS_KEY, displayerParameters);
return document(document, actualParameters, outputSyntax);
}
use of org.xwiki.display.internal.DocumentDisplayerParameters in project xwiki-platform by xwiki.
the class DisplayScriptService method content.
/**
* Displays the content of the given document.
*
* @param document the document whose content is displayed
* @param parameters the display parameters
* @return the result of rendering the content of the given document using the provided parameters
*/
public String content(Document document, Map<String, Object> parameters) {
XWikiContext context = getXWikiContext();
String content = null;
try {
content = document.getTranslatedContent();
} catch (XWikiException e) {
this.logger.warn("Failed to get the translated content of document [{}].", document.getPrefixedFullName(), e);
return null;
}
String renderedContent = this.renderingCache.getRenderedContent(document.getDocumentReference(), content, context);
if (renderedContent == null) {
Map<String, Object> actualParameters = new HashMap<String, Object>(parameters);
DocumentDisplayerParameters displayerParameters = (DocumentDisplayerParameters) parameters.get(DISPLAYER_PARAMETERS_KEY);
if (displayerParameters == null) {
displayerParameters = new DocumentDisplayerParameters();
// Default content display parameters.
displayerParameters.setExecutionContextIsolated(true);
displayerParameters.setContentTranslated(true);
} else if (displayerParameters.isTitleDisplayed()) {
// Clone because we have to enforce content display.
displayerParameters = displayerParameters.clone();
}
// Ensure the content is displayed.
displayerParameters.setTitleDisplayed(false);
Syntax outputSyntax = getOutputSyntax(parameters);
displayerParameters.setTargetSyntax(outputSyntax);
actualParameters.put(DISPLAYER_PARAMETERS_KEY, displayerParameters);
renderedContent = document(document, actualParameters, outputSyntax);
if (renderedContent != null) {
this.renderingCache.setRenderedContent(document.getDocumentReference(), content, renderedContent, context);
}
}
return renderedContent;
}
use of org.xwiki.display.internal.DocumentDisplayerParameters in project xwiki-platform by xwiki.
the class IncludeMacro method execute.
@Override
public List<Block> execute(IncludeMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException {
// Step 1: Perform checks.
if (parameters.getReference() == null) {
throw new MacroExecutionException("You must specify a 'reference' parameter pointing to the entity to include.");
}
DocumentReference includedReference = resolve(context.getCurrentMacroBlock(), parameters);
checkRecursiveInclusion(context.getCurrentMacroBlock(), includedReference);
if (!this.documentAccessBridge.isDocumentViewable(includedReference)) {
throw new MacroExecutionException(String.format("Current user [%s] doesn't have view rights on document [%s]", this.documentAccessBridge.getCurrentUserReference(), this.defaultEntityReferenceSerializer.serialize(includedReference)));
}
Context parametersContext = parameters.getContext();
// Step 2: Retrieve the included document.
DocumentModelBridge documentBridge;
try {
documentBridge = this.documentAccessBridge.getDocumentInstance(includedReference);
} catch (Exception e) {
throw new MacroExecutionException("Failed to load Document [" + this.defaultEntityReferenceSerializer.serialize(includedReference) + "]", e);
}
// Step 3: Display the content of the included document.
// Check the value of the "context" parameter.
//
// If CONTEXT_NEW then display the content in an isolated execution and transformation context.
//
// if CONTEXT_CURRENT then display the content without performing any transformations (we don't want any Macro
// to be executed at this stage since they should be executed by the currently running Macro Transformation.
DocumentDisplayerParameters displayParameters = new DocumentDisplayerParameters();
displayParameters.setContentTransformed(parametersContext == Context.NEW);
displayParameters.setExecutionContextIsolated(displayParameters.isContentTransformed());
displayParameters.setSectionId(parameters.getSection());
displayParameters.setTransformationContextIsolated(displayParameters.isContentTransformed());
displayParameters.setTransformationContextRestricted(context.getTransformationContext().isRestricted());
displayParameters.setTargetSyntax(context.getTransformationContext().getTargetSyntax());
displayParameters.setContentTranslated(true);
Stack<Object> references = this.inclusionsBeingExecuted.get();
if (parametersContext == Context.NEW) {
if (references == null) {
references = new Stack<Object>();
this.inclusionsBeingExecuted.set(references);
}
references.push(includedReference);
}
XDOM result;
try {
result = this.documentDisplayer.display(documentBridge, displayParameters);
} catch (Exception e) {
throw new MacroExecutionException(e.getMessage(), e);
} finally {
if (parametersContext == Context.NEW) {
references.pop();
}
}
// Step 4: Wrap Blocks in a MetaDataBlock with the "source" meta data specified so that we know from where the
// content comes and "base" meta data so that reference are properly resolved
MetaDataBlock metadata = new MetaDataBlock(result.getChildren(), result.getMetaData());
String source = this.defaultEntityReferenceSerializer.serialize(includedReference);
metadata.getMetaData().addMetaData(MetaData.SOURCE, source);
if (parametersContext == Context.NEW) {
metadata.getMetaData().addMetaData(MetaData.BASE, source);
}
return Arrays.<Block>asList(metadata);
}
use of org.xwiki.display.internal.DocumentDisplayerParameters in project xwiki-platform by xwiki.
the class DisplayMacro method execute.
@Override
public List<Block> execute(DisplayMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException {
// Step 1: Perform checks.
if (parameters.getReference() == null) {
throw new MacroExecutionException("You must specify a 'reference' parameter pointing to the entity to display.");
}
DocumentReference includedReference = resolve(context.getCurrentMacroBlock(), parameters);
checkRecursiveDisplay(context.getCurrentMacroBlock(), includedReference);
if (!this.documentAccessBridge.isDocumentViewable(includedReference)) {
throw new MacroExecutionException("Current user [" + this.documentAccessBridge.getCurrentUserReference() + "] doesn't have view rights on document [" + this.defaultEntityReferenceSerializer.serialize(includedReference) + "]");
}
// Step 2: Retrieve the included document.
DocumentModelBridge documentBridge;
try {
documentBridge = this.documentAccessBridge.getDocumentInstance(includedReference);
} catch (Exception e) {
throw new MacroExecutionException("Failed to load Document [" + this.defaultEntityReferenceSerializer.serialize(includedReference) + "]", e);
}
// Step 3: Display the content of the included document.
// Display the content in an isolated execution and transformation context.
DocumentDisplayerParameters displayParameters = new DocumentDisplayerParameters();
displayParameters.setContentTransformed(true);
displayParameters.setExecutionContextIsolated(displayParameters.isContentTransformed());
displayParameters.setSectionId(parameters.getSection());
displayParameters.setTransformationContextIsolated(displayParameters.isContentTransformed());
displayParameters.setTargetSyntax(context.getTransformationContext().getTargetSyntax());
displayParameters.setContentTranslated(true);
Stack<Object> references = this.displaysBeingExecuted.get();
if (references == null) {
references = new Stack<Object>();
this.displaysBeingExecuted.set(references);
}
references.push(includedReference);
XDOM result;
try {
result = this.documentDisplayer.display(documentBridge, displayParameters);
} catch (Exception e) {
throw new MacroExecutionException(e.getMessage(), e);
} finally {
references.pop();
}
// Step 4: Wrap Blocks in a MetaDataBlock with the "source" meta data specified so that we know from where the
// content comes and "base" meta data so that reference are properly resolved
MetaDataBlock metadata = new MetaDataBlock(result.getChildren(), result.getMetaData());
String source = this.defaultEntityReferenceSerializer.serialize(includedReference);
metadata.getMetaData().addMetaData(MetaData.SOURCE, source);
metadata.getMetaData().addMetaData(MetaData.BASE, source);
return Arrays.<Block>asList(metadata);
}
use of org.xwiki.display.internal.DocumentDisplayerParameters in project xwiki-platform by xwiki.
the class DocumentTableBlockDataSource method computeXDOM.
/**
* Get the XDOM for the data source.
*
* @param context the Macro context from which we can get the XDOM if the source is in the current content
* @return the XDOM in which the data source is located
* @throws MacroExecutionException in case of an error getting the XDOM
*/
private XDOM computeXDOM(MacroTransformationContext context) throws MacroExecutionException {
XDOM xdom;
// Context and 2) it's going to cause a cycle...
if (isDefinedChartSourceTheCurrentDocument(context.getCurrentMacroBlock())) {
xdom = context.getXDOM();
} else {
try {
DocumentModelBridge document = this.docBridge.getDocumentInstance(this.documentReference);
DocumentDisplayerParameters parameters = new DocumentDisplayerParameters();
parameters.setContentTranslated(true);
parameters.setTargetSyntax(context.getTransformationContext().getTargetSyntax());
parameters.setContentTranslated(true);
xdom = this.documentDisplayer.display(document, parameters);
} catch (Exception e) {
throw new MacroExecutionException(String.format("Error getting Chart table from document [%s]", this.documentReference, e));
}
}
return xdom;
}
Aggregations