Project

General

Profile

« Previous | Next » 

Revision 59

Added by Matt Jones about 24 years ago

further work on XML docuemnt loading facility in the MetaCatServlet

View differences:

MetaCatServlet.java
14 14
import java.io.IOException;
15 15
import java.io.Reader;
16 16
import java.io.StringReader;
17
import java.io.BufferedReader;
17 18
import java.util.Enumeration;
18 19
import java.util.Hashtable;
19 20
import java.net.URL;
......
87 88
  public void doGet (HttpServletRequest request, HttpServletResponse response)
88 89
    throws ServletException, IOException {
89 90

  
90
    // Get the parameters from the form
91
    String querystring = request.getQueryString();
92
    Hashtable params = HttpUtils.parseQueryString(querystring);
93

  
94 91
    // Process the data and send back the response
95
    handleGetOrPost(response, params);
92
    handleGetOrPost(request, response);
96 93
  }
97 94

  
98 95
  /** Handle "POST" method requests from HTTP clients */
99 96
  public void doPost( HttpServletRequest request, HttpServletResponse response)
100 97
    throws ServletException, IOException {
101 98

  
102
    // Get the input data from the client
103
    ServletInputStream in = request.getInputStream();
104
    int len = request.getContentLength();
105

  
106
    // Parse the input data into a Hashtable
107
    Hashtable params = HttpUtils.parsePostData(len, in);
108

  
109 99
    // Process the data and send back the response
110
    handleGetOrPost(response, params);
100
    handleGetOrPost(request, response);
111 101
  }
112 102

  
113 103
  /**
114 104
   * Control servlet response depending on the action parameter specified
115 105
   */
116
  private void handleGetOrPost(HttpServletResponse response, Hashtable params) 
106
  private void handleGetOrPost(HttpServletRequest request, 
107
    HttpServletResponse response) 
117 108
    throws ServletException, IOException {
118 109

  
119 110
    // Get a handle to the output stream back to the client
120 111
    PrintWriter out = response.getWriter();
121 112
  
113
    String name = null;
114
    String[] value = null;
115
    Hashtable params = new Hashtable();
116
    Enumeration paramlist = request.getParameterNames();
117
    while (paramlist.hasMoreElements()) {
118
      name = (String)paramlist.nextElement();
119
      value = request.getParameterValues(name);
120
      params.put(name,value);
121
    }
122

  
122 123
    String action = ((String[])params.get("action"))[0];
123 124

  
124 125
    if (action.equals("query")) {
......
203 204
   */
204 205
  private void handlePutDocumentAction(PrintWriter out, Hashtable params, 
205 206
               HttpServletResponse response) {
207

  
206 208
      // Get the document indicated
207
      String doctext = ((String[])params.get("doctext"))[0]; 
208
      StringReader xml = new StringReader(doctext);
209
      String[] doctext = (String[])params.get("doctext");
210
      StringReader xml = new StringReader(doctext[0]);
211

  
212
      // write the document to the database
209 213
      try {
210
        DBSAXWriter dbw = new DBSAXWriter(doctext, conn);
214
        DBSAXWriter dbw = new DBSAXWriter(xml, conn);
211 215
      } catch (SQLException e1) {
212
          out.println("Error loading document:<p>\n" + e1.getMessage());
216
          out.println("Error 1 loading document:<p>\n" + e1.getMessage());
213 217
      }catch (IOException e2) {
214
          out.println("Error loading document:<p>\n" + e2.getMessage());
218
          out.println("Error 2 loading document:<p>\n" + e2.getMessage());
215 219
      }catch (ClassNotFoundException e3) {
216
          out.println("Error loading document:<p>\n" + e3.getMessage());
220
          out.println("Error 3 loading document:<p>\n" + e3.getMessage());
217 221
      }
218
      //String doc = docreader.readXMLDocument((new Long(docid)).longValue());
219 222

  
220 223
      // set content type and other response header fields first
221
      response.setContentType("text/html");
224
      response.setContentType("text/xml");
222 225
  
223
      out.println("Finished loading document.");
226
      out.println(doctext[0]);
224 227
  }
225 228
}

Also available in: Unified diff