Project

General

Profile

« Previous | Next » 

Revision 2092

Added by Jing Tao about 20 years ago

Fixed a bug if a document already has index, but now metacat doesn't use index. If you try to delete this one, will cause error.

View differences:

src/edu/ucsb/nceas/metacat/DocumentImpl.java
69 69
   public static final String SCHEMA                 = "Schema";
70 70
   public static final String DTD                    = "DTD";
71 71
   public static final String EML2                   = "eml2";
72
   public static final String EXTERNALSCHEMALOCATIONPROPERTY = 
72
   public static final String EXTERNALSCHEMALOCATIONPROPERTY =
73 73
              "http://apache.org/xml/properties/schema/external-schemaLocation";
74
   /*public static final String EXTERNALSCHEMALOCATION = 
74
   /*public static final String EXTERNALSCHEMALOCATION =
75 75
     "eml://ecoinformatics.org/eml-2.0.0 http://dev.nceas.ucsb.edu/tao/schema/eml.xsd"+
76 76
      " http://www.xml-cml.org/schema/stmml http://dev.nceas.ucsb.edu/tao/schema/stmml.xsd";*/
77 77
   public static final String DECLARATIONHANDLERPROPERTY =
78 78
                            "http://xml.org/sax/properties/declaration-handler";
79 79
   public static final String LEXICALPROPERTY =
80 80
                             "http://xml.org/sax/properties/lexical-handler";
81
   public static final String VALIDATIONFEATURE = 
81
   public static final String VALIDATIONFEATURE =
82 82
                             "http://xml.org/sax/features/validation";
83
   public static final String SCHEMAVALIDATIONFEATURE = 
83
   public static final String SCHEMAVALIDATIONFEATURE =
84 84
                             "http://apache.org/xml/features/validation/schema";
85
   public static final String NAMESPACEFEATURE = 
85
   public static final String NAMESPACEFEATURE =
86 86
                              "http://xml.org/sax/features/namespaces";
87
   public static final String NAMESPACEPREFIXESFEATURE = 
87
   public static final String NAMESPACEPREFIXESFEATURE =
88 88
                              "http://xml.org/sax/features/namespace-prefixes";
89 89
   public static final String EMLNAMESPACE =
90
                                         MetaCatUtil.getOption("eml2namespace"); 
90
                                         MetaCatUtil.getOption("eml2namespace");
91 91
                                         // "eml://ecoinformatics.org/eml-2.0.0";
92
  
92

  
93 93
  public static final String DOCNAME = "docname";
94 94
  public static final String PUBLICID = "publicid";
95 95
  public static final String SYSTEMID = "systemid";
......
114 114
  private int rev;
115 115
  private int serverlocation;
116 116
  private String docHomeServer;
117
  private String publicaccess; 
117
  private String publicaccess;
118 118
  private long rootnodeid;
119 119
  private ElementNode rootNode = null;
120 120
  private TreeSet nodeRecordList = null;
121
  //private static 
121
  //private static
122 122
  //ReplicationServerList serverList = new ReplicationServerList();
123
  
123

  
124 124
  /**
125 125
   * Constructor used to create a document and read the document information
126
   * from the database.  If readNodes is false, then the node data is not 
127
   * read at this time, but is deferred until it is needed (such as when a 
128
   * call to toXml() is made).  
126
   * from the database.  If readNodes is false, then the node data is not
127
   * read at this time, but is deferred until it is needed (such as when a
128
   * call to toXml() is made).
129 129
   *
130 130
   * @param conn the database connection from which to read the document
131 131
   * @param docid the identifier of the document to be created
132 132
   * @param readNodes flag indicating whether the xmlnodes should be read
133 133
   */
134
  public DocumentImpl(String docid, boolean readNodes) 
135
         throws McdbException 
134
  public DocumentImpl(String docid, boolean readNodes)
135
         throws McdbException
136 136
  {
137 137
    try {
138 138
      //this.conn = conn;
139 139
      this.docid = docid;
140
      
140

  
141 141
      // Look up the document information
142 142
      getDocumentInfo(docid);
143
      
143

  
144 144
      if (readNodes) {
145 145
        // Download all of the document nodes using a single SQL query
146 146
        // The sort order of the records is determined by the NodeComparator
147 147
        // class, and needs to represent a depth-first traversal for the
148 148
        // toXml() method to work properly
149 149
        nodeRecordList = getNodeRecordList(rootnodeid);
150
        
150

  
151 151
      }
152
    
152

  
153 153
    } catch (McdbException ex) {
154 154
      throw ex;
155 155
    } catch (Throwable t) {
......
159 159
  }
160 160

  
161 161
  /**
162
   * Constructor, creates document from database connection, used 
162
   * Constructor, creates document from database connection, used
163 163
   * for reading the document
164 164
   *
165 165
   * @param conn the database connection from which to read the document
166 166
   * @param docid the identifier of the document to be created
167 167
   */
168
  public DocumentImpl(String docid) throws McdbException 
168
  public DocumentImpl(String docid) throws McdbException
169 169
  {
170 170
    this(docid, true);
171 171
  }
172 172

  
173
 
174
  
175
  /** 
173

  
174

  
175
  /**
176 176
   * Construct a new document instance, writing the contents to the database.
177 177
   * This method is called from DBSAXHandler because we need to know the
178 178
   * root element name for documents without a DOCTYPE before creating it.
179 179
   *
180
   * In this constructor, the docid is without rev. There is a string rev to 
180
   * In this constructor, the docid is without rev. There is a string rev to
181 181
   * specify the revision user want to upadate. The revion is only need to be
182 182
   * greater than current one. It is not need to be sequent number just after
183 183
   * current one. So it is only used in update action
184 184
   * @param conn the JDBC Connection to which all information is written
185 185
   * @param rootnodeid - sequence id of the root node in the document
186
   * @param docname - the name of DTD, i.e. the name immediately following 
186
   * @param docname - the name of DTD, i.e. the name immediately following
187 187
   *        the DOCTYPE keyword ( should be the root element name ) or
188 188
   *        the root element name if no DOCTYPE declaration provided
189
   *        (Oracle's and IBM parsers are not aware if it is not the 
189
   *        (Oracle's and IBM parsers are not aware if it is not the
190 190
   *        root element name)
191
   * @param doctype - Public ID of the DTD, i.e. the name immediately 
191
   * @param doctype - Public ID of the DTD, i.e. the name immediately
192 192
   *                  following the PUBLIC keyword in DOCTYPE declaration or
193 193
   *                  the docname if no Public ID provided or
194 194
   *                  null if no DOCTYPE declaration provided
......
201 201
   *        resides.
202 202
   *
203 203
   */
204
  public DocumentImpl(DBConnection conn, long rootNodeId, String docName, 
205
                      String docType, String docId, String newRevision, 
204
  public DocumentImpl(DBConnection conn, long rootNodeId, String docName,
205
                      String docType, String docId, String newRevision,
206 206
                      String action, String user,
207 207
                      String pub, String catalogId, int serverCode)
208 208
                      throws SQLException, Exception
......
215 215
    this.updatedVersion = newRevision;
216 216
    writeDocumentToDB(action, user, pub, catalogId, serverCode);
217 217
  }
218
  
218

  
219 219
  /**
220 220
   * This method will be call in handleUploadRequest in MetacatServlet class
221 221
   */
......
223 223
                     String docname, String doctype, String accnum, String user)
224 224
                     throws SQLException, AccessionNumberException, Exception
225 225
  {
226
    
226

  
227 227
    try
228 228
    {
229 229
       // get server location for this doc
......
234 234
    {
235 235
      throw e;
236 236
    }
237
   
238
    
237

  
238

  
239 239
  }
240 240
  /**
241 241
   * Register a document that resides on the filesystem with the database.
......
243 243
   * Creates a reference to a filesystem document (used for non-xml data files).
244 244
   * This class only be called in MetaCatServerlet.
245 245
   * @param conn the JDBC Connection to which all information is written
246
   * @param docname - the name of DTD, i.e. the name immediately following 
246
   * @param docname - the name of DTD, i.e. the name immediately following
247 247
   *        the DOCTYPE keyword ( should be the root element name ) or
248 248
   *        the root element name if no DOCTYPE declaration provided
249
   *        (Oracle's and IBM parsers are not aware if it is not the 
249
   *        (Oracle's and IBM parsers are not aware if it is not the
250 250
   *        root element name)
251
   * @param doctype - Public ID of the DTD, i.e. the name immediately 
251
   * @param doctype - Public ID of the DTD, i.e. the name immediately
252 252
   *                  following the PUBLIC keyword in DOCTYPE declaration or
253 253
   *                  the docname if no Public ID provided or
254 254
   *                  null if no DOCTYPE declaration provided
255
   * @param accnum the accession number to use for the INSERT OR UPDATE, which 
256
   *               includes a revision number for this revision of the document 
255
   * @param accnum the accession number to use for the INSERT OR UPDATE, which
256
   *               includes a revision number for this revision of the document
257 257
   *               (e.g., knb.1.1)
258 258
   * @param user the user that owns the document
259 259
   * @param serverCode the serverid from xml_replication on which this document
260 260
   *        resides.
261 261
   */
262 262
  public static void registerDocument(
263
                     String docname, String doctype, String accnum, 
263
                     String docname, String doctype, String accnum,
264 264
                     String user, int serverCode)
265 265
                     throws SQLException, AccessionNumberException, Exception
266 266
  {
......
291 291
      // it is a updated data file
292 292
      else if (userSpecifyRev>revInDataBase && revInDataBase>0)
293 293
      {
294
        
295
        //archive the old entry 
294

  
295
        //archive the old entry
296 296
        archiveDocRevision(docIdWithoutRev, user);
297 297
        //delete the old entry in xml_documents
298 298
        //deleteXMLDocuments(docIdWithoutRev);
......
302 302
      //other situation
303 303
      else
304 304
      {
305
        
305

  
306 306
        throw new Exception("Revision number couldn't be "
307 307
                    +userSpecifyRev);
308 308
      }
......
313 313
      String dateString = formatter.format(localtime);
314 314
      String sqlDateString=dbAdapter.toDate(dateString, "MM/DD/YY HH24:MI:SS");*/
315 315
      String  sqlDateString = dbAdapter.getDateTimeFunction();
316
  
316

  
317 317
      StringBuffer sql = new StringBuffer();
318 318
      if (action != null && action.equals("insert"))
319 319
      {
......
350 350
      pstmt.execute();
351 351
      pstmt.close();
352 352
      //dbconn.close();
353
    } 
354
    finally 
353
    }
354
    finally
355 355
    {
356 356
      try
357 357
      {
......
361 361
      {
362 362
        DBConnectionPool.returnDBConnection(dbconn, serialNumber);
363 363
      }
364
    }    
364
    }
365 365
  }
366
  
366

  
367 367
    /**
368 368
   * Register a document that resides on the filesystem with the database.
369 369
   * (ie, just an entry in xml_documents, nothing in xml_nodes).
370 370
   * Creates a reference to a filesystem document (used for non-xml data files)
371
   * This method will be called for register data file in xml_documents in 
371
   * This method will be called for register data file in xml_documents in
372 372
   * Replication.
373 373
   * This method is revised from registerDocument.
374 374
   *
375 375
   * @param conn the JDBC Connection to which all information is written
376
   * @param docname - the name of DTD, i.e. the name immediately following 
376
   * @param docname - the name of DTD, i.e. the name immediately following
377 377
   *        the DOCTYPE keyword ( should be the root element name ) or
378 378
   *        the root element name if no DOCTYPE declaration provided
379
   *        (Oracle's and IBM parsers are not aware if it is not the 
379
   *        (Oracle's and IBM parsers are not aware if it is not the
380 380
   *        root element name)
381
   * @param doctype - Public ID of the DTD, i.e. the name immediately 
381
   * @param doctype - Public ID of the DTD, i.e. the name immediately
382 382
   *                  following the PUBLIC keyword in DOCTYPE declaration or
383 383
   *                  the docname if no Public ID provided or
384 384
   *                  null if no DOCTYPE declaration provided
385
   * @param accnum the accession number to use for the INSERT OR UPDATE, which 
386
   *               includes a revision number for this revision of the document 
385
   * @param accnum the accession number to use for the INSERT OR UPDATE, which
386
   *               includes a revision number for this revision of the document
387 387
   *               (e.g., knb.1.1)
388 388
   * @param user the user that owns the document
389 389
   * @param serverCode the serverid from xml_replication on which this document
390 390
   *        resides.
391 391
   */
392 392
  public static void registerDocumentInReplication(
393
                     String docname, String doctype, String accnum, 
393
                     String docname, String doctype, String accnum,
394 394
                     String user, int serverCode)
395 395
                     throws SQLException, AccessionNumberException, Exception
396 396
  {
......
413 413
      //user specified rev should be great than 0
414 414
      if (revInDataBase==-1 && userSpecifyRev>=0 )
415 415
      {
416
       
416

  
417 417
        ac = new AccessionNumber(accnum, "insert");
418 418
        action = "insert";
419 419
      }
......
421 421
      // it is a updated data file
422 422
      else if (userSpecifyRev>revInDataBase && revInDataBase>=0)
423 423
      {
424
        
425
        //archive the old entry 
424

  
425
        //archive the old entry
426 426
        archiveDocRevision(docIdWithoutRev, user);
427 427
        //delete the old entry in xml_documents
428 428
        //deleteXMLDocuments(docIdWithoutRev);
......
439 439
      //other situation
440 440
      else
441 441
      {
442
        
442

  
443 443
        throw new Exception("Revision number couldn't be "
444 444
                    +userSpecifyRev);
445 445
      }
......
450 450
      String dateString = formatter.format(localtime);
451 451
      String sqlDateString=dbAdapter.toDate(dateString, "MM/DD/YY HH24:MI:SS");*/
452 452
      String sqlDateString = dbAdapter.getDateTimeFunction();
453
      
453

  
454 454
      StringBuffer sql = new StringBuffer();
455 455
      if (action != null && action.equals("insert"))
456 456
      {
......
486 486
      // Set auto commit fasle
487 487
      dbconn.setAutoCommit(false);
488 488
      pstmt = dbconn.prepareStatement(sql.toString());
489
     
489

  
490 490
      pstmt.execute();
491 491
      // Commit the insert
492 492
      dbconn.commit();
493 493
      pstmt.close();
494 494
      //dbconn.close();
495
    } 
496
    finally 
495
    }
496
    finally
497 497
    {
498 498
      // Set DBConnection auto commit true
499 499
      dbconn.setAutoCommit(true);
500 500
      pstmt.close();
501 501
      DBConnectionPool.returnDBConnection(dbconn, serialNumber);
502
    }    
502
    }
503 503
  }
504
  
504

  
505 505
 /**
506 506
   * This method will register a data file entry in xml_documents and save a
507 507
   * data file input Stream into file system.. It is only used in replication
......
510 510
   * @param  , the input stream which contain the file content
511 511
   * @param docname - the name of DTD, for data file, it is a docid number.
512 512
   * @param doctype - "BIN" for data file
513
   * @param accnum the accession number to use for the INSERT OR UPDATE, which 
514
   *               includes a revision number for this revision of the document 
513
   * @param accnum the accession number to use for the INSERT OR UPDATE, which
514
   *               includes a revision number for this revision of the document
515 515
   *               (e.g., knb.1.1)
516 516
   * @param user the user that owns the document
517 517
   * @param docHomeServer, the home server of the docid
518
   * @param notificationServer, the server to notify force replication info to 
518
   * @param notificationServer, the server to notify force replication info to
519 519
   *                            local metacat
520 520
   */
521
 public static void writeDataFileInReplication(InputStream input, 
522
                 String filePath, String docname, String doctype, String accnum, 
521
 public static void writeDataFileInReplication(InputStream input,
522
                 String filePath, String docname, String doctype, String accnum,
523 523
                   String user, String docHomeServer, String notificationServer)
524 524
                     throws SQLException, AccessionNumberException, Exception
525 525
 {
526 526
    int serverCode=-2;
527
   
528
    
527

  
528

  
529 529
    if (filePath==null||filePath.equals(""))
530 530
    {
531
      throw new 
531
      throw new
532 532
            Exception("Please specify the directory where file will be store");
533 533
    }
534 534
    if (accnum==null||accnum.equals(""))
535 535
    {
536 536
      throw new Exception("Please specify the stored file name");
537 537
    }
538
    
539
   
540
    
541
    // If server is not int the xml replication talbe, insert it into 
538

  
539

  
540

  
541
    // If server is not int the xml replication talbe, insert it into
542 542
    // xml_replication table
543 543
    //serverList.addToServerListIfItIsNot(docHomeServer);
544 544
    insertServerIntoReplicationTable(docHomeServer);
545
    
545

  
546 546
    // Get server code again
547 547
    serverCode = getServerCode(docHomeServer);
548
    
549
    
548

  
549

  
550 550
    //register data file into xml_documents table
551 551
    registerDocumentInReplication(docname, doctype, accnum, user, serverCode);
552 552
    //write inputstream into file system.
553 553
    File dataDirectory = new File(filePath);
554
    File newFile = new File(dataDirectory, accnum); 
555
       
554
    File newFile = new File(dataDirectory, accnum);
555

  
556 556
    // create a buffered byte output stream
557 557
    // that uses a default-sized output buffer
558 558
    FileOutputStream fos = new FileOutputStream(newFile);
......
562 562
    bis = new BufferedInputStream(input);
563 563
    byte[] buf = new byte[4 * 1024]; // 4K buffer
564 564
    int b = bis.read(buf);
565
       
566
    while (b != -1) 
565

  
566
    while (b != -1)
567 567
    {
568 568
        outPut.write(buf, 0, b);
569 569
        b = bis.read(buf);
570 570
    }
571 571
    bis.close();
572
	  outPut.close();
573
	  fos.close();
574
      
572
          outPut.close();
573
          fos.close();
574

  
575 575
    // Force replicate data file
576 576
    ForceReplicationHandler forceReplication = new ForceReplicationHandler
577 577
                                    (accnum, false, notificationServer);
578
  
578

  
579 579
 }
580
  
581 580

  
582
  
583
  public static boolean getDataFileLockGrant(String accnum) 
581

  
582

  
583
  public static boolean getDataFileLockGrant(String accnum)
584 584
                                                  throws Exception
585
  { 
586
    
585
  {
586

  
587 587
    try
588 588
    {
589
      
589

  
590 590
      int serverLocation=getServerLocationNumber(accnum);
591
    
591

  
592 592
      return getDataFileLockGrant(accnum,serverLocation);
593 593
    }
594 594
    catch (Exception e)
595 595
    {
596
     
596

  
597 597
      throw e;
598 598
    }
599 599
  }
600
    
600

  
601 601
  /**
602 602
   * The method will check if metacat can get data file lock grant
603 603
   * If server code is 1, it get.
604 604
   * If server code is not 1 but call replication getlock successfully,
605 605
   * it get
606 606
   * else, it didn't get
607
   * @param accnum, the ID of the document 
607
   * @param accnum, the ID of the document
608 608
   * @param action, the action to the document
609 609
   * @param serverCode, the server location code
610 610
   */
611 611
  public static boolean getDataFileLockGrant(String accnum, int serverCode)
612
                                          throws Exception 
612
                                          throws Exception
613 613
  {
614 614
    boolean flag=true;
615 615
    //MetaCatUtil util = new MetaCatUtil();
616 616
    String docid = MetaCatUtil.getDocIdFromString(accnum);
617 617
    int rev = MetaCatUtil.getVersionFromString(accnum);
618
    
618

  
619 619
    if (serverCode == 1)
620 620
    {
621 621
      flag=true;
622 622
      return flag;
623 623
    }
624
    
624

  
625 625
    //if((serverCode != 1 && action.equals("UPDATE")) )
626 626
    if (serverCode != 1)
627 627
    { //if this document being written is not a resident of this server then
......
629 629
      //resident server will not give a lock then we send the user a message
630 630
      //saying that he/she needs to download a new copy of the file and
631 631
      //merge the differences manually.
632
      
632

  
633 633
      String server=MetacatReplication.getServerNameForServerCode(serverCode);
634 634
      MetacatReplication.replLog("attempting to lock " + accnum);
635 635
      URL u = new URL("https://" + server + "?server=" +
636
        MetaCatUtil.getLocalReplicationServerName()+"&action=getlock&updaterev=" 
636
        MetaCatUtil.getLocalReplicationServerName()+"&action=getlock&updaterev="
637 637
           +rev + "&docid=" + docid);
638 638
      //System.out.println("sending message: " + u.toString());
639 639
      String serverResStr = MetacatReplication.getURLContent(u);
......
644 644
        //System.out.println("In lockgranted");
645 645
        MetacatReplication.replLog("lock granted for " + accnum + " from " +
646 646
                                      server);
647
        flag=true;  
647
        flag=true;
648 648
        return flag;
649 649
      }//if
650 650

  
......
671 671
                            "merge your changes and try again.");
672 672
      }//else if
673 673
    }//if
674
    
674

  
675 675
   return flag;
676
   
676

  
677 677
  }//getDataFileLockGrant
678
  
678

  
679 679
  /**
680 680
   * get the document name
681 681
   */
......
703 703
  public long getRootNodeID() {
704 704
    return rootnodeid;
705 705
  }
706
  
706

  
707 707
  /**
708 708
   * get the creation date
709 709
   */
710 710
  public String getCreateDate() {
711 711
    return createdate;
712 712
  }
713
  
713

  
714 714
  /**
715 715
   * get the update date
716 716
   */
......
718 718
    return updatedate;
719 719
  }
720 720

  
721
  /** 
721
  /**
722 722
   * Get the document identifier (docid)
723 723
   */
724 724
  public String getDocID() {
725 725
    return docid;
726 726
  }
727
  
727

  
728 728
// DOCTITLE attr cleared from the db
729 729
//  /**
730 730
//   *get the document title
......
732 732
//  public String getDocTitle() {
733 733
//    return doctitle;
734 734
//  }
735
  
735

  
736 736
  public String getUserowner() {
737 737
    return userowner;
738 738
  }
739
  
739

  
740 740
  public String getUserupdated() {
741 741
    return userupdated;
742 742
  }
743
  
743

  
744 744
  public int getServerlocation() {
745 745
    return serverlocation;
746 746
  }
747
  
747

  
748 748
  public String getDocHomeServer() {
749 749
    return docHomeServer;
750 750
  }
751
  
752
 
753
 
751

  
752

  
753

  
754 754
  public String getPublicaccess() {
755 755
    return publicaccess;
756 756
  }
757
  
757

  
758 758
  public int getRev() {
759 759
    return rev;
760 760
  }
761
  
761

  
762 762
  public String getValidateType()
763 763
  {
764 764
    return validateType;
765 765
  }
766
  
766

  
767 767
  /**
768 768
   * Print a string representation of the XML document
769 769
   */
770 770
  public String toString(String user, String[] groups, boolean withInlinedata)
771 771
  {
772 772
    StringWriter docwriter = new StringWriter();
773
    try 
773
    try
774 774
    {
775 775
      this.toXml(docwriter, user, groups, withInlinedata);
776
    } 
777
    catch (McdbException mcdbe) 
776
    }
777
    catch (McdbException mcdbe)
778 778
    {
779 779
      return null;
780 780
    }
781 781
    String document = docwriter.toString();
782 782
    return document;
783 783
  }
784
  
784

  
785 785
   /**
786 786
   * Print a string representation of the XML document
787 787
   */
......
791 791
    String userName = null;
792 792
    String[] groupNames = null;
793 793
    boolean withInlineData = false;
794
    try 
794
    try
795 795
    {
796 796
      this.toXml(docwriter, userName, groupNames, withInlineData);
797
    } 
798
    catch (McdbException mcdbe) 
797
    }
798
    catch (McdbException mcdbe)
799 799
    {
800 800
      return null;
801 801
    }
......
806 806
  /**
807 807
   * Get a text representation of the XML document as a string
808 808
   * This older algorithm uses a recursive tree of Objects to represent the
809
   * nodes of the tree.  Each object is passed the data for the document 
809
   * nodes of the tree.  Each object is passed the data for the document
810 810
   * and searches all of the document data to find its children nodes and
811 811
   * recursively build.  Thus, because each node reads the whole document,
812 812
   * this algorithm is extremely slow for larger documents, and the time
......
827 827

  
828 828
    // Append the resulting document to the StringBuffer and return it
829 829
    doc.append("<?xml version=\"1.0\"?>\n");
830
      
830

  
831 831
    if (docname != null) {
832 832
      if ((doctype != null) && (system_id != null)) {
833
        doc.append("<!DOCTYPE " + docname + " PUBLIC \"" + doctype + 
833
        doc.append("<!DOCTYPE " + docname + " PUBLIC \"" + doctype +
834 834
                   "\" \"" + system_id + "\">\n");
835 835
      } else {
836 836
        doc.append("<!DOCTYPE " + docname + ">\n");
837 837
      }
838 838
    }
839 839
    doc.append(rootNode.toString());
840
  
840

  
841 841
    return (doc.toString());
842 842
  }
843 843

  
......
846 846
   *
847 847
   * @param pw the Writer to which we print the document
848 848
   */
849
  public void toXml(Writer pw, String user, String[] groups, boolean withInLineData) 
849
  public void toXml(Writer pw, String user, String[] groups, boolean withInLineData)
850 850
                                                          throws McdbException
851 851
  {
852 852
    // flag for process  eml2
853 853
    boolean proccessEml2 = false;
854
    boolean storedDTD = false;//flag to inidate publicid or system 
854
    boolean storedDTD = false;//flag to inidate publicid or system
855 855
                              // id stored in db or not
856 856
    boolean firstElement = true;
857 857
    String dbDocName = null;
858 858
    String dbPublicID = null;
859 859
    String dbSystemID = null;
860
    
860

  
861 861
    if (doctype != null && doctype.equals(EMLNAMESPACE))
862 862
    {
863 863
      proccessEml2 = true;
864 864
    }
865 865
    // flag for process inline data
866 866
    boolean prcocessInlineData = false;
867
    
867

  
868 868
    TreeSet nodeRecordLists = null;
869 869
    PrintWriter out = null;
870 870
    if (pw instanceof PrintWriter) {
......
874 874
    }
875 875

  
876 876
    MetaCatUtil util = new MetaCatUtil();
877
    
877

  
878 878
    // Here add code to handle subtree access control
879 879
    PermissionController control = new PermissionController(docid);
880
    Hashtable unaccessableSubTree =control.hasUnaccessableSubTree(user, groups, 
880
    Hashtable unaccessableSubTree =control.hasUnaccessableSubTree(user, groups,
881 881
                                             AccessControlInterface.READSTRING);
882
    
882

  
883 883
    if (!unaccessableSubTree.isEmpty())
884 884
    {
885
     
885

  
886 886
      nodeRecordLists = getPartNodeRecordList(rootnodeid, unaccessableSubTree);
887
      
887

  
888 888
    }
889
    else 
889
    else
890 890
    {
891 891
      nodeRecordLists = getNodeRecordList(rootnodeid);
892 892
    }
......
896 896
    boolean previousNodeWasElement = false;
897 897

  
898 898
    // Step through all of the node records we were given
899
   
899

  
900 900
    Iterator it = nodeRecordLists.iterator();
901
   
902
    while (it.hasNext()) 
901

  
902
    while (it.hasNext())
903 903
    {
904
      
904

  
905 905
      NodeRecord currentNode = (NodeRecord)it.next();
906 906
      util.debugMessage("[Got Node ID: " + currentNode.nodeid +
907 907
                          " (" + currentNode.parentnodeid +
908
                          ", " + currentNode.nodeindex + 
909
                          ", " + currentNode.nodetype + 
910
                          ", " + currentNode.nodename + 
908
                          ", " + currentNode.nodeindex +
909
                          ", " + currentNode.nodetype +
910
                          ", " + currentNode.nodename +
911 911
                          ", " + currentNode.nodedata + ")]", 50);
912 912
      // Print the end tag for the previous node if needed
913 913
      //
......
931 931
            if (previousNodeWasElement) {
932 932
              out.print(">");
933 933
              previousNodeWasElement = false;
934
            }  
934
            }
935 935
            if ( currentElement.nodeprefix != null ) {
936
              out.print("</" + currentElement.nodeprefix + ":" + 
936
              out.print("</" + currentElement.nodeprefix + ":" +
937 937
                        currentElement.nodename + ">" );
938 938
            } else {
939 939
              out.print("</" + currentElement.nodename + ">" );
......
946 946
      // Handle the DOCUMENT node
947 947
      if (currentNode.nodetype.equals("DOCUMENT")) {
948 948
        out.print("<?xml version=\"1.0\"?>");
949
       
950 949

  
950

  
951 951
      // Handle the ELEMENT nodes
952 952
      } else if (currentNode.nodetype.equals("ELEMENT")) {
953 953
        if (atRootElement) {
......
957 957
            out.print(">");
958 958
          }
959 959
        }
960
        
960

  
961 961
        // if publicid or system is not stored into db send it out by default
962 962
        if ( !storedDTD & firstElement )
963 963
        {
964
           if (docname != null && validateType != null && validateType.equals(DTD)) 
964
           if (docname != null && validateType != null && validateType.equals(DTD))
965 965
           {
966
              if ((doctype != null) && (system_id != null)) 
966
              if ((doctype != null) && (system_id != null))
967 967
              {
968
            
969
                  out.print("<!DOCTYPE " + docname + " PUBLIC \"" + doctype + 
968

  
969
                  out.print("<!DOCTYPE " + docname + " PUBLIC \"" + doctype +
970 970
                       "\" \"" + system_id + "\">");
971
               } 
972
               else 
971
               }
972
               else
973 973
               {
974
            
974

  
975 975
                  out.print("<!DOCTYPE " + docname + ">");
976 976
               }
977 977
           }
......
985 985
        } else {
986 986
          out.print("<" + currentNode.nodename);
987 987
        }
988
        
988

  
989 989
        // if currentNode is inline and handle eml2, set flag proccess in
990
        if (currentNode.nodename != null && 
990
        if (currentNode.nodename != null &&
991 991
            currentNode.nodename.equals(EmlSAXHandler.INLINE) && proccessEml2)
992 992
        {
993 993
          prcocessInlineData = true;
......
1021 1021
        }
1022 1022
        else
1023 1023
        {
1024
          // if it is inline data and user want to see it, pull out from 
1024
          // if it is inline data and user want to see it, pull out from
1025 1025
          // file system and output it
1026 1026
          // for inline data, the data base only store the file name, so we
1027 1027
          // can combine the file name and inline data file path, to get it
1028 1028
          String fileName = currentNode.nodedata;
1029
          Reader reader = 
1029
          Reader reader =
1030 1030
                          EmlSAXHandler.readInlineDataFromFileSystem(fileName);
1031 1031
          char [] characterArray = new char [4*1024];
1032 1032
          try
......
1045 1045
            throw new McdbException(e.getMessage());
1046 1046
          }
1047 1047
        }
1048
        
1048

  
1049 1049
        // reset proccess inline data false
1050 1050
        prcocessInlineData =false;
1051 1051
        previousNodeWasElement = false;
......
1066 1066
        out.print("<?" + currentNode.nodename + " " +
1067 1067
                        currentNode.nodedata + "?>");
1068 1068
        previousNodeWasElement = false;
1069
     // Handle the DTD nodes (docname, publicid, systemid)  
1069
     // Handle the DTD nodes (docname, publicid, systemid)
1070 1070
     } else if (currentNode.nodetype.equals(DTD)) {
1071 1071
         storedDTD = true;
1072 1072
         if (currentNode.getNodeName().equals(DOCNAME))
......
1081 1081
         {
1082 1082
           dbSystemID = currentNode.getNodeData();
1083 1083
           // send out <!doctype .../>
1084
           if (dbDocName != null ) 
1084
           if (dbDocName != null )
1085 1085
           {
1086
              if ((dbPublicID!= null) && (dbSystemID != null)) 
1086
              if ((dbPublicID!= null) && (dbSystemID != null))
1087 1087
              {
1088
            
1089
                 out.print("<!DOCTYPE " + dbDocName+" PUBLIC \""+dbPublicID + 
1088

  
1089
                 out.print("<!DOCTYPE " + dbDocName+" PUBLIC \""+dbPublicID +
1090 1090
                       "\" \"" + dbSystemID + "\">");
1091
              } 
1092
              else 
1091
              }
1092
              else
1093 1093
              {
1094
            
1094

  
1095 1095
                out.print("<!DOCTYPE " + dbDocName + ">");
1096 1096
              }
1097 1097
           }
1098
           
1098

  
1099 1099
           //reset these variable
1100 1100
           dbDocName = null;
1101 1101
           dbPublicID = null;
1102 1102
           dbSystemID = null;
1103 1103
         }
1104
       
1104

  
1105 1105
      // Handle any other node type (do nothing)
1106 1106
      } else {
1107 1107
        // Any other types of nodes are not handled.
......
1109 1109
      }
1110 1110
      out.flush();
1111 1111
    }
1112
    
1112

  
1113 1113
    // Print the final end tag for the root element
1114 1114
    while(!openElements.empty())
1115 1115
    {
1116 1116
      NodeRecord currentElement = (NodeRecord)openElements.pop();
1117 1117
      util.debugMessage("\n POPPED: " + currentElement.nodename, 50);
1118 1118
      if ( currentElement.nodeprefix != null ) {
1119
        out.print("</" + currentElement.nodeprefix + ":" + 
1119
        out.print("</" + currentElement.nodeprefix + ":" +
1120 1120
                  currentElement.nodename + ">" );
1121 1121
      } else {
1122 1122
        out.print("</" + currentElement.nodename + ">" );
......
1124 1124
    }
1125 1125
    out.flush();
1126 1126
  }
1127
  
1128 1127

  
1129
  
1128

  
1129

  
1130 1130
  private boolean isRevisionOnly(DocumentIdentifier docid) throws Exception
1131 1131
  {
1132 1132
    //System.out.println("inRevisionOnly");
......
1149 1149
      {
1150 1150
        return false;
1151 1151
      }
1152
    
1152

  
1153 1153
      if(tablehasrows)
1154 1154
      {
1155 1155
        int r = rs.getInt(1);
......
1172 1172
      }
1173 1173
      // Get miss docid and rev, throw to McdDocNotFoundException
1174 1174
      String missDocId = MetaCatUtil.getDocIdFromString(docid.toString());
1175
      String missRevision = 
1175
      String missRevision =
1176 1176
                  MetaCatUtil.getRevisionStringFromString(docid.toString());
1177
      throw new McdbDocNotFoundException("the requested docid '" + 
1177
      throw new McdbDocNotFoundException("the requested docid '" +
1178 1178
                docid.toString() + "' does not exist", missDocId, missRevision);
1179 1179
    }//try
1180 1180
    finally
......
1184 1184
    }//finally
1185 1185
  }
1186 1186

  
1187
  private void getDocumentInfo(String docid) throws McdbException, 
1187
  private void getDocumentInfo(String docid) throws McdbException,
1188 1188
                                        AccessionNumberException, Exception
1189 1189
  {
1190 1190
    getDocumentInfo(new DocumentIdentifier(docid));
1191 1191
  }
1192
  
1192

  
1193 1193
  /**
1194 1194
   * Look up the document type information from the database
1195 1195
   *
......
1202 1202
    int serialNumber = -1;
1203 1203
    PreparedStatement pstmt = null;
1204 1204
    String table = "xml_documents";
1205
        
1205

  
1206 1206
    try
1207 1207
    {
1208 1208
      if(isRevisionOnly(docid))
......
1217 1217
    }
1218 1218
    catch(Exception e)
1219 1219
    {
1220
      
1221
      MetaCatUtil.debugMessage("error in DocumentImpl.getDocumentInfo: " + 
1220

  
1221
      MetaCatUtil.debugMessage("error in DocumentImpl.getDocumentInfo: " +
1222 1222
                          e.getMessage(), 30);
1223 1223
      throw e;
1224 1224
    }
1225
    
1226 1225

  
1227
    
1228
    try 
1226

  
1227

  
1228
    try
1229 1229
    {
1230 1230
      dbconn=DBConnectionPool.getDBConnection("DocumentImpl.getDocumentInfo");
1231 1231
      serialNumber=dbconn.getCheckOutSerialNumber();
......
1261 1261
        this.serverlocation = rs.getInt(8);
1262 1262
        this.publicaccess   = rs.getString(9);
1263 1263
        this.rev            = rs.getInt(10);
1264
      } 
1264
      }
1265 1265
      pstmt.close();
1266
      
1266

  
1267 1267
      //get doc  home server name
1268
      
1268

  
1269 1269
      pstmt = dbconn.prepareStatement("select server " +
1270 1270
                        "from xml_replication where serverid = ?");
1271 1271
      //because connection use twise here, so we need to increase one
......
1276 1276
      tableHasRows = rs.next();
1277 1277
      if (tableHasRows)
1278 1278
      {
1279
        
1279

  
1280 1280
          String server = rs.getString(1);
1281 1281
          //get homeserver name
1282 1282
          if(!server.equals("localhost"))
......
1288 1288
            this.docHomeServer=MetaCatUtil.getLocalReplicationServerName();
1289 1289
          }
1290 1290
          MetaCatUtil.debugMessage("server: "+docHomeServer, 50);
1291
        
1291

  
1292 1292
      }
1293 1293
      pstmt.close();
1294 1294
      if (this.doctype != null) {
......
1300 1300
        dbconn.increaseUsageCount(1);
1301 1301
        // Bind the values to the query
1302 1302
        pstmt.setString(1, doctype);
1303
  
1303

  
1304 1304
        pstmt.execute();
1305 1305
        rs = pstmt.getResultSet();
1306 1306
        tableHasRows = rs.next();
1307 1307
        if (tableHasRows) {
1308 1308
          this.system_id  = rs.getString(1);
1309 1309
          this.validateType = rs.getString(2);
1310
          
1311
        } 
1310

  
1311
        }
1312 1312
        pstmt.close();
1313 1313
      }
1314 1314
    } catch (SQLException e) {
1315
      System.out.println("error in DocumentImpl.getDocumentInfo: " + 
1315
      System.out.println("error in DocumentImpl.getDocumentInfo: " +
1316 1316
                          e.getMessage());
1317 1317
      e.printStackTrace(System.out);
1318 1318
      throw new McdbException("Error accessing database connection in " +
......
1340 1340
                                 docid.getIdentifier(), docid.getRev());
1341 1341
    }
1342 1342
  }
1343
  
1343

  
1344 1344
  /**
1345 1345
   * Look up the node data from the database, but some node would be shown
1346 1346
   * because of access control
1347 1347
   * @param rootnodeid the id of the root node of the node tree to look up
1348 1348
   * @param accessControl  the hashtable has control info
1349 1349
   */
1350
  private TreeSet getPartNodeRecordList(long rootnodeid, 
1351
                                        Hashtable accessControl) 
1350
  private TreeSet getPartNodeRecordList(long rootnodeid,
1351
                                        Hashtable accessControl)
1352 1352
                                        throws McdbException
1353 1353
  {
1354 1354
    PreparedStatement pstmt = null;
......
1364 1364
    String nodedata = null;
1365 1365
    String quotechar = dbAdapter.getStringDelimiter();
1366 1366
    String sql = "SELECT nodeid,parentnodeid,nodeindex, " +
1367
                 "nodetype,nodename,nodeprefix,nodedata " +               
1367
                 "nodetype,nodename,nodeprefix,nodedata " +
1368 1368
                  "FROM xml_nodes WHERE rootnodeid = ?";
1369
                  
1369

  
1370 1370
    // go through the access control for some nodes
1371 1371
     Enumeration en = accessControl.elements();
1372 1372
     while (en.hasMoreElements())
......
1375 1375
         long startId = tree.getStartNodeId();
1376 1376
         long endId  = tree.getEndNodeId();
1377 1377
         sql = sql +" AND(nodeid < " + startId + " OR nodeid > " +endId +")";
1378
         
1378

  
1379 1379
     }
1380 1380
     MetaCatUtil.debugMessage("The final query to select part node tree: " +
1381 1381
                              sql, 25);
1382 1382

  
1383
    try 
1383
    try
1384 1384
    {
1385 1385
      dbconn=DBConnectionPool.
1386 1386
                    getDBConnection("DocumentImpl.getPartNodeRecordList");
......
1392 1392
      pstmt.execute();
1393 1393
      ResultSet rs = pstmt.getResultSet();
1394 1394
      boolean tableHasRows = rs.next();
1395
      while (tableHasRows) 
1395
      while (tableHasRows)
1396 1396
      {
1397 1397
        nodeid = rs.getLong(1);
1398 1398
        parentnodeid = rs.getLong(2);
......
1409 1409

  
1410 1410
        // Advance to the next node
1411 1411
        tableHasRows = rs.next();
1412
      } 
1412
      }
1413 1413
      pstmt.close();
1414 1414

  
1415
    } 
1416
    catch (SQLException e) 
1415
    }
1416
    catch (SQLException e)
1417 1417
    {
1418 1418
      throw new McdbException("Error in DocumentImpl.getPartNodeRecordList " +
1419 1419
                              e.getMessage());
......
1434 1434
        DBConnectionPool.returnDBConnection(dbconn, serialNumber);
1435 1435
      }
1436 1436
    }
1437
      
1438 1437

  
1439
    if (!nodeRecordList.isEmpty()) 
1438

  
1439
    if (!nodeRecordList.isEmpty())
1440 1440
    {
1441
     
1441

  
1442 1442
      return nodeRecordList;
1443
    } 
1444
    else 
1443
    }
1444
    else
1445 1445
    {
1446
      
1446

  
1447 1447
      throw new McdbException("Error getting node data: " + docid);
1448 1448
    }
1449 1449
  }
1450
  
1450

  
1451 1451
  /**
1452 1452
   * Look up the node data from the database
1453 1453
   *
......
1474 1474
      serialNumber=dbconn.getCheckOutSerialNumber();
1475 1475
      pstmt =
1476 1476
      dbconn.prepareStatement("SELECT nodeid,parentnodeid,nodeindex, " +
1477
           "nodetype,nodename,nodeprefix,nodedata " +               
1477
           "nodetype,nodename,nodeprefix,nodedata " +
1478 1478
           "FROM xml_nodes WHERE rootnodeid = ?");
1479 1479

  
1480 1480
      // Bind the values to the query
......
1499 1499

  
1500 1500
        // Advance to the next node
1501 1501
        tableHasRows = rs.next();
1502
      } 
1502
      }
1503 1503
      pstmt.close();
1504 1504

  
1505 1505
    } catch (SQLException e) {
......
1522 1522
        DBConnectionPool.returnDBConnection(dbconn, serialNumber);
1523 1523
      }
1524 1524
    }
1525
  
1525

  
1526 1526
    return nodeRecordList;
1527
   
1527

  
1528 1528
  }
1529
  
1529

  
1530 1530
// NOT USED ANY MORE
1531
//  /** creates SQL code and inserts new document into DB connection 
1531
//  /** creates SQL code and inserts new document into DB connection
1532 1532
//   default serverCode of 1*/
1533 1533
//  private void writeDocumentToDB(String action, String user)
1534 1534
//               throws SQLException, Exception
......
1537 1537
//  }
1538 1538

  
1539 1539
 /** creates SQL code and inserts new document into DB connection */
1540
  private void writeDocumentToDB(String action, String user, String pub, 
1541
                                 String catalogid, int serverCode) 
1540
  private void writeDocumentToDB(String action, String user, String pub,
1541
                                 String catalogid, int serverCode)
1542 1542
               throws SQLException, Exception {
1543 1543
    String sysdate = dbAdapter.getDateTimeFunction();
1544 1544

  
......
1548 1548
      if (action.equals("INSERT")) {
1549 1549
        //AccessionNumber ac = new AccessionNumber();
1550 1550
        //this.docid = ac.generate(docid, "INSERT");
1551
        
1551

  
1552 1552
        pstmt = connection.prepareStatement(
1553 1553
                "INSERT INTO xml_documents " +
1554
                "(docid, rootnodeid, docname, doctype, " + 
1555
                "user_owner, user_updated, date_created, date_updated, " + 
1554
                "(docid, rootnodeid, docname, doctype, " +
1555
                "user_owner, user_updated, date_created, date_updated, " +
1556 1556
                "public_access, catalog_id, server_location, rev) " +
1557
                "VALUES (?, ?, ?, ?, ?, ?, " + sysdate + ", " + sysdate + 
1557
                "VALUES (?, ?, ?, ?, ?, ?, " + sysdate + ", " + sysdate +
1558 1558
                ", ?, ?, ?, ?)");
1559 1559
        // Increase dbconnection usage count
1560 1560
        connection.increaseUsageCount(1);
1561
        
1562
        //note that the server_location is set to 1. 
1561

  
1562
        //note that the server_location is set to 1.
1563 1563
        //this means that "localhost" in the xml_replication table must
1564 1564
        //always be the first entry!!!!!
1565
        
1565

  
1566 1566
        // Bind the values to the query
1567 1567
        pstmt.setString(1, this.docid);
1568 1568
        pstmt.setLong(2, rootnodeid);
......
1581 1581
        }*/
1582 1582
        pstmt.setString(8, catalogid);
1583 1583
        pstmt.setInt(9, serverCode);
1584
        pstmt.setInt(10, Integer.parseInt(updatedVersion)); 
1584
        pstmt.setInt(10, Integer.parseInt(updatedVersion));
1585 1585
      } else if (action.equals("UPDATE")) {
1586 1586

  
1587 1587
        // Save the old document publicaccessentry in a backup table
......
1599 1599
        }
1600 1600
        else
1601 1601
        {
1602
          //set the user specified revision 
1602
          //set the user specified revision
1603 1603
          thisrev=Integer.parseInt(updatedVersion);
1604 1604
        }
1605 1605
        MetaCatUtil.debugMessage("final revsion is: "+thisrev, 40);
1606
        boolean useXMLIndex = 
1606
        boolean useXMLIndex =
1607 1607
            (new Boolean(MetaCatUtil.getOption("usexmlindex"))).booleanValue();
1608 1608
        if (useXMLIndex) {
1609 1609
            MetaCatUtil.debugMessage("before delete", 40);
......
1614 1614
            MetaCatUtil.debugMessage("after delete", 40);
1615 1615
            // Increase dbconnection usage count
1616 1616
            connection.increaseUsageCount(1);
1617
            
1617

  
1618 1618
            pstmt.execute();
1619
            pstmt.close();    
1619
            pstmt.close();
1620 1620
        }
1621
        
1621

  
1622 1622
        // Update the new document to reflect the new node tree
1623 1623
        pstmt = connection.prepareStatement(
1624 1624
            "UPDATE xml_documents " +
......
1652 1652

  
1653 1653
      // Do the insertion
1654 1654
      pstmt.execute();
1655
      
1655

  
1656 1656
      pstmt.close();
1657 1657

  
1658 1658
    } catch (SQLException sqle) {
......
1679 1679
                             String action, String docid, String user,
1680 1680
                             String[] groups )
1681 1681
                throws Exception {
1682
                  
1682

  
1683 1683
    Reader dtd = null;
1684 1684
    if ( dtdfilename != null ) {
1685 1685
      dtd = new FileReader(new File(dtdfilename).toString());
......
1690 1690

  
1691 1691
  public static String write(DBConnection conn,Reader xml,String pub,Reader dtd,
1692 1692
                             String action, String docid, String user,
1693
                             String[] groups, String ruleBase, 
1693
                             String[] groups, String ruleBase,
1694 1694
                             boolean needValidation)
1695 1695
                throws Exception {
1696
    //this method will be called in handleUpdateOrInsert method 
1696
    //this method will be called in handleUpdateOrInsert method
1697 1697
    //in MetacatServlet class and now is wrapper into documentImple
1698 1698
    // get server location for this doc
1699 1699
    int serverLocation=getServerLocationNumber(docid);
......
1701 1701
                 ruleBase, needValidation);
1702 1702
  }
1703 1703

  
1704
 
1705
  
1704

  
1705

  
1706 1706
  /**
1707 1707
   * Write an XML file to the database, given a Reader
1708 1708
   *
......
1719 1719
   * @param override flag to stop insert replication checking.
1720 1720
   *        if override = true then a document not belonging to the local server
1721 1721
   *        will not be checked upon update for a file lock.
1722
   *        if override = false then a document not from this server, upon 
1722
   *        if override = false then a document not from this server, upon
1723 1723
   *        update will be locked and version checked.
1724 1724
   */
1725 1725

  
......
1736 1736
    AccessionNumber ac = new AccessionNumber(accnum, action);
1737 1737
    String docid = ac.getDocid();
1738 1738
    String rev = ac.getRev();
1739
    MetaCatUtil.debugMessage("action: " + action + " servercode: " + 
1739
    MetaCatUtil.debugMessage("action: " + action + " servercode: " +
1740 1740
                             serverCode + " override: " + override, 10);
1741
                     
1741

  
1742 1742
    if((serverCode != 1 && action.equals("UPDATE")) && !override)
1743 1743
    { //if this document being written is not a resident of this server then
1744 1744
      //we need to try to get a lock from it's resident server.  If the
1745 1745
      //resident server will not give a lock then we send the user a message
1746 1746
      //saying that he/she needs to download a new copy of the file and
1747 1747
      //merge the differences manually.
1748
      int istreamInt; 
1748
      int istreamInt;
1749 1749
      char istreamChar;
1750
     
1750

  
1751 1751
      // check for 'write' permission for 'user' to update this document
1752 1752
      if ( !hasWritePermission(user, groups, accnum) ) {
1753
        throw new Exception("User " + user + 
1753
        throw new Exception("User " + user +
1754 1754
              " does not have permission to update XML Document #" + accnum);
1755
      }        
1756
  
1755
      }
1756

  
1757 1757
      DocumentIdentifier id = new DocumentIdentifier(accnum);
1758 1758
      String updaterev = id.getRev();
1759 1759
      String server=MetacatReplication.getServerNameForServerCode(serverCode);
1760 1760
      MetacatReplication.replLog("attempting to lock " + accnum);
1761 1761
      URL u = new URL("https://" + server + "?server="+
1762
        MetaCatUtil.getLocalReplicationServerName()+"&action=getlock&updaterev=" 
1762
        MetaCatUtil.getLocalReplicationServerName()+"&action=getlock&updaterev="
1763 1763
           +updaterev + "&docid=" + docid);
1764 1764
      //System.out.println("sending message: " + u.toString());
1765 1765
      String serverResStr = MetacatReplication.getURLContent(u);
......
1767 1767
      if(openingtag.equals("<lockgranted>"))
1768 1768
      {//the lock was granted go ahead with the insert
1769 1769
        XMLReader parser = null;
1770
        try 
1770
        try
1771 1771
        {
1772 1772
          //System.out.println("In lockgranted");
1773 1773
          MetacatReplication.replLog("lock granted for " + accnum + " from " +
......
1775 1775
          /*XMLReader parser = initializeParser(conn, action, docid, updaterev,
1776 1776
                               validate, user, groups, pub, serverCode, dtd);*/
1777 1777
          parser = initializeParser(conn, action, docid, updaterev,
1778
                                        user, groups, pub, serverCode, 
1779
                                        dtd,ruleBase, needValidation); 
1778
                                        user, groups, pub, serverCode,
1779
                                        dtd,ruleBase, needValidation);
1780 1780
          conn.setAutoCommit(false);
1781
          parser.parse(new InputSource(xml)); 
1781
          parser.parse(new InputSource(xml));
1782 1782
          conn.commit();
1783 1783
          conn.setAutoCommit(true);
1784
        } 
1785
        catch (Exception e) 
1784
        }
1785
        catch (Exception e)
1786 1786
        {
1787 1787
          conn.rollback();
1788 1788
          conn.setAutoCommit(true);
......
1798 1798
          }
1799 1799
          throw e;
1800 1800
        }
1801
        // run write into access db base one relation table and access object 
1801
        // run write into access db base one relation table and access object
1802 1802
        runRelationAndAccessHandler(accnum, user, groups, serverCode);
1803
        
1803

  
1804 1804
        // Force replication the docid
1805 1805
        ForceReplicationHandler frh = new ForceReplicationHandler
1806 1806
                                                          (accnum, true, null);
1807 1807
        return(accnum);
1808
   
1808

  
1809 1809
      }
1810 1810

  
1811 1811
      else if(openingtag.equals("<filelocked>"))
......
1831 1831
                            "merge your changes and try again.");
1832 1832
      }
1833 1833
    }
1834
    
1834

  
1835 1835
    if ( action.equals("UPDATE") ) {
1836 1836
      // check for 'write' permission for 'user' to update this document
1837 1837

  
1838 1838
      if ( !hasWritePermission(user, groups, accnum) ) {
1839
        throw new Exception("User " + user + 
1839
        throw new Exception("User " + user +
1840 1840
              " does not have permission to update XML Document #" + accnum);
1841
      }          
1841
      }
1842 1842
    }
1843 1843
    XMLReader parser = null;
1844
    try 
1845
    { 
1846
      
1847
      parser = initializeParser(conn, action, docid, rev, 
1848
                                          user, groups, pub, serverCode, 
1844
    try
1845
    {
1846

  
1847
      parser = initializeParser(conn, action, docid, rev,
1848
                                          user, groups, pub, serverCode,
1849 1849
                                          dtd, ruleBase, needValidation);
1850
   
1850

  
1851 1851
      conn.setAutoCommit(false);
1852 1852
      parser.parse(new InputSource(xml));
1853 1853
      conn.commit();
1854 1854
      conn.setAutoCommit(true);
1855
    } 
1856
    catch (Exception e) 
1855
    }
1856
    catch (Exception e)
1857 1857
    {
1858 1858
      conn.rollback();
1859 1859
      conn.setAutoCommit(true);
......
1869 1869
       }
1870 1870
      throw e;
1871 1871
    }
1872
    
1873
    // run access db base on relation table and access object       
1872

  
1873
    // run access db base on relation table and access object
1874 1874
    runRelationAndAccessHandler(accnum, user, groups, serverCode);
1875
    
1875

  
1876 1876
    // Force replicate out the new document to each server in our server list.
1877 1877
    // Start the thread to replicate this new document out to the other servers
1878 1878
    // true mean it is xml document
1879 1879
    // null is because no metacat notify the force replication.
1880 1880
    ForceReplicationHandler frh = new ForceReplicationHandler
1881 1881
                                                  (accnum, action, true, null);
1882
      
1883
   
1882

  
1883

  
1884 1884
    MetaCatUtil.debugMessage("Conn Usage count after writting: "
1885
                                                      +conn.getUsageCount(),50); 
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff