Revision 1473
Added by Jing Tao over 21 years ago
src/edu/ucsb/nceas/metacat/EmlSAXHandler.java | ||
---|---|---|
62 | 62 |
private AccessRule accessRule = null; |
63 | 63 |
private Vector accessObjectList = new Vector(); // store every access rule |
64 | 64 |
private Hashtable topLevelAccessControlMap = new Hashtable(); |
65 |
private Hashtable additionalAccessControlMap = new Hashtable(); |
|
65 |
private Hashtable additionalAccessControlMap = new Hashtable();// store |
|
66 |
//subtree access for single |
|
67 |
// additionalmetacat |
|
68 |
private Vector additionalAccessMapList = new Vector();// store maps for |
|
69 |
// every addionalmetadata |
|
66 | 70 |
private Vector describesId = new Vector(); // store the ids in |
67 | 71 |
//additionalmetadata/describes |
68 | 72 |
private Stack subTreeInfoStack = new Stack(); |
... | ... | |
322 | 326 |
//set permission type "allow" |
323 | 327 |
accessRule.setPermissionType(DENY); |
324 | 328 |
} |
325 |
// refernce access, then set up access object (setcion) null |
|
326 |
else if (parentNode.getTagName() != null |
|
327 |
&& (parentNode.getTagName()).equals(ACCESS) |
|
328 |
&& localName.equals(REFERENCES)) |
|
329 |
{ |
|
330 |
accessObject = null; |
|
331 |
} |
|
332 |
|
|
333 |
|
|
329 |
|
|
334 | 330 |
// Add the node to the stack, so that any text data can be |
335 | 331 |
// added as it is encountered |
336 | 332 |
nodeStack.push(currentNode); |
... | ... | |
396 | 392 |
data = (textBuffer.toString()).trim(); |
397 | 393 |
describesId.add(data); |
398 | 394 |
} |
399 |
else if (currentTag.equals(REFERENCES) && processTopLeverAccess) |
|
395 |
else if (currentTag.equals(REFERENCES) && |
|
396 |
(processTopLeverAccess||processAdditionalAccess)) |
|
400 | 397 |
{ |
401 | 398 |
// get reference |
402 | 399 |
data = (textBuffer.toString()).trim(); |
403 |
// insert docid and reference id into toplevlerAccess
|
|
404 |
topLevelAccessControlMap.put(docid, data);
|
|
400 |
// put reference id into accessSection
|
|
401 |
accessObject.setReferences(data);
|
|
405 | 402 |
|
406 | 403 |
} |
407 |
else if (currentTag.equals(REFERENCES) && processAdditionalAccess) |
|
408 |
{ |
|
409 |
|
|
410 |
// get reference |
|
411 |
data = (textBuffer.toString()).trim(); |
|
412 |
// put describeids and reference into additional access mapping |
|
413 |
for ( int i=0; i<describesId.size(); i++) |
|
414 |
{ |
|
415 |
String subId = (String)describesId.elementAt(i); |
|
416 |
MetaCatUtil.debugMessage("sub id in seting additional mapping: " |
|
417 |
+subId, 25); |
|
418 |
MetaCatUtil.debugMessage("refrence id in setting additional mapping: " |
|
419 |
+data, 25); |
|
420 |
if (subId != null) |
|
421 |
{ |
|
422 |
additionalAccessControlMap.put(subId, data); |
|
423 |
} |
|
424 |
} |
|
425 |
|
|
426 |
} |
|
427 | 404 |
// write text to db if it is not inline data |
428 | 405 |
if (!localName.equals(INLINE)) |
429 | 406 |
{ |
... | ... | |
432 | 409 |
} |
433 | 410 |
else |
434 | 411 |
{ |
435 |
MetaCatUtil.debugMessage("Write inline data into file system", 25);
|
|
412 |
MetaCatUtil.debugMessage("Write inline data into file system", 35);
|
|
436 | 413 |
// write inline data into file system and return file name |
437 | 414 |
textBuffer = writeInlineDataIntoFile(textBuffer); |
438 | 415 |
// write file name into db |
... | ... | |
479 | 456 |
if (newAccessObject != null) |
480 | 457 |
{ |
481 | 458 |
// add the accessSection into a vector to store it |
482 |
accessObjectList.add(newAccessObject); |
|
459 |
// if it is not a reference, need to store it |
|
460 |
if ( newAccessObject.getReferences() == null) |
|
461 |
{ |
|
462 |
accessObjectList.add(newAccessObject); |
|
463 |
} |
|
483 | 464 |
if (processTopLeverAccess) |
484 | 465 |
{ |
485 | 466 |
// top level access control will handle whole document -docid |
... | ... | |
491 | 472 |
{ |
492 | 473 |
// for additional control |
493 | 474 |
// put everything in describes value and access object into hash |
475 |
|
|
494 | 476 |
for ( int i=0; i<describesId.size(); i++) |
495 | 477 |
{ |
478 |
|
|
496 | 479 |
String subId = (String)describesId.elementAt(i); |
497 | 480 |
if (subId != null) |
498 | 481 |
{ |
499 | 482 |
additionalAccessControlMap.put(subId, newAccessObject); |
500 | 483 |
}//if |
501 | 484 |
}//for |
485 |
// add this hashtable in to vector |
|
502 | 486 |
|
487 |
additionalAccessMapList.add(additionalAccessControlMap); |
|
488 |
// reset this hashtable in order to store another additional |
|
489 |
//accesscontrol |
|
490 |
additionalAccessControlMap = null; |
|
491 |
additionalAccessControlMap = new Hashtable(); |
|
503 | 492 |
}//if |
504 | 493 |
}//if |
505 | 494 |
//reset access section object |
... | ... | |
556 | 545 |
Object accessSection = topLevelAccessControlMap.get(docid); |
557 | 546 |
boolean top = true; |
558 | 547 |
String subSectionId = null; |
559 |
// if accessSection is not null and isnot reference |
|
560 |
if( accessSection != null && (accessSection instanceof AccessSection) ) |
|
548 |
if ( accessSection != null ) |
|
561 | 549 |
{ |
562 |
AccessSection accessObj = (AccessSection)accessSection; |
|
563 |
writeGivenAccessRuleIntoDB(accessObj, top, subSectionId); |
|
550 |
AccessSection accessSectionObj = (AccessSection)accessSection; |
|
551 |
// if accessSection is not null and is not reference |
|
552 |
if ( accessSectionObj.getReferences() == null) |
|
553 |
{ |
|
554 |
writeGivenAccessRuleIntoDB(accessSectionObj, top, subSectionId); |
|
555 |
} |
|
556 |
else |
|
557 |
{ |
|
558 |
|
|
559 |
// this is a reference and go trough the vector which contains all |
|
560 |
// access object |
|
561 |
String referenceId = accessSectionObj.getReferences(); |
|
562 |
boolean findAccessObject = false; |
|
563 |
MetaCatUtil.debugMessage("referered id for top access: "+ |
|
564 |
referenceId, 35); |
|
565 |
for (int i=0; i<accessObjectList.size(); i++) |
|
566 |
{ |
|
567 |
AccessSection accessObj = (AccessSection)accessObjectList.elementAt(i); |
|
568 |
String accessObjId = accessObj.getAccessSectionId(); |
|
569 |
if (referenceId != null && accessObj != null && |
|
570 |
referenceId.equals(accessObjId)) |
|
571 |
{ |
|
572 |
writeGivenAccessRuleIntoDB(accessObj, top, subSectionId); |
|
573 |
findAccessObject = true; |
|
574 |
} |
|
575 |
}//for |
|
576 |
// if we couldn't find an access subtree id for this reference id |
|
577 |
if (!findAccessObject) |
|
578 |
{ |
|
579 |
throw new SAXException("The referenceid: " + referenceId + |
|
580 |
" is not access subtree"); |
|
581 |
}//if |
|
582 |
}//else |
|
583 |
|
|
564 | 584 |
}//if |
565 | 585 |
else |
566 | 586 |
{ |
567 |
// this is a reference and go trough the vector which contains all |
|
568 |
// access object |
|
569 |
String referenceId = (String) accessSection; |
|
570 |
MetaCatUtil.debugMessage("referered id for top access: "+ |
|
571 |
referenceId, 25); |
|
572 |
for (int i=0; i<accessObjectList.size(); i++) |
|
573 |
{ |
|
574 |
AccessSection accessObj = (AccessSection)accessObjectList.elementAt(i); |
|
575 |
String accessObjId = accessObj.getAccessSectionId(); |
|
576 |
if (referenceId != null && accessObj != null && |
|
577 |
referenceId.equals(accessObjId)) |
|
578 |
{ |
|
579 |
writeGivenAccessRuleIntoDB(accessObj, top, subSectionId); |
|
580 |
} |
|
581 |
} |
|
582 |
|
|
587 |
// couldn't find a access section object and throw an exception |
|
588 |
throw new SAXException("couldn't find access control for document: "+ |
|
589 |
docid); |
|
583 | 590 |
} |
584 | 591 |
|
585 | 592 |
}//writeTopLevelAccessRuletoDB |
... | ... | |
589 | 596 |
{ |
590 | 597 |
|
591 | 598 |
PreparedStatement pstmt = null; |
599 |
boolean topLevel =false; |
|
600 |
// go through the vector which contains the additional access control |
|
601 |
//hashtable. Each hashtable has info for one additonalmetadata container |
|
602 |
for (int j= 0; j < additionalAccessMapList.size(); j++) |
|
603 |
{ |
|
604 |
|
|
605 |
Hashtable accessControlMap = |
|
606 |
(Hashtable)additionalAccessMapList.elementAt(j); |
|
592 | 607 |
// additional access rule |
593 |
Enumeration en = additionalAccessControlMap.keys(); |
|
594 |
boolean topLevel =false; |
|
595 |
|
|
608 |
Enumeration en = accessControlMap.keys(); |
|
609 |
|
|
596 | 610 |
while(en.hasMoreElements()) |
597 |
{ |
|
611 |
{
|
|
598 | 612 |
try |
599 | 613 |
{ |
600 | 614 |
// Get subsection id |
601 | 615 |
String subSectionId = (String)en.nextElement(); |
602 | 616 |
MetaCatUtil.debugMessage("sub section id in additional access mapping" |
603 |
+"(go through: "+ subSectionId);
|
|
617 |
+"(go through): "+ subSectionId, 35);
|
|
604 | 618 |
|
605 | 619 |
if (subSectionId == null) |
606 | 620 |
{ |
607 |
// if id is null ignore the following lines
|
|
608 |
continue;
|
|
621 |
// if id is null, terminate the program
|
|
622 |
throw new SAXException("subtree id is null");
|
|
609 | 623 |
} |
610 | 624 |
// Get AccessSection Object |
611 |
Object accessSection = additionalAccessControlMap.get(subSectionId);
|
|
612 |
if (accessSection == null) |
|
625 |
Object accessSectionObj = accessControlMap.get(subSectionId);
|
|
626 |
if (accessSectionObj == null)
|
|
613 | 627 |
{ |
614 |
// if accesssection is null ignore the following lines
|
|
615 |
continue;
|
|
628 |
// if accesssection is null, terminate the program
|
|
629 |
throw new SAXException("access subtree is null");
|
|
616 | 630 |
} |
617 |
else if ( accessSection instanceof AccessSection ) |
|
618 |
{ |
|
619 |
// it is not reference |
|
620 |
AccessSection accessObj = (AccessSection)accessSection; |
|
621 |
writeGivenAccessRuleIntoDB(accessObj, topLevel, subSectionId); |
|
622 |
} |
|
623 | 631 |
else |
624 | 632 |
{ |
625 |
//this is reference |
|
626 |
// this is a reference and go trough the vector which contains all |
|
627 |
// access object |
|
628 |
String referenceId = (String) accessSection; |
|
629 |
MetaCatUtil.debugMessage("referered id for additional access "+ |
|
630 |
"mapping(go through): "+ referenceId, 25); |
|
631 |
for (int i=0; i<accessObjectList.size(); i++) |
|
633 |
AccessSection accessControlObj = (AccessSection)accessSectionObj; |
|
634 |
// if the access section is not references, write it to db |
|
635 |
if (accessControlObj.getReferences() == null) |
|
632 | 636 |
{ |
633 |
AccessSection accessObj = |
|
637 |
writeGivenAccessRuleIntoDB(accessControlObj, topLevel, |
|
638 |
subSectionId); |
|
639 |
} |
|
640 |
else |
|
641 |
{ |
|
642 |
// this is a reference and go trough the vector which contains all |
|
643 |
// access object |
|
644 |
String referenceId = accessControlObj.getReferences(); |
|
645 |
|
|
646 |
boolean findAccessObject = false; |
|
647 |
MetaCatUtil.debugMessage("referered id for additional access "+ |
|
648 |
"mapping(go through): "+ referenceId, 35); |
|
649 |
for (int i=0; i<accessObjectList.size(); i++) |
|
650 |
{ |
|
651 |
AccessSection accessObj = |
|
634 | 652 |
(AccessSection)accessObjectList.elementAt(i); |
635 |
String accessObjId = accessObj.getAccessSectionId(); |
|
636 |
MetaCatUtil.debugMessage("access obj id in the list(go through): " |
|
637 |
+ accessObjId, 25); |
|
638 |
if (referenceId != null && accessObj != null && |
|
639 |
referenceId.equals(accessObjId)) |
|
653 |
String accessObjId = accessObj.getAccessSectionId(); |
|
654 |
MetaCatUtil.debugMessage("access obj id in the list(go through): " |
|
655 |
+ accessObjId, 35); |
|
656 |
if (referenceId != null && accessObj != null && |
|
657 |
referenceId.equals(accessObjId)) |
|
658 |
{ |
|
659 |
writeGivenAccessRuleIntoDB(accessObj, topLevel, subSectionId); |
|
660 |
findAccessObject = true; |
|
661 |
}//if |
|
662 |
}//for |
|
663 |
// if we couldn't find an access subtree id for this reference id |
|
664 |
if (!findAccessObject) |
|
640 | 665 |
{ |
641 |
writeGivenAccessRuleIntoDB(accessObj, topLevel, subSectionId); |
|
666 |
throw new SAXException("The referenceid: " + referenceId + |
|
667 |
" is not access subtree"); |
|
642 | 668 |
}//if |
643 |
}//for |
|
644 |
|
|
645 |
}//else |
|
669 |
}//else |
|
670 |
}//else |
|
646 | 671 |
}//try |
647 | 672 |
catch (Exception e) |
648 | 673 |
{ |
... | ... | |
651 | 676 |
+ ": "+e.getMessage(), 30); |
652 | 677 |
throw new SAXException(e.getMessage()); |
653 | 678 |
} |
654 |
}//while |
|
679 |
}//while |
|
680 |
}//for |
|
655 | 681 |
}//writeAccessRuletoDB |
656 | 682 |
|
657 | 683 |
/* Write a gaven access rule into db*/ |
... | ... | |
688 | 714 |
connection.increaseUsageCount(1); |
689 | 715 |
// Bind the values to the query |
690 | 716 |
pstmt.setString(1, docid); |
691 |
MetaCatUtil.debugMessage("Docid in accesstable: "+ docid, 25);
|
|
717 |
MetaCatUtil.debugMessage("Docid in accesstable: "+ docid, 35);
|
|
692 | 718 |
pstmt.setString(6, docid); |
693 |
MetaCatUtil.debugMessage("Accessfileid in accesstable: "+ docid, 25);
|
|
719 |
MetaCatUtil.debugMessage("Accessfileid in accesstable: "+ docid, 35);
|
|
694 | 720 |
pstmt.setString(5, permOrder); |
695 |
MetaCatUtil.debugMessage("PermOder in accesstable: "+ permOrder, 25);
|
|
721 |
MetaCatUtil.debugMessage("PermOder in accesstable: "+ permOrder, 35);
|
|
696 | 722 |
// if it is not top level, set subsection id |
697 | 723 |
if (!topLevel) |
698 | 724 |
{ |
... | ... | |
709 | 735 |
{ |
710 | 736 |
SubTree tree = (SubTree)subTreeList.elementAt(i); |
711 | 737 |
String subTreeId = tree.getSubTreeId(); |
712 |
MetaCatUtil.debugMessage("subtree id in the list(go throug: "+ |
|
713 |
subTreeId, 25); |
|
714 | 738 |
if (subSectionId.equals(subTreeId)) |
715 | 739 |
{ |
716 | 740 |
startNodeId = tree.getStartNodeId(); |
... | ... | |
724 | 748 |
} |
725 | 749 |
pstmt.setString(7, subSectionId); |
726 | 750 |
MetaCatUtil.debugMessage("SubSectionId in accesstable: "+ |
727 |
subSectionId, 25);
|
|
751 |
subSectionId, 35);
|
|
728 | 752 |
pstmt.setLong(8, startNodeId); |
729 |
MetaCatUtil.debugMessage("Start node id is: " + startNodeId, 25);
|
|
753 |
MetaCatUtil.debugMessage("Start node id is: " + startNodeId, 35);
|
|
730 | 754 |
pstmt.setLong(9, endNodeId); |
731 |
MetaCatUtil.debugMessage("End node id is: " + endNodeId, 25);
|
|
755 |
MetaCatUtil.debugMessage("End node id is: " + endNodeId, 35);
|
|
732 | 756 |
|
733 | 757 |
} |
734 | 758 |
|
... | ... | |
740 | 764 |
String permType = rule.getPermissionType(); |
741 | 765 |
int permission = rule.getPermission(); |
742 | 766 |
pstmt.setInt(3, permission); |
743 |
MetaCatUtil.debugMessage("permission in accesstable: "+ permission, 25);
|
|
767 |
MetaCatUtil.debugMessage("permission in accesstable: "+ permission, 35);
|
|
744 | 768 |
pstmt.setString(4, permType); |
745 |
MetaCatUtil.debugMessage("Permtype in accesstable: "+ permType, 25);
|
|
769 |
MetaCatUtil.debugMessage("Permtype in accesstable: "+ permType, 35);
|
|
746 | 770 |
// go through every principle in rule |
747 | 771 |
Vector nameVector = rule.getPrincipal(); |
748 | 772 |
for ( int j = 0; j < nameVector.size(); j++ ) |
749 | 773 |
{ |
750 | 774 |
String prName = (String)nameVector.elementAt(j); |
751 | 775 |
pstmt.setString(2, prName); |
752 |
MetaCatUtil.debugMessage("Principal in accesstable: "+prName, 25);
|
|
776 |
MetaCatUtil.debugMessage("Principal in accesstable: "+prName, 35);
|
|
753 | 777 |
pstmt.execute(); |
754 | 778 |
}//for |
755 | 779 |
}//for |
Also available in: Unified diff
Add code in addtionalmetadta, so metacat can handle same subtree id was put in describes in different additionalmetadata.