Project

General

Profile

« Previous | Next » 

Revision 2570

Added by Matt Jones about 19 years ago

Formatting cleanup, fixed a missing 'private' declaration. Preparing for LSID integration work.

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
46 46
import java.util.Iterator;
47 47
import java.util.PropertyResourceBundle;
48 48
import java.util.Vector;
49
import java.util.regex.PatternSyntaxException;
50 49
import java.util.zip.ZipEntry;
51 50
import java.util.zip.ZipOutputStream;
52 51

  
......
59 58
import javax.servlet.http.HttpServletResponse;
60 59
import javax.servlet.http.HttpSession;
61 60

  
62
import edu.ucsb.nceas.utilities.Options;
63

  
64 61
import org.ecoinformatics.eml.EMLParser;
65 62

  
66 63
import com.oreilly.servlet.multipart.FilePart;
......
68 65
import com.oreilly.servlet.multipart.ParamPart;
69 66
import com.oreilly.servlet.multipart.Part;
70 67

  
68
import edu.ucsb.nceas.utilities.Options;
69

  
71 70
/**
72 71
 * A metadata catalog server implemented as a Java Servlet
73 72
 *
......
214 213
        }
215 214
    }
216 215

  
216
    /**
217
     * Close all db connections from the pool
218
     */
219
    public void destroy()
220
    {
221
        // Close all db connection
222
        System.out.println("Destroying MetacatServlet");
223
        DBConnectionPool.release();
224
    }
217 225

  
226
    /** Handle "GET" method requests from HTTP clients */
227
    public void doGet(HttpServletRequest request, HttpServletResponse response)
228
            throws ServletException, IOException
229
    {
230

  
231
        // Process the data and send back the response
232
        handleGetOrPost(request, response);
233
    }
234

  
235
    /** Handle "POST" method requests from HTTP clients */
236
    public void doPost(HttpServletRequest request, HttpServletResponse response)
237
            throws ServletException, IOException
238
    {
239

  
240
        // Process the data and send back the response
241
        handleGetOrPost(request, response);
242
    }
243

  
218 244
    /**
219 245
     * Index the paths specified in the metacat.properties
220 246
     */
221
    void checkIndexPaths(){
247
    private void checkIndexPaths(){
222 248
        MetaCatUtil.pathsForIndexing
223 249
            = MetaCatUtil.getOptionList(MetaCatUtil.getOption("indexed_paths"));
224

  
250
    
225 251
        if (MetaCatUtil.pathsForIndexing != null) {
226

  
252
    
227 253
            MetaCatUtil.debugMessage("Indexing paths....", 20);
228

  
254
    
229 255
            DBConnection conn = null;
230 256
            int serialNumber = -1;
231 257
            PreparedStatement pstmt = null;
232 258
            PreparedStatement pstmt1 = null;
233 259
            ResultSet rs = null;
234

  
260
    
235 261
            for (int i = 0; i < MetaCatUtil.pathsForIndexing.size(); i++) {
236 262
                MetaCatUtil.formattedDebugMessage("Checking if '"
237 263
                           + (String) MetaCatUtil.pathsForIndexing.elementAt(i)
238 264
                           + "' is indexed.... ",30, false, true);
239

  
265
    
240 266
                try {
241 267
                    //check out DBConnection
242 268
                    conn = DBConnectionPool.
243 269
                        getDBConnection("MetaCatServlet.checkIndexPaths");
244 270
                    serialNumber = conn.getCheckOutSerialNumber();
245

  
271
    
246 272
                    pstmt = conn.prepareStatement(
247 273
                        "SELECT * FROM xml_path_index " + "WHERE path = ?");
248 274
                    pstmt.setString(1, (String) MetaCatUtil.pathsForIndexing
249 275
                                    .elementAt(i));
250

  
276
    
251 277
                    pstmt.execute();
252 278
                    rs = pstmt.getResultSet();
253

  
279
    
254 280
                    if (!rs.next()) {
255 281
                        MetaCatUtil.formattedDebugMessage("not indexed yet.", 30,
256 282
                                                       true, false);
257 283
                        rs.close();
258 284
                        pstmt.close();
259 285
                        conn.increaseUsageCount(1);
260

  
286
    
261 287
                        MetaCatUtil.debugMessage(
262 288
                              "Inserting following path in xml_path_index: "
263 289
                              + (String)MetaCatUtil.pathsForIndexing
264 290
                                                   .elementAt(i), 60);
265

  
291
    
266 292
                        pstmt = conn.prepareStatement("SELECT DISTINCT n.docid, "
267 293
                              + "n.nodedata, n.nodedatanumerical, n.parentnodeid"
268 294
                              + " FROM xml_nodes n, xml_index i WHERE"
......
272 298
                                        pathsForIndexing.elementAt(i));
273 299
                        pstmt.execute();
274 300
                        rs = pstmt.getResultSet();
275

  
301
    
276 302
                        int count = 0;
277 303
                        MetaCatUtil.debugMessage(
278 304
                                       "Executed the select statement for: "
279 305
                                       + (String) MetaCatUtil.pathsForIndexing
280 306
                                         .elementAt(i), 60);
281

  
307
    
282 308
                        try {
283 309
                            while (rs.next()) {
284

  
310
    
285 311
                                String docid = rs.getString(1);
286 312
                                String nodedata = rs.getString(2);
287 313
                                float nodedatanumerical = rs.getFloat(3);
288 314
                                int parentnodeid = rs.getInt(4);
289

  
315
    
290 316
                                if (!nodedata.trim().equals("")) {
291 317
                                    pstmt1 = conn.prepareStatement(
292 318
                                        "INSERT INTO xml_path_index"
293 319
                                        + " (docid, path, nodedata, "
294 320
                                        + "nodedatanumerical, parentnodeid)"
295 321
                                        + " VALUES (?, ?, ?, ?, ?)");
296

  
322
    
297 323
                                    pstmt1.setString(1, docid);
298 324
                                    pstmt1.setString(2, (String) MetaCatUtil.
299 325
                                                pathsForIndexing.elementAt(i));
300 326
                                    pstmt1.setString(3, nodedata);
301 327
                                    pstmt1.setFloat(4, nodedatanumerical);
302 328
                                    pstmt1.setFloat(5, parentnodeid);
303

  
329
    
304 330
                                    pstmt1.execute();
305 331
                                    pstmt1.close();
306

  
332
    
307 333
                                    count++;
308

  
334
    
309 335
                                }
310 336
                            }
311 337
                        }
......
313 339
                            System.out.println("Exception:" + e.getMessage());
314 340
                            e.printStackTrace();
315 341
                        }
316

  
342
    
317 343
                        rs.close();
318 344
                        pstmt.close();
319 345
                        conn.increaseUsageCount(1);
320

  
346
    
321 347
                        MetaCatUtil.debugMessage("Indexed " + count
322 348
                                + " records from xml_nodes for '"
323 349
                                + (String) MetaCatUtil.pathsForIndexing.elementAt(i)
324 350
                                + "'", 20);
325

  
351
    
326 352
                    } else {
327 353
                        MetaCatUtil.formattedDebugMessage("already indexed.", 30,
328 354
                                                       true, false);
329 355
                    }
330

  
356
    
331 357
                    rs.close();
332 358
                    pstmt.close();
333 359
                    conn.increaseUsageCount(1);
334

  
360
    
335 361
                } catch (Exception e) {
336 362
                    MetaCatUtil.debugMessage("error in DocumentImpl.delete: "
337 363
                                             + e.getMessage(), 30);
......
339 365
                    //check in DBonnection
340 366
                    DBConnectionPool.returnDBConnection(conn, serialNumber);
341 367
                }
342

  
343

  
368
    
369
    
344 370
            }
345

  
371
    
346 372
            MetaCatUtil.debugMessage("Path Indexing Completed", 20);
347 373
        }
348 374
    }
349
    /**
350
     * Close all db connections from the pool
351
     */
352
    public void destroy()
353
    {
354
        // Close all db connection
355
        System.out.println("Destroying MetacatServlet");
356
        DBConnectionPool.release();
357
    }
358 375

  
359
    /** Handle "GET" method requests from HTTP clients */
360
    public void doGet(HttpServletRequest request, HttpServletResponse response)
361
            throws ServletException, IOException
362
    {
363 376

  
364
        // Process the data and send back the response
365
        handleGetOrPost(request, response);
366
    }
367

  
368
    /** Handle "POST" method requests from HTTP clients */
369
    public void doPost(HttpServletRequest request, HttpServletResponse response)
370
            throws ServletException, IOException
371
    {
372

  
373
        // Process the data and send back the response
374
        handleGetOrPost(request, response);
375
    }
376

  
377 377
    /**
378 378
     * Control servlet response depending on the action parameter specified
379 379
     */
......
842 842
     * @param response the response object linked to the client
843 843
     * @param conn the database connection
844 844
     */
845
    protected void handleSQuery(PrintWriter out, Hashtable params,
845
    private void handleSQuery(PrintWriter out, Hashtable params,
846 846
            HttpServletResponse response, String user, String[] groups,
847 847
            String sessionid)
848 848
    {
......
863 863
     *            squery.
864 864
     * @param response the response object linked to the client
865 865
     */
866
    protected void handleQuery(PrintWriter out, Hashtable params,
866
    private void handleQuery(PrintWriter out, Hashtable params,
867 867
            HttpServletResponse response, String user, String[] groups,
868 868
            String sessionid)
869 869
    {
......
901 901
        ServletOutputStream out = null;
902 902
        // Zip output stream
903 903
        ZipOutputStream zOut = null;
904
        DocumentImpl docImpls = null;
905 904
        DBQuery queryObj = null;
906 905

  
907 906
        String[] docs = new String[10];

Also available in: Unified diff