use of org.xwiki.rendering.block.WordBlock in project xwiki-platform by xwiki.
the class HeadingNameNamingCriterion method getDocumentName.
@Override
public String getDocumentName(XDOM newDoc) {
String documentName = null;
String prefix = spaceName + ".";
if (newDoc.getChildren().size() > 0) {
Block firstChild = newDoc.getChildren().get(0);
if (firstChild instanceof HeaderBlock) {
// Clone the header block and remove any unwanted stuff
Block clonedHeaderBlock = firstChild.clone(new BlockFilter() {
public List<Block> filter(Block block) {
List<Block> blocks = new ArrayList<Block>();
if (block instanceof WordBlock || block instanceof SpaceBlock || block instanceof SpecialSymbolBlock) {
blocks.add(block);
}
return blocks;
}
});
XDOM xdom = new XDOM(clonedHeaderBlock.getChildren());
WikiPrinter printer = new DefaultWikiPrinter();
this.plainSyntaxRenderer.render(xdom, printer);
documentName = cleanPageName(printer.toString());
}
}
// Fall back if necessary.
if (null == documentName || documentName.equals("")) {
documentName = mainPageNameAndNumberingNamingCriterion.getDocumentName(newDoc);
} else if (prependBasePageName) {
documentName = prefix + basePageName + INDEX_SEPERATOR + documentName;
} else {
documentName = prefix + documentName;
}
// Truncate long document names.
int maxWidth = (documentNames.contains(documentName) || docBridge.exists(documentName)) ? 252 : 255;
if (documentName.length() > maxWidth) {
documentName = documentName.substring(0, maxWidth);
}
// Resolve any name clashes.
String newDocumentName = documentName;
int localIndex = 0;
while (documentNames.contains(newDocumentName) || docBridge.exists(newDocumentName)) {
// Append a trailing local index if the page already exists
newDocumentName = documentName + INDEX_SEPERATOR + (++localIndex);
}
// Add the newly generated document name into the pool of generated document names.
documentNames.add(newDocumentName);
return newDocumentName;
}
use of org.xwiki.rendering.block.WordBlock in project xwiki-platform by xwiki.
the class HelloWorldUIExtension method execute.
@Override
public Block execute() {
List<Block> blocks = new ArrayList<Block>();
blocks.add(new WordBlock("HelloWorld"));
return new CompositeBlock(blocks);
}
use of org.xwiki.rendering.block.WordBlock 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.WordBlock in project xwiki-platform by xwiki.
the class DocumentTitleDisplayerTest method fallbackOnSpaceNameWhenSpaceHomePageTitleIsEmpty.
@Test
public void fallbackOnSpaceNameWhenSpaceHomePageTitleIsEmpty() throws Exception {
EntityReferenceProvider defaultEntityReferenceProvider = this.mocker.getInstance(EntityReferenceProvider.class);
when(defaultEntityReferenceProvider.getDefaultReference(EntityType.DOCUMENT)).thenReturn(new EntityReference("Page", EntityType.DOCUMENT));
DocumentModelBridge document = mock(DocumentModelBridge.class);
when(document.getDocumentReference()).thenReturn(new DocumentReference("wiki", Arrays.asList("Space"), "Page"));
XDOM titleXDOM = new XDOM(Arrays.asList(new WordBlock("Space")));
Parser plainTextParser = this.mocker.getInstance(Parser.class, "plain/1.0");
when(plainTextParser.parse(any(StringReader.class))).thenReturn(titleXDOM);
DocumentDisplayerParameters params = new DocumentDisplayerParameters();
params.setTitleDisplayed(true);
assertSame(titleXDOM, this.mocker.getComponentUnderTest().display(document, params));
ArgumentCaptor<Reader> argument = ArgumentCaptor.forClass(Reader.class);
verify(plainTextParser).parse(argument.capture());
assertEquals("Space", IOUtils.toString(argument.getValue()));
}
use of org.xwiki.rendering.block.WordBlock in project xwiki-platform by xwiki.
the class MessageToolTranslationMessageParserTest method messageWithChoiceSyntax.
@Test
public void messageWithChoiceSyntax() throws ComponentLookupException {
TranslationMessage translationMessage = getMockedComponent().parse("{0,choice,0#choice1|0<choice2}");
Assert.assertEquals("{0,choice,0#choice1|0<choice2}", translationMessage.getRawSource());
Assert.assertEquals(new WordBlock("choice1"), translationMessage.render(null, null, 0));
Assert.assertEquals(new WordBlock("choice2"), translationMessage.render(null, null, 42));
}
Aggregations