use of org.xwiki.rendering.syntax.Syntax in project xwiki-platform by xwiki.
the class DefaultHTMLConverter method parseAndRender.
@Override
public String parseAndRender(String dirtyHTML, String syntaxId) {
try {
// Clean
String html = this.htmlCleaner.clean(dirtyHTML);
// Parse
XDOM xdom = this.xhtmlParser.parse(new StringReader(html));
// The XHTML parser sets the "syntax" meta data property of the created XDOM to "xhtml/1.0". The syntax meta
// data is used as the default syntax for macro content. We have to change this to the specified syntax
// because HTML is used only to be able to edit the source syntax in the WYSIWYG editor.
Syntax syntax = Syntax.valueOf(syntaxId);
xdom.getMetaData().addMetaData(MetaData.SYNTAX, syntax);
// Execute the macro transformation
executeMacroTransformation(xdom, Syntax.valueOf(syntaxId));
// Render
WikiPrinter printer = new DefaultWikiPrinter();
this.xhtmlRenderer.render(xdom, printer);
return printer.toString();
} catch (Exception e) {
this.logger.error(e.getLocalizedMessage(), e);
throw new RuntimeException("Exception while refreshing HTML", e);
}
}
use of org.xwiki.rendering.syntax.Syntax in project xwiki-platform by xwiki.
the class DefaultIOTargetServiceTest method testGetterWhenTargetIsTypedIndexedObjectProperty.
@Test
public void testGetterWhenTargetIsTypedIndexedObjectProperty() throws Exception {
final DocumentModelBridge dmb = getMockery().mock(DocumentModelBridge.class);
getMockery().checking(new Expectations() {
{
allowing(classResolver).resolve("XWiki.Class", new DocumentReference("wiki", "Space", "Page"));
will(returnValue(new DocumentReference("wiki", "XWiki", "Class")));
oneOf(dabMock).getProperty(new DocumentReference("wiki", "Space", "Page"), new DocumentReference("wiki", "XWiki", "Class"), 1, "property");
will(returnValue("defcontent"));
oneOf(dabMock).getTranslatedDocumentInstance(new DocumentReference("wiki", "Space", "Page"));
will(returnValue(dmb));
oneOf(dmb).getSyntax();
will(returnValue(new Syntax(SyntaxType.XWIKI, "2.0")));
}
});
String reference = "OBJECT_PROPERTY://wiki:Space.Page^XWiki.Class[1].property";
assertEquals("defcontent", ioTargetService.getSource(reference));
assertEquals("xwiki/2.0", ioTargetService.getSourceSyntax(reference));
}
use of org.xwiki.rendering.syntax.Syntax in project xwiki-platform by xwiki.
the class DefaultIOTargetServiceTest method testGettersWhenTargetIsEmptyString.
@Test
public void testGettersWhenTargetIsEmptyString() throws Exception {
final DocumentModelBridge dmb = getMockery().mock(DocumentModelBridge.class);
getMockery().checking(new Expectations() {
{
// default resolver should be used. Note that this will fail if default values change, not very well
// isolated
allowing(dabMock).getTranslatedDocumentInstance(new DocumentReference("xwiki", "Main", "WebHome"));
will(returnValue(dmb));
oneOf(dmb).getContent();
will(returnValue("defcontent"));
oneOf(dmb).getSyntax();
will(returnValue(new Syntax(SyntaxType.XWIKI, "2.0")));
}
});
// expect source ref to be used as is, as it doesn't parse to something acceptable
String reference = "";
assertEquals("defcontent", ioTargetService.getSource(reference));
assertEquals("xwiki/2.0", ioTargetService.getSourceSyntax(reference));
}
use of org.xwiki.rendering.syntax.Syntax in project xwiki-platform by xwiki.
the class DefaultIOTargetServiceTest method testGetterWhenTargetIsTypedDefaultObjectProperty.
@Test
public void testGetterWhenTargetIsTypedDefaultObjectProperty() throws Exception {
final DocumentModelBridge dmb = getMockery().mock(DocumentModelBridge.class);
getMockery().checking(new Expectations() {
{
allowing(classResolver).resolve("XWiki.Class", new DocumentReference("wiki", "Space", "Page"));
will(returnValue(new DocumentReference("wiki", "XWiki", "Class")));
oneOf(dabMock).getProperty(new DocumentReference("wiki", "Space", "Page"), new DocumentReference("wiki", "XWiki", "Class"), "property");
will(returnValue("defcontent"));
oneOf(dabMock).getTranslatedDocumentInstance(new DocumentReference("wiki", "Space", "Page"));
will(returnValue(dmb));
oneOf(dmb).getSyntax();
will(returnValue(new Syntax(SyntaxType.XWIKI, "2.0")));
}
});
String reference = "OBJECT_PROPERTY://wiki:Space.Page^XWiki.Class.property";
assertEquals("defcontent", ioTargetService.getSource(reference));
assertEquals("xwiki/2.0", ioTargetService.getSourceSyntax(reference));
}
use of org.xwiki.rendering.syntax.Syntax in project xwiki-platform by xwiki.
the class XAROutputFilterStream method beginWikiDocumentRevision.
@Override
public void beginWikiDocumentRevision(String revision, FilterEventParameters parameters) throws FilterException {
checkXMLWriter();
this.currentDocumentVersion = revision;
try {
if (parameters.containsKey(XWikiWikiDocumentFilter.PARAMETER_PARENT)) {
this.writer.writeElement(XarDocumentModel.ELEMENT_PARENT, toString((EntityReference) parameters.get(XWikiWikiDocumentFilter.PARAMETER_PARENT)));
}
if (parameters.containsKey(XWikiWikiDocumentFilter.PARAMETER_REVISION_AUTHOR)) {
this.writer.writeElement(XarDocumentModel.ELEMENT_REVISION_AUTHOR, (String) parameters.get(XWikiWikiDocumentFilter.PARAMETER_REVISION_AUTHOR));
}
if (parameters.containsKey(XWikiWikiDocumentFilter.PARAMETER_CUSTOMCLASS)) {
this.writer.writeElement(XarDocumentModel.ELEMENT_CUSTOMCLASS, (String) parameters.get(XWikiWikiDocumentFilter.PARAMETER_CUSTOMCLASS));
}
if (parameters.containsKey(XWikiWikiDocumentFilter.PARAMETER_CONTENT_AUTHOR)) {
this.writer.writeElement(XarDocumentModel.ELEMENT_CONTENT_AUTHOR, (String) parameters.get(XWikiWikiDocumentFilter.PARAMETER_CONTENT_AUTHOR));
}
if (parameters.containsKey(XWikiWikiDocumentFilter.PARAMETER_REVISION_DATE)) {
this.writer.writeElement(XarDocumentModel.ELEMENT_REVISION_DATE, toString((Date) parameters.get(XWikiWikiDocumentFilter.PARAMETER_REVISION_DATE)));
}
if (parameters.containsKey(XWikiWikiDocumentFilter.PARAMETER_CONTENT_DATE)) {
this.writer.writeElement(XarDocumentModel.ELEMENT_CONTENT_DATE, toString((Date) parameters.get(XWikiWikiDocumentFilter.PARAMETER_CONTENT_DATE)));
}
this.writer.writeElement(XarDocumentModel.ELEMENT_REVISION, this.currentDocumentVersion);
if (parameters.containsKey(XWikiWikiDocumentFilter.PARAMETER_TITLE)) {
this.writer.writeElement(XarDocumentModel.ELEMENT_TITLE, (String) parameters.get(XWikiWikiDocumentFilter.PARAMETER_TITLE));
}
if (parameters.containsKey(XWikiWikiDocumentFilter.PARAMETER_DEFAULTTEMPLATE)) {
this.writer.writeElement(XarDocumentModel.ELEMENT_DEFAULTTEMPLATE, (String) parameters.get(XWikiWikiDocumentFilter.PARAMETER_DEFAULTTEMPLATE));
}
if (parameters.containsKey(XWikiWikiDocumentFilter.PARAMETER_VALIDATIONSCRIPT)) {
this.writer.writeElement(XarDocumentModel.ELEMENT_VALIDATIONSCRIPT, (String) parameters.get(XWikiWikiDocumentFilter.PARAMETER_VALIDATIONSCRIPT));
}
if (parameters.containsKey(XWikiWikiDocumentFilter.PARAMETER_REVISION_COMMENT)) {
this.writer.writeElement(XarDocumentModel.ELEMENT_REVISION_COMMENT, (String) parameters.get(XWikiWikiDocumentFilter.PARAMETER_REVISION_COMMENT));
}
if (parameters.containsKey(XWikiWikiDocumentFilter.PARAMETER_REVISION_MINOR)) {
this.writer.writeElement(XarDocumentModel.ELEMENT_REVISION_MINOR, toString(parameters.get(XWikiWikiDocumentFilter.PARAMETER_REVISION_MINOR)));
}
if (parameters.containsKey(XWikiWikiDocumentFilter.PARAMETER_SYNTAX)) {
this.writer.writeElement(XarDocumentModel.ELEMENT_SYNTAX, toString((Syntax) parameters.get(XWikiWikiDocumentFilter.PARAMETER_SYNTAX)));
}
if (parameters.containsKey(XWikiWikiDocumentFilter.PARAMETER_HIDDEN)) {
this.writer.writeElement(XarDocumentModel.ELEMENT_HIDDEN, toString(parameters.get(XWikiWikiDocumentFilter.PARAMETER_HIDDEN)));
}
if (parameters.containsKey(XWikiWikiDocumentFilter.PARAMETER_CONTENT)) {
this.writer.writeElement(XarDocumentModel.ELEMENT_CONTENT, (String) parameters.get(XWikiWikiDocumentFilter.PARAMETER_CONTENT));
}
if (parameters.containsKey(XWikiWikiDocumentFilter.PARAMETER_CONTENT_HTML)) {
this.writer.writeElement(XarDocumentModel.ELEMENT_CONTENT_HTML, (String) parameters.get(XWikiWikiDocumentFilter.PARAMETER_CONTENT_HTML));
}
} catch (Exception e) {
throw new FilterException(String.format("Failed to write begin document [%s] with version [%s]", this.currentDocumentReference, this.currentDocumentVersion), e);
}
}
Aggregations