@@ -291,12 +291,14 @@ private String downnloadNoteResourcesAndFillXHTMLWithLocalImageLinks(
291291
292292 BufferedReader lineReader = null ;
293293 String result = SSStrU .empty ;
294- Resource resource ;
295- SSUri fileURI ;
296- String fileID ;
294+ SSUri fileURI = null ;
295+ String fileID = null ;
296+ Resource resource = null ;
297+ SSUri thumbnailURI ;
297298 String line ;
298299 String tmpLine ;
299300 String hash ;
301+ String mimeType ;
300302 int startIndex ;
301303 int endIndex1 ;
302304 int endIndex2 ;
@@ -331,25 +333,80 @@ private String downnloadNoteResourcesAndFillXHTMLWithLocalImageLinks(
331333 break ;
332334 }
333335
334- endIndex1 = tmpLine .indexOf ("</en-media>" );
335- endIndex2 = tmpLine .indexOf ("/>" );
336+ endIndex1 = tmpLine .indexOf ("</en-media>" , startIndex );
337+ endIndex2 = tmpLine .indexOf ("/>" , startIndex );
336338
337339 if (endIndex1 != -1 ){
338340 endIndex = endIndex1 ;
339341 }else {
340342 endIndex = endIndex2 ;
341343 }
342344
343- if (//application/pdf //application/vnd.openxmlformats-officedocument.presentationml.presentation //application/msword //application/vnd.openxmlformats-officedocument.wordprocessingml.document
344- !(tmpLine .contains ("type=\" " + SSMimeTypeU .imagePng + "\" " ) &&
345- endIndex > tmpLine .indexOf ("type=\" " + SSMimeTypeU .imagePng + "\" " )
346- ) &&
347- !(tmpLine .contains ("type=\" " + SSMimeTypeU .imageJpeg + "\" " ) &&
348- endIndex > tmpLine .indexOf ("type=\" " + SSMimeTypeU .imageJpeg + "\" " )
349- ) &&
350- !(tmpLine .contains ("type=\" " + SSMimeTypeU .imageGif + "\" " ) &&
351- endIndex > tmpLine .indexOf ("type=\" " + SSMimeTypeU .imageGif + "\" " )
352- )){
345+ mimeType = null ;
346+
347+ if (
348+ tmpLine .contains ("type=\" " + SSMimeTypeU .imageJpeg + "\" " ) &&
349+ endIndex > tmpLine .indexOf ("type=\" " + SSMimeTypeU .imageJpeg + "\" " )){
350+ mimeType = SSMimeTypeU .imageJpeg ;
351+ }
352+
353+ if (
354+ tmpLine .contains ("type=\" " + SSMimeTypeU .imagePng + "\" " ) &&
355+ endIndex > tmpLine .indexOf ("type=\" " + SSMimeTypeU .imagePng + "\" " )){
356+ mimeType = SSMimeTypeU .imagePng ;
357+ }
358+
359+ if (
360+ tmpLine .contains ("type=\" " + SSMimeTypeU .imageGif + "\" " ) &&
361+ endIndex > tmpLine .indexOf ("type=\" " + SSMimeTypeU .imageGif + "\" " )){
362+ mimeType = SSMimeTypeU .imageGif ;
363+ }
364+
365+ if (
366+ tmpLine .contains ("type=\" " + SSMimeTypeU .applicationPdf + "\" " ) &&
367+ endIndex > tmpLine .indexOf ("type=\" " + SSMimeTypeU .applicationPdf + "\" " )){
368+ mimeType = SSMimeTypeU .applicationPdf ;
369+ }
370+
371+ if (
372+ tmpLine .contains ("type=\" " + SSMimeTypeU .applicationMsword2007 + "\" " ) &&
373+ endIndex > tmpLine .indexOf ("type=\" " + SSMimeTypeU .applicationMsword2007 + "\" " )){
374+ mimeType = SSMimeTypeU .applicationMsword2007 ;
375+ }
376+
377+ if (
378+ tmpLine .contains ("type=\" " + SSMimeTypeU .applicationMsword + "\" " ) &&
379+ endIndex > tmpLine .indexOf ("type=\" " + SSMimeTypeU .applicationMsword + "\" " )){
380+ mimeType = SSMimeTypeU .applicationMsword ;
381+ }
382+
383+ if (
384+ tmpLine .contains ("type=\" " + SSMimeTypeU .applicationMspowerpoint2007 + "\" " ) &&
385+ endIndex > tmpLine .indexOf ("type=\" " + SSMimeTypeU .applicationMspowerpoint2007 + "\" " )){
386+ mimeType = SSMimeTypeU .applicationMspowerpoint2007 ;
387+ }
388+
389+ if (
390+ tmpLine .contains ("type=\" " + SSMimeTypeU .applicationMspowerpoint + "\" " ) &&
391+ endIndex > tmpLine .indexOf ("type=\" " + SSMimeTypeU .applicationMspowerpoint + "\" " )){
392+ mimeType = SSMimeTypeU .applicationMspowerpoint ;
393+ }
394+
395+ if (
396+ tmpLine .contains ("type=\" " + SSMimeTypeU .applicationMsexcel2007 + "\" " ) &&
397+ endIndex > tmpLine .indexOf ("type=\" " + SSMimeTypeU .applicationMsexcel2007 + "\" " )){
398+ mimeType = SSMimeTypeU .applicationMsexcel2007 ;
399+ }
400+
401+ if (
402+ tmpLine .contains ("type=\" " + SSMimeTypeU .applicationMsexcel + "\" " ) &&
403+ endIndex > tmpLine .indexOf ("type=\" " + SSMimeTypeU .applicationMsexcel + "\" " )){
404+ mimeType = SSMimeTypeU .applicationMsexcel ;
405+ }
406+
407+ if (mimeType == null ){
408+
409+ SSLogU .warn ("no / unknown mime type set in:" + tmpLine );
353410
354411 if (endIndex == endIndex1 ){
355412 result += tmpLine .substring (0 , endIndex + 11 );
@@ -378,33 +435,89 @@ private String downnloadNoteResourcesAndFillXHTMLWithLocalImageLinks(
378435 continue ;
379436 }
380437
381- hashEndIndex = tmpLine .indexOf ("\" " , hashIndex + 6 );
382- hash = tmpLine .substring (hashIndex + 6 , hashEndIndex );
438+ if (
439+ !SSStrU .equals (mimeType , SSMimeTypeU .applicationMsword2007 ) &&
440+ !SSStrU .equals (mimeType , SSMimeTypeU .applicationMsword ) &&
441+ !SSStrU .equals (mimeType , SSMimeTypeU .applicationMspowerpoint2007 ) &&
442+ !SSStrU .equals (mimeType , SSMimeTypeU .applicationMspowerpoint ) &&
443+ !SSStrU .equals (mimeType , SSMimeTypeU .applicationMsexcel2007 ) &&
444+ !SSStrU .equals (mimeType , SSMimeTypeU .applicationMsexcel )){
445+
446+ hashEndIndex = tmpLine .indexOf ("\" " , hashIndex + 6 );
447+ hash = tmpLine .substring (hashIndex + 6 , hashEndIndex );
448+ fileURI = SSServCaller .vocURICreate (SSFileExtE .valueOf (SSMimeTypeU .fileExtForMimeType (mimeType )));
449+ fileID = SSServCaller .fileIDFromURI (user , fileURI );
450+
451+ resource =
452+ SSServCaller .evernoteResourceByHashGet (
453+ user ,
454+ noteStore ,
455+ note .getGuid (),
456+ hash );
457+
458+ SSFileU .writeFileBytes (
459+ new FileOutputStream (localWorkPath + fileID ),
460+ resource .getData ().getBody (),
461+ resource .getData ().getSize ());
462+ }
383463
384- // if(hashsPerFileURIs.containsKey(hash)){
385- // fileURI = hashsPerFileURIs.get(hash);
464+ result += tmpLine .substring (0 , startIndex );
386465
387- // fileID = SSServCaller.fileIDFromURI(user, fileURI);
388- // }else{
389- fileURI = SSServCaller .vocURICreate (SSFileExtE .png );
390- fileID = SSServCaller .fileIDFromURI (user , fileURI );
466+ if (SSStrU .equals (mimeType , SSMimeTypeU .applicationPdf )){
467+ thumbnailURI = SSDataImportEvernoteThumbHelper .createThumbnail (user , localWorkPath , fileURI , 500 , 500 );
468+ fileID = SSServCaller .fileIDFromURI (user , thumbnailURI );
469+
470+ result +=
471+ "<div>Included PDF (preview):</div>" +
472+ "<img width=\" " +
473+ 500 +
474+ "\" height=\" " +
475+ 500 +
476+ "\" class=\" xmyImagex\" src=\" " +
477+ localWorkPath + fileID +
478+ "\" />" ;
479+ }
391480
392- // hashsPerFileURIs.put(hash, fileURI);
481+ if (
482+ resource != null &&
483+ !SSStrU .equals (mimeType , SSMimeTypeU .applicationPdf ) &&
484+ !SSStrU .equals (mimeType , SSMimeTypeU .applicationMsword2007 ) &&
485+ !SSStrU .equals (mimeType , SSMimeTypeU .applicationMsword ) &&
486+ !SSStrU .equals (mimeType , SSMimeTypeU .applicationMspowerpoint2007 ) &&
487+ !SSStrU .equals (mimeType , SSMimeTypeU .applicationMspowerpoint ) &&
488+ !SSStrU .equals (mimeType , SSMimeTypeU .applicationMsexcel2007 ) &&
489+ !SSStrU .equals (mimeType , SSMimeTypeU .applicationMsexcel )){
393490
394- resource =
395- SSServCaller .evernoteResourceByHashGet (
396- user ,
397- noteStore ,
398- note .getGuid (),
399- hash );
491+ result +=
492+ "<img width=\" " +
493+ resource .getWidth () +
494+ "\" height=\" " +
495+ resource .getHeight () +
496+ "\" class=\" xmyImagex\" src=\" " +
497+ localWorkPath + fileID +
498+ "\" />" ;
499+ }
400500
401- SSFileU .writeFileBytes (
402- new FileOutputStream (localWorkPath + fileID ),
403- resource .getData ().getBody (),
404- resource .getData ().getSize ());
405- // }
501+ if (
502+ SSStrU .equals (mimeType , SSMimeTypeU .applicationMsword ) ||
503+ SSStrU .equals (mimeType , SSMimeTypeU .applicationMsword2007 )){
504+
505+ result += "<div>Includes Microsoft Office Document (no preview available)</div>" ;
506+ }
507+
508+ if (
509+ SSStrU .equals (mimeType , SSMimeTypeU .applicationMspowerpoint ) ||
510+ SSStrU .equals (mimeType , SSMimeTypeU .applicationMspowerpoint2007 )){
511+
512+ result += "<div>Includes Microsoft Office Powerpoint Document (no preview available)</div>" ;
513+ }
406514
407- result += tmpLine .substring (0 , startIndex ) + "<img width=\" " + resource .getWidth () + "\" height=\" " + resource .getHeight () + "\" class=\" xmyImagex\" src=\" " + localWorkPath + fileID + "\" />" ;
515+ if (
516+ SSStrU .equals (mimeType , SSMimeTypeU .applicationMsexcel ) ||
517+ SSStrU .equals (mimeType , SSMimeTypeU .applicationMsexcel2007 )){
518+
519+ result += "<div>Includes Microsoft Office Excel Document (no preview available)</div>" ;
520+ }
408521
409522 if (endIndex == endIndex1 ){
410523 tmpLine = tmpLine .substring (endIndex + 11 , tmpLine .length ());
@@ -414,7 +527,7 @@ private String downnloadNoteResourcesAndFillXHTMLWithLocalImageLinks(
414527 }
415528
416529 result += tmpLine ;
417- result += SSStrU .backslashN ;
530+ result += SSStrU .backslashRBackslashN ;
418531 }
419532
420533 return result .replace ("&nbsp;" , SSStrU .empty ).replace ("Â" , SSStrU .empty ).trim ();
0 commit comments