本文整理了Java中org.xwiki.rendering.parser.Parser.parse()
方法的一些代码示例,展示了Parser.parse()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Parser.parse()
方法的具体详情如下:
包路径:org.xwiki.rendering.parser.Parser
类名称:Parser
方法名:parse
暂无
代码示例来源:origin: org.xwiki.rendering/xwiki-rendering-test
private String convert(String source, Parser parser, BlockRenderer blockRenderer) throws Exception
{
XDOM xdom = parser.parse(new StringReader(source));
WikiPrinter printer = new DefaultWikiPrinter();
blockRenderer.render(xdom, printer);
return printer.toString();
}
代码示例来源:origin: com.xpn.xwiki.platform/xwiki-core
private static XDOM parseContent(String syntaxId, String content) throws XWikiException
{
try {
Parser parser = Utils.getComponent(Parser.class, syntaxId);
return parser.parse(new StringReader(content));
} catch (ParseException e) {
throw new XWikiException(XWikiException.MODULE_XWIKI_RENDERING, XWikiException.ERROR_XWIKI_UNKNOWN,
"Failed to parse content of syntax [" + syntaxId + "]", e);
}
}
代码示例来源:origin: org.xwiki.platform/xwiki-platform-display-api
/**
* Parses the given title as plain text and returns the generated XDOM.
*
* @param title the title to be parsed
* @return the XDOM generated from parsing the title as plain text
*/
protected XDOM parseTitle(String title)
{
try {
XDOM xdom = plainTextParser.parse(new StringReader(title));
parserUtils.removeTopLevelParagraph(xdom.getChildren());
return xdom;
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: org.xwiki.platform/xwiki-core-rendering-parser-wikimodel
result = parser.parse(new StringReader("xwikimarker " + content)).getChildren();
} else if (WikiModelXHTMLParser.class.isAssignableFrom(parser.getClass())) {
contentToParse = contentToParse + content + "</p>";
result = parser.parse(new StringReader(contentToParse)).getChildren();
} else {
result = parser.parse(new StringReader(content)).getChildren();
代码示例来源:origin: org.xwiki.platform/xwiki-core-officeimporter
xdom = this.xwikiParser.parse(new StringReader(buffer.toString()));
代码示例来源:origin: org.xwiki.platform/xwiki-platform-localization-api
} else if (parameter != null) {
try {
XDOM xdom = this.plainParser.parse(new StringReader(parameter.toString()));
代码示例来源:origin: org.xwiki.platform/xwiki-platform-rendering-macro-code
@Override
public void format(String tokenType, String value, Map<String, Object> style)
{
List<Block> blockList;
if (StringUtils.isNotEmpty(value)) {
try {
blockList = this.plainTextParser.parse(new StringReader(value)).getChildren().get(0).getChildren();
} catch (ParseException e) {
// This shouldn't happen since the parser cannot throw an exception since the source is a memory
// String.
throw new RuntimeException("Failed to parse [" + value + "] as plain text.", e);
}
String styleParameter = formatStyle(style);
FormatBlock formatBlock = null;
if (styleParameter.length() > 0) {
formatBlock = new FormatBlock(blockList, Format.NONE);
formatBlock.setParameter("style", styleParameter);
this.blocks.add(formatBlock);
} else {
this.blocks.addAll(blockList);
}
}
}
代码示例来源:origin: org.xwiki.platform/xwiki-platform-rendering-macro-code
@Override
protected List<Block> parseContent(CodeMacroParameters parameters, String content,
MacroTransformationContext context) throws MacroExecutionException
{
List<Block> result;
try {
if (LANGUAGE_NONE.equalsIgnoreCase(parameters.getLanguage())) {
if (StringUtils.isEmpty(content)) {
result = Collections.emptyList();
} else {
result = this.plainTextParser.parse(new StringReader(content)).getChildren().get(0).getChildren();
}
} else {
result = highlight(parameters, content);
}
} catch (Exception e) {
throw new MacroExecutionException("Failed to highlight content", e);
}
Map<String, String> formatParameters = new LinkedHashMap<String, String>();
formatParameters.put("class", "code");
if (context.isInline()) {
result = Arrays.<Block> asList(new FormatBlock(result, Format.NONE, formatParameters));
} else {
result = Arrays.<Block> asList(new GroupBlock(result, formatParameters));
}
return result;
}
代码示例来源:origin: org.xwiki.platform/xwiki-platform-annotation-io
private XDOM getTransformedXDOM(String content, String sourceSyntaxId)
throws ParseException, org.xwiki.component.manager.ComponentLookupException, TransformationException
{
Parser parser = componentManager.getInstance(Parser.class, sourceSyntaxId);
XDOM xdom = parser.parse(new StringReader(content));
// run transformations
TransformationContext txContext =
new TransformationContext(xdom, Syntax.valueOf(sourceSyntaxId));
TransformationManager transformationManager = componentManager.getInstance(TransformationManager.class);
transformationManager.performTransformations(xdom, txContext);
return xdom;
}
代码示例来源:origin: org.xwiki.platform/xwiki-core-rendering-api
return this.plainTextParser.parse(new StringReader(label)).getChildren().get(0).getChildren();
} catch (ParseException e) {
代码示例来源:origin: org.xwiki.platform/xwiki-core-rendering-macro-box
/**
* {@inheritDoc}
* @see MacroContentParser#parse(String, org.xwiki.rendering.syntax.Syntax, boolean)
*/
public List<Block> parse(String content, Syntax syntax, boolean removeTopLevelParagraph)
throws MacroExecutionException
{
try {
List<Block> blocks = getSyntaxParser(syntax).parse(new StringReader(content)).getChildren();
if (removeTopLevelParagraph) {
this.parserUtils.removeTopLevelParagraph(blocks);
}
return blocks;
} catch (Exception e) {
throw new MacroExecutionException("Failed to parse content [" + content + "]", e);
}
}
代码示例来源:origin: org.xwiki.platform/xwiki-core-officeimporter
/**
* {@inheritDoc}
*/
public XDOMOfficeDocument build(XHTMLOfficeDocument xhtmlOfficeDocument) throws OfficeImporterException
{
Document xhtmlDoc = xhtmlOfficeDocument.getContentDocument();
HTMLUtils.stripHTMLEnvelope(xhtmlDoc);
XDOM xdom = null;
try {
xdom = xHtmlParser.parse(new StringReader(HTMLUtils.toString(xhtmlDoc)));
} catch (ParseException ex) {
throw new OfficeImporterException("Error: Could not parse xhtml office content.", ex);
}
return new XDOMOfficeDocument(xdom, xhtmlOfficeDocument.getArtifacts(), componentManager);
}
代码示例来源:origin: org.xwiki.rendering/xwiki-rendering-macro-content
@Override
public List<Block> execute(ContentMacroParameters parameters, String content, MacroTransformationContext context)
throws MacroExecutionException
{
try {
List<Block> blocks = getSyntaxParser(parameters.getSyntax()).parse(new StringReader(content)).getChildren();
MetaDataBlock metaDataBlock = new MetaDataBlock(blocks, MetaData.SYNTAX,
parameters.getSyntax().toIdString());
metaDataBlock.getMetaData().addMetaData(this.getNonGeneratedContentMetaData());
return Collections.singletonList(metaDataBlock);
} catch (ParseException e) {
throw new MacroExecutionException(
String.format("Failed to parse macro content in syntax [%s]", parameters.getSyntax()), e);
}
}
代码示例来源:origin: org.xwiki.platform/xwiki-platform-annotation-maintainer
/**
* Helper method to render the plain text version of the passed content.
*
* @param content the content to render in plain text
* @param syntaxId the source syntax of the content to render
* @throws Exception if anything goes wrong while rendering the content
* @return the normalized plain text rendered content
*/
private String renderPlainText(String content, String syntaxId) throws Exception
{
PrintRenderer renderer = componentManager.getInstance(PrintRenderer.class, "normalizer-plain/1.0");
// parse
Parser parser = componentManager.getInstance(Parser.class, syntaxId);
XDOM xdom = parser.parse(new StringReader(content));
// run transformations -> although it's going to be at least strange to handle rendered content since there
// is no context
Syntax sourceSyntax = Syntax.valueOf(syntaxId);
TransformationManager transformationManager = componentManager.getInstance(TransformationManager.class);
transformationManager.performTransformations(xdom, sourceSyntax);
// render
WikiPrinter printer = new DefaultWikiPrinter();
renderer.setPrinter(printer);
xdom.traverse(renderer);
return printer.toString();
}
代码示例来源:origin: org.xwiki.platform/xwiki-platform-rendering-macro-code
blocks = listener.getBlocks();
} else {
blocks = this.plainTextParser.parse(new StringReader(code)).getChildren().get(0).getChildren();
代码示例来源:origin: org.onebusaway/onebusaway-wiki-integration-xwiki-struts-macros
XDOM xdom = parser.parse(new StringReader(content));
代码示例来源:origin: org.xwiki.rendering/xwiki-rendering-transformation-macro
/**
* creates XDOM.
*/
private XDOM createXDOM(String content, MacroTransformationContext macroContext, boolean transform,
MetaData metadata, boolean inline, Syntax syntax) throws MacroExecutionException
{
try {
XDOM result = getSyntaxParser(syntax).parse(new StringReader(content));
if (metadata != null) {
result.getMetaData().addMetaData(metadata);
}
if (transform && macroContext.getTransformation() != null) {
TransformationContext txContext = new TransformationContext(result, syntax);
txContext.setId(macroContext.getId());
performTransformation((MutableRenderingContext) this.renderingContext,
macroContext.getTransformation(), txContext, result);
}
if (inline) {
result = convertToInline(result);
}
return result;
} catch (Exception e) {
throw new MacroExecutionException("Failed to parse content [" + content + "]", e);
}
}
代码示例来源:origin: org.xwiki.platform/xwiki-core-rendering-tests
private void runTestInternal() throws Throwable
{
WikiPrinter printer = new DefaultWikiPrinter();
if (!this.streaming) {
Parser parser = getComponentManager().lookup(Parser.class, this.parserId);
XDOM xdom = parser.parse(new StringReader(this.input));
if (this.runTransformations) {
SyntaxFactory syntaxFactory = getComponentManager().lookup(SyntaxFactory.class);
TransformationManager transformationManager = getComponentManager().lookup(TransformationManager.class);
TransformationContext txContext =
new TransformationContext(xdom, syntaxFactory.createSyntaxFromIdString(this.parserId));
transformationManager.performTransformations(xdom, txContext);
}
BlockRenderer renderer = getComponentManager().lookup(BlockRenderer.class, this.targetSyntaxId);
renderer.render(xdom, printer);
} else {
StreamParser parser = getComponentManager().lookup(StreamParser.class, this.parserId);
PrintRendererFactory printRendererFactory =
getComponentManager().lookup(PrintRendererFactory.class, this.targetSyntaxId);
parser.parse(new StringReader(this.input), printRendererFactory.createRenderer(printer));
}
assertEquals(this.expected, printer.toString());
}
代码示例来源:origin: org.xwiki.rendering/xwiki-rendering-tests
private void runTestInternal() throws Throwable
{
WikiPrinter printer = new DefaultWikiPrinter();
if (!this.streaming) {
Parser parser = getComponentManager().lookup(Parser.class, this.parserId);
XDOM xdom = parser.parse(new StringReader(this.input));
if (this.runTransformations) {
SyntaxFactory syntaxFactory = getComponentManager().lookup(SyntaxFactory.class);
TransformationManager transformationManager = getComponentManager().lookup(TransformationManager.class);
TransformationContext txContext =
new TransformationContext(xdom, syntaxFactory.createSyntaxFromIdString(this.parserId));
transformationManager.performTransformations(xdom, txContext);
}
BlockRenderer renderer = getComponentManager().lookup(BlockRenderer.class, this.targetSyntaxId);
// remove source syntax from XDOM metadata
Map<String, Object> metadataMap = new HashMap<String, Object>(xdom.getMetaData().getMetaData());
metadataMap.remove(MetaData.SYNTAX);
xdom = new XDOM(xdom.getChildren(), new MetaData(metadataMap));
renderer.render(xdom, printer);
} else {
StreamParser parser = getComponentManager().lookup(StreamParser.class, this.parserId);
PrintRendererFactory printRendererFactory =
getComponentManager().lookup(PrintRendererFactory.class, this.targetSyntaxId);
// remove source syntax from begin/endDocument metadata
WrappingListener listener = new SyntaxWrappingListener();
listener.setWrappedListener(printRendererFactory.createRenderer(printer));
parser.parse(new StringReader(this.input), listener);
}
assertEquals(this.expected, printer.toString());
}
代码示例来源:origin: org.xwiki.platform/xwiki-core-rendering-api
try {
Parser parser = this.componentManager.lookup(Parser.class, sourceSyntax.toIdString());
xdom = parser.parse(source);
} catch (ComponentLookupException e) {
throw new ConversionException("Failed to locate Parser for syntax [" + sourceSyntax + "]", e);
内容来源于网络,如有侵权,请联系作者删除!