use of org.xwiki.rendering.block.GroupBlock in project xwiki-platform by xwiki.
the class DashboardMacro method execute.
@Override
public List<Block> execute(DashboardMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException {
// We don't allow calling the Dashboard macro inside the Dashboard macro to prevent recursions!
preventDashboardRecursion();
// get the gadgets from the objects
List<Gadget> gadgets;
try {
gadgets = this.gadgetSource.getGadgets(parameters.getSource(), context);
} catch (Exception e) {
String message = "Could not get the gadgets.";
// log and throw further
this.logger.error(message, e);
throw new MacroExecutionException(message, e);
}
boolean isInEditMode = this.gadgetSource.isEditing();
DashboardRenderer renderer = getDashboardRenderer(StringUtils.isEmpty(parameters.getLayout()) ? "columns" : parameters.getLayout());
if (renderer == null) {
String message = "Could not find dashboard renderer " + parameters.getLayout();
// log and throw further
this.logger.error(message);
throw new MacroExecutionException(message);
}
GadgetRenderer gadgetRenderer = getGadgetRenderer(isInEditMode);
// else, layout
List<Block> layoutedResult;
try {
layoutedResult = renderer.renderGadgets(gadgets, gadgetRenderer, context);
} catch (Exception e) {
String message = "Could not render the gadgets for layout " + parameters.getLayout();
// log and throw further
this.logger.error(message, e);
throw new MacroExecutionException(message, e);
}
// include the css and js for this macro. here so that it's included after any dependencies have included their
// css, so that it cascades properly
this.includeResources(isInEditMode);
// put everything in a nice toplevel group for this dashboard, to be able to add classes to it
GroupBlock topLevel = new GroupBlock();
// mode
if (isInEditMode) {
topLevel.addChildren(this.gadgetSource.getDashboardSourceMetadata(parameters.getSource(), context));
}
topLevel.addChildren(layoutedResult);
// add the style attribute of the dashboard macro as a class to the toplevel container
topLevel.setParameter("class", MACRO_NAME + (StringUtils.isEmpty(parameters.getStyle()) ? "" : " " + parameters.getStyle()));
// Reduce by 1 the recursive count so that we can have several dashboard macros rendered in the same context
reduceDashboardRecursionCounter();
return Collections.<Block>singletonList(topLevel);
}
use of org.xwiki.rendering.block.GroupBlock in project xwiki-platform by xwiki.
the class DefaultGadgetSource method getDashboardSourceMetadata.
@Override
public List<Block> getDashboardSourceMetadata(String source, MacroTransformationContext context) {
DocumentReference sourceDoc = getSourceDocumentReference(source);
String classParameterName = "class";
GroupBlock metadataContainer = new GroupBlock();
metadataContainer.setParameter(classParameterName, DashboardMacro.METADATA);
// generate anchors for the urls
XWikiContext xContext = getXWikiContext();
String editURL = xContext.getWiki().getURL(sourceDoc, "save", "", "", xContext);
LinkBlock editURLBlock = new LinkBlock(Collections.<Block>emptyList(), new ResourceReference(editURL, ResourceType.URL), false);
editURLBlock.setParameter(classParameterName, DashboardMacro.EDIT_URL);
metadataContainer.addChild(editURLBlock);
String removeURL = xContext.getWiki().getURL(sourceDoc, "objectremove", "", "", xContext);
LinkBlock removeURLBlock = new LinkBlock(Collections.<Block>emptyList(), new ResourceReference(removeURL, ResourceType.URL), false);
removeURLBlock.setParameter(classParameterName, DashboardMacro.REMOVE_URL);
metadataContainer.addChild(removeURLBlock);
String addURL = xContext.getWiki().getURL(sourceDoc, "objectadd", "", "", xContext);
LinkBlock addURLBlock = new LinkBlock(Collections.<Block>emptyList(), new ResourceReference(addURL, ResourceType.URL), false);
addURLBlock.setParameter(classParameterName, DashboardMacro.ADD_URL);
metadataContainer.addChild(addURLBlock);
// and create divs for the source metadata
GroupBlock sourcePageBlock = new GroupBlock();
sourcePageBlock.addChild(new WordBlock(sourceDoc.getName()));
sourcePageBlock.setParameter(classParameterName, DashboardMacro.SOURCE_PAGE);
metadataContainer.addChild(sourcePageBlock);
GroupBlock sourceSpaceBlock = new GroupBlock();
// Extract the full Space Reference (in order to support Nested Spaces) and set it in the XDOM
sourceSpaceBlock.addChild(new WordBlock(this.localReferenceSerializer.serialize(sourceDoc.getLastSpaceReference())));
sourceSpaceBlock.setParameter(classParameterName, DashboardMacro.SOURCE_SPACE);
metadataContainer.addChild(sourceSpaceBlock);
GroupBlock sourceWikiBlock = new GroupBlock();
sourceWikiBlock.addChild(new WordBlock(sourceDoc.getWikiReference().getName()));
sourceWikiBlock.setParameter(classParameterName, DashboardMacro.SOURCE_WIKI);
metadataContainer.addChild(sourceWikiBlock);
String sourceURL = xContext.getWiki().getURL(sourceDoc, "view", "", "", xContext);
LinkBlock sourceURLBlock = new LinkBlock(Collections.<Block>emptyList(), new ResourceReference(sourceURL, ResourceType.URL), false);
sourceURLBlock.setParameter(classParameterName, DashboardMacro.SOURCE_URL);
metadataContainer.addChild(sourceURLBlock);
return Collections.<Block>singletonList(metadataContainer);
}
use of org.xwiki.rendering.block.GroupBlock in project xwiki-platform by xwiki.
the class GalleryMacro method execute.
@Override
public List<Block> execute(GalleryMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException {
if (context != null) {
Map<String, Object> skinExtensionParameters = Collections.singletonMap("forceSkinAction", (Object) true);
this.jsfx.use("uicomponents/widgets/gallery/gallery.js", skinExtensionParameters);
this.ssfx.use("uicomponents/widgets/gallery/gallery.css");
StringBuilder inlineStyle = new StringBuilder();
if (!StringUtils.isEmpty(parameters.getWidth())) {
// Non-empty width value. The empty value means "no explicit width".
inlineStyle.append("width: ").append(parameters.getWidth()).append(';');
} else if (parameters.getWidth() == null) {
// Default width when none is specified.
inlineStyle.append("width: 620px;");
}
if (!StringUtils.isEmpty(parameters.getHeight())) {
// Non-empty height value. The empty value means "no explicit height".
inlineStyle.append("height: ").append(parameters.getHeight()).append(';');
} else if (parameters.getHeight() == null) {
// Default height when none is specified (16:9 aspect ratio).
inlineStyle.append("height: 349px;");
}
Map<String, String> groupParameters = new HashMap<>();
groupParameters.put("class", ("gallery " + StringUtils.defaultString(parameters.getClassNames())).trim());
if (inlineStyle.length() > 0) {
groupParameters.put("style", inlineStyle.toString());
}
Block galleryBlock = new GroupBlock(groupParameters);
// Don't execute transformations explicitly. They'll be executed on the generated content later on.
galleryBlock.addChildren(this.contentParser.parse(content, context, false, false).getChildren());
return Collections.singletonList(galleryBlock);
} else {
return Collections.emptyList();
}
}
use of org.xwiki.rendering.block.GroupBlock in project xwiki-platform by xwiki.
the class AbstractContainerMacro method execute.
@Override
public List<Block> execute(P parameters, String content, MacroTransformationContext context) throws MacroExecutionException {
// TODO: include here container CSS. FTM the only rule, the one about justified text, is in the columns.css, in
// which case the justification makes the most sense.
// transform the container in a group, with appropriate parameters
Map<String, String> containerParameters = new HashMap<String, String>();
if (parameters.isJustify()) {
containerParameters.put(CLASS_ATTRIBUTE, "container-justified");
}
// create the root block for the container macro, as a group block, and add all the blocks resulted from parsing
// its content
GroupBlock containerRoot = new GroupBlock(containerParameters);
containerRoot.addChildren(getContent(parameters, content, context));
// grab the layout manager to layout this container
LayoutManager layoutManager = getLayoutManager(parameters.getLayoutStyle());
// if a suitable layout manager was found, layout this container
if (layoutManager != null) {
layoutManager.layoutContainer(containerRoot);
}
// add the css class, if any, to the container root
if (StringUtils.isNotEmpty(parameters.getCssClass())) {
containerRoot.setParameter(CLASS_ATTRIBUTE, parameters.getCssClass());
}
// and finally return the styled container root
return Collections.<Block>singletonList(containerRoot);
}
use of org.xwiki.rendering.block.GroupBlock in project xwiki-platform by xwiki.
the class CodeMacro method parseContent.
@Override
protected List<Block> parseContent(CodeMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException {
List<Block> result;
try {
if (LANGUAGE_NONE.equalsIgnoreCase(parameters.getLanguage())) {
if (StringUtils.isEmpty(content)) {
result = Collections.emptyList();
} else {
result = this.plainTextParser.parse(new StringReader(content)).getChildren().get(0).getChildren();
}
} else {
result = highlight(parameters, content);
}
} catch (Exception e) {
throw new MacroExecutionException("Failed to highlight content", e);
}
Map<String, String> formatParameters = new LinkedHashMap<String, String>();
formatParameters.put("class", "code");
if (context.isInline()) {
result = Arrays.<Block>asList(new FormatBlock(result, Format.NONE, formatParameters));
} else {
result = Arrays.<Block>asList(new GroupBlock(result, formatParameters));
}
return result;
}
Aggregations