comparison software/eXist/mpdl-modules/src/de/mpg/mpiwg/berlin/mpdl/client/DocumentHandler.java @ 10:59ff47d1e237

TEI Unterst?tzung, Fehlerbehebungen, externe Objekte
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Fri, 11 Mar 2011 13:33:26 +0100
parents 2396a569e446
children 257f67be5c00
comparison
equal deleted inserted replaced
9:1ec29fdd0db8 10:59ff47d1e237
42 */ 42 */
43 public class DocumentHandler { 43 public class DocumentHandler {
44 private MpdlXmlRpcDocHandler mpdlXmlRpcDocHandler; 44 private MpdlXmlRpcDocHandler mpdlXmlRpcDocHandler;
45 private ESciDocIngestor eSciDocIngestor; 45 private ESciDocIngestor eSciDocIngestor;
46 46
47 private String[] docBases = {"archimedes", "echo"}; 47 private String[] docBases = {"archimedes", "echo", "tei"};
48 private String[] languages = {"ar", "de", "el", "en", "fr", "it", "la", "nl", "zh"}; 48 private String[] languages = {"ar", "de", "el", "en", "fr", "it", "la", "nl", "zh"};
49 private String documentRootCollectionMorph = "/db/mpdl/documents/morph"; 49 private String documentRootCollectionMorph = "/db/mpdl/documents/morph";
50 private String documentRootCollectionStandard = "/db/mpdl/documents/standard"; 50 private String documentRootCollectionStandard = "/db/mpdl/documents/standard";
51 private String presentationRootCollection = "/db/mpdl/presentation"; 51 private String presentationRootCollection = "/db/mpdl/presentation";
52 private String schemaRootCollection = "/db/mpdl/schema"; 52 private String schemaRootCollection = "/db/mpdl/schema";
280 String localFileDirStr = localDocumentDirectory + "/" + docBase + "/" + language; 280 String localFileDirStr = localDocumentDirectory + "/" + docBase + "/" + language;
281 File localFileDir = new File(localFileDirStr); 281 File localFileDir = new File(localFileDirStr);
282 FilenameFilter filter = new FilenameFilterExtension("xml"); 282 FilenameFilter filter = new FilenameFilterExtension("xml");
283 File[] files = localFileDir.listFiles(filter); 283 File[] files = localFileDir.listFiles(filter);
284 System.out.println("Adding all documents in path: \"" + localFileDirStr + "\" to eXist collection: \"" + documentCollection + "\" ..."); 284 System.out.println("Adding all documents in path: \"" + localFileDirStr + "\" to eXist collection: \"" + documentCollection + "\" ...");
285 for (int k=0; k < files.length; k++) { 285 if (files != null) {
286 File f = files[k]; 286 for (int k=0; k < files.length; k++) {
287 String localFileNameWithoutPath = f.getName(); 287 File f = files[k];
288 String fullLocalFileName = f.getPath(); 288 String localFileNameWithoutPath = f.getName();
289 String srcUrl = "file://" + fullLocalFileName; 289 String fullLocalFileName = f.getPath();
290 MpdlDocOperation docOperation = new MpdlDocOperation("updateExist", srcUrl, null, docBase, language, localFileNameWithoutPath); 290 String srcUrl = "file://" + fullLocalFileName;
291 long begin = new Date().getTime(); 291 MpdlDocOperation docOperation = new MpdlDocOperation("updateExist", srcUrl, null, docBase, language, localFileNameWithoutPath);
292 doOperation(docOperation); 292 long begin = new Date().getTime();
293 long end = new Date().getTime(); 293 doOperation(docOperation);
294 System.out.println("Added document \"" + fullLocalFileName + "\" to eXist collection: \"" + documentCollection + "\" (" + (end - begin) + " ms)" ); 294 long end = new Date().getTime();
295 counter++; 295 System.out.println("Added document \"" + fullLocalFileName + "\" to eXist collection: \"" + documentCollection + "\" (" + (end - begin) + " ms)" );
296 counter++;
297 }
296 } 298 }
297 } 299 }
298 } 300 }
299 System.out.println("Imported documents: " + counter); 301 System.out.println("Imported documents: " + counter);
300 } 302 }
309 String localFileDirStr = localDocumentDirectory + "/" + docBase + "/" + language; 311 String localFileDirStr = localDocumentDirectory + "/" + docBase + "/" + language;
310 File localFileDir = new File(localFileDirStr); 312 File localFileDir = new File(localFileDirStr);
311 FilenameFilter filter = new FilenameFilterExtension("xml"); 313 FilenameFilter filter = new FilenameFilterExtension("xml");
312 File[] files = localFileDir.listFiles(filter); 314 File[] files = localFileDir.listFiles(filter);
313 System.out.println("Generating Pdf/Html documents in path: \"" + localFileDirStr + "\" ..."); 315 System.out.println("Generating Pdf/Html documents in path: \"" + localFileDirStr + "\" ...");
314 for (int k=0; k < files.length; k++) { 316 if (files != null) {
315 File f = files[k]; 317 for (int k=0; k < files.length; k++) {
316 String localFileName = f.getName(); 318 File f = files[k];
317 String fullLocalFileName = f.getPath(); 319 String localFileName = f.getName();
318 String srcUrl = "file://" + fullLocalFileName; 320 String fullLocalFileName = f.getPath();
319 String localFileNameWithoutExtension = localFileName.substring(0, localFileName.length() - 4); // without ".xml" 321 String srcUrl = "file://" + fullLocalFileName;
320 String fullLocalPdfFileName = MpdlConstants.MPDL_EXIST_DATA_DIR + "/documents/" + docBase + "/" + language + "/" + localFileNameWithoutExtension + ".pdf"; 322 String localFileNameWithoutExtension = localFileName.substring(0, localFileName.length() - 4); // without ".xml"
321 File localPdfFile = new File(fullLocalPdfFileName); 323 String fullLocalPdfFileName = MpdlConstants.MPDL_EXIST_DATA_DIR + "/documents/" + docBase + "/" + language + "/" + localFileNameWithoutExtension + ".pdf";
322 boolean pdfFileAlreadyExists = localPdfFile.exists(); 324 File localPdfFile = new File(fullLocalPdfFileName);
323 // generate Pdf/Html file only if pdf file does not already exist 325 boolean pdfFileAlreadyExists = localPdfFile.exists();
324 if (! pdfFileAlreadyExists) { 326 // generate Pdf/Html file only if pdf file does not already exist
325 MpdlDocOperation docOperation = new MpdlDocOperation("generatePdf", srcUrl, null, docBase, language, localFileName); 327 if (! pdfFileAlreadyExists) {
326 SchemaHandler schemaHandler = new SchemaHandler(); 328 MpdlDocOperation docOperation = new MpdlDocOperation("generatePdf", srcUrl, null, docBase, language, localFileName);
327 schemaHandler.validate(fullLocalFileName, docOperation); 329 SchemaHandler schemaHandler = new SchemaHandler();
328 long begin = new Date().getTime(); 330 schemaHandler.validate(fullLocalFileName, docOperation);
329 MetadataRecord mdRecord = docOperation.getMdRecord(); // after validation, docOperation has a mdRecord 331 long begin = new Date().getTime();
330 mpdlRenderer.createFile(true, true, "text", mdRecord); // generate Pdf/Html document 332 MetadataRecord mdRecord = docOperation.getMdRecord(); // after validation, docOperation has a mdRecord
331 long end = new Date().getTime(); 333 mpdlRenderer.createFile(true, true, "text", mdRecord); // generate Pdf/Html document
332 System.out.println("Generate Pdf/Html document for: \"" + fullLocalFileName + "\" (" + (end - begin) + " ms)" ); 334 long end = new Date().getTime();
333 counter++; 335 System.out.println("Generate Pdf/Html document for: \"" + fullLocalFileName + "\" (" + (end - begin) + " ms)" );
334 try { 336 counter++;
335 Thread.sleep(60000); // delay so that called servers (digilib, eXist) are not stressed too much 337 try {
336 } catch (InterruptedException e) { 338 Thread.sleep(60000); // delay so that called servers (digilib, eXist) are not stressed too much
337 throw new ApplicationException(e); 339 } catch (InterruptedException e) {
340 throw new ApplicationException(e);
341 }
338 } 342 }
339 } 343 }
340 } 344 }
341 } 345 }
342 } 346 }