1
2
3
4
5
6
7 package org.utgenome.gwt.utgb.server.app;
8
9 import java.io.IOException;
10 import java.io.PrintWriter;
11 import java.io.StringReader;
12 import java.text.SimpleDateFormat;
13 import java.util.Date;
14
15 import javax.servlet.ServletException;
16 import javax.servlet.http.HttpServletRequest;
17 import javax.servlet.http.HttpServletResponse;
18
19 import org.utgenome.config.OldViewXML;
20 import org.utgenome.gwt.utgb.client.view.TrackView;
21 import org.utgenome.gwt.utgb.server.WebTrackBase;
22 import org.xerial.core.XerialException;
23 import org.xerial.lens.SilkLens;
24 import org.xerial.lens.XMLLens;
25 import org.xerial.util.log.Logger;
26
27
28
29
30
31 public class EchoBackView extends WebTrackBase {
32 private static final long serialVersionUID = 1L;
33 private static Logger _logger = Logger.getLogger(EchoBackView.class);
34
35 private String view;
36 private long time = new Date().getTime();
37
38 public EchoBackView() {
39 }
40
41 @Override
42 public void handle(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
43
44 SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd-HHmmss");
45 String timeStamp = formatter.format(new Date(time));
46 String fileName = "utgb-view-" + timeStamp + ".silk";
47 response.setContentType("application/octet-stream");
48 response.addHeader("Content-disposition", "attachment; filename=\"" + fileName + "\"");
49
50 try {
51
52 OldViewXML viewXML = XMLLens.loadXML(OldViewXML.class, new StringReader(view));
53 TrackView tv = viewXML.toTrackView();
54
55 PrintWriter writer = response.getWriter();
56 writer.append(SilkLens.toSilk(tv));
57 writer.flush();
58 }
59 catch (XerialException e) {
60 _logger.error(e);
61 }
62 }
63
64 public void setView(String view) {
65 this.view = view;
66 }
67
68 public void setTime(long time) {
69 this.time = time;
70 }
71
72 }