View Javadoc

1   package wise2.converter;
2   
3   import java.io.File;
4   import java.io.FileOutputStream;
5   import java.io.IOException;
6   import java.io.OutputStream;
7   import java.net.MalformedURLException;
8   import java.net.URL;
9   import java.util.zip.ZipFile;
10  
11  import net.sf.sail.core.util.BinaryUtils;
12  
13  import org.dom4j.DocumentException;
14  
15  public class OnlineProjectConverter {
16  
17  	/***
18  	 * @param args
19  	 * @throws Exception
20  	 */
21  	public static void main(String[] args) throws Exception {
22  		String host = args[0];
23  		int projectID = Integer.parseInt(args[1]);
24  
25  		URL wobnitUrl = projectDumpUrl(host, projectID);
26  		System.out.println("source url: " + wobnitUrl);
27  		File outPath = new File("target/converted-" + host + "-" + projectID
28  				+ ".jar");
29  		FileOutputStream fileOutputStream = new FileOutputStream(outPath);
30  		convertWobnitToCurnit(wobnitUrl, fileOutputStream);
31  		System.out.println("written to " + outPath.getAbsolutePath());
32  		System.exit(0);
33  	}
34  
35  	public static void convertWobnitToCurnit(URL wobnitUrl,
36  			OutputStream curnitOutputStream) throws IOException {
37  		File wobnitArchiveFile = BinaryUtils.tempFileForUrl(wobnitUrl);
38  		System.out.println("loading from " + wobnitArchiveFile);
39  		ProjectConverter pc;
40  		try {
41  			pc = new ProjectConverter(new ZipFile(wobnitArchiveFile));
42  		} catch (DocumentException e) {
43  			// TODO Auto-generated catch block
44  			e.printStackTrace();
45  			throw new IOException("Error converting wobnit: " + e);
46  		}
47  		String omitValue = System.getProperty("org.telscenter.omit.unconverted");
48  		
49  		boolean omit = false;
50  		if( omitValue != null)
51  		omit = omitValue.toLowerCase().equals("true");
52  		
53  		pc.setOmitUnsupportedSteps(omit);
54  		pc.writeCurnit(curnitOutputStream);
55  	}
56  
57  	public static URL projectDumpUrl(String host, int projectID) {
58  		String path = "/project/export/id/" + projectID;
59  		try {
60  			URL url = new URL("http", host, 80, path);
61  			return url;
62  		} catch (MalformedURLException e) {
63  			// should never happen
64  			e.printStackTrace();
65  			throw new RuntimeException(e);
66  		}
67  	}
68  
69  }