/** * Write the specified WSDL definition to the specified Writer. * * @param wsdlDef the WSDL definition to be written. * @param sink the Writer to write the xml to. */ public void writeWSDL(Definition wsdlDef, Writer sink) throws WSDLException { String encoding = null; try { TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); // Unless a width is set, there will be only line breaks but no indentation. // The IBM JDK and the Sun JDK don't agree on the property name, // so we set them both. // transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "2"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); if (encoding != null) { transformer.setOutputProperty(OutputKeys.ENCODING, encoding); } Document document = ((DefinitionImpl) wsdlDef).getDocument(); if (document == null) { ((DefinitionImpl) wsdlDef).updateElement(true); document = ((DefinitionImpl) wsdlDef).getDocument(); } transformer.transform(new DOMSource(document), new StreamResult(sink)); } catch (TransformerException exception) { throw new WSDLException(WSDLException.OTHER_ERROR, "Failed to save Definitions.", exception); } }
/* * Writes the wsdl definition to the file at the given path, relative to the target folder. */ private String writeXMLObj(IPath path, Definition definition, IProgressMonitor monitor) throws WSDLException, URIException, IOException, CoreException { String[] targetURI = appendPathToURI(targetFolderURI, path); OutputStream os = uriFactory.newURI(targetURI[0]).getOutputStream(); DefinitionImpl definitionImpl = (DefinitionImpl) definition; WSDLResourceImpl resource = (WSDLResourceImpl) definitionImpl.eResource(); Document document = definitionImpl.getDocument(); resource.serialize(os, document, document.getXmlEncoding()); os.close(); return targetURI[1]; }