use of org.xwiki.rendering.block.GroupBlock in project xwiki-platform by xwiki.
the class EditableGadgetRenderer method getGadgetEditMetadata.
/**
* @param gadget the gadget to decorate
* @return the block containing the metadata that will allow clients to edit this gadget
*/
protected Block getGadgetEditMetadata(Gadget gadget) {
GroupBlock metadataBlock = new GroupBlock();
metadataBlock.setParameter(CLASS, METADATA);
// look at the content of the gadget and store whether it's a macro or not
boolean isMacro = gadget.getContent().size() == 1 && gadget.getContent().get(0) instanceof MacroMarkerBlock;
GroupBlock isMacroBlock = new GroupBlock();
isMacroBlock.setParameter(CLASS, "isMacro");
isMacroBlock.addChild(new WordBlock(Boolean.toString(isMacro)));
metadataBlock.addChild(isMacroBlock);
if (isMacro) {
// render the annotated macro call in the page, to be able to edit it. Only the macro call comments will be
// rendered, since transformations are not ran, so there is no content in the macro. But annotation is
// enough.
GroupBlock renderedContentBlock = new GroupBlock();
renderedContentBlock.setParameter(CLASS, "content");
WikiPrinter printer = new DefaultWikiPrinter();
BlockRenderer gadgetContentRenderer = getGadgetContentRenderer();
gadgetContentRenderer.render(gadget.getContent(), printer);
RawBlock rawBlock = new RawBlock(printer.toString(), getRawBlockSyntax(gadgetContentRenderer));
renderedContentBlock.addChild(rawBlock);
// render the title in the page as well, to be edited as source
GroupBlock gadgetTitleBlock = new GroupBlock();
gadgetTitleBlock.setParameter(CLASS, "title");
// even if it's not a word, it's fine since it will be rendered in one piece
gadgetTitleBlock.addChild(new WordBlock(gadget.getTitleSource()));
metadataBlock.addChild(renderedContentBlock);
metadataBlock.addChild(gadgetTitleBlock);
}
return metadataBlock;
}
use of org.xwiki.rendering.block.GroupBlock in project xwiki-platform by xwiki.
the class RssMacro method execute.
@Override
public List<Block> execute(RssMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException {
List<Block> result;
SyndFeed feed = this.romeFeedFactory.createFeed(parameters);
if (parameters.isDecoration()) {
BoxMacroParameters boxParameters = new BoxMacroParameters();
boolean hasImage = parameters.isImage() && (feed.getImage() != null);
boxParameters.setCssClass(FEED_CLASS_VALUE);
if (StringUtils.isNotEmpty(parameters.getWidth())) {
boxParameters.setWidth(parameters.getWidth());
}
boxParameters.setBlockTitle(generateBoxTitle("rsschanneltitle", feed));
if (hasImage) {
boxParameters.setImage(new ResourceReference(feed.getImage().getUrl(), ResourceType.URL));
}
result = this.boxMacro.execute(boxParameters, content == null ? StringUtils.EMPTY : content, context);
} else {
result = Arrays.<Block>asList(new GroupBlock(Collections.singletonMap(CLASS_ATTRIBUTE, FEED_CLASS_VALUE)));
}
generateEntries(result.get(0), feed, parameters);
return result;
}
use of org.xwiki.rendering.block.GroupBlock in project xwiki-platform by xwiki.
the class ColumnsLayoutManager method layoutContainer.
@Override
public void layoutContainer(Block container) {
List<GroupBlock> innerGroups = container.getBlocks(new ClassBlockMatcher(GroupBlock.class), Block.Axes.CHILD);
// FIXME Should we cry and throw an exception if ever we meet something else than a group right under
// the container macro, or automatically put it in a group maybe ?
int count = innerGroups.size();
if (innerGroups.size() == 0) {
// nothing inside, nothing to layout
return;
}
Map<String, Object> skinxParams = new HashMap<String, Object>();
skinxParams.put("forceSkinAction", true);
ssfx.use("uicomponents/container/columns.css", skinxParams);
// add styles to all columns inside
for (int i = 0; i < count; i++) {
GroupBlock column = innerGroups.get(i);
String classValue = "column";
if (i == 0) {
// we're at the first element in the list, put a marker. Don't need it to do standard columns layout,
// but maybe somebody needs it for customization...
classValue = classValue + " first-column";
}
if (i == count - 1) {
// we're at the last element in the list, put a marker
classValue = classValue + " last-column";
}
String oldClass = column.getParameter(CLASS_ATTRIBUTE);
column.setParameter(CLASS_ATTRIBUTE, (StringUtils.isEmpty(oldClass) ? classValue : oldClass + " " + classValue));
}
// finally, clear the floats introduced by the columns
Map<String, String> clearFloatsParams = new HashMap<String, String>();
clearFloatsParams.put(CLASS_ATTRIBUTE, "clearfloats");
String oldClass = container.getParameter(CLASS_ATTRIBUTE);
String newClass = "container-columns container-columns-" + count;
container.setParameter(CLASS_ATTRIBUTE, StringUtils.isEmpty(oldClass) ? newClass : oldClass + " " + newClass);
container.addChild(new GroupBlock(clearFloatsParams));
}
use of org.xwiki.rendering.block.GroupBlock in project xwiki-platform by xwiki.
the class TranslationMacro method execute.
@Override
public List<Block> execute(TranslationMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException {
Locale locale = parameters.getLocale() != null ? parameters.getLocale() : this.localizationContext.getCurrentLocale();
Translation translation = this.localization.getTranslation(parameters.getKey(), locale);
List<Block> blocks;
if (translation != null) {
Block block = parameters.getParameters() != null ? translation.render(locale, (Object[]) parameters.getParameters()) : translation.render(locale);
if (block instanceof CompositeBlock) {
blocks = block.getChildren();
} else {
blocks = Arrays.asList(block);
}
if (!context.getCurrentMacroBlock().isInline()) {
// Make the content standalone
blocks = Arrays.<Block>asList(new GroupBlock(blocks));
}
} else if (content != null) {
blocks = this.macroContentParser.parse(content, context, false, context.getCurrentMacroBlock().isInline()).getChildren();
} else {
try {
blocks = this.plainParser.parse(new StringReader(parameters.getKey())).getChildren();
if (context.getCurrentMacroBlock().isInline()) {
PARSERUTILS.removeTopLevelParagraph(blocks);
}
} catch (ParseException e) {
throw new MacroExecutionException("Failed to parse key [" + parameters.getKey() + "]", e);
}
}
return blocks;
}
Aggregations