use of org.xwiki.rendering.block.RawBlock in project xwiki-platform by xwiki.
the class RssMacro method generateEntries.
/**
* Renders the given RSS's entries.
*
* @param parentBlock the parent Block to which the output is going to be added
* @param feed the RSS Channel we retrieved via the Feed URL
* @param parameters our parameter helper object
* @throws MacroExecutionException if the content cannot be rendered
*/
private void generateEntries(Block parentBlock, SyndFeed feed, RssMacroParameters parameters) throws MacroExecutionException {
int maxElements = parameters.getCount();
int count = 0;
for (Object item : feed.getEntries()) {
++count;
if (count > maxElements) {
break;
}
SyndEntry entry = (SyndEntry) item;
ResourceReference titleResourceReference = new ResourceReference(entry.getLink(), ResourceType.URL);
Block titleBlock = new LinkBlock(parsePlainText(entry.getTitle()), titleResourceReference, true);
ParagraphBlock paragraphTitleBlock = new ParagraphBlock(Collections.singletonList(titleBlock));
paragraphTitleBlock.setParameter(CLASS_ATTRIBUTE, "rssitemtitle");
parentBlock.addChild(paragraphTitleBlock);
if (parameters.isContent() && entry.getDescription() != null) {
// We are wrapping the feed entry content in a HTML macro, not considering what the declared content
// is, because some feed will declare text while they actually contain HTML.
// See http://stuffthathappens.com/blog/2007/10/29/i-hate-rss/
// A case where doing this might hurt is if a feed declares "text" and has any XML inside it does
// not want to be interpreted as such, but displayed as is instead. But this certainly is too rare
// compared to mis-formed feeds that say text while they want to say HTML.
Block html = new RawBlock(entry.getDescription().getValue(), Syntax.XHTML_1_0);
parentBlock.addChild(new GroupBlock(Arrays.asList(html), Collections.singletonMap(CLASS_ATTRIBUTE, "rssitemdescription")));
}
}
}
use of org.xwiki.rendering.block.RawBlock 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;
}
Aggregations