|
1 |
/**
|
|
2 |
* '$RCSfile$'
|
|
3 |
* Purpose: A Class that handles the SAX XML events as they
|
|
4 |
* are generated from XML documents
|
|
5 |
* Copyright: 2000 Regents of the University of California and the
|
|
6 |
* National Center for Ecological Analysis and Synthesis
|
|
7 |
* Authors: Matt Jones, Jivka Bojilova
|
|
8 |
* Release: @release@
|
|
9 |
*
|
|
10 |
* '$Author$'
|
|
11 |
* '$Date$'
|
|
12 |
* '$Revision$'
|
|
13 |
*
|
|
14 |
* This program is free software; you can redistribute it and/or modify
|
|
15 |
* it under the terms of the GNU General Public License as published by
|
|
16 |
* the Free Software Foundation; either version 2 of the License, or
|
|
17 |
* (at your option) any later version.
|
|
18 |
*
|
|
19 |
* This program is distributed in the hope that it will be useful,
|
|
20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22 |
* GNU General Public License for more details.
|
|
23 |
*
|
|
24 |
* You should have received a copy of the GNU General Public License
|
|
25 |
* along with this program; if not, write to the Free Software
|
|
26 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
27 |
*/
|
|
28 |
|
|
29 |
package edu.ucsb.nceas.metacat;
|
|
30 |
|
|
31 |
import java.io.BufferedReader;
|
|
32 |
import java.io.File;
|
|
33 |
import java.io.FileReader;
|
|
34 |
import java.io.FileWriter;
|
|
35 |
import java.io.IOException;
|
|
36 |
import java.io.Reader;
|
|
37 |
import java.sql.PreparedStatement;
|
|
38 |
import java.sql.ResultSet;
|
|
39 |
import java.sql.SQLException;
|
|
40 |
import java.sql.Statement;
|
|
41 |
import java.util.EmptyStackException;
|
|
42 |
import java.util.Enumeration;
|
|
43 |
import java.util.Hashtable;
|
|
44 |
import java.util.Stack;
|
|
45 |
import java.util.Vector;
|
|
46 |
|
|
47 |
import org.xml.sax.Attributes;
|
|
48 |
import org.xml.sax.SAXException;
|
|
49 |
|
|
50 |
/**
|
|
51 |
* A database aware Class implementing callback bethods for the SAX parser to
|
|
52 |
* call when processing the XML stream and generating events
|
|
53 |
*/
|
|
54 |
public class Eml210SAXHandler extends DBSAXHandler implements
|
|
55 |
AccessControlInterface
|
|
56 |
{
|
|
57 |
|
|
58 |
private Vector allowRules = new Vector();
|
|
59 |
|
|
60 |
private Vector denyRules = new Vector();
|
|
61 |
|
|
62 |
private String documentId = null;
|
|
63 |
|
|
64 |
private Vector subDocumentIdList = new Vector();
|
|
65 |
|
|
66 |
private boolean processTopLeverAccess = false;
|
|
67 |
|
|
68 |
private boolean processAdditionalAccess = false;
|
|
69 |
|
|
70 |
private boolean processOtherAccess = false;
|
|
71 |
|
|
72 |
private AccessSection accessObject = null;
|
|
73 |
|
|
74 |
private AccessRule accessRule = null;
|
|
75 |
|
|
76 |
private Vector accessObjectList = new Vector(); // store every access rule
|
|
77 |
|
|
78 |
private Hashtable topLevelAccessControlMap = new Hashtable();
|
|
79 |
|
|
80 |
private Hashtable additionalAccessControlMap = new Hashtable();// store
|
|
81 |
|
|
82 |
//subtree access for single
|
|
83 |
// additionalmetacat
|
|
84 |
private Vector additionalAccessMapList = new Vector();// store maps for
|
|
85 |
|
|
86 |
// every addionalmetadata
|
|
87 |
private Vector describesId = new Vector(); // store the ids in
|
|
88 |
|
|
89 |
//additionalmetadata/describes
|
|
90 |
private Stack subTreeInfoStack = new Stack();
|
|
91 |
|
|
92 |
private Vector subTreeList = new Vector();// store the final subtree
|
|
93 |
|
|
94 |
private Hashtable unChangableSubTreeHash = new Hashtable();
|
|
95 |
|
|
96 |
private Stack currentUnChangedableSubtreeNodeStack = new Stack();
|
|
97 |
|
|
98 |
private boolean startCriticalSubTree = false;
|
|
99 |
|
|
100 |
private boolean firstElementForCriticalSubTree = false;
|
|
101 |
|
|
102 |
private String firstElementNameForCriticalSubTree;
|
|
103 |
|
|
104 |
private boolean needCheckingAccessModule = false;
|
|
105 |
|
|
106 |
private Vector unChangableAccessSubTreeVector = new Vector();
|
|
107 |
|
|
108 |
private Stack currentUnchangableAccessModuleNodeStack = new Stack();
|
|
109 |
|
|
110 |
private AccessSection topAccessSection;
|
|
111 |
|
|
112 |
// we need an another stack to store the access node which we pull out just
|
|
113 |
// from xml. If a reference happend, we can use the stack the compare nodes
|
|
114 |
private Stack storedAccessNodeStack = new Stack();
|
|
115 |
|
|
116 |
// vector stored the data file id which will be write into relation table
|
|
117 |
private Vector onlineDataFileIdInRelationVector = new Vector();
|
|
118 |
|
|
119 |
// vector stored the data file id which will be write top access rules to
|
|
120 |
// access table
|
|
121 |
private Vector onlineDataFileIdInTopAccessVector = new Vector();
|
|
122 |
|
|
123 |
// Indicator of inline data
|
|
124 |
private boolean handleInlineData = false;
|
|
125 |
|
|
126 |
private Stack inlineDataNodeStack = null;
|
|
127 |
|
|
128 |
private Hashtable inlineDataNameSpace = null;
|
|
129 |
|
|
130 |
private FileWriter inlineDataFileWriter = null;
|
|
131 |
|
|
132 |
private String inlineDataFileName = null;
|
|
133 |
|
|
134 |
private int inLineDataIndex = 0;
|
|
135 |
|
|
136 |
private Vector inlineFileIDList = new Vector();
|
|
137 |
|
|
138 |
|
|
139 |
// Constant
|
|
140 |
private static final String EML = "eml";
|
|
141 |
|
|
142 |
private static final String DESCRIBES = "describes";
|
|
143 |
|
|
144 |
private static final String ADDITIONALMETADATA = "additionalMetadata";
|
|
145 |
|
|
146 |
private static final String ORDER = "order";
|
|
147 |
|
|
148 |
private static final String ID = "id";
|
|
149 |
|
|
150 |
private static final String REFERENCES = "references";
|
|
151 |
|
|
152 |
public static final String INLINE = "inline";
|
|
153 |
|
|
154 |
private static final String ONLINE = "online";
|
|
155 |
|
|
156 |
private static final String URL = "url";
|
|
157 |
|
|
158 |
private static final String PERMISSIONERROR = "User try to update a subtree"
|
|
159 |
+ " which it doesn't have write permission!";
|
|
160 |
|
|
161 |
private static final String UPDATEACCESSERROR = "User try to update a "
|
|
162 |
+ "access module which it doesn't have \"ALL\" permission!";
|
|
163 |
|
|
164 |
private static final String TOPLEVEL = "top";
|
|
165 |
|
|
166 |
private static final String SUBTREELEVEL = "subtree";
|
|
167 |
|
|
168 |
private static final String RELATION = "Provides info for";
|
|
169 |
|
|
170 |
/**
|
|
171 |
* Construct an instance of the handler class In this constructor, user can
|
|
172 |
* specify the version need to upadate
|
|
173 |
*
|
|
174 |
* @param conn the JDBC connection to which information is written
|
|
175 |
* @param action - "INSERT" or "UPDATE"
|
|
176 |
* @param docid to be inserted or updated into JDBC connection
|
|
177 |
* @param revision, the user specified the revision need to be update
|
|
178 |
* @param user the user connected to MetaCat servlet and owns the document
|
|
179 |
* @param groups the groups to which user belongs
|
|
180 |
* @param pub flag for public "read" access on document
|
|
181 |
* @param serverCode the serverid from xml_replication on which this
|
|
182 |
* document resides.
|
|
183 |
*
|
|
184 |
*/
|
|
185 |
public Eml210SAXHandler(DBConnection conn, String action, String docid,
|
|
186 |
String revision, String user, String[] groups, String pub,
|
|
187 |
int serverCode) throws SAXException
|
|
188 |
{
|
|
189 |
super(conn, action, docid, revision, user, groups, pub, serverCode);
|
|
190 |
// Get the unchangable subtrees (user doesn't have write permission)
|
|
191 |
try {
|
|
192 |
PermissionController control = new PermissionController(docid
|
|
193 |
+ MetaCatUtil.getOption("accNumSeparator") + revision);
|
|
194 |
//unChangableSubTreeHash = getUnchangableSubTree(control, user,
|
|
195 |
// groups);
|
|
196 |
|
|
197 |
//If the action is update and user doesn't have "ALL" permission
|
|
198 |
// we need to check if user update access subtree
|
|
199 |
if (action.equals("UPDATE")
|
|
200 |
&& !control.hasPermission(user, groups,
|
|
201 |
AccessControlInterface.ALLSTRING)) {
|
|
202 |
needCheckingAccessModule = true;
|
|
203 |
unChangableAccessSubTreeVector = getAccessSubTreeListFromDB();
|
|
204 |
}
|
|
205 |
} catch (Exception e) {
|
|
206 |
throw new SAXException(e.getMessage());
|
|
207 |
}
|
|
208 |
}
|
|
209 |
|
|
210 |
/* Pass a permission control and get the list of unchangable subtree */
|
|
211 |
private Hashtable getUnchangableSubTree(PermissionController controller,
|
|
212 |
String user, String[] groups) throws Exception
|
|
213 |
{
|
|
214 |
Hashtable list = null;
|
|
215 |
Hashtable result = new Hashtable();
|
|
216 |
// get unwritable sutree from controller
|
|
217 |
list = 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 |
MetaCatUtil.debugMessage(
|
|
227 |
"unchangable subtree id: " + subTreeId, 40);
|
|
228 |
long startNodeId = treeWithoutStack.getStartNodeId();
|
|
229 |
MetaCatUtil.debugMessage("unchangable subtree startnodeid: "
|
|
230 |
+ startNodeId, 40);
|
|
231 |
long endNodeId = treeWithoutStack.getEndNodeId();
|
|
232 |
MetaCatUtil.debugMessage("unchangable subtree endnodeid: "
|
|
233 |
+ endNodeId, 40);
|
|
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 |
}
|
|
246 |
|
|
247 |
/*
|
|
248 |
* Get the subtree node info from xml_accesssubtree table
|
|
249 |
*/
|
|
250 |
private Vector getAccessSubTreeListFromDB() throws Exception
|
|
251 |
{
|
|
252 |
Vector result = new Vector();
|
|
253 |
PreparedStatement pstmt = null;
|
|
254 |
ResultSet rs = null;
|
|
255 |
String sql = "SELECT controllevel, subtreeid, startnodeid, endnodeid "
|
|
256 |
+ "FROM xml_accesssubtree WHERE docid like ? "
|
|
257 |
+ "ORDER BY startnodeid ASC";
|
|
258 |
|
|
259 |
try {
|
|
260 |
|
|
261 |
pstmt = connection.prepareStatement(sql);
|
|
262 |
// Increase DBConnection usage count
|
|
263 |
connection.increaseUsageCount(1);
|
|
264 |
// Bind the values to the query
|
|
265 |
pstmt.setString(1, docid);
|
|
266 |
pstmt.execute();
|
|
267 |
|
|
268 |
// Get result set
|
|
269 |
rs = pstmt.getResultSet();
|
|
270 |
while (rs.next()) {
|
|
271 |
String level = rs.getString(1);
|
|
272 |
String sectionId = rs.getString(2);
|
|
273 |
long startNodeId = rs.getLong(3);
|
|
274 |
long endNodeId = rs.getLong(4);
|
|
275 |
// create a new access section
|
|
276 |
AccessSection accessObj = new AccessSection();
|
|
277 |
accessObj.setControlLevel(level);
|
|
278 |
accessObj.setDocId(docid);
|
|
279 |
accessObj.setSubTreeId(sectionId);
|
|
280 |
accessObj.setStartNodeId(startNodeId);
|
|
281 |
accessObj.setEndNodeId(endNodeId);
|
|
282 |
Stack nodeStack = accessObj.getSubTreeNodeList();
|
|
283 |
accessObj.setSubTreeNodeStack(nodeStack);
|
|
284 |
// add this access obj into vector
|
|
285 |
result.add(accessObj);
|
|
286 |
// Get the top level access subtree control
|
|
287 |
if (level != null && level.equals(TOPLEVEL)) {
|
|
288 |
topAccessSection = accessObj;
|
|
289 |
}
|
|
290 |
}
|
|
291 |
pstmt.close();
|
|
292 |
}//try
|
|
293 |
catch (SQLException e) {
|
|
294 |
throw new SAXException(
|
|
295 |
"EMLSAXHandler.getAccessSubTreeListFromDB(): "
|
|
296 |
+ e.getMessage());
|
|
297 |
}//catch
|
|
298 |
finally {
|
|
299 |
try {
|
|
300 |
pstmt.close();
|
|
301 |
} catch (SQLException ee) {
|
|
302 |
throw new SAXException(
|
|
303 |
"EMLSAXHandler.getAccessSubTreeListFromDB(): "
|
|
304 |
+ ee.getMessage());
|
|
305 |
}
|
|
306 |
}//finally
|
|
307 |
return result;
|
|
308 |
}
|
|
309 |
|
|
310 |
/** SAX Handler that is called at the start of each XML element */
|
|
311 |
public void startElement(String uri, String localName, String qName,
|
|
312 |
Attributes atts) throws SAXException
|
|
313 |
{
|
|
314 |
// for element <eml:eml...> qname is "eml:eml", local name is "eml"
|
|
315 |
// for element <acl....> both qname and local name is "eml"
|
|
316 |
// uri is namesapce
|
|
317 |
MetaCatUtil.debugMessage("Start ELEMENT(qName) " + qName, 50);
|
|
318 |
MetaCatUtil.debugMessage("Start ELEMENT(localName) " + localName, 50);
|
|
319 |
MetaCatUtil.debugMessage("Start ELEMENT(uri) " + uri, 50);
|
|
320 |
|
|
321 |
DBSAXNode parentNode = null;
|
|
322 |
DBSAXNode currentNode = null;
|
|
323 |
|
|
324 |
if (!handleInlineData) {
|
|
325 |
// Get a reference to the parent node for the id
|
|
326 |
try {
|
|
327 |
parentNode = (DBSAXNode) nodeStack.peek();
|
|
328 |
} catch (EmptyStackException e) {
|
|
329 |
parentNode = null;
|
|
330 |
}
|
|
331 |
|
|
332 |
//start handle inline data
|
|
333 |
if (localName.equals(INLINE)) {
|
|
334 |
handleInlineData = true;
|
|
335 |
inLineDataIndex++;
|
|
336 |
//intitialize namespace hash for in line data
|
|
337 |
inlineDataNameSpace = new Hashtable();
|
|
338 |
//initialize file writer
|
|
339 |
String docidWithoutRev = MetaCatUtil.getDocIdFromString(docid);
|
|
340 |
String seperator = MetaCatUtil.getOption("accNumSeparator");
|
|
341 |
// the new file name will look like docid.rev.2
|
|
342 |
inlineDataFileName = docidWithoutRev + seperator + revision
|
|
343 |
+ seperator + inLineDataIndex;
|
|
344 |
inlineDataFileWriter = createInlineDataFileWriter(inlineDataFileName);
|
|
345 |
// put the inline file id into a vector. If upload failed,
|
|
346 |
// metacat will
|
|
347 |
// delete the inline data file
|
|
348 |
inlineFileIDList.add(inlineDataFileName);
|
|
349 |
|
|
350 |
}
|
|
351 |
|
|
352 |
// If hit a text node, we need write this text for current's parent
|
|
353 |
// node
|
|
354 |
// This will happend if the element is mixted
|
|
355 |
if (hitTextNode && parentNode != null) {
|
|
356 |
//compare text node data for unchangesubtree
|
|
357 |
if (startCriticalSubTree) {
|
|
358 |
compareTextNode(currentUnChangedableSubtreeNodeStack,
|
|
359 |
textBuffer, PERMISSIONERROR);
|
|
360 |
}//if
|
|
361 |
|
|
362 |
//compare top level access module
|
|
363 |
if (processTopLeverAccess && needCheckingAccessModule) {
|
|
364 |
compareTextNode(currentUnchangableAccessModuleNodeStack,
|
|
365 |
textBuffer, UPDATEACCESSERROR);
|
|
366 |
}
|
|
367 |
|
|
368 |
if (needCheckingAccessModule
|
|
369 |
&& (processAdditionalAccess || processOtherAccess || processTopLeverAccess)) {
|
|
370 |
// stored the pull out nodes into storedNode stack
|
|
371 |
NodeRecord nodeElement = new NodeRecord(-2, -2, -2, "TEXT",
|
|
372 |
null, null, MetaCatUtil.normalize(textBuffer
|
|
373 |
.toString()));
|
|
374 |
storedAccessNodeStack.push(nodeElement);
|
|
375 |
|
|
376 |
}
|
|
377 |
|
|
378 |
// write the textbuffer into db for parent node.
|
|
379 |
endNodeId = writeTextForDBSAXNode(endNodeId, textBuffer,
|
|
380 |
parentNode);
|
|
381 |
// rest hitTextNode
|
|
382 |
hitTextNode = false;
|
|
383 |
// reset textbuffer
|
|
384 |
textBuffer = null;
|
|
385 |
textBuffer = new StringBuffer();
|
|
386 |
|
|
387 |
}
|
|
388 |
|
|
389 |
// Document representation that points to the root document node
|
|
390 |
if (atFirstElement) {
|
|
391 |
atFirstElement = false;
|
|
392 |
// If no DOCTYPE declaration: docname = root element
|
|
393 |
// doctype = root element name or name space
|
|
394 |
if (docname == null) {
|
|
395 |
docname = localName;
|
|
396 |
// if uri isn't null doctype = uri(namespace)
|
|
397 |
// othewise root element
|
|
398 |
if (uri != null && !(uri.trim()).equals("")) {
|
|
399 |
doctype = uri;
|
|
400 |
} else {
|
|
401 |
doctype = docname;
|
|
402 |
}
|
|
403 |
MetaCatUtil.debugMessage("DOCNAME-a: " + docname, 30);
|
|
404 |
MetaCatUtil.debugMessage("DOCTYPE-a: " + doctype, 30);
|
|
405 |
} else if (doctype == null) {
|
|
406 |
// because docname is not null and it is declared in dtd
|
|
407 |
// so could not be in schema, no namespace
|
|
408 |
doctype = docname;
|
|
409 |
MetaCatUtil.debugMessage("DOCTYPE-b: " + doctype, 30);
|
|
410 |
}
|
|
411 |
rootNode.writeNodename(docname);
|
|
412 |
try {
|
|
413 |
// for validated XML Documents store a reference to XML DB
|
|
414 |
// Catalog
|
|
415 |
// Because this is select statement and it needn't to roll
|
|
416 |
// back if
|
|
417 |
// insert document action fialed.
|
|
418 |
// In order to decrease DBConnection usage count, we get a
|
|
419 |
// new
|
|
420 |
// dbconnection from pool
|
|
421 |
String catalogid = null;
|
|
422 |
DBConnection dbConn = null;
|
|
423 |
int serialNumber = -1;
|
|
424 |
|
|
425 |
try {
|
|
426 |
// Get dbconnection
|
|
427 |
dbConn = DBConnectionPool
|
|
428 |
.getDBConnection("DBSAXHandler.startElement");
|
|
429 |
serialNumber = dbConn.getCheckOutSerialNumber();
|
|
430 |
|
|
431 |
Statement stmt = dbConn.createStatement();
|
|
432 |
ResultSet rs = stmt
|
|
433 |
.executeQuery("SELECT catalog_id FROM xml_catalog "
|
|
434 |
+ "WHERE entry_type = 'Schema' "
|
|
435 |
+ "AND public_id = '" + doctype + "'");
|
|
436 |
boolean hasRow = rs.next();
|
|
437 |
if (hasRow) {
|
|
438 |
catalogid = rs.getString(1);
|
|
439 |
}
|
|
440 |
stmt.close();
|
|
441 |
}//try
|
|
442 |
finally {
|
|
443 |
// Return dbconnection
|
|
444 |
DBConnectionPool.returnDBConnection(dbConn,
|
|
445 |
serialNumber);
|
|
446 |
}//finally
|
|
447 |
|
|
448 |
//create documentImpl object by the constructor which can
|
|
449 |
// specify
|
|
450 |
//the revision
|
|
451 |
currentDocument = new DocumentImpl(connection, rootNode
|
|
452 |
.getNodeID(), docname, doctype, docid, revision,
|
|
453 |
action, user, this.pub, catalogid, this.serverCode);
|
|
454 |
|
|
455 |
} catch (Exception ane) {
|
|
456 |
throw (new SAXException(
|
|
457 |
"Error in EMLSaxHandler.startElement " + action,
|
|
458 |
ane));
|
|
459 |
}
|
|
460 |
}
|
|
461 |
|
|
462 |
// Create the current node representation
|
|
463 |
currentNode = new DBSAXNode(connection, qName, localName,
|
|
464 |
parentNode, currentDocument.getRootNodeID(), docid,
|
|
465 |
currentDocument.getDoctype());
|
|
466 |
// Use a local variable to store the element node id
|
|
467 |
// If this element is a start point of subtree(section), it will be
|
|
468 |
// stored
|
|
469 |
// otherwise, it will be discated
|
|
470 |
long startNodeId = currentNode.getNodeID();
|
|
471 |
// Add all of the namespaces
|
|
472 |
String prefix = null;
|
|
473 |
String nsuri = null;
|
|
474 |
Enumeration prefixes = namespaces.keys();
|
|
475 |
while (prefixes.hasMoreElements()) {
|
|
476 |
prefix = (String) prefixes.nextElement();
|
|
477 |
nsuri = (String) namespaces.get(prefix);
|
|
478 |
endNodeId = currentNode.setNamespace(prefix, nsuri, docid);
|
|
479 |
}
|
|
480 |
|
|
481 |
// Add all of the attributes
|
|
482 |
for (int i = 0; i < atts.getLength(); i++) {
|
|
483 |
String attributeName = atts.getQName(i);
|
|
484 |
String attributeValue = atts.getValue(i);
|
|
485 |
endNodeId = currentNode.setAttribute(attributeName,
|
|
486 |
attributeValue, docid);
|
|
487 |
|
|
488 |
// To handle name space and schema location if the attribute
|
|
489 |
// name is
|
|
490 |
// xsi:schemaLocation. If the name space is in not in catalog
|
|
491 |
// table
|
|
492 |
// it will be regeistered.
|
|
493 |
if (attributeName != null
|
|
494 |
&& attributeName
|
|
495 |
.indexOf(MetaCatServlet.SCHEMALOCATIONKEYWORD) != -1) {
|
|
496 |
SchemaLocationResolver resolver = new SchemaLocationResolver(
|
|
497 |
attributeValue);
|
|
498 |
resolver.resolveNameSpace();
|
|
499 |
|
|
500 |
} else if (attributeName != null && attributeName.equals(ID)) {
|
|
501 |
|
|
502 |
//check unchangedable subtree hash if contains this
|
|
503 |
// subtree id
|
|
504 |
if (unChangableSubTreeHash.containsKey(attributeValue)) {
|
|
505 |
// this subtree couldn't be changed by the user and
|
|
506 |
// move it from hash
|
|
507 |
SubTree currentUnChangedableSubtree = (SubTree) unChangableSubTreeHash
|
|
508 |
.remove(attributeValue);
|
|
509 |
currentUnChangedableSubtreeNodeStack = currentUnChangedableSubtree
|
|
510 |
.getSubTreeNodeStack();
|
|
511 |
startCriticalSubTree = true;
|
|
512 |
firstElementForCriticalSubTree = true;
|
|
513 |
}
|
|
514 |
|
|
515 |
// handle subtree info
|
|
516 |
SubTree subTress = new SubTree();
|
|
517 |
// set sub tree id
|
|
518 |
subTress.setSubTreeId(attributeValue);
|
|
519 |
// set sub tree sstart lement name
|
|
520 |
subTress.setStartElementName(currentNode.getTagName());
|
|
521 |
// set start node number
|
|
522 |
subTress.setStartNodeId(startNodeId);
|
|
523 |
// add to stack, but it didn't get end node id yet
|
|
524 |
subTreeInfoStack.push(subTress);
|
|
525 |
|
|
526 |
}
|
|
527 |
}//for
|
|
528 |
|
|
529 |
// handle access stuff
|
|
530 |
if (localName.equals(ACCESS)) {
|
|
531 |
// if it is in addtionalmetacat
|
|
532 |
if (parentNode.getTagName() == ADDITIONALMETADATA) {
|
|
533 |
processAdditionalAccess = true;
|
|
534 |
|
|
535 |
} else {
|
|
536 |
//make sure the access is top level
|
|
537 |
// this mean current node's parent's parent should be "eml"
|
|
538 |
DBSAXNode tmpNode = (DBSAXNode) nodeStack.pop();// pop out
|
|
539 |
// parent
|
|
540 |
// node
|
|
541 |
//peek out grandParentNode
|
|
542 |
DBSAXNode grandParentNode = (DBSAXNode) nodeStack.peek();
|
|
543 |
// put parent node back
|
|
544 |
nodeStack.push(tmpNode);
|
|
545 |
String grandParentTag = grandParentNode.getTagName();
|
|
546 |
if (grandParentTag.equals(EML)) {
|
|
547 |
processTopLeverAccess = true;
|
|
548 |
} else {
|
|
549 |
// process other access embedded into resource level
|
|
550 |
// module
|
|
551 |
processOtherAccess = true;
|
|
552 |
}
|
|
553 |
|
|
554 |
}
|
|
555 |
// create access object
|
|
556 |
accessObject = new AccessSection();
|
|
557 |
// set permission order
|
|
558 |
String permOrder = currentNode.getAttribute(ORDER);
|
|
559 |
accessObject.setPermissionOrder(permOrder);
|
|
560 |
// set access id
|
|
561 |
String accessId = currentNode.getAttribute(ID);
|
|
562 |
accessObject.setSubTreeId(accessId);
|
|
563 |
accessObject.setStartNodeId(startNodeId);
|
|
564 |
accessObject.setDocId(docid);
|
|
565 |
|
|
566 |
// load top level node stack to
|
|
567 |
// currentUnchangableAccessModuleNodeStack
|
|
568 |
if (processTopLeverAccess && needCheckingAccessModule) {
|
|
569 |
// get the node stack for
|
|
570 |
currentUnchangableAccessModuleNodeStack = topAccessSection
|
|
571 |
.getSubTreeNodeStack();
|
|
572 |
}
|
|
573 |
|
|
574 |
}
|
|
575 |
// Set up a access rule for allow
|
|
576 |
else if (parentNode.getTagName() != null
|
|
577 |
&& (parentNode.getTagName()).equals(ACCESS)
|
|
578 |
&& localName.equals(ALLOW)) {
|
|
579 |
|
|
580 |
accessRule = new AccessRule();
|
|
581 |
|
|
582 |
//set permission type "allow"
|
|
583 |
accessRule.setPermissionType(ALLOW);
|
|
584 |
|
|
585 |
}
|
|
586 |
// set up an access rule for den
|
|
587 |
else if (parentNode.getTagName() != null
|
|
588 |
&& (parentNode.getTagName()).equals(ACCESS)
|
|
589 |
&& localName.equals(DENY)) {
|
|
590 |
accessRule = new AccessRule();
|
|
591 |
//set permission type "allow"
|
|
592 |
accessRule.setPermissionType(DENY);
|
|
593 |
}
|
|
594 |
|
|
595 |
// Add the node to the stack, so that any text data can be
|
|
596 |
// added as it is encountered
|
|
597 |
nodeStack.push(currentNode);
|
|
598 |
// Add the node to the vector used by thread for writing XML Index
|
|
599 |
nodeIndex.addElement(currentNode);
|
|
600 |
|
|
601 |
// handle critical subtree
|
|
602 |
if (startCriticalSubTree && firstElementForCriticalSubTree) {
|
|
603 |
//store the element name
|
|
604 |
firstElementNameForCriticalSubTree = qName;
|
|
605 |
firstElementForCriticalSubTree = false;
|
|
606 |
}//for first element
|
|
607 |
|
|
608 |
// handle critical subtree
|
|
609 |
if (startCriticalSubTree) {
|
|
610 |
compareElementNameSpaceAttributes(
|
|
611 |
currentUnChangedableSubtreeNodeStack, namespaces, atts,
|
|
612 |
localName, PERMISSIONERROR);
|
|
613 |
|
|
614 |
}
|
|
615 |
//compare top access level module
|
|
616 |
if (processTopLeverAccess && needCheckingAccessModule) {
|
|
617 |
compareElementNameSpaceAttributes(
|
|
618 |
currentUnchangableAccessModuleNodeStack, namespaces,
|
|
619 |
atts, localName, UPDATEACCESSERROR);
|
|
620 |
|
|
621 |
}
|
|
622 |
|
|
623 |
// store access module element and attributes into stored stack
|
|
624 |
if (needCheckingAccessModule
|
|
625 |
&& (processAdditionalAccess || processOtherAccess || processTopLeverAccess)) {
|
|
626 |
// stored the pull out nodes into storedNode stack
|
|
627 |
NodeRecord nodeElement = new NodeRecord(-2, -2, -2, "ELEMENT",
|
|
628 |
localName, prefix, MetaCatUtil.normalize(null));
|
|
629 |
storedAccessNodeStack.push(nodeElement);
|
|
630 |
for (int i = 0; i < atts.getLength(); i++) {
|
|
631 |
String attributeName = atts.getQName(i);
|
|
632 |
String attributeValue = atts.getValue(i);
|
|
633 |
NodeRecord nodeAttribute = new NodeRecord(-2, -2, -2,
|
|
634 |
"ATTRIBUTE", attributeName, null, MetaCatUtil
|
|
635 |
.normalize(attributeValue));
|
|
636 |
storedAccessNodeStack.push(nodeAttribute);
|
|
637 |
}
|
|
638 |
|
|
639 |
}
|
|
640 |
|
|
641 |
// reset name space
|
|
642 |
namespaces = null;
|
|
643 |
namespaces = new Hashtable();
|
|
644 |
}//not inline data
|
|
645 |
else {
|
|
646 |
// we don't buffer the inline data in characters() method
|
|
647 |
// so start character don't need to hand text node.
|
|
648 |
|
|
649 |
// inline data may be the xml format.
|
|
650 |
StringBuffer inlineElements = new StringBuffer();
|
|
651 |
inlineElements.append("<").append(qName);
|
|
652 |
// append attributes
|
|
653 |
for (int i = 0; i < atts.getLength(); i++) {
|
|
654 |
String attributeName = atts.getQName(i);
|
|
655 |
String attributeValue = atts.getValue(i);
|
|
656 |
inlineElements.append(" ");
|
|
657 |
inlineElements.append(attributeName);
|
|
658 |
inlineElements.append("=\"");
|
|
659 |
inlineElements.append(attributeValue);
|
|
660 |
inlineElements.append("\"");
|
|
661 |
}
|
|
662 |
// append namespace
|
|
663 |
String prefix = null;
|
|
664 |
String nsuri = null;
|
|
665 |
Enumeration prefixes = inlineDataNameSpace.keys();
|
|
666 |
while (prefixes.hasMoreElements()) {
|
|
667 |
prefix = (String) prefixes.nextElement();
|
|
668 |
nsuri = (String) namespaces.get(prefix);
|
|
669 |
inlineElements.append(" ");
|
|
670 |
inlineElements.append("xmlns:");
|
|
671 |
inlineElements.append(prefix);
|
|
672 |
inlineElements.append("=\"");
|
|
673 |
inlineElements.append(nsuri);
|
|
674 |
inlineElements.append("\"");
|
|
675 |
}
|
|
676 |
inlineElements.append(">");
|
|
677 |
//reset inline data name space
|
|
678 |
inlineDataNameSpace = null;
|
|
679 |
inlineDataNameSpace = new Hashtable();
|
|
680 |
//write inline data into file
|
|
681 |
MetaCatUtil.debugMessage("the inline element data is: "
|
|
682 |
+ inlineElements.toString(), 50);
|
|
683 |
writeInlineDataIntoFile(inlineDataFileWriter, inlineElements);
|
|
684 |
}//else
|
|
685 |
|
|
686 |
}
|
|
687 |
|
|
688 |
private void compareElementNameSpaceAttributes(Stack unchangableNodeStack,
|
|
689 |
Hashtable nameSpaces, Attributes attributes, String localName,
|
|
690 |
String error) throws SAXException
|
|
691 |
{
|
|
692 |
//Get element subtree node stack (element node)
|
|
693 |
NodeRecord elementNode = null;
|
|
694 |
try {
|
|
695 |
elementNode = (NodeRecord) unchangableNodeStack.pop();
|
|
696 |
} catch (EmptyStackException ee) {
|
|
697 |
MetaCatUtil
|
|
698 |
.debugMessage("Node stack is empty for element data", 35);
|
|
699 |
throw new SAXException(error);
|
|
700 |
}
|
|
701 |
MetaCatUtil.debugMessage("current node type from xml is ELEMENT", 40);
|
|
702 |
MetaCatUtil.debugMessage("node type from stack: "
|
|
703 |
+ elementNode.getNodeType(), 40);
|
|
704 |
MetaCatUtil.debugMessage("node name from xml document: " + localName,
|
|
705 |
40);
|
|
706 |
MetaCatUtil.debugMessage("node name from stack: "
|
|
707 |
+ elementNode.getNodeName(), 40);
|
|
708 |
MetaCatUtil.debugMessage("node data from stack: "
|
|
709 |
+ elementNode.getNodeData(), 40);
|
|
710 |
MetaCatUtil.debugMessage("node id is: " + elementNode.getNodeId(), 40);
|
|
711 |
// if this node is not element or local name not equal or name space
|
|
712 |
// not
|
|
713 |
// equals, throw an exception
|
|
714 |
if (!elementNode.getNodeType().equals("ELEMENT")
|
|
715 |
|| !localName.equals(elementNode.getNodeName()))
|
|
716 |
// (uri != null && !uri.equals(elementNode.getNodePrefix())))
|
|
717 |
{
|
|
718 |
MetaCatUtil.debugMessage("Inconsistence happend: ", 40);
|
|
719 |
MetaCatUtil.debugMessage("current node type from xml is ELEMENT",
|
|
720 |
40);
|
|
721 |
MetaCatUtil.debugMessage("node type from stack: "
|
|
722 |
+ elementNode.getNodeType(), 40);
|
|
723 |
MetaCatUtil.debugMessage("node name from xml document: "
|
|
724 |
+ localName, 40);
|
|
725 |
MetaCatUtil.debugMessage("node name from stack: "
|
|
726 |
+ elementNode.getNodeName(), 40);
|
|
727 |
MetaCatUtil.debugMessage("node data from stack: "
|
|
728 |
+ elementNode.getNodeData(), 40);
|
|
729 |
MetaCatUtil.debugMessage("node id is: " + elementNode.getNodeId(),
|
|
730 |
40);
|
|
731 |
throw new SAXException(error);
|
|
732 |
}
|
|
733 |
|
|
734 |
//compare namespace
|
|
735 |
Enumeration nameEn = nameSpaces.keys();
|
|
736 |
while (nameEn.hasMoreElements()) {
|
|
737 |
//Get namespacke node stack (element node)
|
|
738 |
NodeRecord nameNode = null;
|
|
739 |
try {
|
|
740 |
nameNode = (NodeRecord) unchangableNodeStack.pop();
|
|
741 |
} catch (EmptyStackException ee) {
|
|
742 |
MetaCatUtil.debugMessage(
|
|
743 |
"Node stack is empty for namespace data", 35);
|
|
744 |
throw new SAXException(error);
|
|
745 |
}
|
|
746 |
|
|
747 |
String prefixName = (String) nameEn.nextElement();
|
|
748 |
String nameSpaceUri = (String) nameSpaces.get(prefixName);
|
|
749 |
if (!nameNode.getNodeType().equals("NAMESPACE")
|
|
750 |
|| !prefixName.equals(nameNode.getNodeName())
|
|
751 |
|| !nameSpaceUri.equals(nameNode.getNodeData())) {
|
|
752 |
MetaCatUtil.debugMessage("Inconsistence happend: ", 40);
|
|
753 |
MetaCatUtil.debugMessage(
|
|
754 |
"current node type from xml is NAMESPACE", 40);
|
|
755 |
MetaCatUtil.debugMessage("node type from stack: "
|
|
756 |
+ nameNode.getNodeType(), 40);
|
|
757 |
MetaCatUtil.debugMessage("current node name from xml is: "
|
|
758 |
+ prefixName, 40);
|
|
759 |
MetaCatUtil.debugMessage("node name from stack: "
|
|
760 |
+ nameNode.getNodeName(), 40);
|
|
761 |
MetaCatUtil.debugMessage("current node data from xml is: "
|
|
762 |
+ nameSpaceUri, 40);
|
|
763 |
MetaCatUtil.debugMessage("node data from stack: "
|
|
764 |
+ nameNode.getNodeData(), 40);
|
|
765 |
MetaCatUtil.debugMessage("node id is: " + nameNode.getNodeId(),
|
|
766 |
40);
|
|
767 |
throw new SAXException(error);
|
|
768 |
}
|
|
769 |
|
|
770 |
}//while
|
|
771 |
|
|
772 |
//compare attributes
|
|
773 |
for (int i = 0; i < attributes.getLength(); i++) {
|
|
774 |
NodeRecord attriNode = null;
|
|
775 |
try {
|
|
776 |
attriNode = (NodeRecord) unchangableNodeStack.pop();
|
|
777 |
|
|
778 |
} catch (EmptyStackException ee) {
|
|
779 |
MetaCatUtil.debugMessage(
|
|
780 |
"Node stack is empty for attribute data", 35);
|
|
781 |
throw new SAXException(error);
|
|
782 |
}
|
|
783 |
String attributeName = attributes.getQName(i);
|
|
784 |
String attributeValue = attributes.getValue(i);
|
|
785 |
MetaCatUtil.debugMessage(
|
|
786 |
"current node type from xml is ATTRIBUTE ", 40);
|
|
787 |
MetaCatUtil.debugMessage("node type from stack: "
|
|
788 |
+ attriNode.getNodeType(), 40);
|
|
789 |
MetaCatUtil.debugMessage("current node name from xml is: "
|
|
790 |
+ attributeName, 40);
|
|
791 |
MetaCatUtil.debugMessage("node name from stack: "
|
|
792 |
+ attriNode.getNodeName(), 40);
|
|
793 |
MetaCatUtil.debugMessage("current node data from xml is: "
|
|
794 |
+ attributeValue, 40);
|
|
795 |
MetaCatUtil.debugMessage("node data from stack: "
|
|
796 |
+ attriNode.getNodeData(), 40);
|
|
797 |
MetaCatUtil.debugMessage("node id is: " + attriNode.getNodeId(),
|
|
798 |
40);
|
|
799 |
|
|
800 |
if (!attriNode.getNodeType().equals("ATTRIBUTE")
|
|
801 |
|| !attributeName.equals(attriNode.getNodeName())
|
|
802 |
|| !attributeValue.equals(attriNode.getNodeData())) {
|
|
803 |
MetaCatUtil.debugMessage("Inconsistence happend: ", 40);
|
|
804 |
MetaCatUtil.debugMessage(
|
|
805 |
"current node type from xml is ATTRIBUTE ", 40);
|
|
806 |
MetaCatUtil.debugMessage("node type from stack: "
|
|
807 |
+ attriNode.getNodeType(), 40);
|
|
808 |
MetaCatUtil.debugMessage("current node name from xml is: "
|
|
809 |
+ attributeName, 40);
|
|
810 |
MetaCatUtil.debugMessage("node name from stack: "
|
|
811 |
+ attriNode.getNodeName(), 40);
|
|
812 |
MetaCatUtil.debugMessage("current node data from xml is: "
|
|
813 |
+ attributeValue, 40);
|
|
814 |
MetaCatUtil.debugMessage("node data from stack: "
|
|
815 |
+ attriNode.getNodeData(), 40);
|
|
816 |
MetaCatUtil.debugMessage("node is: " + attriNode.getNodeId(),
|
|
817 |
40);
|
|
818 |
throw new SAXException(error);
|
|
819 |
}
|
|
820 |
}//for
|
|
821 |
|
|
822 |
}
|
|
823 |
|
|
824 |
/* mehtod to compare current text node and node in db */
|
|
825 |
private void compareTextNode(Stack nodeStack, StringBuffer text,
|
|
826 |
String error) throws SAXException
|
|
827 |
{
|
|
828 |
NodeRecord node = null;
|
|
829 |
//get node from current stack
|
|
830 |
try {
|
|
831 |
node = (NodeRecord) nodeStack.pop();
|
|
832 |
} catch (EmptyStackException ee) {
|
|
833 |
MetaCatUtil.debugMessage(
|
|
834 |
"Node stack is empty for text data in startElement", 35);
|
|
835 |
throw new SAXException(error);
|
|
836 |
}
|
|
837 |
MetaCatUtil.debugMessage(
|
|
838 |
"current node type from xml is TEXT in start element", 40);
|
|
839 |
MetaCatUtil.debugMessage("node type from stack: " + node.getNodeType(),
|
|
840 |
40);
|
|
841 |
MetaCatUtil.debugMessage("current node data from xml is: "
|
|
842 |
+ text.toString(), 40);
|
|
843 |
MetaCatUtil.debugMessage("node data from stack: " + node.getNodeData(),
|
|
844 |
40);
|
|
845 |
MetaCatUtil.debugMessage("node name from stack: " + node.getNodeName(),
|
|
846 |
40);
|
|
847 |
MetaCatUtil.debugMessage("node is: " + node.getNodeId(), 40);
|
|
848 |
if (!node.getNodeType().equals("TEXT")
|
|
849 |
|| !(text.toString()).equals(node.getNodeData())) {
|
|
850 |
MetaCatUtil.debugMessage("Inconsistence happend: ", 40);
|
|
851 |
MetaCatUtil.debugMessage(
|
|
852 |
"current node type from xml is TEXT in start element", 40);
|
|
853 |
MetaCatUtil.debugMessage("node type from stack: "
|
|
854 |
+ node.getNodeType(), 40);
|
|
855 |
MetaCatUtil.debugMessage("current node data from xml is: "
|
|
856 |
+ text.toString(), 40);
|
|
857 |
MetaCatUtil.debugMessage("node data from stack: "
|
|
858 |
+ node.getNodeData(), 40);
|
|
859 |
MetaCatUtil.debugMessage("node name from stack: "
|
|
860 |
+ node.getNodeName(), 40);
|
|
861 |
MetaCatUtil.debugMessage("node is: " + node.getNodeId(), 40);
|
|
862 |
throw new SAXException(error);
|
|
863 |
}//if
|
|
864 |
}
|
|
865 |
|
|
866 |
/** SAX Handler that is called for each XML text node */
|
|
867 |
public void characters(char[] cbuf, int start, int len) throws SAXException
|
|
868 |
{
|
|
869 |
MetaCatUtil.debugMessage("CHARACTERS", 50);
|
|
870 |
if (!handleInlineData) {
|
|
871 |
// buffer all text nodes for same element. This is for text was
|
|
872 |
// splited
|
|
873 |
// into different nodes
|
|
874 |
textBuffer.append(new String(cbuf, start, len));
|
|
875 |
// set hittextnode true
|
|
876 |
hitTextNode = true;
|
|
877 |
// if text buffer .size is greater than max, write it to db.
|
|
878 |
// so we can save memory
|
|
879 |
if (textBuffer.length() > MAXDATACHARS) {
|
|
880 |
MetaCatUtil
|
|
881 |
.debugMessage(
|
|
882 |
"Write text into DB in charaters"
|
|
883 |
+ " when text buffer size is greater than maxmum number",
|
|
884 |
50);
|
|
885 |
DBSAXNode currentNode = (DBSAXNode) nodeStack.peek();
|
|
886 |
endNodeId = writeTextForDBSAXNode(endNodeId, textBuffer,
|
|
887 |
currentNode);
|
|
888 |
textBuffer = null;
|
|
889 |
textBuffer = new StringBuffer();
|
|
890 |
}
|
|
891 |
} else {
|
|
892 |
// this is inline data and write file system directly
|
|
893 |
// we don't need to buffered it.
|
|
894 |
StringBuffer inlineText = new StringBuffer();
|
|
895 |
inlineText.append(new String(cbuf, start, len));
|
|
896 |
MetaCatUtil.debugMessage(
|
|
897 |
"The inline text data write into file system: "
|
|
898 |
+ inlineText.toString(), 50);
|
|
899 |
writeInlineDataIntoFile(inlineDataFileWriter, inlineText);
|
|
900 |
}
|
|
901 |
}
|
|
902 |
|
|
903 |
/** SAX Handler that is called at the end of each XML element */
|
|
904 |
public void endElement(String uri, String localName, String qName)
|
|
905 |
throws SAXException
|
|
906 |
{
|
|
907 |
MetaCatUtil.debugMessage("End ELEMENT " + qName, 50);
|
|
908 |
|
|
909 |
if (localName.equals(INLINE) && handleInlineData) {
|
|
910 |
// Get the node from the stack
|
|
911 |
DBSAXNode currentNode = (DBSAXNode) nodeStack.pop();
|
|
912 |
String currentTag = currentNode.getTagName();
|
|
913 |
MetaCatUtil.debugMessage("End of inline data", 35);
|
|
914 |
// close file writer
|
|
915 |
try {
|
|
916 |
inlineDataFileWriter.close();
|
|
917 |
handleInlineData = false;
|
|
918 |
} catch (IOException ioe) {
|
|
919 |
throw new SAXException(ioe.getMessage());
|
|
920 |
}
|
|
921 |
|
|
922 |
//check if user changed inine data or not if user doesn't have
|
|
923 |
// write permission
|
|
924 |
if (startCriticalSubTree) {
|
|
925 |
NodeRecord node = null;
|
|
926 |
String inlineData;
|
|
927 |
try {
|
|
928 |
node = (NodeRecord) currentUnChangedableSubtreeNodeStack
|
|
929 |
.pop();
|
|
930 |
// get file name from db
|
|
931 |
String fileName = node.getNodeData();
|
|
932 |
MetaCatUtil.debugMessage("in handle inline data", 35);
|
|
933 |
MetaCatUtil.debugMessage(
|
|
934 |
"the inline data file name from node is: "
|
|
935 |
+ fileName, 40);
|
|
936 |
if (!compareInlineDataFiles(fileName, inlineDataFileName)) {
|
|
937 |
MetaCatUtil.debugMessage(
|
|
938 |
"inline data was changed by a user"
|
|
939 |
+ " who doesn't have permission", 30);
|
|
940 |
throw new SAXException(PERMISSIONERROR);
|
|
941 |
}
|
|
942 |
} catch (EmptyStackException ee) {
|
|
943 |
MetaCatUtil.debugMessage(
|
|
944 |
"the stack is empty for text data", 32);
|
|
945 |
throw new SAXException(PERMISSIONERROR);
|
|
946 |
} catch (McdbException eee) {
|
|
947 |
throw new SAXException(eee.getMessage());
|
|
948 |
} finally {
|
|
949 |
// delete the inline data file already in file system
|
|
950 |
deleteInlineDataFile(inlineDataFileName);
|
|
951 |
}
|
|
952 |
|
|
953 |
}//if
|
|
954 |
// write put inline data file name into text buffer (without path)
|
|
955 |
textBuffer = new StringBuffer(inlineDataFileName);
|
|
956 |
// write file name into db
|
|
957 |
endNodeId = writeTextForDBSAXNode(endNodeId, textBuffer,
|
|
958 |
currentNode);
|
|
959 |
// reset textbuff
|
|
960 |
textBuffer = null;
|
|
961 |
textBuffer = new StringBuffer();
|
|
962 |
return;
|
|
963 |
}
|
|
964 |
|
|
965 |
if (!handleInlineData) {
|
|
966 |
// Get the node from the stack
|
|
967 |
DBSAXNode currentNode = (DBSAXNode) nodeStack.pop();
|
|
968 |
String currentTag = currentNode.getTagName();
|
|
969 |
|
|
970 |
// If before the end element, the parser hit text nodes and store
|
|
971 |
// them
|
|
972 |
// into the buffer, write the buffer to data base. The reason we
|
|
973 |
// put
|
|
974 |
// write database here is for xerces some time split text node
|
|
975 |
if (hitTextNode) {
|
|
976 |
// get access value
|
|
977 |
String data = null;
|
|
978 |
// add principal
|
|
979 |
if (currentTag.equals(PRINCIPAL) && accessRule != null) {
|
|
980 |
data = (textBuffer.toString()).trim();
|
|
981 |
accessRule.addPrincipal(data);
|
|
982 |
|
|
983 |
} else if (currentTag.equals(PERMISSION) && accessRule != null) {
|
|
984 |
data = (textBuffer.toString()).trim();
|
|
985 |
// we conbine different a permission into one value
|
|
986 |
int permission = accessRule.getPermission();
|
|
987 |
// add permision
|
|
988 |
if (data.toUpperCase().equals(READSTRING)) {
|
|
989 |
permission = permission | READ;
|
|
990 |
} else if (data.toUpperCase().equals(WRITESTRING)) {
|
|
991 |
permission = permission | WRITE;
|
|
992 |
} else if (data.toUpperCase().equals(CHMODSTRING)) {
|
|
993 |
permission = permission | CHMOD;
|
|
994 |
} else if (data.toUpperCase().equals(ALLSTRING)) {
|
|
995 |
permission = permission | ALL;
|
|
996 |
}
|
|
997 |
accessRule.setPermission(permission);
|
|
998 |
}
|
|
999 |
// put additionalmetadata/describes into vector
|
|
1000 |
else if (currentTag.equals(DESCRIBES)) {
|
|
1001 |
data = (textBuffer.toString()).trim();
|
|
1002 |
describesId.add(data);
|
|
1003 |
} else if (currentTag.equals(REFERENCES)
|
|
1004 |
&& (processTopLeverAccess || processAdditionalAccess || processOtherAccess)) {
|
|
1005 |
// get reference
|
|
1006 |
data = (textBuffer.toString()).trim();
|
|
1007 |
// put reference id into accessSection
|
|
1008 |
accessObject.setReferences(data);
|
|
1009 |
|
|
1010 |
} else if (currentTag.equals(URL)) {
|
|
1011 |
//handle online data, make sure its'parent is online
|
|
1012 |
DBSAXNode parentNode = (DBSAXNode) nodeStack.peek();
|
|
1013 |
if (parentNode != null && parentNode.getTagName() != null
|
|
1014 |
&& parentNode.getTagName().equals(ONLINE)) {
|
|
1015 |
// if online data is in local metacat, add it to the
|
|
1016 |
// vector
|
|
1017 |
data = (textBuffer.toString()).trim();
|
|
1018 |
handleOnlineUrlDataFile(data);
|
|
1019 |
/*if (data != null
|
Made initial changes for accepting EML version 2.1.0 in Metacat