Revision 2245
Added by sgarg over 19 years ago
DocumentImpl.java | ||
---|---|---|
798 | 798 |
StringWriter docwriter = new StringWriter(); |
799 | 799 |
String userName = null; |
800 | 800 |
String[] groupNames = null; |
801 |
boolean withInlineData = false;
|
|
801 |
boolean withInlineData = true;
|
|
802 | 802 |
try |
803 | 803 |
{ |
804 | 804 |
this.toXml(docwriter, userName, groupNames, withInlineData); |
... | ... | |
853 | 853 |
* Print a text representation of the XML document to a Writer |
854 | 854 |
* |
855 | 855 |
* @param pw the Writer to which we print the document |
856 |
* Now we decide no matter withinInlineData's value, the document will |
|
857 |
* |
|
856 | 858 |
*/ |
857 | 859 |
public void toXml(Writer pw, String user, String[] groups, boolean withInLineData) |
858 | 860 |
throws McdbException |
... | ... | |
884 | 886 |
MetaCatUtil util = new MetaCatUtil(); |
885 | 887 |
|
886 | 888 |
// Here add code to handle subtree access control |
887 |
PermissionController control = new PermissionController(docid); |
|
889 |
/*PermissionController control = new PermissionController(docid);
|
|
888 | 890 |
Hashtable unaccessableSubTree =control.hasUnaccessableSubTree(user, groups, |
889 | 891 |
AccessControlInterface.READSTRING); |
890 | 892 |
|
... | ... | |
897 | 899 |
else |
898 | 900 |
{ |
899 | 901 |
nodeRecordLists = getNodeRecordList(rootnodeid); |
900 |
} |
|
901 |
|
|
902 |
}*/
|
|
903 |
nodeRecordLists = getNodeRecordList(rootnodeid); |
|
902 | 904 |
Stack openElements = new Stack(); |
903 | 905 |
boolean atRootElement = true; |
904 | 906 |
boolean previousNodeWasElement = false; |
... | ... | |
1018 | 1020 |
|
1019 | 1021 |
// Handle the TEXT nodes |
1020 | 1022 |
} else if (currentNode.nodetype.equals("TEXT")) { |
1021 |
if (previousNodeWasElement) { |
|
1023 |
if (previousNodeWasElement) |
|
1024 |
{ |
|
1022 | 1025 |
out.print(">"); |
1023 | 1026 |
} |
1024 |
if (!prcocessInlineData || !withInLineData)
|
|
1027 |
if (!prcocessInlineData) |
|
1025 | 1028 |
{ |
1026 |
// if it is not inline data just out put data or it is line data |
|
1027 |
// but user don't want it, just put local id in inlinedata |
|
1029 |
// if it is not inline data just out put data |
|
1028 | 1030 |
out.print(currentNode.nodedata); |
1029 | 1031 |
} |
1030 | 1032 |
else |
1031 | 1033 |
{ |
1032 |
// if it is inline data and user want to see it, pull out from |
|
1033 |
// file system and output it |
|
1034 |
// for inline data, the data base only store the file name, so we |
|
1035 |
// can combine the file name and inline data file path, to get it |
|
1034 |
// if it is inline data first to get the inline data internal id |
|
1036 | 1035 |
String fileName = currentNode.nodedata; |
1037 |
Reader reader =
|
|
1038 |
Eml200SAXHandler.readInlineDataFromFileSystem(fileName);
|
|
1039 |
char [] characterArray = new char [4*1024];
|
|
1036 |
String accessfileName = MetaCatUtil.getDocIdWithoutRevFromInlineDataID(fileName);
|
|
1037 |
// check if user has read permision for this inline data
|
|
1038 |
boolean readInlinedata = false;
|
|
1040 | 1039 |
try |
1041 | 1040 |
{ |
1042 |
int length = reader.read(characterArray); |
|
1043 |
while ( length != -1) |
|
1041 |
Hashtable unReadableInlineDataList = |
|
1042 |
PermissionController.getUnReadableInlineDataIdList(accessfileName,user,groups); |
|
1043 |
if (!unReadableInlineDataList.containsValue(fileName)) |
|
1044 | 1044 |
{ |
1045 |
out.print(new String(characterArray, 0, length)); |
|
1046 |
out.flush(); |
|
1047 |
length = reader.read(characterArray); |
|
1045 |
readInlinedata = true; |
|
1048 | 1046 |
} |
1049 |
reader.close(); |
|
1050 | 1047 |
} |
1051 |
catch (IOException e)
|
|
1048 |
catch (Exception e) |
|
1052 | 1049 |
{ |
1053 | 1050 |
throw new McdbException(e.getMessage()); |
1054 | 1051 |
} |
1055 |
} |
|
1056 | 1052 |
|
1057 |
// reset proccess inline data false |
|
1058 |
prcocessInlineData =false; |
|
1053 |
if (readInlinedata) |
|
1054 |
{ |
|
1055 |
//user want to see it, pull out from |
|
1056 |
// file system and output it |
|
1057 |
// for inline data, the data base only store the file name, so we |
|
1058 |
// can combine the file name and inline data file path, to get it |
|
1059 |
|
|
1060 |
Reader reader = |
|
1061 |
Eml200SAXHandler.readInlineDataFromFileSystem(fileName); |
|
1062 |
char[] characterArray = new char[4 * 1024]; |
|
1063 |
try |
|
1064 |
{ |
|
1065 |
int length = reader.read(characterArray); |
|
1066 |
while (length != -1) |
|
1067 |
{ |
|
1068 |
out.print(new String(characterArray, 0, length)); |
|
1069 |
out.flush(); |
|
1070 |
length = reader.read(characterArray); |
|
1071 |
} |
|
1072 |
reader.close(); |
|
1073 |
} |
|
1074 |
catch (IOException e) |
|
1075 |
{ |
|
1076 |
throw new McdbException(e.getMessage()); |
|
1077 |
} |
|
1078 |
}//if can read inline data |
|
1079 |
else |
|
1080 |
{ |
|
1081 |
// if user can't read it, we only send it back a empty string |
|
1082 |
// in inline element. |
|
1083 |
out.print(""); |
|
1084 |
}// else can't read inlinedata |
|
1085 |
// reset proccess inline data false |
|
1086 |
prcocessInlineData =false; |
|
1087 |
}// in inlinedata part |
|
1059 | 1088 |
previousNodeWasElement = false; |
1060 |
|
|
1061 | 1089 |
// Handle the COMMENT nodes |
1062 | 1090 |
} else if (currentNode.nodetype.equals("COMMENT")) { |
1063 | 1091 |
if (previousNodeWasElement) { |
... | ... | |
2197 | 2225 |
|
2198 | 2226 |
MetaCatUtil.debugMessage("Start deleting doc "+docid+ "...", 20); |
2199 | 2227 |
// check for 'write' permission for 'user' to delete this document |
2200 |
if ( !hasWritePermission(user, groups, accnum) ) {
|
|
2228 |
if ( !hasAllPermission(user, groups, accnum) ) {
|
|
2201 | 2229 |
throw new Exception("User " + user + |
2202 | 2230 |
" does not have permission to delete XML Document #" + accnum); |
2203 | 2231 |
} |
... | ... | |
2226 | 2254 |
pstmt.close(); |
2227 | 2255 |
conn.increaseUsageCount(1); |
2228 | 2256 |
|
2257 |
pstmt = conn. |
|
2258 |
prepareStatement("DELETE FROM xml_access WHERE docid = ?"); |
|
2259 |
pstmt.setString(1, docid); |
|
2260 |
pstmt.execute(); |
|
2261 |
pstmt.close(); |
|
2262 |
conn.increaseUsageCount(1); |
|
2263 |
|
|
2264 |
|
|
2229 | 2265 |
// Delete it from relation table |
2230 | 2266 |
pstmt = conn. |
2231 | 2267 |
prepareStatement("DELETE FROM xml_relation WHERE docid = ?"); |
... | ... | |
2314 | 2350 |
AccessControlInterface.READSTRING); |
2315 | 2351 |
} |
2316 | 2352 |
|
2353 |
/** |
|
2354 |
* Check for "WRITE" permission on @docid for @user and/or @groups |
|
2355 |
* from DB connection |
|
2356 |
*/ |
|
2357 |
private static boolean hasAllPermission (String user, |
|
2358 |
String[] groups, String docid ) |
|
2359 |
throws SQLException, Exception |
|
2360 |
{ |
|
2361 |
// Check for WRITE permission on @docid for @user and/or @groups |
|
2362 |
PermissionController controller = new PermissionController(docid); |
|
2363 |
return controller.hasPermission(user,groups, |
|
2364 |
AccessControlInterface.ALLSTRING); |
|
2365 |
} |
|
2317 | 2366 |
|
2367 |
|
|
2318 | 2368 |
/** |
2319 | 2369 |
* Set up the parser handlers for writing the document to the database |
2320 | 2370 |
*/ |
Also available in: Unified diff
Merging in changes made in branch 'dataaccess' by Jing Tao.