org.xwiki.rendering.syntax.Syntax.valueOf()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(138)

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

Syntax.valueOf介绍

暂无

代码示例

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

private List<Syntax> convertList(List<String> syntaxesAsStrings)
{
  if (syntaxesAsStrings == null) {
    return null;
  }
  List<Syntax> syntaxes = new ArrayList<>();
  for (String syntaxAsString : syntaxesAsStrings) {
    try {
      syntaxes.add(Syntax.valueOf(syntaxAsString));
    } catch (ParseException e) {
      throw new RuntimeException(String.format("Failed to convert [%s] into Syntax object", syntaxAsString),
        e);
    }
  }
  return syntaxes;
}

代码示例来源:origin: org.xwiki.platform/xwiki-platform-filter-stream-xar

protected <T> T convert(Class<?> type, String source) throws FilterException
{
  Object value = source;
  if (type == Locale.class) {
    value = toLocale(source);
  } else if (type == Date.class) {
    value = StringUtils.isNotEmpty(source) ? new Date(Long.parseLong(source)) : null;
  } else if (type == Boolean.class) {
    value = StringUtils.isNotEmpty(source) ? Boolean.parseBoolean(source) : null;
  } else if (type == Syntax.class) {
    if (StringUtils.isNotEmpty(source)) {
      try {
        value = Syntax.valueOf(source);
      } catch (ParseException e) {
        throw new FilterException(String.format("Failed to create Syntax istance for [%s]", source), e);
      }
    } else {
      value = null;
    }
  } else if (type == Integer.class) {
    value = StringUtils.isNotEmpty(source) ? Integer.parseInt(source) : null;
  }
  return (T) value;
}

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

@Override
  public MacroId createMacroId(String macroIdAsString) throws ParseException
  {
    MacroId macroId;

    // Verify if we have a syntax specified.
    String[] hintParts = macroIdAsString.split("/");
    if (hintParts.length == 3) {
      // We've found a macro id for a macro that should be available only for a given syntax
      Syntax syntax;
      try {
        syntax = Syntax.valueOf(String.format("%s/%s", hintParts[1], hintParts[2]));
      } catch (ParseException e) {
        throw new ParseException(String.format(INVALID_MACRO_ID_FORMAT, macroIdAsString), e);
      }
      macroId = new MacroId(hintParts[0], syntax);
    } else if (hintParts.length == 1) {
      // We've found a macro registered for all syntaxes
      macroId = new MacroId(macroIdAsString);
    } else {
      // Invalid format
      throw new ParseException(String.format(INVALID_MACRO_ID_FORMAT, macroIdAsString));
    }

    return macroId;
  }
}

代码示例来源: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.rendering/xwiki-rendering-test

private org.xwiki.rendering.syntax.Syntax getOutputSyntax(String inputSyntaxId, String outputSyntaxId)
  throws Exception
{
  org.xwiki.rendering.syntax.Syntax syntax;
  if (isStreamingTest(inputSyntaxId, outputSyntaxId)) {
    PrintRendererFactory rendererFactory =
      getComponentManager().getInstance(PrintRendererFactory.class, outputSyntaxId);
    syntax = rendererFactory.getSyntax();
  } else {
    syntax = org.xwiki.rendering.syntax.Syntax.valueOf(outputSyntaxId);
  }
  return syntax;
}

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

private Syntax getRendererSyntax() throws Exception
{
  Syntax syntax;
  if (getComponentManager().hasComponent(PrintRendererFactory.class, this.targetSyntaxId)) {
    PrintRendererFactory streamRendererFactory =
      getComponentManager().getInstance(PrintRendererFactory.class, this.targetSyntaxId);
    syntax = streamRendererFactory.getSyntax();
  } else {
    syntax = Syntax.valueOf(this.targetSyntaxId);
  }
  return syntax;
}

代码示例来源: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.rendering/xwiki-rendering-test

private String convert(String source, String sourceSyntaxId, String targetSyntaxId) throws Exception
{
  String result;
  ExecutionContext executionContext = new ExecutionContext();
  ExecutionContextManager executionContextManager = componentManager.getInstance(ExecutionContextManager.class);
  executionContextManager.initialize(executionContext);
  // Set TargetSyntax for Macro tests
  RenderingContext renderingContext = componentManager.getInstance(RenderingContext.class);
  ((MutableRenderingContext) renderingContext).push(renderingContext.getTransformation(),
    renderingContext.getXDOM(), renderingContext.getDefaultSyntax(), renderingContext.getTransformationId(),
    renderingContext.isRestricted(), Syntax.valueOf(targetSyntaxId));
  try {
    if (isStreamingTest(sourceSyntaxId, targetSyntaxId)) {
      StreamParser parser = getComponentManager().getInstance(StreamParser.class, sourceSyntaxId);
      PrintRendererFactory rendererFactory =
        getComponentManager().getInstance(PrintRendererFactory.class, targetSyntaxId);
      result = convert(source, parser, rendererFactory);
    } else {
      Parser parser = getComponentManager().getInstance(Parser.class, sourceSyntaxId);
      BlockRenderer blockRenderer = getComponentManager().getInstance(BlockRenderer.class, targetSyntaxId);
      result = convert(source, parser, blockRenderer);
    }
  } finally {
    ((MutableRenderingContext) renderingContext).pop();
    Execution execution = componentManager.getInstance(Execution.class);
    execution.removeContext();
  }
  return result;
}

相关文章