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

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

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

XStream.setMode介绍

[英]Change mode for dealing with duplicate references. Valid values are XPATH_ABSOLUTE_REFERENCES, XPATH_RELATIVE_REFERENCES, XStream.ID_REFERENCES and XStream.NO_REFERENCES.
[中]更改处理重复引用的模式。有效值为XPATH_ABSOLUTE_REFERENCESXPATH_RELATIVE_REFERENCESXStream.ID_REFERENCESXStream.NO_REFERENCES

代码示例

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

public String getSolverConfigAsHtmlEscapedXml() {
  // TODO reuse a single XStream instance for the entire report
  XStream xStream = XStreamXmlSolverFactory.buildXStream();
  xStream.setMode(XStream.NO_REFERENCES);
  String xml = xStream.toXML(solverConfig);
  return StringEscapeUtils.escapeHtml4(xml);
}

代码示例来源:origin: spring-projects/spring-framework

xstream.setMode(this.mode);

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

public XStreamSolutionFileIO(Class... xStreamAnnotatedClasses) {
  xStream = new XStream();
  xStream.setMode(XStream.ID_REFERENCES);
  xStream.processAnnotations(xStreamAnnotatedClasses);
  XStream.setupDefaultSecurity(xStream);
  // Presume the XML file comes from a trusted source so it works out of the box. See class javadoc.
  xStream.addPermission(new AnyTypePermission());
}

代码示例来源:origin: chanjarster/weixin-java-tools

public static XStream getInstance() {
 XStream xstream = new XStream(new XppDriver() {
  @Override
  public HierarchicalStreamWriter createWriter(Writer out) {
   return new PrettyPrintWriter(out, getNameCoder()) {
    protected String PREFIX_CDATA = "<![CDATA[";
    protected String SUFFIX_CDATA = "]]>";
    protected String PREFIX_MEDIA_ID = "<MediaId>";
    protected String SUFFIX_MEDIA_ID = "</MediaId>";
    @Override
    protected void writeText(QuickWriter writer, String text) {
     if (text.startsWith(PREFIX_CDATA) && text.endsWith(SUFFIX_CDATA)) {
      writer.write(text);
     } else if (text.startsWith(PREFIX_MEDIA_ID) && text.endsWith(SUFFIX_MEDIA_ID)) {
      writer.write(text);
     } else {
      super.writeText(writer, text);
     }
    }
   };
  }
 });
 xstream.ignoreUnknownElements();
 xstream.setMode(XStream.NO_REFERENCES);
 xstream.addPermission(NullPermission.NULL);
 xstream.addPermission(PrimitiveTypePermission.PRIMITIVES);
 return xstream;
}

代码示例来源:origin: javamelody/javamelody

private static XStream createXStream(boolean json) {
    final XStream xstream;
    if (json) {
      // format json
      xstream = new XStream(new JsonHierarchicalStreamDriver());
      xstream.setMode(XStream.NO_REFERENCES);
    } else {
      // sinon format xml, utilise la dépendance XPP3 par défaut
      xstream = new XStream();
    }
    for (final Map.Entry<String, Class<?>> entry : XStreamAlias.getMap().entrySet()) {
      xstream.alias(entry.getKey(), entry.getValue());
    }
    final MapConverter mapConverter = new MapConverter(xstream.getMapper()) {
      /** {@inheritDoc} */
      @SuppressWarnings("rawtypes")
      @Override
      public boolean canConvert(Class type) {
        return true; // Counter.requests est bien une map
      }
    };
    xstream.registerLocalConverter(Counter.class, "requests", mapConverter);
    xstream.registerLocalConverter(Counter.class, "rootCurrentContextsByThreadId",
        mapConverter);
    return 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

public static <T> T serializeAndDeserializeWithXStream(T input) {
  XStream xStream = new XStream();
  xStream.setMode(XStream.ID_REFERENCES);
  if (input != null) {
    xStream.processAnnotations(input.getClass());
  }
  XStream.setupDefaultSecurity(xStream);
  xStream.addPermission(new AnyTypePermission());
  String xmlString = xStream.toXML(input);
  return (T) xStream.fromXML(xmlString);
}

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

private XStreamXmlPlannerBenchmarkFactory createXStreamXmlPlannerBenchmarkFactory(String plannerBenchmarkConfigResource) throws IOException {
  InputStream originalConfigInputStream = getClass().getResourceAsStream(plannerBenchmarkConfigResource);
  XStreamXmlPlannerBenchmarkFactory plannerBenchmarkFactory = new XStreamXmlPlannerBenchmarkFactory().configure(originalConfigInputStream);
  plannerBenchmarkFactory.getXStream().setMode(XStream.NO_REFERENCES);
  return plannerBenchmarkFactory;
}

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

@Test
public void configFileRemainsSameAfterReadWrite() throws IOException {
  String solverConfigResource = "testdataSolverConfigXStream.xml";
  String originalXml = IOUtils.toString(getClass().getResourceAsStream(solverConfigResource), "UTF-8");
  InputStream originalConfigInputStream = getClass().getResourceAsStream(solverConfigResource);
  XStreamXmlSolverFactory solverFactory = new XStreamXmlSolverFactory().configure(originalConfigInputStream);
  solverFactory.getXStream().setMode(XStream.NO_REFERENCES);
  SolverConfig solverConfig = solverFactory.getSolverConfig();
  SolverConfigContext configContext = new SolverConfigContext(getClass().getClassLoader());
  solverConfig.buildSolver(configContext);
  String savedXml = solverFactory.getXStream().toXML(solverConfig);
  assertEquals(originalXml.trim(), savedXml.trim());
  originalConfigInputStream.close();
}

代码示例来源: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: geoserver/geoserver

/** Constructs the persister and underlying xstream specifying the stream driver explicitly. */
protected XStreamPersister(HierarchicalStreamDriver streamDriver) {
  // control the order in which fields are sorted
  SortableFieldKeySorter sorter = new SortableFieldKeySorter();
  // sorter.registerFieldOrder( DefaultCatalogDAO.class, new String[]{ "workspaces",
  // "namespaces", "stores", "styles",
  /* these we actually omit, but the sorter needs them specified */
  //    "layerGroups", "resources", "maps", "defaultStores", "listeners", "layers",
  // "resourcePool", "resourceLoader", "LOGGER" } );
  ReflectionProvider reflectionProvider =
      new CustomReflectionProvider(new FieldDictionary(sorter));
  // new Sun14ReflectionProvider( new FieldDictionary( sorter  ) );
  if (streamDriver != null) {
    xs = new SecureXStream(reflectionProvider, streamDriver);
  } else {
    xs = new SecureXStream(reflectionProvider);
  }
  xs.setMode(XStream.NO_REFERENCES);
  init(xs);
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

setupConverters();
setupImmutableTypes();
setMode(XPATH_RELATIVE_REFERENCES);

代码示例来源: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.tinygroup/org.tinygroup.weixinpay

public String toString() {
    XStream xstream = new XStream();
    xstream.setMode(XStream.NO_REFERENCES);
    xstream.processAnnotations(getClass());
    return xstream.toXML(this);
  }
}

代码示例来源:origin: GeoWebCache/geowebcache

public static XStream getConfiguredXStream(XStream xs) {
  // Allow anything that's part of GWC Diskquota
  // TODO: replace this with a more narrow whitelist
  xs.allowTypesByWildcard(new String[] {"org.geowebcache.**"});
  xs.setMode(XStream.NO_REFERENCES);
  xs.alias("gwcQuotaConfiguration", DiskQuotaConfig.class);
  xs.alias("layerQuotas", List.class);
  xs.alias("LayerQuota", LayerQuota.class);
  xs.alias("Quota", Quota.class);
  xs.registerConverter(new QuotaXSTreamConverter());
  return xs;
}

代码示例来源:origin: GeoWebCache/geowebcache

private static XStream getXStream() {
  XStream xs = new GeoWebCacheXStream();
  // Allow anything that's part of GWC
  // TODO: replace this with a more narrow whitelist
  xs.allowTypesByWildcard(new String[] {"org.geowebcache.**"});
  xs.setMode(XStream.NO_REFERENCES);
  xs.alias("gwcJdbcConfiguration", JDBCConfiguration.class);
  xs.alias("connectionPool", ConnectionPoolConfiguration.class);
  return xs;
}

代码示例来源:origin: org.apache.camel/camel-xstream

@Override
protected XStream createXStream(ClassResolver resolver, ClassLoader classLoader) {
  XStream xs = super.createXStream(resolver, classLoader);
  if (getMode() != null) {
    xs.setMode(getModeFromString(getMode()));
  } else {
    xs.setMode(XStream.NO_REFERENCES);
  }
  return xs;
}

代码示例来源:origin: org.optaplanner/optaplanner-wb-solver-editor-backend

public XStreamSolutionImporter(ClassLoader classLoader) {
  xStream = XStreamUtils.createTrustingXStream();
  xStream.setClassLoader(classLoader);
  xStream.setMode(XStream.ID_REFERENCES);
}

代码示例来源:origin: org.dataconservancy.reporting/dcs-pkg-ui-reporting-model-builder-xstream

public static XStream newInstance() {
  
  final QNameMap qnames = new QNameMap();
  
  final DcsPullDriver driver = new DcsPullDriver(qnames);
  
  // The XStream Driver
  final XStream x = new XStream(driver);
  x.setMode(XStream.NO_REFERENCES);
  
  x.addDefaultImplementation(IngestReport.class, IngestReport.class);
  x.alias(IngestReportConverter.E_INGEST_REPORT, IngestReport.class);
  x.registerConverter(new IngestReportConverter());
  qnames.registerMapping(new QName(null, IngestReportConverter.E_INGEST_REPORT), IngestReport.class);
  
  return x;
}

代码示例来源:origin: org.tinygroup/org.tinygroup.weixinpay

public String toString() {
  XStream xstream = new XStream(new XppDriver(new NoNameCoder()));
  xstream.setMode(XStream.NO_REFERENCES);
  xstream.processAnnotations(getClass());
  return xstream.toXML(this);
}

相关文章