private void parseRootNode(SMHierarchicCursor rootCursor, SensorContext context) throws XMLStreamException { checkElementName(rootCursor, "coverage"); String version = rootCursor.getAttrValue("version"); if (!"1".equals(version)) { throw new IllegalStateException("Unknown report version: " + version + ". This parser only handles version 1."); } parseFiles(rootCursor.childElementCursor(), context); }
private void parseRootNode(SMHierarchicCursor rootCursor, SensorContext context) throws XMLStreamException { String elementName = rootCursor.getLocalName(); if (!OLD_ROOT_ELEMENT.equals(elementName) && !ROOT_ELEMENT.equals(elementName)) { throw new IllegalStateException( "Unknown XML node, expected \"" + ROOT_ELEMENT + "\" but got \"" + elementName + "\" at line " + rootCursor.getCursorLocation().getLineNumber()); } if (OLD_ROOT_ELEMENT.equals(elementName)) { LOG.warn("Using '" + OLD_ROOT_ELEMENT + "' as root element of the report is deprecated. Please change to '" + ROOT_ELEMENT + "'."); } String version = rootCursor.getAttrValue("version"); if (!"1".equals(version)) { throw new IllegalStateException("Unknown report version: " + version + ". This parser only handles version 1."); } parseFiles(rootCursor.childElementCursor(), context); }
/** * Loads rules by reading the XML input stream. The reader is not closed by the method, so it * should be handled by the caller. * @since 4.3 */ public void load(RulesDefinition.NewRepository repo, Reader reader) { XMLInputFactory xmlFactory = XMLInputFactory.newInstance(); xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE); // just so it won't try to load DTD in if there's DOCTYPE xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE); SMInputFactory inputFactory = new SMInputFactory(xmlFactory); try { SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader); rootC.advance(); // <rules> SMInputCursor rulesC = rootC.childElementCursor("rule"); while (rulesC.getNext() != null) { // <rule> processRule(repo, rulesC); } } catch (XMLStreamException e) { throw new IllegalStateException("XML is not valid", e); } }
public List<Rule> parse(Reader reader) { XMLInputFactory xmlFactory = XMLInputFactory.newInstance(); xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE); // just so it won't try to load DTD in if there's DOCTYPE xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE); SMInputFactory inputFactory = new SMInputFactory(xmlFactory); try { SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader); rootC.advance(); // <rules> List<Rule> rules = new ArrayList<>(); SMInputCursor rulesC = rootC.childElementCursor("rule"); while (rulesC.getNext() != null) { // <rule> Rule rule = Rule.create(); rules.add(rule); processRule(rule, rulesC); } return rules; } catch (XMLStreamException e) { throw new SonarException("XML is not valid", e); } }
SMHierarchicCursor root = inputFactory.rootElementCursor(new StringReader(duplicationsData)); SMInputCursor cursor = root.childElementCursor("g"); while (cursor.getNext() != null) { List<Duplication> duplications = new ArrayList<>();
public List<RuleDebt> importXML(Reader xml, ValidationMessages validationMessages) { List<RuleDebt> ruleDebts = newArrayList(); try { SMInputFactory inputFactory = initStax(); SMHierarchicCursor cursor = inputFactory.rootElementCursor(xml); // advance to <sqale> cursor.advance(); SMInputCursor rootCursor = cursor.childElementCursor(CHARACTERISTIC); while (rootCursor.getNext() != null) { process(ruleDebts, validationMessages, rootCursor); } cursor.getStreamReader().closeCompletely(); } catch (XMLStreamException e) { throw new IllegalStateException("XML is not valid", e); } return ruleDebts; }
throw new IllegalArgumentException("Backup XML is not valid. Root element must be <profile>."); SMInputCursor cursor = rootC.childElementCursor(); while (cursor.getNext() != null) { String nodeName = cursor.getLocalName();
public RulesProfile parse(Reader reader, ValidationMessages messages) { RulesProfile profile = RulesProfile.create(); SMInputFactory inputFactory = initStax(); try { SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader); rootC.advance(); // <profile> SMInputCursor cursor = rootC.childElementCursor(); while (cursor.getNext() != null) { String nodeName = cursor.getLocalName(); if (StringUtils.equals("rules", nodeName)) { SMInputCursor rulesCursor = cursor.childElementCursor("rule"); processRules(rulesCursor, profile, messages); } else if (StringUtils.equals("name", nodeName)) { profile.setName(StringUtils.trim(cursor.collectDescendantText(false))); } else if (StringUtils.equals("language", nodeName)) { profile.setLanguage(StringUtils.trim(cursor.collectDescendantText(false))); } } } catch (XMLStreamException e) { messages.addErrorText("XML is not valid: " + e.getMessage()); } checkProfile(profile, messages); return profile; }
private void parseRootNode(SMHierarchicCursor rootCursor, SensorContext context) throws XMLStreamException { checkElementName(rootCursor, "coverage"); String version = rootCursor.getAttrValue("version"); if (!"1".equals(version)) { throw new IllegalStateException("Unknown report version: " + version + ". This parser only handles version 1."); } parseFiles(rootCursor.childElementCursor(), context); }
private void parseRootNode(SMHierarchicCursor rootCursor, SensorContext context) throws XMLStreamException { String elementName = rootCursor.getLocalName(); if (!OLD_ROOT_ELEMENT.equals(elementName) && !ROOT_ELEMENT.equals(elementName)) { throw new IllegalStateException( "Unknown XML node, expected \"" + ROOT_ELEMENT + "\" but got \"" + elementName + "\" at line " + rootCursor.getCursorLocation().getLineNumber()); } if (OLD_ROOT_ELEMENT.equals(elementName)) { LOG.warn("Using '" + OLD_ROOT_ELEMENT + "' as root element of the report is deprecated. Please change to '" + ROOT_ELEMENT + "'."); } String version = rootCursor.getAttrValue("version"); if (!"1".equals(version)) { throw new IllegalStateException("Unknown report version: " + version + ". This parser only handles version 1."); } parseFiles(rootCursor.childElementCursor(), context); }
public void load(RulesDefinition.NewRepository repo, Reader reader) { XMLInputFactory xmlFactory = XMLInputFactory.newInstance(); xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE); // just so it won't try to load DTD in if there's DOCTYPE xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE); SMInputFactory inputFactory = new SMInputFactory(xmlFactory); try { SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader); rootC.advance(); // <rules> SMInputCursor rulesC = rootC.childElementCursor("rule"); while (rulesC.getNext() != null) { // <rule> processRule(repo, rulesC); } } catch (XMLStreamException e) { throw new IllegalStateException("XML is not valid", e); } }
private static TestSuites processRoot(File file, SMInputFactory inputFactory) throws XMLStreamException { SMHierarchicCursor rootCursor = inputFactory.rootElementCursor(file); rootCursor.advance(); if (!"testsuites".equals(rootCursor.getLocalName())) { throw new XMLStreamException("Report should start with <testsuites>"); } SMInputCursor childCursor = rootCursor.childElementCursor("testsuite"); List<TestSuite> testSuites = new ArrayList<>(); while (childCursor.getNext() != null) { testSuites.add(processTestSuite(childCursor)); } return new TestSuites(testSuites); }
private static TestSuites processRoot(File file, SMInputFactory inputFactory) throws XMLStreamException { SMHierarchicCursor rootCursor = inputFactory.rootElementCursor(file); rootCursor.advance(); if (!"testsuites".equals(rootCursor.getLocalName())) { throw new XMLStreamException("Report should start with <testsuites>"); } SMInputCursor childCursor = rootCursor.childElementCursor("testsuite"); List<TestSuite> testSuites = new ArrayList<>(); while (childCursor.getNext() != null) { testSuites.add(processTestSuite(childCursor)); } return new TestSuites(testSuites); }
/** * Loads rules by reading the XML input stream. The reader is not closed by the method, so it * should be handled by the caller. * @since 4.3 */ public void load(RulesDefinition.NewRepository repo, Reader reader) { XMLInputFactory xmlFactory = XMLInputFactory.newInstance(); xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE); // just so it won't try to load DTD in if there's DOCTYPE xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE); SMInputFactory inputFactory = new SMInputFactory(xmlFactory); try { SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader); rootC.advance(); // <rules> SMInputCursor rulesC = rootC.childElementCursor("rule"); while (rulesC.getNext() != null) { // <rule> processRule(repo, rulesC); } } catch (XMLStreamException e) { throw new IllegalStateException("XML is not valid", e); } }
private static CoverageNode parseCoverageNode(SMHierarchicCursor cursor) throws XMLStreamException { CoverageNode result = new CoverageNode(); SMInputCursor childCursor = cursor.childElementCursor("project"); while (childCursor.getNext() != null) { result.getProjects().add(parseProjectNode(childCursor)); } return result; }
private static CoverageNode parseCoverageNode(SMHierarchicCursor cursor) throws XMLStreamException { CoverageNode result = new CoverageNode(); SMInputCursor childCursor = cursor.childElementCursor("project"); while (childCursor.getNext() != null) { result.getProjects().add(parseProjectNode(childCursor)); } return result; }
public List<RuleDebt> importXML(Reader xml, ValidationMessages validationMessages) { List<RuleDebt> ruleDebts = newArrayList(); try { SMInputFactory inputFactory = initStax(); SMHierarchicCursor cursor = inputFactory.rootElementCursor(xml); // advance to <sqale> cursor.advance(); SMInputCursor rootCursor = cursor.childElementCursor(CHARACTERISTIC); while (rootCursor.getNext() != null) { process(ruleDebts, validationMessages, rootCursor); } cursor.getStreamReader().closeCompletely(); } catch (XMLStreamException e) { throw new IllegalStateException("XML is not valid", e); } return ruleDebts; }
private void processRoot(InputStreamReader reader, SMInputFactory inputFactory) throws XMLStreamException { SMHierarchicCursor rootCursor = inputFactory.rootElementCursor(reader); rootCursor.advance(); SMInputCursor charCursor = rootCursor.childElementCursor("chc"); while (charCursor.getNext() != null) { SMInputCursor subCharCursor = charCursor.childElementCursor("chc"); while (subCharCursor.getNext() != null) { processSubChar(subCharCursor); } } }
public RulesProfile parse(Reader reader, ValidationMessages messages) { RulesProfile profile = RulesProfile.create(); SMInputFactory inputFactory = initStax(); try { SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader); rootC.advance(); // <profile> SMInputCursor cursor = rootC.childElementCursor(); while (cursor.getNext() != null) { String nodeName = cursor.getLocalName(); if (StringUtils.equals("rules", nodeName)) { SMInputCursor rulesCursor = cursor.childElementCursor("rule"); processRules(rulesCursor, profile, messages); } else if (StringUtils.equals("name", nodeName)) { profile.setName(StringUtils.trim(cursor.collectDescendantText(false))); } else if (StringUtils.equals("language", nodeName)) { profile.setLanguage(StringUtils.trim(cursor.collectDescendantText(false))); } } } catch (XMLStreamException e) { messages.addErrorText("XML is not valid: " + e.getMessage()); } checkProfile(profile, messages); return profile; }
@Override public RulesProfile importProfile(Reader reader, ValidationMessages messages) { SMInputFactory inputFactory = initStax(); RulesProfile profile = RulesProfile.create(); try { SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader); rootC.advance(); // <module name="Checker"> SMInputCursor rootModulesCursor = rootC.childElementCursor(MODULE_NODE); while (rootModulesCursor.getNext() != null) { String configKey = rootModulesCursor.getAttrValue("name"); if (StringUtils.equals(TREEWALKER_MODULE, configKey)) { SMInputCursor treewalkerCursor = rootModulesCursor.childElementCursor(MODULE_NODE); while (treewalkerCursor.getNext() != null) { processModule(profile, CHECKER_MODULE + "/" + TREEWALKER_MODULE + "/", treewalkerCursor, messages); } } else { processModule(profile, CHECKER_MODULE + "/", rootModulesCursor, messages); } } } catch (XMLStreamException e) { messages.addErrorText("XML is not valid: " + e.getMessage()); } return profile; }