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;
}
Aggregations