Revision 4472
Added by daigle about 16 years ago
src/edu/ucsb/nceas/metacat/Eml210SAXHandler.java | ||
---|---|---|
52 | 52 |
import edu.ucsb.nceas.utilities.PropertyNotFoundException; |
53 | 53 |
|
54 | 54 |
/** |
55 |
* A database aware Class implementing callback bethods for the SAX parser to
|
|
55 |
* A database aware Class implementing callback methods for the SAX parser to
|
|
56 | 56 |
* call when processing the XML stream and generating events |
57 | 57 |
*/ |
58 | 58 |
public class Eml210SAXHandler extends DBSAXHandler implements |
59 | 59 |
AccessControlInterface |
60 | 60 |
{ |
61 | 61 |
|
62 |
private Vector allowRules = new Vector();
|
|
62 |
private boolean processTopLevelAccess = false;
|
|
63 | 63 |
|
64 |
private Vector denyRules = new Vector(); |
|
65 |
|
|
66 |
private String documentId = null; |
|
67 |
|
|
68 |
private Vector subDocumentIdList = new Vector(); |
|
69 |
|
|
70 |
private boolean processTopLeverAccess = false; |
|
71 |
|
|
72 | 64 |
private boolean processAdditionalAccess = false; |
73 | 65 |
|
74 | 66 |
private boolean processOtherAccess = false; |
... | ... | |
77 | 69 |
|
78 | 70 |
private AccessRule accessRule = null; |
79 | 71 |
|
80 |
private Vector accessObjectList = new Vector(); // store every access rule
|
|
72 |
private Vector<AccessSection> accessObjectList = new Vector<AccessSection>(); // store every access rule
|
|
81 | 73 |
|
82 |
private Hashtable topLevelAccessControlMap = new Hashtable();
|
|
74 |
private Hashtable<String,AccessSection> topLevelAccessControlMap = new Hashtable<String,AccessSection>();
|
|
83 | 75 |
|
84 |
private Hashtable additionalAccessControlMap = new Hashtable();// store
|
|
76 |
private Hashtable<String,AccessSection> additionalAccessControlMap = new Hashtable<String,AccessSection>();// store
|
|
85 | 77 |
|
86 |
//subtree access for single |
|
87 |
// additionalmetacat |
|
88 |
private Vector additionalAccessMapList = new Vector();// store maps for |
|
78 |
//subtree access for single additionalmetacat |
|
79 |
private Vector<Hashtable<String,AccessSection>> additionalAccessMapList = new Vector<Hashtable<String,AccessSection>>();// store maps for |
|
89 | 80 |
|
90 |
// every addionalmetadata |
|
91 |
private Vector describesId = new Vector(); // store the ids in
|
|
81 |
// every additionalmetadata
|
|
82 |
private Vector<String> describesId = new Vector<String>(); // store the ids in
|
|
92 | 83 |
|
93 | 84 |
//additionalmetadata/describes |
94 |
private Stack subTreeInfoStack = new Stack();
|
|
85 |
private Stack<SubTree> subTreeInfoStack = new Stack<SubTree>();
|
|
95 | 86 |
|
96 |
private Vector subTreeList = new Vector();// store the final subtree
|
|
87 |
private Vector<SubTree> subTreeList = new Vector<SubTree>();// store the final subtree
|
|
97 | 88 |
|
98 |
private Hashtable unChangableSubTreeHash = new Hashtable(); |
|
89 |
// MCD - Removed the following lines. They are used for node level access control |
|
90 |
// which is not yet implemented in EML 2.1.0 |
|
91 |
// private Hashtable<String,SubTree> unChangeableSubTreeHash = new Hashtable<String,SubTree>(); |
|
92 |
// private Stack<NodeRecord> currentUnChangeableSubtreeNodeStack = new Stack<NodeRecord>(); |
|
93 |
// private boolean startCriticalSubTree = false; |
|
94 |
// private boolean firstElementForCriticalSubTree = false; |
|
95 |
// private String firstElementNameForCriticalSubTree; |
|
99 | 96 |
|
100 |
private Stack currentUnChangedableSubtreeNodeStack = new Stack();
|
|
97 |
private boolean needToCheckAccessModule = false;
|
|
101 | 98 |
|
102 |
private boolean startCriticalSubTree = false;
|
|
99 |
private Vector<AccessSection> unChangeableAccessSubTreeVector = new Vector<AccessSection>();
|
|
103 | 100 |
|
104 |
private boolean firstElementForCriticalSubTree = false;
|
|
101 |
private Stack<NodeRecord> currentUnchangeableAccessModuleNodeStack = new Stack<NodeRecord>();
|
|
105 | 102 |
|
106 |
private String firstElementNameForCriticalSubTree; |
|
107 |
|
|
108 |
private boolean needCheckingAccessModule = false; |
|
109 |
|
|
110 |
private Vector unChangableAccessSubTreeVector = new Vector(); |
|
111 |
|
|
112 |
private Stack currentUnchangableAccessModuleNodeStack = new Stack(); |
|
113 |
|
|
114 | 103 |
private AccessSection topAccessSection; |
115 | 104 |
|
116 | 105 |
// we need an another stack to store the access node which we pull out just |
117 |
// from xml. If a reference happend, we can use the stack the compare nodes |
|
118 |
private Stack storedAccessNodeStack = new Stack();
|
|
106 |
// from xml. If a reference happened, we can use the stack the compare nodes
|
|
107 |
private Stack<NodeRecord> storedAccessNodeStack = new Stack<NodeRecord>();
|
|
119 | 108 |
|
120 | 109 |
// vector stored the data file id which will be write into relation table |
121 |
private Vector onlineDataFileIdInRelationVector = new Vector();
|
|
110 |
private Vector<String> onlineDataFileIdInRelationVector = new Vector<String>();
|
|
122 | 111 |
|
123 | 112 |
// vector stored the data file id which will be write top access rules to |
124 | 113 |
// access table |
125 |
private Vector onlineDataFileIdInTopAccessVector = new Vector();
|
|
114 |
private Vector<String> onlineDataFileIdInTopAccessVector = new Vector<String>();
|
|
126 | 115 |
|
127 | 116 |
// Indicator of inline data |
128 | 117 |
private boolean handleInlineData = false; |
129 | 118 |
|
130 |
private Stack inlineDataNodeStack = null;
|
|
119 |
private Hashtable<String,String> inlineDataNameSpace = null;
|
|
131 | 120 |
|
132 |
private Hashtable inlineDataNameSpace = null; |
|
133 |
|
|
134 | 121 |
private FileWriter inlineDataFileWriter = null; |
135 | 122 |
|
136 | 123 |
private String inlineDataFileName = null; |
137 | 124 |
|
138 |
private int inLineDataIndex = 0; |
|
125 |
// This variable keeps a counter of each distribution element. This index will |
|
126 |
// be used to name the inline data file that gets written to disk, and to strip |
|
127 |
// inline data from the metadata document on file if the user does not have read |
|
128 |
// access. |
|
129 |
private int distributionIndex = 0; |
|
139 | 130 |
|
140 |
private Vector inlineFileIDList = new Vector(); |
|
131 |
// This is used to delete inline files if the xml does not parse correctly. |
|
132 |
private Vector<String> inlineFileIdList = new Vector<String>(); |
|
141 | 133 |
|
142 | 134 |
// Constant |
143 | 135 |
private static final String EML = "eml"; |
136 |
|
|
137 |
private static final String DISTRIBUTION = "distribution"; |
|
144 | 138 |
|
145 |
private static final String DESCRIBES = "describes"; |
|
146 |
|
|
147 |
private static final String ADDITIONALMETADATA = "additionalMetadata"; |
|
148 |
|
|
149 | 139 |
private static final String ORDER = "order"; |
150 | 140 |
|
151 | 141 |
private static final String ID = "id"; |
... | ... | |
158 | 148 |
|
159 | 149 |
private static final String URL = "url"; |
160 | 150 |
|
161 |
private static final String PERMISSIONERROR = "User try to update a subtree"
|
|
162 |
+ " which it doesn't have write permission!";
|
|
151 |
// private static final String PERMISSIONERROR = "User tried to update a subtree "
|
|
152 |
// + "when they don't have write permission!";
|
|
163 | 153 |
|
164 |
private static final String UPDATEACCESSERROR = "User try to update a "
|
|
165 |
+ "access module which it doesn't have \"ALL\" permission!";
|
|
154 |
private static final String UPDATEACCESSERROR = "User tried to update an "
|
|
155 |
+ "access module when they don't have \"ALL\" permission!";
|
|
166 | 156 |
|
167 | 157 |
private static final String TOPLEVEL = "top"; |
168 | 158 |
|
... | ... | |
174 | 164 |
|
175 | 165 |
/** |
176 | 166 |
* Construct an instance of the handler class In this constructor, user can |
177 |
* specify the version need to upadate
|
|
167 |
* specify the version need to update |
|
178 | 168 |
* |
179 | 169 |
* @param conn the JDBC connection to which information is written |
180 | 170 |
* @param action - "INSERT" or "UPDATE" |
... | ... | |
193 | 183 |
{ |
194 | 184 |
super(conn, action, docid, revision, user, groups, pub, |
195 | 185 |
serverCode, createDate, updateDate); |
196 |
// Get the unchangable subtrees (user doesn't have write permission) |
|
186 |
// Get the unchangeable subtrees (user doesn't have write permission)
|
|
197 | 187 |
try { |
198 | 188 |
PermissionController control = new PermissionController(docid |
199 | 189 |
+ PropertyService.getProperty("document.accNumSeparator") + revision); |
... | ... | |
201 | 191 |
// groups); |
202 | 192 |
|
203 | 193 |
//If the action is update and user doesn't have "ALL" permission |
204 |
// we need to check if user update access subtree |
|
194 |
// we need to check if user can update access subtree
|
|
205 | 195 |
if (action.equals("UPDATE") |
206 | 196 |
&& !control.hasPermission(user, groups, |
207 | 197 |
AccessControlInterface.ALLSTRING)) { |
208 |
needCheckingAccessModule = true;
|
|
209 |
unChangableAccessSubTreeVector = getAccessSubTreeListFromDB(); |
|
198 |
needToCheckAccessModule = true;
|
|
199 |
unChangeableAccessSubTreeVector = getAccessSubTreeListFromDB();
|
|
210 | 200 |
} |
211 | 201 |
} catch (Exception e) { |
212 | 202 |
throw new SAXException(e.getMessage()); |
213 | 203 |
} |
214 | 204 |
} |
215 | 205 |
|
216 |
/* Pass a permission control and get the list of unchangable subtree */ |
|
217 |
private Hashtable getUnchangableSubTree(PermissionController controller, |
|
218 |
String user, String[] groups) throws Exception |
|
219 |
{ |
|
220 |
Hashtable list = null; |
|
221 |
Hashtable result = new Hashtable(); |
|
222 |
// get unwritable sutree from controller |
|
223 |
list = null; |
|
224 |
// changed after old code removal |
|
225 |
//controller.hasUnaccessableSubTree(user, groups, |
|
226 |
// AccessControlInterface.WRITESTRING); |
|
227 |
if (list != null) { |
|
206 |
// MCD - Removed the following method. It is used for node level access control |
|
207 |
// which is not yet implemented in EML 2.1.0 |
|
208 |
// /* Pass a permission control and get the list of unchangable subtree */ |
|
209 |
// private Hashtable getUnchangableSubTree(PermissionController controller, |
|
210 |
// String user, String[] groups) throws Exception |
|
211 |
// { |
|
212 |
// Hashtable list = null; |
|
213 |
// Hashtable result = new Hashtable(); |
|
214 |
// // get unwritable sutree from controller |
|
215 |
// list = null; |
|
216 |
// // changed after old code removal |
|
217 |
// //controller.hasUnaccessableSubTree(user, groups, |
|
218 |
// // AccessControlInterface.WRITESTRING); |
|
219 |
// if (list != null) { |
|
220 |
// |
|
221 |
// Enumeration en = list.elements(); |
|
222 |
// while (en.hasMoreElements()) { |
|
223 |
// // Get a subtree without node record list |
|
224 |
// SubTree treeWithoutStack = (SubTree) en.nextElement(); |
|
225 |
// String subTreeId = treeWithoutStack.getSubTreeId(); |
|
226 |
// logMetacat.info( |
|
227 |
// "unchangable subtree id: " + subTreeId); |
|
228 |
// long startNodeId = treeWithoutStack.getStartNodeId(); |
|
229 |
// logMetacat.info("unchangable subtree startnodeid: " |
|
230 |
// + startNodeId); |
|
231 |
// long endNodeId = treeWithoutStack.getEndNodeId(); |
|
232 |
// logMetacat.info("unchangable subtree endnodeid: " |
|
233 |
// + endNodeId); |
|
234 |
// // Get a subtree has the nodelist |
|
235 |
// SubTree tree = new SubTree(docid, subTreeId, startNodeId, |
|
236 |
// endNodeId); |
|
237 |
// // add this tree to the result |
|
238 |
// result.put(subTreeId, tree); |
|
239 |
// |
|
240 |
// }//while |
|
241 |
// |
|
242 |
// }//if |
|
243 |
// |
|
244 |
// return result; |
|
245 |
// } |
|
228 | 246 |
|
229 |
Enumeration en = list.elements(); |
|
230 |
while (en.hasMoreElements()) { |
|
231 |
// Get a subtree without node record list |
|
232 |
SubTree treeWithoutStack = (SubTree) en.nextElement(); |
|
233 |
String subTreeId = treeWithoutStack.getSubTreeId(); |
|
234 |
logMetacat.info( |
|
235 |
"unchangable subtree id: " + subTreeId); |
|
236 |
long startNodeId = treeWithoutStack.getStartNodeId(); |
|
237 |
logMetacat.info("unchangable subtree startnodeid: " |
|
238 |
+ startNodeId); |
|
239 |
long endNodeId = treeWithoutStack.getEndNodeId(); |
|
240 |
logMetacat.info("unchangable subtree endnodeid: " |
|
241 |
+ endNodeId); |
|
242 |
// Get a subtree has the nodelist |
|
243 |
SubTree tree = new SubTree(docid, subTreeId, startNodeId, |
|
244 |
endNodeId); |
|
245 |
// add this tree to the result |
|
246 |
result.put(subTreeId, tree); |
|
247 |
|
|
248 |
}//while |
|
249 |
|
|
250 |
}//if |
|
251 |
|
|
252 |
return result; |
|
253 |
} |
|
254 |
|
|
255 | 247 |
/* |
256 | 248 |
* Get the subtree node info from xml_accesssubtree table |
257 | 249 |
*/ |
258 |
private Vector getAccessSubTreeListFromDB() throws Exception |
|
250 |
private Vector<AccessSection> getAccessSubTreeListFromDB() throws Exception
|
|
259 | 251 |
{ |
260 |
Vector result = new Vector();
|
|
252 |
Vector<AccessSection> result = new Vector<AccessSection>();
|
|
261 | 253 |
PreparedStatement pstmt = null; |
262 | 254 |
ResultSet rs = null; |
263 | 255 |
String sql = "SELECT controllevel, subtreeid, startnodeid, endnodeid " |
... | ... | |
287 | 279 |
accessObj.setSubTreeId(sectionId); |
288 | 280 |
accessObj.setStartNodeId(startNodeId); |
289 | 281 |
accessObj.setEndNodeId(endNodeId); |
290 |
Stack nodeStack = accessObj.getSubTreeNodeStack(); |
|
282 |
Stack<NodeRecord> nodeStack = accessObj.getSubTreeNodeStack();
|
|
291 | 283 |
accessObj.setSubTreeNodeStack(nodeStack); |
292 | 284 |
// add this access obj into vector |
293 | 285 |
result.add(accessObj); |
... | ... | |
322 | 314 |
// for element <eml:eml...> qname is "eml:eml", local name is "eml" |
323 | 315 |
// for element <acl....> both qname and local name is "eml" |
324 | 316 |
// uri is namesapce |
325 |
logMetacat.info("Start ELEMENT(qName) " + qName);
|
|
326 |
logMetacat.info("Start ELEMENT(localName) " + localName);
|
|
327 |
logMetacat.info("Start ELEMENT(uri) " + uri);
|
|
317 |
logMetacat.debug("Start ELEMENT(qName) " + qName);
|
|
318 |
logMetacat.debug("Start ELEMENT(localName) " + localName);
|
|
319 |
logMetacat.debug("Start ELEMENT(uri) " + uri);
|
|
328 | 320 |
|
329 | 321 |
DBSAXNode parentNode = null; |
330 | 322 |
DBSAXNode currentNode = null; |
... | ... | |
340 | 332 |
//start handle inline data |
341 | 333 |
if (localName.equals(INLINE)) { |
342 | 334 |
handleInlineData = true; |
343 |
inLineDataIndex++; |
|
344 |
//intitialize namespace hash for in line data |
|
345 |
inlineDataNameSpace = new Hashtable(); |
|
335 |
//initialize namespace hash for in line data |
|
336 |
inlineDataNameSpace = new Hashtable<String,String>(); |
|
346 | 337 |
//initialize file writer |
347 | 338 |
String docidWithoutRev = MetaCatUtil.getDocIdFromString(docid); |
348 | 339 |
String seperator = "."; |
... | ... | |
353 | 344 |
+ "Setting separator to '.': " + pnfe.getMessage()); |
354 | 345 |
} |
355 | 346 |
// the new file name will look like docid.rev.2 |
356 |
inlineDataFileName = docidWithoutRev + seperator + revision |
|
357 |
+ seperator + inLineDataIndex;
|
|
347 |
inlineDataFileName = docidWithoutRev + seperator + revision + seperator
|
|
348 |
+ distributionIndex;
|
|
358 | 349 |
inlineDataFileWriter = createInlineDataFileWriter(inlineDataFileName); |
359 | 350 |
// put the inline file id into a vector. If upload failed, |
360 |
// metacat will |
|
361 |
// delete the inline data file |
|
362 |
inlineFileIDList.add(inlineDataFileName); |
|
351 |
// metacat will delete the inline data file |
|
352 |
inlineFileIdList.add(inlineDataFileName); |
|
363 | 353 |
|
364 | 354 |
} |
365 | 355 |
|
366 | 356 |
// If hit a text node, we need write this text for current's parent |
367 |
// node |
|
368 |
// This will happend if the element is mixted |
|
357 |
// node This will happen if the element is mixed |
|
369 | 358 |
if (hitTextNode && parentNode != null) { |
370 |
//compare text node data for unchangesubtree |
|
371 |
if (startCriticalSubTree) { |
|
372 |
compareTextNode(currentUnChangedableSubtreeNodeStack, |
|
373 |
textBuffer, PERMISSIONERROR); |
|
374 |
}//if |
|
359 |
// MCD - Removed the following method. It is used for node level access control |
|
360 |
// which is not yet implemented in EML 2.1.0 |
|
361 |
// //compare text node data for unchangeablesubtree |
|
362 |
// if (startCriticalSubTree) { |
|
363 |
// compareTextNode(currentUnChangeableSubtreeNodeStack, |
|
364 |
// textBuffer, PERMISSIONERROR); |
|
365 |
// }//if |
|
375 | 366 |
|
376 | 367 |
//compare top level access module |
377 |
if (processTopLeverAccess && needCheckingAccessModule) {
|
|
378 |
compareTextNode(currentUnchangableAccessModuleNodeStack, |
|
368 |
if (processTopLevelAccess && needToCheckAccessModule) {
|
|
369 |
compareTextNode(currentUnchangeableAccessModuleNodeStack,
|
|
379 | 370 |
textBuffer, UPDATEACCESSERROR); |
380 | 371 |
} |
381 | 372 |
|
382 |
if (needCheckingAccessModule
|
|
383 |
&& (processAdditionalAccess || processOtherAccess || processTopLeverAccess)) {
|
|
373 |
if (needToCheckAccessModule
|
|
374 |
&& (processAdditionalAccess || processOtherAccess || processTopLevelAccess)) {
|
|
384 | 375 |
// stored the pull out nodes into storedNode stack |
385 | 376 |
NodeRecord nodeElement = new NodeRecord(-2, -2, -2, "TEXT", |
386 | 377 |
null, null, MetaCatUtil.normalize(textBuffer |
... | ... | |
414 | 405 |
} else { |
415 | 406 |
doctype = docname; |
416 | 407 |
} |
417 |
logMetacat.info("DOCNAME-a: " + docname);
|
|
418 |
logMetacat.info("DOCTYPE-a: " + doctype);
|
|
408 |
logMetacat.debug("DOCNAME-a: " + docname);
|
|
409 |
logMetacat.debug("DOCTYPE-a: " + doctype);
|
|
419 | 410 |
} else if (doctype == null) { |
420 | 411 |
// because docname is not null and it is declared in dtd |
421 | 412 |
// so could not be in schema, no namespace |
422 | 413 |
doctype = docname; |
423 |
logMetacat.info("DOCTYPE-b: " + doctype);
|
|
414 |
logMetacat.debug("DOCTYPE-b: " + doctype);
|
|
424 | 415 |
} |
425 | 416 |
rootNode.writeNodename(docname); |
426 | 417 |
try { |
427 | 418 |
// for validated XML Documents store a reference to XML DB |
428 |
// Catalog |
|
429 |
// Because this is select statement and it needn't to roll |
|
430 |
// back if |
|
431 |
// insert document action fialed. |
|
432 |
// In order to decrease DBConnection usage count, we get a |
|
433 |
// new |
|
434 |
// dbconnection from pool |
|
435 |
//String catalogid = null; |
|
419 |
// Catalog. Because this is select statement and it needn't |
|
420 |
// roll back if insert document action failed. In order to |
|
421 |
// decrease DBConnection usage count, we get a new |
|
422 |
// dbconnection from pool String catalogid = null; |
|
436 | 423 |
DBConnection dbConn = null; |
437 | 424 |
int serialNumber = -1; |
438 | 425 |
|
... | ... | |
460 | 447 |
}//finally |
461 | 448 |
|
462 | 449 |
//create documentImpl object by the constructor which can |
463 |
// specify |
|
464 |
//the revision |
|
450 |
// specify the revision |
|
465 | 451 |
if (!super.getIsRevisionDoc()) |
466 | 452 |
{ |
467 | 453 |
currentDocument = new DocumentImpl(connection, rootNode |
... | ... | |
482 | 468 |
parentNode, rootNode.getNodeID(), docid, doctype); |
483 | 469 |
// Use a local variable to store the element node id |
484 | 470 |
// If this element is a start point of subtree(section), it will be |
485 |
// stored |
|
486 |
// otherwise, it will be discated |
|
471 |
// stored otherwise, it will be discarded |
|
487 | 472 |
long startNodeId = currentNode.getNodeID(); |
488 | 473 |
// Add all of the namespaces |
489 | 474 |
String prefix = null; |
490 | 475 |
String nsuri = null; |
491 |
Enumeration prefixes = namespaces.keys(); |
|
476 |
Enumeration<String> prefixes = namespaces.keys();
|
|
492 | 477 |
while (prefixes.hasMoreElements()) { |
493 |
prefix = (String) prefixes.nextElement();
|
|
494 |
nsuri = (String) namespaces.get(prefix);
|
|
478 |
prefix = prefixes.nextElement(); |
|
479 |
nsuri = namespaces.get(prefix); |
|
495 | 480 |
endNodeId = currentNode.setNamespace(prefix, nsuri, docid); |
496 | 481 |
} |
497 | 482 |
|
... | ... | |
503 | 488 |
attributeValue, docid); |
504 | 489 |
|
505 | 490 |
// To handle name space and schema location if the attribute |
506 |
// name is |
|
507 |
// xsi:schemaLocation. If the name space is in not in catalog |
|
508 |
// table |
|
509 |
// it will be regeistered. |
|
491 |
// name is xsi:schemaLocation. If the name space is in not |
|
492 |
// in catalog table it will be registered. |
|
510 | 493 |
if (attributeName != null |
511 | 494 |
&& attributeName |
512 | 495 |
.indexOf(MetaCatServlet.SCHEMALOCATIONKEYWORD) != -1) { |
... | ... | |
515 | 498 |
resolver.resolveNameSpace(); |
516 | 499 |
|
517 | 500 |
} else if (attributeName != null && attributeName.equals(ID)) { |
518 |
|
|
519 |
//check unchangedable subtree hash if contains this |
|
520 |
// subtree id |
|
521 |
if (unChangableSubTreeHash.containsKey(attributeValue)) { |
|
522 |
// this subtree couldn't be changed by the user and |
|
523 |
// move it from hash |
|
524 |
SubTree currentUnChangedableSubtree = (SubTree) unChangableSubTreeHash |
|
525 |
.remove(attributeValue); |
|
526 |
currentUnChangedableSubtreeNodeStack = currentUnChangedableSubtree |
|
527 |
.getSubTreeNodeStack(); |
|
528 |
startCriticalSubTree = true; |
|
529 |
firstElementForCriticalSubTree = true; |
|
530 |
} |
|
531 |
|
|
532 |
// handle subtree info |
|
533 |
SubTree subTress = new SubTree(); |
|
534 |
// set sub tree id |
|
535 |
subTress.setSubTreeId(attributeValue); |
|
536 |
// set sub tree sstart lement name |
|
537 |
subTress.setStartElementName(currentNode.getTagName()); |
|
538 |
// set start node number |
|
539 |
subTress.setStartNodeId(startNodeId); |
|
540 |
// add to stack, but it didn't get end node id yet |
|
541 |
subTreeInfoStack.push(subTress); |
|
542 |
|
|
501 |
// MCD - Removed the following code. It is used for node level access |
|
502 |
// control which is not yet implemented in EML 2.1.0 |
|
503 |
// // check unchangeable subtree hash if contains this |
|
504 |
// // subtree id |
|
505 |
// if (unChangeableSubTreeHash.containsKey(attributeValue)) { |
|
506 |
// // this subtree couldn't be changed by the user and |
|
507 |
// // move it from hash |
|
508 |
// SubTree currentUnChangedableSubtree = unChangeableSubTreeHash |
|
509 |
// .remove(attributeValue); |
|
510 |
// currentUnChangeableSubtreeNodeStack = currentUnChangedableSubtree |
|
511 |
// .getSubTreeNodeStack(); |
|
512 |
// startCriticalSubTree = true; |
|
513 |
// firstElementForCriticalSubTree = true; |
|
514 |
// } |
|
543 | 515 |
} |
544 | 516 |
}//for |
545 | 517 |
|
546 | 518 |
// handle access stuff |
547 | 519 |
if (localName.equals(ACCESS)) { |
548 |
// if it is in addtionalmetacat |
|
549 |
if (parentNode.getTagName() == ADDITIONALMETADATA) { |
|
550 |
processAdditionalAccess = true; |
|
551 |
|
|
552 |
} else { |
|
553 |
//make sure the access is top level |
|
554 |
// this mean current node's parent's parent should be "eml" |
|
555 |
DBSAXNode tmpNode = (DBSAXNode) nodeStack.pop();// pop out |
|
556 |
// parent |
|
557 |
// node |
|
558 |
//peek out grandParentNode |
|
559 |
DBSAXNode grandParentNode = (DBSAXNode) nodeStack.peek(); |
|
560 |
// put parent node back |
|
561 |
nodeStack.push(tmpNode); |
|
562 |
String grandParentTag = grandParentNode.getTagName(); |
|
563 |
if (grandParentTag.equals(EML)) { |
|
564 |
processTopLeverAccess = true; |
|
565 |
} else { |
|
566 |
// process other access embedded into resource level |
|
567 |
// module |
|
568 |
processOtherAccess = true; |
|
569 |
} |
|
570 |
|
|
571 |
} |
|
520 |
if (parentNode.getTagName().equals(EML)) { |
|
521 |
processTopLevelAccess = true; |
|
522 |
} else if (parentNode.getTagName() == DISTRIBUTION) { |
|
523 |
processAdditionalAccess = true; |
|
524 |
} else { |
|
525 |
// process other access embedded into resource level |
|
526 |
// module |
|
527 |
processOtherAccess = true; |
|
528 |
} |
|
572 | 529 |
// create access object |
573 | 530 |
accessObject = new AccessSection(); |
574 | 531 |
// set permission order |
... | ... | |
579 | 536 |
accessObject.setSubTreeId(accessId); |
580 | 537 |
accessObject.setStartNodeId(startNodeId); |
581 | 538 |
accessObject.setDocId(docid); |
539 |
if (processAdditionalAccess) { |
|
540 |
accessObject.setInlineDataFileName(inlineDataFileName); |
|
541 |
} |
|
582 | 542 |
|
583 | 543 |
// load top level node stack to |
584 | 544 |
// currentUnchangableAccessModuleNodeStack |
585 |
if (processTopLeverAccess && needCheckingAccessModule) {
|
|
545 |
if (processTopLevelAccess && needToCheckAccessModule) {
|
|
586 | 546 |
// get the node stack for |
587 |
currentUnchangableAccessModuleNodeStack = topAccessSection |
|
547 |
currentUnchangeableAccessModuleNodeStack = topAccessSection
|
|
588 | 548 |
.getSubTreeNodeStack(); |
589 | 549 |
} |
590 |
|
|
591 | 550 |
} |
551 |
else if (localName.equals(DISTRIBUTION)) { |
|
552 |
distributionIndex++; |
|
553 |
|
|
554 |
// handle subtree info |
|
555 |
SubTree subTree = new SubTree(); |
|
556 |
// set sub tree id |
|
557 |
subTree.setSubTreeId(String.valueOf(distributionIndex)); |
|
558 |
// set sub tree start element name |
|
559 |
subTree.setStartElementName(currentNode.getTagName()); |
|
560 |
// set start node number |
|
561 |
subTree.setStartNodeId(startNodeId); |
|
562 |
// add to stack, but it didn't get end node id yet |
|
563 |
subTreeInfoStack.push(subTree); |
|
564 |
} |
|
592 | 565 |
// Set up a access rule for allow |
593 | 566 |
else if (parentNode.getTagName() != null |
594 | 567 |
&& (parentNode.getTagName()).equals(ACCESS) |
... | ... | |
600 | 573 |
accessRule.setPermissionType(ALLOW); |
601 | 574 |
|
602 | 575 |
} |
603 |
// set up an access rule for den |
|
576 |
// set up an access rule for deny
|
|
604 | 577 |
else if (parentNode.getTagName() != null |
605 | 578 |
&& (parentNode.getTagName()).equals(ACCESS) |
606 | 579 |
&& localName.equals(DENY)) { |
... | ... | |
614 | 587 |
nodeStack.push(currentNode); |
615 | 588 |
// Add the node to the vector used by thread for writing XML Index |
616 | 589 |
nodeIndex.addElement(currentNode); |
617 |
|
|
618 |
// handle critical subtree |
|
619 |
if (startCriticalSubTree && firstElementForCriticalSubTree) { |
|
620 |
//store the element name |
|
621 |
firstElementNameForCriticalSubTree = qName; |
|
622 |
firstElementForCriticalSubTree = false; |
|
623 |
}//for first element |
|
624 |
|
|
625 |
// handle critical subtree |
|
626 |
if (startCriticalSubTree) { |
|
627 |
compareElementNameSpaceAttributes( |
|
628 |
currentUnChangedableSubtreeNodeStack, namespaces, atts, |
|
629 |
localName, PERMISSIONERROR); |
|
630 |
|
|
631 |
} |
|
590 |
|
|
591 |
// MCD - Removed the following code. It is used for node level access |
|
592 |
// control which is not yet implemented in EML 2.1.0 |
|
593 |
// // handle critical subtree |
|
594 |
// if (startCriticalSubTree && firstElementForCriticalSubTree) { |
|
595 |
// //store the element name |
|
596 |
// firstElementNameForCriticalSubTree = qName; |
|
597 |
// firstElementForCriticalSubTree = false; |
|
598 |
// }//for first element |
|
599 |
// |
|
600 |
// // handle critical subtree |
|
601 |
// if (startCriticalSubTree) { |
|
602 |
// compareElementNameSpaceAttributes( |
|
603 |
// currentUnChangeableSubtreeNodeStack, namespaces, atts, |
|
604 |
// localName, PERMISSIONERROR); |
|
605 |
// |
|
606 |
// } |
|
607 |
|
|
632 | 608 |
//compare top access level module |
633 |
if (processTopLeverAccess && needCheckingAccessModule) {
|
|
609 |
if (processTopLevelAccess && needToCheckAccessModule) {
|
|
634 | 610 |
compareElementNameSpaceAttributes( |
635 |
currentUnchangableAccessModuleNodeStack, namespaces, |
|
611 |
currentUnchangeableAccessModuleNodeStack, namespaces,
|
|
636 | 612 |
atts, localName, UPDATEACCESSERROR); |
637 | 613 |
|
638 | 614 |
} |
639 | 615 |
|
640 | 616 |
// store access module element and attributes into stored stack |
641 |
if (needCheckingAccessModule
|
|
642 |
&& (processAdditionalAccess || processOtherAccess || processTopLeverAccess)) {
|
|
617 |
if (needToCheckAccessModule
|
|
618 |
&& (processAdditionalAccess || processOtherAccess || processTopLevelAccess)) {
|
|
643 | 619 |
// stored the pull out nodes into storedNode stack |
644 | 620 |
NodeRecord nodeElement = new NodeRecord(-2, -2, -2, "ELEMENT", |
645 | 621 |
localName, prefix, MetaCatUtil.normalize(null)); |
... | ... | |
657 | 633 |
|
658 | 634 |
// reset name space |
659 | 635 |
namespaces = null; |
660 |
namespaces = new Hashtable(); |
|
636 |
namespaces = new Hashtable<String, String>();
|
|
661 | 637 |
}//not inline data |
662 | 638 |
else { |
663 | 639 |
// we don't buffer the inline data in characters() method |
... | ... | |
679 | 655 |
// append namespace |
680 | 656 |
String prefix = null; |
681 | 657 |
String nsuri = null; |
682 |
Enumeration prefixes = inlineDataNameSpace.keys(); |
|
658 |
Enumeration<String> prefixes = inlineDataNameSpace.keys();
|
|
683 | 659 |
while (prefixes.hasMoreElements()) { |
684 |
prefix = (String) prefixes.nextElement();
|
|
685 |
nsuri = (String) namespaces.get(prefix);
|
|
660 |
prefix = prefixes.nextElement(); |
|
661 |
nsuri = namespaces.get(prefix); |
|
686 | 662 |
inlineElements.append(" "); |
687 | 663 |
inlineElements.append("xmlns:"); |
688 | 664 |
inlineElements.append(prefix); |
... | ... | |
693 | 669 |
inlineElements.append(">"); |
694 | 670 |
//reset inline data name space |
695 | 671 |
inlineDataNameSpace = null; |
696 |
inlineDataNameSpace = new Hashtable(); |
|
672 |
inlineDataNameSpace = new Hashtable<String, String>();
|
|
697 | 673 |
//write inline data into file |
698 |
logMetacat.info("the inline element data is: "
|
|
674 |
logMetacat.debug("the inline element data is: "
|
|
699 | 675 |
+ inlineElements.toString()); |
700 | 676 |
writeInlineDataIntoFile(inlineDataFileWriter, inlineElements); |
701 | 677 |
}//else |
702 | 678 |
|
703 | 679 |
} |
704 | 680 |
|
705 |
private void compareElementNameSpaceAttributes(Stack unchangableNodeStack,
|
|
706 |
Hashtable nameSpaces, Attributes attributes, String localName, |
|
681 |
private void compareElementNameSpaceAttributes(Stack<NodeRecord> unchangeableNodeStack,
|
|
682 |
Hashtable<String,String> nameSpaces, Attributes attributes, String localName,
|
|
707 | 683 |
String error) throws SAXException |
708 | 684 |
{ |
709 | 685 |
//Get element subtree node stack (element node) |
710 | 686 |
NodeRecord elementNode = null; |
711 | 687 |
try { |
712 |
elementNode = (NodeRecord) unchangableNodeStack.pop();
|
|
688 |
elementNode = unchangeableNodeStack.pop();
|
|
713 | 689 |
} catch (EmptyStackException ee) { |
714 | 690 |
logMetacat.error("Node stack is empty for element data"); |
715 | 691 |
throw new SAXException(error); |
716 | 692 |
} |
717 |
logMetacat.info("current node type from xml is ELEMENT");
|
|
718 |
logMetacat.info("node type from stack: "
|
|
693 |
logMetacat.debug("current node type from xml is ELEMENT");
|
|
694 |
logMetacat.debug("node type from stack: "
|
|
719 | 695 |
+ elementNode.getNodeType()); |
720 |
logMetacat.info("node name from xml document: " + localName);
|
|
721 |
logMetacat.info("node name from stack: "
|
|
696 |
logMetacat.debug("node name from xml document: " + localName);
|
|
697 |
logMetacat.debug("node name from stack: "
|
|
722 | 698 |
+ elementNode.getNodeName()); |
723 |
logMetacat.info("node data from stack: "
|
|
699 |
logMetacat.debug("node data from stack: "
|
|
724 | 700 |
+ elementNode.getNodeData()); |
725 |
logMetacat.info("node id is: " + elementNode.getNodeId());
|
|
701 |
logMetacat.debug("node id is: " + elementNode.getNodeId());
|
|
726 | 702 |
// if this node is not element or local name not equal or name space |
727 |
// not |
|
728 |
// equals, throw an exception |
|
703 |
// not equals, throw an exception |
|
729 | 704 |
if (!elementNode.getNodeType().equals("ELEMENT") |
730 | 705 |
|| !localName.equals(elementNode.getNodeName())) |
731 | 706 |
// (uri != null && !uri.equals(elementNode.getNodePrefix()))) |
732 | 707 |
{ |
733 |
logMetacat.info("Inconsistence happend: ");
|
|
734 |
logMetacat.info("current node type from xml is ELEMENT");
|
|
735 |
logMetacat.info("node type from stack: "
|
|
708 |
logMetacat.error("Inconsistence happened: ");
|
|
709 |
logMetacat.error("current node type from xml is ELEMENT");
|
|
710 |
logMetacat.error("node type from stack: "
|
|
736 | 711 |
+ elementNode.getNodeType()); |
737 |
logMetacat.info("node name from xml document: "
|
|
712 |
logMetacat.error("node name from xml document: "
|
|
738 | 713 |
+ localName); |
739 |
logMetacat.info("node name from stack: "
|
|
714 |
logMetacat.error("node name from stack: "
|
|
740 | 715 |
+ elementNode.getNodeName()); |
741 |
logMetacat.info("node data from stack: "
|
|
716 |
logMetacat.error("node data from stack: "
|
|
742 | 717 |
+ elementNode.getNodeData()); |
743 |
logMetacat.info("node id is: " + elementNode.getNodeId());
|
|
718 |
logMetacat.error("node id is: " + elementNode.getNodeId());
|
|
744 | 719 |
throw new SAXException(error); |
745 | 720 |
} |
746 | 721 |
|
747 | 722 |
//compare namespace |
748 |
Enumeration nameEn = nameSpaces.keys(); |
|
723 |
Enumeration<String> nameEn = nameSpaces.keys();
|
|
749 | 724 |
while (nameEn.hasMoreElements()) { |
750 | 725 |
//Get namespacke node stack (element node) |
751 | 726 |
NodeRecord nameNode = null; |
752 | 727 |
try { |
753 |
nameNode = (NodeRecord) unchangableNodeStack.pop();
|
|
728 |
nameNode = unchangeableNodeStack.pop();
|
|
754 | 729 |
} catch (EmptyStackException ee) { |
755 | 730 |
logMetacat.error( |
756 | 731 |
"Node stack is empty for namespace data"); |
757 | 732 |
throw new SAXException(error); |
758 | 733 |
} |
759 | 734 |
|
760 |
String prefixName = (String) nameEn.nextElement();
|
|
761 |
String nameSpaceUri = (String) nameSpaces.get(prefixName);
|
|
735 |
String prefixName = nameEn.nextElement(); |
|
736 |
String nameSpaceUri = nameSpaces.get(prefixName); |
|
762 | 737 |
if (!nameNode.getNodeType().equals("NAMESPACE") |
763 | 738 |
|| !prefixName.equals(nameNode.getNodeName()) |
764 | 739 |
|| !nameSpaceUri.equals(nameNode.getNodeData())) { |
765 |
logMetacat.info("Inconsistence happend: ");
|
|
766 |
logMetacat.info(
|
|
740 |
logMetacat.error("Inconsistence happened: ");
|
|
741 |
logMetacat.error(
|
|
767 | 742 |
"current node type from xml is NAMESPACE"); |
768 |
logMetacat.info("node type from stack: "
|
|
743 |
logMetacat.error("node type from stack: "
|
|
769 | 744 |
+ nameNode.getNodeType()); |
770 |
logMetacat.info("current node name from xml is: "
|
|
745 |
logMetacat.error("current node name from xml is: "
|
|
771 | 746 |
+ prefixName); |
772 |
logMetacat.info("node name from stack: "
|
|
747 |
logMetacat.error("node name from stack: "
|
|
773 | 748 |
+ nameNode.getNodeName()); |
774 |
logMetacat.info("current node data from xml is: "
|
|
749 |
logMetacat.error("current node data from xml is: "
|
|
775 | 750 |
+ nameSpaceUri); |
776 |
logMetacat.info("node data from stack: "
|
|
751 |
logMetacat.error("node data from stack: "
|
|
777 | 752 |
+ nameNode.getNodeData()); |
778 |
logMetacat.info("node id is: " + nameNode.getNodeId());
|
|
753 |
logMetacat.error("node id is: " + nameNode.getNodeId());
|
|
779 | 754 |
throw new SAXException(error); |
780 | 755 |
} |
781 | 756 |
|
... | ... | |
785 | 760 |
for (int i = 0; i < attributes.getLength(); i++) { |
786 | 761 |
NodeRecord attriNode = null; |
787 | 762 |
try { |
788 |
attriNode = (NodeRecord) unchangableNodeStack.pop();
|
|
763 |
attriNode = unchangeableNodeStack.pop();
|
|
789 | 764 |
|
790 | 765 |
} catch (EmptyStackException ee) { |
791 |
logMetacat.error( |
|
792 |
"Node stack is empty for attribute data"); |
|
766 |
logMetacat.error("Node stack is empty for attribute data"); |
|
793 | 767 |
throw new SAXException(error); |
794 | 768 |
} |
795 | 769 |
String attributeName = attributes.getQName(i); |
796 | 770 |
String attributeValue = attributes.getValue(i); |
797 |
logMetacat.info(
|
|
771 |
logMetacat.debug(
|
|
798 | 772 |
"current node type from xml is ATTRIBUTE "); |
799 |
logMetacat.info("node type from stack: "
|
|
773 |
logMetacat.debug("node type from stack: "
|
|
800 | 774 |
+ attriNode.getNodeType()); |
801 |
logMetacat.info("current node name from xml is: "
|
|
775 |
logMetacat.debug("current node name from xml is: "
|
|
802 | 776 |
+ attributeName); |
803 |
logMetacat.info("node name from stack: "
|
|
777 |
logMetacat.debug("node name from stack: "
|
|
804 | 778 |
+ attriNode.getNodeName()); |
805 |
logMetacat.info("current node data from xml is: "
|
|
779 |
logMetacat.debug("current node data from xml is: "
|
|
806 | 780 |
+ attributeValue); |
807 |
logMetacat.info("node data from stack: "
|
|
781 |
logMetacat.debug("node data from stack: "
|
|
808 | 782 |
+ attriNode.getNodeData()); |
809 |
logMetacat.info("node id is: " + attriNode.getNodeId());
|
|
783 |
logMetacat.debug("node id is: " + attriNode.getNodeId());
|
|
810 | 784 |
|
811 | 785 |
if (!attriNode.getNodeType().equals("ATTRIBUTE") |
812 | 786 |
|| !attributeName.equals(attriNode.getNodeName()) |
813 | 787 |
|| !attributeValue.equals(attriNode.getNodeData())) { |
814 |
logMetacat.info("Inconsistence happend: ");
|
|
815 |
logMetacat.info(
|
|
788 |
logMetacat.error("Inconsistence happened: ");
|
|
789 |
logMetacat.error(
|
|
816 | 790 |
"current node type from xml is ATTRIBUTE "); |
817 |
logMetacat.info("node type from stack: "
|
|
791 |
logMetacat.error("node type from stack: "
|
|
818 | 792 |
+ attriNode.getNodeType()); |
819 |
logMetacat.info("current node name from xml is: "
|
|
793 |
logMetacat.error("current node name from xml is: "
|
|
820 | 794 |
+ attributeName); |
821 |
logMetacat.info("node name from stack: "
|
|
795 |
logMetacat.error("node name from stack: "
|
|
822 | 796 |
+ attriNode.getNodeName()); |
823 |
logMetacat.info("current node data from xml is: "
|
|
797 |
logMetacat.error("current node data from xml is: "
|
|
824 | 798 |
+ attributeValue); |
825 |
logMetacat.info("node data from stack: "
|
|
799 |
logMetacat.error("node data from stack: "
|
|
826 | 800 |
+ attriNode.getNodeData()); |
827 |
logMetacat.info("node is: " + attriNode.getNodeId());
|
|
801 |
logMetacat.error("node is: " + attriNode.getNodeId());
|
|
828 | 802 |
throw new SAXException(error); |
829 | 803 |
} |
830 | 804 |
}//for |
831 | 805 |
|
832 | 806 |
} |
833 | 807 |
|
834 |
/* mehtod to compare current text node and node in db */
|
|
835 |
private void compareTextNode(Stack nodeStack, StringBuffer text, |
|
808 |
/* method to compare current text node and node in db */
|
|
809 |
private void compareTextNode(Stack<NodeRecord> nodeStack, StringBuffer text,
|
|
836 | 810 |
String error) throws SAXException |
837 | 811 |
{ |
838 | 812 |
NodeRecord node = null; |
839 | 813 |
//get node from current stack |
840 | 814 |
try { |
841 |
node = (NodeRecord) nodeStack.pop();
|
|
815 |
node = nodeStack.pop(); |
|
842 | 816 |
} catch (EmptyStackException ee) { |
843 | 817 |
logMetacat.error( |
844 | 818 |
"Node stack is empty for text data in startElement"); |
845 | 819 |
throw new SAXException(error); |
846 | 820 |
} |
847 |
logMetacat.info(
|
|
821 |
logMetacat.debug(
|
|
848 | 822 |
"current node type from xml is TEXT in start element"); |
849 |
logMetacat.info("node type from stack: " + node.getNodeType());
|
|
850 |
logMetacat.info("current node data from xml is: "
|
|
823 |
logMetacat.debug("node type from stack: " + node.getNodeType());
|
|
824 |
logMetacat.debug("current node data from xml is: "
|
|
851 | 825 |
+ text.toString()); |
852 |
logMetacat.info("node data from stack: " + node.getNodeData());
|
|
853 |
logMetacat.info("node name from stack: " + node.getNodeName());
|
|
854 |
logMetacat.info("node is: " + node.getNodeId());
|
|
826 |
logMetacat.debug("node data from stack: " + node.getNodeData());
|
|
827 |
logMetacat.debug("node name from stack: " + node.getNodeName());
|
|
828 |
logMetacat.debug("node is: " + node.getNodeId());
|
|
855 | 829 |
if (!node.getNodeType().equals("TEXT") |
856 | 830 |
|| !(text.toString()).equals(node.getNodeData())) { |
857 |
logMetacat.info("Inconsistence happend: ");
|
|
858 |
logMetacat.info(
|
|
831 |
logMetacat.error("Inconsistence happened: ");
|
|
832 |
logMetacat.error(
|
|
859 | 833 |
"current node type from xml is TEXT in start element"); |
860 |
logMetacat.info("node type from stack: "
|
|
834 |
logMetacat.error("node type from stack: "
|
|
861 | 835 |
+ node.getNodeType()); |
862 |
logMetacat.info("current node data from xml is: "
|
|
836 |
logMetacat.error("current node data from xml is: "
|
|
863 | 837 |
+ text.toString()); |
864 |
logMetacat.info("node data from stack: "
|
|
838 |
logMetacat.error("node data from stack: "
|
|
865 | 839 |
+ node.getNodeData()); |
866 |
logMetacat.info("node name from stack: "
|
|
840 |
logMetacat.error("node name from stack: "
|
|
867 | 841 |
+ node.getNodeName()); |
868 |
logMetacat.info("node is: " + node.getNodeId());
|
|
842 |
logMetacat.error("node is: " + node.getNodeId());
|
|
869 | 843 |
throw new SAXException(error); |
870 | 844 |
}//if |
871 | 845 |
} |
... | ... | |
873 | 847 |
/** SAX Handler that is called for each XML text node */ |
874 | 848 |
public void characters(char[] cbuf, int start, int len) throws SAXException |
875 | 849 |
{ |
876 |
logMetacat.info("CHARACTERS");
|
|
850 |
logMetacat.debug("CHARACTERS");
|
|
877 | 851 |
if (!handleInlineData) { |
878 |
// buffer all text nodes for same element. This is for text was |
|
879 |
// splited |
|
880 |
// into different nodes |
|
852 |
// buffer all text nodes for same element. This is for if text was |
|
853 |
// split into different nodes |
|
881 | 854 |
textBuffer.append(new String(cbuf, start, len)); |
882 | 855 |
// set hittextnode true |
883 | 856 |
hitTextNode = true; |
884 | 857 |
// if text buffer .size is greater than max, write it to db. |
885 | 858 |
// so we can save memory |
886 | 859 |
if (textBuffer.length() > MAXDATACHARS) { |
887 |
logMetacat.info("Write text into DB in charaters"
|
|
860 |
logMetacat.debug("Write text into DB in charaters"
|
|
888 | 861 |
+ " when text buffer size is greater than maxmum number"); |
889 | 862 |
DBSAXNode currentNode = (DBSAXNode) nodeStack.peek(); |
890 | 863 |
endNodeId = writeTextForDBSAXNode(endNodeId, textBuffer, |
... | ... | |
894 | 867 |
} |
895 | 868 |
} else { |
896 | 869 |
// this is inline data and write file system directly |
897 |
// we don't need to buffered it.
|
|
870 |
// we don't need to buffer it. |
|
898 | 871 |
StringBuffer inlineText = new StringBuffer(); |
899 | 872 |
inlineText.append(new String(cbuf, start, len)); |
900 |
logMetacat.info(
|
|
873 |
logMetacat.debug(
|
|
901 | 874 |
"The inline text data write into file system: " |
902 | 875 |
+ inlineText.toString()); |
903 | 876 |
writeInlineDataIntoFile(inlineDataFileWriter, inlineText); |
... | ... | |
908 | 881 |
public void endElement(String uri, String localName, String qName) |
909 | 882 |
throws SAXException |
910 | 883 |
{ |
911 |
logMetacat.info("End ELEMENT " + qName);
|
|
884 |
logMetacat.debug("End ELEMENT " + qName);
|
|
912 | 885 |
|
913 | 886 |
if (localName.equals(INLINE) && handleInlineData) { |
914 | 887 |
// Get the node from the stack |
915 | 888 |
DBSAXNode currentNode = (DBSAXNode) nodeStack.pop(); |
916 |
String currentTag = currentNode.getTagName(); |
|
917 |
logMetacat.info("End of inline data"); |
|
889 |
logMetacat.debug("End of inline data"); |
|
918 | 890 |
// close file writer |
919 | 891 |
try { |
920 | 892 |
inlineDataFileWriter.close(); |
... | ... | |
922 | 894 |
} catch (IOException ioe) { |
923 | 895 |
throw new SAXException(ioe.getMessage()); |
924 | 896 |
} |
925 |
|
|
926 |
//check if user changed inine data or not if user doesn't have |
|
927 |
// write permission |
|
928 |
if (startCriticalSubTree) { |
|
929 |
NodeRecord node = null; |
|
930 |
String inlineData; |
|
931 |
try { |
|
932 |
node = (NodeRecord) currentUnChangedableSubtreeNodeStack |
|
933 |
.pop(); |
|
934 |
// get file name from db |
|
935 |
String fileName = node.getNodeData(); |
|
936 |
logMetacat.info("in handle inline data"); |
|
937 |
logMetacat.info( |
|
938 |
"the inline data file name from node is: " |
|
939 |
+ fileName); |
|
940 |
if (!compareInlineDataFiles(fileName, inlineDataFileName)) { |
|
941 |
logMetacat.info( |
|
942 |
"inline data was changed by a user" |
|
943 |
+ " who doesn't have permission"); |
|
944 |
throw new SAXException(PERMISSIONERROR); |
|
945 |
} |
|
946 |
} catch (EmptyStackException ee) { |
|
947 |
logMetacat.error( |
|
948 |
"the stack is empty for text data"); |
|
949 |
throw new SAXException(PERMISSIONERROR); |
|
950 |
} catch (McdbException eee) { |
|
951 |
throw new SAXException(eee.getMessage()); |
|
952 |
} finally { |
|
953 |
// delete the inline data file already in file system |
|
954 |
deleteInlineDataFile(inlineDataFileName); |
|
955 |
} |
|
956 |
|
|
957 |
}//if |
|
897 |
// MCD - Removed the following code. It is used for node level access |
|
898 |
// control which is not yet implemented in EML 2.1.0 |
|
899 |
// //check if user changed inline data or not if user doesn't have |
|
900 |
// // write permission |
|
901 |
// if (startCriticalSubTree) { |
|
902 |
// NodeRecord node = null; |
|
903 |
// try { |
|
904 |
// node = currentUnChangeableSubtreeNodeStack.pop(); |
|
905 |
// // get file name from db |
|
906 |
// String fileName = node.getNodeData(); |
|
907 |
// logMetacat.info("in handle inline data"); |
|
908 |
// logMetacat.info( |
|
909 |
// "the inline data file name from node is: " |
|
910 |
// + fileName); |
|
911 |
// if (!compareInlineDataFiles(fileName, inlineDataFileName)) { |
|
912 |
// logMetacat.info( |
|
913 |
// "inline data was changed by a user" |
|
914 |
// + " who doesn't have permission"); |
|
915 |
// throw new SAXException(PERMISSIONERROR); |
|
916 |
// } |
|
917 |
// } catch (EmptyStackException ee) { |
|
918 |
// logMetacat.error( |
|
919 |
// "the stack is empty for text data"); |
|
920 |
// throw new SAXException(PERMISSIONERROR); |
|
921 |
// } catch (McdbException eee) { |
|
922 |
// throw new SAXException(eee.getMessage()); |
|
923 |
// } finally { |
|
924 |
// // delete the inline data file already in file system |
|
925 |
// deleteInlineDataFile(inlineDataFileName); |
|
926 |
// } |
|
927 |
// }//if |
|
928 |
|
|
958 | 929 |
// write put inline data file name into text buffer (without path) |
959 | 930 |
textBuffer = new StringBuffer(inlineDataFileName); |
960 | 931 |
// write file name into db |
... | ... | |
972 | 943 |
String currentTag = currentNode.getTagName(); |
973 | 944 |
|
974 | 945 |
// If before the end element, the parser hit text nodes and store |
975 |
// them |
|
976 |
// into the buffer, write the buffer to data base. The reason we |
|
977 |
// put |
|
978 |
// write database here is for xerces some time split text node |
|
946 |
// them into the buffer, write the buffer to data base. The reason |
|
947 |
// we put write database here is for xerces some time split text node |
|
979 | 948 |
if (hitTextNode) { |
980 | 949 |
// get access value |
981 | 950 |
String data = null; |
... | ... | |
986 | 955 |
|
987 | 956 |
} else if (currentTag.equals(PERMISSION) && accessRule != null) { |
988 | 957 |
data = (textBuffer.toString()).trim(); |
989 |
// we conbine different a permission into one value
|
|
958 |
// we combine different a permission into one value
|
|
990 | 959 |
int permission = accessRule.getPermission(); |
991 |
// add permision |
|
960 |
// add permission
|
|
992 | 961 |
if (data.toUpperCase().equals(READSTRING)) { |
993 | 962 |
permission = permission | READ; |
994 | 963 |
} else if (data.toUpperCase().equals(WRITESTRING)) { |
... | ... | |
999 | 968 |
permission = permission | ALL; |
1000 | 969 |
} |
1001 | 970 |
accessRule.setPermission(permission); |
1002 |
} |
|
1003 |
// put additionalmetadata/describes into vector |
|
1004 |
else if (currentTag.equals(DESCRIBES)) { |
|
1005 |
data = (textBuffer.toString()).trim(); |
|
1006 |
describesId.add(data); |
|
1007 | 971 |
} else if (currentTag.equals(REFERENCES) |
1008 |
&& (processTopLeverAccess || processAdditionalAccess || processOtherAccess)) {
|
|
972 |
&& (processTopLevelAccess || processAdditionalAccess || processOtherAccess)) {
|
|
1009 | 973 |
// get reference |
1010 | 974 |
data = (textBuffer.toString()).trim(); |
1011 | 975 |
// put reference id into accessSection |
... | ... | |
1036 | 1000 |
// write text to db if it is not inline data |
1037 | 1001 |
//if (!localName.equals(INLINE)) |
1038 | 1002 |
{ |
1039 |
logMetacat.info(
|
|
1003 |
logMetacat.debug(
|
|
1040 | 1004 |
"Write text into DB in End Element"); |
1041 |
//compare text node if need |
|
1042 |
if (startCriticalSubTree) { |
|
1043 |
compareTextNode(currentUnChangedableSubtreeNodeStack, |
|
1044 |
textBuffer, PERMISSIONERROR); |
|
1045 |
}//if |
|
1005 |
// MCD - Removed the following code. It is used for node level access |
|
1006 |
// control which is not yet implemented in EML 2.1.0 |
|
1007 |
// //compare text node if need |
|
1008 |
// if (startCriticalSubTree) { |
|
1009 |
// compareTextNode(currentUnChangeableSubtreeNodeStack, |
|
1010 |
// textBuffer, PERMISSIONERROR); |
|
1011 |
// }//if |
|
1012 |
|
|
1046 | 1013 |
//compare top level access module |
1047 |
if (processTopLeverAccess && needCheckingAccessModule) {
|
|
1014 |
if (processTopLevelAccess && needToCheckAccessModule) {
|
|
1048 | 1015 |
compareTextNode( |
1049 |
currentUnchangableAccessModuleNodeStack, |
|
1016 |
currentUnchangeableAccessModuleNodeStack,
|
|
1050 | 1017 |
textBuffer, UPDATEACCESSERROR); |
1051 | 1018 |
} |
1052 | 1019 |
// write text node into db |
1053 | 1020 |
endNodeId = writeTextForDBSAXNode(endNodeId, textBuffer, |
1054 | 1021 |
currentNode); |
1055 | 1022 |
} |
1056 |
if (needCheckingAccessModule
|
|
1057 |
&& (processAdditionalAccess || processOtherAccess || processTopLeverAccess)) {
|
|
1023 |
if (needToCheckAccessModule
|
|
1024 |
&& (processAdditionalAccess || processOtherAccess || processTopLevelAccess)) {
|
|
1058 | 1025 |
// stored the pull out nodes into storedNode stack |
1059 | 1026 |
NodeRecord nodeElement = new NodeRecord(-2, -2, -2, "TEXT", |
1060 | 1027 |
null, null, MetaCatUtil.normalize(textBuffer |
... | ... | |
1063 | 1030 |
|
1064 | 1031 |
} |
1065 | 1032 |
}//if |
1033 |
|
|
1034 |
// MCD - Removed the following code. It is used for node level access |
|
1035 |
// control which is not yet implemented in EML 2.1.0 |
|
1036 |
// //end critical subtree(user doesn't have permission to write) |
|
1037 |
// //When reach the first element and stack is empty |
|
1038 |
// if (localName.equals(firstElementNameForCriticalSubTree) |
|
1039 |
// && currentUnChangeableSubtreeNodeStack.isEmpty()) { |
|
1040 |
// startCriticalSubTree = false; |
|
1041 |
// } |
|
1066 | 1042 |
|
1067 |
//end crtical subtree(user doesn't have permission to write) |
|
1068 |
//When reach the first element and stack is empty |
|
1069 |
if (localName.equals(firstElementNameForCriticalSubTree) |
|
1070 |
&& currentUnChangedableSubtreeNodeStack.isEmpty()) { |
|
1071 |
startCriticalSubTree = false; |
|
1072 |
} |
|
1073 |
|
|
1074 | 1043 |
//set hitText false |
1075 | 1044 |
hitTextNode = false; |
1076 | 1045 |
// reset textbuff |
... | ... | |
1079 | 1048 |
|
1080 | 1049 |
// hand sub stree stuff |
1081 | 1050 |
if (!subTreeInfoStack.empty()) { |
1082 |
SubTree tree = (SubTree) subTreeInfoStack.peek();// get last
|
|
1051 |
SubTree tree = subTreeInfoStack.peek();// get last |
|
1083 | 1052 |
// subtree |
1084 | 1053 |
if (tree != null && tree.getStartElementName() != null |
1085 | 1054 |
&& (tree.getStartElementName()).equals(currentTag)) { |
... | ... | |
1094 | 1063 |
|
1095 | 1064 |
// access stuff |
1096 | 1065 |
if (currentTag.equals(ALLOW) || currentTag.equals(DENY)) { |
1097 |
// finish parser a ccess rule and assign it to new one
|
|
1066 |
// finish parser access rule and assign it to new one |
|
1098 | 1067 |
AccessRule newRule = accessRule; |
1099 | 1068 |
//add the new rule to access section object |
1100 | 1069 |
accessObject.addAccessRule(newRule); |
1101 | 1070 |
// reset access rule |
1102 | 1071 |
accessRule = null; |
1103 | 1072 |
} else if (currentTag.equals(ACCESS)) { |
1104 |
// finish parse a access setction and assign it to new one |
|
1105 |
|
|
1073 |
// finish parsing an access section and assign it to new one |
|
1074 |
DBSAXNode parentNode = (DBSAXNode) nodeStack.peek(); |
|
1075 |
if (parentNode != null && parentNode.getTagName() != null |
|
1076 |
&& parentNode.getTagName().equals(DISTRIBUTION)) { |
|
1077 |
describesId.add(String.valueOf(distributionIndex)); |
|
1078 |
} |
|
1106 | 1079 |
accessObject.setEndNodeId(endNodeId); |
1107 | 1080 |
AccessSection newAccessObject = accessObject; |
1108 | 1081 |
|
... | ... | |
1116 | 1089 |
.setStoredTmpNodeStack(storedAccessNodeStack); |
1117 | 1090 |
accessObjectList.add(newAccessObject); |
1118 | 1091 |
} |
1119 |
if (processTopLeverAccess) {
|
|
1092 |
if (processTopLevelAccess) {
|
|
1120 | 1093 |
|
1121 | 1094 |
// top level access control will handle whole document |
1122 | 1095 |
// -docid |
... | ... | |
1125 | 1098 |
|
1126 | 1099 |
}//if |
1127 | 1100 |
else if (processAdditionalAccess) { |
1128 |
// for additional control |
|
1129 |
// put everything in describes value and access object |
|
1130 |
// into hash |
|
1101 |
// for additional control put everything in describes value |
|
1102 |
// and access object into hash |
|
1131 | 1103 |
for (int i = 0; i < describesId.size(); i++) { |
1132 | 1104 |
|
1133 |
String subId = (String) describesId.elementAt(i);
|
|
1105 |
String subId = describesId.elementAt(i); |
|
1134 | 1106 |
if (subId != null) { |
1135 | 1107 |
additionalAccessControlMap.put(subId, |
1136 | 1108 |
newAccessObject); |
... | ... | |
1143 | 1115 |
// additional |
1144 | 1116 |
//accesscontrol |
1145 | 1117 |
additionalAccessControlMap = null; |
1146 |
additionalAccessControlMap = new Hashtable(); |
|
1118 |
additionalAccessControlMap = new Hashtable<String, AccessSection>();
|
|
1147 | 1119 |
}//if |
1148 | 1120 |
|
1149 | 1121 |
}//if |
1150 | 1122 |
//check if access node stack is empty after parsing top access |
1151 | 1123 |
//module |
1152 | 1124 |
|
1153 |
if (needCheckingAccessModule && processTopLeverAccess
|
|
1154 |
&& !currentUnchangableAccessModuleNodeStack.isEmpty()) { |
|
1125 |
if (needToCheckAccessModule && processTopLevelAccess
|
|
1126 |
&& !currentUnchangeableAccessModuleNodeStack.isEmpty()) {
|
|
1155 | 1127 |
|
1156 |
logMetacat.info(
|
|
1128 |
logMetacat.error(
|
|
1157 | 1129 |
"Access node stack is not empty after " |
1158 | 1130 |
+ "parsing access subtree"); |
1159 | 1131 |
throw new SAXException(UPDATEACCESSERROR); |
... | ... | |
1165 | 1137 |
|
1166 | 1138 |
// reset tmp stored node stack |
1167 | 1139 |
storedAccessNodeStack = null; |
1168 |
storedAccessNodeStack = new Stack(); |
|
1140 |
storedAccessNodeStack = new Stack<NodeRecord>();
|
|
1169 | 1141 |
|
1170 | 1142 |
// reset flag |
1171 | 1143 |
processAdditionalAccess = false; |
1172 |
processTopLeverAccess = false;
|
|
1144 |
processTopLevelAccess = false;
|
|
1173 | 1145 |
processOtherAccess = false; |
1174 | 1146 |
|
1175 |
} else if (currentTag.equals(ADDITIONALMETADATA)) {
|
|
1147 |
} else if (currentTag.equals(DISTRIBUTION)) {
|
|
1176 | 1148 |
//reset describesId |
1177 | 1149 |
describesId = null; |
1178 |
describesId = new Vector(); |
|
1150 |
describesId = new Vector<String>();
|
|
1179 | 1151 |
} |
1180 | 1152 |
} else { |
1181 | 1153 |
// this is in inline part |
... | ... | |
1183 | 1155 |
endElement.append("</"); |
1184 | 1156 |
endElement.append(qName); |
1185 | 1157 |
endElement.append(">"); |
1186 |
logMetacat.info("inline endElement: "
|
|
1158 |
logMetacat.debug("inline endElement: "
|
|
1187 | 1159 |
+ endElement.toString()); |
1188 | 1160 |
writeInlineDataIntoFile(inlineDataFileWriter, endElement); |
1189 | 1161 |
} |
... | ... | |
1194 | 1166 |
*/ |
1195 | 1167 |
public void comment(char[] ch, int start, int length) throws SAXException |
1196 | 1168 |
{ |
1197 |
logMetacat.info("COMMENT");
|
|
1169 |
logMetacat.debug("COMMENT");
|
|
1198 | 1170 |
if (!handleInlineData) { |
1199 | 1171 |
if (!processingDTD) { |
1200 | 1172 |
DBSAXNode currentNode = (DBSAXNode) nodeStack.peek(); |
1201 | 1173 |
String str = new String(ch, start, length); |
1202 | 1174 |
|
1203 |
//compare comment if need |
|
1204 |
if (startCriticalSubTree) { |
|
1205 |
compareCommentNode(currentUnChangedableSubtreeNodeStack, |
|
1206 |
str, PERMISSIONERROR); |
|
1207 |
}//if |
|
1175 |
// MCD - Removed the following code. It is used for node level access |
|
1176 |
// control which is not yet implemented in EML 2.1.0 |
|
1177 |
// //compare comment if need |
|
1178 |
// if (startCriticalSubTree) { |
|
1179 |
// compareCommentNode(currentUnChangeableSubtreeNodeStack, |
|
1180 |
// str, PERMISSIONERROR); |
|
1181 |
// }//if |
|
1182 |
|
|
1208 | 1183 |
//compare top level access module |
1209 |
if (processTopLeverAccess && needCheckingAccessModule) {
|
|
1210 |
compareCommentNode(currentUnchangableAccessModuleNodeStack, |
|
1184 |
if (processTopLevelAccess && needToCheckAccessModule) {
|
|
1185 |
compareCommentNode(currentUnchangeableAccessModuleNodeStack,
|
|
1211 | 1186 |
str, UPDATEACCESSERROR); |
1212 | 1187 |
} |
1213 | 1188 |
endNodeId = currentNode.writeChildNodeToDB("COMMENT", null, |
1214 | 1189 |
str, docid); |
1215 |
if (needCheckingAccessModule
|
|
1216 |
&& (processAdditionalAccess || processOtherAccess || processTopLeverAccess)) {
|
|
1190 |
if (needToCheckAccessModule
|
|
1191 |
&& (processAdditionalAccess || processOtherAccess || processTopLevelAccess)) {
|
|
1217 | 1192 |
// stored the pull out nodes into storedNode stack |
1218 | 1193 |
NodeRecord nodeElement = new NodeRecord(-2, -2, -2, |
1219 | 1194 |
"COMMENT", null, null, MetaCatUtil.normalize(str)); |
... | ... | |
1227 | 1202 |
inlineComment.append("<!--"); |
1228 | 1203 |
inlineComment.append(new String(ch, start, length)); |
1229 | 1204 |
inlineComment.append("-->"); |
1230 |
logMetacat.info("inline data comment: "
|
|
1205 |
logMetacat.debug("inline data comment: "
|
|
1231 | 1206 |
+ inlineComment.toString()); |
1232 | 1207 |
writeInlineDataIntoFile(inlineDataFileWriter, inlineComment); |
1233 | 1208 |
} |
1234 | 1209 |
} |
1235 | 1210 |
|
1236 |
/* Comparet comment from xml and db */
|
|
1237 |
private void compareCommentNode(Stack nodeStack, String string, String error) |
|
1211 |
/* Compare comment from xml and db */ |
|
1212 |
private void compareCommentNode(Stack<NodeRecord> nodeStack, String string, String error)
|
|
1238 | 1213 |
throws SAXException |
1239 | 1214 |
{ |
1240 | 1215 |
NodeRecord node = null; |
1241 | 1216 |
try { |
1242 |
node = (NodeRecord) nodeStack.pop();
|
|
1217 |
node = nodeStack.pop(); |
|
1243 | 1218 |
} catch (EmptyStackException ee) { |
1244 | 1219 |
logMetacat.error("the stack is empty for comment data"); |
1245 | 1220 |
throw new SAXException(error); |
1246 | 1221 |
} |
1247 |
logMetacat.info("current node type from xml is COMMENT");
|
|
1248 |
logMetacat.info("node type from stack: " + node.getNodeType());
|
|
1249 |
logMetacat.info("current node data from xml is: " + string);
|
|
1250 |
logMetacat.info("node data from stack: " + node.getNodeData());
|
|
1251 |
logMetacat.info("node is from stack: " + node.getNodeId());
|
|
1222 |
logMetacat.debug("current node type from xml is COMMENT");
|
|
1223 |
logMetacat.debug("node type from stack: " + node.getNodeType());
|
|
1224 |
logMetacat.debug("current node data from xml is: " + string);
|
|
1225 |
logMetacat.debug("node data from stack: " + node.getNodeData());
|
|
1226 |
logMetacat.debug("node is from stack: " + node.getNodeId());
|
|
1252 | 1227 |
// if not consistent terminate program and throw a exception |
1253 | 1228 |
if (!node.getNodeType().equals("COMMENT") |
1254 | 1229 |
|| !string.equals(node.getNodeData())) { |
1255 |
logMetacat.info("Inconsistence happend: ");
|
|
1256 |
logMetacat.info("current node type from xml is COMMENT");
|
|
1257 |
logMetacat.info("node type from stack: "
|
|
1230 |
logMetacat.error("Inconsistence happened: ");
|
|
1231 |
logMetacat.error("current node type from xml is COMMENT");
|
|
1232 |
logMetacat.error("node type from stack: "
|
|
1258 | 1233 |
+ node.getNodeType()); |
1259 |
logMetacat.info(
|
|
1234 |
logMetacat.error(
|
|
1260 | 1235 |
"current node data from xml is: " + string); |
1261 |
logMetacat.info("node data from stack: "
|
|
1236 |
logMetacat.error("node data from stack: "
|
|
1262 | 1237 |
+ node.getNodeData()); |
1263 |
logMetacat.info("node is from stack: " + node.getNodeId());
|
|
1238 |
logMetacat.error("node is from stack: " + node.getNodeId());
|
|
1264 | 1239 |
throw new SAXException(error); |
1265 | 1240 |
}//if |
1266 | 1241 |
} |
... | ... | |
1272 | 1247 |
public void processingInstruction(String target, String data) |
1273 | 1248 |
throws SAXException |
1274 | 1249 |
{ |
1275 |
logMetacat.info("PI");
|
|
1250 |
logMetacat.debug("PI");
|
|
1276 | 1251 |
if (!handleInlineData) { |
1277 | 1252 |
DBSAXNode currentNode = (DBSAXNode) nodeStack.peek(); |
1278 | 1253 |
endNodeId = currentNode.writeChildNodeToDB("PI", target, data, |
... | ... | |
1284 | 1259 |
inlinePI.append(" "); |
1285 | 1260 |
inlinePI.append(data); |
1286 | 1261 |
inlinePI.append("?>"); |
1287 |
logMetacat.info("inline data pi is: "
|
|
1262 |
logMetacat.debug("inline data pi is: "
|
|
1288 | 1263 |
+ inlinePI.toString()); |
1289 | 1264 |
writeInlineDataIntoFile(inlineDataFileWriter, inlinePI); |
1290 | 1265 |
} |
... | ... | |
1294 | 1269 |
public void startPrefixMapping(String prefix, String uri) |
1295 | 1270 |
throws SAXException |
1296 | 1271 |
{ |
1297 |
logMetacat.info("NAMESPACE");
|
|
1272 |
logMetacat.debug("NAMESPACE");
|
|
1298 | 1273 |
if (!handleInlineData) { |
1299 | 1274 |
namespaces.put(prefix, uri); |
1300 | 1275 |
} else { |
... | ... | |
1312 | 1287 |
// When validation is turned "on", white spaces are reported here |
1313 | 1288 |
// When validation is turned "off" white spaces are not reported here, |
1314 | 1289 |
// but through characters() callback |
1315 |
logMetacat.info("IGNORABLEWHITESPACE");
|
|
1290 |
logMetacat.debug("IGNORABLEWHITESPACE");
|
|
1316 | 1291 |
if (!handleInlineData) { |
1317 | 1292 |
DBSAXNode currentNode = (DBSAXNode) nodeStack.peek(); |
1318 | 1293 |
String data = null; |
... | ... | |
1335 | 1310 |
moredata = false; |
1336 | 1311 |
} |
1337 | 1312 |
|
1338 |
//compare whitespace if need |
|
1339 |
if (startCriticalSubTree) { |
|
1340 |
compareWhiteSpace(currentUnChangedableSubtreeNodeStack, |
|
1341 |
data, PERMISSIONERROR); |
|
1342 |
}//if |
|
1313 |
// MCD - Removed the following code. It is used for node level access |
|
1314 |
// control which is not yet implemented in EML 2.1.0 |
|
1315 |
// //compare whitespace if need |
|
1316 |
// if (startCriticalSubTree) { |
|
1317 |
// compareWhiteSpace(currentUnChangeableSubtreeNodeStack, |
|
1318 |
// data, PERMISSIONERROR); |
|
1319 |
// }//if |
|
1343 | 1320 |
|
1344 | 1321 |
//compare whitespace in access top module |
1345 |
if (processTopLeverAccess && needCheckingAccessModule) {
|
|
1346 |
compareWhiteSpace(currentUnchangableAccessModuleNodeStack, |
|
1322 |
if (processTopLevelAccess && needToCheckAccessModule) {
|
|
1323 |
compareWhiteSpace(currentUnchangeableAccessModuleNodeStack,
|
|
1347 | 1324 |
data, UPDATEACCESSERROR); |
1348 | 1325 |
} |
1349 | 1326 |
// Write the content of the node to the database |
1350 |
if (needCheckingAccessModule
|
|
1351 |
&& (processAdditionalAccess || processOtherAccess || processTopLeverAccess)) {
|
|
1327 |
if (needToCheckAccessModule
|
|
1328 |
&& (processAdditionalAccess || processOtherAccess || processTopLevelAccess)) {
|
|
1352 | 1329 |
// stored the pull out nodes into storedNode stack |
1353 | 1330 |
NodeRecord nodeElement = new NodeRecord(-2, -2, -2, "TEXT", |
1354 | 1331 |
null, null, MetaCatUtil.normalize(data)); |
... | ... | |
1368 | 1345 |
} |
1369 | 1346 |
|
1370 | 1347 |
/* Compare whitespace from xml and db */ |
1371 |
private void compareWhiteSpace(Stack nodeStack, String string, String error) |
|
1348 |
private void compareWhiteSpace(Stack<NodeRecord> nodeStack, String string, String error)
|
|
1372 | 1349 |
throws SAXException |
1373 | 1350 |
{ |
1374 | 1351 |
NodeRecord node = null; |
1375 | 1352 |
try { |
1376 |
node = (NodeRecord) nodeStack.pop();
|
|
1353 |
node = nodeStack.pop(); |
|
1377 | 1354 |
} catch (EmptyStackException ee) { |
1378 | 1355 |
logMetacat.error("the stack is empty for whitespace data"); |
1379 | 1356 |
throw new SAXException(error); |
1380 | 1357 |
} |
1381 | 1358 |
if (!node.getNodeType().equals("TEXT") |
1382 | 1359 |
|| !string.equals(node.getNodeData())) { |
1383 |
logMetacat.info("Inconsistence happend: ");
|
|
1384 |
logMetacat.info(
|
|
1360 |
logMetacat.error("Inconsistence happened: ");
|
|
1361 |
logMetacat.error(
|
|
1385 | 1362 |
"current node type from xml is WHITESPACE TEXT"); |
1386 |
logMetacat.info("node type from stack: "
|
|
1363 |
logMetacat.error("node type from stack: "
|
|
1387 | 1364 |
+ node.getNodeType()); |
1388 |
logMetacat.info(
|
|
1365 |
logMetacat.error(
|
|
1389 | 1366 |
"current node data from xml is: " + string); |
1390 |
logMetacat.info("node data from stack: "
|
|
1367 |
logMetacat.error("node data from stack: "
|
|
1391 | 1368 |
+ node.getNodeData()); |
1392 |
logMetacat.info("node is from stack: " + node.getNodeId());
|
|
1369 |
logMetacat.error("node is from stack: " + node.getNodeId());
|
|
1393 | 1370 |
throw new SAXException(error); |
1394 | 1371 |
}//if |
1395 | 1372 |
} |
... | ... | |
1397 | 1374 |
/** SAX Handler that receives notification of end of the document */ |
1398 | 1375 |
public void endDocument() throws SAXException |
1399 | 1376 |
{ |
1400 |
logMetacat.info("end Document");
|
|
1377 |
logMetacat.debug("end Document");
|
|
1401 | 1378 |
// There are some unchangable subtree didn't be compare |
1402 | 1379 |
// This maybe cause user change the subtree id |
1403 |
if (!unChangableSubTreeHash.isEmpty()) { |
|
1404 |
logMetacat.info("The unChangealbe subtree is not empty"); |
|
1405 |
throw new SAXException(PERMISSIONERROR); |
|
1406 |
} |
|
1380 |
// MCD - Removed the following code. It is used for node level access |
|
1381 |
// control which is not yet implemented in EML 2.1.0 |
|
1382 |
// if (!unChangeableSubTreeHash.isEmpty()) { |
|
1383 |
// logMetacat.info("The unChangealbe subtree is not empty"); |
|
1384 |
// throw new SAXException(PERMISSIONERROR); |
|
1385 |
// } |
|
1407 | 1386 |
if (!super.getIsRevisionDoc()) |
1408 | 1387 |
{ |
1409 | 1388 |
// write access rule to db |
... | ... | |
1412 | 1391 |
deleteRelations(); |
1413 | 1392 |
//write relations |
1414 | 1393 |
for (int i = 0; i < onlineDataFileIdInRelationVector.size(); i++) { |
1415 |
String id = (String) onlineDataFileIdInRelationVector.elementAt(i);
|
|
1394 |
String id = onlineDataFileIdInRelationVector.elementAt(i); |
|
1416 | 1395 |
writeOnlineDataFileIdIntoRelationTable(id); |
1417 | 1396 |
} |
1418 | 1397 |
} |
1419 |
|
|
1420 |
|
|
1421 | 1398 |
} |
1422 | 1399 |
|
1423 | 1400 |
/* The method to write all access rule into db */ |
... | ... | |
1428 | 1405 |
//write top leve access rule |
1429 | 1406 |
writeTopLevelAccessRuleToDB(); |
1430 | 1407 |
//write additional access rule |
1431 |
//writeAddtionalAccessRuleToDB();
|
|
1408 |
writeAddtionalAccessRuleToDB(); |
|
1432 | 1409 |
}//writeAccessRuleToDB |
1433 | 1410 |
|
1434 | 1411 |
/* The method to write top level access rule into db. */ |
1435 | 1412 |
private void writeTopLevelAccessRuleToDB() throws SAXException |
1436 | 1413 |
{ |
1437 |
|
|
1438 | 1414 |
// for top document level |
1439 |
Object accessSection = topLevelAccessControlMap.get(docid);
|
|
1415 |
AccessSection accessSection = topLevelAccessControlMap.get(docid);
|
|
1440 | 1416 |
boolean top = true; |
1441 | 1417 |
String subSectionId = null; |
1442 | 1418 |
if (accessSection != null) { |
1443 |
AccessSection accessSectionObj = (AccessSection) accessSection;
|
|
1419 |
AccessSection accessSectionObj = accessSection; |
|
1444 | 1420 |
|
1445 | 1421 |
// if accessSection is not null and is not reference |
1446 | 1422 |
if (accessSectionObj.getReferences() == null) { |
1447 | 1423 |
// write the top level access module into xml_accesssubtree to |
1448 |
// store info |
Also available in: Unified diff
Changes to support EML 2.1.0. Mostly access control changes, but others as well.