com.thoughtworks.xstream.XStream.allowTypesByRegExp()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(3.4k)|赞(0)|评价(0)|浏览(193)

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

XStream.allowTypesByRegExp介绍

[英]Add security permission for types matching one of the specified regular expressions.
[中]为与指定正则表达式之一匹配的类型添加安全权限。

代码示例

代码示例来源:origin: kiegroup/optaplanner

public BenchmarkResultIO() {
  xStream = XStreamXmlSolverFactory.buildXStream();
  xStream.processAnnotations(PlannerBenchmarkResult.class);
  xStream.allowTypesByRegExp(new String[]{"org\\.optaplanner\\.\\w+\\.api\\..*"});
  xStream.allowTypesByRegExp(new String[]{"org\\.optaplanner\\.\\w+\\.impl\\..*"});
  AbstractScoreXStreamConverter.registerScoreConverters(xStream);
}

代码示例来源:origin: kiegroup/optaplanner

/**
 * Builds the {@link XStream} setup which is used to read/write {@link SolverConfig solver configs} and benchmark configs.
 * It should never be used to read/write {@link PlanningSolution solutions}.
 * Use XStreamSolutionFileIO for that instead.
 * @return never null.
 */
public static XStream buildXStream() {
  XStream xStream = new XStream();
  xStream.setMode(XStream.ID_REFERENCES);
  xStream.aliasSystemAttribute("xStreamId", "id");
  xStream.aliasSystemAttribute("xStreamRef", "reference");
  xStream.processAnnotations(SolverConfig.class);
  XStream.setupDefaultSecurity(xStream);
  xStream.allowTypesByRegExp(new String[]{"org\\.optaplanner\\.\\w+\\.config\\..*"});
  return xStream;
}

代码示例来源:origin: kiegroup/optaplanner

protected <S extends Score, W extends TestScoreWrapper<S>> void assertSerializeAndDeserialize(S expectedScore, W input) {
  XStream xStream = new XStream();
  xStream.setMode(XStream.ID_REFERENCES);
  xStream.processAnnotations(input.getClass());
  XStream.setupDefaultSecurity(xStream);
  xStream.allowTypesByRegExp(new String[]{"org\\.optaplanner\\.\\w+\\.config\\..*",
      "org\\.optaplanner\\.persistence\\.xstream\\..*\\$Test\\w+ScoreWrapper"});
  String xmlString = xStream.toXML(input);
  W output = (W) xStream.fromXML(xmlString);
  assertEquals(expectedScore, output.getScore());
  String regex;
  if (expectedScore != null) {
    regex = "<([\\w\\-\\.]+)( id=\"\\d+\")?>" // Start of element
        + "\\s*<score( id=\"\\d+\")?>"
        + expectedScore.toString().replaceAll("\\[", "\\\\[").replaceAll("\\]", "\\\\]") // Score
        + "</score>"
        + "\\s*</\\1>"; // End of element
  } else {
    regex = "<([\\w\\-\\.]+)( id=\"\\d+\")?/>"; // Start and end of element
  }
  if (!xmlString.matches(regex)) {
    fail("Regular expression match failed.\nExpected regular expression: " + regex + "\nActual string: " + xmlString);
  }
}

代码示例来源:origin: pippo-java/pippo

private XStream xstream() {
  XStream xstream = new XStream();
  // allow annotations on models for maximum flexibility
  xstream.autodetectAnnotations(true);
  // prevent xstream from creating complex XML graphs
  xstream.setMode(XStream.NO_REFERENCES);
  // setup security (see http://x-stream.github.io/security.html)
  xstream.allowTypes(WhitelistObjectInputStream.getWhiteClassNames());
  xstream.allowTypesByRegExp(WhitelistObjectInputStream.getWhiteRegEx());
  return xstream;
}

代码示例来源:origin: org.powermock/powermock-classloading-xstream

private void disableSecurity() {
  XStream.setupDefaultSecurity(xStream);
  xStream.allowTypesByRegExp(new String[]{".*"});
}

相关文章