Example usage for javax.xml.stream XMLInputFactory SUPPORT_DTD

List of usage examples for javax.xml.stream XMLInputFactory SUPPORT_DTD

Introduction

In this page you can find the example usage for javax.xml.stream XMLInputFactory SUPPORT_DTD.

Prototype

String SUPPORT_DTD

To view the source code for javax.xml.stream XMLInputFactory SUPPORT_DTD.

Click Source Link

Document

The property that requires the parser to support DTDs

Usage

From source file:org.sonar.plugins.android.lint.AndroidLintProfileExporter.java

private void loadRuleKeys() {
    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);
    InputStream inputStream = getClass().getResourceAsStream(AndroidLintRulesDefinition.RULES_XML_PATH);
    InputStreamReader reader = new InputStreamReader(inputStream, Charsets.UTF_8);
    try {//from  w w  w.  j a  v a 2 s  .co m
        SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader);
        rootC.advance(); // <rules>

        SMInputCursor rulesC = rootC.childElementCursor("rule");
        while (rulesC.getNext() != null) {
            // <rule>
            SMInputCursor cursor = rulesC.childElementCursor();
            while (cursor.getNext() != null) {
                if (StringUtils.equalsIgnoreCase("key", cursor.getLocalName())) {
                    String key = StringUtils.trim(cursor.collectDescendantText(false));
                    ruleKeys.add(key);
                }
            }
        }

    } catch (XMLStreamException e) {
        throw new IllegalStateException("XML is not valid", e);
    }
}

From source file:org.sonar.plugins.checkstyle.CheckstyleProfileImporter.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);
    SMInputFactory inputFactory = new SMInputFactory(xmlFactory);
    return inputFactory;
}

From source file:org.sonar.plugins.javascript.jslint.JsLintXmlRuleParser.java

public List<JsLintRule> 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.  j  av a  2s  .co  m
        SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader);
        rootC.advance(); // <rules>
        List<JsLintRule> rules = new ArrayList<JsLintRule>();

        SMInputCursor rulesC = rootC.childElementCursor("rule");
        while (rulesC.getNext() != null) {
            // <rule>
            JsLintRule rule = new JsLintRule();
            rules.add(rule);

            processRule(rule, rulesC);
        }
        return rules;

    } catch (XMLStreamException e) {
        throw new SonarException("XML is not valid", e);
    }
}

From source file:org.sonar.plugins.ndepend.QueryLoader.java

public ImmutableList<NdependQuery> getQueries(Reader reader) {
    XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
    xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
    xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE);
    xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
    SMInputFactory inputFactory = new SMInputFactory(xmlFactory);
    ImmutableList.Builder<NdependQuery> builder = new Builder<NdependQuery>();
    try {//from   w w  w. j  a  va2 s  .c  om
        SMHierarchicCursor root = inputFactory.rootElementCursor(reader);
        root.advance();

        SMInputCursor rules = root.childElementCursor("rule");
        while (rules.getNext() != null) {
            builder.add(processRule(rules));
        }
        return builder.build();

    } catch (XMLStreamException e) {
        throw new IllegalStateException("XML is not valid", e);
    }
}

From source file:org.sonar.plugins.xaml.fxcop.XamlFxCopRulesSensor.java

protected 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.server.duplication.ws.DuplicationsParser.java

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);
}

From source file:org.wso2.carbon.device.mgt.core.config.tenant.PlatformConfigurationManagementServiceImpl.java

@Override
public PlatformConfiguration getConfiguration(String resourcePath) throws ConfigurationManagementException {
    Resource resource;/*from   ww  w .  ja va  2s.c  om*/
    try {
        resource = ConfigurationManagerUtil.getRegistryResource(resourcePath);
        if (resource != null) {
            XMLInputFactory factory = XMLInputFactory.newInstance();
            factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
            factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
            XMLStreamReader reader = factory
                    .createXMLStreamReader(new StringReader(new String((byte[]) resource.getContent(),
                            Charset.forName(ConfigurationManagerConstants.CharSets.CHARSET_UTF8))));

            JAXBContext context = JAXBContext.newInstance(PlatformConfiguration.class);
            Unmarshaller unmarshaller = context.createUnmarshaller();
            return (PlatformConfiguration) unmarshaller.unmarshal(reader);
        }
        return new PlatformConfiguration();
    } catch (JAXBException | XMLStreamException e) {
        throw new ConfigurationManagementException(
                "Error occurred while parsing the Tenant configuration : " + e.getMessage(), e);
    } catch (RegistryException e) {
        throw new ConfigurationManagementException(
                "Error occurred while retrieving the Registry resource of Tenant Configuration : "
                        + e.getMessage(),
                e);
    }
}

From source file:org.wso2.carbon.device.mgt.extensions.device.type.template.DeviceTypeManager.java

@Override
public PlatformConfiguration getConfiguration() throws DeviceManagementException {
    Resource resource;/*from  w  w  w. j a va  2 s  .co m*/
    try {
        resource = DeviceTypeUtils.getRegistryResource(deviceType);
        if (resource != null) {
            XMLInputFactory factory = XMLInputFactory.newInstance();
            factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
            factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
            XMLStreamReader reader = factory
                    .createXMLStreamReader(new StringReader(new String((byte[]) resource.getContent(),
                            Charset.forName(DeviceTypePluginConstants.CHARSET_UTF8))));

            JAXBContext context = JAXBContext.newInstance(PlatformConfiguration.class);
            Unmarshaller unmarshaller = context.createUnmarshaller();
            return (PlatformConfiguration) unmarshaller.unmarshal(reader);
        } else if (defaultPlatformConfiguration != null) {
            return defaultPlatformConfiguration;
        }
        return null;
    } catch (DeviceTypeMgtPluginException e) {
        throw new DeviceManagementException(
                "Error occurred while retrieving the Registry instance : " + e.getMessage(), e);
    } catch (JAXBException | XMLStreamException e) {
        throw new DeviceManagementException(
                "Error occurred while parsing the " + deviceType + " configuration : " + e.getMessage(), e);
    } catch (RegistryException e) {
        throw new DeviceManagementException("Error occurred while retrieving the Registry resource of "
                + deviceType + " Configuration : " + e.getMessage(), e);
    }
}

From source file:org.wso2.carbon.device.mgt.mobile.android.impl.AndroidDeviceManager.java

@Override
public PlatformConfiguration getConfiguration() throws DeviceManagementException {
    Resource resource;//from w  ww. ja  va 2s .c  om
    try {
        String androidRegPath = MobileDeviceManagementUtil
                .getPlatformConfigPath(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
        resource = MobileDeviceManagementUtil.getRegistryResource(androidRegPath);
        if (resource != null) {
            XMLInputFactory factory = XMLInputFactory.newInstance();
            factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
            factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
            XMLStreamReader reader = factory
                    .createXMLStreamReader(new StringReader(new String((byte[]) resource.getContent(),
                            Charset.forName(AndroidPluginConstants.MobilePluginConstants.CHARSET_UTF8))));
            JAXBContext context = JAXBContext.newInstance(PlatformConfiguration.class);
            Unmarshaller unmarshaller = context.createUnmarshaller();
            return (PlatformConfiguration) unmarshaller.unmarshal(reader);
        }
        return null;
    } catch (AndroidDeviceMgtPluginException e) {
        throw new DeviceManagementException(
                "Error occurred while retrieving the Registry instance : " + e.getMessage(), e);
    } catch (JAXBException | XMLStreamException e) {
        throw new DeviceManagementException(
                "Error occurred while parsing the Android configuration : " + e.getMessage(), e);
    } catch (RegistryException e) {
        throw new DeviceManagementException(
                "Error occurred while retrieving the Registry resource of Android Configuration : "
                        + e.getMessage(),
                e);
    }
}

From source file:pl.hycom.pip.messanger.pipeline.PipelineManager.java

@Override
public void afterPropertiesSet() throws Exception {
    XMLInputFactory xif = XMLInputFactory.newFactory();
    xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
    XMLStreamReader xsr = xif/*from  w  w w .j  a  va  2s  .  c om*/
            .createXMLStreamReader(new StreamSource(getClass().getResourceAsStream(pipelineFileURL)));

    pipeline = (Pipeline) JAXBContext.newInstance(Pipeline.class).createUnmarshaller().unmarshal(xsr);
}