/** * 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; }
public static void main(String[] args) { Players xstramAliasObject = new Players(); XStream xstream = new XStream(new JsonHierarchicalStreamDriver()); xstream.setMode(XStream.NO_REFERENCES); xstream.aliasSystemAttribute(null, "class"); xstream.autodetectAnnotations(true); System.out.println("--- "+xstream.toXML(xstramAliasObject)); }
/** * Builds rule sets from xml file * * @param configuration Xml file configuration * @return Rule set */ public static Ruleset buildRuleSetFromXml(String configuration) { XStream xstream = new XStream(); xstream.setClassLoader(DelphiRulesUtils.class.getClassLoader()); xstream.processAnnotations(Ruleset.class); xstream.processAnnotations(DelphiRule.class); xstream.processAnnotations(Property.class); xstream.aliasSystemAttribute("ref", "class"); return (Ruleset) xstream.fromXML(configuration); }
/** * Gets the coverage. * * @param coverageReportFile * the coverage report file * @return the coverage */ private CoverageNode getCoverage(File coverageReportFile) { InputStream inputStream = null; try { XStream xstream = new XStream(); xstream.setClassLoader(getClass().getClassLoader()); xstream.aliasSystemAttribute("classType", "class"); xstream.processAnnotations(CoverageNode.class); xstream.processAnnotations(ProjectNode.class); xstream.processAnnotations(FileNode.class); xstream.processAnnotations(MetricsNode.class); xstream.processAnnotations(LineNode.class); inputStream = new FileInputStream(coverageReportFile); return (CoverageNode) xstream.fromXML(inputStream); } catch (IOException e) { throw new SonarException("Can't read pUnit report : " + coverageReportFile.getName(), e); } finally { IOUtils.closeQuietly(inputStream); } }
/** * Gets the test suites. * * @param report * the report * @return the test suites */ private TestSuites getTestSuites(File report) { InputStream inputStream = null; try { XStream xstream = new XStream(); // Sonar 2.2 migration xstream.setClassLoader(getClass().getClassLoader()); xstream.aliasSystemAttribute("fileName", "class"); xstream.processAnnotations(TestSuites.class); xstream.processAnnotations(TestSuite.class); xstream.processAnnotations(TestCase.class); inputStream = new FileInputStream(report); TestSuites testSuites = (TestSuites) xstream.fromXML(inputStream); Log.debug("Tests suites: " + testSuites); return testSuites; } catch (IOException e) { throw new SonarException("Can't read PhpUnit report : " + report.getAbsolutePath(), e); } finally { IOUtils.closeQuietly(inputStream); } }
/** * Gets the duplications. * * @param reportFile * the report file * @return the coverage */ private List<DuplicationNode> getDuplications(File reportFile) { InputStream inputStream = null; try { XStream xstream = new XStream(); xstream.setClassLoader(getClass().getClassLoader()); xstream.aliasSystemAttribute("classType", "class"); xstream.processAnnotations(PmdCpdNode.class); xstream.processAnnotations(DuplicationNode.class); xstream.processAnnotations(FileNode.class); inputStream = new FileInputStream(reportFile); PmdCpdNode node = (PmdCpdNode) xstream.fromXML(inputStream); if (node.getDuplications() != null) { return node.getDuplications(); } } catch (IOException e) { throw new SonarException("Can't read phpcpd report : " + reportFile.getName(), e); } finally { IOUtils.closeQuietly(inputStream); } return new ArrayList<DuplicationNode>(); }
public DigitalCollectionsXStreamMarshaller() { super(); setStreamDriver(new CdataXppDriver()); Map<String, Class> aliases = getAliases(); setAliases(aliases); Map<Class, String> attributes = new HashMap<>(); attributes.put(MarkImpl.class, "type"); setUseAttributeFor(attributes); XStream xStream = getXStream(); xStream.aliasSystemAttribute(null, "class"); xStream.registerConverter(new MapToFlatConverter(xStream.getMapper())); xStream.aliasField("body", TextImpl.class, "text"); xStream.aliasField("content", BlockquoteImpl.class, "contentBlocks"); xStream.aliasField("content", BulletListImpl.class, "contentBlocks"); xStream.aliasField("content", CodeBlockImpl.class, "contentBlocks"); xStream.aliasField("content", HeadingImpl.class, "contentBlocks"); xStream.aliasField("content", ListItemImpl.class, "contentBlocks"); xStream.aliasField("content", OrderedListImpl.class, "contentBlocks"); xStream.aliasField("content", ParagraphImpl.class, "contentBlocks"); xStream.setMode(XStream.NO_REFERENCES); }
xStream.alias("format", ReportValueFormat.class); xStream.addDefaultImplementation(LinkedHashMap.class, Map.class); xStream.aliasSystemAttribute(null, "class");
public V1DigitalCollectionsXStreamMarshaller() { super(); setStreamDriver(new CdataXppDriver()); Map<String, Class> aliases = getAliases(); setAliases(aliases); Map<Class, String> attributes = new HashMap<>(); attributes.put(MarkImpl.class, "type"); setUseAttributeFor(attributes); XStream xStream = getXStream(); xStream.aliasSystemAttribute(null, "class"); xStream.registerConverter(new MapToFlatConverter(xStream.getMapper())); xStream.aliasField("body", TextImpl.class, "text"); xStream.aliasField("content", BlockquoteImpl.class, "contentBlocks"); xStream.aliasField("content", BulletListImpl.class, "contentBlocks"); xStream.aliasField("content", CodeBlockImpl.class, "contentBlocks"); xStream.aliasField("content", HeadingImpl.class, "contentBlocks"); xStream.aliasField("content", ListItemImpl.class, "contentBlocks"); xStream.aliasField("content", OrderedListImpl.class, "contentBlocks"); xStream.aliasField("content", ParagraphImpl.class, "contentBlocks"); xStream.aliasField("content", StructuredContentImpl.class, "contentBlocks"); xStream.aliasField("documents", LocalizedStructuredContentImpl.class, "localizedStructuredContent"); xStream.setMode(XStream.NO_REFERENCES); }
xstream.aliasSystemAttribute("refid", "id");