comparison software/eXist/mpdl-modules/src/de/mpg/mpiwg/berlin/mpdl/externalObjects/app/ExternalObjectsHandler.java @ 9:1ec29fdd0db8

neue .lex Dateien f?r Normalisierung / externe Objekte update
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Tue, 22 Feb 2011 16:03:45 +0100
parents 2396a569e446
children 59ff47d1e237
comparison
equal deleted inserted replaced
8:d2a1c14fde31 9:1ec29fdd0db8
8 import com.sleepycat.je.Database; 8 import com.sleepycat.je.Database;
9 import com.sleepycat.je.DatabaseEntry; 9 import com.sleepycat.je.DatabaseEntry;
10 import com.sleepycat.je.DatabaseException; 10 import com.sleepycat.je.DatabaseException;
11 import com.sleepycat.je.LockMode; 11 import com.sleepycat.je.LockMode;
12 import com.sleepycat.je.OperationStatus; 12 import com.sleepycat.je.OperationStatus;
13 13 import com.sleepycat.je.Transaction;
14
15 import de.mpg.mpiwg.berlin.mpdl.util.StringUtilEscapeChars;
14 import de.mpg.mpiwg.berlin.mpdl.util.Util; 16 import de.mpg.mpiwg.berlin.mpdl.util.Util;
15 import de.mpg.mpiwg.berlin.mpdl.exception.ApplicationException; 17 import de.mpg.mpiwg.berlin.mpdl.exception.ApplicationException;
16 import de.mpg.mpiwg.berlin.mpdl.externalObjects.db.DbEnvExternalObjects; 18 import de.mpg.mpiwg.berlin.mpdl.externalObjects.db.DbEnvExternalObjects;
17 import de.mpg.mpiwg.berlin.mpdl.general.MpdlConstants; 19 import de.mpg.mpiwg.berlin.mpdl.general.MpdlConstants;
18 20
30 instance.init(); 32 instance.init();
31 } 33 }
32 return instance; 34 return instance;
33 } 35 }
34 36
35 public ArrayList<ExtElement> readExternalElements(String documentId, String pageNumber) throws ApplicationException { 37 public void createExternalElement(ExtElement element) throws ApplicationException {
36 return readDBExternalElements(documentId, pageNumber); 38 createDBExternalElement(element);
37 } 39 }
38 40
39 public void writeExternalElement(ExtElement element) throws ApplicationException { 41 public void updateExternalElement(ExtElement element) throws ApplicationException {
40 writeDBExternalElement(element); 42 updateDBExternalElement(element);
41 } 43 }
42 44
43 public void deleteExternalElement(ExtElement element) throws ApplicationException { 45 public void deleteExternalElement(ExtElement element) throws ApplicationException {
44 deleteDBExternalElement(element); 46 deleteDBExternalElement(element);
45 } 47 }
46 48
47 private void writeDBExternalElement(ExtElement element) throws ApplicationException { 49 public ArrayList<ExtElement> readExternalElements(ExtElement element) throws ApplicationException {
48 try { 50 return readDBExternalElements(element);
49 String keyStr = element.getDocumentId() + "###" + element.getPageNumber(); 51 }
52
53 public void createExternalObject(ExtObject object) throws ApplicationException {
54 createDBExternalObject(object);
55 }
56
57 public void updateExternalObject(ExtObject object) throws ApplicationException {
58 updateDBExternalObject(object);
59 }
60
61 public void deleteExternalObject(ExtObject object) throws ApplicationException {
62 deleteDBExternalObject(object);
63 }
64
65 public ArrayList<ExtObject> readExternalObjects(ExtObject object) throws ApplicationException {
66 return readDBExternalObjects(object);
67 }
68
69 private void createDBExternalElement(ExtElement element) throws ApplicationException {
70 try {
71 test(element);
72 String content = element.getContent();
50 String valueStr = element.getXmlString(); 73 String valueStr = element.getXmlString();
74 if (content == null)
75 throw new ApplicationException("External object: no content element specified in: " + valueStr);
76 Date now = new Date();
77 element.setModificationDate(now);
78 String docId = element.getDocumentId();
79 String pageNumber = element.getPageNumber();
80 String keyStr = docId + "###" + pageNumber;
51 DatabaseEntry dbEntryKey = new DatabaseEntry(keyStr.getBytes("utf-8")); 81 DatabaseEntry dbEntryKey = new DatabaseEntry(keyStr.getBytes("utf-8"));
52 DatabaseEntry dbEntryValue = new DatabaseEntry(valueStr.getBytes("utf-8")); 82 DatabaseEntry dbEntryValue = new DatabaseEntry(valueStr.getBytes("utf-8"));
53 Database elementDB = dbEnvExternalObjects.getElementDB(); 83 Database elementDB = dbEnvExternalObjects.getElementDB();
54 elementDB.put(null, dbEntryKey, dbEntryValue); 84 elementDB.put(null, dbEntryKey, dbEntryValue);
55 } catch (DatabaseException e) { 85 } catch (DatabaseException e) {
57 } catch (UnsupportedEncodingException e) { 87 } catch (UnsupportedEncodingException e) {
58 throw new ApplicationException(e); 88 throw new ApplicationException(e);
59 } 89 }
60 } 90 }
61 91
92 private void updateDBExternalElement(ExtElement element) throws ApplicationException {
93 test(element);
94 String content = element.getContent();
95 String elementXmlStr = element.getXmlString();
96 if (content == null)
97 throw new ApplicationException("External object: no content element specified in: " + elementXmlStr);
98 Date now = new Date();
99 element.setModificationDate(now);
100 String docId = element.getDocumentId();
101 String pageNumber = element.getPageNumber();
102 String uid = element.getUid();
103 String xmlNodeId = element.getXmlNodeId();
104 String hashKey = docId + "###" + pageNumber;
105 boolean updated = false;
106 try {
107 Database elementDB = dbEnvExternalObjects.getElementDB();
108 Transaction t = dbEnvExternalObjects.getEnv().beginTransaction(null, null);
109 Cursor cursor = elementDB.openCursor(t, null);
110 byte[] bHashKey = hashKey.getBytes("utf-8");
111 DatabaseEntry dbEntryKey = new DatabaseEntry(bHashKey);
112 DatabaseEntry foundValue = new DatabaseEntry();
113 OperationStatus operationStatus = cursor.getSearchKey(dbEntryKey, foundValue, LockMode.DEFAULT);
114 while (operationStatus == OperationStatus.SUCCESS && ! updated) {
115 byte[] foundValueBytes = foundValue.getData();
116 String foundValueStr = new String(foundValueBytes, "utf-8");
117 ExtElement elem = ExtElement.parseXmlStr(foundValueStr);
118 String elemUid = elem.getUid();
119 String elemXmlNodeId = elem.getXmlNodeId();
120 if (uid.equals(elemUid) && xmlNodeId.equals(elemXmlNodeId)) {
121 cursor.delete();
122 byte[] elementXmlStrBytes = elementXmlStr.getBytes("utf-8");
123 DatabaseEntry dbEntryValue = new DatabaseEntry(elementXmlStrBytes);
124 cursor.put(dbEntryKey, dbEntryValue);
125 updated = true;
126 break;
127 }
128 operationStatus = cursor.getNextDup(dbEntryKey, foundValue, LockMode.DEFAULT);
129 }
130 cursor.close();
131 t.commit();
132 } catch (DatabaseException e) {
133 throw new ApplicationException(e);
134 } catch (UnsupportedEncodingException e) {
135 throw new ApplicationException(e);
136 }
137 }
138
62 private void deleteDBExternalElement(ExtElement element) throws ApplicationException { 139 private void deleteDBExternalElement(ExtElement element) throws ApplicationException {
63 try { 140 test(element);
64 String keyStr = element.getDocumentId() + "###" + element.getPageNumber(); 141 String docId = element.getDocumentId();
65 DatabaseEntry dbEntryKey = new DatabaseEntry(keyStr.getBytes("utf-8")); 142 String pageNumber = element.getPageNumber();
143 String uid = element.getUid();
144 String xmlNodeId = element.getXmlNodeId();
145 String hashKey = docId + "###" + pageNumber;
146 try {
66 Database elementDB = dbEnvExternalObjects.getElementDB(); 147 Database elementDB = dbEnvExternalObjects.getElementDB();
67 elementDB.delete(null, dbEntryKey); 148 Transaction t = dbEnvExternalObjects.getEnv().beginTransaction(null, null);
68 } catch (DatabaseException e) { 149 Cursor cursor = elementDB.openCursor(t, null);
69 throw new ApplicationException(e); 150 byte[] bHashKey = hashKey.getBytes("utf-8");
70 } catch (UnsupportedEncodingException e) { 151 DatabaseEntry dbEntryKey = new DatabaseEntry(bHashKey);
71 throw new ApplicationException(e); 152 DatabaseEntry foundValue = new DatabaseEntry();
72 } 153 OperationStatus operationStatus = cursor.getSearchKey(dbEntryKey, foundValue, LockMode.DEFAULT);
73 } 154 while (operationStatus == OperationStatus.SUCCESS) {
74 155 byte[] foundValueBytes = foundValue.getData();
75 private ArrayList<ExtElement> readDBExternalElements(String documentId, String pageNumber) throws ApplicationException { 156 String foundValueStr = new String(foundValueBytes, "utf-8");
157 ExtElement elem = ExtElement.parseXmlStr(foundValueStr);
158 String elemUid = elem.getUid();
159 String elemXmlNodeId = elem.getXmlNodeId();
160 if (uid.equals(elemUid) && xmlNodeId.equals(elemXmlNodeId)) {
161 cursor.delete();
162 }
163 operationStatus = cursor.getNextDup(dbEntryKey, foundValue, LockMode.DEFAULT);
164 }
165 cursor.close();
166 t.commit();
167 } catch (DatabaseException e) {
168 throw new ApplicationException(e);
169 } catch (UnsupportedEncodingException e) {
170 throw new ApplicationException(e);
171 }
172 }
173
174 private ArrayList<ExtElement> readDBExternalElements(ExtElement element) throws ApplicationException {
76 ArrayList<ExtElement> retElements = new ArrayList<ExtElement>(); 175 ArrayList<ExtElement> retElements = new ArrayList<ExtElement>();
176 String documentId = element.getDocumentId();
177 String pageNumber = element.getPageNumber();
77 String hashKey = documentId + "###" + pageNumber; 178 String hashKey = documentId + "###" + pageNumber;
78 try { 179 try {
79 Database elementDB = dbEnvExternalObjects.getElementDB(); 180 Database elementDB = dbEnvExternalObjects.getElementDB();
80 Cursor cursor = elementDB.openCursor(null, null); 181 Cursor cursor = elementDB.openCursor(null, null);
81 byte[] bHashKey = hashKey.getBytes("utf-8"); 182 byte[] bHashKey = hashKey.getBytes("utf-8");
96 throw new ApplicationException(e); 197 throw new ApplicationException(e);
97 } 198 }
98 return retElements; 199 return retElements;
99 } 200 }
100 201
202 private void test(ExtElement element) throws ApplicationException {
203 String uid = element.getUid();
204 String docId = element.getDocumentId();
205 String xmlNodeId = element.getXmlNodeId();
206 String pageNumber = element.getPageNumber();
207 String xmlStr = element.getXmlString();
208 if (uid == null)
209 throw new ApplicationException("External object: no attribute \"uid\" specified in: " + xmlStr);
210 if (docId == null)
211 throw new ApplicationException("External object: no attribute \"documentId\" specified in: " + xmlStr);
212 if (xmlNodeId == null)
213 throw new ApplicationException("External object: no attribute \"xmlNodeId\" specified in: " + xmlStr);
214 if (pageNumber == null)
215 throw new ApplicationException("External object: no attribute \"pageNumber\" specified in: " + xmlStr);
216 }
217
218 private void createDBExternalObject(ExtObject extObject) throws ApplicationException {
219 try {
220 test(extObject);
221 Date now = new Date();
222 extObject.setModificationDate(now);
223 String type = extObject.getType();
224 String uid = extObject.getUid();
225 String docId = extObject.getDocumentId();
226 if (docId == null || docId.isEmpty())
227 docId = "-1";
228 String keyStr = type + "###" + uid + "###" + docId;
229 String valueStr = extObject.getXmlString();
230 DatabaseEntry dbEntryKey = new DatabaseEntry(keyStr.getBytes("utf-8"));
231 DatabaseEntry dbEntryValue = new DatabaseEntry(valueStr.getBytes("utf-8"));
232 Database objectDB = dbEnvExternalObjects.getObjectDB();
233 objectDB.put(null, dbEntryKey, dbEntryValue);
234 } catch (DatabaseException e) {
235 throw new ApplicationException(e);
236 } catch (UnsupportedEncodingException e) {
237 throw new ApplicationException(e);
238 }
239 }
240
241 private void updateDBExternalObject(ExtObject object) throws ApplicationException {
242 test(object);
243 String content = object.getContent();
244 String elementXmlStr = object.getXmlString();
245 if (content == null)
246 throw new ApplicationException("External object: no content element specified in: " + elementXmlStr);
247 Date modificationDate = object.getModificationDate();
248 Date now = new Date();
249 object.setModificationDate(now);
250 String type = object.getType();
251 String uid = object.getUid();
252 String docId = object.getDocumentId();
253 String hashKey = type + "###" + uid + "###" + docId;
254 boolean updated = false;
255 try {
256 Database objectDB = dbEnvExternalObjects.getObjectDB();
257 Transaction t = dbEnvExternalObjects.getEnv().beginTransaction(null, null);
258 Cursor cursor = objectDB.openCursor(t, null);
259 byte[] bHashKey = hashKey.getBytes("utf-8");
260 DatabaseEntry dbEntryKey = new DatabaseEntry(bHashKey);
261 DatabaseEntry foundValue = new DatabaseEntry();
262 OperationStatus operationStatus = cursor.getSearchKey(dbEntryKey, foundValue, LockMode.DEFAULT);
263 while (operationStatus == OperationStatus.SUCCESS && ! updated) {
264 byte[] foundValueBytes = foundValue.getData();
265 String foundValueStr = new String(foundValueBytes, "utf-8");
266 ExtObject obj = object.getInstance(foundValueStr);
267 Date objModificationDate = obj.getModificationDate();
268 if (modificationDate.equals(objModificationDate)) {
269 cursor.delete();
270 byte[] elementXmlStrBytes = elementXmlStr.getBytes("utf-8");
271 DatabaseEntry dbEntryValue = new DatabaseEntry(elementXmlStrBytes);
272 cursor.put(dbEntryKey, dbEntryValue);
273 updated = true;
274 break;
275 }
276 operationStatus = cursor.getNextDup(dbEntryKey, foundValue, LockMode.DEFAULT);
277 }
278 cursor.close();
279 t.commit();
280 } catch (DatabaseException e) {
281 throw new ApplicationException(e);
282 } catch (UnsupportedEncodingException e) {
283 throw new ApplicationException(e);
284 }
285 }
286
287 private void deleteDBExternalObject(ExtObject object) throws ApplicationException {
288 test(object);
289 Date modificationDate = object.getModificationDate();
290 Date now = new Date();
291 object.setModificationDate(now);
292 String type = object.getType();
293 String uid = object.getUid();
294 String docId = object.getDocumentId();
295 String hashKey = type + "###" + uid + "###" + docId;
296 try {
297 Database objectDB = dbEnvExternalObjects.getObjectDB();
298 Transaction t = dbEnvExternalObjects.getEnv().beginTransaction(null, null);
299 Cursor cursor = objectDB.openCursor(t, null);
300 byte[] bHashKey = hashKey.getBytes("utf-8");
301 DatabaseEntry dbEntryKey = new DatabaseEntry(bHashKey);
302 DatabaseEntry foundValue = new DatabaseEntry();
303 OperationStatus operationStatus = cursor.getSearchKey(dbEntryKey, foundValue, LockMode.DEFAULT);
304 while (operationStatus == OperationStatus.SUCCESS) {
305 byte[] foundValueBytes = foundValue.getData();
306 String foundValueStr = new String(foundValueBytes, "utf-8");
307 ExtObject obj = object.getInstance(foundValueStr);
308 Date objModificationDate = obj.getModificationDate();
309 if (modificationDate == null || modificationDate.equals(objModificationDate)) {
310 cursor.delete();
311 }
312 operationStatus = cursor.getNextDup(dbEntryKey, foundValue, LockMode.DEFAULT);
313 }
314 cursor.close();
315 t.commit();
316 } catch (DatabaseException e) {
317 throw new ApplicationException(e);
318 } catch (UnsupportedEncodingException e) {
319 throw new ApplicationException(e);
320 }
321 }
322
323 private ArrayList<ExtObject> readDBExternalObjects(ExtObject object) throws ApplicationException {
324 ArrayList<ExtObject> retElements = new ArrayList<ExtObject>();
325 String type = object.getType();
326 String uid = object.getUid();
327 String docId = object.getDocumentId();
328 String hashKey = type + "###" + uid + "###" + docId;
329 try {
330 Database objectDB = dbEnvExternalObjects.getObjectDB();
331 Cursor cursor = objectDB.openCursor(null, null);
332 byte[] bHashKey = hashKey.getBytes("utf-8");
333 DatabaseEntry dbEntryKey = new DatabaseEntry(bHashKey);
334 DatabaseEntry foundValue = new DatabaseEntry();
335 OperationStatus operationStatus = cursor.getSearchKey(dbEntryKey, foundValue, LockMode.DEFAULT);
336 while (operationStatus == OperationStatus.SUCCESS) {
337 byte[] foundValueBytes = foundValue.getData();
338 String foundValueStr = new String(foundValueBytes, "utf-8");
339 ExtObject obj = object.getInstance(foundValueStr);
340 retElements.add(obj);
341 operationStatus = cursor.getNextDup(dbEntryKey, foundValue, LockMode.DEFAULT);
342 }
343 cursor.close();
344 } catch (DatabaseException e) {
345 throw new ApplicationException(e);
346 } catch (UnsupportedEncodingException e) {
347 throw new ApplicationException(e);
348 }
349 return retElements;
350 }
351
352 private void test(ExtObject object) throws ApplicationException {
353 String uid = object.getUid();
354 String xmlStr = object.getXmlString();
355 if (uid == null)
356 throw new ApplicationException("External object: no attribute \"uid\" specified in: " + xmlStr);
357 }
358
359
360
101 private void init() throws ApplicationException { 361 private void init() throws ApplicationException {
102 dbEnvExternalObjects = new DbEnvExternalObjects(); 362 dbEnvExternalObjects = new DbEnvExternalObjects();
103 dbEnvExternalObjects.setDataDir(DB_DIR_EXTERNAL_OBJECTS); 363 dbEnvExternalObjects.setDataDir(DB_DIR_EXTERNAL_OBJECTS);
104 dbEnvExternalObjects.init(); 364 dbEnvExternalObjects.init();
105 dbEnvExternalObjects.openDatabases(); 365 dbEnvExternalObjects.openDatabases();
107 367
108 public static void main(String[] args) throws ApplicationException { 368 public static void main(String[] args) throws ApplicationException {
109 getInstance(); 369 getInstance();
110 instance.beginOperation(); 370 instance.beginOperation();
111 System.out.print("Start ..."); 371 System.out.print("Start ...");
112 // instance.deleteSampleData(); 372 instance.deleteSampleData();
113 // instance.writeSampleData(); 373 instance.createSampleData();
374 // instance.updateSampleData();
114 instance.readSampleData(); 375 instance.readSampleData();
115 instance.end(); 376 instance.end();
116 instance.endOperation(); 377 instance.endOperation();
117 Double elapsedTime = new Util().getSecondWithMillisecondsBetween(instance.beginOfOperation, instance.endOfOperation); 378 Double elapsedTime = new Util().getSecondWithMillisecondsBetween(instance.beginOfOperation, instance.endOfOperation);
118 System.out.println("End."); 379 System.out.println("End.");
119 System.out.println("Needed time: " + elapsedTime + " seconds"); 380 System.out.println("Needed time: " + elapsedTime + " seconds");
120 } 381 }
121 382
122 private void deleteSampleData() throws ApplicationException { 383 private void deleteSampleData() throws ApplicationException {
123 ExtElement e = new ExtElement(); 384 String xmlNodeId1 = "/archimedes[1]/text[1]/body[1]/chap[1]/p[1]/s[2]";
124 e.setUid("joe"); 385 String objectXmlStr1 =
125 e.setDocumentId("/archimedes/it/l223.xml"); 386 "<object type=\"" + "element" + "\" " +
126 e.setPageNumber("17"); 387 "uid=\"" + "joe" + "\" " +
127 deleteExternalElement(e); 388 "documentId=\"" + "/archimedes/it/l223.xml" + "\" " +
128 } 389 "pageNumber=\"" + "17" + "\" " +
129 390 "xmlNodeId=\"" + xmlNodeId1 + "\"" +
130 private void writeSampleData() throws ApplicationException { 391 ">" +
392 "</object>";
393 ExtElement e1 = ExtElement.parseXmlStr(objectXmlStr1);
394 String xmlNodeId2 = "/archimedes[1]/text[1]/body[1]/chap[1]/p[1]/s[4]";
395 String objectXmlStr2 =
396 "<object type=\"" + "element" + "\" " +
397 "uid=\"" + "michael" + "\" " +
398 "documentId=\"" + "/archimedes/it/l223.xml" + "\" " +
399 "pageNumber=\"" + "17" + "\" " +
400 "xmlNodeId=\"" + xmlNodeId2 + "\"" +
401 ">" +
402 "</object>";
403 ExtElement e2 = ExtElement.parseXmlStr(objectXmlStr2);
404 deleteExternalElement(e1);
405 deleteExternalElement(e2);
406
407 ExtQuery q = new ExtQuery();
408 q.setUid("joe");
409 q.setDocumentId("/archimedes/it/l223.xml");
410 ArrayList<ExtObject> objects = readExternalObjects(q);
411 for (int i=0; i<objects.size(); i++) {
412 ExtObject o = objects.get(i);
413 deleteExternalObject(o);
414 }
415
416 ExtQuery q2 = new ExtQuery();
417 q2.setUid("michael");
418 q2.setDocumentId("/archimedes/it/l223.xml");
419 objects = readExternalObjects(q2);
420 for (int i=0; i<objects.size(); i++) {
421 ExtObject o = objects.get(i);
422 deleteExternalObject(o);
423 }
424 }
425
426 private void createSampleData() throws ApplicationException {
131 Date now = new Date(); 427 Date now = new Date();
132 428
133 String sId = "1.2.2.2.2.5"; 429 String sId = "/archimedes[1]/text[1]/body[1]/chap[1]/p[1]/s[2]";
134 ExtElement e = new ExtElement(); 430 ExtElement e = new ExtElement();
135 e.setUid("joe"); 431 e.setUid("joe");
136 e.setModificationDate(now); 432 e.setModificationDate(now);
137 e.setDocumentId("/archimedes/it/l223.xml"); 433 e.setDocumentId("/archimedes/it/l223.xml");
138 e.setPageNumber("17"); 434 e.setPageNumber("17");
139 e.setXmlNodeId(sId); 435 e.setXmlNodeId(sId);
140 e.setContent("<note>This is a test note to sentence " + sId + "</note>"); 436 e.setContent("<note>This is a test note to element " + sId + " with <seg xlink:href=\"http://slime.de\">this external link</seg>" + "</note>");
141 writeExternalElement(e); 437 createExternalElement(e);
142 438
143 ExtElement e2 = new ExtElement(); 439 ExtElement e2 = new ExtElement();
144 String sId2 = "1.2.2.2.2.7"; 440 String sId2 = "/archimedes[1]/text[1]/body[1]/chap[1]/p[1]/s[4]";
145 e2.setUid("michael"); 441 e2.setUid("michael");
146 e2.setModificationDate(now); 442 e2.setModificationDate(now);
147 e2.setDocumentId("/archimedes/it/l223.xml"); 443 e2.setDocumentId("/archimedes/it/l223.xml");
148 e2.setPageNumber("17"); 444 e2.setPageNumber("17");
149 e2.setXmlNodeId(sId2); 445 e2.setXmlNodeId(sId2);
150 e2.setCharPos("18"); 446 e2.setCharPos("18");
151 e2.setContent("<note>This is a test note to sentence " + sId2 + "</note>"); 447 e2.setContent("<note>This is a test note to element " + sId2 + "</note>");
152 writeExternalElement(e2); 448 createExternalElement(e2);
153 449
154 /* 450 ExtQuery q1 = new ExtQuery();
155 String sId3 = "1.2.2.2.2.8.15.3.3"; 451 q1.setUid("joe");
156 e3.setUid("joe"); 452 q1.setDocumentId("/archimedes/it/l223.xml");
157 e3.setModificationDate(now); 453 q1.setQueryType("fulltext");
158 e3.setDocumentId("/archimedes/it/l223.xml"); 454 q1.setQueryName("seminario");
159 e3.setPageNumber("17"); 455 createExternalObject(q1);
160 e3.setXmlNodeId(sId3); 456
161 e2.setContent("<note>This is an external test note to sentence " + sId3 + "</note>"); 457 ExtQuery q2 = new ExtQuery();
162 writeExternalElement(e3); 458 q2.setUid("michael");
163 */ 459 q2.setDocumentId("/archimedes/it/l223.xml");
164 460 q2.setQueryType("url");
165 } 461 String url = "http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/page-query-result.xql?document=/archimedes/it/l223.xml&pn=17&mode=text&query-type=fulltextMorph&query=seminario&query-result-pn=1";
166 462 String urlDeresolved = StringUtilEscapeChars.deresolveXmlEntities(url);
463 q2.setQueryName(urlDeresolved);
464 createExternalObject(q2);
465
466 }
467
468 private void updateSampleData() throws ApplicationException {
469 Date now = new Date();
470 String xmlNodeId = "/archimedes[1]/text[1]/body[1]/chap[1]/p[1]/s[2]";
471 String objectXmlStr =
472 "<object type=\"" + "element" + "\" " +
473 "uid=\"" + "joe" + "\" " +
474 "documentId=\"" + "/archimedes/it/l223.xml" + "\" " +
475 "pageNumber=\"" + "17" + "\" " +
476 "xmlNodeId=\"" + xmlNodeId + "\"" +
477 ">" +
478 "<content>" + "<note>This is a test note to element " + xmlNodeId + " with <seg xlink:href=\"http://slime.de\">this external link</seg>" + "</note>" + "</content>" +
479 "</object>";
480 ExtElement e = ExtElement.parseXmlStr(objectXmlStr);
481 e.setModificationDate(now);
482 updateExternalElement(e);
483 }
484
167 private void readSampleData() throws ApplicationException { 485 private void readSampleData() throws ApplicationException {
168 ArrayList<ExtElement> elements = readExternalElements("/archimedes/it/l223.xml", "17"); 486 ExtElement elem = new ExtElement();
487 elem.setDocumentId("/archimedes/it/l223.xml");
488 elem.setPageNumber("17");
489 ArrayList<ExtElement> elements = readExternalElements(elem);
169 System.out.println(elements); 490 System.out.println(elements);
491
492 ExtQuery q1 = new ExtQuery();
493 q1.setUid("joe");
494 q1.setDocumentId("/archimedes/it/l223.xml");
495 ArrayList<ExtObject> objects = readExternalObjects(q1);
496 System.out.println(objects);
497
498 ExtQuery q2 = new ExtQuery();
499 q2.setUid("michael");
500 q2.setDocumentId("/archimedes/it/l223.xml");
501 objects = readExternalObjects(q2);
502 System.out.println(objects);
170 } 503 }
171 504
172 private void end() throws ApplicationException { 505 private void end() throws ApplicationException {
173 dbEnvExternalObjects.close(); 506 dbEnvExternalObjects.close();
174 } 507 }