Revision 1544
Added by Jing Tao over 21 years ago
src/edu/ucsb/nceas/metacat/EmlSAXHandler.java | ||
---|---|---|
82 | 82 |
private String firstElementNameForCriticalSubTree; |
83 | 83 |
private boolean needCheckingAccessModule = false; |
84 | 84 |
private Vector unChangableAccessSubTreeVector; |
85 |
private Stack currentUnchangableAccessModuleNodeStack; |
|
85 | 86 |
private AccessSection topAccessSection; |
87 |
|
|
88 |
// we need an another stack to store the access node which we pull out just |
|
89 |
// from xml. If a reference happend, we can use the stack the compare nodes |
|
90 |
private Stack storedAccessNodeStack = new Stack(); |
|
86 | 91 |
|
87 | 92 |
|
88 | 93 |
// Constant |
... | ... | |
95 | 100 |
public static final String INLINE = "inline"; |
96 | 101 |
private static final String PERMISSIONERROR ="User try to update a subtree"+ |
97 | 102 |
" which it doesn't have write permission!"; |
103 |
private static final String UPDATEACCESSERROR = "User try to update a " + |
|
104 |
"access module which it doesn't have \"ALL\" permission!"; |
|
98 | 105 |
private static final String TOPLEVEL = "top"; |
99 | 106 |
private static final String SUBTREELEVEL ="subtree"; |
100 | 107 |
|
... | ... | |
127 | 134 |
//If the action is update and user doesn't have "ALL" permission |
128 | 135 |
// we need to check if user update access subtree |
129 | 136 |
if (action.equals("UPDATE") && |
130 |
control.hasPermission(user, groups, AccessControlInterface.ALLSTRING)) |
|
137 |
!control.hasPermission(user, groups, AccessControlInterface.ALLSTRING))
|
|
131 | 138 |
{ |
132 | 139 |
needCheckingAccessModule = true; |
133 | 140 |
unChangableAccessSubTreeVector = getAccessSubTreeListFromDB(); |
... | ... | |
186 | 193 |
Vector result = new Vector(); |
187 | 194 |
PreparedStatement pstmt = null; |
188 | 195 |
ResultSet rs = null; |
189 |
String sql = "SELECT controllevel, subtreeid, startnodeid, endnodeid) " +
|
|
196 |
String sql = "SELECT controllevel, subtreeid, startnodeid, endnodeid " + |
|
190 | 197 |
"FROM xml_accesssubtree WHERE docid like ? " + |
191 | 198 |
"ORDER BY startnodeid ASC"; |
192 | 199 |
|
... | ... | |
278 | 285 |
// This will happend if the element is mixted |
279 | 286 |
if (hitTextNode && parentNode != null) |
280 | 287 |
{ |
281 |
//compare text node data |
|
288 |
//compare text node data for unchangesubtree
|
|
282 | 289 |
if (startCriticalSubTree) |
283 | 290 |
{ |
284 |
NodeRecord node = null; |
|
285 |
try |
|
286 |
{ |
|
287 |
node = (NodeRecord)currentUnChangedableSubtreeNodeStack.pop(); |
|
288 |
} |
|
289 |
catch (EmptyStackException ee) |
|
290 |
{ |
|
291 |
MetaCatUtil.debugMessage("Node stack is empty for text data in startElement", 35); |
|
292 |
throw new SAXException(PERMISSIONERROR); |
|
293 |
} |
|
294 |
MetaCatUtil.debugMessage("current node type from xml is TEXT in start element", 40); |
|
295 |
MetaCatUtil.debugMessage("node type from stack: " + |
|
296 |
node.getNodeType(), 40); |
|
297 |
MetaCatUtil.debugMessage("current node data from xml is: " + |
|
298 |
textBuffer.toString(), 40); |
|
299 |
MetaCatUtil.debugMessage("node data from stack: " + |
|
300 |
node.getNodeData(), 40); |
|
301 |
MetaCatUtil.debugMessage("node name from stack: " + |
|
302 |
node.getNodeName(), 40); |
|
303 |
MetaCatUtil.debugMessage("node is: "+ node.getNodeId(), 40); |
|
304 |
if (!node.getNodeType().equals("TEXT") || |
|
305 |
!(textBuffer.toString()).equals(node.getNodeData())) |
|
306 |
{ |
|
307 |
MetaCatUtil.debugMessage("current node type from xml is TEXT in start element", 40); |
|
308 |
MetaCatUtil.debugMessage("node type from stack: " + |
|
309 |
node.getNodeType(), 40); |
|
310 |
MetaCatUtil.debugMessage("current node data from xml is: " + |
|
311 |
textBuffer.toString(), 40); |
|
312 |
MetaCatUtil.debugMessage("node data from stack: " + |
|
313 |
node.getNodeData(), 40); |
|
314 |
MetaCatUtil.debugMessage("node name from stack: " + |
|
315 |
node.getNodeName(), 40); |
|
316 |
MetaCatUtil.debugMessage("node is: "+ node.getNodeId(), 40); |
|
317 |
throw new SAXException(PERMISSIONERROR); |
|
318 |
}//if |
|
319 |
}//if |
|
291 |
compareTextNode(currentUnChangedableSubtreeNodeStack, textBuffer, |
|
292 |
PERMISSIONERROR); |
|
293 |
}//if |
|
294 |
|
|
295 |
//compare top level access module |
|
296 |
if (processTopLeverAccess && needCheckingAccessModule) |
|
297 |
{ |
|
298 |
compareTextNode(currentUnchangableAccessModuleNodeStack, |
|
299 |
textBuffer, UPDATEACCESSERROR); |
|
300 |
} |
|
301 |
|
|
302 |
if (needCheckingAccessModule && |
|
303 |
(processAdditionalAccess || processOtherAccess || processTopLeverAccess)) |
|
304 |
{ |
|
305 |
// stored the pull out nodes into storedNode stack |
|
306 |
NodeRecord nodeElement = new NodeRecord(-2, -2, -2, "TEXT", |
|
307 |
null, null, textBuffer.toString()); |
|
308 |
storedAccessNodeStack.push(nodeElement); |
|
309 |
|
|
310 |
} |
|
311 |
|
|
320 | 312 |
// write the textbuffer into db for parent node. |
321 | 313 |
endNodeId = writeTextForDBSAXNode(textBuffer, parentNode); |
322 | 314 |
// rest hitTextNode |
... | ... | |
420 | 412 |
// otherwise, it will be discated |
421 | 413 |
long startNodeId = currentNode.getNodeID(); |
422 | 414 |
// Add all of the namespaces |
423 |
String prefix; |
|
424 |
String nsuri; |
|
415 |
String prefix =null;
|
|
416 |
String nsuri = null;
|
|
425 | 417 |
Enumeration prefixes = namespaces.keys(); |
426 | 418 |
while ( prefixes.hasMoreElements() ) |
427 | 419 |
{ |
... | ... | |
519 | 511 |
String accessId = currentNode.getAttribute(ID); |
520 | 512 |
accessObject.setSubTreeId(accessId); |
521 | 513 |
accessObject.setStartNodeId(startNodeId); |
514 |
accessObject.setDocId(docid); |
|
522 | 515 |
|
516 |
// load top level node stack to currentUnchangableAccessModuleNodeStack |
|
517 |
if (processTopLeverAccess && needCheckingAccessModule) |
|
518 |
{ |
|
519 |
// get the node stack for |
|
520 |
currentUnchangableAccessModuleNodeStack = |
|
521 |
topAccessSection.getSubTreeNodeStack(); |
|
522 |
} |
|
523 |
|
|
524 |
|
|
523 | 525 |
} |
524 | 526 |
// Set up a access rule for allow |
525 | 527 |
else if (parentNode.getTagName() != null && |
... | ... | |
554 | 556 |
firstElementNameForCriticalSubTree = qName; |
555 | 557 |
firstElementForCriticalSubTree = false; |
556 | 558 |
}//for first element |
559 |
|
|
557 | 560 |
// handle critical subtree |
558 | 561 |
if (startCriticalSubTree) |
559 | 562 |
{ |
560 |
//Get element subtree node stack (element node) |
|
563 |
compareElementNameSpaceAttributes(currentUnChangedableSubtreeNodeStack, |
|
564 |
namespaces, atts, localName, |
|
565 |
PERMISSIONERROR); |
|
566 |
|
|
567 |
} |
|
568 |
//compare top access level module |
|
569 |
if (processTopLeverAccess && needCheckingAccessModule) |
|
570 |
{ |
|
571 |
compareElementNameSpaceAttributes(currentUnchangableAccessModuleNodeStack, |
|
572 |
namespaces, atts, localName, |
|
573 |
UPDATEACCESSERROR); |
|
574 |
|
|
575 |
} |
|
576 |
|
|
577 |
if (needCheckingAccessModule && |
|
578 |
(processAdditionalAccess || processOtherAccess || processTopLeverAccess)) |
|
579 |
{ |
|
580 |
// stored the pull out nodes into storedNode stack |
|
581 |
NodeRecord nodeElement = new NodeRecord(-2, -2, -2, "ELEMENT", |
|
582 |
localName, prefix, null); |
|
583 |
storedAccessNodeStack.push(nodeElement); |
|
584 |
for (int i=0; i<atts.getLength(); i++) |
|
585 |
{ |
|
586 |
String attributeName = atts.getQName(i); |
|
587 |
String attributeValue = atts.getValue(i); |
|
588 |
NodeRecord nodeAttribute = new NodeRecord(-2, -2, -2, "ATTRIBUTE", |
|
589 |
attributeName, null, attributeValue); |
|
590 |
storedAccessNodeStack.push(nodeAttribute); |
|
591 |
} |
|
592 |
|
|
593 |
} |
|
594 |
|
|
595 |
// reset name space |
|
596 |
namespaces = null; |
|
597 |
namespaces = new Hashtable(); |
|
598 |
} |
|
599 |
|
|
600 |
private void compareElementNameSpaceAttributes(Stack unchangableNodeStack, |
|
601 |
Hashtable nameSpaces, |
|
602 |
Attributes attributes, |
|
603 |
String localName, String error) |
|
604 |
throws SAXException |
|
605 |
{ |
|
606 |
//Get element subtree node stack (element node) |
|
561 | 607 |
NodeRecord elementNode = null; |
562 | 608 |
try |
563 | 609 |
{ |
564 |
elementNode= (NodeRecord) currentUnChangedableSubtreeNodeStack.pop();
|
|
610 |
elementNode= (NodeRecord) unchangableNodeStack.pop();
|
|
565 | 611 |
} |
566 | 612 |
catch (EmptyStackException ee) |
567 | 613 |
{ |
568 | 614 |
MetaCatUtil.debugMessage("Node stack is empty for element data", 35); |
569 |
throw new SAXException(PERMISSIONERROR);
|
|
615 |
throw new SAXException(error);
|
|
570 | 616 |
} |
571 | 617 |
MetaCatUtil.debugMessage("current node type from xml is ELEMENT", 40); |
572 | 618 |
MetaCatUtil.debugMessage("node type from stack: " + |
... | ... | |
577 | 623 |
elementNode.getNodeName(), 40); |
578 | 624 |
MetaCatUtil.debugMessage("node data from stack: " + |
579 | 625 |
elementNode.getNodeData(), 40); |
580 |
MetaCatUtil.debugMessage("node is: "+ elementNode.getNodeId(), 40); |
|
626 |
MetaCatUtil.debugMessage("node id is: "+ elementNode.getNodeId(), 40);
|
|
581 | 627 |
// if this node is not element or local name not equal or name space not |
582 | 628 |
// equals, throw an exception |
583 | 629 |
if (!elementNode.getNodeType().equals("ELEMENT") || |
584 | 630 |
!localName.equals(elementNode.getNodeName())) |
585 | 631 |
// (uri != null && !uri.equals(elementNode.getNodePrefix()))) |
586 | 632 |
{ |
633 |
MetaCatUtil.debugMessage("Inconsistence happend: ", 40); |
|
587 | 634 |
MetaCatUtil.debugMessage("current node type from xml is ELEMENT", 40); |
588 | 635 |
MetaCatUtil.debugMessage("node type from stack: " + |
589 | 636 |
elementNode.getNodeType(), 40); |
... | ... | |
593 | 640 |
elementNode.getNodeName(), 40); |
594 | 641 |
MetaCatUtil.debugMessage("node data from stack: " + |
595 | 642 |
elementNode.getNodeData(), 40); |
596 |
MetaCatUtil.debugMessage("node is: "+ elementNode.getNodeId(), 40); |
|
597 |
throw new SAXException(PERMISSIONERROR);
|
|
643 |
MetaCatUtil.debugMessage("node id is: "+ elementNode.getNodeId(), 40);
|
|
644 |
throw new SAXException(error);
|
|
598 | 645 |
} |
599 | 646 |
|
600 | 647 |
//compare namespace |
601 |
Enumeration nameEn = namespaces.keys();
|
|
648 |
Enumeration nameEn = nameSpaces.keys();
|
|
602 | 649 |
while ( nameEn.hasMoreElements() ) |
603 | 650 |
{ |
604 | 651 |
//Get namespacke node stack (element node) |
605 | 652 |
NodeRecord nameNode = null; |
606 | 653 |
try |
607 | 654 |
{ |
608 |
nameNode = (NodeRecord) currentUnChangedableSubtreeNodeStack.pop();
|
|
655 |
nameNode = (NodeRecord) unchangableNodeStack.pop();
|
|
609 | 656 |
} |
610 | 657 |
catch (EmptyStackException ee) |
611 | 658 |
{ |
612 | 659 |
MetaCatUtil.debugMessage("Node stack is empty for namespace data", 35); |
613 |
throw new SAXException(PERMISSIONERROR);
|
|
660 |
throw new SAXException(error);
|
|
614 | 661 |
} |
615 | 662 |
|
616 | 663 |
String prefixName = (String)nameEn.nextElement(); |
617 |
String nameSpaceUri = (String)namespaces.get(prefixName);
|
|
664 |
String nameSpaceUri = (String)nameSpaces.get(prefixName);
|
|
618 | 665 |
if (!nameNode.getNodeType().equals("NAMESPACE") || |
619 | 666 |
!prefixName.equals(nameNode.getNodeName()) || |
620 | 667 |
!nameSpaceUri.equals(nameNode.getNodeData())) |
621 | 668 |
{ |
669 |
MetaCatUtil.debugMessage("Inconsistence happend: ", 40); |
|
622 | 670 |
MetaCatUtil.debugMessage("current node type from xml is NAMESPACE", 40); |
623 | 671 |
MetaCatUtil.debugMessage("node type from stack: " + |
624 | 672 |
nameNode.getNodeType(), 40); |
... | ... | |
630 | 678 |
nameSpaceUri, 40); |
631 | 679 |
MetaCatUtil.debugMessage("node data from stack: " + |
632 | 680 |
nameNode.getNodeData(), 40); |
633 |
MetaCatUtil.debugMessage("node is: "+ nameNode.getNodeId(), 40); |
|
634 |
throw new SAXException(PERMISSIONERROR);
|
|
681 |
MetaCatUtil.debugMessage("node id is: "+ nameNode.getNodeId(), 40);
|
|
682 |
throw new SAXException(error);
|
|
635 | 683 |
} |
636 | 684 |
|
637 | 685 |
}//while |
638 | 686 |
|
639 | 687 |
//compare attributes |
640 |
for (int i=0; i<atts.getLength(); i++) |
|
688 |
for (int i=0; i<attributes.getLength(); i++)
|
|
641 | 689 |
{ |
642 | 690 |
NodeRecord attriNode = null; |
643 | 691 |
try |
644 | 692 |
{ |
645 |
attriNode = (NodeRecord)currentUnChangedableSubtreeNodeStack.pop();
|
|
693 |
attriNode = (NodeRecord)unchangableNodeStack.pop();
|
|
646 | 694 |
|
647 | 695 |
} |
648 | 696 |
catch (EmptyStackException ee) |
649 | 697 |
{ |
650 | 698 |
MetaCatUtil.debugMessage("Node stack is empty for attribute data", 35); |
651 |
throw new SAXException(PERMISSIONERROR);
|
|
699 |
throw new SAXException(error);
|
|
652 | 700 |
} |
653 |
String attributeName = atts.getQName(i); |
|
654 |
String attributeValue = atts.getValue(i); |
|
701 |
String attributeName = attributes.getQName(i);
|
|
702 |
String attributeValue = attributes.getValue(i);
|
|
655 | 703 |
MetaCatUtil.debugMessage("current node type from xml is ATTRIBUTE ", 40); |
656 | 704 |
MetaCatUtil.debugMessage("node type from stack: " + |
657 | 705 |
attriNode.getNodeType(), 40); |
... | ... | |
663 | 711 |
attributeValue, 40); |
664 | 712 |
MetaCatUtil.debugMessage("node data from stack: " + |
665 | 713 |
attriNode.getNodeData(), 40); |
666 |
MetaCatUtil.debugMessage("node is: "+ attriNode.getNodeId(), 40); |
|
714 |
MetaCatUtil.debugMessage("node id is: "+ attriNode.getNodeId(), 40);
|
|
667 | 715 |
|
668 | 716 |
if (!attriNode.getNodeType().equals("ATTRIBUTE") || |
669 | 717 |
!attributeName.equals(attriNode.getNodeName()) || |
670 | 718 |
!attributeValue.equals(attriNode.getNodeData())) |
671 | 719 |
{ |
720 |
MetaCatUtil.debugMessage("Inconsistence happend: ", 40); |
|
672 | 721 |
MetaCatUtil.debugMessage("current node type from xml is ATTRIBUTE ", 40); |
673 | 722 |
MetaCatUtil.debugMessage("node type from stack: " + |
674 | 723 |
attriNode.getNodeType(), 40); |
... | ... | |
681 | 730 |
MetaCatUtil.debugMessage("node data from stack: " + |
682 | 731 |
attriNode.getNodeData(), 40); |
683 | 732 |
MetaCatUtil.debugMessage("node is: "+ attriNode.getNodeId(), 40); |
684 |
throw new SAXException(PERMISSIONERROR);
|
|
733 |
throw new SAXException(error);
|
|
685 | 734 |
} |
686 | 735 |
}//for |
687 |
|
|
688 |
} |
|
689 |
// reset name space |
|
690 |
namespaces = null; |
|
691 |
namespaces = new Hashtable(); |
|
736 |
|
|
692 | 737 |
} |
693 | 738 |
|
694 |
|
|
739 |
/* mehtod to compare current text node and node in db*/ |
|
740 |
private void compareTextNode(Stack nodeStack, StringBuffer text, String error) |
|
741 |
throws SAXException |
|
742 |
{ |
|
743 |
NodeRecord node = null; |
|
744 |
//get node from current stack |
|
745 |
try |
|
746 |
{ |
|
747 |
node = (NodeRecord)nodeStack.pop(); |
|
748 |
} |
|
749 |
catch (EmptyStackException ee) |
|
750 |
{ |
|
751 |
MetaCatUtil. |
|
752 |
debugMessage("Node stack is empty for text data in startElement", 35); |
|
753 |
throw new SAXException(error); |
|
754 |
} |
|
755 |
MetaCatUtil.debugMessage("current node type from xml is TEXT in start element", 40); |
|
756 |
MetaCatUtil.debugMessage("node type from stack: " + |
|
757 |
node.getNodeType(), 40); |
|
758 |
MetaCatUtil.debugMessage("current node data from xml is: " + |
|
759 |
text.toString(), 40); |
|
760 |
MetaCatUtil.debugMessage("node data from stack: " + |
|
761 |
node.getNodeData(), 40); |
|
762 |
MetaCatUtil.debugMessage("node name from stack: " + |
|
763 |
node.getNodeName(), 40); |
|
764 |
MetaCatUtil.debugMessage("node is: "+ node.getNodeId(), 40); |
|
765 |
if (!node.getNodeType().equals("TEXT") || |
|
766 |
!(text.toString()).equals(node.getNodeData())) |
|
767 |
{ |
|
768 |
MetaCatUtil.debugMessage("Inconsistence happend: ", 40); |
|
769 |
MetaCatUtil.debugMessage("current node type from xml is TEXT in start element", 40); |
|
770 |
MetaCatUtil.debugMessage("node type from stack: " + |
|
771 |
node.getNodeType(), 40); |
|
772 |
MetaCatUtil.debugMessage("current node data from xml is: " + |
|
773 |
text.toString(), 40); |
|
774 |
MetaCatUtil.debugMessage("node data from stack: " + |
|
775 |
node.getNodeData(), 40); |
|
776 |
MetaCatUtil.debugMessage("node name from stack: " + |
|
777 |
node.getNodeName(), 40); |
|
778 |
MetaCatUtil.debugMessage("node is: "+ node.getNodeId(), 40); |
|
779 |
throw new SAXException(error); |
|
780 |
}//if |
|
781 |
} |
|
695 | 782 |
/** SAX Handler that is called at the end of each XML element */ |
696 | 783 |
public void endElement(String uri, String localName, |
697 | 784 |
String qName) throws SAXException |
... | ... | |
760 | 847 |
if (!localName.equals(INLINE)) |
761 | 848 |
{ |
762 | 849 |
MetaCatUtil.debugMessage("Write text into DB in End Element", 50); |
763 |
//compare whitespace if need
|
|
850 |
//compare text node if need
|
|
764 | 851 |
if (startCriticalSubTree) |
765 | 852 |
{ |
766 |
NodeRecord node = null; |
|
767 |
try |
|
768 |
{ |
|
769 |
node = (NodeRecord)currentUnChangedableSubtreeNodeStack.pop(); |
|
770 |
} |
|
771 |
catch (EmptyStackException ee) |
|
772 |
{ |
|
773 |
MetaCatUtil.debugMessage("the stack is empty for text data", 32); |
|
774 |
throw new SAXException(PERMISSIONERROR); |
|
775 |
} |
|
776 |
MetaCatUtil.debugMessage("current node type from xml is TEXT in endElement", 40); |
|
777 |
MetaCatUtil.debugMessage("node type from stack: " + |
|
778 |
node.getNodeType(), 40); |
|
779 |
MetaCatUtil.debugMessage("current node data from xml is: " + |
|
780 |
textBuffer.toString(), 40); |
|
781 |
MetaCatUtil.debugMessage("node data from stack: " + |
|
782 |
node.getNodeData(), 40); |
|
783 |
MetaCatUtil.debugMessage("node name from stack: " + |
|
784 |
node.getNodeName(), 40); |
|
785 |
MetaCatUtil.debugMessage("node is from stack: " + |
|
786 |
node.getNodeId(), 40); |
|
787 |
if (!node.getNodeType().equals("TEXT") || |
|
788 |
!(textBuffer.toString()).equals(node.getNodeData())) |
|
789 |
{ |
|
790 |
MetaCatUtil.debugMessage("current node type from xml is TEXT in endElement", 40); |
|
791 |
MetaCatUtil.debugMessage("node type from stack: " + |
|
792 |
node.getNodeType(), 40); |
|
793 |
MetaCatUtil.debugMessage("current node data from xml is: " + |
|
794 |
textBuffer.toString(), 40); |
|
795 |
MetaCatUtil.debugMessage("node data from stack: " + |
|
796 |
node.getNodeData(), 40); |
|
797 |
MetaCatUtil.debugMessage("node name from stack: " + |
|
798 |
node.getNodeName(), 40); |
|
799 |
MetaCatUtil.debugMessage("node is from stack: " + |
|
800 |
node.getNodeId(), 40); |
|
801 |
throw new SAXException(PERMISSIONERROR); |
|
802 |
}//if |
|
853 |
compareTextNode(currentUnChangedableSubtreeNodeStack, textBuffer, |
|
854 |
PERMISSIONERROR); |
|
803 | 855 |
}//if |
856 |
//compare top level access module |
|
857 |
if (processTopLeverAccess && needCheckingAccessModule) |
|
858 |
{ |
|
859 |
compareTextNode(currentUnchangableAccessModuleNodeStack, |
|
860 |
textBuffer, UPDATEACCESSERROR); |
|
861 |
} |
|
862 |
// write text node into db |
|
804 | 863 |
endNodeId = writeTextForDBSAXNode(textBuffer, currentNode); |
805 | 864 |
} |
806 | 865 |
else |
... | ... | |
845 | 904 |
// write file name into db |
846 | 905 |
endNodeId = writeTextForDBSAXNode(textBuffer, currentNode); |
847 | 906 |
} |
907 |
|
|
908 |
if (needCheckingAccessModule && |
|
909 |
(processAdditionalAccess || processOtherAccess || processTopLeverAccess)) |
|
910 |
{ |
|
911 |
// stored the pull out nodes into storedNode stack |
|
912 |
NodeRecord nodeElement = new NodeRecord(-2, -2, -2, "TEXT", |
|
913 |
null, null, textBuffer.toString()); |
|
914 |
storedAccessNodeStack.push(nodeElement); |
|
915 |
|
|
916 |
} |
|
848 | 917 |
}//if |
849 | 918 |
|
850 | 919 |
//end crtical subtree(user doesn't have permission to write) |
... | ... | |
899 | 968 |
// if it is not a reference, need to store it |
900 | 969 |
if ( newAccessObject.getReferences() == null) |
901 | 970 |
{ |
971 |
newAccessObject.setStoredTmpNodeStack(storedAccessNodeStack); |
|
902 | 972 |
accessObjectList.add(newAccessObject); |
903 | 973 |
} |
904 | 974 |
if (processTopLeverAccess) |
... | ... | |
931 | 1001 |
additionalAccessControlMap = new Hashtable(); |
932 | 1002 |
}//if |
933 | 1003 |
}//if |
1004 |
//check if access node stack is empty after parsing top access |
|
1005 |
//module |
|
1006 |
if (!currentUnchangableAccessModuleNodeStack.isEmpty() && |
|
1007 |
processTopLeverAccess && needCheckingAccessModule) |
|
1008 |
{ |
|
1009 |
MetaCatUtil.debugMessage("Access node stack is not empty after " + |
|
1010 |
"parsing access subtree", 40); |
|
1011 |
throw new SAXException(UPDATEACCESSERROR); |
|
1012 |
|
|
1013 |
} |
|
934 | 1014 |
//reset access section object |
935 | 1015 |
accessObject = null; |
1016 |
// reset tmp stored node stack |
|
1017 |
storedAccessNodeStack = null; |
|
1018 |
storedAccessNodeStack = new Stack(); |
|
936 | 1019 |
// reset flag |
937 | 1020 |
processAdditionalAccess =false; |
938 | 1021 |
processTopLeverAccess =false; |
939 | 1022 |
processOtherAccess = false; |
1023 |
|
|
940 | 1024 |
} |
941 | 1025 |
else if (currentTag.equals(ADDITIONALMETADATA)) |
942 | 1026 |
{ |
... | ... | |
959 | 1043 |
//compare comment if need |
960 | 1044 |
if (startCriticalSubTree) |
961 | 1045 |
{ |
962 |
NodeRecord node = null; |
|
963 |
try |
|
964 |
{ |
|
965 |
node = (NodeRecord)currentUnChangedableSubtreeNodeStack.pop(); |
|
966 |
} |
|
967 |
catch (EmptyStackException ee) |
|
968 |
{ |
|
969 |
MetaCatUtil.debugMessage("the stack is empty for comment data", 32); |
|
970 |
throw new SAXException(PERMISSIONERROR); |
|
971 |
} |
|
972 |
MetaCatUtil.debugMessage("current node type from xml is COMMENT", 40); |
|
973 |
MetaCatUtil.debugMessage("node type from stack: " + |
|
1046 |
compareCommentNode(currentUnChangedableSubtreeNodeStack, str, |
|
1047 |
PERMISSIONERROR); |
|
1048 |
}//if |
|
1049 |
//compare top level access module |
|
1050 |
if (processTopLeverAccess && needCheckingAccessModule) |
|
1051 |
{ |
|
1052 |
compareCommentNode(currentUnchangableAccessModuleNodeStack, str, |
|
1053 |
UPDATEACCESSERROR); |
|
1054 |
} |
|
1055 |
endNodeId = currentNode.writeChildNodeToDB("COMMENT", null, str, docid); |
|
1056 |
if (needCheckingAccessModule && |
|
1057 |
(processAdditionalAccess || processOtherAccess || processTopLeverAccess)) |
|
1058 |
{ |
|
1059 |
// stored the pull out nodes into storedNode stack |
|
1060 |
NodeRecord nodeElement = new NodeRecord(-2, -2, -2, "COMMENT", |
|
1061 |
null, null, str); |
|
1062 |
storedAccessNodeStack.push(nodeElement); |
|
1063 |
|
|
1064 |
} |
|
1065 |
} |
|
1066 |
} |
|
1067 |
|
|
1068 |
/* Comparet comment from xml and db */ |
|
1069 |
private void compareCommentNode(Stack nodeStack, String string, String error) |
|
1070 |
throws SAXException |
|
1071 |
{ |
|
1072 |
NodeRecord node = null; |
|
1073 |
try |
|
1074 |
{ |
|
1075 |
node = (NodeRecord)nodeStack.pop(); |
|
1076 |
} |
|
1077 |
catch (EmptyStackException ee) |
|
1078 |
{ |
|
1079 |
MetaCatUtil.debugMessage("the stack is empty for comment data", 32); |
|
1080 |
throw new SAXException(error); |
|
1081 |
} |
|
1082 |
MetaCatUtil.debugMessage("current node type from xml is COMMENT", 40); |
|
1083 |
MetaCatUtil.debugMessage("node type from stack: " + |
|
974 | 1084 |
node.getNodeType(), 40); |
975 |
MetaCatUtil.debugMessage("current node data from xml is: " +
|
|
976 |
str, 40); |
|
977 |
MetaCatUtil.debugMessage("node data from stack: " +
|
|
1085 |
MetaCatUtil.debugMessage("current node data from xml is: " + |
|
1086 |
string, 40);
|
|
1087 |
MetaCatUtil.debugMessage("node data from stack: " + |
|
978 | 1088 |
node.getNodeData(), 40); |
979 |
MetaCatUtil.debugMessage("node is from stack: " + |
|
980 |
node.getNodeId(), 40); |
|
981 |
if (!node.getNodeType().equals("COMMENT") || |
|
982 |
!str.equals(node.getNodeData())) |
|
983 |
{ |
|
984 |
MetaCatUtil.debugMessage("current node type from xml is COMMENT", 40); |
|
985 |
MetaCatUtil.debugMessage("node type from stack: " + |
|
1089 |
MetaCatUtil.debugMessage("node is from stack: " + |
|
1090 |
node.getNodeId(), 40); |
|
1091 |
// if not consistent terminate program and throw a exception |
|
1092 |
if (!node.getNodeType().equals("COMMENT") || |
|
1093 |
!string.equals(node.getNodeData())) |
|
1094 |
{ |
|
1095 |
MetaCatUtil.debugMessage("Inconsistence happend: ", 40); |
|
1096 |
MetaCatUtil.debugMessage("current node type from xml is COMMENT", 40); |
|
1097 |
MetaCatUtil.debugMessage("node type from stack: " + |
|
986 | 1098 |
node.getNodeType(), 40); |
987 |
MetaCatUtil.debugMessage("current node data from xml is: " +
|
|
988 |
str, 40); |
|
989 |
MetaCatUtil.debugMessage("node data from stack: " +
|
|
1099 |
MetaCatUtil.debugMessage("current node data from xml is: " + |
|
1100 |
string, 40);
|
|
1101 |
MetaCatUtil.debugMessage("node data from stack: " + |
|
990 | 1102 |
node.getNodeData(), 40); |
991 |
MetaCatUtil.debugMessage("node is from stack: " +
|
|
1103 |
MetaCatUtil.debugMessage("node is from stack: " + |
|
992 | 1104 |
node.getNodeId(), 40); |
993 |
throw new SAXException(PERMISSIONERROR); |
|
994 |
}//if |
|
995 |
}//if |
|
996 |
|
|
997 |
endNodeId = currentNode.writeChildNodeToDB("COMMENT", null, str, docid); |
|
998 |
} |
|
1105 |
throw new SAXException(error); |
|
1106 |
}//if |
|
999 | 1107 |
} |
1000 | 1108 |
|
1001 | 1109 |
/** |
... | ... | |
1037 | 1145 |
//compare whitespace if need |
1038 | 1146 |
if (startCriticalSubTree) |
1039 | 1147 |
{ |
1040 |
NodeRecord node = null; |
|
1041 |
try |
|
1042 |
{ |
|
1043 |
node = (NodeRecord)currentUnChangedableSubtreeNodeStack.pop(); |
|
1044 |
} |
|
1045 |
catch (EmptyStackException ee) |
|
1046 |
{ |
|
1047 |
MetaCatUtil.debugMessage("the stack is empty for whitespace data", 32); |
|
1048 |
throw new SAXException(PERMISSIONERROR); |
|
1049 |
} |
|
1050 |
if (!node.getNodeType().equals("TEXT") || |
|
1051 |
!data.equals(node.getNodeData())) |
|
1052 |
{ |
|
1053 |
MetaCatUtil.debugMessage("current node type from xml is WHITESPACE TEXT", 40); |
|
1054 |
MetaCatUtil.debugMessage("node type from stack: " + |
|
1055 |
node.getNodeType(), 40); |
|
1056 |
MetaCatUtil.debugMessage("current node data from xml is: " + |
|
1057 |
data, 40); |
|
1058 |
MetaCatUtil.debugMessage("node data from stack: " + |
|
1059 |
node.getNodeData(), 40); |
|
1060 |
MetaCatUtil.debugMessage("node is from stack: " + |
|
1061 |
node.getNodeId(), 40); |
|
1062 |
throw new SAXException(PERMISSIONERROR); |
|
1063 |
}//if |
|
1148 |
compareWhiteSpace(currentUnChangedableSubtreeNodeStack, data, |
|
1149 |
PERMISSIONERROR); |
|
1064 | 1150 |
}//if |
1151 |
|
|
1152 |
//compare whitespace in access top module |
|
1153 |
if (processTopLeverAccess && needCheckingAccessModule) |
|
1154 |
{ |
|
1155 |
compareWhiteSpace(currentUnchangableAccessModuleNodeStack, data, |
|
1156 |
UPDATEACCESSERROR); |
|
1157 |
} |
|
1065 | 1158 |
// Write the content of the node to the database |
1159 |
if (needCheckingAccessModule && |
|
1160 |
(processAdditionalAccess || processOtherAccess || processTopLeverAccess)) |
|
1161 |
{ |
|
1162 |
// stored the pull out nodes into storedNode stack |
|
1163 |
NodeRecord nodeElement = new NodeRecord(-2, -2, -2, "TEXT", |
|
1164 |
null, null, data); |
|
1165 |
storedAccessNodeStack.push(nodeElement); |
|
1166 |
|
|
1167 |
} |
|
1066 | 1168 |
endNodeId = currentNode.writeChildNodeToDB("TEXT", null, data, docid); |
1067 | 1169 |
} |
1068 |
|
|
1069 |
|
|
1170 |
} |
|
1070 | 1171 |
|
1172 |
/* Compare whitespace from xml and db */ |
|
1173 |
private void compareWhiteSpace(Stack nodeStack, String string, String error) |
|
1174 |
throws SAXException |
|
1175 |
{ |
|
1176 |
NodeRecord node = null; |
|
1177 |
try |
|
1178 |
{ |
|
1179 |
node = (NodeRecord)nodeStack.pop(); |
|
1180 |
} |
|
1181 |
catch (EmptyStackException ee) |
|
1182 |
{ |
|
1183 |
MetaCatUtil.debugMessage("the stack is empty for whitespace data", 32); |
|
1184 |
throw new SAXException(error); |
|
1185 |
} |
|
1186 |
if (!node.getNodeType().equals("TEXT") || |
|
1187 |
!string.equals(node.getNodeData())) |
|
1188 |
{ |
|
1189 |
MetaCatUtil.debugMessage("Inconsistence happend: ", 40); |
|
1190 |
MetaCatUtil.debugMessage("current node type from xml is WHITESPACE TEXT", 40); |
|
1191 |
MetaCatUtil.debugMessage("node type from stack: " + |
|
1192 |
node.getNodeType(), 40); |
|
1193 |
MetaCatUtil.debugMessage("current node data from xml is: " + |
|
1194 |
string, 40); |
|
1195 |
MetaCatUtil.debugMessage("node data from stack: " + |
|
1196 |
node.getNodeData(), 40); |
|
1197 |
MetaCatUtil.debugMessage("node is from stack: " + |
|
1198 |
node.getNodeId(), 40); |
|
1199 |
throw new SAXException(error); |
|
1200 |
}//if |
|
1071 | 1201 |
} |
1072 | 1202 |
|
1073 | 1203 |
/** SAX Handler that receives notification of end of the document */ |
... | ... | |
1123 | 1253 |
if ( accessSection != null ) |
1124 | 1254 |
{ |
1125 | 1255 |
AccessSection accessSectionObj = (AccessSection)accessSection; |
1126 |
// write the top level access module into xml_accesssubtree to store info |
|
1127 |
// and then when update to check if the user can update it or not |
|
1128 |
deleteAccessSubTreeRecord(docid); |
|
1129 |
writeAccessSubTreeIntoDB(accessSectionObj,TOPLEVEL); |
|
1130 |
|
|
1256 |
|
|
1131 | 1257 |
// if accessSection is not null and is not reference |
1132 | 1258 |
if ( accessSectionObj.getReferences() == null) |
1133 | 1259 |
{ |
1260 |
// write the top level access module into xml_accesssubtree to store info |
|
1261 |
// and then when update to check if the user can update it or not |
|
1262 |
deleteAccessSubTreeRecord(docid); |
|
1263 |
writeAccessSubTreeIntoDB(accessSectionObj,TOPLEVEL); |
|
1264 |
//write access section into xml_access table |
|
1134 | 1265 |
writeGivenAccessRuleIntoDB(accessSectionObj, top, subSectionId); |
1135 | 1266 |
} |
1136 | 1267 |
else |
... | ... | |
1149 | 1280 |
if (referenceId != null && accessObj != null && |
1150 | 1281 |
referenceId.equals(accessObjId)) |
1151 | 1282 |
{ |
1283 |
// make sure the user didn't change any thing in this access moduel |
|
1284 |
// too if user doesn't have all permission |
|
1285 |
if (needCheckingAccessModule) |
|
1286 |
{ |
|
1287 |
|
|
1288 |
Stack newStack = accessObj.getStoredTmpNodeStack(); |
|
1289 |
//revise order |
|
1290 |
newStack = MetaCatUtil.reviseStack(newStack); |
|
1291 |
// go throught the vector of unChangableAccessSubtreevector |
|
1292 |
// and find the one whose id is as same as referenceid |
|
1293 |
AccessSection oldAccessObj = |
|
1294 |
getAccessSectionFromUnchangableAccessVector(referenceId); |
|
1295 |
//if oldAccessObj is null something is wrong |
|
1296 |
if (oldAccessObj == null) |
|
1297 |
{ |
|
1298 |
throw new SAXException(UPDATEACCESSERROR); |
|
1299 |
}//if |
|
1300 |
else |
|
1301 |
{ |
|
1302 |
// Get the node stack from old access obj |
|
1303 |
Stack oldStack = oldAccessObj.getSubTreeNodeStack(); |
|
1304 |
comparingNodeStacks(newStack, oldStack); |
|
1305 |
}//else |
|
1306 |
}//if |
|
1307 |
|
|
1152 | 1308 |
writeGivenAccessRuleIntoDB(accessObj, top, subSectionId); |
1153 |
// write the reference access into xml_accesssubtree too |
|
1309 |
//write the reference access into xml_accesssubtree too |
|
1310 |
// write the top level access module into xml_accesssubtree to store info |
|
1311 |
// and then when update to check if the user can update it or not |
|
1312 |
deleteAccessSubTreeRecord(docid); |
|
1313 |
writeAccessSubTreeIntoDB(accessSectionObj,TOPLEVEL); |
|
1154 | 1314 |
writeAccessSubTreeIntoDB(accessObj, SUBTREELEVEL); |
1155 | 1315 |
findAccessObject = true; |
1316 |
break; |
|
1156 | 1317 |
} |
1157 | 1318 |
}//for |
1158 | 1319 |
// if we couldn't find an access subtree id for this reference id |
... | ... | |
1163 | 1324 |
}//if |
1164 | 1325 |
}//else |
1165 | 1326 |
|
1327 |
|
|
1166 | 1328 |
}//if |
1167 | 1329 |
else |
1168 | 1330 |
{ |
... | ... | |
1172 | 1334 |
} |
1173 | 1335 |
|
1174 | 1336 |
}//writeTopLevelAccessRuletoDB |
1175 |
|
|
1337 |
|
|
1338 |
/* Given a subtree id and find the responding access section*/ |
|
1339 |
private AccessSection getAccessSectionFromUnchangableAccessVector(String id) |
|
1340 |
{ |
|
1341 |
AccessSection result = null; |
|
1342 |
// Makse sure the id |
|
1343 |
if (id == null || id.equals("")) |
|
1344 |
{ |
|
1345 |
return result; |
|
1346 |
} |
|
1347 |
// go throught vector and find the list |
|
1348 |
for (int i=0; i<unChangableAccessSubTreeVector.size();i++) |
|
1349 |
{ |
|
1350 |
AccessSection accessObj = (AccessSection) |
|
1351 |
unChangableAccessSubTreeVector.elementAt(i); |
|
1352 |
if (accessObj.getSubTreeId() != null && |
|
1353 |
(accessObj.getSubTreeId()).equals(id)) |
|
1354 |
{ |
|
1355 |
result = accessObj; |
|
1356 |
}//if |
|
1357 |
}//for |
|
1358 |
return result; |
|
1359 |
}//getAccessSectionFromUnchangableAccessVector |
|
1360 |
|
|
1361 |
/* Compare two node stacks to see if they are same */ |
|
1362 |
private void comparingNodeStacks(Stack stack1, Stack stack2) |
|
1363 |
throws SAXException |
|
1364 |
{ |
|
1365 |
// make sure stack1 and stack2 are not empty |
|
1366 |
if (stack1.isEmpty() || stack2.isEmpty()) |
|
1367 |
{ |
|
1368 |
MetaCatUtil.debugMessage("Because stack is empty!", 35); |
|
1369 |
throw new SAXException(UPDATEACCESSERROR); |
|
1370 |
} |
|
1371 |
// go throw two stacks and compare every element |
|
1372 |
while (!stack1.isEmpty()) |
|
1373 |
{ |
|
1374 |
// Pop an element from stack1 |
|
1375 |
NodeRecord record1 = (NodeRecord) stack1.pop(); |
|
1376 |
// Pop an element from stack2(stack 2 maybe empty) |
|
1377 |
NodeRecord record2 = null; |
|
1378 |
try |
|
1379 |
{ |
|
1380 |
record2 = (NodeRecord) stack2.pop(); |
|
1381 |
} |
|
1382 |
catch (EmptyStackException ee) |
|
1383 |
{ |
|
1384 |
MetaCatUtil.debugMessage("Node stack2 is empty but stack1 isn't!", 35); |
|
1385 |
throw new SAXException(UPDATEACCESSERROR); |
|
1386 |
} |
|
1387 |
// if two records are not same throw a exception |
|
1388 |
if (!record1.contentEquals(record2)) |
|
1389 |
{ |
|
1390 |
MetaCatUtil.debugMessage("Two records from new and old stack are not "+ |
|
1391 |
"same!", 30); |
|
1392 |
throw new SAXException(UPDATEACCESSERROR); |
|
1393 |
}//if |
|
1394 |
}//while |
|
1395 |
|
|
1396 |
// now stack1 is empty and we should make sure stack2 is empty too |
|
1397 |
if(!stack2.isEmpty()) |
|
1398 |
{ |
|
1399 |
MetaCatUtil.debugMessage("stack2 still have some elements while stack "+ |
|
1400 |
"is empty! ", 30); |
|
1401 |
throw new SAXException(UPDATEACCESSERROR); |
|
1402 |
}//if |
|
1403 |
}//comparingNodeStacks |
|
1404 |
|
|
1176 | 1405 |
/* The method to write addtional access rule into db. */ |
1177 | 1406 |
private void writeAddtionalAccessRuleToDB() throws SAXException |
1178 | 1407 |
{ |
Also available in: Unified diff
Add code to handle reference access couldn't be updated if user doesn't have all permission.