use of org.xwiki.rendering.syntax.Syntax in project xwiki-platform by xwiki.
the class OfficeImporterScriptServiceTest method saveWithAppend.
@Test
public void saveWithAppend() throws Exception {
XDOMOfficeDocument doc = mock(XDOMOfficeDocument.class);
DocumentReference documentReference = new DocumentReference("wiki", "Space", "Page");
String syntaxId = "test/1.0";
when(documentAccessBridge.isDocumentEditable(documentReference)).thenReturn(true);
when(documentAccessBridge.exists(documentReference)).thenReturn(true);
DocumentModelBridge document = mock(DocumentModelBridge.class);
when(documentAccessBridge.getTranslatedDocumentInstance(documentReference)).thenReturn(document);
when(document.getSyntax()).thenReturn(new Syntax(new SyntaxType("test", "Test"), "1.0"));
when(documentAccessBridge.getDocumentContent(documentReference, null)).thenReturn("before");
when(doc.getContentAsString(syntaxId)).thenReturn("after");
assertTrue(officeImporterScriptService.save(doc, documentReference, syntaxId, null, null, true));
verify(documentAccessBridge).setDocumentContent(documentReference, "before\nafter", "Updated by office importer.", false);
}
use of org.xwiki.rendering.syntax.Syntax 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.rendering.syntax.Syntax 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.rendering.syntax.Syntax in project xwiki-platform by xwiki.
the class PanelWikiUIExtensionComponentBuilder method buildComponents.
@Override
public List<WikiComponent> buildComponents(BaseObject baseObject) throws WikiComponentException {
String content = baseObject.getStringValue("content");
Syntax syntax = baseObject.getOwnerDocument().getSyntax();
DocumentReference documentReference = baseObject.getOwnerDocument().getDocumentReference();
DocumentReference authorReference = baseObject.getOwnerDocument().getAuthorReference();
XDOM xdom = this.parser.parse(content, syntax, documentReference);
try {
return Collections.<WikiComponent>singletonList(new PanelWikiUIExtension(baseObject.getReference(), authorReference, xdom, syntax, this.componentManager));
} catch (ComponentLookupException e) {
throw new WikiComponentException(String.format("Failed to initialize Panel UI extension [%s]", baseObject), e);
}
}
use of org.xwiki.rendering.syntax.Syntax in project xwiki-platform by xwiki.
the class XWikiDocument method setSyntaxId.
/**
* Note that this method cannot be removed for now since it's used by Hibernate for saving a XWikiDocument.
*
* @param syntaxId the new syntax id to set (e.g. {@code xwiki/2.0}, {@code xwiki/2.1}, etc)
* @see #getSyntaxId()
* @deprecated since 2.3M1, use {link #setSyntax(Syntax)} instead
*/
@Deprecated
public void setSyntaxId(String syntaxId) {
Syntax syntax;
// syntax/1.0 syntax.
if (StringUtils.isBlank(syntaxId)) {
syntax = Syntax.XWIKI_1_0;
} else {
try {
syntax = Syntax.valueOf(syntaxId);
} catch (ParseException e) {
syntax = getDefaultDocumentSyntax();
LOGGER.warn("Failed to set syntax [" + syntaxId + "] for [" + getDefaultEntityReferenceSerializer().serialize(getDocumentReference()) + "], setting syntax [" + syntax.toIdString() + "] instead.", e);
}
}
setSyntax(syntax);
}
Aggregations