List of usage examples for javax.xml.stream XMLInputFactory SUPPORT_DTD
String SUPPORT_DTD
To view the source code for javax.xml.stream XMLInputFactory SUPPORT_DTD.
Click Source Link
From source file:org.jboss.loom.migrators.logging.LoggingMigrator.java
@Override public void loadSourceServerConfig(MigrationContext ctx) throws LoadMigrationException { try {/* w w w . jav a 2 s .c o m*/ File log4jConfFile = Utils.createPath( //super.getGlobalConfig().getAS5Config().getDir(), "server", //super.getGlobalConfig().getAS5Config().getProfileName(), //"conf", "jboss-log4j.xml"); super.getGlobalConfig().getAS5Config().getConfDir(), "jboss-log4j.xml"); XMLInputFactory xif = XMLInputFactory.newFactory(); xif.setProperty(XMLInputFactory.SUPPORT_DTD, false); XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(log4jConfFile)); //if( ! log4jConfFile.canRead()) // throw new LoadMigrationException("Cannot find/open file: " + log4jConfFile.getAbsolutePath()); Unmarshaller unmarshaller = JAXBContext.newInstance(LoggingAS5Bean.class).createUnmarshaller(); LoggingAS5Bean loggingAS5 = (LoggingAS5Bean) unmarshaller.unmarshal(xsr); MigratorData mData = new MigratorData(); if (loggingAS5.getCategories() != null) { mData.getConfigFragments().addAll(loggingAS5.getCategories()); } if (loggingAS5.getLoggers() != null) { mData.getConfigFragments().addAll(loggingAS5.getLoggers()); } mData.getConfigFragments().addAll(loggingAS5.getAppenders()); mData.getConfigFragments().add(loggingAS5.getRootLoggerAS5()); ctx.getMigrationData().put(LoggingMigrator.class, mData); } catch (JAXBException | XMLStreamException e) { throw new LoadMigrationException(e); } }
From source file:org.jmecsoftware.plugins.tests.utils.StaxParser.java
/** * Stax parser for a given stream handler and iso control chars set awarness to on. * The iso control chars in the xml file will be replaced by simple spaces, usefull for * potentially bogus XML files to parse, this has a small perfs overhead so use it only when necessary * * @param streamHandler the xml stream handler * @param isoControlCharsAwareParser true or false *//*from w w w .jav a 2 s .c om*/ public StaxParser(XmlStreamHandler streamHandler, boolean isoControlCharsAwareParser) { this.streamHandler = streamHandler; XMLInputFactory xmlFactory = XMLInputFactory.newInstance(); if (xmlFactory instanceof WstxInputFactory) { WstxInputFactory wstxInputfactory = (WstxInputFactory) xmlFactory; wstxInputfactory.configureForLowMemUsage(); wstxInputfactory.getConfig().setUndeclaredEntityResolver(new UndeclaredEntitiesXMLResolver()); } xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, false); xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false); xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false); this.isoControlCharsAwareParser = isoControlCharsAwareParser; inf = new SMInputFactory(xmlFactory); }
From source file:org.odata4j.format.xml.AtomFeedFormatParserExt.java
private XMLEventReader2 createXMLEventReader(Reader reader) { XMLInputFactory factory = XMLInputFactory.newInstance(); //XXE on its own can be prevented by setting IS_SUPPORT_EXTERNAL_ENTITIES to false but this will not //prevent a billion laugh attack. Setting IS_REPLACING_ENTITY_REFERENCES to false does //not force the implementation to not process internal entity references. //Safest thing to do is to set SUPPORT_DTD to false to prevent both XXE and billion laugh. factory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); XMLEventReader2 xmlEventReader2 = new StaxXMLInputFactory2Ext(factory).createXMLEventReader(reader); return xmlEventReader2; }
From source file:org.opendaylight.controller.config.persist.storage.file.xml.model.Config.java
public static Config fromXml(File from) { if (isEmpty(from)) { return new Config(); }/*www. j a v a 2s . co m*/ try { JAXBContext jaxbContext = JAXBContext.newInstance(Config.class); Unmarshaller um = jaxbContext.createUnmarshaller(); XMLInputFactory xif = XMLInputFactory.newFactory(); xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); xif.setProperty(XMLInputFactory.SUPPORT_DTD, false); XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(from)); return ((Config) um.unmarshal(xsr)); } catch (JAXBException | XMLStreamException e) { throw new PersistException("Unable to restore configuration", e); } }
From source file:org.sonar.api.profiles.XMLProfileParser.java
private 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); }
From source file:org.sonar.api.rules.XMLRuleParser.java
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 {/*from w ww . ja va 2s .com*/ SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader); rootC.advance(); // <rules> List<Rule> rules = new ArrayList<Rule>(); 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); } }
From source file:org.sonar.api.server.rule.RulesDefinitionXmlLoader.java
/** * Loads rules by reading the XML input stream. The reader is not closed by the method, so it * should be handled by the caller./* www .ja v a 2 s. c om*/ * @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); } }
From source file:org.sonar.core.technicaldebt.TechnicalDebtXMLImporter.java
private SMInputFactory initStax() { XMLInputFactory xmlFactory = XMLInputFactory2.newInstance(); xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE); xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE); return new SMInputFactory(xmlFactory); }
From source file:org.sonar.cxx.sensors.utils.StaxParser.java
/** * StaxParser for a given stream handler and ISO control chars set awareness to on. The ISO control chars in the XML * file will be replaced by simple spaces, useful for potentially bogus XML files to parse, this has a small perfs * overhead so use it only when necessary * * @param streamHandler the XML stream handler * @param isoControlCharsAwareParser true or false */// w ww .j a va2 s . c om public StaxParser(XmlStreamHandler streamHandler, boolean isoControlCharsAwareParser) { this.streamHandler = streamHandler; XMLInputFactory xmlFactory = XMLInputFactory.newInstance(); if (xmlFactory instanceof WstxInputFactory) { WstxInputFactory wstxInputfactory = (WstxInputFactory) xmlFactory; wstxInputfactory.configureForLowMemUsage(); wstxInputfactory.getConfig().setUndeclaredEntityResolver(new UndeclaredEntitiesXMLResolver()); } xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE); xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE); this.isoControlCharsAwareParser = isoControlCharsAwareParser; inf = new SMInputFactory(xmlFactory); }
From source file:org.sonar.plugins.ada.rules.AdaProfileImporter.java
/** * @return//from w w w . j a va 2 s .co m */ private SMInputFactory initStax() { XMLInputFactory xmlFactory = XMLInputFactory2.newInstance(); xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE); xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE); SMInputFactory inputFactory = new SMInputFactory(xmlFactory); return inputFactory; }