org.xwiki.rendering.parser.Parser类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(126)

本文整理了Java中org.xwiki.rendering.parser.Parser类的一些代码示例,展示了Parser类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Parser类的具体详情如下:
包路径:org.xwiki.rendering.parser.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

  1. private String convert(String source, Parser parser, BlockRenderer blockRenderer) throws Exception
  2. {
  3. XDOM xdom = parser.parse(new StringReader(source));
  4. WikiPrinter printer = new DefaultWikiPrinter();
  5. blockRenderer.render(xdom, printer);
  6. return printer.toString();
  7. }

代码示例来源:origin: org.xwiki.platform/xwiki-platform-rendering-configuration-default

  1. /**
  2. * @return the list of syntaxes for which a Parser is available
  3. */
  4. public List<Syntax> getAvailableParserSyntaxes()
  5. {
  6. List<Syntax> syntaxes = new ArrayList<>();
  7. try {
  8. for (Parser parser : this.componentManagerProvider.get().<Parser>getInstanceList(Parser.class)) {
  9. syntaxes.add(parser.getSyntax());
  10. }
  11. } catch (ComponentLookupException e) {
  12. // This shouldn't happen; if it does then it's critical
  13. throw new RuntimeException("Failed to lookup parsers", e);
  14. }
  15. return syntaxes;
  16. }
  17. }

代码示例来源:origin: com.xpn.xwiki.platform/xwiki-core

  1. private static XDOM parseContent(String syntaxId, String content) throws XWikiException
  2. {
  3. try {
  4. Parser parser = Utils.getComponent(Parser.class, syntaxId);
  5. return parser.parse(new StringReader(content));
  6. } catch (ParseException e) {
  7. throw new XWikiException(XWikiException.MODULE_XWIKI_RENDERING, XWikiException.ERROR_XWIKI_UNKNOWN,
  8. "Failed to parse content of syntax [" + syntaxId + "]", e);
  9. }
  10. }

代码示例来源:origin: com.xpn.xwiki.platform/xwiki-core

  1. /**
  2. * Gets all syntaxes supported by the rendering parsers as an input for a syntax conversion.
  3. *
  4. * @param token The authentication token.
  5. * @return A list containing all syntaxes supported by rendering parsers.
  6. * @throws Exception An invalid token is provided or the syntax lookup fails.
  7. */
  8. public List<String> getInputSyntaxes(String token) throws Exception
  9. {
  10. XWikiXmlRpcUser user = XWikiUtils.checkToken(token, this.xwikiContext);
  11. List<String> syntaxes = new ArrayList<String>();
  12. List<Parser> parsers;
  13. ComponentManager componentManager = Utils.getComponentManager();
  14. try {
  15. parsers = componentManager.lookupList(Parser.class);
  16. for (Parser parser : parsers) {
  17. syntaxes.add(parser.getSyntax().toIdString());
  18. }
  19. } catch (ComponentLookupException e) {
  20. throw new RuntimeException("Failed to lookup the list of available parser syntaxes", e);
  21. }
  22. return syntaxes;
  23. }

代码示例来源:origin: org.xwiki.platform/xwiki-platform-display-api

  1. /**
  2. * Parses the given title as plain text and returns the generated XDOM.
  3. *
  4. * @param title the title to be parsed
  5. * @return the XDOM generated from parsing the title as plain text
  6. */
  7. protected XDOM parseTitle(String title)
  8. {
  9. try {
  10. XDOM xdom = plainTextParser.parse(new StringReader(title));
  11. parserUtils.removeTopLevelParagraph(xdom.getChildren());
  12. return xdom;
  13. } catch (ParseException e) {
  14. throw new RuntimeException(e);
  15. }
  16. }

代码示例来源:origin: org.xwiki.rendering/xwiki-rendering-test

  1. private org.xwiki.rendering.syntax.Syntax getInputSyntax(String inputSyntaxId, String outputSyntaxId)
  2. throws Exception
  3. {
  4. org.xwiki.rendering.syntax.Syntax syntax;
  5. if (isStreamingTest(inputSyntaxId, outputSyntaxId)) {
  6. StreamParser parser = getComponentManager().getInstance(StreamParser.class, inputSyntaxId);
  7. syntax = parser.getSyntax();
  8. } else {
  9. Parser parser = getComponentManager().getInstance(Parser.class, inputSyntaxId);
  10. syntax = parser.getSyntax();
  11. }
  12. return syntax;
  13. }

代码示例来源:origin: org.xwiki.platform/xwiki-core-rendering-parser-wikimodel

  1. result = parser.parse(new StringReader("xwikimarker " + content)).getChildren();
  2. } else if (WikiModelXHTMLParser.class.isAssignableFrom(parser.getClass())) {
  3. contentToParse = contentToParse + content + "</p>";
  4. result = parser.parse(new StringReader(contentToParse)).getChildren();
  5. } else {
  6. result = parser.parse(new StringReader(content)).getChildren();

代码示例来源:origin: org.xwiki.platform/xwiki-core-officeimporter

  1. xdom = this.xwikiParser.parse(new StringReader(buffer.toString()));

代码示例来源:origin: org.xwiki.platform/xwiki-platform-localization-api

  1. } else if (parameter != null) {
  2. try {
  3. XDOM xdom = this.plainParser.parse(new StringReader(parameter.toString()));

代码示例来源:origin: org.xwiki.platform/xwiki-platform-rendering-macro-code

  1. @Override
  2. public void format(String tokenType, String value, Map<String, Object> style)
  3. {
  4. List<Block> blockList;
  5. if (StringUtils.isNotEmpty(value)) {
  6. try {
  7. blockList = this.plainTextParser.parse(new StringReader(value)).getChildren().get(0).getChildren();
  8. } catch (ParseException e) {
  9. // This shouldn't happen since the parser cannot throw an exception since the source is a memory
  10. // String.
  11. throw new RuntimeException("Failed to parse [" + value + "] as plain text.", e);
  12. }
  13. String styleParameter = formatStyle(style);
  14. FormatBlock formatBlock = null;
  15. if (styleParameter.length() > 0) {
  16. formatBlock = new FormatBlock(blockList, Format.NONE);
  17. formatBlock.setParameter("style", styleParameter);
  18. this.blocks.add(formatBlock);
  19. } else {
  20. this.blocks.addAll(blockList);
  21. }
  22. }
  23. }

代码示例来源:origin: org.xwiki.platform/xwiki-core-rendering-syntax-wikimodel

  1. result = parser.parse(new StringReader("xwikimarker " + content)).getChildren();
  2. } else if (WikiModelXHTMLParser.class.isAssignableFrom(parser.getClass())) {
  3. contentToParse = contentToParse + content + "</p>";
  4. result = parser.parse(new StringReader(contentToParse)).getChildren();
  5. } else {
  6. result = parser.parse(new StringReader(content)).getChildren();

代码示例来源:origin: org.xwiki.platform/xwiki-platform-rendering-macro-code

  1. @Override
  2. protected List<Block> parseContent(CodeMacroParameters parameters, String content,
  3. MacroTransformationContext context) throws MacroExecutionException
  4. {
  5. List<Block> result;
  6. try {
  7. if (LANGUAGE_NONE.equalsIgnoreCase(parameters.getLanguage())) {
  8. if (StringUtils.isEmpty(content)) {
  9. result = Collections.emptyList();
  10. } else {
  11. result = this.plainTextParser.parse(new StringReader(content)).getChildren().get(0).getChildren();
  12. }
  13. } else {
  14. result = highlight(parameters, content);
  15. }
  16. } catch (Exception e) {
  17. throw new MacroExecutionException("Failed to highlight content", e);
  18. }
  19. Map<String, String> formatParameters = new LinkedHashMap<String, String>();
  20. formatParameters.put("class", "code");
  21. if (context.isInline()) {
  22. result = Arrays.<Block> asList(new FormatBlock(result, Format.NONE, formatParameters));
  23. } else {
  24. result = Arrays.<Block> asList(new GroupBlock(result, formatParameters));
  25. }
  26. return result;
  27. }

代码示例来源:origin: org.xwiki.platform/xwiki-platform-annotation-io

  1. private XDOM getTransformedXDOM(String content, String sourceSyntaxId)
  2. throws ParseException, org.xwiki.component.manager.ComponentLookupException, TransformationException
  3. {
  4. Parser parser = componentManager.getInstance(Parser.class, sourceSyntaxId);
  5. XDOM xdom = parser.parse(new StringReader(content));
  6. // run transformations
  7. TransformationContext txContext =
  8. new TransformationContext(xdom, Syntax.valueOf(sourceSyntaxId));
  9. TransformationManager transformationManager = componentManager.getInstance(TransformationManager.class);
  10. transformationManager.performTransformations(xdom, txContext);
  11. return xdom;
  12. }

代码示例来源:origin: org.xwiki.platform/xwiki-core-rendering-macro-box

  1. /**
  2. * {@inheritDoc}
  3. * @see MacroContentParser#parse(String, org.xwiki.rendering.syntax.Syntax, boolean)
  4. */
  5. public List<Block> parse(String content, Syntax syntax, boolean removeTopLevelParagraph)
  6. throws MacroExecutionException
  7. {
  8. try {
  9. List<Block> blocks = getSyntaxParser(syntax).parse(new StringReader(content)).getChildren();
  10. if (removeTopLevelParagraph) {
  11. this.parserUtils.removeTopLevelParagraph(blocks);
  12. }
  13. return blocks;
  14. } catch (Exception e) {
  15. throw new MacroExecutionException("Failed to parse content [" + content + "]", e);
  16. }
  17. }

代码示例来源:origin: org.xwiki.platform/xwiki-core-rendering-api

  1. return this.plainTextParser.parse(new StringReader(label)).getChildren().get(0).getChildren();
  2. } catch (ParseException e) {

代码示例来源:origin: org.xwiki.platform/xwiki-core-officeimporter

  1. /**
  2. * {@inheritDoc}
  3. */
  4. public XDOMOfficeDocument build(XHTMLOfficeDocument xhtmlOfficeDocument) throws OfficeImporterException
  5. {
  6. Document xhtmlDoc = xhtmlOfficeDocument.getContentDocument();
  7. HTMLUtils.stripHTMLEnvelope(xhtmlDoc);
  8. XDOM xdom = null;
  9. try {
  10. xdom = xHtmlParser.parse(new StringReader(HTMLUtils.toString(xhtmlDoc)));
  11. } catch (ParseException ex) {
  12. throw new OfficeImporterException("Error: Could not parse xhtml office content.", ex);
  13. }
  14. return new XDOMOfficeDocument(xdom, xhtmlOfficeDocument.getArtifacts(), componentManager);
  15. }

代码示例来源:origin: org.xwiki.rendering/xwiki-rendering-macro-content

  1. @Override
  2. public List<Block> execute(ContentMacroParameters parameters, String content, MacroTransformationContext context)
  3. throws MacroExecutionException
  4. {
  5. try {
  6. List<Block> blocks = getSyntaxParser(parameters.getSyntax()).parse(new StringReader(content)).getChildren();
  7. MetaDataBlock metaDataBlock = new MetaDataBlock(blocks, MetaData.SYNTAX,
  8. parameters.getSyntax().toIdString());
  9. metaDataBlock.getMetaData().addMetaData(this.getNonGeneratedContentMetaData());
  10. return Collections.singletonList(metaDataBlock);
  11. } catch (ParseException e) {
  12. throw new MacroExecutionException(
  13. String.format("Failed to parse macro content in syntax [%s]", parameters.getSyntax()), e);
  14. }
  15. }

代码示例来源:origin: org.xwiki.platform/xwiki-platform-rendering-macro-script

  1. } else {
  2. try {
  3. result = this.plainTextParser.parse(new StringReader(content)).getChildren();
  4. } catch (ParseException e) {

代码示例来源:origin: org.xwiki.platform/xwiki-core-rendering-macro-script

  1. } else {
  2. try {
  3. result = this.plainTextParser.parse(new StringReader(content)).getChildren();
  4. } catch (ParseException e) {

代码示例来源:origin: org.xwiki.platform/xwiki-platform-annotation-maintainer

  1. /**
  2. * Helper method to render the plain text version of the passed content.
  3. *
  4. * @param content the content to render in plain text
  5. * @param syntaxId the source syntax of the content to render
  6. * @throws Exception if anything goes wrong while rendering the content
  7. * @return the normalized plain text rendered content
  8. */
  9. private String renderPlainText(String content, String syntaxId) throws Exception
  10. {
  11. PrintRenderer renderer = componentManager.getInstance(PrintRenderer.class, "normalizer-plain/1.0");
  12. // parse
  13. Parser parser = componentManager.getInstance(Parser.class, syntaxId);
  14. XDOM xdom = parser.parse(new StringReader(content));
  15. // run transformations -> although it's going to be at least strange to handle rendered content since there
  16. // is no context
  17. Syntax sourceSyntax = Syntax.valueOf(syntaxId);
  18. TransformationManager transformationManager = componentManager.getInstance(TransformationManager.class);
  19. transformationManager.performTransformations(xdom, sourceSyntax);
  20. // render
  21. WikiPrinter printer = new DefaultWikiPrinter();
  22. renderer.setPrinter(printer);
  23. xdom.traverse(renderer);
  24. return printer.toString();
  25. }

相关文章