Project

General

Profile

Revision 1422

Added by Jing Tao over 18 years ago

Now, eml parser can support pulling out access control for document level and subtree level.

View differences:

src/edu/ucsb/nceas/metacat/EmlSAXHandler.java
58 58
   private boolean processAdditionalAccess = false;
59 59
   private AccessSection accessObject= null;
60 60
   private AccessRule accessRule = null;
61
   private Vector accessObjectList = new Vector(); // store every access rule
61 62
   private Hashtable topLevelAccessControlMap = new Hashtable();
62 63
   private Hashtable additionalAccessControlMap = new Hashtable();
63 64
   private Vector describesId = new Vector(); // store the ids in
......
128 129
     DBSAXNode currentNode = null;
129 130

  
130 131
     // Get a reference to the parent node for the id
131
     try {
132
     try 
133
     {
132 134
       parentNode = (DBSAXNode)nodeStack.peek();
133
     } catch (EmptyStackException e) {
135
     } 
136
     catch (EmptyStackException e) 
137
     {
134 138
       parentNode = null;
135 139
     }
136 140
     
......
294 298
       // if it is in addtionalmetacat
295 299
       if (parentNode.getTagName() == ADDITIONALMETADATA)
296 300
       {
297
          processAdditionalAccess = true;
301
         processAdditionalAccess = true;
298 302
        
299 303
       }
300 304
       else
......
312 316
       accessObject.setAccessSectionId(accessId);
313 317
       
314 318
     }
315
     
316
    
317 319
     // Set up a access rule for allow
318
     if (parentNode.getTagName() != null && 
320
     else if (parentNode.getTagName() != null && 
319 321
       (parentNode.getTagName()).equals(ACCESS) && localName.equals(ALLOW))
320 322
     {
321 323
      
......
333 335
       //set permission type "allow"
334 336
       accessRule.setPermissionType(DENY);
335 337
     }
338
     // refernce access, then set up access object (setcion) null
339
     else if (parentNode.getTagName() != null 
340
           && (parentNode.getTagName()).equals(ACCESS) 
341
           && localName.equals(REFERENCES))
342
     {
343
       accessObject = null;
344
     }
336 345
   
337 346
     // Add the node to the stack, so that any text data can be
338 347
     // added as it is encountered
339 348
     nodeStack.push(currentNode);
340 349
     // Add the node to the vector used by thread for writing XML Index
341 350
     nodeIndex.addElement(currentNode);
351
    
342 352

  
343 353
  }
344 354
  
......
408 418
       }
409 419
       else if (currentTag.equals(REFERENCES) && processAdditionalAccess)
410 420
       {
421
       
411 422
          // get reference 
412 423
          data = (textBuffer.toString()).trim();
413
          additionalAccessControlMap.put(docid, data);
424
          // put describeids and reference into additional access mapping
425
          for ( int i=0; i<describesId.size(); i++)
426
          {
427
            String subId = (String)describesId.elementAt(i);
428
            MetaCatUtil.debugMessage("sub id in seting additional mapping: "
429
                                    +subId, 25);
430
            MetaCatUtil.debugMessage("refrence id in setting additional mapping: "
431
                                    +data, 25);
432
            if (subId != null)
433
            {
434
              additionalAccessControlMap.put(subId, data);
435
            }
436
          }
437
          
414 438
       }
415 439
       // write text to db
416 440
       MetaCatUtil.debugMessage("Write text into DB in End Element", 50);
......
424 448
     textBuffer = new StringBuffer();
425 449
     
426 450
     // hand sub stree stuff
427
     SubTree tree = (SubTree)subTreeInfoStack.peek();// get last subtree
428
     if (tree != null && tree.getStartElementName() != null && 
451
     if (!subTreeInfoStack.empty())
452
     {
453
       SubTree tree = (SubTree)subTreeInfoStack.peek();// get last subtree
454
       if (tree != null && tree.getStartElementName() != null && 
429 455
         (tree.getStartElementName()).equals(currentTag))
430
     {
431
       // find the end of sub tree and set the end node id
432
       tree.setEndNodeId(endNodeId);
433
       // add the subtree into the final store palace
434
       subTreeList.add(tree);
435
       // get rid of it from stack
436
       subTreeInfoStack.pop();
437
     }
456
       {
457
         // find the end of sub tree and set the end node id
458
         tree.setEndNodeId(endNodeId);
459
         // add the subtree into the final store palace
460
         subTreeList.add(tree);
461
         // get rid of it from stack
462
         subTreeInfoStack.pop();
463
       }//if
464
     }//if
438 465

  
439 466
     // access stuff
440 467
     if (currentTag.equals(ALLOW) || currentTag.equals(DENY))
......
450 477
     {
451 478
       // finish parse a access setction and assign it to new one
452 479
       AccessSection newAccessObject = accessObject;
453
       if (processTopLeverAccess)
480
       if (newAccessObject != null)
454 481
       {
455
         // top level access control will handle whole document -docid
456
         topLevelAccessControlMap.put(docid, newAccessObject);
457
         // reset processtopleveraccess tag
458
         processTopLeverAccess =false;
459
       }
460
       else if (processAdditionalAccess)
461
       {
462
         // for additional control
463
         // put everything in describes value and access object into hash
464
         for ( int i=0; i<describesId.size(); i++)
465
         {
466
           String subId = (String)describesId.elementAt(i);
467
           if (subId != null)
468
           {
469
             additionalAccessControlMap.put(subId, newAccessObject);
470
           }
471
         }
472
       }
473
       
482
        // add the accessSection into a vector to store it
483
        accessObjectList.add(newAccessObject);
484
        if (processTopLeverAccess)
485
        {
486
          // top level access control will handle whole document -docid
487
          topLevelAccessControlMap.put(docid, newAccessObject);
488
          // reset processtopleveraccess tag
489
          
490
        }//if
491
        else if (processAdditionalAccess)
492
        {
493
          // for additional control
494
          // put everything in describes value and access object into hash
495
          for ( int i=0; i<describesId.size(); i++)
496
          {
497
            String subId = (String)describesId.elementAt(i);
498
            if (subId != null)
499
            {
500
              additionalAccessControlMap.put(subId, newAccessObject);
501
            }//if
502
          }//for
503
         
504
        }//if
505
       }//if
474 506
       //reset access section object
475 507
       accessObject = null;
508
       // reset flag
509
       processAdditionalAccess =false;
510
       processTopLeverAccess =false;
476 511
     }
477 512
     else if (currentTag.equals(ADDITIONALMETADATA))
478 513
     {
479 514
        //reset describesId
515
        describesId = null;
480 516
        describesId = new Vector();
481 517
     }
482 518
   }
......
508 544
    //write top leve access rule
509 545
    writeTopLevelAccessRuleToDB();
510 546
    //write additional access rule
511
   // writeAddtionalAccessRuleToDB();
547
    writeAddtionalAccessRuleToDB();
512 548
  }//writeAccessRuleToDB
513 549
   
514 550
  /* The method to write top level access rule into db. */
......
517 553
    
518 554
    // for top document level
519 555
    Object accessSection = topLevelAccessControlMap.get(docid);
556
    boolean top = true;
557
    String subSectionId = null;
520 558
    // if accessSection is not null and isnot reference
521 559
    if( accessSection != null && (accessSection instanceof AccessSection) )
522 560
    {
523
       String subSectionId = null;
524
       boolean top = true;
525 561
       AccessSection accessObj = (AccessSection)accessSection;
526 562
       writeGivenAccessRuleIntoDB(accessObj, top, subSectionId);
527 563
    }//if
528 564
    else
529 565
    {
530
      // this is a reference
566
      // this is a reference and go trough the vector which contains all
567
      // access object
568
      String referenceId = (String) accessSection;
569
      MetaCatUtil.debugMessage("referered id for top access: "+ 
570
                               referenceId, 25);
571
      for (int i=0; i<accessObjectList.size(); i++)
572
      {
573
        AccessSection accessObj = (AccessSection)accessObjectList.elementAt(i);
574
        String accessObjId = accessObj.getAccessSectionId();
575
        if (referenceId != null && accessObj != null &&
576
            referenceId.equals(accessObjId))
577
        {
578
          writeGivenAccessRuleIntoDB(accessObj, top, subSectionId);
579
        }
580
      }
581
      
531 582
    }
532 583
    
533 584
  }//writeTopLevelAccessRuletoDB
......
547 598
       {
548 599
         // Get subsection id
549 600
          String subSectionId = (String)en.nextElement();
601
          MetaCatUtil.debugMessage("sub section id in additional access mapping"
602
                                   +"(go through: "+ subSectionId);
550 603
          
551 604
          if (subSectionId == null)
552 605
          {
......
569 622
          else
570 623
          {
571 624
            //this is reference
572
          }
625
            // this is a reference and go trough the vector which contains all
626
            // access object
627
            String referenceId = (String) accessSection;
628
            MetaCatUtil.debugMessage("referered id for additional access "+
629
                                     "mapping(go through): "+ referenceId, 25);
630
            for (int i=0; i<accessObjectList.size(); i++)
631
            {
632
              AccessSection accessObj = 
633
                                (AccessSection)accessObjectList.elementAt(i);
634
              String accessObjId = accessObj.getAccessSectionId();
635
              MetaCatUtil.debugMessage("access obj id in the list(go through): "
636
                                        + accessObjId, 25);
637
              if (referenceId != null && accessObj != null &&
638
                  referenceId.equals(accessObjId))
639
              {
640
                writeGivenAccessRuleIntoDB(accessObj, topLevel, subSectionId);
641
              }//if
642
           }//for
643
      
644
         }//else
573 645
       }//try
574 646
       catch (Exception e)
575 647
       {
648
         
576 649
         MetaCatUtil.debugMessage("error in EmlSAXHandler.writeAddtionalAccess"
577 650
                                   + ": "+e.getMessage(), 30);
651
         throw new SAXException(e.getMessage());
578 652
       }
579 653
    }//while
580 654
  }//writeAccessRuletoDB
......
600 674
      }
601 675
      else
602 676
      {
603
        sql ="INSERT INTO xml_access (docid, principal_name, "+ 
604
            "permission, perm_type, perm_order, accessfileid, sectionid) VALUES" 
605
             +" (?, ?, ?, ?, ?, ?, ?)";
677
        sql ="INSERT INTO xml_access (docid,principal_name, "+ 
678
             "permission, perm_type, perm_order, accessfileid, subtreeid, "+
679
             " startnodeid, endnodeid) VALUES" +
680
             " (?, ?, ?, ?, ?, ?, ?, ?, ?)";
606 681
      }
607 682
      try 
608 683
      {
......
612 687
        connection.increaseUsageCount(1);
613 688
        // Bind the values to the query
614 689
        pstmt.setString(1, docid);
615
        MetaCatUtil.debugMessage("Docid in accesstable: "+ docid);
690
        MetaCatUtil.debugMessage("Docid in accesstable: "+ docid, 25);
616 691
        pstmt.setString(6, docid);
617
        MetaCatUtil.debugMessage("Accessfileid in accesstable: "+ docid);
692
        MetaCatUtil.debugMessage("Accessfileid in accesstable: "+ docid, 25);
618 693
        pstmt.setString(5, permOrder);
619
        MetaCatUtil.debugMessage("PermOder in accesstable: "+ permOrder);
694
        MetaCatUtil.debugMessage("PermOder in accesstable: "+ permOrder, 25);
620 695
        // if it is not top level, set subsection id
621 696
        if (!topLevel)
622 697
        {
698
          long startNodeId = 0;
699
          long endNodeId = 0;
700
          // for subtree should specify the
701
          if (subSectionId == null)
702
          {
703
            throw new SAXException("The subsection is null");
704
          }
705
          // go through the substree list vector and found the start node id
706
          // and stop node id for this subtree id
707
          for (int i=0; i<subTreeList.size(); i++)
708
          {
709
            SubTree tree = (SubTree)subTreeList.elementAt(i);
710
            String subTreeId = tree.getSubTreeId();
711
            MetaCatUtil.debugMessage("subtree id in the list(go throug: "+
712
                                      subTreeId, 25);
713
            if (subSectionId.equals(subTreeId))
714
            {
715
              startNodeId = tree.getStartNodeId();
716
              endNodeId = tree.getEndNodeId(); 
717
            }//if
718
          }//for
719
          if (startNodeId == 0 || endNodeId == 0)
720
          {
721
            throw new SAXException("Could find the subtree"
722
                                   + "for this id: "+subSectionId);
723
          }
623 724
          pstmt.setString(7, subSectionId);
624 725
          MetaCatUtil.debugMessage("SubSectionId in accesstable: "+ 
625
                                    subSectionId);
726
                                    subSectionId, 25);
727
          pstmt.setLong(8, startNodeId);
728
          MetaCatUtil.debugMessage("Start node id is: " + startNodeId, 25);
729
          pstmt.setLong(9, endNodeId);
730
          MetaCatUtil.debugMessage("End node id is: " + endNodeId, 25);
731
          
626 732
        }
627 733
      
628 734
        Vector accessRules = accessSection.getAccessRules();
......
633 739
          String permType = rule.getPermissionType();
634 740
          int permission = rule.getPermission();
635 741
          pstmt.setInt(3, permission);
636
          MetaCatUtil.debugMessage("permission in accesstable: "+ permission);
742
          MetaCatUtil.debugMessage("permission in accesstable: "+ permission, 25);
637 743
          pstmt.setString(4, permType);
638
          MetaCatUtil.debugMessage("Permtype in accesstable: "+ permType);
744
          MetaCatUtil.debugMessage("Permtype in accesstable: "+ permType, 25);
639 745
          // go through every principle in rule
640 746
          Vector nameVector = rule.getPrincipal();
641 747
          for ( int j = 0; j < nameVector.size(); j++ ) 
642 748
          {
643 749
            String prName = (String)nameVector.elementAt(j);
644 750
            pstmt.setString(2, prName);
645
            MetaCatUtil.debugMessage("Principal in accesstable: "+prName);
751
            MetaCatUtil.debugMessage("Principal in accesstable: "+prName, 25);
646 752
            pstmt.execute();
647 753
          }//for
648 754
        }//for

Also available in: Unified diff