List of usage examples for javax.xml.stream XMLInputFactory IS_COALESCING
String IS_COALESCING
To view the source code for javax.xml.stream XMLInputFactory IS_COALESCING.
Click Source Link
From source file:org.sonar.plugins.ada.rules.AdaProfileImporter.java
/** * @return/*from w ww .j av a2 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; }
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 ww w.j a v a 2 s .com*/ 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 w w.j a v 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 w w w . j a va 2 s . 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.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.appfactory.core.dao.ApplicationDAO.java
/** * Method to add an application artifact to registry * * @param info information of application, that need to be added to the registry * @param lifecycleAttribute the name of lifecycle, that should be associated with the application * @return registry path of the application artifact * @throws AppFactoryException/*from w w w. j a va2s. c om*/ */ public String addApplicationArtifact(String info, String lifecycleAttribute) throws AppFactoryException { RegistryUtils.recordStatistics(AppFactoryConstants.RXT_KEY_APPINFO_APPLICATION, info, lifecycleAttribute); String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain(); try { UserRegistry userRegistry = GovernanceUtil.getUserRegistry(); XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_COALESCING, true); XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(info)); GenericArtifactManager manager = new GenericArtifactManager(userRegistry, AppFactoryConstants.RXT_KEY_APPINFO_APPLICATION); GenericArtifact artifact = manager .newGovernanceArtifact(new StAXOMBuilder(reader).getDocumentElement()); // want to save original content, so set content here artifact.setContent(info.getBytes()); manager.addGenericArtifact(artifact); if (lifecycleAttribute != null) { String lifecycle = artifact.getAttribute(lifecycleAttribute); if (lifecycle != null) { artifact.attachLifecycle(lifecycle); } } return AppFactoryConstants.REGISTRY_GOVERNANCE_PATH + artifact.getPath(); } catch (Exception e) { log.error("Error while adding application artifact in tenant : " + tenantDomain); throw new AppFactoryException(e); } }
From source file:org.wso2.carbon.appfactory.core.governance.RxtManager.java
public String addArtifact(String key, String info, String lifecycleAttribute) throws AppFactoryException { RegistryUtils.recordStatistics(key, info, lifecycleAttribute); try {//w ww . j a v a 2 s . c o m UserRegistry userRegistry = getUserRegistry(); XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_COALESCING, true); XMLStreamReader reader = null; reader = factory.createXMLStreamReader(new StringReader(info)); GenericArtifactManager manager = new GenericArtifactManager(userRegistry, key); GenericArtifact artifact = manager .newGovernanceArtifact(new StAXOMBuilder(reader).getDocumentElement()); // want to save original content, so set content here artifact.setContent(info.getBytes()); manager.addGenericArtifact(artifact); if (lifecycleAttribute != null) { String lifecycle = artifact.getAttribute(lifecycleAttribute); if (lifecycle != null) { artifact.attachLifecycle(lifecycle); } } return "/_system/governance" + artifact.getPath(); } catch (Exception e) { String errorMsg = "Error adding artifact"; throw new AppFactoryException(errorMsg, e); } }
From source file:org.wso2.carbon.event.processor.storm.StormProcessorDeployer.java
private OMElement getExecutionPlanOMElement(File executionPlanFile) throws DeploymentException { OMElement executionPlanElement;//from w w w . ja va 2 s . co m BufferedInputStream inputStream = null; try { inputStream = new BufferedInputStream(new FileInputStream(executionPlanFile)); XMLInputFactory xif = XMLInputFactory.newInstance(); XMLStreamReader parser = xif.createXMLStreamReader(inputStream); xif.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE); //for CDATA StAXOMBuilder builder = new StAXOMBuilder(parser); executionPlanElement = builder.getDocumentElement(); executionPlanElement.build(); } catch (FileNotFoundException e) { String errorMessage = "file cannot be found : " + executionPlanFile.getName(); log.error(errorMessage, e); throw new DeploymentException(errorMessage, e); } catch (XMLStreamException e) { String errorMessage = "Invalid XML for " + executionPlanFile.getName(); log.error(errorMessage, e); throw new DeploymentException(errorMessage, e); } catch (OMException e) { String errorMessage = "XML tags are not properly closed in " + executionPlanFile.getName(); log.error(errorMessage, e); throw new DeploymentException(errorMessage, e); } finally { try { if (inputStream != null) { inputStream.close(); } } catch (IOException e) { String errorMessage = "Can not close the input stream"; log.error(errorMessage, e); } } return executionPlanElement; }