Revision 5311
Added by daigle about 14 years ago
Eml210SAXHandler.java | ||
---|---|---|
63 | 63 |
*/ |
64 | 64 |
public class Eml210SAXHandler extends DBSAXHandler implements AccessControlInterface { |
65 | 65 |
|
66 |
private boolean processTopLevelAccess = false; |
|
66 |
private boolean processingTopLevelAccess = false;
|
|
67 | 67 |
|
68 |
private boolean processAdditionalAccess = false; |
|
68 |
private boolean processingAdditionalAccess = false;
|
|
69 | 69 |
|
70 |
private boolean processOtherAccess = false; |
|
70 |
private boolean processingOtherAccess = false;
|
|
71 | 71 |
|
72 | 72 |
private AccessSection accessObject = null; |
73 | 73 |
|
74 | 74 |
private AccessRule accessRule = null; |
75 | 75 |
|
76 |
private Vector<AccessSection> accessObjectList = new Vector<AccessSection>(); // store |
|
77 |
// every |
|
78 |
// access |
|
79 |
// rule |
|
76 |
// all access rules |
|
77 |
private Vector<AccessSection> accessObjectList = new Vector<AccessSection>(); |
|
80 | 78 |
|
81 | 79 |
private Hashtable<String, AccessSection> topLevelAccessControlMap = new Hashtable<String, AccessSection>(); |
82 | 80 |
|
83 |
private Hashtable<String, AccessSection> additionalAccessControlMap = new Hashtable<String, AccessSection>();// store |
|
84 |
|
|
85 |
// subtree access for single additionalmetacat |
|
86 |
private Vector<Hashtable<String, AccessSection>> additionalAccessMapList = new Vector<Hashtable<String, AccessSection>>();// store |
|
87 |
// maps |
|
88 |
// for |
|
89 |
|
|
90 |
// every additionalmetadata |
|
91 |
private Vector<String> describesId = new Vector<String>(); // store the ids |
|
92 |
// in |
|
93 |
|
|
94 |
// additionalmetadata/describes |
|
81 |
// subtree access for additionalmetadata |
|
82 |
private Hashtable<String, AccessSection> additionalAccessControlMap = new Hashtable<String, AccessSection>(); |
|
83 |
|
|
84 |
|
|
85 |
private Vector<Hashtable<String, AccessSection>> additionalAccessMapList = new Vector<Hashtable<String, AccessSection>>(); |
|
86 |
|
|
87 |
// ids from additionalmetadata/describes |
|
88 |
private Vector<String> describesId = new Vector<String>(); |
|
89 |
|
|
95 | 90 |
private Stack<SubTree> subTreeInfoStack = new Stack<SubTree>(); |
96 | 91 |
|
97 |
private Vector<SubTree> subTreeList = new Vector<SubTree>();// store the |
|
98 |
// final subtree |
|
92 |
private Vector<SubTree> subTreeList = new Vector<SubTree>(); |
|
99 | 93 |
|
100 | 94 |
private boolean needToCheckAccessModule = false; |
101 | 95 |
|
... | ... | |
204 | 198 |
try { |
205 | 199 |
PermissionController control = new PermissionController(docid |
206 | 200 |
+ PropertyService.getProperty("document.accNumSeparator") + revision); |
207 |
// unChangableSubTreeHash = getUnchangableSubTree(control, user, |
|
208 |
// groups); |
|
209 | 201 |
|
210 | 202 |
// If the action is update and user doesn't have "ALL" permission |
211 | 203 |
// we need to check if user can update access subtree |
... | ... | |
333 | 325 |
if (hitTextNode && parentNode != null) { |
334 | 326 |
|
335 | 327 |
// compare top level access module |
336 |
if (processTopLevelAccess && needToCheckAccessModule) { |
|
337 |
compareTextNode(currentUnchangeableAccessModuleNodeStack, textBuffer, |
|
338 |
UPDATEACCESSERROR); |
|
328 |
if (processingTopLevelAccess && needToCheckAccessModule) { |
|
329 |
compareAccessTextNode(currentUnchangeableAccessModuleNodeStack, textBuffer); |
|
339 | 330 |
} |
340 | 331 |
|
341 | 332 |
if (needToCheckAccessModule |
342 |
&& (processAdditionalAccess || processOtherAccess || processTopLevelAccess)) {
|
|
333 |
&& (processingAdditionalAccess || processingOtherAccess || processingTopLevelAccess)) {
|
|
343 | 334 |
// stored the pull out nodes into storedNode stack |
344 | 335 |
NodeRecord nodeElement = new NodeRecord(-2, -2, -2, "TEXT", null, |
345 | 336 |
null, MetacatUtil.normalize(textBuffer.toString())); |
... | ... | |
482 | 473 |
// handle access stuff |
483 | 474 |
if (localName.equals(ACCESS)) { |
484 | 475 |
if (parentNode.getTagName().equals(EML)) { |
485 |
processTopLevelAccess = true; |
|
476 |
processingTopLevelAccess = true;
|
|
486 | 477 |
} else if (parentNode.getTagName() == DISTRIBUTION) { |
487 |
processAdditionalAccess = true; |
|
478 |
processingAdditionalAccess = true;
|
|
488 | 479 |
} else { |
489 | 480 |
// process other access embedded into resource level |
490 | 481 |
// module |
491 |
processOtherAccess = true; |
|
482 |
processingOtherAccess = true;
|
|
492 | 483 |
} |
493 | 484 |
// create access object |
494 | 485 |
accessObject = new AccessSection(); |
... | ... | |
500 | 491 |
accessObject.setSubTreeId(accessId); |
501 | 492 |
accessObject.setStartNodeId(startNodeId); |
502 | 493 |
accessObject.setDocId(docid); |
503 |
if (processAdditionalAccess) { |
|
494 |
if (processingAdditionalAccess) {
|
|
504 | 495 |
accessObject.setDataFileName(inlineDataFileName); |
505 | 496 |
} |
506 | 497 |
|
507 | 498 |
// load top level node stack to |
508 | 499 |
// currentUnchangableAccessModuleNodeStack |
509 |
if (processTopLevelAccess && needToCheckAccessModule) { |
|
500 |
if (processingTopLevelAccess && needToCheckAccessModule) {
|
|
510 | 501 |
// get the node stack for |
511 | 502 |
currentUnchangeableAccessModuleNodeStack = topAccessSection |
512 | 503 |
.getSubTreeNodeStack(); |
... | ... | |
552 | 543 |
nodeIndex.addElement(currentNode); |
553 | 544 |
|
554 | 545 |
// compare top access level module |
555 |
if (processTopLevelAccess && needToCheckAccessModule) { |
|
546 |
if (processingTopLevelAccess && needToCheckAccessModule) {
|
|
556 | 547 |
compareElementNameSpaceAttributes( |
557 | 548 |
currentUnchangeableAccessModuleNodeStack, namespaces, atts, |
558 | 549 |
localName, UPDATEACCESSERROR); |
... | ... | |
561 | 552 |
|
562 | 553 |
// store access module element and attributes into stored stack |
563 | 554 |
if (needToCheckAccessModule |
564 |
&& (processAdditionalAccess || processOtherAccess || processTopLevelAccess)) {
|
|
555 |
&& (processingAdditionalAccess || processingOtherAccess || processingTopLevelAccess)) {
|
|
565 | 556 |
// stored the pull out nodes into storedNode stack |
566 | 557 |
NodeRecord nodeElement = new NodeRecord(-2, -2, -2, "ELEMENT", localName, |
567 | 558 |
prefix, MetacatUtil.normalize(null)); |
... | ... | |
724 | 715 |
} |
725 | 716 |
|
726 | 717 |
/* method to compare current text node and node in db */ |
727 |
private void compareTextNode(Stack<NodeRecord> nodeStack, StringBuffer text, |
|
728 |
String error) throws SAXException { |
|
718 |
private void compareAccessTextNode(Stack<NodeRecord> nodeStack, StringBuffer text) throws SAXException { |
|
729 | 719 |
NodeRecord node = null; |
730 | 720 |
// get node from current stack |
731 | 721 |
try { |
732 | 722 |
node = nodeStack.pop(); |
733 | 723 |
} catch (EmptyStackException ee) { |
734 |
logMetacat.error("Node stack is empty for text data in startElement");
|
|
735 |
throw new SAXException(error);
|
|
724 |
logMetacat.error("Node stack is empty for text data in startElement for doc id " + docid);
|
|
725 |
throw new SAXException("Access rules could not be found in database.");
|
|
736 | 726 |
} |
737 |
logMetacat.debug("current node type from xml is TEXT in start element"); |
|
738 |
logMetacat.debug("node type from stack: " + node.getNodeType()); |
|
739 |
logMetacat.debug("current node data from xml is: " + text.toString()); |
|
740 |
logMetacat.debug("node data from stack: " + node.getNodeData()); |
|
741 |
logMetacat.debug("node name from stack: " + node.getNodeName()); |
|
742 |
logMetacat.debug("node is: " + node.getNodeId()); |
|
727 |
|
|
728 |
String dbAccessData = node.getNodeData(); |
|
729 |
String docAccessData = text.toString().trim(); |
|
730 |
|
|
731 |
logMetacat.debug("Eml210SAXHandler.compareAccessTextNode - \n" + |
|
732 |
"\t access node type from db: " + node.getNodeType() + "\n" + |
|
733 |
"\t access node data from db: " + node.getNodeData() + "\n" + |
|
734 |
"\t access node data from document: " + text.toString()); |
|
735 |
|
|
743 | 736 |
if (!node.getNodeType().equals("TEXT") |
744 |
|| !(text.toString()).equals(node.getNodeData())) { |
|
745 |
logMetacat.error("Inconsistence happened: "); |
|
746 |
logMetacat.error("current node type from xml is TEXT in start element"); |
|
747 |
logMetacat.error("node type from stack: " + node.getNodeType()); |
|
748 |
logMetacat.error("current node data from xml is: " + text.toString()); |
|
749 |
logMetacat.error("node data from stack: " + node.getNodeData()); |
|
750 |
logMetacat.error("node name from stack: " + node.getNodeName()); |
|
751 |
logMetacat.error("node is: " + node.getNodeId()); |
|
752 |
throw new SAXException(error); |
|
737 |
|| !docAccessData.equals(dbAccessData)) { |
|
738 |
logMetacat.warn("Eml210SAXHandler.compareAccessTextNode - Access record mismatch: \n" + |
|
739 |
"\t access node type from db: " + node.getNodeType() + "\n" + |
|
740 |
"\t access node data from db: " + dbAccessData + "\n" + |
|
741 |
"\t access node data from document: " + docAccessData); |
|
742 |
|
|
743 |
throw new SAXException(UPDATEACCESSERROR + " [Eml210SAXHandler.compareAccessTextNode]"); |
|
753 | 744 |
}// if |
754 | 745 |
} |
755 | 746 |
|
... | ... | |
843 | 834 |
} |
844 | 835 |
accessRule.setPermission(permission); |
845 | 836 |
} else if (currentTag.equals(REFERENCES) |
846 |
&& (processTopLevelAccess || processAdditionalAccess || processOtherAccess)) {
|
|
837 |
&& (processingTopLevelAccess || processingAdditionalAccess || processingOtherAccess)) {
|
|
847 | 838 |
// get reference |
848 | 839 |
data = (textBuffer.toString()).trim(); |
849 | 840 |
// put reference id into accessSection |
... | ... | |
858 | 849 |
// vector |
859 | 850 |
data = (textBuffer.toString()).trim(); |
860 | 851 |
handleOnlineUrlDataFile(data); |
861 |
/* |
|
862 |
* if (data != null && (data.indexOf(MetacatUtil |
|
863 |
* .getProperty("httpserver")) != -1 || data |
|
864 |
* .indexOf(MetacatUtil .getProperty("server")) != -1)) { // |
|
865 |
* Get docid from url String dataId = MetacatUtil |
|
866 |
* .getDocIdWithRevFromOnlineURL(data); // add to vector |
|
867 |
* onlineDataFileIdVector.add(dataId); }//if |
|
868 |
*/ |
|
852 |
|
|
869 | 853 |
}// if |
870 | 854 |
}// else if |
855 |
|
|
871 | 856 |
// write text to db if it is not inline data |
872 |
// if (!localName.equals(INLINE)) |
|
873 |
{ |
|
874 |
logMetacat.debug("Write text into DB in End Element"); |
|
857 |
logMetacat.debug("Write text into DB in End Element"); |
|
875 | 858 |
|
876 |
// compare top level access module |
|
877 |
if (processTopLevelAccess && needToCheckAccessModule) { |
|
878 |
compareTextNode(currentUnchangeableAccessModuleNodeStack, |
|
879 |
textBuffer, UPDATEACCESSERROR); |
|
880 |
} |
|
881 |
// write text node into db |
|
882 |
endNodeId = writeTextForDBSAXNode(endNodeId, textBuffer, currentNode); |
|
859 |
// compare top level access module |
|
860 |
if (processingTopLevelAccess && needToCheckAccessModule) { |
|
861 |
compareAccessTextNode(currentUnchangeableAccessModuleNodeStack, |
|
862 |
textBuffer); |
|
883 | 863 |
} |
884 |
if (needToCheckAccessModule |
|
885 |
&& (processAdditionalAccess || processOtherAccess || processTopLevelAccess)) { |
|
886 |
// stored the pull out nodes into storedNode stack |
|
887 |
NodeRecord nodeElement = new NodeRecord(-2, -2, -2, "TEXT", null, |
|
888 |
null, MetacatUtil.normalize(textBuffer.toString())); |
|
889 |
storedAccessNodeStack.push(nodeElement); |
|
864 |
// write text node into db |
|
865 |
endNodeId = writeTextForDBSAXNode(endNodeId, textBuffer, currentNode); |
|
866 |
} |
|
867 |
|
|
868 |
if (needToCheckAccessModule |
|
869 |
&& (processingAdditionalAccess || processingOtherAccess || processingTopLevelAccess)) { |
|
870 |
// stored the pull out nodes into storedNode stack |
|
871 |
NodeRecord nodeElement = new NodeRecord(-2, -2, -2, "TEXT", null, |
|
872 |
null, MetacatUtil.normalize(textBuffer.toString())); |
|
873 |
storedAccessNodeStack.push(nodeElement); |
|
890 | 874 |
|
891 |
} |
|
892 |
}// if |
|
875 |
} |
|
893 | 876 |
|
894 | 877 |
// set hitText false |
895 | 878 |
hitTextNode = false; |
... | ... | |
943 | 926 |
newAccessObject.setStoredTmpNodeStack(storedAccessNodeStack); |
944 | 927 |
accessObjectList.add(newAccessObject); |
945 | 928 |
} |
946 |
if (processTopLevelAccess) { |
|
929 |
if (processingTopLevelAccess) {
|
|
947 | 930 |
|
948 | 931 |
// top level access control will handle whole document |
949 | 932 |
// -docid |
... | ... | |
951 | 934 |
// reset processtopleveraccess tag |
952 | 935 |
|
953 | 936 |
}// if |
954 |
else if (processAdditionalAccess) { |
|
937 |
else if (processingAdditionalAccess) {
|
|
955 | 938 |
// for additional control put everything in describes |
956 | 939 |
// value |
957 | 940 |
// and access object into hash |
... | ... | |
976 | 959 |
// check if access node stack is empty after parsing top access |
977 | 960 |
// module |
978 | 961 |
|
979 |
if (needToCheckAccessModule && processTopLevelAccess |
|
962 |
if (needToCheckAccessModule && processingTopLevelAccess
|
|
980 | 963 |
&& !currentUnchangeableAccessModuleNodeStack.isEmpty()) { |
981 | 964 |
|
982 | 965 |
logMetacat.error("Access node stack is not empty after " |
... | ... | |
993 | 976 |
storedAccessNodeStack = new Stack<NodeRecord>(); |
994 | 977 |
|
995 | 978 |
// reset flag |
996 |
processAdditionalAccess = false; |
|
997 |
processTopLevelAccess = false; |
|
998 |
processOtherAccess = false; |
|
979 |
processingAdditionalAccess = false;
|
|
980 |
processingTopLevelAccess = false;
|
|
981 |
processingOtherAccess = false;
|
|
999 | 982 |
|
1000 | 983 |
} else if (currentTag.equals(DISTRIBUTION)) { |
1001 | 984 |
// If the current Distribution is inline or data and it doesn't have an access section |
... | ... | |
1045 | 1028 |
String str = new String(ch, start, length); |
1046 | 1029 |
|
1047 | 1030 |
// compare top level access module |
1048 |
if (processTopLevelAccess && needToCheckAccessModule) { |
|
1031 |
if (processingTopLevelAccess && needToCheckAccessModule) {
|
|
1049 | 1032 |
compareCommentNode(currentUnchangeableAccessModuleNodeStack, str, |
1050 | 1033 |
UPDATEACCESSERROR); |
1051 | 1034 |
} |
1052 | 1035 |
endNodeId = currentNode.writeChildNodeToDB("COMMENT", null, str, docid); |
1053 | 1036 |
if (needToCheckAccessModule |
1054 |
&& (processAdditionalAccess || processOtherAccess || processTopLevelAccess)) {
|
|
1037 |
&& (processingAdditionalAccess || processingOtherAccess || processingTopLevelAccess)) {
|
|
1055 | 1038 |
// stored the pull out nodes into storedNode stack |
1056 | 1039 |
NodeRecord nodeElement = new NodeRecord(-2, -2, -2, "COMMENT", null, |
1057 | 1040 |
null, MetacatUtil.normalize(str)); |
... | ... | |
1141 | 1124 |
DBSAXNode currentNode = (DBSAXNode) nodeStack.peek(); |
1142 | 1125 |
String data = new String(cbuf, start, len); |
1143 | 1126 |
// compare whitespace in access top module |
1144 |
if (processTopLevelAccess && needToCheckAccessModule) { |
|
1127 |
if (processingTopLevelAccess && needToCheckAccessModule) {
|
|
1145 | 1128 |
compareWhiteSpace(currentUnchangeableAccessModuleNodeStack, data, |
1146 | 1129 |
UPDATEACCESSERROR); |
1147 | 1130 |
} |
1148 | 1131 |
// Write the content of the node to the database |
1149 | 1132 |
if (needToCheckAccessModule |
1150 |
&& (processAdditionalAccess || processOtherAccess || processTopLevelAccess)) {
|
|
1133 |
&& (processingAdditionalAccess || processingOtherAccess || processingTopLevelAccess)) {
|
|
1151 | 1134 |
// stored the pull out nodes into storedNode stack |
1152 | 1135 |
NodeRecord nodeElement = new NodeRecord(-2, -2, -2, "TEXT", null, |
1153 | 1136 |
null, MetacatUtil.normalize(data)); |
Also available in: Unified diff
Merge 1.9.2 changes back into the trunk