1 package org.molwind.servlet;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 import java.io.IOException;
19
20
21 import org.jdom.*;
22 import org.jdom.output.XMLOutputter;
23 import org.jdom.output.Format;
24 import java.io.*;
25 import javax.servlet.http.HttpServletResponse;
26
27
28
29
30
31
32
33
34
35 public abstract class AbstractCommand implements Command{
36
37
38
39
40
41
42
43
44
45
46
47
48 public void writeXML(HttpServletResponse response,String[] array){
49
50 response.setContentType("text/xml");
51 Element root = new Element("molwind");
52 Element params = new Element("params");
53 Format format = Format.getPrettyFormat();
54
55
56
57
58 XMLOutputter out = new XMLOutputter(format);
59
60
61
62 int i=1;
63
64
65
66 for(String s:array){
67
68 Element param = new Element("param");
69 param.setAttribute("index",String.valueOf(i));
70 param.setText(s);
71
72 params.addContent(param);
73 i++;
74
75
76 }
77
78
79
80
81 root.addContent(params);
82 try{
83 Document doc = new Document(root);
84 out.output(doc,response.getWriter());
85 }catch(IOException e){
86 e.printStackTrace();
87 }
88
89
90 }
91 public void writeXML(OutputStream response,String[] array){
92
93 Element root = new Element("molwind");
94 Element params = new Element("params");
95 Format format = Format.getPrettyFormat();
96
97 XMLOutputter out = new XMLOutputter(format);
98
99 int i = 1;
100
101 for(String s:array){
102 Element param = new Element("param");
103 param.setAttribute("index",String.valueOf(i));
104 param.setText(s);
105
106 params.addContent(param);
107 i++;
108 }
109 root.addContent(params);
110 try{
111 Document doc = new Document(root);
112 out.output(doc,response);
113 }catch(IOException e){
114 e.printStackTrace();
115 }
116
117
118 }
119
120 }