List of usage examples for javax.xml.stream XMLInputFactory setProperty
public abstract void setProperty(java.lang.String name, Object value) throws java.lang.IllegalArgumentException;
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/* www . j a v a2s . co m*/ */ 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 {//from ww w . java2 s . co 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.bam.service.data.publisher.internal.StatisticsServiceComponent.java
private OMElement getPublishingConfig() { String bamConfigPath = CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + CommonConstants.BAM_CONFIG_XML; File bamConfigFile = new File(bamConfigPath); try {//from ww w . j av a 2s . com XMLInputFactory xif = XMLInputFactory.newInstance(); InputStream inputStream = new FileInputStream(bamConfigFile); XMLStreamReader reader = xif.createXMLStreamReader(inputStream); xif.setProperty("javax.xml.stream.isCoalescing", false); StAXOMBuilder builder = new StAXOMBuilder(reader); return builder.getDocument().getOMDocumentElement(); } catch (FileNotFoundException e) { log.warn("No " + CommonConstants.BAM_CONFIG_XML + " found in " + bamConfigPath); return null; } catch (XMLStreamException e) { log.error("Incorrect format " + CommonConstants.BAM_CONFIG_XML + " file", e); return null; } }
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. j av a2 s.c o m 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;//w ww . j a v a2 s.c om 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 w w.java 2 s.co m 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:org.wso2.carbon.event.processor.storm.StormProcessorDeployer.java
private OMElement getExecutionPlanOMElement(File executionPlanFile) throws DeploymentException { OMElement executionPlanElement;//from w w w . ja va2s . c om 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; }
From source file:org.wso2.carbon.governance.api.endpoints.dataobjects.EndpointImpl.java
public OMElement buildOMElement(String content) throws GovernanceException { XMLStreamReader parser;/*from ww w. j a v a 2 s . c o m*/ try { XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_COALESCING, new Boolean(true)); parser = factory.createXMLStreamReader(new StringReader(content)); } catch (XMLStreamException e) { String msg = "Error in initializing the parser to build the OMElement."; log.error(msg, e); throw new GovernanceException(msg, e); } //create the builder StAXOMBuilder builder = new StAXOMBuilder(parser); //get the root element (in this case the envelope) return builder.getDocumentElement(); }
From source file:org.wso2.carbon.governance.api.generic.GenericArtifactManager.java
/** * Creates a new artifact from the given string content. * * @param omContent the artifact content in string * * @return the artifact added.//from w ww.j ava 2s. c om * @throws GovernanceException if the operation failed. */ public GenericArtifact newGovernanceArtifact(String omContent) throws GovernanceException { XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_COALESCING, true); try { XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(omContent)); GenericArtifact artifact = this.newGovernanceArtifact(new StAXOMBuilder(reader).getDocumentElement()); artifact.setContent(omContent.getBytes()); return artifact; } catch (XMLStreamException e) { String message = "Error in creating the content from the parameters."; log.error(message, e); throw new GovernanceException(message, e); } }
From source file:org.wso2.carbon.governance.api.util.GovernanceUtils.java
/** * Method to build an AXIOM element from a byte stream. * * @param content the stream of bytes./* w ww . java 2s .c o m*/ * @return the AXIOM element. * @throws GovernanceException if the operation failed. */ public static OMElement buildOMElement(byte[] content) throws RegistryException { XMLStreamReader parser; try { XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_COALESCING, new Boolean(true)); parser = factory.createXMLStreamReader(new StringReader(RegistryUtils.decodeBytes(content))); } catch (XMLStreamException e) { String msg = "Error in initializing the parser to build the OMElement."; log.error(msg, e); throw new GovernanceException(msg, e); } //create the builder StAXOMBuilder builder = new StAXOMBuilder(parser); //get the root element (in this case the envelope) return builder.getDocumentElement(); }