Refine search
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); }
/** * 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); } }
/** * @return */ public List<PhpCodeSnifferViolation> getViolations(File reportFile) { LOG.debug("Report file for PHP_CodeSniffer is " + reportFile); if (reportFile == null || !reportFile.exists()) { throw new SonarException("The XML report '" + reportFile + "' can't be found"); } String reportPath = reportFile.getAbsolutePath(); LOG.debug("Getting violations form report file"); List<PhpCodeSnifferViolation> violations = new ArrayList<PhpCodeSnifferViolation>(); try {// <checkstyle> SMInputFactory inputFactory = new SMInputFactory(XMLInputFactory.newInstance());// <checkstyle> SMInputCursor rootNodeCursor = inputFactory.rootElementCursor(reportFile).advance(); // <file> SMInputCursor fileNodeCursor = rootNodeCursor.childElementCursor(FILE_NODE_NAME).advance(); while (fileNodeCursor.asEvent() != null) { String fileName = fileNodeCursor.getAttrValue(FILE_NAME_ATTRIBUTE_NAME); SMInputCursor violationNodeCursor = fileNodeCursor.childElementCursor().advance(); // <error> while (violationNodeCursor.asEvent() != null) { violations.add(getViolation(fileName, violationNodeCursor)); violationNodeCursor.advance(); } fileNodeCursor.advance(); } rootNodeCursor.getStreamReader().closeCompletely(); } catch (XMLStreamException e) { throw new XmlParserException("Unable to parse the XML Report '" + reportPath + "'", e); } return violations; }
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); }
SMHierarchicCursor root = inputFactory.rootElementCursor(new StringReader(duplicationsData)); root.advance(); // <duplications> SMInputCursor cursor = root.childElementCursor("g"); while (cursor.getNext() != null) { List<Duplication> duplications = new ArrayList<>();
List<Rule> rules = Lists.newArrayList(); SMInputFactory inputFactory = initStax(); SMHierarchicCursor rootC = inputFactory.rootElementCursor(backup); rootC.advance(); // <profile> if (!"profile".equals(rootC.getLocalName())) { 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();
/** * {@inheritDoc} */ @Override public RulesProfile importProfile(Reader reader, ValidationMessages messages) { RulesProfile profile = RulesProfile.create(); profile.setLanguage(languageKey); SMInputFactory inputFactory = initStax(); try { SMHierarchicCursor cursor = inputFactory.rootElementCursor(reader); SMInputCursor rulesetCursor = cursor.advance().childElementCursor(); parseRules(profile, rulesetCursor); cursor.getStreamReader().closeCompletely(); } catch (XMLStreamException e) { messages.addErrorText("Failed to read the profile to import: " + e.getMessage()); } return profile; }
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 Collection<String> getAllRuleKeysFromFile(InputStream inputStream) { SMInputFactory inputFactory = ZapUtils.newStaxParser(); try { SMHierarchicCursor rootC = inputFactory.rootElementCursor(inputStream); SMInputCursor rulesCursor = rootC.advance(); return processRules(rulesCursor); } catch (XMLStreamException e) { throw new IllegalStateException("XML is not valid", e); } }
/** @noinspection RefusedBequest*/ @Override protected SMInputFactory initialValue() { return new SMInputFactory( StaxSupport.XML_INPUT_FACTORY.get() ); } };
/** * Gets the coverage. * * @param coverageReportFile the coverage report file * @return the coverage */ private static CoverageNode getCoverage(File coverageReportFile) { SMInputFactory inputFactory = JUnitLogParserForPhpUnit.inputFactory(); try { SMHierarchicCursor rootCursor = inputFactory.rootElementCursor(coverageReportFile); rootCursor.advance(); if (!"coverage".equals(rootCursor.getLocalName())) { throw new XMLStreamException("Report should start with <coverage>"); } return parseCoverageNode(rootCursor); } catch (XMLStreamException e) { throw new IllegalStateException("Can't read phpUnit report: " + coverageReportFile.getName(), e); } }
public void parse(Reader xmlReader) throws XMLStreamException { if (isoControlCharsAwareParser) { throw new IllegalStateException("Method call not supported when isoControlCharsAwareParser=true"); } parse(inf.rootElementCursor(xmlReader)); }
public static Analysis parse(InputStream inputStream) throws XMLStreamException { SMInputFactory inputFactory = DependencyCheckUtils.newStaxParser(); SMHierarchicCursor rootC = inputFactory.rootElementCursor(inputStream); rootC.advance(); // <analysis> SMInputCursor childCursor = rootC.childCursor(); ScanInfo scanInfo = null; ProjectInfo projectInfo = null; Collection<Dependency> dependencies = Collections.emptyList(); while (childCursor.getNext() != null) { String nodeName = childCursor.getLocalName(); if ("scanInfo".equals(nodeName)) { scanInfo = processScanInfo(childCursor); } else if ("projectInfo".equals(nodeName)) { projectInfo = processProjectInfo(childCursor); } else if ("dependencies".equals(nodeName)) { dependencies = processDependencies(childCursor); } } return new Analysis(scanInfo, projectInfo, dependencies); }
public void parse(InputStream xmlInput) throws XMLStreamException { SMHierarchicCursor rootCursor = inf.rootElementCursor(xmlInput); try { streamHandler.stream(rootCursor); } finally { rootCursor.getStreamReader().closeCompletely(); } }
/** * Method that will construct and return * a nested cursor that will only ever iterate to one node, that * is, the root element of the document reader is reading. *<p> * Cursor is built based on Stax stream reader constructed to * read contents of resource specified by the URL argument. *<p> * Method uses standard "element-only" filter from * {@link org.codehaus.staxmate.in.SMFilterFactory}. */ public SMHierarchicCursor rootElementCursor(URL url) throws XMLStreamException { return constructHierarchic(createStax2Reader(url), SMFilterFactory.getElementOnlyFilter()); }
public SMFlatteningCursor flatteningCursor(File input, SMFilter f) throws XMLStreamException { return constructFlattening(createStax2Reader(input), f); }
/** * Static factory method used to construct root-level flattening (descendant) * cursor, when starting to process an xml document or fragment. * Additional cursors are usually constructed via methods * within this cursor and its child cursors). * * @param sr Underlying stream reader cursor will use * @param f (optional) Filter to use for the cursor, if any; null * means that no filtering will be done. */ public static SMFlatteningCursor flatteningCursor(XMLStreamReader sr, SMFilter f) { return constructFlattening(wrapIfNecessary(sr), f); }
/** * Static factory method used to construct root-level hierarchic (child) * cursor, when starting to process an xml document or fragment. * Additional cursors are usually constructed via methods * within this cursor and its child cursors). * * @param sr Underlying stream reader cursor will use * @param f (optional) Filter to use for the cursor, if any; null * means that no filtering will be done. */ public static SMHierarchicCursor hierarchicCursor(XMLStreamReader sr, SMFilter f) { return constructHierarchic(wrapIfNecessary(sr), f); }
public List<XmlBugInstance> getBugInstances() { List<XmlBugInstance> result = Lists.newArrayList(); try { SMInputFactory inf = new SMInputFactory(XMLInputFactory.newInstance()); SMInputCursor cursor = inf.rootElementCursor(findbugsXmlReport).advance(); SMInputCursor bugInstanceCursor = cursor.childElementCursor("BugInstance").advance(); while (bugInstanceCursor.asEvent() != null) {
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); }