Revision 1762
Added by Jing Tao over 21 years ago
src/edu/ucsb/nceas/metacat/EmlSAXHandler.java | ||
---|---|---|
30 | 30 |
|
31 | 31 |
import java.sql.*; |
32 | 32 |
import java.io.BufferedReader; |
33 |
import java.io.IOException; |
|
33 | 34 |
import java.io.File; |
34 | 35 |
import java.io.FileReader; |
35 | 36 |
import java.io.FileWriter; |
... | ... | |
74 | 75 |
//additionalmetadata/describes |
75 | 76 |
private Stack subTreeInfoStack = new Stack(); |
76 | 77 |
private Vector subTreeList = new Vector();// store the final subtree |
77 |
private int inLineDataIndex = 1; |
|
78 | 78 |
private Hashtable unChangableSubTreeHash = new Hashtable(); |
79 | 79 |
private Stack currentUnChangedableSubtreeNodeStack =new Stack(); |
80 | 80 |
private boolean startCriticalSubTree = false; |
... | ... | |
90 | 90 |
private Stack storedAccessNodeStack = new Stack(); |
91 | 91 |
// vector stored the data file id which will be write into relation table |
92 | 92 |
private Vector onlineDataFileIdVector = new Vector(); |
93 |
// Indicator of inline data |
|
94 |
private boolean handleInlineData = false; |
|
95 |
private Stack inlineDataNodeStack = null; |
|
96 |
private Hashtable inlineDataNameSpace = null; |
|
97 |
private FileWriter inlineDataFileWriter = null; |
|
98 |
private String inlineDataFileName = null; |
|
99 |
private int inLineDataIndex = 0; |
|
93 | 100 |
|
94 |
|
|
95 | 101 |
// Constant |
96 | 102 |
private static final String EML ="eml"; |
97 | 103 |
private static final String DESCRIBES = "describes"; |
... | ... | |
265 | 271 |
String qName, Attributes atts) |
266 | 272 |
throws SAXException |
267 | 273 |
{ |
268 |
// for element <eml:eml...> qname is "eml:eml", local name is "eml"
|
|
269 |
// for element <acl....> both qname and local name is "eml"
|
|
270 |
// uri is namesapce
|
|
271 |
MetaCatUtil.debugMessage("Start ELEMENT(qName) " + qName, 50);
|
|
272 |
MetaCatUtil.debugMessage("Start ELEMENT(localName) " + localName, 50);
|
|
273 |
MetaCatUtil.debugMessage("Start ELEMENT(uri) " + uri, 50);
|
|
274 |
// for element <eml:eml...> qname is "eml:eml", local name is "eml" |
|
275 |
// for element <acl....> both qname and local name is "eml" |
|
276 |
// uri is namesapce |
|
277 |
MetaCatUtil.debugMessage("Start ELEMENT(qName) " + qName, 50); |
|
278 |
MetaCatUtil.debugMessage("Start ELEMENT(localName) " + localName, 50); |
|
279 |
MetaCatUtil.debugMessage("Start ELEMENT(uri) " + uri, 50); |
|
274 | 280 |
|
275 | 281 |
|
276 |
DBSAXNode parentNode = null; |
|
277 |
DBSAXNode currentNode = null; |
|
278 |
|
|
282 |
DBSAXNode parentNode = null; |
|
283 |
DBSAXNode currentNode = null; |
|
284 |
|
|
285 |
if (!handleInlineData) |
|
286 |
{ |
|
279 | 287 |
// Get a reference to the parent node for the id |
280 | 288 |
try |
281 | 289 |
{ |
... | ... | |
286 | 294 |
parentNode = null; |
287 | 295 |
} |
288 | 296 |
|
297 |
//start handle inline data |
|
298 |
if (localName.equals(INLINE)) |
|
299 |
{ |
|
300 |
handleInlineData = true; |
|
301 |
inLineDataIndex ++; |
|
302 |
//intitialize namespace hash for in line data |
|
303 |
inlineDataNameSpace = new Hashtable(); |
|
304 |
//initialize file writer |
|
305 |
String docidWithoutRev = MetaCatUtil.getDocIdFromString(docid); |
|
306 |
String seperator = MetaCatUtil.getOption("accNumSeparator"); |
|
307 |
// the new file name will look like docid.rev.2 |
|
308 |
inlineDataFileName = docidWithoutRev + seperator+revision+seperator + |
|
309 |
inLineDataIndex; |
|
310 |
inlineDataFileWriter = createInlineDataFileWriter(inlineDataFileName); |
|
311 |
} |
|
312 |
|
|
313 |
|
|
289 | 314 |
// If hit a text node, we need write this text for current's parent node |
290 | 315 |
// This will happend if the element is mixted |
291 | 316 |
if (hitTextNode && parentNode != null) |
... | ... | |
315 | 340 |
} |
316 | 341 |
|
317 | 342 |
// write the textbuffer into db for parent node. |
318 |
endNodeId = writeTextForDBSAXNode(textBuffer, parentNode); |
|
343 |
endNodeId = writeTextForDBSAXNode(endNodeId, textBuffer, parentNode);
|
|
319 | 344 |
// rest hitTextNode |
320 | 345 |
hitTextNode =false; |
321 | 346 |
// reset textbuffer |
... | ... | |
601 | 626 |
// reset name space |
602 | 627 |
namespaces = null; |
603 | 628 |
namespaces = new Hashtable(); |
629 |
}//not inline data |
|
630 |
else |
|
631 |
{ |
|
632 |
// we don't buffer the inline data in characters() method |
|
633 |
// so start character don't need to hand text node. |
|
634 |
|
|
635 |
// inline data may be the xml format. |
|
636 |
StringBuffer inlineElements = new StringBuffer(); |
|
637 |
inlineElements.append("<").append(qName); |
|
638 |
// append attributes |
|
639 |
for (int i=0; i<atts.getLength(); i++) |
|
640 |
{ |
|
641 |
String attributeName = atts.getQName(i); |
|
642 |
String attributeValue = atts.getValue(i); |
|
643 |
inlineElements.append(" "); |
|
644 |
inlineElements.append(attributeName); |
|
645 |
inlineElements.append("=\""); |
|
646 |
inlineElements.append(attributeValue); |
|
647 |
inlineElements.append("\""); |
|
648 |
} |
|
649 |
// append namespace |
|
650 |
String prefix =null; |
|
651 |
String nsuri = null; |
|
652 |
Enumeration prefixes = inlineDataNameSpace.keys(); |
|
653 |
while ( prefixes.hasMoreElements() ) |
|
654 |
{ |
|
655 |
prefix = (String)prefixes.nextElement(); |
|
656 |
nsuri = (String)namespaces.get(prefix); |
|
657 |
inlineElements.append(" "); |
|
658 |
inlineElements.append("xmlns:"); |
|
659 |
inlineElements.append(prefix); |
|
660 |
inlineElements.append("=\""); |
|
661 |
inlineElements.append(nsuri); |
|
662 |
inlineElements.append("\""); |
|
663 |
} |
|
664 |
inlineElements.append(">"); |
|
665 |
//reset inline data name space |
|
666 |
inlineDataNameSpace = null; |
|
667 |
inlineDataNameSpace = new Hashtable(); |
|
668 |
//write inline data into file |
|
669 |
MetaCatUtil.debugMessage("the inline element data is: "+ |
|
670 |
inlineElements.toString(), 50); |
|
671 |
writeInlineDataIntoFile(inlineDataFileWriter, inlineElements); |
|
672 |
}//else |
|
673 |
|
|
604 | 674 |
} |
605 | 675 |
|
606 | 676 |
private void compareElementNameSpaceAttributes(Stack unchangableNodeStack, |
... | ... | |
785 | 855 |
throw new SAXException(error); |
786 | 856 |
}//if |
787 | 857 |
} |
858 |
|
|
859 |
/** SAX Handler that is called for each XML text node */ |
|
860 |
public void characters(char[] cbuf, int start, int len) throws SAXException |
|
861 |
{ |
|
862 |
MetaCatUtil.debugMessage("CHARACTERS", 50); |
|
863 |
if (!handleInlineData) |
|
864 |
{ |
|
865 |
// buffer all text nodes for same element. This is for text was splited |
|
866 |
// into different nodes |
|
867 |
textBuffer.append(new String(cbuf, start,len)); |
|
868 |
// set hittextnode true |
|
869 |
hitTextNode = true; |
|
870 |
// if text buffer .size is greater than max, write it to db. |
|
871 |
// so we can save memory |
|
872 |
if (textBuffer.length() > MAXDATACHARS) |
|
873 |
{ |
|
874 |
MetaCatUtil.debugMessage("Write text into DB in charaters" + |
|
875 |
" when text buffer size is greater than maxmum number", 50); |
|
876 |
DBSAXNode currentNode = (DBSAXNode)nodeStack.peek(); |
|
877 |
endNodeId = writeTextForDBSAXNode(endNodeId, textBuffer, currentNode); |
|
878 |
textBuffer = null; |
|
879 |
textBuffer = new StringBuffer(); |
|
880 |
} |
|
881 |
} |
|
882 |
else |
|
883 |
{ |
|
884 |
// this is inline data and write file system directly |
|
885 |
// we don't need to buffered it. |
|
886 |
StringBuffer inlineText = new StringBuffer(); |
|
887 |
inlineText.append(new String(cbuf, start,len)); |
|
888 |
MetaCatUtil.debugMessage("The inline text data write into file system: " |
|
889 |
+ inlineText.toString(), 50); |
|
890 |
writeInlineDataIntoFile(inlineDataFileWriter, inlineText); |
|
891 |
} |
|
892 |
} |
|
893 |
|
|
894 |
|
|
788 | 895 |
/** SAX Handler that is called at the end of each XML element */ |
789 | 896 |
public void endElement(String uri, String localName, |
790 | 897 |
String qName) throws SAXException |
791 | 898 |
{ |
792 |
MetaCatUtil.debugMessage("End ELEMENT " + qName, 50); |
|
793 |
|
|
899 |
MetaCatUtil.debugMessage("End ELEMENT " + qName, 50); |
|
900 |
|
|
901 |
if (localName.equals(INLINE) && handleInlineData) |
|
902 |
{ |
|
903 |
// Get the node from the stack |
|
904 |
DBSAXNode currentNode = (DBSAXNode)nodeStack.pop(); |
|
905 |
String currentTag = currentNode.getTagName(); |
|
906 |
MetaCatUtil.debugMessage("End of inline data", 35); |
|
907 |
// close file writer |
|
908 |
try |
|
909 |
{ |
|
910 |
inlineDataFileWriter.close(); |
|
911 |
handleInlineData = false; |
|
912 |
} |
|
913 |
catch (IOException ioe) |
|
914 |
{ |
|
915 |
throw new SAXException(ioe.getMessage()); |
|
916 |
} |
|
917 |
|
|
918 |
//check if user changed inine data or not if user doesn't have |
|
919 |
// write permission |
|
920 |
if (startCriticalSubTree) |
|
921 |
{ |
|
922 |
NodeRecord node = null; |
|
923 |
String inlineData; |
|
924 |
try |
|
925 |
{ |
|
926 |
node = (NodeRecord)currentUnChangedableSubtreeNodeStack.pop(); |
|
927 |
// get file name from db |
|
928 |
String fileName = node.getNodeData(); |
|
929 |
MetaCatUtil.debugMessage("in handle inline data", 35); |
|
930 |
MetaCatUtil.debugMessage("the inline data file name from node is: "+ |
|
931 |
fileName, 40); |
|
932 |
if (!compareInlineDataFiles(fileName, inlineDataFileName)) |
|
933 |
{ |
|
934 |
MetaCatUtil.debugMessage("inline data was changed by a user" + |
|
935 |
" who doesn't have permission", 30); |
|
936 |
throw new SAXException(PERMISSIONERROR); |
|
937 |
} |
|
938 |
} |
|
939 |
catch (EmptyStackException ee) |
|
940 |
{ |
|
941 |
MetaCatUtil.debugMessage("the stack is empty for text data", 32); |
|
942 |
throw new SAXException(PERMISSIONERROR); |
|
943 |
} |
|
944 |
catch (McdbException eee) |
|
945 |
{ |
|
946 |
throw new SAXException(eee.getMessage()); |
|
947 |
} |
|
948 |
finally |
|
949 |
{ |
|
950 |
// delete the inline data file already in file system |
|
951 |
deleteInlineDataFile(inlineDataFileName); |
|
952 |
} |
|
953 |
|
|
954 |
}//if |
|
955 |
// write put inline data file name into text buffer (without path) |
|
956 |
textBuffer = new StringBuffer(inlineDataFileName); |
|
957 |
// write file name into db |
|
958 |
endNodeId = writeTextForDBSAXNode(endNodeId, textBuffer, currentNode); |
|
959 |
return; |
|
960 |
} |
|
961 |
|
|
962 |
if (!handleInlineData) |
|
963 |
{ |
|
794 | 964 |
// Get the node from the stack |
795 | 965 |
DBSAXNode currentNode = (DBSAXNode)nodeStack.pop(); |
796 | 966 |
String currentTag = currentNode.getTagName(); |
... | ... | |
870 | 1040 |
}//if |
871 | 1041 |
}//else if |
872 | 1042 |
// write text to db if it is not inline data |
873 |
if (!localName.equals(INLINE)) |
|
1043 |
//if (!localName.equals(INLINE))
|
|
874 | 1044 |
{ |
875 | 1045 |
MetaCatUtil.debugMessage("Write text into DB in End Element", 50); |
876 | 1046 |
//compare text node if need |
... | ... | |
886 | 1056 |
textBuffer, UPDATEACCESSERROR); |
887 | 1057 |
} |
888 | 1058 |
// write text node into db |
889 |
endNodeId = writeTextForDBSAXNode(textBuffer, currentNode); |
|
1059 |
endNodeId = writeTextForDBSAXNode(endNodeId, textBuffer, currentNode);
|
|
890 | 1060 |
} |
891 |
else |
|
892 |
{ |
|
893 |
MetaCatUtil.debugMessage("Write inline data into file system", 35); |
|
894 |
|
|
895 |
//check if user changed inine data or not if user doesn't have |
|
896 |
// write permission |
|
897 |
if (startCriticalSubTree) |
|
898 |
{ |
|
899 |
NodeRecord node = null; |
|
900 |
String inlineData; |
|
901 |
try |
|
902 |
{ |
|
903 |
node = (NodeRecord)currentUnChangedableSubtreeNodeStack.pop(); |
|
904 |
// get file name from db |
|
905 |
String fileName = node.getNodeData(); |
|
906 |
MetaCatUtil.debugMessage("in handle inline data", 35); |
|
907 |
MetaCatUtil.debugMessage("the inline data file name from node is: "+ |
|
908 |
fileName, 40); |
|
909 |
inlineData = readInlineDataFromFileSystem(fileName); |
|
910 |
} |
|
911 |
catch (EmptyStackException ee) |
|
912 |
{ |
|
913 |
MetaCatUtil.debugMessage("the stack is empty for text data", 32); |
|
914 |
throw new SAXException(PERMISSIONERROR); |
|
915 |
} |
|
916 |
catch (McdbException eee) |
|
917 |
{ |
|
918 |
throw new SAXException(eee.getMessage()); |
|
919 |
} |
|
920 |
|
|
921 |
if (!(textBuffer.toString()).equals(inlineData)) |
|
922 |
{ |
|
923 |
MetaCatUtil.debugMessage("inline data was changed by a user" + |
|
924 |
" who doesn't have permission", 30); |
|
925 |
throw new SAXException(PERMISSIONERROR); |
|
926 |
}//if |
|
927 |
}//if |
|
928 |
// write inline data into file system and return file name |
|
929 |
textBuffer = writeInlineDataIntoFile(textBuffer); |
|
930 |
// write file name into db |
|
931 |
endNodeId = writeTextForDBSAXNode(textBuffer, currentNode); |
|
932 |
} |
|
933 |
|
|
934 | 1061 |
if (needCheckingAccessModule && |
935 | 1062 |
(processAdditionalAccess || processOtherAccess || processTopLeverAccess)) |
936 | 1063 |
{ |
... | ... | |
1064 | 1191 |
describesId = null; |
1065 | 1192 |
describesId = new Vector(); |
1066 | 1193 |
} |
1067 |
|
|
1068 |
} |
|
1194 |
} |
|
1195 |
else |
|
1196 |
{ |
|
1197 |
// this is in inline part |
|
1198 |
StringBuffer endElement = new StringBuffer(); |
|
1199 |
endElement.append("</"); |
|
1200 |
endElement.append(qName); |
|
1201 |
endElement.append(">"); |
|
1202 |
MetaCatUtil.debugMessage("inline endElement: " + |
|
1203 |
endElement.toString(), 50); |
|
1204 |
writeInlineDataIntoFile(inlineDataFileWriter, endElement); |
|
1205 |
} |
|
1206 |
} |
|
1069 | 1207 |
|
1070 | 1208 |
/** |
1071 | 1209 |
* SAX Handler that receives notification of comments in the DTD |
1072 | 1210 |
*/ |
1073 |
public void comment(char[] ch, int start, int length) throws SAXException { |
|
1211 |
public void comment(char[] ch, int start, int length) throws SAXException |
|
1212 |
{ |
|
1074 | 1213 |
MetaCatUtil.debugMessage("COMMENT", 50); |
1075 |
if ( !processingDTD )
|
|
1214 |
if ( !handleInlineData)
|
|
1076 | 1215 |
{ |
1077 |
DBSAXNode currentNode = (DBSAXNode)nodeStack.peek(); |
|
1078 |
String str = new String(ch, start, length); |
|
1216 |
if ( !processingDTD ) |
|
1217 |
{ |
|
1218 |
DBSAXNode currentNode = (DBSAXNode)nodeStack.peek(); |
|
1219 |
String str = new String(ch, start, length); |
|
1079 | 1220 |
|
1080 |
//compare comment if need |
|
1081 |
if (startCriticalSubTree) |
|
1082 |
{ |
|
1083 |
compareCommentNode(currentUnChangedableSubtreeNodeStack, str, |
|
1221 |
//compare comment if need
|
|
1222 |
if (startCriticalSubTree)
|
|
1223 |
{
|
|
1224 |
compareCommentNode(currentUnChangedableSubtreeNodeStack, str,
|
|
1084 | 1225 |
PERMISSIONERROR); |
1085 |
}//if |
|
1086 |
//compare top level access module |
|
1087 |
if (processTopLeverAccess && needCheckingAccessModule) |
|
1088 |
{ |
|
1089 |
compareCommentNode(currentUnchangableAccessModuleNodeStack, str, |
|
1226 |
}//if
|
|
1227 |
//compare top level access module
|
|
1228 |
if (processTopLeverAccess && needCheckingAccessModule)
|
|
1229 |
{
|
|
1230 |
compareCommentNode(currentUnchangableAccessModuleNodeStack, str,
|
|
1090 | 1231 |
UPDATEACCESSERROR); |
1091 |
} |
|
1092 |
endNodeId = currentNode.writeChildNodeToDB("COMMENT", null, str, docid); |
|
1093 |
if (needCheckingAccessModule && |
|
1094 |
(processAdditionalAccess || processOtherAccess || processTopLeverAccess)) |
|
1095 |
{ |
|
1096 |
// stored the pull out nodes into storedNode stack |
|
1097 |
NodeRecord nodeElement = new NodeRecord(-2, -2, -2, "COMMENT", |
|
1232 |
}
|
|
1233 |
endNodeId = currentNode.writeChildNodeToDB("COMMENT", null, str, docid);
|
|
1234 |
if (needCheckingAccessModule &&
|
|
1235 |
(processAdditionalAccess || processOtherAccess || processTopLeverAccess))
|
|
1236 |
{
|
|
1237 |
// stored the pull out nodes into storedNode stack
|
|
1238 |
NodeRecord nodeElement = new NodeRecord(-2, -2, -2, "COMMENT",
|
|
1098 | 1239 |
null, null, MetaCatUtil.normalize(str)); |
1099 |
storedAccessNodeStack.push(nodeElement); |
|
1240 |
storedAccessNodeStack.push(nodeElement);
|
|
1100 | 1241 |
|
1101 |
} |
|
1242 |
} |
|
1243 |
} |
|
1102 | 1244 |
} |
1245 |
else |
|
1246 |
{ |
|
1247 |
// inline data comment |
|
1248 |
StringBuffer inlineComment = new StringBuffer(); |
|
1249 |
inlineComment.append("<!--"); |
|
1250 |
inlineComment.append(new String(ch, start, length)); |
|
1251 |
inlineComment.append("-->"); |
|
1252 |
MetaCatUtil.debugMessage("inline data comment: "+ |
|
1253 |
inlineComment.toString(), 50); |
|
1254 |
writeInlineDataIntoFile(inlineDataFileWriter, inlineComment); |
|
1255 |
} |
|
1103 | 1256 |
} |
1104 | 1257 |
|
1258 |
|
|
1105 | 1259 |
/* Comparet comment from xml and db */ |
1106 | 1260 |
private void compareCommentNode(Stack nodeStack, String string, String error) |
1107 | 1261 |
throws SAXException |
... | ... | |
1143 | 1297 |
}//if |
1144 | 1298 |
} |
1145 | 1299 |
|
1300 |
/** |
|
1301 |
* SAX Handler called once for each processing instruction found: |
|
1302 |
* node that PI may occur before or after the root element. |
|
1303 |
*/ |
|
1304 |
public void processingInstruction(String target, String data) |
|
1305 |
throws SAXException |
|
1306 |
{ |
|
1307 |
MetaCatUtil.debugMessage("PI", 50); |
|
1308 |
if (!handleInlineData) |
|
1309 |
{ |
|
1310 |
DBSAXNode currentNode = (DBSAXNode)nodeStack.peek(); |
|
1311 |
endNodeId = currentNode.writeChildNodeToDB("PI", target, data, docid); |
|
1312 |
} |
|
1313 |
else |
|
1314 |
{ |
|
1315 |
StringBuffer inlinePI = new StringBuffer(); |
|
1316 |
inlinePI.append("<?"); |
|
1317 |
inlinePI.append(target); |
|
1318 |
inlinePI.append(" "); |
|
1319 |
inlinePI.append(data); |
|
1320 |
inlinePI.append("?>"); |
|
1321 |
MetaCatUtil.debugMessage("inline data pi is: " + |
|
1322 |
inlinePI.toString(), 50); |
|
1323 |
writeInlineDataIntoFile(inlineDataFileWriter, inlinePI); |
|
1324 |
} |
|
1325 |
} |
|
1326 |
|
|
1327 |
/** SAX Handler that is called at the start of Namespace */ |
|
1328 |
public void startPrefixMapping(String prefix, String uri) |
|
1329 |
throws SAXException |
|
1330 |
{ |
|
1331 |
MetaCatUtil.debugMessage("NAMESPACE", 50); |
|
1332 |
if (!handleInlineData) |
|
1333 |
{ |
|
1334 |
namespaces.put(prefix, uri); |
|
1335 |
} |
|
1336 |
else |
|
1337 |
{ |
|
1338 |
inlineDataNameSpace.put(prefix, uri); |
|
1339 |
} |
|
1340 |
} |
|
1146 | 1341 |
/** |
1147 | 1342 |
* SAX Handler that is called for each XML text node that is |
1148 | 1343 |
* Ignorable white space |
... | ... | |
1154 | 1349 |
// When validation is turned "off" white spaces are not reported here, |
1155 | 1350 |
// but through characters() callback |
1156 | 1351 |
MetaCatUtil.debugMessage("IGNORABLEWHITESPACE", 50); |
1157 |
DBSAXNode currentNode = (DBSAXNode)nodeStack.peek(); |
|
1158 |
String data = null; |
|
1159 |
int leftover = len; |
|
1160 |
int offset = start; |
|
1161 |
boolean moredata = true; |
|
1352 |
if (!handleInlineData) |
|
1353 |
{ |
|
1354 |
DBSAXNode currentNode = (DBSAXNode)nodeStack.peek(); |
|
1355 |
String data = null; |
|
1356 |
int leftover = len; |
|
1357 |
int offset = start; |
|
1358 |
boolean moredata = true; |
|
1162 | 1359 |
|
1163 |
// This loop deals with the case where there are more characters |
|
1164 |
// than can fit in a single database text field (limit is |
|
1165 |
// MAXDATACHARS). If the text to be inserted exceeds MAXDATACHARS, |
|
1166 |
// write a series of nodes that are MAXDATACHARS long, and then the |
|
1167 |
// final node contains the remainder |
|
1168 |
while (moredata) |
|
1169 |
{ |
|
1170 |
if (leftover > MAXDATACHARS) |
|
1360 |
// This loop deals with the case where there are more characters |
|
1361 |
// than can fit in a single database text field (limit is |
|
1362 |
// MAXDATACHARS). If the text to be inserted exceeds MAXDATACHARS, |
|
1363 |
// write a series of nodes that are MAXDATACHARS long, and then the |
|
1364 |
// final node contains the remainder |
|
1365 |
while (moredata) |
|
1171 | 1366 |
{ |
1172 |
data = new String(cbuf, offset, MAXDATACHARS); |
|
1173 |
leftover -= MAXDATACHARS; |
|
1174 |
offset += MAXDATACHARS; |
|
1175 |
} |
|
1176 |
else |
|
1177 |
{ |
|
1178 |
data = new String(cbuf, offset, leftover); |
|
1179 |
moredata = false; |
|
1180 |
} |
|
1367 |
if (leftover > MAXDATACHARS) |
|
1368 |
{ |
|
1369 |
data = new String(cbuf, offset, MAXDATACHARS); |
|
1370 |
leftover -= MAXDATACHARS; |
|
1371 |
offset += MAXDATACHARS; |
|
1372 |
} |
|
1373 |
else |
|
1374 |
{ |
|
1375 |
data = new String(cbuf, offset, leftover); |
|
1376 |
moredata = false; |
|
1377 |
} |
|
1181 | 1378 |
|
1182 |
//compare whitespace if need |
|
1183 |
if (startCriticalSubTree) |
|
1184 |
{ |
|
1185 |
compareWhiteSpace(currentUnChangedableSubtreeNodeStack, data, |
|
1379 |
//compare whitespace if need
|
|
1380 |
if (startCriticalSubTree)
|
|
1381 |
{
|
|
1382 |
compareWhiteSpace(currentUnChangedableSubtreeNodeStack, data,
|
|
1186 | 1383 |
PERMISSIONERROR); |
1187 |
}//if |
|
1384 |
}//if
|
|
1188 | 1385 |
|
1189 |
//compare whitespace in access top module |
|
1190 |
if (processTopLeverAccess && needCheckingAccessModule) |
|
1191 |
{ |
|
1192 |
compareWhiteSpace(currentUnchangableAccessModuleNodeStack, data, |
|
1386 |
//compare whitespace in access top module
|
|
1387 |
if (processTopLeverAccess && needCheckingAccessModule)
|
|
1388 |
{
|
|
1389 |
compareWhiteSpace(currentUnchangableAccessModuleNodeStack, data,
|
|
1193 | 1390 |
UPDATEACCESSERROR); |
1194 |
} |
|
1195 |
// Write the content of the node to the database |
|
1196 |
if (needCheckingAccessModule && |
|
1197 |
(processAdditionalAccess || processOtherAccess || processTopLeverAccess)) |
|
1198 |
{ |
|
1199 |
// stored the pull out nodes into storedNode stack |
|
1200 |
NodeRecord nodeElement = new NodeRecord(-2, -2, -2, "TEXT", |
|
1391 |
}
|
|
1392 |
// Write the content of the node to the database
|
|
1393 |
if (needCheckingAccessModule &&
|
|
1394 |
(processAdditionalAccess || processOtherAccess || processTopLeverAccess))
|
|
1395 |
{
|
|
1396 |
// stored the pull out nodes into storedNode stack
|
|
1397 |
NodeRecord nodeElement = new NodeRecord(-2, -2, -2, "TEXT",
|
|
1201 | 1398 |
null, null, MetaCatUtil.normalize(data)); |
1202 |
storedAccessNodeStack.push(nodeElement); |
|
1399 |
storedAccessNodeStack.push(nodeElement);
|
|
1203 | 1400 |
|
1401 |
} |
|
1402 |
endNodeId = currentNode.writeChildNodeToDB("TEXT", null, data, docid); |
|
1204 | 1403 |
} |
1205 |
endNodeId = currentNode.writeChildNodeToDB("TEXT", null, data, docid); |
|
1206 | 1404 |
} |
1405 |
else |
|
1406 |
{ |
|
1407 |
//This is inline data write to file directly |
|
1408 |
StringBuffer inlineWhiteSpace = new |
|
1409 |
StringBuffer(new String(cbuf, start, len)); |
|
1410 |
writeInlineDataIntoFile(inlineDataFileWriter, inlineWhiteSpace); |
|
1411 |
} |
|
1412 |
|
|
1207 | 1413 |
} |
1208 | 1414 |
|
1209 | 1415 |
/* Compare whitespace from xml and db */ |
... | ... | |
1886 | 2092 |
} |
1887 | 2093 |
}//deleteAccessSubTreeRecord |
1888 | 2094 |
|
1889 |
// write inline data into file system and return file name(without path)
|
|
1890 |
private StringBuffer writeInlineDataIntoFile(StringBuffer data)
|
|
2095 |
// open a file writer for writing inline data to file
|
|
2096 |
private FileWriter createInlineDataFileWriter(String fileName)
|
|
1891 | 2097 |
throws SAXException |
1892 | 2098 |
{ |
1893 |
StringBuffer fileNameBuffer = null; |
|
1894 |
String fileName = null; |
|
1895 |
String docidWithoutRev = MetaCatUtil.getDocIdFromString(docid); |
|
2099 |
FileWriter writer = null; |
|
1896 | 2100 |
String path = MetaCatUtil.getOption("inlinedatafilepath"); |
1897 |
String seperator = MetaCatUtil.getOption("accNumSeparator"); |
|
1898 |
// the new file name will look like path/docid.rev.2 |
|
1899 |
fileName = docidWithoutRev + seperator+revision+seperator +inLineDataIndex; |
|
1900 | 2101 |
File inlineDataDirectory = new File(path); |
1901 |
File newFile = new File(inlineDataDirectory, fileName); |
|
1902 |
// incease inLinedataindex for next one |
|
1903 |
inLineDataIndex++ ; |
|
2102 |
File newFile = new File(inlineDataDirectory, fileName); |
|
1904 | 2103 |
try |
1905 | 2104 |
{ |
1906 |
FileWriter writer = new FileWriter(newFile); |
|
2105 |
// true means append |
|
2106 |
writer = new FileWriter(newFile, true); |
|
2107 |
} |
|
2108 |
catch (IOException ioe) |
|
2109 |
{ |
|
2110 |
throw new SAXException(ioe.getMessage()); |
|
2111 |
} |
|
2112 |
return writer; |
|
2113 |
} |
|
2114 |
// write inline data into file system and return file name(without path) |
|
2115 |
private void writeInlineDataIntoFile(FileWriter writer, |
|
2116 |
StringBuffer data) |
|
2117 |
throws SAXException |
|
2118 |
{ |
|
2119 |
try |
|
2120 |
{ |
|
1907 | 2121 |
writer.write(data.toString()); |
1908 |
writer.close();
|
|
2122 |
writer.flush();
|
|
1909 | 2123 |
} |
1910 | 2124 |
catch (Exception e) |
1911 | 2125 |
{ |
1912 | 2126 |
throw new SAXException(e.getMessage()); |
1913 | 2127 |
} |
2128 |
} |
|
2129 |
|
|
2130 |
/* In eml2, the inline data wouldn't store in db, it store in file system |
|
2131 |
* The db stores file name(without path). We got the old file name from db |
|
2132 |
* and compare to the new in line data file |
|
2133 |
*/ |
|
2134 |
public boolean compareInlineDataFiles(String oldFileName, String newFileName) |
|
2135 |
throws McdbException |
|
2136 |
{ |
|
2137 |
// this method need to be testing |
|
2138 |
boolean same = true; |
|
2139 |
String data = null; |
|
2140 |
String path = MetaCatUtil.getOption("inlinedatafilepath"); |
|
2141 |
// the new file name will look like path/docid.rev.2 |
|
2142 |
File inlineDataDirectory = new File(path); |
|
2143 |
File oldDataFile = new File(inlineDataDirectory, oldFileName); |
|
2144 |
File newDataFile = new File(inlineDataDirectory, newFileName); |
|
2145 |
try |
|
2146 |
{ |
|
2147 |
FileReader oldFileReader = new FileReader(oldDataFile); |
|
2148 |
BufferedReader oldStringReader = new BufferedReader(oldFileReader); |
|
2149 |
FileReader newFileReader = new FileReader(newDataFile); |
|
2150 |
BufferedReader newStringReader = new BufferedReader(newFileReader); |
|
2151 |
// read first line of data |
|
2152 |
String oldString = oldStringReader.readLine(); |
|
2153 |
String newString = newStringReader.readLine(); |
|
2154 |
|
|
2155 |
// at the end oldstring will be null |
|
2156 |
while (oldString != null) |
|
2157 |
{ |
|
2158 |
oldString = oldStringReader.readLine(); |
|
2159 |
newString = newStringReader.readLine(); |
|
2160 |
if (!oldString.equals(newString)) |
|
2161 |
{ |
|
2162 |
same = false; |
|
2163 |
break; |
|
2164 |
} |
|
2165 |
} |
|
2166 |
|
|
2167 |
// if oldString is null but newString is not null, they are same |
|
2168 |
if (same) |
|
2169 |
{ |
|
2170 |
if (newString != null) |
|
2171 |
{ |
|
2172 |
same = false; |
|
2173 |
} |
|
2174 |
} |
|
2175 |
|
|
2176 |
} |
|
2177 |
catch (Exception e) |
|
2178 |
{ |
|
2179 |
throw new McdbException(e.getMessage()); |
|
2180 |
} |
|
2181 |
MetaCatUtil.debugMessage("the inline data retrieve from file: "+data, 50); |
|
2182 |
return same; |
|
2183 |
} |
|
2184 |
|
|
2185 |
/* delete the inline data file */ |
|
2186 |
private void deleteInlineDataFile(String fileName) |
|
2187 |
{ |
|
1914 | 2188 |
|
1915 |
fileNameBuffer = new StringBuffer(fileName); |
|
1916 |
return fileNameBuffer; |
|
2189 |
String path = MetaCatUtil.getOption("inlinedatafilepath"); |
|
2190 |
File inlineDataDirectory = new File(path); |
|
2191 |
File newFile = new File(inlineDataDirectory, fileName); |
|
2192 |
newFile.delete(); |
|
2193 |
|
|
1917 | 2194 |
} |
1918 | 2195 |
|
1919 |
/* In eml2, the inline data wouldn't store in db, it store in file system |
|
2196 |
/* In eml2, the inline data wouldn't store in db, it store in file system
|
|
1920 | 2197 |
* The db stores file name(without path). |
1921 | 2198 |
*/ |
1922 | 2199 |
public static String readInlineDataFromFileSystem(String fileName) |
Also available in: Unified diff
Change the way to handle inline data.