Revision 1439
Added by Jing Tao almost 22 years ago
src/edu/ucsb/nceas/metacat/DocumentImpl.java | ||
---|---|---|
835 | 835 |
public void toXml(Writer pw, String user, String[] groups) |
836 | 836 |
throws McdbException |
837 | 837 |
{ |
838 |
TreeSet nodeRecordLists = null; |
|
838 | 839 |
PrintWriter out = null; |
839 | 840 |
if (pw instanceof PrintWriter) { |
840 | 841 |
out = (PrintWriter)pw; |
... | ... | |
851 | 852 |
|
852 | 853 |
if (!unaccessableSubTree.isEmpty()) |
853 | 854 |
{ |
854 |
Enumeration en = unaccessableSubTree.elements(); |
|
855 |
while (en.hasMoreElements()) |
|
856 |
{ |
|
857 |
SubTree tree = (SubTree)en.nextElement(); |
|
858 |
//System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); |
|
859 |
//System.out.println("subtree id pull out: "+tree.getSubTreeId()); |
|
860 |
//System.out.println("start node id: "+tree.getStartNodeId()); |
|
861 |
//System.out.println("end node id: "+tree.getEndNodeId()); |
|
862 |
} |
|
855 |
|
|
856 |
nodeRecordLists = getPartNodeRecordList(rootnodeid, unaccessableSubTree); |
|
857 |
|
|
863 | 858 |
} |
864 |
|
|
865 |
// First, check that we have the needed node data, and get it if not |
|
866 |
if (nodeRecordList == null) |
|
859 |
else |
|
867 | 860 |
{ |
868 |
nodeRecordList = getNodeRecordList(rootnodeid); |
|
861 |
nodeRecordLists = getNodeRecordList(rootnodeid);
|
|
869 | 862 |
} |
870 | 863 |
|
871 | 864 |
Stack openElements = new Stack(); |
... | ... | |
873 | 866 |
boolean previousNodeWasElement = false; |
874 | 867 |
|
875 | 868 |
// Step through all of the node records we were given |
876 |
Iterator it = nodeRecordList.iterator(); |
|
877 |
while (it.hasNext()) { |
|
869 |
|
|
870 |
Iterator it = nodeRecordLists.iterator(); |
|
871 |
|
|
872 |
while (it.hasNext()) |
|
873 |
{ |
|
874 |
|
|
878 | 875 |
NodeRecord currentNode = (NodeRecord)it.next(); |
879 |
//util.debugMessage("[Got Node ID: " + currentNode.nodeid +
|
|
880 |
//" (" + currentNode.parentnodeid +
|
|
881 |
//", " + currentNode.nodeindex +
|
|
882 |
//", " + currentNode.nodetype +
|
|
883 |
//", " + currentNode.nodename +
|
|
884 |
//", " + currentNode.nodedata + ")]");
|
|
876 |
util.debugMessage("[Got Node ID: " + currentNode.nodeid + |
|
877 |
" (" + currentNode.parentnodeid + |
|
878 |
", " + currentNode.nodeindex + |
|
879 |
", " + currentNode.nodetype + |
|
880 |
", " + currentNode.nodename + |
|
881 |
", " + currentNode.nodedata + ")]", 50);
|
|
885 | 882 |
// Print the end tag for the previous node if needed |
886 | 883 |
// |
887 | 884 |
// This is determined by inspecting the parent nodeid for the |
... | ... | |
994 | 991 |
} |
995 | 992 |
out.flush(); |
996 | 993 |
} |
997 |
|
|
994 |
|
|
998 | 995 |
// Print the final end tag for the root element |
999 | 996 |
while(!openElements.empty()) |
1000 | 997 |
{ |
... | ... | |
1221 | 1218 |
docid.getIdentifier(), docid.getRev()); |
1222 | 1219 |
} |
1223 | 1220 |
} |
1221 |
|
|
1222 |
/** |
|
1223 |
* Look up the node data from the database, but some node would be shown |
|
1224 |
* because of access control |
|
1225 |
* @param rootnodeid the id of the root node of the node tree to look up |
|
1226 |
* @param accessControl the hashtable has control info |
|
1227 |
*/ |
|
1228 |
private TreeSet getPartNodeRecordList(long rootnodeid, |
|
1229 |
Hashtable accessControl) |
|
1230 |
throws McdbException |
|
1231 |
{ |
|
1232 |
PreparedStatement pstmt = null; |
|
1233 |
DBConnection dbconn = null; |
|
1234 |
int serialNumber = -1; |
|
1235 |
TreeSet nodeRecordList = new TreeSet(new NodeComparator()); |
|
1236 |
long nodeid = 0; |
|
1237 |
long parentnodeid = 0; |
|
1238 |
long nodeindex = 0; |
|
1239 |
String nodetype = null; |
|
1240 |
String nodename = null; |
|
1241 |
String nodeprefix = null; |
|
1242 |
String nodedata = null; |
|
1243 |
String quotechar = dbAdapter.getStringDelimiter(); |
|
1244 |
String sql = "SELECT nodeid,parentnodeid,nodeindex, " + |
|
1245 |
"nodetype,nodename,nodeprefix,nodedata " + |
|
1246 |
"FROM xml_nodes WHERE rootnodeid = ?"; |
|
1247 |
|
|
1248 |
// go through the access control for some nodes |
|
1249 |
Enumeration en = accessControl.elements(); |
|
1250 |
while (en.hasMoreElements()) |
|
1251 |
{ |
|
1252 |
SubTree tree = (SubTree)en.nextElement(); |
|
1253 |
long startId = tree.getStartNodeId(); |
|
1254 |
long endId = tree.getEndNodeId(); |
|
1255 |
sql = sql +" AND(nodeid < " + startId + " OR nodeid > " +endId +")"; |
|
1256 |
|
|
1257 |
} |
|
1258 |
MetaCatUtil.debugMessage("The final query to select part node tree: " + |
|
1259 |
sql, 25); |
|
1224 | 1260 |
|
1261 |
try |
|
1262 |
{ |
|
1263 |
dbconn=DBConnectionPool. |
|
1264 |
getDBConnection("DocumentImpl.getPartNodeRecordList"); |
|
1265 |
serialNumber=dbconn.getCheckOutSerialNumber(); |
|
1266 |
pstmt = dbconn.prepareStatement(sql); |
|
1267 |
|
|
1268 |
// Bind the values to the query |
|
1269 |
pstmt.setLong(1, rootnodeid); |
|
1270 |
pstmt.execute(); |
|
1271 |
ResultSet rs = pstmt.getResultSet(); |
|
1272 |
boolean tableHasRows = rs.next(); |
|
1273 |
while (tableHasRows) |
|
1274 |
{ |
|
1275 |
nodeid = rs.getLong(1); |
|
1276 |
parentnodeid = rs.getLong(2); |
|
1277 |
nodeindex = rs.getLong(3); |
|
1278 |
nodetype = rs.getString(4); |
|
1279 |
nodename = rs.getString(5); |
|
1280 |
nodeprefix = rs.getString(6); |
|
1281 |
nodedata = rs.getString(7); |
|
1282 |
nodedata = MetaCatUtil.normalize(nodedata); |
|
1283 |
// add the data to the node record list hashtable |
|
1284 |
NodeRecord currentRecord = new NodeRecord(nodeid,parentnodeid,nodeindex, |
|
1285 |
nodetype, nodename, nodeprefix, nodedata); |
|
1286 |
nodeRecordList.add(currentRecord); |
|
1287 |
|
|
1288 |
// Advance to the next node |
|
1289 |
tableHasRows = rs.next(); |
|
1290 |
} |
|
1291 |
pstmt.close(); |
|
1292 |
|
|
1293 |
} |
|
1294 |
catch (SQLException e) |
|
1295 |
{ |
|
1296 |
throw new McdbException("Error in DocumentImpl.getPartNodeRecordList " + |
|
1297 |
e.getMessage()); |
|
1298 |
} |
|
1299 |
finally |
|
1300 |
{ |
|
1301 |
try |
|
1302 |
{ |
|
1303 |
pstmt.close(); |
|
1304 |
} |
|
1305 |
catch (SQLException ee) |
|
1306 |
{ |
|
1307 |
MetaCatUtil.debugMessage("error in DocumentImpl.getPartNodeRecordList: " |
|
1308 |
+ee.getMessage(), 30); |
|
1309 |
} |
|
1310 |
finally |
|
1311 |
{ |
|
1312 |
DBConnectionPool.returnDBConnection(dbconn, serialNumber); |
|
1313 |
} |
|
1314 |
} |
|
1315 |
|
|
1316 |
|
|
1317 |
if (!nodeRecordList.isEmpty()) |
|
1318 |
{ |
|
1319 |
|
|
1320 |
return nodeRecordList; |
|
1321 |
} |
|
1322 |
else |
|
1323 |
{ |
|
1324 |
|
|
1325 |
throw new McdbException("Error getting node data: " + docid); |
|
1326 |
} |
|
1327 |
} |
|
1328 |
|
|
1225 | 1329 |
/** |
1226 | 1330 |
* Look up the node data from the database |
1227 | 1331 |
* |
... | ... | |
1298 | 1402 |
} |
1299 | 1403 |
|
1300 | 1404 |
|
1301 |
if (nodeRecordList != null) {
|
|
1405 |
if (!nodeRecordList.isEmpty()) {
|
|
1302 | 1406 |
return nodeRecordList; |
1303 | 1407 |
} else { |
1304 | 1408 |
throw new McdbException("Error getting node data: " + docid); |
Also available in: Unified diff
Add code to handle read part of tree. Now the subtree access control for reading works.