List of usage examples for javax.xml.stream XMLOutputFactory newInstance
public static XMLOutputFactory newInstance() throws FactoryConfigurationError
From source file:org.wso2.carbon.registry.lifecycle.test.server.mgt.RegistryConfiguratorTestCase.java
private void increaseConnectionTimeoutValue() throws Exception { FileOutputStream fileOutputStream = null; XMLStreamWriter writer = null; OMElement documentElement = getAxis2XmlOmElement(); try {/*from w w w .j ava 2 s . c o m*/ AXIOMXPath xpathExpression = new AXIOMXPath("/axisconfig/transportSender/parameter"); List<OMElement> nodes = xpathExpression.selectNodes(documentElement); for (OMElement node : nodes) { if (node.getAttributeValue(new QName("name")).equals("SO_TIMEOUT")) { node.setText("240000"); } if (node.getAttributeValue(new QName("name")).equals("CONNECTION_TIMEOUT")) { node.setText("240000"); } } fileOutputStream = new FileOutputStream(getAxis2XMLPath()); writer = XMLOutputFactory.newInstance().createXMLStreamWriter(fileOutputStream); documentElement.serialize(writer); documentElement.build(); Thread.sleep(2000); } catch (Exception e) { log.error("axis2_client.xml edit fails" + e.getMessage()); throw new Exception("axis2_client.xml edit fails" + e.getMessage()); } finally { assert fileOutputStream != null; fileOutputStream.close(); assert writer != null; writer.flush(); } }
From source file:org.wso2.carbon.registry.scm.test.SvnTestCase.java
private void addScmConfiguration() throws Exception { FileOutputStream fileOutputStream = null; XMLStreamWriter writer = null; try {// w w w . j a v a2s . co m OMElement regConfig = getRegistryXmlOmElement(); File checkOutDir = new File(getTempLocation()); String scmConfig = "<scm>" + " <connection checkOutURL=\"scm:svn:https://svn.wso2.org/repos/wso2/carbon/" + "platform/trunk/platform-integration/platform-automated-test-suite/" + "org.wso2.carbon.automation.test.repo/src/main/resources/artifacts/GREG/" + "policy\" workingDir=\"" + getTempLocation() + "\" mountPoint=\"/_system/" + "governance/policy\" checkInURL=\"\" readOnly=\"\" updateFrequency=\"1\">" + " <username>anonymoususer</username>" + " <password>anonymoususer123</password>" + " </connection>" + " </scm>"; OMElement scmConfigOMElement = AXIOMUtil.stringToOM(scmConfig); scmConfigOMElement.build(); regConfig.addChild(scmConfigOMElement); fileOutputStream = new FileOutputStream(getRegistryXMLPath()); writer = XMLOutputFactory.newInstance().createXMLStreamWriter(fileOutputStream); regConfig.serialize(writer); regConfig.build(); isSCMConfigAdded = true; if (!checkOutDir.exists()) { checkOutDir.mkdir(); } Thread.sleep(2000); } catch (Exception e) { log.error("registry.xml edit fails" + e.getMessage()); throw new Exception("registry.xml edit fails" + e.getMessage()); } finally { assert fileOutputStream != null; assert writer != null; writer.flush(); writer.close(); fileOutputStream.close(); } }
From source file:org.wso2.carbon.registry.scm.test.SvnTestCase.java
private void removeScmConfiguration() throws Exception { FileOutputStream fileOutputStream = null; XMLStreamWriter writer = null; try {//from w w w . j av a2s . co m OMElement regConfig = RegistryConfiguratorTestCase.getRegistryXmlOmElement(); regConfig.getFirstChildWithName(new QName("scm")).discard(); fileOutputStream = new FileOutputStream(getRegistryXMLPath()); writer = XMLOutputFactory.newInstance().createXMLStreamWriter(fileOutputStream); regConfig.serialize(writer); regConfig.build(); Thread.sleep(2000); } catch (Exception e) { log.error("registry.xml edit fails" + e.getMessage()); throw new Exception("registry.xml edit fails" + e.getMessage()); } finally { assert fileOutputStream != null; assert writer != null; writer.flush(); writer.close(); fileOutputStream.close(); } }
From source file:org.wso2.carbon.registry.server.mgt.RegistryConfiguratorTestCase.java
private void increaseSearchIndexStartTimeDelay() throws Exception { FileOutputStream fileOutputStream = null; XMLStreamWriter writer = null; OMElement documentElement = getRegistryXmlOmElement(); try {/*from w w w .j a va2 s .c om*/ AXIOMXPath xpathExpression = new AXIOMXPath( "/wso2registry/indexingConfiguration/startingDelayInSeconds"); OMElement indexConfigNode = (OMElement) xpathExpression.selectSingleNode(documentElement); indexConfigNode.setText("30"); AXIOMXPath xpathExpression1 = new AXIOMXPath( "/wso2registry/indexingConfiguration/indexingFrequencyInSeconds"); OMElement indexConfigNode1 = (OMElement) xpathExpression1.selectSingleNode(documentElement); indexConfigNode1.setText("3"); AXIOMXPath xpathExpression2 = new AXIOMXPath("/wso2registry/indexingConfiguration/batchSize"); OMElement indexConfigNode2 = (OMElement) xpathExpression2.selectSingleNode(documentElement); indexConfigNode2.setText("70"); AXIOMXPath xpathExpression3 = new AXIOMXPath("/wso2registry/indexingConfiguration/indexerPoolSize"); OMElement indexConfigNode3 = (OMElement) xpathExpression3.selectSingleNode(documentElement); indexConfigNode3.setText("50"); fileOutputStream = new FileOutputStream(getRegistryXMLPath()); writer = XMLOutputFactory.newInstance().createXMLStreamWriter(fileOutputStream); documentElement.serialize(writer); documentElement.build(); Thread.sleep(2000); } catch (Exception e) { log.error("registry.xml edit fails" + e.getMessage()); throw new Exception("registry.xml edit fails" + e.getMessage()); } finally { assert fileOutputStream != null; fileOutputStream.close(); assert writer != null; writer.flush(); } }
From source file:org.wso2.carbon.registry.server.mgt.test.RegistryConfiguratorTestCase.java
private void increaseSearchIndexStartTimeDelay() throws Exception { FileOutputStream fileOutputStream = null; XMLStreamWriter writer = null; OMElement documentElement = getRegistryXmlOmElement(); try {//from www.ja v a2s.c o m AXIOMXPath xpathExpression = new AXIOMXPath( "/wso2registry/indexingConfiguration/startingDelayInSeconds"); OMElement indexConfigNode = (OMElement) xpathExpression.selectSingleNode(documentElement); indexConfigNode.setText("60"); AXIOMXPath xpathExpression1 = new AXIOMXPath( "/wso2registry/indexingConfiguration/indexingFrequencyInSeconds"); OMElement indexConfigNode1 = (OMElement) xpathExpression1.selectSingleNode(documentElement); indexConfigNode1.setText("30"); fileOutputStream = new FileOutputStream(getRegistryXMLPath()); writer = XMLOutputFactory.newInstance().createXMLStreamWriter(fileOutputStream); documentElement.serialize(writer); documentElement.build(); Thread.sleep(2000); } catch (Exception e) { log.error("registry.xml edit fails" + e.getMessage()); throw new Exception("registry.xml edit fails" + e.getMessage()); } finally { assert fileOutputStream != null; fileOutputStream.close(); assert writer != null; writer.flush(); } }
From source file:org.wso2.carbon.registry.server.mgt.test.RegistryConfiguratorTestCase.java
/** * This method is used to change sso idp port due to port offsets. * * @throws Exception/*from w ww . java 2 s .c o m*/ */ private void changeSsoIdpPort() throws Exception { FileOutputStream fileOutputStream = null; XMLStreamWriter writer = null; OMElement documentElement = getSsoIdpConfigOmElement(); try { AXIOMXPath xpathExpression = new AXIOMXPath( "/SSOIdentityProviderConfig/ServiceProviders/ServiceProvider"); List nodes = xpathExpression.selectNodes(documentElement); for (Object node : nodes) { OMElement nodeElement = (OMElement) node; AXIOMXPath xPathAssertionConsumerService = new AXIOMXPath("AssertionConsumerService"); OMElement nodeUrlElement = (OMElement) xPathAssertionConsumerService.selectSingleNode(nodeElement); String newURL = nodeUrlElement.getText().replace("9443", "10343"); nodeUrlElement.setText(newURL); } fileOutputStream = new FileOutputStream(getSsoIdpConfigXMLPath()); writer = XMLOutputFactory.newInstance().createXMLStreamWriter(fileOutputStream); documentElement.serialize(writer); documentElement.build(); Thread.sleep(2000); } catch (Exception e) { log.error("sso-idp-config.xml edit fails" + e.getMessage()); throw new Exception("sso-idp-config.xml edit fails" + e.getMessage()); } finally { if (fileOutputStream != null) { fileOutputStream.close(); } if (writer != null) { writer.flush(); } } }
From source file:org.wso2.carbon.registry.synchronization.operation.CheckInCommand.java
private void restoreFromFileSystem(Registry registry, UserInputCallback callback) throws SynchronizationException { sentCount = 0;//w w w . j ava 2 s.c om // we are doing the check-in through a temp file. (so assumed enough spaces are there) File tempFile = null; boolean deleteTempFileFailed = false; XMLStreamWriter xmlWriter = null; Writer writer = null; try { try { tempFile = File.createTempFile(SynchronizationConstants.DUMP_META_FILE_NAME, SynchronizationConstants.META_FILE_EXTENSION); try { writer = new FileWriter(tempFile); // wrap the writer with an xml stream writer xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer); // prepare the dump xml xmlWriter.writeStartDocument(); createMetaElement(xmlWriter, workingLocation, checkInPath, callback); xmlWriter.writeEndDocument(); } finally { try { if (xmlWriter != null) { xmlWriter.close(); } } finally { if (writer != null) { writer.close(); } } } } catch (IOException e) { throw new SynchronizationException(MessageCode.ERROR_IN_CREATING_TEMP_FILE_FOR_DUMP, e); } catch (XMLStreamException e) { throw new SynchronizationException(MessageCode.ERROR_IN_CREATING_XML_STREAM_WRITER, e); } // do the restoring if the file system is actually updated if (updated) { try { Reader reader = null; try { reader = new FileReader(tempFile); registry.restore(checkInPath, reader); } finally { if (reader != null) { reader.close(); } } } catch (IOException e) { throw new SynchronizationException(MessageCode.ERROR_IN_READING_TEMP_FILE_OF_DUMP, e); } catch (RegistryException e) { throw new SynchronizationException(MessageCode.ERROR_IN_RESTORING, e, new String[] { "path: " + checkInPath, "registry url: " + registryUrl, "username: " + username }); } } } finally { if (tempFile != null) { // Our intention here is to delete the temporary file. We are not bothered whether // this operation fails. deleteTempFileFailed = !FileUtils.deleteQuietly(tempFile); } } if (deleteTempFileFailed) { throw new SynchronizationException(MessageCode.ERROR_IN_CLEANING_UP, new String[] { "file path: " + tempFile.getAbsolutePath() }); } if (cleanRegistry && registryUrl == null) { Utils.cleanEmbeddedRegistry(); } }
From source file:org.wso2.carbon.registry.synchronization.Utils.java
private static void addMetadata(String metaFilePath, String fileName, boolean isCollection, String registryPath, String registryUrl, boolean root) throws SynchronizationException { FileWriter writer = null;//from w w w . j av a 2 s . co m File metaDir; File file = new File(metaFilePath); if (file.exists()) { return; } try { metaDir = new File(file.getParent()); metaDir.mkdirs(); file.createNewFile(); writer = new FileWriter(file); XMLOutputFactory xof = XMLOutputFactory.newInstance(); XMLStreamWriter xmlWriter = xof.createXMLStreamWriter(writer); xmlWriter.writeStartElement("resource"); xmlWriter.writeAttribute("name", fileName); xmlWriter.writeAttribute("isCollection", String.valueOf(isCollection)); xmlWriter.writeAttribute("path", registryPath); if (registryUrl != null) { xmlWriter.writeAttribute("registryUrl", registryUrl); } xmlWriter.writeAttribute("status", "added"); xmlWriter.writeEndElement(); xmlWriter.flush(); } catch (Exception e) { throw new SynchronizationException(MessageCode.ERROR_IN_ADDING_METADATA); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { log.error("Failed to close the stream", e); } } } }
From source file:org.wso2.carbon.registry.synchronization.Utils.java
private static void setDelete(String metaFilePath) throws SynchronizationException { File metaFile = new File(metaFilePath); OMElement resourceElement;/* w w w. j a v a 2s . co m*/ FileWriter writer = null; try { resourceElement = new StAXOMBuilder(new FileInputStream(metaFile)).getDocumentElement(); resourceElement.addAttribute("status", "deleted", null); writer = new FileWriter(metaFile); XMLOutputFactory xof = XMLOutputFactory.newInstance(); XMLStreamWriter xmlWriter = xof.createXMLStreamWriter(writer); resourceElement.serialize(xmlWriter); xmlWriter.flush(); } catch (FileNotFoundException e) { throw new SynchronizationException(MessageCode.RESOURCE_NOT_UNDER_REGISTRY_CONTROL); } catch (Exception e) { throw new SynchronizationException(MessageCode.RESOURCE_METADATA_CORRUPTED); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { log.error("Failed to close the stream", e); } } } }
From source file:org.wso2.carbon.reporting.template.core.handler.metadata.AbstractMetaDataHandler.java
private void saveTempfile() { try {// w ww . j a v a2 s . co m File file = new File("metadata.xml"); FileWriter fstream = new FileWriter(file); BufferedWriter out = new BufferedWriter(fstream); XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(out); reportsElement.serialize(writer, true); writer.flush(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } }