Revision 1555
Added by Jing Tao over 21 years ago
src/edu/ucsb/nceas/metacat/EmlSAXHandler.java | ||
---|---|---|
76 | 76 |
private Vector subTreeList = new Vector();// store the final subtree |
77 | 77 |
private int inLineDataIndex = 1; |
78 | 78 |
private Hashtable unChangableSubTreeHash = new Hashtable(); |
79 |
private Stack currentUnChangedableSubtreeNodeStack; |
|
79 |
private Stack currentUnChangedableSubtreeNodeStack =new Stack();
|
|
80 | 80 |
private boolean startCriticalSubTree = false; |
81 | 81 |
private boolean firstElementForCriticalSubTree = false; |
82 | 82 |
private String firstElementNameForCriticalSubTree; |
83 | 83 |
private boolean needCheckingAccessModule = false; |
84 |
private Vector unChangableAccessSubTreeVector; |
|
85 |
private Stack currentUnchangableAccessModuleNodeStack; |
|
84 |
private Vector unChangableAccessSubTreeVector = new Vector();
|
|
85 |
private Stack currentUnchangableAccessModuleNodeStack = new Stack();
|
|
86 | 86 |
private AccessSection topAccessSection; |
87 | 87 |
|
88 | 88 |
// we need an another stack to store the access node which we pull out just |
89 | 89 |
// from xml. If a reference happend, we can use the stack the compare nodes |
90 | 90 |
private Stack storedAccessNodeStack = new Stack(); |
91 |
// vector stored the data file id which will be write into relation table |
|
92 |
private Vector onlineDataFileIdVector = new Vector(); |
|
91 | 93 |
|
92 | 94 |
|
93 | 95 |
// Constant |
... | ... | |
98 | 100 |
private static final String ID ="id"; |
99 | 101 |
private static final String REFERENCES = "references"; |
100 | 102 |
public static final String INLINE = "inline"; |
103 |
private static final String ONLINE = "online"; |
|
104 |
private static final String URL = "url"; |
|
101 | 105 |
private static final String PERMISSIONERROR ="User try to update a subtree"+ |
102 | 106 |
" which it doesn't have write permission!"; |
103 | 107 |
private static final String UPDATEACCESSERROR = "User try to update a " + |
104 | 108 |
"access module which it doesn't have \"ALL\" permission!"; |
105 | 109 |
private static final String TOPLEVEL = "top"; |
106 | 110 |
private static final String SUBTREELEVEL ="subtree"; |
111 |
private static final String RELATION = "Provides info for"; |
|
107 | 112 |
|
108 | 113 |
/** Construct an instance of the handler class |
109 | 114 |
* In this constructor, user can specify the version need to upadate |
... | ... | |
844 | 849 |
accessObject.setReferences(data); |
845 | 850 |
|
846 | 851 |
} |
852 |
else if (currentTag.equals(URL)) |
|
853 |
{ |
|
854 |
//handle online data, make sure its'parent is online |
|
855 |
DBSAXNode parentNode = (DBSAXNode)nodeStack.peek(); |
|
856 |
if (parentNode != null && parentNode.getTagName()!= null && |
|
857 |
parentNode.getTagName().equals(ONLINE)) |
|
858 |
{ |
|
859 |
// if online data is in local metacat, add it to the vector |
|
860 |
data = (textBuffer.toString()).trim(); |
|
861 |
if (data != null && |
|
862 |
(data.indexOf(MetaCatUtil.getOption("httpserver")) != -1 || |
|
863 |
data.indexOf(MetaCatUtil.getOption("server")) != -1)) |
|
864 |
{ |
|
865 |
// Get docid from url |
|
866 |
String dataId =MetaCatUtil.getDocIdWithRevFromOnlineURL(data); |
|
867 |
// add to vector |
|
868 |
onlineDataFileIdVector.add(dataId); |
|
869 |
}//if |
|
870 |
}//if |
|
871 |
}//else if |
|
847 | 872 |
// write text to db if it is not inline data |
848 | 873 |
if (!localName.equals(INLINE)) |
849 | 874 |
{ |
... | ... | |
961 | 986 |
else if (currentTag.equals(ACCESS)) |
962 | 987 |
{ |
963 | 988 |
// finish parse a access setction and assign it to new one |
989 |
|
|
964 | 990 |
accessObject.setEndNodeId(endNodeId); |
965 | 991 |
AccessSection newAccessObject = accessObject; |
992 |
|
|
966 | 993 |
if (newAccessObject != null) |
967 | 994 |
{ |
995 |
|
|
968 | 996 |
// add the accessSection into a vector to store it |
969 | 997 |
// if it is not a reference, need to store it |
970 | 998 |
if ( newAccessObject.getReferences() == null) |
971 | 999 |
{ |
1000 |
|
|
972 | 1001 |
newAccessObject.setStoredTmpNodeStack(storedAccessNodeStack); |
973 | 1002 |
accessObjectList.add(newAccessObject); |
974 | 1003 |
} |
975 | 1004 |
if (processTopLeverAccess) |
976 | 1005 |
{ |
1006 |
|
|
977 | 1007 |
// top level access control will handle whole document -docid |
978 | 1008 |
topLevelAccessControlMap.put(docid, newAccessObject); |
979 | 1009 |
// reset processtopleveraccess tag |
... | ... | |
983 | 1013 |
{ |
984 | 1014 |
// for additional control |
985 | 1015 |
// put everything in describes value and access object into hash |
986 |
|
|
987 | 1016 |
for ( int i=0; i<describesId.size(); i++) |
988 | 1017 |
{ |
989 | 1018 |
|
... | ... | |
1001 | 1030 |
additionalAccessControlMap = null; |
1002 | 1031 |
additionalAccessControlMap = new Hashtable(); |
1003 | 1032 |
}//if |
1033 |
|
|
1004 | 1034 |
}//if |
1005 | 1035 |
//check if access node stack is empty after parsing top access |
1006 | 1036 |
//module |
1007 |
if (!currentUnchangableAccessModuleNodeStack.isEmpty() && |
|
1008 |
processTopLeverAccess && needCheckingAccessModule) |
|
1037 |
|
|
1038 |
if (needCheckingAccessModule && processTopLeverAccess && |
|
1039 |
!currentUnchangableAccessModuleNodeStack.isEmpty()) |
|
1009 | 1040 |
{ |
1041 |
|
|
1010 | 1042 |
MetaCatUtil.debugMessage("Access node stack is not empty after " + |
1011 | 1043 |
"parsing access subtree", 40); |
1012 | 1044 |
throw new SAXException(UPDATEACCESSERROR); |
1013 | 1045 |
|
1014 | 1046 |
} |
1015 | 1047 |
//reset access section object |
1048 |
|
|
1016 | 1049 |
accessObject = null; |
1050 |
|
|
1017 | 1051 |
// reset tmp stored node stack |
1018 | 1052 |
storedAccessNodeStack = null; |
1019 | 1053 |
storedAccessNodeStack = new Stack(); |
1054 |
|
|
1020 | 1055 |
// reset flag |
1021 | 1056 |
processAdditionalAccess =false; |
1022 | 1057 |
processTopLeverAccess =false; |
... | ... | |
1029 | 1064 |
describesId = null; |
1030 | 1065 |
describesId = new Vector(); |
1031 | 1066 |
} |
1067 |
|
|
1032 | 1068 |
} |
1033 | 1069 |
|
1034 | 1070 |
/** |
... | ... | |
1215 | 1251 |
|
1216 | 1252 |
// write access rule to db |
1217 | 1253 |
writeAccessRuleToDB(); |
1254 |
|
|
1255 |
//delete relation table |
|
1256 |
deleteRelations(); |
|
1257 |
//write relations |
|
1258 |
for (int i= 0; i<onlineDataFileIdVector.size(); i++) |
|
1259 |
{ |
|
1260 |
String id = (String)onlineDataFileIdVector.elementAt(i); |
|
1261 |
writeOnlineDataFileIdIntoRelationTable(id); |
|
1262 |
} |
|
1218 | 1263 |
|
1219 | 1264 |
// Starting new thread for writing XML Index. |
1220 | 1265 |
// It calls the run method of the thread. |
... | ... | |
1811 | 1856 |
MetaCatUtil.debugMessage("the inline data retrieve from file: "+data, 50); |
1812 | 1857 |
return data; |
1813 | 1858 |
} |
1859 |
|
|
1860 |
/* Delete relations */ |
|
1861 |
private void deleteRelations() throws SAXException |
|
1862 |
{ |
|
1863 |
PreparedStatement pStmt = null; |
|
1864 |
String sql = "DELETE FROM xml_relation where docid =?"; |
|
1865 |
try |
|
1866 |
{ |
|
1867 |
pStmt = connection.prepareStatement(sql); |
|
1868 |
//bind variable |
|
1869 |
pStmt.setString(1, docid); |
|
1870 |
//execute query |
|
1871 |
pStmt.execute(); |
|
1872 |
pStmt.close(); |
|
1873 |
}//try |
|
1874 |
catch (SQLException e) |
|
1875 |
{ |
|
1876 |
throw new |
|
1877 |
SAXException("EMLSAXHandler.deleteRelations(): " + |
|
1878 |
e.getMessage()); |
|
1879 |
}//catch |
|
1880 |
finally |
|
1881 |
{ |
|
1882 |
try |
|
1883 |
{ |
|
1884 |
pStmt.close(); |
|
1885 |
}//try |
|
1886 |
catch(SQLException ee) |
|
1887 |
{ |
|
1888 |
throw new |
|
1889 |
SAXException("EMLSAXHandler.deleteRelations: " + |
|
1890 |
ee.getMessage()); |
|
1891 |
}//catch |
|
1892 |
}//finally |
|
1893 |
} |
|
1894 |
|
|
1895 |
/* Write an online data file id into xml_relation table*/ |
|
1896 |
private void writeOnlineDataFileIdIntoRelationTable(String dataId) |
|
1897 |
throws SAXException |
|
1898 |
{ |
|
1899 |
// Get rid of rev |
|
1900 |
dataId = MetaCatUtil.getDocIdFromString(dataId); |
|
1901 |
PreparedStatement pStmt = null; |
|
1902 |
String sql = "INSERT into xml_relation (docid, packagetype, subject, "+ |
|
1903 |
"relationship, object) values (?, ?, ?, ?, ?)"; |
|
1904 |
try |
|
1905 |
{ |
|
1906 |
pStmt = connection.prepareStatement(sql); |
|
1907 |
//bind variable |
|
1908 |
pStmt.setString(1, docid); |
|
1909 |
pStmt.setString(2, DocumentImpl.EMLNAMESPACE); |
|
1910 |
pStmt.setString(3, docid); |
|
1911 |
pStmt.setString(4, RELATION); |
|
1912 |
pStmt.setString(5, dataId); |
|
1913 |
//execute query |
|
1914 |
pStmt.execute(); |
|
1915 |
pStmt.close(); |
|
1916 |
}//try |
|
1917 |
catch (SQLException e) |
|
1918 |
{ |
|
1919 |
throw new |
|
1920 |
SAXException("EMLSAXHandler.writeOnlineDataFileIdIntoRelationTable(): " + |
|
1921 |
e.getMessage()); |
|
1922 |
}//catch |
|
1923 |
finally |
|
1924 |
{ |
|
1925 |
try |
|
1926 |
{ |
|
1927 |
pStmt.close(); |
|
1928 |
}//try |
|
1929 |
catch(SQLException ee) |
|
1930 |
{ |
|
1931 |
throw new |
|
1932 |
SAXException("EMLSAXHandler.writeOnlineDataFileIdIntoRelationTable(): " + |
|
1933 |
ee.getMessage()); |
|
1934 |
}//catch |
|
1935 |
}//finally |
|
1936 |
|
|
1937 |
}//writeOnlineDataFileIdIntoRelationTable |
|
1814 | 1938 |
} |
Also available in: Unified diff
Fixed a bug which cause null exception.