use of org.codehaus.staxmate.SMInputFactory in project sonarqube by SonarSource.
the class QProfileBackuper method restore.
/**
* @param reader the XML backup
* @param toProfileName the target profile. If <code>null</code>, then use the
* lang and name declared in the backup
*/
public BulkChangeResult restore(Reader reader, @Nullable QProfileName toProfileName) {
try {
String profileLang = null;
String profileName = null;
List<RuleActivation> ruleActivations = Lists.newArrayList();
SMInputFactory inputFactory = initStax();
SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader);
// <profile>
rootC.advance();
if (!rootC.getLocalName().equals("profile")) {
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();
if (StringUtils.equals("name", nodeName)) {
profileName = StringUtils.trim(cursor.collectDescendantText(false));
} else if (StringUtils.equals("language", nodeName)) {
profileLang = StringUtils.trim(cursor.collectDescendantText(false));
} else if (StringUtils.equals("rules", nodeName)) {
SMInputCursor rulesCursor = cursor.childElementCursor("rule");
ruleActivations = parseRuleActivations(rulesCursor);
}
}
QProfileName target = (QProfileName) ObjectUtils.defaultIfNull(toProfileName, new QProfileName(profileLang, profileName));
return reset.reset(target, ruleActivations);
} catch (XMLStreamException e) {
throw new IllegalStateException("Fail to restore Quality profile backup", e);
}
}
use of org.codehaus.staxmate.SMInputFactory in project sonarqube by SonarSource.
the class DebtRulesXMLImporter method initStax.
private static SMInputFactory initStax() {
XMLInputFactory xmlFactory = XMLInputFactory2.newInstance();
xmlFactory.setProperty(IS_COALESCING, TRUE);
xmlFactory.setProperty(IS_NAMESPACE_AWARE, FALSE);
xmlFactory.setProperty(SUPPORT_DTD, FALSE);
xmlFactory.setProperty(IS_VALIDATING, FALSE);
return new SMInputFactory(xmlFactory);
}
use of org.codehaus.staxmate.SMInputFactory in project sonarqube by SonarSource.
the class DuplicationsParser method initStax.
private static SMInputFactory initStax() {
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);
return new SMInputFactory(xmlFactory);
}
use of org.codehaus.staxmate.SMInputFactory in project sonarqube by SonarSource.
the class XMLRuleParser method parse.
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);
// <rules>
rootC.advance();
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);
}
}
use of org.codehaus.staxmate.SMInputFactory in project sonarqube by SonarSource.
the class XMLProfileParser method initStax.
private static SMInputFactory initStax() {
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);
return new SMInputFactory(xmlFactory);
}
Aggregations