Example usage for javax.xml.stream XMLInputFactory setProperty

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

Introduction

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

Prototype

public abstract void setProperty(java.lang.String name, Object value) throws java.lang.IllegalArgumentException;

Source Link

Document

Allows the user to set specific feature/property on the underlying implementation.

Usage

From source file:org.sonar.plugins.ada.rules.AdaProfileImporter.java

/**
 * @return/*w ww .  j  a  v a 2s .c o 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;
}

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 {/* ww  w . j  a va2s.c  o  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 {/*  ww w  .jav  a2s. c  o 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 ww  w. j  av a 2s.  c o m*/
        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.debt.DebtRulesXMLImporter.java

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

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.apimgt.impl.APIProviderImplTest.java

private static OMElement buildOMElement(InputStream inputStream) throws APIManagementException {
    XMLStreamReader parser;//  w ww . ja  va2s  . c  om
    StAXOMBuilder builder;
    try {
        XMLInputFactory factory = XMLInputFactory.newInstance();
        factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
        parser = factory.createXMLStreamReader(inputStream);
        builder = new StAXOMBuilder(parser);
    } catch (XMLStreamException e) {
        String msg = "Error in initializing the parser.";
        throw new APIManagementException(msg, e);
    }

    return builder.getDocumentElement();
}

From source file:org.wso2.carbon.apimgt.usage.client.impl.APIUsageStatisticsRestClientImpl.java

/**
 * This method read XML content from the given stream
 *
 * @param inputStream Stream to read XML
 * @return XML represented by OMElement//  w  ww .  j  a va 2s .c o m
 * @throws Exception throws generic exception
 */
public static OMElement buildOMElement(InputStream inputStream) throws Exception {
    XMLStreamReader parser;
    try {
        XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
        xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
        parser = xmlInputFactory.createXMLStreamReader(inputStream);
    } catch (XMLStreamException e) {
        String msg = "Error in initializing the parser to build the OMElement.";
        log.error(msg, e);
        throw new Exception(msg, e);
    }
    StAXOMBuilder builder = new StAXOMBuilder(parser);
    return builder.getDocumentElement();
}