本文整理了Java中org.xwiki.rendering.parser.Parser
类的一些代码示例,展示了Parser
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Parser
类的具体详情如下:
包路径:org.xwiki.rendering.parser.Parser
类名称:Parser
[英]Parse content into a XDOM (a tree of org.xwiki.rendering.block.Blocks).
[中]将内容解析为XDOM(org.xwiki.rendering.block.Blocks的树)。
代码示例来源: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: org.xwiki.platform/xwiki-platform-rendering-configuration-default
/**
* @return the list of syntaxes for which a Parser is available
*/
public List<Syntax> getAvailableParserSyntaxes()
{
List<Syntax> syntaxes = new ArrayList<>();
try {
for (Parser parser : this.componentManagerProvider.get().<Parser>getInstanceList(Parser.class)) {
syntaxes.add(parser.getSyntax());
}
} catch (ComponentLookupException e) {
// This shouldn't happen; if it does then it's critical
throw new RuntimeException("Failed to lookup parsers", e);
}
return syntaxes;
}
}
代码示例来源: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: com.xpn.xwiki.platform/xwiki-core
/**
* Gets all syntaxes supported by the rendering parsers as an input for a syntax conversion.
*
* @param token The authentication token.
* @return A list containing all syntaxes supported by rendering parsers.
* @throws Exception An invalid token is provided or the syntax lookup fails.
*/
public List<String> getInputSyntaxes(String token) throws Exception
{
XWikiXmlRpcUser user = XWikiUtils.checkToken(token, this.xwikiContext);
List<String> syntaxes = new ArrayList<String>();
List<Parser> parsers;
ComponentManager componentManager = Utils.getComponentManager();
try {
parsers = componentManager.lookupList(Parser.class);
for (Parser parser : parsers) {
syntaxes.add(parser.getSyntax().toIdString());
}
} catch (ComponentLookupException e) {
throw new RuntimeException("Failed to lookup the list of available parser syntaxes", e);
}
return syntaxes;
}
代码示例来源: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.rendering/xwiki-rendering-test
private org.xwiki.rendering.syntax.Syntax getInputSyntax(String inputSyntaxId, String outputSyntaxId)
throws Exception
{
org.xwiki.rendering.syntax.Syntax syntax;
if (isStreamingTest(inputSyntaxId, outputSyntaxId)) {
StreamParser parser = getComponentManager().getInstance(StreamParser.class, inputSyntaxId);
syntax = parser.getSyntax();
} else {
Parser parser = getComponentManager().getInstance(Parser.class, inputSyntaxId);
syntax = parser.getSyntax();
}
return syntax;
}
代码示例来源: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-core-rendering-syntax-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-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-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-rendering-api
return this.plainTextParser.parse(new StringReader(label)).getChildren().get(0).getChildren();
} catch (ParseException 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-rendering-macro-script
} else {
try {
result = this.plainTextParser.parse(new StringReader(content)).getChildren();
} catch (ParseException e) {
代码示例来源:origin: org.xwiki.platform/xwiki-core-rendering-macro-script
} else {
try {
result = this.plainTextParser.parse(new StringReader(content)).getChildren();
} catch (ParseException 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();
}
内容来源于网络,如有侵权,请联系作者删除!