Project

General

Profile

« Previous | Next » 

Revision 1360

Added by Jing Tao almost 22 years ago

Merge code from branch monarch.

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
40 40
import java.io.BufferedInputStream;
41 41
import java.util.Enumeration;
42 42
import java.util.Hashtable;
43
import java.util.ResourceBundle; 
43
import java.util.ResourceBundle;
44 44
import java.util.Random;
45 45
import java.util.PropertyResourceBundle;
46 46
import java.net.URL;
......
72 72
 * <p>Valid parameters are:<br>
73 73
 * action=query -- query the values of all elements and attributes
74 74
 *                     and return a result set of nodes<br>
75
 * action=squery -- structured query (see pathquery.dtd)<br> 
75
 * action=squery -- structured query (see pathquery.dtd)<br>
76 76
 * action= -- export a zip format for data packadge<br>
77 77
 * action=read -- read any metadata/data file from Metacat and from Internet<br>
78 78
 * action=insert -- insert an XML document into the database store<br>
......
97 97
 * action=getprincipals -- retrieve a list of principals in XML<br>
98 98
 * datadoc -- data document name (id)<br>
99 99
 * <p>
100
 * The particular combination of parameters that are valid for each 
100
 * The particular combination of parameters that are valid for each
101 101
 * particular action value is quite specific.  This documentation
102 102
 * will be reorganized to reflect this information.
103 103
 */
......
108 108
  private String resultStyleURL = null;
109 109
  private String xmlcatalogfile = null;
110 110
  private String saxparser = null;
111
  private String datafilepath = null; 
111
  private String datafilepath = null;
112 112
  private File dataDirectory = null;
113
  private String servletpath = null; 
114
  private String htmlpath = null; 
113
  private String servletpath = null;
114
  private String htmlpath = null;
115 115
  private PropertyResourceBundle options = null;
116 116
  private MetaCatUtil util = null;
117 117
  private DBConnectionPool connPool = null;
......
123 123
    try {
124 124
      super.init( config );
125 125
      this.config = config;
126
      this.context = config.getServletContext(); 
126
      this.context = config.getServletContext();
127 127
      System.out.println("MetaCatServlet Initialize");
128 128

  
129 129
      util = new MetaCatUtil();
130
      
130

  
131 131
      //initial DBConnection pool
132 132
      connPool = DBConnectionPool.getInstance();
133 133

  
......
153 153
   * Close all db connections from the pool
154 154
   */
155 155
  public void destroy() {
156
      // Close all db connection  
156
      // Close all db connection
157
      System.out.println("Destroying MetacatServlet");
157 158
      connPool.release();
158 159
  }
159 160

  
......
176 177
  /**
177 178
   * Control servlet response depending on the action parameter specified
178 179
   */
179
  private void handleGetOrPost(HttpServletRequest request, 
180
                               HttpServletResponse response) 
181
                               throws ServletException, IOException 
180
  private void handleGetOrPost(HttpServletRequest request,
181
                               HttpServletResponse response)
182
                               throws ServletException, IOException
182 183
  {
183 184

  
184 185
    if ( util == null ) {
185
        util = new MetaCatUtil(); 
186
        util = new MetaCatUtil();
186 187
    }
187 188
    /*MetaCatUtil.debugMessage("Connection pool size: "
188 189
                                     +connPool.getSizeOfDBConnectionPool(),10);
189 190
    MetaCatUtil.debugMessage("Free DBConnection number: "
190 191
                                  +connPool.getFreeDBConnectionNumber(), 10);*/
191
    //If all DBConnection in the pool are free and DBConnection pool 
192
    //size is greater than initial value, shrink the connection pool 
192
    //If all DBConnection in the pool are free and DBConnection pool
193
    //size is greater than initial value, shrink the connection pool
193 194
    //size to initial value
194 195
    DBConnectionPool.shrinkDBConnectionPoolSize();
195
    
196

  
196 197
    //Debug message to print out the method which have a busy DBConnection
197 198
    connPool.printMethodNameHavingBusyDBConnection();
198
   
199

  
199 200
    String ctype = request.getContentType();
200 201
    if (ctype != null && ctype.startsWith("multipart/form-data")) {
201 202
      handleMultipartForm(request, response);
202 203
    } else {
203
    
204
  
204

  
205

  
205 206
      String name = null;
206 207
      String[] value = null;
207 208
      String[] docid = new String[3];
208 209
      Hashtable params = new Hashtable();
209 210
      Enumeration paramlist = request.getParameterNames();
210
     
211
    
211

  
212

  
212 213
      while (paramlist.hasMoreElements()) {
213
      
214

  
214 215
        name = (String)paramlist.nextElement();
215 216
        value = request.getParameterValues(name);
216
  
217

  
217 218
        // Decode the docid and mouse click information
218 219
        if (name.endsWith(".y")) {
219 220
          docid[0] = name.substring(0,name.length()-2);
......
222 223
        }
223 224
        if (name.endsWith(".x")) {
224 225
          name = "xpos";
225
        } 
226
  
227
        params.put(name,value); 
228
      }  
229
      
230
    
226
        }
227

  
228
        params.put(name,value);
229
      }
230

  
231

  
231 232
      //handle param is emptpy
232 233
      if (params.isEmpty() || params == null)
233 234
      {
......
235 236
      }
236 237
      //if the user clicked on the input images, decode which image
237 238
      //was clicked then set the action.
238
      String action = ((String[])params.get("action"))[0];  
239
      String action = ((String[])params.get("action"))[0];
239 240
      util.debugMessage("Line 230: Action is: " + action, 1);
240
  
241

  
241 242
      // This block handles session management for the servlet
242 243
      // by looking up the current session information for all actions
243 244
      // other than "login" and "logout"
......
245 246
      String password = null;
246 247
      String[] groupnames = null;
247 248
      String sess_id = null;
248
  
249

  
249 250
      // handle login action
250 251
      if (action.equals("login")) {
251 252
        PrintWriter out = response.getWriter();
252 253
        handleLoginAction(out, params, request, response);
253 254
        out.close();
254
  
255
      // handle logout action  
255

  
256
      // handle logout action
256 257
      } else if (action.equals("logout")) {
257 258
        PrintWriter out = response.getWriter();
258 259
        handleLogoutAction(out, params, request, response);
259 260
        out.close();
260
        
261

  
261 262
      // handle shrink DBConnection request
262 263
      } else if (action.equals("shrink")) {
263 264
        PrintWriter out = response.getWriter();
264 265
        boolean success = false;
265
        //If all DBConnection in the pool are free and DBConnection pool 
266
        //size is greater than initial value, shrink the connection pool 
266
        //If all DBConnection in the pool are free and DBConnection pool
267
        //size is greater than initial value, shrink the connection pool
267 268
        //size to initial value
268 269
        success = DBConnectionPool.shrinkConnectionPoolSize();
269 270
        if (success)
......
277 278
        }
278 279
       //close out put
279 280
        out.close();
280
      
281
      // aware of session expiration on every request  
282
      } else {   
283
  
281

  
282
      // aware of session expiration on every request
283
      } else {
284

  
284 285
        HttpSession sess = request.getSession(true);
285
        if (sess.isNew()) { 
286
        if (sess.isNew()) {
286 287
          // session expired or has not been stored b/w user requests
287 288
          username = "public";
288 289
          sess.setAttribute("username", username);
......
294 295
            sess_id = (String)sess.getId();
295 296
          } catch(IllegalStateException ise) {
296 297
            System.out.println("error in handleGetOrPost: this shouldn't " +
297
                               "happen: the session should be valid: " + 
298
                               "happen: the session should be valid: " +
298 299
                               ise.getMessage());
299 300
          }
300
        }  
301
      }    
302
  
301
        }
302
      }
303

  
303 304
       // Now that we know the session is valid, we can delegate the request
304 305
      // to a particular action handler
305 306
      if(action.equals("query")) {
......
316 317
          out.close();
317 318
        }
318 319
      } else if (action.equals("export")) {
319
        
320

  
320 321
        handleExportAction(params, response, username, groupnames, password);
321 322
      } else if (action.equals("read")) {
322 323
        handleReadAction(params, response, username,password, groupnames);
......
324 325
        PrintWriter out = response.getWriter();
325 326
        if ( (username != null) &&  !username.equals("public") ) {
326 327
          handleInsertOrUpdateAction(out,params,response,username,groupnames);
327
        } else {  
328
        } else {
328 329
          out.println("Permission denied for " + action);
329 330
        }
330 331
        out.close();
......
332 333
        PrintWriter out = response.getWriter();
333 334
        if ( (username != null) &&  !username.equals("public") ) {
334 335
          handleDeleteAction(out, params, response, username, groupnames);
335
        } else {  
336
        } else {
336 337
          out.println("Permission denied for " + action);
337 338
        }
338 339
        out.close();
......
418 419
        out.println("</error>");
419 420
        out.close();
420 421
      }
421
      
422

  
422 423
      //util.closeConnections();
423 424
      // Close the stream to the client
424 425
      //out.close();
425 426
    }
426 427
  }
427
  
428

  
428 429
  // LOGIN & LOGOUT SECTION
429
  /** 
430
  /**
430 431
   * Handle the login request. Create a new session object.
431 432
   * Do user authentication through the session.
432 433
   */
433
  private void handleLoginAction(PrintWriter out, Hashtable params, 
434
  private void handleLoginAction(PrintWriter out, Hashtable params,
434 435
               HttpServletRequest request, HttpServletResponse response) {
435 436

  
436 437
    AuthSession sess = null;
......
438 439
    String pw = ((String[])params.get("password"))[0];
439 440
    String action = ((String[])params.get("action"))[0];
440 441
    String qformat = ((String[])params.get("qformat"))[0];
441
    
442

  
442 443
    try {
443 444
      sess = new AuthSession();
444 445
    } catch (Exception e) {
......
451 452
    // format and transform the output
452 453
    if (qformat.equals("xml")) {
453 454
      response.setContentType("text/xml");
454
      out.println(sess.getMessage()); 
455
      out.println(sess.getMessage());
455 456
    } else {
456
     
457

  
457 458
      try {
458
        
459

  
459 460
        DBTransform trans = new DBTransform();
460 461
        response.setContentType("text/html");
461 462
        trans.transformXMLDocument(sess.getMessage(), "-//NCEAS//login//EN",
462 463
                                   "-//W3C//HTML//EN", qformat, out);
463
         
464

  
464 465
      } catch(Exception e) {
465
        
466

  
466 467
        MetaCatUtil.debugMessage("Error in MetaCatServlet.handleLoginAction: "
467 468
                                +e.getMessage(), 30);
468
      } 
469
      
470
    // any output is returned  
469
      }
470

  
471
    // any output is returned
471 472
    }
472
  }    
473
  }
473 474

  
474
  /** 
475
  /**
475 476
   * Handle the logout request. Close the connection.
476 477
   */
477
  private void handleLogoutAction(PrintWriter out, Hashtable params, 
478
  private void handleLogoutAction(PrintWriter out, Hashtable params,
478 479
               HttpServletRequest request, HttpServletResponse response) {
479 480

  
480 481
    String qformat = ((String[])params.get("qformat"))[0];
481 482

  
482 483
    // close the connection
483 484
    HttpSession sess = request.getSession(false);
484
    if (sess != null) { sess.invalidate();  }    
485
    if (sess != null) { sess.invalidate();  }
485 486

  
486 487
    // produce output
487 488
    StringBuffer output = new StringBuffer();
......
493 494
    //format and transform the output
494 495
    if (qformat.equals("xml")) {
495 496
      response.setContentType("text/xml");
496
      out.println(output.toString()); 
497
      out.println(output.toString());
497 498
    } else {
498
      
499

  
499 500
      try {
500
       
501

  
501 502
        DBTransform trans = new DBTransform();
502 503
        response.setContentType("text/html");
503
        trans.transformXMLDocument(output.toString(), "-//NCEAS//login//EN", 
504
        trans.transformXMLDocument(output.toString(), "-//NCEAS//login//EN",
504 505
                                   "-//W3C//HTML//EN", qformat, out);
505
         
506

  
506 507
      } catch(Exception e) {
507
        
508

  
508 509
        MetaCatUtil.debugMessage("Error in MetaCatServlet.handleLogoutAction"
509 510
                                  +e.getMessage(), 30);
510
      } 
511
      }
511 512
    }
512 513
  }
513 514
  // END OF LOGIN & LOGOUT SECTION
514
  
515

  
515 516
  // SQUERY & QUERY SECTION
516
  /**      
517
  /**
517 518
   * Retreive the squery xml, execute it and display it
518 519
   *
519 520
   * @param out the output stream to the client
520 521
   * @param params the Hashtable of parameters that should be included
521 522
   * in the squery.
522 523
   * @param response the response object linked to the client
523
   * @param conn the database connection 
524
   * @param conn the database connection
524 525
   */
525
  protected void handleSQuery(PrintWriter out, Hashtable params, 
526
  protected void handleSQuery(PrintWriter out, Hashtable params,
526 527
                 HttpServletResponse response, String user, String[] groups)
527
  { 
528
  {
528 529
    String xmlquery = ((String[])params.get("query"))[0];
529 530
    String qformat = ((String[])params.get("qformat"))[0];
530 531
    String resultdoc = null;
531 532
    MetaCatUtil.debugMessage("xmlquery: "+xmlquery, 30);
532 533
    double startTime = System.currentTimeMillis()/1000;
533 534
    Hashtable doclist = runQuery(xmlquery, user, groups);
534
    double docListTime = System.currentTimeMillis()/1000; 
535
    double docListTime = System.currentTimeMillis()/1000;
535 536
    MetaCatUtil.debugMessage("Time for getting doc list: "
536 537
                                            +(docListTime-startTime), 30);
537
                                            
538

  
538 539
    resultdoc = createResultDocument(doclist, transformQuery(xmlquery));
539 540
    double toStringTime = System.currentTimeMillis()/1000;
540 541
    MetaCatUtil.debugMessage("Time to create xml string: "
541 542
                              +(toStringTime-docListTime), 30);
542 543
    //format and transform the results
543
    double outPutTime = 0;                                          
544
    double outPutTime = 0;
544 545
    if(qformat.equals("xml")) {
545 546
      response.setContentType("text/xml");
546 547
      out.println(resultdoc);
......
560 561
    * @param params the Hashtable of parameters that should be included
561 562
    * in the squery.
562 563
    * @param response the response object linked to the client
563
    */ 
564
  protected void handleQuery(PrintWriter out, Hashtable params, 
564
    */
565
  protected void handleQuery(PrintWriter out, Hashtable params,
565 566
                 HttpServletResponse response, String user, String[] groups)
566 567
  {
567 568
    //create the query and run it
......
569 570
    Hashtable doclist = runQuery(xmlquery, user, groups);
570 571
    String qformat = ((String[])params.get("qformat"))[0];
571 572
    String resultdoc = null;
572
    
573

  
573 574
    resultdoc = createResultDocument(doclist, transformQuery(params));
574 575

  
575
    //format and transform the results                                        
576
    //format and transform the results
576 577
    if(qformat.equals("xml")) {
577 578
      response.setContentType("text/xml");
578 579
      out.println(resultdoc);
579
    } else { 
580
    } else {
580 581
      transformResultset(resultdoc, response, out, qformat);
581 582
    }
582 583
  }
583
  
584

  
584 585
  /**
585 586
   * Removes the <?xml version="x"?> tag from the beginning of xmlquery
586 587
   * so it can properly be placed in the <query> tag of the resultset.
587 588
   * This method is overwritable so that other applications can customize
588 589
   * the structure of what is in the <query> tag.
589
   * 
590
   *
590 591
   * @param xmlquery is the query to remove the <?xml version="x"?> tag from.
591 592
   */
592 593
  protected String transformQuery(Hashtable params)
593 594
  {
594
    //DBQuery.createSQuery is a re-calling of a previously called 
595
    //DBQuery.createSQuery is a re-calling of a previously called
595 596
    //function but it is necessary
596 597
    //so that overriding methods have access to the params hashtable
597 598
    String xmlquery = DBQuery.createSQuery(params);
......
600 601
    int index = xmlquery.indexOf("?>");
601 602
    return xmlquery.substring(index + 2, xmlquery.length());
602 603
  }
603
  
604

  
604 605
  /**
605 606
   * removes the <?xml version="1.0"?> tag from the beginning.  This takes a
606 607
   * string as a param instead of a hashtable.
607
   * 
608
   *
608 609
   * @param xmlquery a string representing a query.
609 610
   */
610 611
  protected String transformQuery(String xmlquery)
......
613 614
    int index = xmlquery.indexOf("?>");
614 615
    return xmlquery.substring(index + 2, xmlquery.length());
615 616
  }
616
  
617

  
617 618
  /**
618 619
   * Run the query and return a hashtable of results.
619 620
   *
......
622 623
  private Hashtable runQuery(String xmlquery, String user, String[] groups)
623 624
  {
624 625
    Hashtable doclist=null;
625
  
626

  
626 627
    try
627 628
    {
628
    
629

  
629 630
      DBQuery queryobj = new DBQuery(saxparser);
630 631
      doclist = queryobj.findDocuments(new StringReader(xmlquery),user,groups);
631
 
632

  
632 633
      return doclist;
633
    } 
634
    catch (Exception e) 
634
    }
635
    catch (Exception e)
635 636
    {
636
    
637
      MetaCatUtil.debugMessage("Error in MetacatServlet.runQuery: " 
637

  
638
      MetaCatUtil.debugMessage("Error in MetacatServlet.runQuery: "
638 639
                                                      + e.getMessage(), 30);
639 640
      doclist = null;
640 641
      return doclist;
641
    }    
642
    }
642 643
  }
643
  
644

  
644 645
  /**
645 646
   * Transorms an xml resultset document to html and sends it to the browser
646 647
   *
......
649 650
   * @param response the HttpServletResponse object bound to the client.
650 651
   * @param out the output stream to the client
651 652
   * @param qformat the name of the style-set to use for transformations
652
   */ 
653
  protected void transformResultset(String resultdoc, 
653
   */
654
  protected void transformResultset(String resultdoc,
654 655
                                    HttpServletResponse response,
655 656
                                    PrintWriter out, String qformat)
656 657
  {
657
  
658

  
658 659
    try {
659
     
660

  
660 661
      DBTransform trans = new DBTransform();
661 662
      response.setContentType("text/html");
662
      trans.transformXMLDocument(resultdoc, "-//NCEAS//resultset//EN", 
663
      trans.transformXMLDocument(resultdoc, "-//NCEAS//resultset//EN",
663 664
                                 "-//W3C//HTML//EN", qformat, out);
664
     
665

  
665 666
    }
666 667
    catch(Exception e)
667 668
    {
668
      
669

  
669 670
      MetaCatUtil.debugMessage("Error in MetaCatServlet.transformResultset:"
670 671
                                +e.getMessage(), 30);
671
    } 
672
    }
672 673
  }
673
  
674

  
674 675
  /**
675 676
   * Transforms a hashtable of documents to an xml or html result.
676 677
   *
......
681 682
  {
682 683
    // Create a buffer to hold the xml result
683 684
    StringBuffer resultset = new StringBuffer();
684
 
685
    // Print the resulting root nodes 
685

  
686
    // Print the resulting root nodes
686 687
    String docid = null;
687 688
    String document = null;
688 689
    resultset.append("<?xml version=\"1.0\"?>\n");
689 690
    resultset.append("<resultset>\n");
690
      
691
    resultset.append("  <query>" + xmlquery + "</query>");   
692 691

  
692
    resultset.append("  <query>" + xmlquery + "</query>");
693

  
693 694
    if(doclist != null)
694 695
    {
695
      Enumeration doclistkeys = doclist.keys(); 
696
      while (doclistkeys.hasMoreElements()) 
696
      Enumeration doclistkeys = doclist.keys();
697
      while (doclistkeys.hasMoreElements())
697 698
      {
698 699
        docid = (String)doclistkeys.nextElement();
699 700
        document = (String)doclist.get(docid);
......
705 706
    return resultset.toString();
706 707
  }
707 708
  // END OF SQUERY & QUERY SECTION
708
  
709

  
709 710
 //Exoport section
710 711
 /**
711 712
   * Handle the "export" request of data package from Metacat in zip format
......
714 715
   * @param user the username sent the request
715 716
   * @param groups the user's groupnames
716 717
   */
717
  private void handleExportAction(Hashtable params, 
718
  private void handleExportAction(Hashtable params,
718 719
    HttpServletResponse response, String user, String[] groups, String passWord)
719 720
  {
720 721
    // Output stream
......
723 724
    ZipOutputStream zOut = null;
724 725
    DocumentImpl docImpls=null;
725 726
    DBQuery queryObj=null;
726
  
727

  
727 728
    String[] docs = new String[10];
728 729
    String docId = "";
729 730

  
730 731
    try
731 732
    {
732 733
      // read the params
733
      if (params.containsKey("docid")) 
734
      if (params.containsKey("docid"))
734 735
      {
735 736
        docs = (String[])params.get("docid");
736 737
      }//if
......
749 750
        pw.println("<error>");
750 751
        pw.println("You didn't specify requested docid");
751 752
        pw.println("</error>");
752
        // Close printwriter 
753
        // Close printwriter
753 754
        pw.close();
754 755
        return;
755 756
      }//if
......
760 761
      zOut =queryObj.getZippedPackage(docId, out, user, groups, passWord);
761 762
      zOut.finish(); //terminate the zip file
762 763
      zOut.close();  //close the zip stream
763
      
764
    }//try 
764

  
765
    }//try
765 766
    catch (Exception e)
766 767
    {
767 768
      try
......
780 781
            // Close output stream
781 782
            out.close();
782 783
        }//if
783
        // Close zip output stream 
784
        // Close zip output stream
784 785
        if ( zOut != null )
785 786
        {
786 787
          zOut.close();
......
796 797
      MetaCatUtil.debugMessage("Error in MetacatServlet.handleExportAction: " +
797 798
                         e.getMessage(), 30);
798 799
      e.printStackTrace(System.out);
799
      
800

  
800 801
    }//catch
801
 
802

  
802 803
  }//handleExportAction
803
  
804

  
804 805
  // READ SECTION
805
  /** 
806
  /**
806 807
   * Handle the "read" request of metadata/data files from Metacat
807 808
   * or any files from Internet;
808 809
   * transformed metadata XML document into HTML presentation if requested;
......
814 815
   * @param groups the user's groupnames
815 816
   */
816 817
  private void handleReadAction(Hashtable params, HttpServletResponse response,
817
                                String user, String passWord, String[] groups) 
818
                                String user, String passWord, String[] groups)
818 819
  {
819 820
    ServletOutputStream out = null;
820 821
    ZipOutputStream zout = null;
821 822
    PrintWriter pw = null;
822 823
    boolean zip = false;
823
    
824

  
824 825
    try {
825 826
      String[] docs = new String[0];
826 827
      String docid = "";
827 828
      String qformat = "";
828 829
      String abstrpath = null;
829
      
830

  
830 831
      // read the params
831 832
      if (params.containsKey("docid")) {
832 833
        docs = (String[])params.get("docid");
......
853 854

  
854 855
          URL murl = new URL(docs[i]);
855 856
          Hashtable murlQueryStr = util.parseQuery(murl.getQuery());
856
          // case docid="http://.../?docid=aaa" 
857
          // case docid="http://.../?docid=aaa"
857 858
          // or docid="metacat://.../?docid=bbb"
858 859
          if (murlQueryStr.containsKey("docid")) {
859 860
            // get only docid, eliminate the rest
......
885 886
                            user, groups, zip, zout);
886 887
          }
887 888
        }
888
        
889

  
889 890
      } /* end for */
890
      
891

  
891 892
      if ( zip ) {
892 893
        zout.finish(); //terminate the zip file
893 894
        zout.close();  //close the zip stream
894 895
      }
895
      
896
  
896

  
897

  
897 898
    }
898 899
    // To handle doc not found exception
899 900
    catch (McdbDocNotFoundException notFoundE)
......
918 919
        {
919 920
          out.close();
920 921
        }
921
        
922

  
922 923
      }//try
923 924
      catch ( Exception exc)
924 925
      {
......
926 927
                                      exc.getMessage(), 30);
927 928
        try
928 929
        {
929
          if (out != null) 
930
          if (out != null)
930 931
          {
931 932
            response.setContentType("text/xml");
932 933
            // Send back error message by printWriter
......
937 938
            pw.println("</error>");
938 939
            pw.close();
939 940
            out.close();
940
            
941

  
941 942
          }
942 943
          else
943 944
          {
......
955 956
           pw.close();
956 957
        }
957 958
        // close zout
958
        if ( zout != null ) 
959
        { 
960
          zout.close(); 
959
        if ( zout != null )
960
        {
961
          zout.close();
961 962
        }
962 963
        }//try
963 964
        catch (IOException ie)
......
968 969
        }//cathch
969 970
      }//catch
970 971
    }// catch McdbDocNotFoundException
971
    catch (Exception e) 
972
    catch (Exception e)
972 973
    {
973 974
      try {
974
       
975

  
975 976
        if (out != null) {
976 977
            response.setContentType("text/xml"); //MIME type
977 978
            pw = new PrintWriter(out);
......
995 996
           pw.println(e.getMessage());
996 997
           pw.println("</error>");
997 998
           pw.close();
998
          
999

  
999 1000
        }
1000 1001
        // Close zip output stream
1001 1002
        if ( zout != null ) { zout.close(); }
1002
        
1003

  
1003 1004
      } catch (IOException ioe) {
1004 1005
        MetaCatUtil.debugMessage("Problem with the servlet output " +
1005 1006
                           "in MetacatServlet.handleReadAction: " +
1006 1007
                           ioe.getMessage(), 30);
1007 1008
        ioe.printStackTrace(System.out);
1008
        
1009

  
1009 1010
      }
1010 1011

  
1011 1012
      System.out.println("Error in MetacatServlet.handleReadAction: " +
1012 1013
                         e.getMessage());
1013 1014
      e.printStackTrace(System.out);
1014 1015
    }
1015
    
1016

  
1016 1017
  }
1017
  
1018

  
1018 1019
  // read metadata or data from Metacat
1019 1020
  private void readFromMetacat(HttpServletResponse response, String docid,
1020 1021
                               String qformat, String abstrpath, String user,
1021 1022
                             String[] groups, boolean zip, ZipOutputStream zout)
1022
               throws ClassNotFoundException, IOException, SQLException, 
1023
               throws ClassNotFoundException, IOException, SQLException,
1023 1024
                      McdbException, Exception
1024 1025
  {
1025
   
1026

  
1026 1027
    try {
1027
     
1028
      
1028

  
1029

  
1029 1030
      DocumentImpl doc = new DocumentImpl(docid);
1030
    
1031

  
1031 1032
      //check the permission for read
1032 1033
      if (!doc.hasReadPermission(user, groups, docid))
1033 1034
      {
1034 1035
        Exception e = new Exception("User " + user + " does not have permission"
1035 1036
                       +" to read the document with the docid " + docid);
1036
    
1037

  
1037 1038
        throw e;
1038 1039
      }
1039
     
1040

  
1040 1041
      if ( doc.getRootNodeID() == 0 ) {
1041 1042
        // this is data file
1042 1043
        String filepath = util.getOption("datafilepath");
......
1046 1047
        String filename = filepath + docid;
1047 1048
        FileInputStream fin = null;
1048 1049
        fin = new FileInputStream(filename);
1049
        
1050

  
1050 1051
        //MIME type
1051 1052
        String contentType = getServletContext().getMimeType(filename);
1052 1053
        if (contentType == null) {
......
1072 1073
        response.setContentType(contentType);
1073 1074
        // if we decide to use "application/octet-stream" for all data returns
1074 1075
        // response.setContentType("application/octet-stream");
1075
       
1076

  
1076 1077
        try {
1077
          
1078
          ServletOutputStream out = response.getOutputStream(); 
1078

  
1079
          ServletOutputStream out = response.getOutputStream();
1079 1080
          byte[] buf = new byte[4 * 1024]; // 4K buffer
1080 1081
          int b = fin.read(buf);
1081 1082
          while (b != -1) {
......
1088 1089

  
1089 1090
      } else {
1090 1091
        // this is metadata doc
1091
        if ( qformat.equals("xml") ) { 
1092
          
1092
        if ( qformat.equals("xml") ) {
1093

  
1093 1094
          // set content type first
1094 1095
          response.setContentType("text/xml");   //MIME type
1095 1096
          PrintWriter out = response.getWriter();
......
1097 1098
        } else {
1098 1099
          response.setContentType("text/html");  //MIME type
1099 1100
          PrintWriter out = response.getWriter();
1100
    
1101

  
1101 1102
          // Look up the document type
1102 1103
          String doctype = doc.getDoctype();
1103 1104
          // Transform the document to the new doctype
......
1105 1106
          dbt.transformXMLDocument(doc.toString(),
1106 1107
                                   doctype,"-//W3C//HTML//EN", qformat, out);
1107 1108
        }
1108
      
1109

  
1109 1110
      }
1110 1111
    }
1111
    catch (Exception except) 
1112
    catch (Exception except)
1112 1113
    {
1113 1114
      throw except;
1114
    
1115

  
1115 1116
    }
1116
    
1117

  
1117 1118
  }
1118
  
1119

  
1119 1120
  // read data from URLConnection
1120 1121
  private void readFromURLConnection(HttpServletResponse response, String docid)
1121 1122
               throws IOException, MalformedURLException
1122 1123
  {
1123
    ServletOutputStream out = response.getOutputStream(); 
1124
    ServletOutputStream out = response.getOutputStream();
1124 1125
    String contentType = getServletContext().getMimeType(docid); //MIME type
1125 1126
    if (contentType == null) {
1126 1127
      if (docid.endsWith(".xml")) {
......
1160 1161
    } finally {
1161 1162
      if (bis != null) bis.close();
1162 1163
    }
1163
    
1164

  
1164 1165
  }
1165
  
1166

  
1166 1167
  // read file/doc and write to ZipOutputStream
1167
  private void addDocToZip(String docid, ZipOutputStream zout, 
1168
  private void addDocToZip(String docid, ZipOutputStream zout,
1168 1169
                              String user, String[] groups)
1169
               throws ClassNotFoundException, IOException, SQLException, 
1170
               throws ClassNotFoundException, IOException, SQLException,
1170 1171
                      McdbException, Exception
1171 1172
  {
1172 1173
    byte[] bytestring = null;
......
1193 1194
      zout.closeEntry();
1194 1195

  
1195 1196
    } catch (MalformedURLException mue) {
1196
      
1197

  
1197 1198
      // this is metacat doc (data file or metadata doc)
1198
  
1199

  
1199 1200
      try {
1200
       
1201

  
1201 1202
        DocumentImpl doc = new DocumentImpl(docid);
1202
        
1203

  
1203 1204
        //check the permission for read
1204 1205
        if (!doc.hasReadPermission(user, groups, docid))
1205 1206
        {
1206 1207
          Exception e = new Exception("User " + user + " does not have "
1207 1208
                    +"permission to read the document with the docid " + docid);
1208
        
1209

  
1209 1210
          throw e;
1210
        } 
1211
        
1211
        }
1212

  
1212 1213
        if ( doc.getRootNodeID() == 0 ) {
1213 1214
          // this is data file; add file to zip
1214 1215
          String filepath = util.getOption("datafilepath");
......
1219 1220
          FileInputStream fin = null;
1220 1221
          fin = new FileInputStream(filename);
1221 1222
          try {
1222
            
1223

  
1223 1224
            zentry = new ZipEntry(docid);
1224 1225
            zout.putNextEntry(zentry);
1225 1226
            byte[] buf = new byte[4 * 1024]; // 4K buffer
......
1244 1245
        }
1245 1246
      } catch (Exception except) {
1246 1247
        throw except;
1247
       
1248

  
1248 1249
      }
1249
      
1250

  
1250 1251
    }
1251
      
1252

  
1252 1253
  }
1253
  
1254

  
1254 1255
  // view abstract within document
1255 1256
  private void viewAbstract(HttpServletResponse response,
1256 1257
                            String abstractpath, String docid)
1257 1258
               throws ClassNotFoundException, IOException, SQLException,
1258 1259
                      McdbException, Exception
1259 1260
  {
1260
  
1261

  
1261 1262
    PrintWriter out =null;
1262 1263
    try {
1263
   
1264

  
1264 1265
      response.setContentType("text/html");  //MIME type
1265 1266
      out = response.getWriter();
1266 1267
      Object[] abstracts = DBQuery.getNodeContent(abstractpath, docid);
......
1276 1277
       out.println("<error>");
1277 1278
       out.println(e.getMessage());
1278 1279
       out.println("</error>");
1279
    
1280
   
1280

  
1281

  
1281 1282
    }
1282 1283
  }
1283 1284
  /**
1284 1285
   * If metacat couldn't find a data file or document locally, it will read this
1285 1286
   * docid from its home server. This is for the replication feature
1286 1287
   */
1287
  private void readFromRemoteMetaCat(HttpServletResponse response, String docid, 
1288
                     String rev, String user, String password, 
1288
  private void readFromRemoteMetaCat(HttpServletResponse response, String docid,
1289
                     String rev, String user, String password,
1289 1290
                     ServletOutputStream out, boolean zip, ZipOutputStream zout)
1290 1291
                        throws Exception
1291 1292
 {
1292 1293
   // Create a object of RemoteDocument, "" is for zipEntryPath
1293
   RemoteDocument remoteDoc = 
1294
   RemoteDocument remoteDoc =
1294 1295
                        new RemoteDocument (docid, rev,user, password, "");
1295 1296
   String docType = remoteDoc.getDocType();
1296 1297
   // Only read data file
......
1300 1301
    if (zip)
1301 1302
    {
1302 1303
      remoteDoc.readDocumentFromRemoteServerByZip(zout);
1303
    }//if 
1304
    }//if
1304 1305
    else
1305 1306
    {
1306 1307
      if (out == null)
......
1310 1311
      response.setContentType("application/octet-stream");
1311 1312
      remoteDoc.readDocumentFromRemoteServer(out);
1312 1313
    }//else (not zip)
1313
   }//if doctype=bin 
1314
   }//if doctype=bin
1314 1315
   else
1315 1316
   {
1316 1317
     throw new Exception("Docid: "+docid+"."+rev+" couldn't find");
1317
   }//else                 
1318
   }//else
1318 1319
 }//readFromRemoteMetaCat
1319
  
1320

  
1320 1321
  // END OF READ SECTION
1321
    
1322

  
1322 1323
  // INSERT/UPDATE SECTION
1323
  /** 
1324
   * Handle the database putdocument request and write an XML document 
1324
  /**
1325
   * Handle the database putdocument request and write an XML document
1325 1326
   * to the database connection
1326 1327
   */
1327
  private void handleInsertOrUpdateAction(PrintWriter out, Hashtable params, 
1328
  private void handleInsertOrUpdateAction(PrintWriter out, Hashtable params,
1328 1329
               HttpServletResponse response, String user, String[] groups) {
1329 1330

  
1330 1331
    DBConnection dbConn = null;
......
1348 1349
          }
1349 1350
        } catch (NullPointerException npe) {}
1350 1351
      }
1351
      
1352

  
1352 1353
      StringReader xml = null;
1353 1354
      boolean validate = false;
1354 1355
      try {
1355
        // look inside XML Document for <!DOCTYPE ... PUBLIC/SYSTEM ... > 
1356
        // look inside XML Document for <!DOCTYPE ... PUBLIC/SYSTEM ... >
1356 1357
        // in order to decide whether to use validation parser
1357 1358
        validate = validateXML(doctext[0]);
1358 1359
        xml = new StringReader(doctext[0]);
......
1367 1368
        } else if (action[0].equals("update")) {
1368 1369
          doAction = "UPDATE";
1369 1370
        }
1370
        
1371
        try 
1371

  
1372
        try
1372 1373
        {
1373 1374
          // get a connection from the pool
1374 1375
          dbConn=DBConnectionPool.
1375 1376
                  getDBConnection("MetaCatServlet.handleInsertOrUpdateAction");
1376 1377
          serialNumber=dbConn.getCheckOutSerialNumber();
1377
          
1378
          
1378

  
1379

  
1379 1380
          // write the document to the database
1380
          try 
1381
          try
1381 1382
          {
1382 1383
            String accNumber = docid[0];
1383 1384
            MetaCatUtil.debugMessage(""+ doAction + " " + accNumber +"...", 10);
1384
            if (accNumber.equals("")) 
1385
            if (accNumber.equals(""))
1385 1386
            {
1386 1387
              accNumber = null;
1387 1388
            }//if
1388 1389
            newdocid = DocumentImpl.write(dbConn, xml, pub, dtd, doAction,
1389 1390
                                          accNumber, user, groups, validate);
1390
            
1391
          }//try 
1392
          catch (NullPointerException npe) 
1391

  
1392
          }//try
1393
          catch (NullPointerException npe)
1393 1394
          {
1394 1395
            newdocid = DocumentImpl.write(dbConn, xml, pub, dtd, doAction,
1395 1396
                                          null, user, groups, validate);
1396 1397
          }//catch
1397
        }//try 
1398
        finally 
1398
        }//try
1399
        finally
1399 1400
        {
1400 1401
          // Return db connection
1401 1402
          DBConnectionPool.returnDBConnection(dbConn, serialNumber);
1402
        }    
1403
        }
1403 1404

  
1404 1405
        // set content type and other response header fields first
1405 1406
        response.setContentType("text/xml");
1406 1407
        out.println("<?xml version=\"1.0\"?>");
1407 1408
        out.println("<success>");
1408
        out.println("<docid>" + newdocid + "</docid>"); 
1409
        out.println("<docid>" + newdocid + "</docid>");
1409 1410
        out.println("</success>");
1410 1411

  
1411 1412
      } catch (NullPointerException npe) {
1412 1413
        response.setContentType("text/xml");
1413 1414
        out.println("<?xml version=\"1.0\"?>");
1414 1415
        out.println("<error>");
1415
        out.println(npe.getMessage()); 
1416
        out.println(npe.getMessage());
1416 1417
        out.println("</error>");
1417 1418
      }
1418 1419
    } catch (Exception e) {
1419 1420
      response.setContentType("text/xml");
1420 1421
      out.println("<?xml version=\"1.0\"?>");
1421 1422
      out.println("<error>");
1422
      out.println(e.getMessage()); 
1423
      out.println(e.getMessage());
1423 1424
      if (e instanceof SAXException) {
1424 1425
        Exception e2 = ((SAXException)e).getException();
1425 1426
        out.println("<error>");
......
1438 1439
    }
1439 1440
  }
1440 1441

  
1441
  /** 
1442
   * Parse XML Document to look for <!DOCTYPE ... PUBLIC/SYSTEM ... > 
1442
  /**
1443
   * Parse XML Document to look for <!DOCTYPE ... PUBLIC/SYSTEM ... >
1443 1444
   * in order to decide whether to use validation parser
1444 1445
   */
1445 1446
  private static boolean validateXML(String xmltext) throws IOException {
1446
    
1447

  
1447 1448
    StringReader xmlreader = new StringReader(xmltext);
1448 1449
    StringBuffer cbuff = new StringBuffer();
1449 1450
    java.util.Stack st = new java.util.Stack();
1450 1451
    boolean validate = false;
1451 1452
    int c;
1452 1453
    int inx;
1453
    
1454

  
1454 1455
    // read from the stream until find the keywords
1455 1456
    while ( (st.empty() || st.size()<4) && ((c = xmlreader.read()) != -1) ) {
1456 1457
      cbuff.append((char)c);
......
1471 1472
        st.push("SYSTEM");
1472 1473
      }
1473 1474
      // ">" character is found; put it in the stack
1474
      // ">" is found twice: fisrt from <?xml ...?> 
1475
      // ">" is found twice: fisrt from <?xml ...?>
1475 1476
      // and second from <!DOCTYPE ... >
1476 1477
      if ( (inx = cbuff.toString().indexOf(">")) != -1 ) {
1477 1478
        cbuff = new StringBuffer();
......
1499 1500
  // END OF INSERT/UPDATE SECTION
1500 1501

  
1501 1502
  // DELETE SECTION
1502
  /** 
1503
   * Handle the database delete request and delete an XML document 
1503
  /**
1504
   * Handle the database delete request and delete an XML document
1504 1505
   * from the database connection
1505 1506
   */
1506
  private void handleDeleteAction(PrintWriter out, Hashtable params, 
1507
  private void handleDeleteAction(PrintWriter out, Hashtable params,
1507 1508
               HttpServletResponse response, String user, String[] groups) {
1508 1509

  
1509 1510
    String[] docid = (String[])params.get("docid");
1510
  
1511

  
1511 1512
    // delete the document from the database
1512 1513
    try {
1513
 
1514

  
1514 1515
                                      // NOTE -- NEED TO TEST HERE
1515 1516
                                      // FOR EXISTENCE OF DOCID PARAM
1516 1517
                                      // BEFORE ACCESSING ARRAY
1517
      try { 
1518
      try {
1518 1519
        DocumentImpl.delete(docid[0], user, groups);
1519 1520
        response.setContentType("text/xml");
1520 1521
        out.println("<?xml version=\"1.0\"?>");
1521 1522
        out.println("<success>");
1522
        out.println("Document deleted."); 
1523
        out.println("Document deleted.");
1523 1524
        out.println("</success>");
1524 1525
      } catch (AccessionNumberException ane) {
1525 1526
        response.setContentType("text/xml");
1526 1527
        out.println("<?xml version=\"1.0\"?>");
1527 1528
        out.println("<error>");
1528 1529
        out.println("Error deleting document!!!");
1529
        out.println(ane.getMessage()); 
1530
        out.println(ane.getMessage());
1530 1531
        out.println("</error>");
1531 1532
      }
1532 1533
    } catch (Exception e) {
1533 1534
      response.setContentType("text/xml");
1534 1535
      out.println("<?xml version=\"1.0\"?>");
1535 1536
      out.println("<error>");
1536
      out.println(e.getMessage()); 
1537
      out.println(e.getMessage());
1537 1538
      out.println("</error>");
1538
    } 
1539
    }
1539 1540
  }
1540 1541
  // END OF DELETE SECTION
1541
  
1542

  
1542 1543
  // VALIDATE SECTION
1543
  /** 
1544
  /**
1544 1545
   * Handle the validation request and return the results to the requestor
1545 1546
   */
1546 1547
  private void handleValidateAction(PrintWriter out, Hashtable params) {
......
1549 1550
    String valtext = null;
1550 1551
    DBConnection dbConn = null;
1551 1552
    int serialNumber = -1;
1552
    
1553

  
1553 1554
    try {
1554 1555
      valtext = ((String[])params.get("valtext"))[0];
1555 1556
    } catch (Exception nullpe) {
1556 1557

  
1557
     
1558

  
1558 1559
      String docid = null;
1559 1560
      try {
1560 1561
        // Find the document id number
1561
        docid = ((String[])params.get("docid"))[0]; 
1562
        docid = ((String[])params.get("docid"))[0];
1562 1563

  
1563
      
1564

  
1564 1565
        // Get the document indicated from the db
1565 1566
        DocumentImpl xmldoc = new DocumentImpl(docid);
1566 1567
        valtext = xmldoc.toString();
1567 1568

  
1568 1569
      } catch (NullPointerException npe) {
1569
        
1570

  
1570 1571
        out.println("<error>Error getting document ID: " + docid + "</error>");
1571 1572
        //if ( conn != null ) { util.returnConnection(conn); }
1572 1573
        return;
1573 1574
      } catch (Exception e) {
1574
       
1575
        out.println(e.getMessage()); 
1576
      } 
1575

  
1576
        out.println(e.getMessage());
1577
      }
1577 1578
    }
1578 1579

  
1579
  
1580

  
1580 1581
    try {
1581 1582
      // get a connection from the pool
1582 1583
      dbConn=DBConnectionPool.
......
1586 1587
      boolean valid = valobj.validateString(valtext);
1587 1588

  
1588 1589
      // set content type and other response header fields first
1589
      
1590

  
1590 1591
      out.println(valobj.returnErrors());
1591 1592

  
1592 1593
    } catch (NullPointerException npe2) {
1593 1594
      // set content type and other response header fields first
1594
      
1595
      out.println("<error>Error validating document.</error>"); 
1595

  
1596
      out.println("<error>Error validating document.</error>");
1596 1597
    } catch (Exception e) {
1597
     
1598
      out.println(e.getMessage()); 
1598

  
1599
      out.println(e.getMessage());
1599 1600
    } finally {
1600 1601
      // Return db connection
1601 1602
      DBConnectionPool.returnDBConnection(dbConn, serialNumber);
1602
    }  
1603
    }
1603 1604
  }
1604 1605
  // END OF VALIDATE SECTION
1605
 
1606

  
1606 1607
  // OTHER ACTION HANDLERS
1607
  
1608

  
1608 1609
  /**
1609 1610
   * Handle "getrevsionanddoctype" action
1610 1611
   * Given a docid, return it's current revision and doctype from data base
1611 1612
   * The output is String look like "rev;doctype"
1612 1613
   */
1613
  private void handleGetRevisionAndDocTypeAction(PrintWriter out, 
1614
  private void handleGetRevisionAndDocTypeAction(PrintWriter out,
1614 1615
                                                              Hashtable params)
1615 1616
  {
1616 1617
    // To store doc parameter
......
1618 1619
    // Store a single doc id
1619 1620
    String givenDocId = null;
1620 1621
    // Get docid from parameters
1621
    if (params.containsKey("docid")) 
1622
    if (params.containsKey("docid"))
1622 1623
    {
1623 1624
      docs = (String[])params.get("docid");
1624 1625
    }
1625 1626
    // Get first docid form string array
1626 1627
    givenDocId = docs[0];
1627
   
1628
    try 
1628

  
1629
    try
1629 1630
    {
1630 1631
      // Make sure there is a docid
1631 1632
      if (givenDocId == null || givenDocId.equals(""))
1632 1633
      {
1633 1634
        throw new Exception("User didn't specify docid!");
1634 1635
      }//if
1635
      
1636

  
1636 1637
      // Create a DBUtil object
1637 1638
      DBUtil dbutil = new DBUtil();
1638 1639
      // Get a rev and doctype
1639
      String revAndDocType = 
1640
      String revAndDocType =
1640 1641
                dbutil.getCurrentRevisionAndDocTypeForGivenDocument(givenDocId);
1641 1642
      out.println(revAndDocType);
1642 1643

  
1643
    }//try 
1644
    catch (Exception e) 
1644
    }//try
1645
    catch (Exception e)
1645 1646
    {
1646 1647
      // Handle exception
1647 1648
      out.println("<?xml version=\"1.0\"?>");
1648 1649
      out.println("<error>");
1649 1650
      out.println(e.getMessage());
1650 1651
      out.println("</error>");
1651
    }//catch 
1652
    
1652
    }//catch
1653

  
1653 1654
  }//handleGetRevisionAndDocTypeAction
1654
  
1655
  /** 
1655

  
1656
  /**
1656 1657
   * Handle "getaccesscontrol" action.
1657 1658
   * Read Access Control List from db connection in XML format
1658 1659
   */
1659
  private void handleGetAccessControlAction(PrintWriter out, Hashtable params, 
1660
                                       HttpServletResponse response, 
1660
  private void handleGetAccessControlAction(PrintWriter out, Hashtable params,
1661
                                       HttpServletResponse response,
1661 1662
                                       String username, String[] groupnames) {
1662 1663

  
1663 1664
    DBConnection dbConn = null;
1664 1665
    int serialNumber = -1;
1665 1666
    String docid = ((String[])params.get("docid"))[0];
1666
    
1667

  
1667 1668
    try {
1668 1669

  
1669 1670
        // get connection from the pool
......
1682 1683
    } finally {
1683 1684
      // Retrun db connection to pool
1684 1685
      DBConnectionPool.returnDBConnection(dbConn, serialNumber);
1685
    }  
1686
    
1686
    }
1687

  
1687 1688
  }
1688 1689

  
1689
  /** 
1690
  /**
1690 1691
   * Handle the "getprincipals" action.
1691 1692
   * Read all principals from authentication scheme in XML format
1692 1693
   */
1693 1694
  private void handleGetPrincipalsAction(PrintWriter out, String user,
1694 1695
                                         String password) {
1695 1696

  
1696
   
1697

  
1697 1698
    try {
1698 1699

  
1699
        
1700

  
1700 1701
        AuthSession auth = new AuthSession();
1701 1702
        String principals = auth.getPrincipals(user, password);
1702 1703
        out.println(principals);
......
1706 1707
      out.println("<error>");
1707 1708
      out.println(e.getMessage());
1708 1709
      out.println("</error>");
1709
    } 
1710
    
1710
    }
1711

  
1711 1712
  }
1712 1713

  
1713
  /** 
1714
  /**
1714 1715
   * Handle "getdoctypes" action.
1715 1716
   * Read all doctypes from db connection in XML format
1716 1717
   */
1717
  private void handleGetDoctypesAction(PrintWriter out, Hashtable params, 
1718
  private void handleGetDoctypesAction(PrintWriter out, Hashtable params,
1718 1719
                                       HttpServletResponse response) {
1719 1720

  
1720
   
1721

  
1721 1722
    try {
1722 1723

  
1723
     
1724

  
1724 1725
        DBUtil dbutil = new DBUtil();
1725 1726
        String doctypes = dbutil.readDoctypes();
1726 1727
        out.println(doctypes);
......
1730 1731
      out.println("<error>");
1731 1732
      out.println(e.getMessage());
1732 1733
      out.println("</error>");
1733
    } 
1734
    
1734
    }
1735

  
1735 1736
  }
1736 1737

  
1737
  /** 
1738
  /**
1738 1739
   * Handle the "getdtdschema" action.
1739 1740
   * Read DTD or Schema file for a given doctype from Metacat catalog system
1740 1741
   */
1741 1742
  private void handleGetDTDSchemaAction(PrintWriter out, Hashtable params,
1742 1743
                                        HttpServletResponse response) {
1743 1744

  
1744
   
1745

  
1745 1746
    String doctype = null;
1746 1747
    String[] doctypeArr = (String[])params.get("doctype");
1747 1748

  
1748 1749
    // get only the first doctype specified in the list of doctypes
1749 1750
    // it could be done for all doctypes in that list
1750 1751
    if (doctypeArr != null) {
1751
        doctype = ((String[])params.get("doctype"))[0]; 
1752
        doctype = ((String[])params.get("doctype"))[0];
1752 1753
    }
1753 1754

  
1754 1755
    try {
1755 1756

  
1756
       
1757

  
1757 1758
        DBUtil dbutil = new DBUtil();
1758 1759
        String dtdschema = dbutil.readDTDSchema(doctype);
1759 1760
        out.println(dtdschema);
......
1763 1764
      out.println("<error>");
1764 1765
      out.println(e.getMessage());
1765 1766
      out.println("</error>");
1766
    } 
1767
    
1767
    }
1768

  
1768 1769
  }
1769 1770

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff