View Javadoc

1   package org.molwind.servlet;
2   /*
3    * This file is part of Molwind.
4    *
5    * Molwind is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    *
10   * Molwind is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with Molwind. If not, see <http://www.gnu.org/licenses/>.
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   *Abstract Command is n abtract implementation of 
29   *
30   *
31   *
32   *
33   */
34  
35  public abstract class AbstractCommand implements Command{
36  
37     
38      /**
39       *Constructs an Xml-Document from the Array und puts to the HttpServletResponse
40       *    
41       * @param response
42       *     HttpServletResponse to be written
43       * @param array
44       *     String [] with the information to be put
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 }