Search in sources :

Example 11 with FileWriterUtil

use of org.apache.cxf.tools.util.FileWriterUtil in project cxf by apache.

the class XSDToWSDLProcessor method getOutputWriter.

private Writer getOutputWriter() throws ToolException {
    Writer writer = null;
    String newName = null;
    String outputDir;
    if (env.get(ToolConstants.CFG_OUTPUTFILE) != null) {
        newName = (String) env.get(ToolConstants.CFG_OUTPUTFILE);
    } else {
        String oldName = (String) env.get(ToolConstants.CFG_XSDURL);
        int position = oldName.lastIndexOf("/");
        if (position < 0) {
            position = oldName.lastIndexOf("\\");
        }
        if (position >= 0) {
            oldName = oldName.substring(position + 1, oldName.length());
        }
        if (oldName.toLowerCase().indexOf(XSD_FILE_NAME_EXT) >= 0) {
            newName = oldName.substring(0, oldName.length() - 4) + WSDL_FILE_NAME_EXT;
        } else {
            newName = oldName + WSDL_FILE_NAME_EXT;
        }
    }
    if (env.get(ToolConstants.CFG_OUTPUTDIR) != null) {
        outputDir = (String) env.get(ToolConstants.CFG_OUTPUTDIR);
        if (!("/".equals(outputDir.substring(outputDir.length() - 1)) || "\\".equals(outputDir.substring(outputDir.length() - 1)))) {
            outputDir = outputDir + "/";
        }
    } else {
        outputDir = "./";
    }
    FileWriterUtil fw = new FileWriterUtil(outputDir, env.get(OutputStreamCreator.class));
    try {
        writer = fw.getWriter("", newName);
    } catch (IOException ioe) {
        Message msg = new Message("FAIL_TO_WRITE_FILE", LOG, env.get(ToolConstants.CFG_OUTPUTDIR) + System.getProperty("file.seperator") + newName);
        throw new ToolException(msg, ioe);
    }
    return writer;
}
Also used : Message(org.apache.cxf.common.i18n.Message) FileWriterUtil(org.apache.cxf.tools.util.FileWriterUtil) OutputStreamCreator(org.apache.cxf.tools.util.OutputStreamCreator) IOException(java.io.IOException) ToolException(org.apache.cxf.tools.common.ToolException) WSDLWriter(javax.wsdl.xml.WSDLWriter) Writer(java.io.Writer)

Aggregations

FileWriterUtil (org.apache.cxf.tools.util.FileWriterUtil)11 Writer (java.io.Writer)8 IOException (java.io.IOException)6 File (java.io.File)5 Message (org.apache.cxf.common.i18n.Message)5 ToolException (org.apache.cxf.tools.common.ToolException)5 WSDLWriter (javax.wsdl.xml.WSDLWriter)4 OutputStreamCreator (org.apache.cxf.tools.util.OutputStreamCreator)4 BufferedOutputStream (java.io.BufferedOutputStream)2 OutputStream (java.io.OutputStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Definition (javax.wsdl.Definition)2 ToolContext (org.apache.cxf.tools.common.ToolContext)2 VelocityGenerator (org.apache.cxf.tools.common.VelocityGenerator)2 Test (org.junit.Test)2 Element (org.w3c.dom.Element)2 FileNotFoundException (java.io.FileNotFoundException)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1