├── .classpath ├── .gitignore ├── .project ├── CHANGELOG ├── INSTALL ├── LICENSE.TXT ├── README.md ├── build.properties.template ├── build.xml ├── lib ├── ScratchApplet.jar ├── ant │ ├── ant.jar │ ├── junit-3.jar │ ├── junit-4.10.jar │ ├── junit-4.8.1.jar │ ├── junit-4.8.2.jar │ ├── junit_license.html │ ├── tlddoc.jar │ ├── unitth-1.3.1.jar │ └── xmltask.jar ├── jodconverter3 │ ├── LICENSE.txt │ ├── commons-cli-1.1.jar │ ├── commons-io-1.4.jar │ ├── jodconverter-core-3.0-beta-3_r220.jar │ ├── json-20090211.jar │ ├── juh-3.2.1.jar │ ├── jurt-3.2.1.jar │ ├── ridl-3.2.1.jar │ └── unoil-3.2.1.jar ├── shared-with-regain-preperators │ ├── commons-logging-1.1-for-pdfbox.jar │ ├── fontbox-1.6.0-for-pdfbox.jar │ ├── pdfbox-1.6.0.jar │ ├── poi-3.8-20120326.jar │ ├── poi-ooxml-3.8-20120326.jar │ ├── poi-ooxml-schemas-3.8-20120326.jar │ └── poi-scratchpad-3.8-20120326.jar └── shared-with-regain │ ├── aperture-core-1.5.0.jar │ ├── depencies.txt │ ├── rdf2go.api-4.6.2-for-aperture.jar │ ├── slf4j-api-1.3.0-for-aperture.jar │ ├── slf4j-jdk14-1.3.0-for-aperture.jar │ └── slf4j-simple-1.3.0-for-aperture.jar ├── plugin └── src │ └── de │ └── uni_siegen │ └── wineme │ └── come_in │ └── thumbnailer │ └── plugin │ ├── ThumbnailerLuceneConstants.java │ ├── ThumbnailerPlugin.java │ ├── server │ └── taglib │ │ └── ImgTag.java │ └── sharedlib │ └── ImgTag.java ├── ressources ├── conf │ ├── how-to-create-an-openoffice-profile.txt │ └── javathumbnailer.log4j.properties ├── dummy-jdk-api-doc │ └── package-list └── stylesheet.css ├── screenshot.png ├── src ├── de │ └── uni_siegen │ │ └── wineme │ │ └── come_in │ │ └── thumbnailer │ │ ├── FileDoesNotExistException.java │ │ ├── Main.java │ │ ├── ThumbnailerConstants.java │ │ ├── ThumbnailerException.java │ │ ├── ThumbnailerManager.java │ │ ├── UnsupportedInputFileFormatException.java │ │ ├── thumbnailers │ │ ├── AbstractThumbnailer.java │ │ ├── CobraThumbnailer.java │ │ ├── DummyThumbnailer.java │ │ ├── JODConverterThumbnailer.java │ │ ├── JODExcelConverterThumbnailer.java │ │ ├── JODHtmlConverterThumbnailer.java │ │ ├── JODPowerpointConverterThumbnailer.java │ │ ├── JODWordConverterThumbnailer.java │ │ ├── NativeImageThumbnailer.java │ │ ├── OpenOfficeThumbnailer.java │ │ ├── PDFBoxThumbnailer.java │ │ ├── ScratchThumbnailer.java │ │ └── Thumbnailer.java │ │ └── util │ │ ├── ChainedHashMap.java │ │ ├── IOUtil.java │ │ ├── Platform.java │ │ ├── ResizeImage.java │ │ ├── StringUtil.java │ │ ├── TemporaryFilesManager.java │ │ ├── ThumbnailReadyObserver.java │ │ └── mime │ │ ├── DocFileIdentifier.java │ │ ├── MimeTypeDetector.java │ │ ├── MimeTypeIdentifier.java │ │ ├── Office2007FileIdentifier.java │ │ ├── OfficeFileIdentifier.java │ │ ├── PptFileIdentifier.java │ │ ├── ScratchFileIdentifier.java │ │ └── XlsFileIdentifier.java └── jirau │ └── DWGThumbnailer.java ├── test ├── lib │ └── commons-exec-1.1.jar ├── log4j.properties ├── src │ ├── de │ │ └── uni_siegen │ │ │ └── wineme │ │ │ └── come_in │ │ │ └── thumbnailer │ │ │ └── test │ │ │ ├── ChainedHashtableTest.java │ │ │ ├── IOUtilTest.java │ │ │ ├── MimeDetectionTest.java │ │ │ ├── MyTestCase.java │ │ │ ├── Profiler.java │ │ │ ├── TemporaryFilesManagerTest.java │ │ │ ├── TestConfiguration.java │ │ │ ├── ThumbnailGeneratorBasicTest.java │ │ │ ├── ThumbnailGeneratorMIMETest.java │ │ │ ├── ThumbnailImageFormatTest.java │ │ │ ├── ThumbnailerFileTestDummy.java │ │ │ ├── ThumbnailerManagerTest.java │ │ │ ├── ThumbnailersFailingTest.java │ │ │ ├── integration │ │ │ └── ThumbnailerStandaloneBasicTest.java │ │ │ └── slow │ │ │ ├── MIMEDectectionExtensiveTest.java │ │ │ └── ThumbnailImageStrangeFilesTest.java │ └── uk │ │ └── ac │ │ └── lkl │ │ └── common │ │ └── util │ │ └── testing │ │ └── LabelledParameterized.java └── testfiles │ ├── do_not_work_yet │ ├── test.tiff │ ├── test.zip │ └── test2.tiff │ ├── format │ ├── breit.png │ ├── hoch.png │ ├── orig.png │ └── small.png │ ├── space space.txt │ ├── test.bmp │ ├── test.doc │ ├── test.docx │ ├── test.dwg │ ├── test.html │ ├── test.jpg │ ├── test.odp │ ├── test.ods │ ├── test.odt │ ├── test.pdf │ ├── test.png │ ├── test.ppt │ ├── test.pptx │ ├── test.rtf │ ├── test.sb │ ├── test.txt │ ├── test.xls │ ├── test.xlsx │ ├── test2.dwg │ ├── test2.html │ ├── test3.dwg │ ├── tmp │ ├── sage.sb │ └── test_hoch.pdf │ └── wrong_extension │ ├── test2-bmp.png │ ├── test2-doc.ott │ ├── test2-docx.doc │ ├── test2-dwg.doc │ ├── test2-jpg.bmp │ ├── test2-odp.pps │ ├── test2-ods.xls │ ├── test2-odt.doc │ ├── test2-odt.sxw │ ├── test2-pdf.ps │ ├── test2-png.jpg │ ├── test2-ppt.odp │ ├── test2-pptx.ppt │ ├── test2-rtf.pdf │ ├── test2-sb.sbx │ ├── test2-xls.odp │ ├── test2-xlsx.ods │ └── test2-xlsx.ppt ├── unitth.properties └── web ├── img ├── _image_missing_orig.png ├── image_missing.png └── image_missing2.png ├── search_example.jsp ├── search_xml_example.jsp └── taglib └── regain-thumbnailer.tld /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | thumbs 3 | bin 4 | log 5 | /build.properties 6 | junitvmwatcher* 7 | *.log 8 | test/reports 9 | /.settings 10 | /.fbprefs 11 | /reports/ 12 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | java-thumbnailer 4 | 5 | 6 | regain-svn 7 | 8 | 9 | 10 | org.eclipse.jdt.core.javabuilder 11 | 12 | 13 | 14 | 15 | 16 | org.eclipse.jdt.core.javanature 17 | 18 | 19 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | CHANGELOG of java-thumbnailer 2 | ----------------------------- 3 | 4 | + Add Feature 5 | * Bugfix 6 | # Enhance Feature 7 | 8 | 9 | v0.6 10 | ---- 11 | (05. December 2012) 12 | * Delete Thumbnails that were not saved in the index. (This can happen if crawling happens several times a day, as the document is only indexed once a day.) 13 | + JODConverterThumbnailer: Port can now be configured. 14 | + Automatic regain installation via ant (see https://github.com/benjaminpick/java-thumbnailer/wiki/Building-from-source) 15 | * Fix possible NullPointerException for Office2007FileIdentifier 16 | + Change Mime Type in regain index to detected one (our mime type detector is more accurate than regain's) 17 | 18 | v0.5 19 | ---- 20 | (30. March 2012) 21 | * Catch all errors of POI (no idea in which edge case this could change something) 22 | * MS-Office-FileIdentifiers does not need temporary files anymore. 23 | * Improve Perfomance of PDFBox a little bit 24 | * Centralise handling of temporary files 25 | * Add HTML thumnailing (rudimentary) 26 | 27 | v0.4 28 | ---- 29 | (5. January 2012) 30 | 31 | + Add Apache POI 3.7 32 | * Update JODConverter to latest version in SVN 33 | + Old Office Files are now detected via MIME => Performance improvement: Zip files can quicker be detected as non-office file 34 | 35 | Failing Tests: 36 | - ChainedHashtable: testBacking (not important, as currently not used) 37 | - ThumbnailersFailingTest: testFailingJOD (JOD may falsely claim having succeeded when converting a binary file) 38 | - MIMEDectectionExtensiveTest: txt-related (10) (Txt files cannot be detected by content - should we detect ASCII-Files?) 39 | 40 | v0.3 41 | ---- 42 | (9. August 2011) 43 | 44 | * Make Lucene Value "filelocation" relative to thumnailFolder 45 | * Changed Lucene Value "no thumbnailer found" to "nothumbnailerfound" (to avoid tokenizing) 46 | * Add to taglib 47 | 48 | v0.2 49 | ---- 50 | (2. August 2011) 51 | 52 | + MIME-Test: Office2007-Files & OpenOffice files are detected via Zip/XML 53 | # Upgrade PDFBox 1.5.0 -> 1.6.0 54 | * JODConverter didn't delete his temporary files if conversion failed 55 | 56 | Failing tests: 57 | - ChainedHashtable: testBacking (not important, as currently not used) 58 | - MimeDetectionTest: testOfficeFiles{1,2,3} (meaning only that conversion takes longer than necessary) 59 | - ThumbnailersFailingTest: testFailingJOD (JOD may falsely claim having succeeded when converting a binary file) 60 | 61 | v0.1 62 | ---- 63 | (29. July 2011) 64 | 65 | First public release. 66 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | This document is intended to help you getting started. 2 | The most recent instructions can be found at https://github.com/benjaminpick/java-thumbnailer/wiki/Installation 3 | 4 | --- 5 | 6 | Installation 7 | ============ 8 | 9 | There are two versions of JavaThumbnailer: 10 | 11 | * If you want to include this as a library to your own project, or use it from command-line only, you should take the **Standalone Version**. 12 | * For integration into the regain Desktop search, take the **Regain Plugin Version**. 13 | 14 | ## Standalone Version 15 | 16 | 1. Get the recent version of JavaThumbnailer at the [Download Page](https://github.com/benjaminpick/java-thumbnailer/releases) (or [build it from source](Building from Source).) 17 | 2. To run it via the commandline: `java -jar javathumbnailer-standalone.jar input.doc [output.png]` 18 | 3. To use it in your own project, include this `.jar` in your classpath. For an example of usage (and configuration), see the code in [Main.java](https://github.com/benjaminpick/java-thumbnailer/blob/master/src/de/uni_siegen/wineme/come_in/thumbnailer/Main.java). 19 | 20 | ## Regain Plugin Version 21 | 22 | 0. Get the recent version of [regain](http://regain.sourceforge.net/download.php). 23 | 1. Get the recent version of JavaThumbnailer at the [Download Page](https://github.com/benjaminpick/java-thumbnailer/releases) (or [build it from source](Building from Source).) 24 | 25 | ### Crawler Plugin 26 | 2. Save javathumbnailer-crawlerplugin-${version}.jar it into the `/plugins/`-Folder of regain. 27 | 3. Edit `CrawlerConfiguration.xml` to suit your needs. Here are the default values: 28 | 29 | 33 | 34 | de.uni_siegen.wineme.come_in.thumbnailer.plugin.ThumbnailerPlugin 35 | 36 |
37 | 39 | thumbs/ 40 | 41 | 42 | 160 43 | 120 44 |
45 |
46 | 47 | 48 | 49 | 50 | 51 |
52 |
53 |
54 | 55 | ### Search 56 | 57 | 4. Extract `web/` to your web/-Folder (Server: deployed folder). It contains: 58 | * `search_example.jsp` : Modified version of `regain/web/common/search.jsp` . If you didn't modify it, you can overwrite the regain version of `search.jsp`. 59 | * `img/image_missing.png` : Example of an image that is shown instead of the thumbnail when thumbnail generation failed 60 | * `taglib/regain-thumbnailer.tld` : Tag declarations. Used only by the server version. 61 | * `taglib/thumbnailer.jar`: Tag implementations. Used by server & desktop version. 62 | 63 | #### Desktop Search 64 | *(If you don't use the desktop search, you can skip this section.)* 65 | 66 | 5. Add the thumbnailer-Tag in `DesktopConfiguration.xml`: 67 | 68 | 69 | 70 | 71 | net.sf.regain.search.sharedlib 72 | net.sf.regain.ui.desktop.config.sharedlib 73 | net.sf.regain.ui.desktop.status.sharedlib 74 | 75 | 76 | de.uni_siegen.wineme.come_in.thumbnailer.plugin.sharedlib 77 | 78 | 79 | #### Server Search 80 | *(If you don't use the tomcat server search, you can skip this section.)* 81 | 82 | 6. Copy `web/taglib/thumbnailer.jar` into the deployed application folder `WEB-INF/lib`. 83 | 7. Make sure you added `<%@taglib uri="taglib/regain-thumbnailer.tld" prefix="thumbnailer" %>` at the top of your jsp where you use the tag ``. 84 | 8. Restart Tomcat or the regain-application. 85 | 86 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Thumbnailer 2 | =========== 3 | 4 | This is a Java Plugin for creating Thumbnails of files during the crawling process of regain.
5 | It can also be used as a standalone library to create thumbnails of different file types (image, text).
6 | (Regain is a Lucene-based desktop search engine.) 7 | 8 | *Current Version* : 0.6 (Beta)
9 | *Licence* : GNU GPL 2.1 or later 10 | 11 | Similar Project: 12 | 13 | * https://code.google.com/p/thumbnailator/ only for images 14 | 15 | Requirements 16 | ------------ 17 | 18 | * Java JRE 1.8 19 | * (optional) OpenOffice 3.x/LibreOffice 20 | * Tested in Windows/Linux/Mac 21 | 22 | Supported Fileformats 23 | --------------------- 24 | 25 | * Office files (doc, docx, xls, xlsx, ppt, pptx) 26 | * OpenOffice files (all of them) 27 | * Text files (txt, pdf, rtf, html) 28 | * Image files (jpg, png, bmp, gif) 29 | * MIT Scratch files (sb) 30 | * AutoCad files (dwg) 31 | 32 | (Detection is based on MIME-Type, not filename extension. So files with an incorrect file extension will be treated correctly, not as they deserve.) 33 | 34 | Output are always PNG files. The dimension of this Thumbnail can be configured. 35 | 36 | TODO 37 | ---- 38 | 39 | ### Thumbnailer: 40 | * JODConverter 3beta 41 | * Upgrade to 3beta5 when it appears 42 | * remove log4j info messages 43 | * Find a way to let him fail if he can't convert the file (sb is a binary format and really shouldn't be treated as plain text.) 44 | * PDFBox: Library Conflict with regain. (We need to include this in the plugin, but it is included in a maybe-loaded preparator as well.) 45 | * That means that both should be updated at the same time! 46 | 47 | 48 | Author 49 | ------ 50 | 51 | This is a project of the university of Siegen for the benefit of [come_IN Computerclubs](http://www.computerclub-comein.de). But of course, if you have patches etc. go ahead! 52 | -------------------------------------------------------------------------------- /build.properties.template: -------------------------------------------------------------------------------- 1 | # Rename this file to build.properties in order to use it. 2 | 3 | # The current Version 4 | version.prefix=0.7 5 | 6 | # Is the version a preview version (an inofficial release) 7 | is-preview=true 8 | 9 | # Should be compiled with the debug flag? 10 | debug=true 11 | 12 | # The location of the Java API 13 | java-api-location=http://java.sun.com/javase/6/docs/api/ 14 | 15 | # The location of the Java Standard Edition 6 16 | java.dir=C:/Programme/Java/jdk1.6.0_12 17 | 18 | # If package-plugin: where the regain installation is located 19 | # We need to have access to its build.xml in order to build their classes (linkage) 20 | regain-location=C:/Programme/Regain 21 | 22 | # The directory where the tomcat server is located 23 | # For targets: deploy-server,deploy-tomcat 24 | deploy-target.dir=/home/b/bin/apache-tomcat/webapps 25 | -------------------------------------------------------------------------------- /lib/ScratchApplet.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/ScratchApplet.jar -------------------------------------------------------------------------------- /lib/ant/ant.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/ant/ant.jar -------------------------------------------------------------------------------- /lib/ant/junit-3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/ant/junit-3.jar -------------------------------------------------------------------------------- /lib/ant/junit-4.10.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/ant/junit-4.10.jar -------------------------------------------------------------------------------- /lib/ant/junit-4.8.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/ant/junit-4.8.1.jar -------------------------------------------------------------------------------- /lib/ant/junit-4.8.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/ant/junit-4.8.2.jar -------------------------------------------------------------------------------- /lib/ant/tlddoc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/ant/tlddoc.jar -------------------------------------------------------------------------------- /lib/ant/unitth-1.3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/ant/unitth-1.3.1.jar -------------------------------------------------------------------------------- /lib/ant/xmltask.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/ant/xmltask.jar -------------------------------------------------------------------------------- /lib/jodconverter3/commons-cli-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/jodconverter3/commons-cli-1.1.jar -------------------------------------------------------------------------------- /lib/jodconverter3/commons-io-1.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/jodconverter3/commons-io-1.4.jar -------------------------------------------------------------------------------- /lib/jodconverter3/jodconverter-core-3.0-beta-3_r220.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/jodconverter3/jodconverter-core-3.0-beta-3_r220.jar -------------------------------------------------------------------------------- /lib/jodconverter3/json-20090211.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/jodconverter3/json-20090211.jar -------------------------------------------------------------------------------- /lib/jodconverter3/juh-3.2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/jodconverter3/juh-3.2.1.jar -------------------------------------------------------------------------------- /lib/jodconverter3/jurt-3.2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/jodconverter3/jurt-3.2.1.jar -------------------------------------------------------------------------------- /lib/jodconverter3/ridl-3.2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/jodconverter3/ridl-3.2.1.jar -------------------------------------------------------------------------------- /lib/jodconverter3/unoil-3.2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/jodconverter3/unoil-3.2.1.jar -------------------------------------------------------------------------------- /lib/shared-with-regain-preperators/commons-logging-1.1-for-pdfbox.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/shared-with-regain-preperators/commons-logging-1.1-for-pdfbox.jar -------------------------------------------------------------------------------- /lib/shared-with-regain-preperators/fontbox-1.6.0-for-pdfbox.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/shared-with-regain-preperators/fontbox-1.6.0-for-pdfbox.jar -------------------------------------------------------------------------------- /lib/shared-with-regain-preperators/pdfbox-1.6.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/shared-with-regain-preperators/pdfbox-1.6.0.jar -------------------------------------------------------------------------------- /lib/shared-with-regain-preperators/poi-3.8-20120326.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/shared-with-regain-preperators/poi-3.8-20120326.jar -------------------------------------------------------------------------------- /lib/shared-with-regain-preperators/poi-ooxml-3.8-20120326.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/shared-with-regain-preperators/poi-ooxml-3.8-20120326.jar -------------------------------------------------------------------------------- /lib/shared-with-regain-preperators/poi-ooxml-schemas-3.8-20120326.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/shared-with-regain-preperators/poi-ooxml-schemas-3.8-20120326.jar -------------------------------------------------------------------------------- /lib/shared-with-regain-preperators/poi-scratchpad-3.8-20120326.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/shared-with-regain-preperators/poi-scratchpad-3.8-20120326.jar -------------------------------------------------------------------------------- /lib/shared-with-regain/aperture-core-1.5.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/shared-with-regain/aperture-core-1.5.0.jar -------------------------------------------------------------------------------- /lib/shared-with-regain/depencies.txt: -------------------------------------------------------------------------------- 1 | pdfbox 2 | > fontbox 3 | > apache logging 4 | 5 | aperture 6 | > rdf2go 7 | > slf4j 8 | 9 | log4j 10 | -------------------------------------------------------------------------------- /lib/shared-with-regain/rdf2go.api-4.6.2-for-aperture.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/shared-with-regain/rdf2go.api-4.6.2-for-aperture.jar -------------------------------------------------------------------------------- /lib/shared-with-regain/slf4j-api-1.3.0-for-aperture.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/shared-with-regain/slf4j-api-1.3.0-for-aperture.jar -------------------------------------------------------------------------------- /lib/shared-with-regain/slf4j-jdk14-1.3.0-for-aperture.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/shared-with-regain/slf4j-jdk14-1.3.0-for-aperture.jar -------------------------------------------------------------------------------- /lib/shared-with-regain/slf4j-simple-1.3.0-for-aperture.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/lib/shared-with-regain/slf4j-simple-1.3.0-for-aperture.jar -------------------------------------------------------------------------------- /plugin/src/de/uni_siegen/wineme/come_in/thumbnailer/plugin/ThumbnailerLuceneConstants.java: -------------------------------------------------------------------------------- 1 | package de.uni_siegen.wineme.come_in.thumbnailer.plugin; 2 | 3 | /** 4 | * Constants that are used to read/write lucene fields. 5 | * 6 | * @author Benjamin 7 | */ 8 | public interface ThumbnailerLuceneConstants { 9 | /** Fieldname prefix that is used within the Lucene index */ 10 | public static final String THUMBNAILER_INDEX_PREFIX = "thumbnailer_"; 11 | 12 | /** Fieldnames and -values */ 13 | public static final String LUCENE_FIELD_NAME_STATUS = THUMBNAILER_INDEX_PREFIX + "status"; 14 | public static final String LUCENE_FIELD_VALUE_STATUS_OK = "ok"; 15 | public static final String LUCENE_FIELD_VALUE_STATUS_NO_THUMBNAILER_FOUND = "nothumbnailerfound"; 16 | public static final String LUCENE_FIELD_VALUE_STATUS_FAILED = "failed"; 17 | public static final String LUCENE_FIELD_NAME_FILE_LOCATION = THUMBNAILER_INDEX_PREFIX + "filelocation"; 18 | } -------------------------------------------------------------------------------- /plugin/src/de/uni_siegen/wineme/come_in/thumbnailer/plugin/server/taglib/ImgTag.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain - A file search engine providing plenty of formats 3 | * Copyright (C) 2004 Til Schneider 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Til Schneider, info@murfman.de 20 | * 21 | * CVS information: 22 | * $RCSfile$ 23 | * $Source$ 24 | * $Date$ 25 | * $Author$ 26 | * $Revision$ 27 | */ 28 | package de.uni_siegen.wineme.come_in.thumbnailer.plugin.server.taglib; 29 | 30 | import net.sf.regain.util.sharedtag.taglib.SharedTagWrapperTag; 31 | 32 | /** 33 | * Taglib wrapper for the shared msg tag. 34 | * 35 | * @see net.sf.regain.search.sharedlib.MsgTag 36 | * @author Til Schneider, www.murfman.de 37 | */ 38 | public class ImgTag extends SharedTagWrapperTag { 39 | 40 | private static final long serialVersionUID = 9145558444625323945L; 41 | 42 | /** 43 | * Creates a new instance of MsgTag. 44 | */ 45 | public ImgTag() { 46 | super(new de.uni_siegen.wineme.come_in.thumbnailer.plugin.sharedlib.ImgTag()); 47 | } 48 | 49 | public void setWidth(String width) { 50 | getNestedTag().setParameter("width", width); 51 | } 52 | 53 | public void setHeight(String height) { 54 | getNestedTag().setParameter("height", height); 55 | } 56 | 57 | public void setMissing(String missing) { 58 | getNestedTag().setParameter("missing", missing); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /plugin/src/de/uni_siegen/wineme/come_in/thumbnailer/plugin/sharedlib/ImgTag.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain - A file search engine providing plenty of formats 3 | * Copyright (C) 2004 Til Schneider 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Til Schneider, info@murfman.de 20 | * 21 | * CVS information: 22 | * $RCSfile$ 23 | * $Source$ 24 | * $Date$ 25 | * $Author$ 26 | * $Revision$ 27 | */ 28 | package de.uni_siegen.wineme.come_in.thumbnailer.plugin.sharedlib; 29 | 30 | import net.sf.regain.RegainException; 31 | import net.sf.regain.search.SearchToolkit; 32 | import net.sf.regain.search.sharedlib.hit.AbstractHitTag; 33 | import net.sf.regain.util.sharedtag.PageRequest; 34 | import net.sf.regain.util.sharedtag.PageResponse; 35 | 36 | import org.apache.lucene.document.Document; 37 | 38 | import de.uni_siegen.wineme.come_in.thumbnailer.ThumbnailerConstants; 39 | import de.uni_siegen.wineme.come_in.thumbnailer.plugin.ThumbnailerLuceneConstants; 40 | 41 | /** 42 | * Generates the value of an index field of the current hit's document. 43 | *

44 | * Tag Parameters: 45 | *

50 | * 51 | * @author b 52 | */ 53 | public class ImgTag extends AbstractHitTag implements ThumbnailerLuceneConstants, ThumbnailerConstants { 54 | 55 | /** 56 | * Generates the tag. 57 | * 58 | * @param request The page request. 59 | * @param response The page response. 60 | * @param hit The current search hit. 61 | * @param hitIndex The index of the hit. 62 | * @throws RegainException If there was an exception. 63 | */ 64 | protected void printEndTag(PageRequest request, PageResponse response, 65 | Document hit, int hitIndex) 66 | throws RegainException { 67 | //SearchResults results = SearchToolkit.getSearchResults(request); 68 | 69 | int width = getParameterAsInt("width", THUMBNAIL_DEFAULT_WIDTH); 70 | if (width < 0) 71 | width = THUMBNAIL_DEFAULT_WIDTH; 72 | 73 | int height = getParameterAsInt("height", THUMBNAIL_DEFAULT_HEIGHT); 74 | if (height < 0) 75 | height = THUMBNAIL_DEFAULT_HEIGHT; 76 | 77 | String size = "width=\"" + width + "\" height=\"" + height + "\""; 78 | 79 | String status = SearchToolkit.getCompressedFieldValue(hit, LUCENE_FIELD_NAME_STATUS); 80 | 81 | String location = null; 82 | if (LUCENE_FIELD_VALUE_STATUS_OK.equals(status)) 83 | location = SearchToolkit.getCompressedFieldValue(hit, LUCENE_FIELD_NAME_FILE_LOCATION); 84 | 85 | // New For Thumbnail Tag 86 | if (location != null) { 87 | response.print(""); 90 | } 91 | else { 92 | String img_missing = getParameter("missing", false); 93 | if (img_missing != null && !img_missing.isEmpty()) 94 | response.print(""); 95 | } 96 | } 97 | 98 | private String rewrite(String value) { 99 | // TODO: Config Rewrite Rule / Thumbnail Base Path 100 | return "thumbs/" + value; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /ressources/conf/how-to-create-an-openoffice-profile.txt: -------------------------------------------------------------------------------- 1 | How to create an OpenOffice Profile 2 | =================================== 3 | 4 | JODConverter can create a new profile, but if you want to set openoffice-Preferences or just save that overhead, this is how you can create a profile folder. (JODConverter will actually only use copies of it, so it won't get modified.) 5 | 6 | 1. Go to the commandline and type: 7 | 8 | soffice -env:UserInstallation=[profile dir here] 9 | 10 | (You may need to go to the OpenOffice-Directory first.) 11 | 2. Now Openoffice starts within this profile, creating it if it didn't exist yet. 12 | 3. Change any preferences you like. 13 | 4. Close the window. 14 | 15 | Now go to CrawlerConfiguration.xml and tell the JavaThumbnailer where to look for a such profile (scroll down to crawlerPlugin > section:externalHelpers > param:openOfficeProfile ) 16 | 17 | -------------------------------------------------------------------------------- /ressources/conf/javathumbnailer.log4j.properties: -------------------------------------------------------------------------------- 1 | # NOTE: cascaded variable substitution doesn't work! 2 | 3 | # The root category 4 | log4j.rootCategory=INFO, file, stdout 5 | 6 | # Special categories 7 | # Disable log messages from PDFBox 8 | log4j.category.org.apache.pdfbox.util.PDFStreamEngine=WARN 9 | # Disable Font replacement warnings from PDFBox 10 | log4j.category.org.apache.pdfbox.pdmodel.font.PDSimpleFont=ERROR 11 | 12 | # Some layouts 13 | #layout.example.1=%d{dd/MM/yyyy HH:mm:ss} [%-5p](%F:%L) %m%n 14 | #layout.example.2=%d{dd/MM/yyyy HH:mm:ss} [%t] %-5p %c{2} - %m%n 15 | layout.long=%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p: %m%n 16 | layout.medium=%d{HH:mm:ss}: %m%n 17 | layout.short=%m%n 18 | 19 | 20 | # The console appender 21 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 22 | 23 | # The console appender layout 24 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 25 | log4j.appender.stdout.layout.ConversionPattern=${layout.medium} 26 | 27 | # The file appender 28 | log4j.appender.file=org.apache.log4j.RollingFileAppender 29 | 30 | # Log only errors to the log file 31 | log4j.appender.file.Threshold=ERROR 32 | 33 | # The file appender layout 34 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 35 | log4j.appender.file.layout.ConversionPattern=${layout.long} 36 | 37 | # Path of the log-file 38 | log4j.appender.file.File=log/regain.log 39 | 40 | # Maximum size of the log-file (only org.apache.log4j.RollingFileAppender) 41 | log4j.appender.file.MaxFileSize=2MB 42 | 43 | # Amount of backup files (only org.apache.log4j.RollingFileAppender) 44 | log4j.appender.file.MaxBackupIndex=2 45 | -------------------------------------------------------------------------------- /ressources/dummy-jdk-api-doc/package-list: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | java.applet 5 | java.awt 6 | java.awt.color 7 | java.awt.datatransfer 8 | java.awt.dnd 9 | java.awt.event 10 | java.awt.font 11 | java.awt.geom 12 | java.awt.im 13 | java.awt.im.spi 14 | java.awt.image 15 | java.awt.image.renderable 16 | java.awt.print 17 | java.beans 18 | java.beans.beancontext 19 | java.io 20 | java.lang 21 | java.lang.ref 22 | java.lang.reflect 23 | java.math 24 | java.net 25 | java.rmi 26 | java.rmi.activation 27 | java.rmi.dgc 28 | java.rmi.registry 29 | java.rmi.server 30 | java.security 31 | java.security.acl 32 | java.security.cert 33 | java.security.interfaces 34 | java.security.spec 35 | java.sql 36 | java.text 37 | java.util 38 | java.util.jar 39 | java.util.zip 40 | javax.accessibility 41 | javax.naming 42 | javax.naming.directory 43 | javax.naming.event 44 | javax.naming.ldap 45 | javax.naming.spi 46 | javax.rmi 47 | javax.rmi.CORBA 48 | javax.sound.midi 49 | javax.sound.midi.spi 50 | javax.sound.sampled 51 | javax.sound.sampled.spi 52 | javax.swing 53 | javax.swing.border 54 | javax.swing.colorchooser 55 | javax.swing.event 56 | javax.swing.filechooser 57 | javax.swing.plaf 58 | javax.swing.plaf.basic 59 | javax.swing.plaf.metal 60 | javax.swing.plaf.multi 61 | javax.swing.table 62 | javax.swing.text 63 | javax.swing.text.html 64 | javax.swing.text.html.parser 65 | javax.swing.text.rtf 66 | javax.swing.tree 67 | javax.swing.undo 68 | javax.transaction 69 | org.omg.CORBA 70 | org.omg.CORBA_2_3 71 | org.omg.CORBA_2_3.portable 72 | org.omg.CORBA.DynAnyPackage 73 | org.omg.CORBA.ORBPackage 74 | org.omg.CORBA.portable 75 | org.omg.CORBA.TypeCodePackage 76 | org.omg.CosNaming 77 | org.omg.CosNaming.NamingContextPackage 78 | org.omg.SendingContext 79 | org.omg.stub.java.rmi 80 | 81 | -------------------------------------------------------------------------------- /ressources/stylesheet.css: -------------------------------------------------------------------------------- 1 | /* Javadoc style sheet */ 2 | 3 | /* Define colors, fonts and other style attributes here to override the defaults */ 4 | 5 | /* Page background color */ 6 | body { background-color: #FFFFFF } 7 | 8 | /* Headings */ 9 | h1 { font-size: 145% } 10 | 11 | /* Table colors */ 12 | .TableHeadingColor { background: #CCCCFF } /* Dark mauve */ 13 | .TableSubHeadingColor { background: #EEEEFF } /* Light mauve */ 14 | .TableRowColor { background: #EEEEEE } /* Light gray */ 15 | 16 | /* Font used in left-hand frame lists */ 17 | .FrameTitleFont { font-size: 100%; font-family: Helvetica, Arial, sans-serif } 18 | .FrameHeadingFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif } 19 | .FrameItemFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif } 20 | 21 | /* Navigation bar fonts and colors */ 22 | .NavBarCell1 { background-color:#EEEEFF;} /* Light mauve */ 23 | .NavBarCell1Rev { background-color:#00008B;} /* Dark Blue */ 24 | .NavBarFont1 { font-family: Arial, Helvetica, sans-serif; color:#000000;} 25 | .NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;} 26 | 27 | .NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;} 28 | .NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;} 29 | 30 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/screenshot.png -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/FileDoesNotExistException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | */ 21 | 22 | package de.uni_siegen.wineme.come_in.thumbnailer; 23 | 24 | import java.io.File; 25 | import java.io.IOException; 26 | 27 | public class FileDoesNotExistException extends IOException { 28 | 29 | private static final long serialVersionUID = -8622959058435621680L; 30 | 31 | public FileDoesNotExistException() { 32 | } 33 | 34 | public FileDoesNotExistException(String arg0) { 35 | super(arg0); 36 | } 37 | 38 | public FileDoesNotExistException(Throwable arg0) { 39 | super(arg0); 40 | } 41 | 42 | public FileDoesNotExistException(String arg0, Throwable arg1) { 43 | super(arg0, arg1); 44 | } 45 | 46 | /** 47 | * Test if the file/directory exists and can be read. 48 | * @param f File to be tested 49 | * @param label How the file is called. 50 | * @throws FileDoesNotExistException if it does not exists or cannot be read. 51 | */ 52 | public static void check(File f, String label) throws FileDoesNotExistException 53 | { 54 | if (label == null) 55 | label = "The file"; 56 | 57 | if (f == null) 58 | throw new FileDoesNotExistException(label + " does not exist (is null)."); 59 | else if (!f.isFile() && !f.isDirectory()) 60 | throw new FileDoesNotExistException(label + " is not a file or directory: "+ 61 | f.getAbsolutePath()); 62 | else if (!f.exists()) 63 | throw new FileDoesNotExistException(label + " does not exist: "+ 64 | f.getAbsolutePath()); 65 | else if (!f.canRead()) 66 | throw new FileDoesNotExistException(label + " cannot be read: "+ 67 | f.getAbsolutePath()); 68 | } 69 | 70 | public static void check(File f) throws FileDoesNotExistException 71 | { 72 | check(f, null); 73 | } 74 | 75 | public static void checkWrite(File f, String label, boolean createParentDirsIfNotExist, boolean isDir) throws FileDoesNotExistException { 76 | if (label == null) 77 | label = "The file"; 78 | if (f == null) 79 | throw new FileDoesNotExistException(label + " does not exist (is null)."); 80 | 81 | if (createParentDirsIfNotExist) 82 | { 83 | boolean ret; 84 | if (isDir) 85 | { 86 | ret = f.mkdirs(); 87 | if (!ret && !f.exists()) 88 | throw new FileDoesNotExistException("Not all directories could be created: " + f.getAbsolutePath()); 89 | } 90 | else 91 | { 92 | File parent = f.getParentFile(); 93 | if (parent != null) // No idea why it returns null sometimes 94 | { 95 | ret = parent.mkdirs(); 96 | if (!ret && !parent.exists()) 97 | throw new FileDoesNotExistException("Not all parent directories could be created: " + f.getAbsolutePath()); 98 | } 99 | } 100 | } 101 | 102 | if (isDir) 103 | { 104 | if (!f.canWrite()) 105 | throw new FileDoesNotExistException(label + " cannot be written/modified: " + f.getAbsolutePath()); 106 | } 107 | else 108 | { 109 | try { 110 | f.createNewFile(); 111 | f.delete(); 112 | } catch (IOException e) { 113 | throw new FileDoesNotExistException(label + " ist nicht beschreibbar: " + f.getAbsolutePath()); 114 | } 115 | } 116 | } 117 | public static void checkWrite(File f, String label) throws FileDoesNotExistException { 118 | checkWrite(f, label, false, false); 119 | } 120 | public static void checkWrite(File f) throws FileDoesNotExistException { 121 | checkWrite(f, null); 122 | } 123 | 124 | 125 | } 126 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/Main.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | */ 21 | 22 | package de.uni_siegen.wineme.come_in.thumbnailer; 23 | 24 | import java.io.File; 25 | import java.io.IOException; 26 | import java.io.InputStream; 27 | import java.io.OutputStream; 28 | 29 | import jirau.DWGThumbnailer; 30 | 31 | import org.apache.commons.cli.CommandLine; 32 | import org.apache.commons.cli.CommandLineParser; 33 | import org.apache.commons.cli.GnuParser; 34 | import org.apache.commons.cli.HelpFormatter; 35 | import org.apache.commons.cli.OptionBuilder; 36 | import org.apache.commons.cli.Options; 37 | import org.apache.commons.cli.ParseException; 38 | import org.apache.commons.io.FileUtils; 39 | import org.apache.commons.io.IOUtils; 40 | import org.apache.log4j.Logger; 41 | import org.apache.log4j.PropertyConfigurator; 42 | 43 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.JODExcelConverterThumbnailer; 44 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.JODHtmlConverterThumbnailer; 45 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.JODPowerpointConverterThumbnailer; 46 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.JODWordConverterThumbnailer; 47 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.NativeImageThumbnailer; 48 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.OpenOfficeThumbnailer; 49 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.PDFBoxThumbnailer; 50 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.ScratchThumbnailer; 51 | 52 | /** 53 | * Little Command-line Application to illustrate the usage of this library. 54 | * 55 | * @author Benjamin 56 | * @needs Commons-cli (included in jodconverter) 57 | */ 58 | public class Main { 59 | protected static Logger mLog = Logger.getLogger(Main.class); 60 | private static Options options; 61 | private static ThumbnailerManager thumbnailer; 62 | private static File outFile; 63 | private static File inFile; 64 | private static final String LOG4J_CONFIG_FILE = "conf/javathumbnailer.log4j.properties"; 65 | 66 | public static void main(String[] params) throws Exception 67 | { 68 | if (params.length == 0) 69 | { 70 | explainUsage(); 71 | System.exit(-1); 72 | } 73 | initLogging(); 74 | 75 | thumbnailer = new ThumbnailerManager(); 76 | 77 | loadExistingThumbnailers(); 78 | 79 | // Set Default Values 80 | thumbnailer.setImageSize(160, 120, 0); 81 | thumbnailer.setThumbnailFolder("thumbs/"); 82 | 83 | initParams(); 84 | parseParams(params); 85 | 86 | if (outFile == null) 87 | outFile = thumbnailer.createThumbnail(inFile); 88 | else 89 | thumbnailer.generateThumbnail(inFile, outFile); 90 | 91 | System.out.println("SUCCESS: Thumbnail created:\n" + outFile.getAbsolutePath()); 92 | } 93 | 94 | private static void initParams() { 95 | options = new Options(); 96 | OptionBuilder.withArgName("WIDTHxHEIGHT"); 97 | OptionBuilder.hasArg(); 98 | OptionBuilder.withDescription("Size of the new thumbnail (default: 160x120)"); 99 | options.addOption(OptionBuilder.create("size")); 100 | } 101 | 102 | private static void parseParams(String[] params) { 103 | CommandLineParser parser = new GnuParser(); 104 | CommandLine line = null; 105 | try { 106 | line = parser.parse(options, params); 107 | } catch ( ParseException e ) { 108 | System.err.println("Invalid command line: " + e.getMessage()); 109 | explainUsage(); 110 | System.exit(1); 111 | } 112 | 113 | if (line.hasOption("size")) 114 | { 115 | // TODO Set 116 | } 117 | 118 | String[] files = line.getArgs(); 119 | if (files.length == 0 || files.length > 2) 120 | { 121 | explainUsage(); 122 | System.exit(1); 123 | } 124 | inFile = new File(files[0]); 125 | if (files.length > 1) 126 | outFile = new File(files[1]); 127 | } 128 | 129 | private static void explainUsage() { 130 | System.out.println("JavaThumbnailer"); 131 | System.out.println("==============="); 132 | System.out.println(""); 133 | System.out.println("Usage: java -jar javathumbnailer-standalone.jar [-size 160x120] inputfile [outputfile]"); 134 | 135 | HelpFormatter formatter = new HelpFormatter(); 136 | formatter.printHelp( "java -jar javathumbnailer-standalone.jar", options ); 137 | } 138 | 139 | protected static void loadExistingThumbnailers() { 140 | if (classExists("de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.NativeImageThumbnailer")) 141 | thumbnailer.registerThumbnailer(new NativeImageThumbnailer()); 142 | 143 | thumbnailer.registerThumbnailer(new OpenOfficeThumbnailer()); 144 | thumbnailer.registerThumbnailer(new PDFBoxThumbnailer()); 145 | 146 | try { 147 | thumbnailer.registerThumbnailer(new JODWordConverterThumbnailer()); 148 | thumbnailer.registerThumbnailer(new JODExcelConverterThumbnailer()); 149 | thumbnailer.registerThumbnailer(new JODPowerpointConverterThumbnailer()); 150 | thumbnailer.registerThumbnailer(new JODHtmlConverterThumbnailer()); 151 | } catch (IOException e) { 152 | mLog.error("Could not initialize JODConverter:", e); 153 | } 154 | 155 | thumbnailer.registerThumbnailer(new ScratchThumbnailer()); 156 | 157 | thumbnailer.registerThumbnailer(new DWGThumbnailer()); 158 | } 159 | 160 | protected static void initLogging() throws IOException 161 | { 162 | System.setProperty("log4j.configuration", LOG4J_CONFIG_FILE); 163 | 164 | File logConfigFile = new File(LOG4J_CONFIG_FILE); 165 | if (!logConfigFile.exists()) 166 | { 167 | // Extract config properties from jar 168 | InputStream in = Main.class.getResourceAsStream("/" + LOG4J_CONFIG_FILE); 169 | if (in == null) 170 | { 171 | System.err.println("Packaging error: can't find logging configuration inside jar. (Neither can I find the config file on the file system: " + logConfigFile.getAbsolutePath() + ")"); 172 | System.exit(1); 173 | } 174 | 175 | OutputStream out = null; 176 | try { 177 | out = FileUtils.openOutputStream(logConfigFile); 178 | IOUtils.copy(in, out); 179 | } finally { try { if (in != null) in.close(); } finally { if (out != null) out.close(); } } 180 | } 181 | 182 | PropertyConfigurator.configureAndWatch(logConfigFile.getAbsolutePath(), 10 * 1000); 183 | mLog.info("Logging initialized"); 184 | } 185 | 186 | public static boolean classExists(String qualifiedClassname) 187 | { 188 | try { 189 | Class.forName(qualifiedClassname); 190 | } catch (ClassNotFoundException e) { 191 | return false; 192 | } 193 | return true; 194 | } 195 | } 196 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/ThumbnailerConstants.java: -------------------------------------------------------------------------------- 1 | package de.uni_siegen.wineme.come_in.thumbnailer; 2 | 3 | public interface ThumbnailerConstants { 4 | public static final int THUMBNAIL_DEFAULT_HEIGHT = 120; 5 | 6 | public static final int THUMBNAIL_DEFAULT_WIDTH = 160; 7 | } 8 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/ThumbnailerException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | */ 21 | 22 | package de.uni_siegen.wineme.come_in.thumbnailer; 23 | 24 | /** 25 | * Thrown if Thumbnailing process failed. 26 | * 27 | */ 28 | public class ThumbnailerException extends Exception { 29 | 30 | private static final long serialVersionUID = -7988812285439060247L; 31 | 32 | public ThumbnailerException() { 33 | super(); 34 | } 35 | 36 | public ThumbnailerException(String message) { 37 | super(message); 38 | } 39 | 40 | public ThumbnailerException(Throwable cause) { 41 | super(cause); 42 | } 43 | 44 | public ThumbnailerException(String message, Throwable cause) { 45 | super(message, cause); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/UnsupportedInputFileFormatException.java: -------------------------------------------------------------------------------- 1 | package de.uni_siegen.wineme.come_in.thumbnailer; 2 | 3 | import java.io.IOException; 4 | 5 | public class UnsupportedInputFileFormatException extends IOException { 6 | 7 | private static final long serialVersionUID = -8728813367662852880L; 8 | 9 | public UnsupportedInputFileFormatException() { 10 | } 11 | 12 | public UnsupportedInputFileFormatException(String arg0) { 13 | super(arg0); 14 | } 15 | 16 | public UnsupportedInputFileFormatException(Throwable arg0) { 17 | super(arg0); 18 | } 19 | 20 | public UnsupportedInputFileFormatException(String arg0, Throwable arg1) { 21 | super(arg0, arg1); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/thumbnailers/AbstractThumbnailer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | */ 21 | 22 | package de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers; 23 | 24 | import java.io.File; 25 | import java.io.IOException; 26 | 27 | import de.uni_siegen.wineme.come_in.thumbnailer.ThumbnailerConstants; 28 | import de.uni_siegen.wineme.come_in.thumbnailer.ThumbnailerException; 29 | 30 | /** 31 | * This AbstractThumbnailer may be used in order to implement only essential methods. 32 | * It 33 | *
  • stores the current thumbnail height/width 34 | *
  • implements an empty close method 35 | *
  • specifies an wildcard MIME Type as appropriate Filetype 36 | * 37 | * @author Benjamin 38 | */ 39 | public abstract class AbstractThumbnailer implements Thumbnailer, ThumbnailerConstants { 40 | 41 | /** 42 | * @var Height of thumbnail picture to create (in Pixel) 43 | */ 44 | protected int thumbHeight; 45 | 46 | /** 47 | * @var Width of thumbnail picture to create (in Pixel) 48 | */ 49 | protected int thumbWidth; 50 | 51 | /** 52 | * @var Options for image resizer (currently unused) 53 | */ 54 | protected int imageResizeOptions = 0; 55 | 56 | /** 57 | * @var Keep memory if this thumbnailer was closed before. 58 | */ 59 | protected boolean closed = false; 60 | 61 | /** 62 | * Initialize the thumbnail size from default constants. 63 | */ 64 | public AbstractThumbnailer() 65 | { 66 | thumbHeight = THUMBNAIL_DEFAULT_HEIGHT; 67 | thumbWidth = THUMBNAIL_DEFAULT_WIDTH; 68 | } 69 | 70 | /** 71 | * Set a new Thumbnail size. All following thumbnails will be generated in this size. 72 | * 73 | * @param width Width in Pixel 74 | * @param height Height in Pixel 75 | * @param imageResizeOptions Options for ResizeImage (currently ignored) 76 | */ 77 | @Override 78 | public void setImageSize(int thumbWidth, int thumbHeight, int imageResizeOptions) { 79 | this.thumbHeight = thumbHeight; 80 | this.thumbWidth = thumbWidth; 81 | this.imageResizeOptions = imageResizeOptions; 82 | } 83 | 84 | /** 85 | * Get the currently set Image Width of this Thumbnailer. 86 | * @return image width of created thumbnails. 87 | */ 88 | public int getCurrentImageWidth() 89 | { 90 | return thumbWidth; 91 | } 92 | 93 | /** 94 | * Get the currently set Image Height of this Thumbnailer. 95 | * @return image height of created thumbnails. 96 | */ 97 | public int getCurrentImageHeight() 98 | { 99 | return thumbHeight; 100 | } 101 | 102 | /** 103 | * This function will be called after all Thumbnails are generated. 104 | * Note: This acts as a Deconstructor. Do not expect this object to work 105 | * after calling this method. 106 | * 107 | * @throws IOException If some errors occured during finalising 108 | */ 109 | @Override 110 | public void close() throws IOException { 111 | // Do nothing for now - other Thumbnailer may need cleanup code here. 112 | closed = true; 113 | } 114 | 115 | /** 116 | * Call close() just in case the caller forgot. 117 | */ 118 | protected void finalize() throws Throwable 119 | { 120 | try { 121 | super.finalize(); 122 | } finally { 123 | if (!closed) 124 | close(); 125 | } 126 | } 127 | 128 | /** 129 | * Get a list of all MIME Types that this Thumbnailer is ready to process. 130 | * You should override this method in order to give hints when which Thumbnailer is most appropriate. 131 | * If you do not override this method, the Thumbnailer will be called in any case - awaiting a ThumbnailException if 132 | * this thumbnailer cannot treat such a file. 133 | * 134 | * @return List of MIME Types. If null, all Files may be passed to this Thumbnailer. 135 | */ 136 | public String[] getAcceptedMIMETypes() 137 | { 138 | return null; 139 | } 140 | 141 | /** 142 | * Generate a Thumbnail of the input file. 143 | * (You can override this method if you want to handle the different MIME-Types). 144 | * 145 | * @param input Input file that should be processed 146 | * @param output File in which should be written 147 | * @param mimeType MIME-Type of input file (null if unknown) 148 | * @throws IOException If file cannot be read/written 149 | * @throws ThumbnailerException If the thumbnailing process failed. 150 | */ 151 | public void generateThumbnail(File input, File output, String mimeType) throws IOException, ThumbnailerException { 152 | // Ignore MIME-Type-Hint 153 | generateThumbnail(input, output); 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/thumbnailers/CobraThumbnailer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | */ 21 | 22 | package de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers; 23 | 24 | import java.io.File; 25 | import java.io.IOException; 26 | 27 | import de.uni_siegen.wineme.come_in.thumbnailer.ThumbnailerException; 28 | 29 | /** 30 | * This class creates Thumbnails from websites 31 | * 32 | * Depends: 33 | *
  • Cobra http://lobobrowser.org/cobra/ 34 | * 35 | */ 36 | public class CobraThumbnailer extends AbstractThumbnailer { 37 | 38 | @Override 39 | public void generateThumbnail(File input, File output) throws IOException, ThumbnailerException { 40 | 41 | 42 | /* 43 | BufferedInputStream in = null; 44 | ZipFile zipFile = null; 45 | 46 | try { 47 | zipFile = new ZipFile(input); 48 | } catch (ZipException e) { 49 | throw new ThumbnailerException("This is not a zipped file. Is this really an OpenOffice-File?", e); 50 | } 51 | 52 | try { 53 | ZipEntry entry = zipFile.getEntry("Thumbnails/thumbnail.png"); 54 | if (entry == null) 55 | throw new ThumbnailerException("Zip file does not contain 'Thumbnails/thumbnail.png' . Is this really an OpenOffice-File?"); 56 | 57 | in = new BufferedInputStream(zipFile.getInputStream(entry)); 58 | 59 | ResizeImage resizer = new ResizeImage(thumbWidth, thumbHeight); 60 | resizer.setInputImage(in); 61 | resizer.writeOutput(output); 62 | 63 | in.close(); 64 | } 65 | finally { 66 | IOUtil.quietlyClose(in); 67 | IOUtil.quietlyClose(zipFile); 68 | } 69 | */ 70 | } 71 | 72 | /** 73 | * Get a List of accepted File Types. 74 | * All OpenOffice Formats are accepted. 75 | * 76 | * @return MIME-Types 77 | */ 78 | public String[] getAcceptedMIMETypes() 79 | { 80 | return new String[] { 81 | "text/html" 82 | }; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/thumbnailers/DummyThumbnailer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | */ 21 | package de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers; 22 | 23 | import java.io.File; 24 | import java.io.IOException; 25 | import de.uni_siegen.wineme.come_in.thumbnailer.ThumbnailerException; 26 | 27 | // For example code 28 | import java.awt.image.BufferedImage; 29 | import javax.imageio.ImageIO; 30 | 31 | /** 32 | * Example class for new Thumbnailers. 33 | * 34 | * Copy this file and rename the class. 35 | * 36 | * @see https://github.com/benjaminpick/java-thumbnailer/wiki/How-To-Write-A-New-Thumbnailer 37 | */ 38 | public class DummyThumbnailer extends AbstractThumbnailer { 39 | 40 | /** 41 | * Generate a Thumbnail of the input file. 42 | * 43 | * @param input Input file that should be processed 44 | * @param output File in which should be written 45 | * @throws IOException If file cannot be read/written 46 | * @throws ThumbnailerException If the thumbnailing process failed. 47 | */ 48 | @Override 49 | public void generateThumbnail(File input, File output) throws IOException, ThumbnailerException { 50 | if (! "hello-world.txt".equals(input.getName())) 51 | throw new ThumbnailerException("This is not a suitable file format!"); 52 | 53 | // For testing purpose, just create an empty image. 54 | BufferedImage image = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_RGB); 55 | ImageIO.write(image, "PNG", output); 56 | } 57 | 58 | /** 59 | * Get a list of all MIME Types that this Thumbnailer is ready to process. 60 | * You should override this method in order to give hints when which Thumbnailer is most appropriate. 61 | * If you do not override this method, the Thumbnailer will be called in any case - awaiting a ThumbnailException if 62 | * this thumbnailer cannot treat such a file. 63 | * 64 | * @return List of MIME Types. If null, all Files may be passed to this Thumbnailer. 65 | */ 66 | public String[] getAcceptedMIMETypes() 67 | { 68 | return new String[] { 69 | "text/hello-world", 70 | "text/hello-world-2" 71 | }; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/thumbnailers/JODExcelConverterThumbnailer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | */ 21 | 22 | package de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers; 23 | 24 | import java.io.IOException; 25 | 26 | /** 27 | * Dummy class for converting Spreadsheet documents into Openoffice-Textfiles. 28 | * @see JODConverterThumbnailer 29 | */ 30 | public class JODExcelConverterThumbnailer extends JODConverterThumbnailer { 31 | 32 | public JODExcelConverterThumbnailer() throws IOException { super(); } 33 | 34 | protected String getStandardOpenOfficeExtension() { 35 | return "ods"; 36 | } 37 | 38 | protected String getStandardZipExtension() { 39 | return "xlsx"; 40 | } 41 | protected String getStandardOfficeExtension() { 42 | return "xls"; 43 | } 44 | 45 | /** 46 | * Get a List of accepted File Types. 47 | * All Spreadsheet Office Formats that OpenOffice understands are accepted. 48 | * 49 | * @return MIME-Types 50 | * @see http://www.artofsolving.com/opensource/jodconverter/guide/supportedformats 51 | */ 52 | public String[] getAcceptedMIMETypes() 53 | { 54 | return new String[]{ 55 | "application/vnd.ms-excel", 56 | "application/vnd.openxmlformats-officedocument.spreadsheetml", 57 | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", 58 | /* "application/vnd.ms-office", // xls? 59 | "application/zip" // xlsx? */ 60 | }; 61 | } 62 | 63 | 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/thumbnailers/JODHtmlConverterThumbnailer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | */ 21 | 22 | package de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers; 23 | 24 | import java.io.IOException; 25 | 26 | /** 27 | * Dummy class for converting Html documents into Openoffice-Textfiles. 28 | * 29 | * (The preview won't be better than what OpenOffice can achieve. See also 30 | * issue https://github.com/benjamin4ruby/java-thumbnailer/issues/8) 31 | * @see JODConverterThumbnailer 32 | */ 33 | public class JODHtmlConverterThumbnailer extends JODConverterThumbnailer { 34 | 35 | public JODHtmlConverterThumbnailer() throws IOException { super(); } 36 | 37 | protected String getStandardOpenOfficeExtension() { 38 | return ".odt"; 39 | } 40 | 41 | protected String getStandardZipExtension() { 42 | return "html"; 43 | } 44 | protected String getStandardOfficeExtension() { 45 | return "html"; 46 | } 47 | 48 | /** 49 | * Get a List of accepted File Types. 50 | * All Text Office Formats that OpenOffice understands are accepted. 51 | * (txt, rtf, doc, docx, wpd) 52 | * 53 | * @return MIME-Types 54 | * @see http://www.artofsolving.com/opensource/jodconverter/guide/supportedformats 55 | */ 56 | public String[] getAcceptedMIMETypes() 57 | { 58 | return new String[]{ 59 | "text/html" 60 | }; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/thumbnailers/JODPowerpointConverterThumbnailer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | */ 21 | 22 | package de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers; 23 | 24 | import java.io.IOException; 25 | 26 | /** 27 | * Dummy class for converting Presentation documents into Openoffice-Textfiles. 28 | * @see JODConverterThumbnailer 29 | */ 30 | public class JODPowerpointConverterThumbnailer extends JODConverterThumbnailer { 31 | 32 | public JODPowerpointConverterThumbnailer() throws IOException { super(); } 33 | 34 | protected String getStandardOpenOfficeExtension() { 35 | return ".odp"; 36 | } 37 | 38 | protected String getStandardZipExtension() { 39 | return "pptx"; 40 | } 41 | protected String getStandardOfficeExtension() { 42 | return "ppt"; 43 | } 44 | 45 | 46 | /** 47 | * Get a List of accepted File Types. 48 | * All Presentation Office Formats that OpenOffice understands are accepted. 49 | * (ppt, pptx, pps, ppsx) 50 | * 51 | * @return MIME-Types 52 | * @see http://www.artofsolving.com/opensource/jodconverter/guide/supportedformats 53 | */ 54 | public String[] getAcceptedMIMETypes() 55 | { 56 | return new String[]{ 57 | "application/vnd.ms-powerpoint", 58 | "application/vnd.openxmlformats-officedocument.presentationml", 59 | "application/vnd.openxmlformats-officedocument.presentationml.presentation", 60 | /* "application/vnd.ms-office", // ppt? 61 | "application/zip" // pptx? */ 62 | 63 | }; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/thumbnailers/JODWordConverterThumbnailer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | */ 21 | 22 | package de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers; 23 | 24 | import java.io.IOException; 25 | 26 | /** 27 | * Dummy class for converting Text documents into Openoffice-Textfiles. 28 | * 29 | * Tika could be used to detect ms-word-files, but quite a heavy library. Maybe it would be useful as a preperator as well? 30 | * @see JODConverterThumbnailer 31 | */ 32 | public class JODWordConverterThumbnailer extends JODConverterThumbnailer { 33 | 34 | public JODWordConverterThumbnailer() throws IOException { super(); } 35 | 36 | protected String getStandardOpenOfficeExtension() { 37 | return ".odt"; 38 | } 39 | 40 | protected String getStandardZipExtension() { 41 | return "docx"; 42 | } 43 | protected String getStandardOfficeExtension() { 44 | return "doc"; 45 | } 46 | 47 | /** 48 | * Get a List of accepted File Types. 49 | * All Text Office Formats that OpenOffice understands are accepted. 50 | * (txt, rtf, doc, docx, wpd) 51 | * 52 | * @return MIME-Types 53 | * @see http://www.artofsolving.com/opensource/jodconverter/guide/supportedformats 54 | */ 55 | public String[] getAcceptedMIMETypes() 56 | { 57 | return new String[]{ 58 | "text/plain", 59 | "text/rtf", 60 | /* "application/msword", */ 61 | "application/vnd.ms-word", 62 | "application/vnd.openxmlformats-officedocument.wordprocessingml", 63 | "application/vnd.openxmlformats-officedocument.wordprocessingml.document", 64 | "application/wordperfect", 65 | /* "application/vnd.ms-office", // doc? 66 | "application/zip" // docx? */ 67 | }; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/thumbnailers/NativeImageThumbnailer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | */ 21 | 22 | package de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers; 23 | 24 | import java.io.File; 25 | import java.io.IOException; 26 | 27 | import javax.imageio.ImageIO; 28 | 29 | import de.uni_siegen.wineme.come_in.thumbnailer.ThumbnailerException; 30 | import de.uni_siegen.wineme.come_in.thumbnailer.UnsupportedInputFileFormatException; 31 | import de.uni_siegen.wineme.come_in.thumbnailer.util.ResizeImage; 32 | 33 | /** 34 | * This class uses Java Image I/O (Java's internal Image Processing library) in order to resize images. 35 | * JAI can be extended with extra Readers, this Thumbnailer will use all available image readers. 36 | * 37 | * Depends: 38 | *
  • JAI Image I/O Tools (optional, for TIFF support) (@see http://java.net/projects/imageio-ext/ - licence not gpl compatible I suspect ...) 39 | */ 40 | public class NativeImageThumbnailer extends AbstractThumbnailer { 41 | 42 | public void generateThumbnail(File input, File output) throws IOException, ThumbnailerException { 43 | ResizeImage resizer = new ResizeImage(thumbWidth, thumbHeight); 44 | 45 | try { 46 | resizer.setInputImage(input); 47 | } catch (UnsupportedInputFileFormatException e) { 48 | throw new ThumbnailerException("File format could not be interpreted as image", e); 49 | } 50 | resizer.writeOutput(output); 51 | } 52 | 53 | /** 54 | * Get a List of accepted File Types. 55 | * Normally, these are: bmp, jpg, wbmp, jpeg, png, gif 56 | * The exact list may depend on the Java installation. 57 | * 58 | * @return MIME-Types 59 | */ 60 | public String[] getAcceptedMIMETypes() 61 | { 62 | return ImageIO.getReaderMIMETypes(); 63 | } 64 | } -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/thumbnailers/OpenOfficeThumbnailer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | */ 21 | 22 | package de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers; 23 | 24 | import java.io.BufferedInputStream; 25 | import java.io.File; 26 | import java.io.IOException; 27 | import java.util.zip.ZipEntry; 28 | import java.util.zip.ZipException; 29 | import java.util.zip.ZipFile; 30 | 31 | import de.uni_siegen.wineme.come_in.thumbnailer.ThumbnailerException; 32 | import de.uni_siegen.wineme.come_in.thumbnailer.util.IOUtil; 33 | import de.uni_siegen.wineme.come_in.thumbnailer.util.ResizeImage; 34 | 35 | /** 36 | * This class extracts Thumbnails from OpenOffice-Files. 37 | * 38 | * Depends: 39 | *
  • NOT on OpenOffice, as the Thumbnail is already inside the file. (184x256px regardless of page orientation) 40 | * (So if the thumbnail generation is not correct, it's OpenOffice's fault, not our's :-) 41 | * 42 | */ 43 | public class OpenOfficeThumbnailer extends AbstractThumbnailer { 44 | 45 | @Override 46 | public void generateThumbnail(File input, File output) throws IOException, ThumbnailerException { 47 | BufferedInputStream in = null; 48 | ZipFile zipFile = null; 49 | 50 | try { 51 | zipFile = new ZipFile(input); 52 | } catch (ZipException e) { 53 | throw new ThumbnailerException("This is not a zipped file. Is this really an OpenOffice-File?", e); 54 | } 55 | 56 | try { 57 | ZipEntry entry = zipFile.getEntry("Thumbnails/thumbnail.png"); 58 | if (entry == null) 59 | throw new ThumbnailerException("Zip file does not contain 'Thumbnails/thumbnail.png' . Is this really an OpenOffice-File?"); 60 | 61 | in = new BufferedInputStream(zipFile.getInputStream(entry)); 62 | 63 | ResizeImage resizer = new ResizeImage(thumbWidth, thumbHeight); 64 | resizer.setInputImage(in); 65 | resizer.writeOutput(output); 66 | 67 | in.close(); 68 | } 69 | finally { 70 | IOUtil.quietlyClose(in); 71 | IOUtil.quietlyClose(zipFile); 72 | } 73 | } 74 | 75 | /** 76 | * Get a List of accepted File Types. 77 | * All OpenOffice Formats are accepted. 78 | * 79 | * @return MIME-Types 80 | */ 81 | public String[] getAcceptedMIMETypes() 82 | { 83 | return new String[] { 84 | "application/vnd.sun.xml.writer", 85 | "application/vnd.sun.xml.writer.template", 86 | "application/vnd.sun.xml.writer.global", 87 | "application/vnd.sun.xml.calc", 88 | "application/vnd.sun.xml.calc.template", 89 | "application/vnd.stardivision.calc", 90 | "application/vnd.sun.xml.impress", 91 | "application/vnd.sun.xml.impress.template ", 92 | "application/vnd.stardivision.impress sdd", 93 | "application/vnd.sun.xml.draw", 94 | "application/vnd.sun.xml.draw.template", 95 | "application/vnd.stardivision.draw", 96 | "application/vnd.sun.xml.math", 97 | "application/vnd.stardivision.math", 98 | "application/vnd.oasis.opendocument.text", 99 | "application/vnd.oasis.opendocument.text-template", 100 | "application/vnd.oasis.opendocument.text-web", 101 | "application/vnd.oasis.opendocument.text-master", 102 | "application/vnd.oasis.opendocument.graphics", 103 | "application/vnd.oasis.opendocument.graphics-template", 104 | "application/vnd.oasis.opendocument.presentation", 105 | "application/vnd.oasis.opendocument.presentation-template", 106 | "application/vnd.oasis.opendocument.spreadsheet", 107 | "application/vnd.oasis.opendocument.spreadsheet-template", 108 | "application/vnd.oasis.opendocument.chart", 109 | "application/vnd.oasis.opendocument.formula", 110 | "application/vnd.oasis.opendocument.database", 111 | "application/vnd.oasis.opendocument.image", 112 | 113 | "application/zip" /* Could be an OpenOffice file! */ 114 | }; 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/thumbnailers/PDFBoxThumbnailer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | */ 21 | 22 | package de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers; 23 | 24 | import java.awt.Color; 25 | import java.awt.Dimension; 26 | import java.awt.Graphics2D; 27 | import java.awt.image.BufferedImage; 28 | import java.awt.image.ImagingOpException; 29 | import java.io.File; 30 | import java.io.IOException; 31 | import java.util.List; 32 | 33 | import javax.imageio.ImageIO; 34 | 35 | import org.apache.commons.io.FileUtils; 36 | import org.apache.pdfbox.pdfviewer.PageDrawer; 37 | import org.apache.pdfbox.pdmodel.PDDocument; 38 | import org.apache.pdfbox.pdmodel.PDPage; 39 | import org.apache.pdfbox.pdmodel.common.PDRectangle; 40 | 41 | import de.uni_siegen.wineme.come_in.thumbnailer.FileDoesNotExistException; 42 | import de.uni_siegen.wineme.come_in.thumbnailer.ThumbnailerException; 43 | import de.uni_siegen.wineme.come_in.thumbnailer.util.ResizeImage; 44 | 45 | /** 46 | * Renders the first page of a PDF file into a thumbnail. 47 | * 48 | * Performance note: This takes about 2-3 seconds per file. 49 | * (TODO : Try to override PDPage.convertToImage - this is where the heavy lifting takes place) 50 | * 51 | * Depends on: 52 | *
  • PDFBox (>= 1.5.0) 53 | */ 54 | public class PDFBoxThumbnailer extends AbstractThumbnailer { 55 | 56 | private static final Color TRANSPARENT_WHITE = new Color(255, 255, 255, 0); 57 | 58 | @Override 59 | public void generateThumbnail(File input, File output) throws IOException, 60 | ThumbnailerException { 61 | FileDoesNotExistException.check(input); 62 | if (input.length() == 0) 63 | throw new FileDoesNotExistException("File is empty"); 64 | FileUtils.deleteQuietly(output); 65 | 66 | PDDocument document = null; 67 | try 68 | { 69 | try { 70 | document = PDDocument.load(input); 71 | } catch (IOException e) { 72 | throw new ThumbnailerException("Could not load PDF File", e); 73 | } 74 | 75 | BufferedImage tmpImage = writeImageFirstPage(document, BufferedImage.TYPE_INT_RGB); 76 | 77 | if (tmpImage.getWidth() == thumbWidth) 78 | { 79 | ImageIO.write(tmpImage, "PNG", output); 80 | } 81 | else 82 | { 83 | ResizeImage resizer = new ResizeImage(thumbWidth, thumbHeight); 84 | resizer.resizeMethod = ResizeImage.NO_RESIZE_ONLY_CROP; 85 | resizer.setInputImage(tmpImage); 86 | resizer.writeOutput(output); 87 | } 88 | } 89 | finally 90 | { 91 | if( document != null ) 92 | { 93 | try { 94 | document.close(); 95 | } catch (IOException e) {} 96 | } 97 | } 98 | } 99 | 100 | /** 101 | * Loosely based on the commandline-Tool PDFImageWriter 102 | * @param document 103 | * @param imageType 104 | * @return 105 | * @throws IOException 106 | */ 107 | private BufferedImage writeImageFirstPage(PDDocument document, int imageType) 108 | throws IOException 109 | { 110 | List pages = document.getDocumentCatalog().getAllPages(); 111 | 112 | PDPage page = (PDPage)pages.get(0); 113 | 114 | // resolution: Unfortunately, the resolution is in integer in the call ... so we approximate by taking slightly less (rounding down). 115 | /* Before: 116 | PDRectangle rect = page.getMediaBox(); 117 | float resolution = (thumb_width / rect.getWidth() * 72); 118 | page.convertToImage(imageType, (int) resolution); 119 | */ 120 | 121 | // Here is the main work: 122 | BufferedImage image = convertToImage(page, imageType, thumbWidth, thumbHeight); 123 | 124 | return image; 125 | } 126 | 127 | /* */ private BufferedImage convertToImage(PDPage page, int imageType, int thumbWidth, int thumbHeight) 128 | /* */ throws IOException 129 | /* */ { 130 | /* 707 */ PDRectangle mBox = page.findMediaBox(); 131 | /* 708 */ float widthPt = mBox.getWidth(); 132 | /* 709 */ float heightPt = mBox.getHeight(); 133 | /* 711 */ int widthPx = thumbWidth; // Math.round(widthPt * scaling); 134 | /* 712 */ int heightPx = thumbHeight; // Math.round(heightPt * scaling); 135 | /* 710 */ float scaling = thumbWidth / widthPt; // resolution / 72.0F; 136 | /* */ 137 | /* 714 */ Dimension pageDimension = new Dimension((int) widthPt, (int) heightPt); 138 | /* */ 139 | /* 716 */ BufferedImage retval = new BufferedImage(widthPx, heightPx, imageType); 140 | /* 717 */ Graphics2D graphics = (Graphics2D)retval.getGraphics(); 141 | /* 718 */ graphics.setBackground(TRANSPARENT_WHITE); 142 | /* 719 */ graphics.clearRect(0, 0, retval.getWidth(), retval.getHeight()); 143 | /* 720 */ graphics.scale(scaling, scaling); 144 | /* 721 */ PageDrawer drawer = new PageDrawer(); 145 | /* 722 */ drawer.drawPage(graphics, page, pageDimension); 146 | /* */ try 147 | /* */ { 148 | /* 728 */ int rotation = page.findRotation(); 149 | /* 729 */ if ((rotation == 90) || (rotation == 270)) 150 | /* */ { 151 | /* 731 */ int w = retval.getWidth(); 152 | /* 732 */ int h = retval.getHeight(); 153 | /* 733 */ BufferedImage rotatedImg = new BufferedImage(w, h, retval.getType()); 154 | /* 734 */ Graphics2D g = rotatedImg.createGraphics(); 155 | /* 735 */ g.rotate(Math.toRadians(rotation), w / 2, h / 2); 156 | /* 736 */ g.drawImage(retval, null, 0, 0); 157 | /* */ } 158 | /* */ } 159 | /* */ catch (ImagingOpException e) 160 | /* */ { 161 | /* 741 */ //log.warn("Unable to rotate page image", e); 162 | /* */ } 163 | /* */ 164 | /* 744 */ return retval; 165 | /* */ } 166 | 167 | /** 168 | * Get a List of accepted File Types. 169 | * Only PDF Files are accepted. 170 | * 171 | * @return MIME-Types 172 | */ 173 | public String[] getAcceptedMIMETypes() 174 | { 175 | return new String[]{ 176 | "application/pdf" 177 | }; 178 | } 179 | 180 | 181 | } 182 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/thumbnailers/ScratchThumbnailer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | */ 21 | 22 | package de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers; 23 | 24 | import java.awt.image.BufferedImage; 25 | import java.io.File; 26 | import java.io.FileInputStream; 27 | import java.io.IOException; 28 | import java.util.Hashtable; 29 | import java.util.Map.Entry; 30 | 31 | import de.uni_siegen.wineme.come_in.thumbnailer.ThumbnailerException; 32 | import de.uni_siegen.wineme.come_in.thumbnailer.util.IOUtil; 33 | import de.uni_siegen.wineme.come_in.thumbnailer.util.ResizeImage; 34 | import de.uni_siegen.wineme.come_in.thumbnailer.util.mime.ScratchFileIdentifier; 35 | 36 | import edu.mit.scratch.*; 37 | 38 | /** 39 | * This Thumbnailer extracts the Thumbnail from Scratch files. 40 | * This Thumbnail is generated from the start screen of the project. 41 | * 42 | * (Scratch is a visual programming language for children.) 43 | * @author Benjamin 44 | * @TODO invent MIME type for scratch projects? 45 | * 46 | * Depends on: 47 | *
  • ScratchApplet (needs modification: Move all classes to package "edu.mit.scratch" and make ObjReader public). 48 | */ 49 | public class ScratchThumbnailer extends AbstractThumbnailer { 50 | 51 | /** 52 | * Generate a thumbnail from a Scratch file. 53 | * 54 | * Adapted from GetThumbnail version 1.1, Jan Rochat 2009 55 | * @see http://scratch.mit.edu/forums/viewtopic.php?id=13463 56 | * 57 | * @param input Scratch file to process 58 | * @param output Where to save the thumbnail 59 | * @throws ThumbnailerException If input is not a scratch file 60 | * @throws IOException If output cannot be written. 61 | */ 62 | public void generateThumbnail(File input, File output) throws ThumbnailerException, IOException 63 | { 64 | FileInputStream in = null; 65 | try { 66 | in = new FileInputStream(input); 67 | ObjReader reader = new ObjReader(in); 68 | 69 | Hashtable parsedScratchFile; 70 | try { 71 | parsedScratchFile = reader.readInfo(); 72 | } catch (IOException e) { 73 | throw new ThumbnailerException("Error - Is this really a scratch project file?"); 74 | } 75 | 76 | BufferedImage image = (BufferedImage) parsedScratchFile.get("thumbnail"); 77 | 78 | /* Output internal data of Scratch files for debug purposes 79 | 80 | debugOutputHashtable(parsedScratchFile); 81 | 82 | // Rewind 83 | in = new FileInputStream(input); 84 | reader = new ObjReader(in); 85 | 86 | debugOutputObjects(reader.readObjects(null)); 87 | */ 88 | 89 | ResizeImage imageResizer = new ResizeImage(thumbWidth, thumbHeight); 90 | imageResizer.setInputImage(image); 91 | imageResizer.writeOutput(output); 92 | } finally { 93 | IOUtil.quietlyClose(in); 94 | } 95 | } 96 | 97 | @SuppressWarnings("unused") 98 | private void debugOutputObjects(Object[][] readObjects) { 99 | for (int i = 0; i < readObjects.length; i++) 100 | { 101 | for (int j = 0; j < readObjects[i].length; j++) 102 | { 103 | String str = readObjects[i][j].toString(); 104 | if (!(readObjects[i][j] instanceof String)) 105 | str = readObjects[i][j].getClass().getName() + ":" + str; 106 | System.out.println("obj[" + i + "][" + j + "]: " + readObjects[i][j]); 107 | } 108 | } 109 | } 110 | 111 | @SuppressWarnings("unused") 112 | private void debugOutputHashtable(Hashtable parsedScratchFile) { 113 | for (Entry key : parsedScratchFile.entrySet()) 114 | { 115 | System.out.println("Key: " + key.getKey() + " Value: " + key.getValue()); 116 | } 117 | } 118 | 119 | /** 120 | * Get a list of all MIME Types that this Thumbnailer is ready to process. 121 | * You should override this method in order to give hints when which Thumbnailer is most appropriate. 122 | * If you do not override this method, the Thumbnailer will be called in any case - awaiting a ThumbnailException if 123 | * this thumbnailer cannot treat such a file. 124 | * 125 | * @return List of MIME Types. If null, all Files may be passed to this Thumbnailer. 126 | */ 127 | public String[] getAcceptedMIMETypes() 128 | { 129 | return new String[]{ScratchFileIdentifier.SCRATCH_MIME_TYPE}; 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/thumbnailers/Thumbnailer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | */ 21 | 22 | package de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers; 23 | 24 | import java.io.Closeable; 25 | import java.io.File; 26 | import java.io.IOException; 27 | 28 | import de.uni_siegen.wineme.come_in.thumbnailer.ThumbnailerException; 29 | 30 | /** 31 | * This interface is implemented by any method suitable to create a thumbnail of a given File. 32 | * @author Benjamin 33 | */ 34 | public interface Thumbnailer extends Closeable { 35 | 36 | /** 37 | * Generate a Thumbnail of the input file. 38 | * 39 | * @param input Input file that should be processed 40 | * @param output File in which should be written 41 | * @param mimeType MIME-Type of input file (null if unknown) 42 | * @throws IOException If file cannot be read/written 43 | * @throws ThumbnailerException If the thumbnailing process failed. 44 | */ 45 | public void generateThumbnail(File input, File output, String mimeType) throws IOException, ThumbnailerException; 46 | 47 | /** 48 | * Generate a Thumbnail of the input file. 49 | * 50 | * @param input Input file that should be processed 51 | * @param output File in which should be written 52 | * @throws IOException If file cannot be read/written 53 | * @throws ThumbnailerException If the thumbnailing process failed. 54 | */ 55 | public void generateThumbnail(File input, File output) throws IOException, ThumbnailerException; 56 | 57 | /** 58 | * This function will be called after all Thumbnails are generated. 59 | * Note: This acts as a Deconstructor. Do not expect this object to work 60 | * after calling this method. 61 | * 62 | * @throws IOException If some errors occured during finalising 63 | */ 64 | public void close() throws IOException; 65 | 66 | 67 | /** 68 | * Set a new Thumbnail size. All following thumbnails will be generated in this size. 69 | * 70 | * @param width Width in Pixel 71 | * @param height Height in Pixel 72 | * @param imageResizeOptions Options for ResizeImage (currently ignored) 73 | */ 74 | public void setImageSize(int width, int height, int imageResizeOptions); 75 | 76 | /** 77 | * Get the currently set Image Width of this Thumbnailer. 78 | * @return image width of created thumbnails. 79 | */ 80 | public int getCurrentImageWidth(); 81 | 82 | /** 83 | * Get the currently set Image Height of this Thumbnailer. 84 | * @return image height of created thumbnails. 85 | */ 86 | public int getCurrentImageHeight(); 87 | 88 | /** 89 | * Get a list of all MIME Types that this Thumbnailer is ready to process. 90 | * 91 | * @return List of MIME Types. If null, all Files may be passed to this Thumbnailer. 92 | */ 93 | public String[] getAcceptedMIMETypes(); 94 | } 95 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/util/IOUtil.java: -------------------------------------------------------------------------------- 1 | package de.uni_siegen.wineme.come_in.thumbnailer.util; 2 | 3 | import java.io.Closeable; 4 | import java.io.File; 5 | import java.io.IOException; 6 | import java.util.zip.ZipFile; 7 | 8 | public class IOUtil { 9 | /** 10 | * Close, ignoring IOExceptions 11 | * @param stream Stream to be closed. May be null (in this case, nothing is done). 12 | * @see Apache I/O Utils 13 | */ 14 | public static void quietlyClose(Closeable stream) 15 | { 16 | try 17 | { 18 | if (stream != null) 19 | stream.close(); 20 | } 21 | catch (IOException e) 22 | { 23 | // Ignore 24 | } 25 | } 26 | 27 | public static void quietlyClose(ZipFile zipFile) { 28 | try 29 | { 30 | if (zipFile != null) 31 | zipFile.close(); 32 | } 33 | catch (IOException e) 34 | { 35 | // Ignore 36 | } 37 | } 38 | 39 | public static void deleteQuietlyForce(File file) 40 | { 41 | if (file != null) 42 | { 43 | if(!file.delete()) 44 | { 45 | if (file.exists()) 46 | file.deleteOnExit(); 47 | } 48 | } 49 | } 50 | 51 | // More difficult than I thought. See http://www.java2s.com/Code/Java/File-Input-Output/Getrelativepath.htm and http://stackoverflow.com/questions/204784/how-to-construct-a-relative-path-in-java-from-two-absolute-paths-or-urls 52 | /** 53 | * Simplistic version: return the substring after the base 54 | */ 55 | public static String getRelativeFilename(File base, File target) { 56 | return getRelativeFilename(base.getAbsolutePath(), target.getAbsolutePath()); 57 | } 58 | 59 | public static String getRelativeFilename(String sBase, String sTarget) { 60 | if (sTarget.startsWith(sBase)) 61 | { 62 | if (sBase.endsWith("/") || sBase.endsWith("\\") || sTarget.length() == sBase.length()) 63 | return sTarget.substring(sBase.length()); 64 | else 65 | return sTarget.substring(sBase.length() + 1); 66 | } 67 | else 68 | return sTarget; // Leave absolute 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/util/Platform.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | */ 21 | 22 | package de.uni_siegen.wineme.come_in.thumbnailer.util; 23 | 24 | /** 25 | * Detect Platform. 26 | * @author Benjamin 27 | */ 28 | 29 | public class Platform { 30 | 31 | public static final int UNKNOWN = -1; 32 | 33 | public static final int WINDOWS = 0; 34 | 35 | public static final int UNIX_BEGIN = 10; 36 | public static final int MAC = 10; 37 | public static final int LINUX = 11; 38 | public static final int BSD = 12; 39 | public static final int UNIX_END = 19; 40 | 41 | private static int detectedPlatform; 42 | 43 | static 44 | { 45 | String os = System.getProperty("os.name"); 46 | if (os.contains("indows")) 47 | detectedPlatform = WINDOWS; 48 | else if (os.contains("Mac")) 49 | detectedPlatform = MAC; 50 | else if (os.contains("Linux")) 51 | detectedPlatform = LINUX; 52 | else if (os.contains("BSD")) 53 | detectedPlatform = BSD; 54 | else 55 | detectedPlatform = UNKNOWN; 56 | } 57 | 58 | public static boolean isWindows() 59 | { 60 | return detectedPlatform == WINDOWS; 61 | } 62 | 63 | public static boolean isLinux() 64 | { 65 | return detectedPlatform == LINUX; 66 | } 67 | 68 | public static boolean isMac() 69 | { 70 | return detectedPlatform == MAC; 71 | } 72 | 73 | public static boolean isUnix() 74 | { 75 | return detectedPlatform >= UNIX_BEGIN && detectedPlatform >= UNIX_END; 76 | } 77 | 78 | public static int getDetectedPlatform() 79 | { 80 | return detectedPlatform; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/util/ResizeImage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | */ 21 | 22 | package de.uni_siegen.wineme.come_in.thumbnailer.util; 23 | 24 | import java.awt.Color; 25 | import java.awt.Graphics2D; 26 | import java.awt.RenderingHints; 27 | import java.awt.image.BufferedImage; 28 | import java.io.File; 29 | import java.io.IOException; 30 | import java.io.InputStream; 31 | 32 | import javax.imageio.ImageIO; 33 | 34 | import org.apache.log4j.Logger; 35 | 36 | import de.uni_siegen.wineme.come_in.thumbnailer.UnsupportedInputFileFormatException; 37 | 38 | /** 39 | * Resize an image. 40 | * 41 | * @author Benjamin 42 | * @TODO Comment. Refactor?? (3 lines of code per generation) 43 | */ 44 | public class ResizeImage { 45 | 46 | /** The logger for this class */ 47 | private static final Logger mLog = Logger.getLogger(ResizeImage.class); 48 | 49 | 50 | BufferedImage inputImage; 51 | private boolean isProcessed = false; 52 | BufferedImage outputImage; 53 | 54 | private int imageWidth; 55 | private int imageHeight; 56 | private int thumbWidth; 57 | private int thumbHeight; 58 | private double resizeRatio = 1.0; 59 | 60 | /** 61 | * Scale input image so that width and height is equal (or smaller) to the output size. 62 | * The other dimension will be smaller or equal than the output size. 63 | */ 64 | public static final int RESIZE_FIT_BOTH_DIMENSIONS = 2; 65 | 66 | /** 67 | * Scale input image so that width or height is equal to the output size. 68 | * The other dimension will be bigger or equal than the output size. 69 | */ 70 | public static final int RESIZE_FIT_ONE_DIMENSION = 3; 71 | 72 | /** 73 | * Do not resize the image. Instead, crop the image (if smaller) or center it (if bigger) 74 | */ 75 | public static final int NO_RESIZE_ONLY_CROP = 4; 76 | 77 | /** 78 | * Do not try to scale the image up, only down. If bigger, center it. 79 | */ 80 | public static final int DO_NOT_SCALE_UP = 16; 81 | 82 | /** 83 | * If output image is bigger than input image, allow the output to be smaller than expected (the size of the input image) 84 | */ 85 | public static final int ALLOW_SMALLER = 32; 86 | 87 | public int resizeMethod = RESIZE_FIT_ONE_DIMENSION; 88 | public int extraOptions = DO_NOT_SCALE_UP; 89 | 90 | private int scaledWidth; 91 | private int scaledHeight; 92 | private int offsetX; 93 | private int offsetY; 94 | 95 | 96 | 97 | public ResizeImage(int thumbWidth, int thumbHeight) 98 | { 99 | this.thumbWidth = thumbWidth; 100 | this.thumbHeight = thumbHeight; 101 | } 102 | 103 | public void setInputImage(File input) throws IOException 104 | { 105 | BufferedImage image = ImageIO.read(input); 106 | setInputImage(image); 107 | } 108 | 109 | public void setInputImage(InputStream input) throws IOException 110 | { 111 | BufferedImage image = ImageIO.read(input); 112 | setInputImage(image); 113 | } 114 | 115 | public void setInputImage(BufferedImage input) throws UnsupportedInputFileFormatException 116 | { 117 | if (input == null) 118 | throw new UnsupportedInputFileFormatException("The image reader could not open the file."); 119 | 120 | this.inputImage = input; 121 | isProcessed = false; 122 | imageWidth = inputImage.getWidth(null); 123 | imageHeight = inputImage.getHeight(null); 124 | } 125 | 126 | public void writeOutput(File output) throws IOException 127 | { 128 | writeOutput(output, "PNG"); 129 | } 130 | 131 | public void writeOutput(File output, String format) throws IOException 132 | { 133 | if (!isProcessed) 134 | process(); 135 | 136 | ImageIO.write(outputImage, format, output); 137 | } 138 | 139 | private void process() 140 | { 141 | if (imageWidth == thumbWidth && imageHeight == thumbHeight) 142 | outputImage = inputImage; 143 | else 144 | { 145 | calcDimensions(resizeMethod); 146 | paint(); 147 | } 148 | 149 | isProcessed = true; 150 | } 151 | 152 | private void calcDimensions(int resizeMethod) 153 | { 154 | switch (resizeMethod) 155 | { 156 | case RESIZE_FIT_BOTH_DIMENSIONS: 157 | resizeRatio = Math.min(((double) thumbWidth) / imageWidth, ((double) thumbHeight) / imageHeight); 158 | break; 159 | 160 | case RESIZE_FIT_ONE_DIMENSION: 161 | resizeRatio = Math.max(((double) thumbWidth) / imageWidth, ((double) thumbHeight) / imageHeight); 162 | break; 163 | 164 | case NO_RESIZE_ONLY_CROP: 165 | resizeRatio = 1.0; 166 | break; 167 | } 168 | if ((extraOptions & DO_NOT_SCALE_UP) > 0) 169 | if (resizeRatio > 1.0) 170 | resizeRatio = 1.0; 171 | 172 | 173 | scaledWidth = (int) Math.round(imageWidth * resizeRatio); 174 | scaledHeight = (int) Math.round(imageHeight * resizeRatio); 175 | 176 | if ((extraOptions & ALLOW_SMALLER) > 0) { 177 | if (scaledWidth < thumbWidth && scaledHeight < thumbHeight) 178 | { 179 | thumbWidth = scaledWidth; 180 | thumbHeight = scaledHeight; 181 | } 182 | } 183 | 184 | // Center if smaller. 185 | if (scaledWidth < thumbWidth) 186 | offsetX = (thumbWidth - scaledWidth) / 2; 187 | else 188 | offsetX = 0; 189 | 190 | if (scaledHeight < thumbHeight) 191 | offsetY = (thumbHeight - scaledHeight) / 2; 192 | else 193 | offsetY = 0; 194 | } 195 | 196 | private void paint() 197 | { 198 | outputImage = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_ARGB); 199 | 200 | Graphics2D graphics2D = outputImage.createGraphics(); 201 | 202 | // Fill background with white color 203 | graphics2D.setBackground(Color.WHITE); 204 | graphics2D.setPaint(Color.WHITE); 205 | graphics2D.fillRect(0, 0, thumbWidth, thumbHeight); 206 | 207 | // Enable smooth, high-quality resampling 208 | graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); 209 | 210 | ThumbnailReadyObserver observer = new ThumbnailReadyObserver(Thread.currentThread()); 211 | boolean scalingComplete = graphics2D.drawImage(inputImage, offsetX, offsetY, scaledWidth, scaledHeight, observer); 212 | 213 | if (!scalingComplete && observer != null) 214 | { 215 | // ImageObserver must wait for ready 216 | if (mLog.isDebugEnabled()) 217 | throw new RuntimeException("Scaling is not yet complete!"); 218 | else 219 | { 220 | mLog.warn("ResizeImage: Scaling is not yet complete!"); 221 | 222 | while(!observer.ready) 223 | { 224 | System.err.println("Waiting .4 sec..."); 225 | try { 226 | Thread.sleep(400); 227 | } catch (InterruptedException e) { 228 | } 229 | } 230 | } 231 | } 232 | 233 | graphics2D.dispose(); 234 | } 235 | } 236 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/util/StringUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | */ 21 | 22 | package de.uni_siegen.wineme.come_in.thumbnailer.util; 23 | 24 | import java.math.BigInteger; 25 | import java.security.MessageDigest; 26 | import java.security.NoSuchAlgorithmException; 27 | import java.util.Random; 28 | 29 | public class StringUtil { 30 | static Random rand = new Random(); 31 | static String alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"; 32 | 33 | /** 34 | * Create a random ASCII-String consisting of a certain number of chars. 35 | * 36 | * @param numChars How many chars should the string have 37 | * @return Random String 38 | */ 39 | public static String randomString(int numChars) 40 | { 41 | StringBuilder sb = new StringBuilder(); 42 | for (int i = 0; i < numChars; i++) { 43 | sb.append(alphabet.charAt(rand.nextInt(alphabet.length()))); 44 | } 45 | return sb.toString(); 46 | } 47 | 48 | /** 49 | * Transpose a string from Hex into 36-Base string. 50 | * @param str String of a Base-16-Number (e.g., MD5-Hash) 51 | * @return Equivalent of it as 36-Base-Number (less characters) 52 | */ 53 | public static String transposeString(String str) 54 | { 55 | BigInteger bi = new BigInteger(str, 16); 56 | return bi.toString(Character.MAX_RADIX); 57 | } 58 | 59 | /** 60 | * Create an MD5 Hash of an input String. 61 | * Uses the MD5 Algorithm of MessageDigest. 62 | * @param input String to Hash 63 | * @return Hash (Hex-Encoded) 64 | */ 65 | public static String md5(String input){ 66 | StringBuilder res = new StringBuilder(); 67 | try { 68 | MessageDigest algorithm = MessageDigest.getInstance("MD5"); 69 | algorithm.reset(); 70 | algorithm.update(input.getBytes()); 71 | byte[] md5 = algorithm.digest(); 72 | String tmp = ""; 73 | for (int i = 0; i < md5.length; i++) { 74 | tmp = (Integer.toHexString(0xFF & md5[i])); 75 | if (tmp.length() == 1) { 76 | res.append("0").append(tmp); 77 | } else { 78 | res.append(tmp); 79 | } 80 | } 81 | } catch (NoSuchAlgorithmException ex) { return ""; } 82 | return res.toString(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/util/TemporaryFilesManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2012 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | */ 21 | package de.uni_siegen.wineme.come_in.thumbnailer.util; 22 | 23 | import java.io.File; 24 | import java.io.IOException; 25 | import java.util.HashMap; 26 | 27 | import org.apache.commons.io.FileUtils; 28 | import org.apache.commons.io.FilenameUtils; 29 | 30 | /** 31 | * Keep a list of temporary files so that the same file needn't be copied twice. 32 | */ 33 | public class TemporaryFilesManager { 34 | private HashMap files = new HashMap(); 35 | 36 | /** 37 | * Create a new, read-only temporary file. 38 | * 39 | * @param file Original file that you need a copy of 40 | * @param newExtension The extension that the new file should have 41 | * @return File (read-only) 42 | * @throws IOException 43 | */ 44 | public File createTempfileCopy(File file, String newExtension) throws IOException 45 | { 46 | File destFile = files.get(file); 47 | if (destFile == null) 48 | { 49 | destFile = File.createTempFile("temp", "." + newExtension); 50 | createNewCopy(file, destFile); 51 | destFile.setWritable(false, false); 52 | } 53 | else 54 | { 55 | String newFilename = FilenameUtils.removeExtension(destFile.getAbsolutePath()) + "." + newExtension; 56 | File newFile = new File(newFilename); 57 | boolean renameSucces = destFile.renameTo(newFile); 58 | if (!renameSucces) 59 | { 60 | createNewCopy(file, newFile); 61 | } 62 | files.put(file, newFile); 63 | destFile = newFile; 64 | } 65 | return destFile; 66 | } 67 | 68 | private void createNewCopy(File file, File destFile) 69 | throws IOException { 70 | FileUtils.copyFile(file, destFile); 71 | files.put(file, destFile); 72 | } 73 | 74 | /** 75 | * Delete all registered temporary files 76 | */ 77 | public void deleteAllTempfiles() { 78 | for (File destFile : files.values()) 79 | { 80 | IOUtil.deleteQuietlyForce(destFile); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/util/ThumbnailReadyObserver.java: -------------------------------------------------------------------------------- 1 | package de.uni_siegen.wineme.come_in.thumbnailer.util; 2 | 3 | import java.awt.Image; 4 | import java.awt.image.ImageObserver; 5 | 6 | import org.apache.log4j.Logger; 7 | 8 | /** 9 | * Not quite sure if this is necessary: 10 | * This is intended to give awt a chance to draw image asynchronously. 11 | * 12 | * @author Benjamin 13 | */ 14 | public class ThumbnailReadyObserver implements ImageObserver { 15 | 16 | private Thread toNotify; 17 | 18 | /** The logger for this class */ 19 | private final static Logger mLog = Logger.getLogger(ThumbnailReadyObserver.class); 20 | 21 | public volatile boolean ready = false; 22 | 23 | public ThumbnailReadyObserver(Thread toNotify) 24 | { 25 | this.toNotify = toNotify; 26 | ready = false; 27 | } 28 | 29 | public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { 30 | 31 | mLog.info("Observer debug info: imageUpdate: " + infoflags); 32 | if ((infoflags & ImageObserver.ALLBITS) > 0) 33 | { 34 | ready = true; 35 | mLog.info("Observer says: Now ready!"); 36 | toNotify.notify(); 37 | return true; 38 | } 39 | return false; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/util/mime/DocFileIdentifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | * 21 | * Concept from Nuxeo: 22 | * Licenced LGPL 2.1 23 | * (C) Copyright 2006-2007 Nuxeo SAS (http://nuxeo.com/) and contributors. 24 | */ 25 | 26 | package de.uni_siegen.wineme.come_in.thumbnailer.util.mime; 27 | 28 | import java.io.File; 29 | import java.io.FileInputStream; 30 | 31 | import org.apache.poi.hwpf.HWPFDocument; 32 | 33 | public class DocFileIdentifier extends OfficeFileIdentifier 34 | { 35 | public DocFileIdentifier() 36 | { 37 | super(); 38 | ext.add("doc"); 39 | } 40 | 41 | @Override 42 | public String identify(String mimeType, byte[] bytes, File file) { 43 | 44 | if (isOfficeFile(mimeType) && !DOC_MIME_TYPE.equals(mimeType)) 45 | { 46 | try { 47 | FileInputStream stream = new FileInputStream(file); 48 | HWPFDocument document = new HWPFDocument(stream); 49 | 50 | if (document.getRange().getEndOffset() > 0) { 51 | return DOC_MIME_TYPE; 52 | } 53 | } catch (Throwable e) { 54 | } 55 | } 56 | 57 | return mimeType; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/util/mime/MimeTypeDetector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | */ 21 | 22 | package de.uni_siegen.wineme.come_in.thumbnailer.util.mime; 23 | 24 | import java.io.File; 25 | import java.io.FileInputStream; 26 | import java.io.IOException; 27 | import java.util.ArrayList; 28 | import java.util.HashMap; 29 | import java.util.List; 30 | import java.util.Map; 31 | 32 | import org.apache.log4j.Logger; 33 | import org.ontoware.rdf2go.model.node.impl.URIImpl; 34 | import org.semanticdesktop.aperture.mime.identifier.magic.MagicMimeTypeIdentifier; 35 | import org.semanticdesktop.aperture.mime.identifier.magic.MagicMimeTypeIdentifierFactory; 36 | 37 | import de.uni_siegen.wineme.come_in.thumbnailer.util.IOUtil; 38 | 39 | /** 40 | * Wrapper class for MIME Identification of Files. 41 | * 42 | * Depends: 43 | *
  • Aperture (for MIME-Detection) 44 | */ 45 | public class MimeTypeDetector { 46 | 47 | private MagicMimeTypeIdentifier mimeTypeIdentifier; 48 | 49 | private List extraIdentifiers; 50 | 51 | private static Logger mLog = Logger.getLogger(MimeTypeDetector.class); 52 | 53 | /** 54 | * Create a MimeType Detector and init it. 55 | */ 56 | public MimeTypeDetector() 57 | { 58 | MagicMimeTypeIdentifierFactory mimeTypeFactory = new MagicMimeTypeIdentifierFactory(); 59 | mimeTypeIdentifier = (MagicMimeTypeIdentifier) mimeTypeFactory.get(); 60 | 61 | extraIdentifiers = new ArrayList(); 62 | 63 | addMimeTypeIdentifier(new ScratchFileIdentifier()); 64 | addMimeTypeIdentifier(new Office2007FileIdentifier()); 65 | addMimeTypeIdentifier(new PptFileIdentifier()); 66 | addMimeTypeIdentifier(new XlsFileIdentifier()); 67 | addMimeTypeIdentifier(new DocFileIdentifier()); 68 | } 69 | 70 | /** 71 | * Add a new MimeTypeIdentifier to this Detector. 72 | * MimeTypeIdentifier may override the decision of the detector. 73 | * The order the identifiers are added will also be the order they will be executed 74 | * (i.e., the last identifiers may override all others.) 75 | * 76 | * @param identifier a new MimeTypeIdentifier 77 | */ 78 | public void addMimeTypeIdentifier(MimeTypeIdentifier identifier) 79 | { 80 | extraIdentifiers.add(identifier); 81 | } 82 | 83 | /** 84 | * Detect MIME-Type for this file. 85 | * 86 | * @param file File to analyse 87 | * @return String of MIME-Type, or null if no detection was possible (or unknown MIME Type) 88 | */ 89 | public String getMimeType(File file) 90 | { 91 | byte[] bytes = new byte[mimeTypeIdentifier.getMinArrayLength()]; 92 | 93 | FileInputStream fis = null; 94 | try { 95 | fis = new FileInputStream(file); 96 | fis.read(bytes); 97 | fis.close(); 98 | fis = null; 99 | } catch (IOException e) { 100 | return null; // File does not exist or other I/O Error 101 | } finally { 102 | IOUtil.quietlyClose(fis); 103 | } 104 | String file_url = file.toURI().toASCIIString(); 105 | String mimeType = mimeTypeIdentifier.identify(bytes, file.getPath(), new URIImpl(file_url)) ; 106 | 107 | /* I don't see any effect of this 108 | if (mimeType != null && mimeType.equalsIgnoreCase("application/zip")) { 109 | mLog.info("Is a zip-file. Try second round-detection ..."); 110 | // some new files like MS Office documents are zip files 111 | // so rewrite the URL for the correct mimetype detection 112 | mimeType = mimeTypeIdentifier.identify(bytes, null, new URIImpl("zip:mime:" + file_url)); 113 | } 114 | */ 115 | 116 | if (mimeType != null && mimeType.length() == 0) 117 | mimeType = null; 118 | 119 | // Identifiers may re-write MIME. 120 | for (MimeTypeIdentifier identifier : extraIdentifiers) 121 | mimeType = identifier.identify(mimeType, bytes, file); 122 | 123 | mLog.info("Detected MIME-Type of " + file.getName() + " is " + mimeType); 124 | return mimeType; 125 | } 126 | 127 | /** 128 | * Return the standard extension of a specific MIME-Type. 129 | * What are these files "normally" called? 130 | * 131 | * @param mimeType MIME-Type, e.g. "text/plain" 132 | * @return Extension, e.g. "txt" 133 | */ 134 | public String getStandardExtensionForMimeType(String mimeType) 135 | { 136 | List extensions = getExtensionsCached(mimeType); 137 | 138 | if (extensions == null) 139 | return null; 140 | 141 | try { 142 | return extensions.get(0); 143 | } catch (IndexOutOfBoundsException e) { 144 | return null; 145 | } 146 | } 147 | 148 | Map> extensionsCache = new HashMap>(); 149 | 150 | @SuppressWarnings("unchecked") 151 | protected List getExtensionsCached(String mimeType) { 152 | List extensions = extensionsCache.get(mimeType); 153 | if (extensions != null) 154 | return extensions; 155 | 156 | extensions = (List) mimeTypeIdentifier.getExtensionsFor(mimeType); 157 | 158 | for (MimeTypeIdentifier identifier : extraIdentifiers) 159 | { 160 | if (extensions != null) 161 | return extensions; 162 | 163 | extensions = identifier.getExtensionsFor(mimeType); 164 | } 165 | 166 | extensionsCache.put(mimeType, extensions); 167 | return extensions; 168 | } 169 | 170 | /** 171 | * Test if an given extension can contain a File of MIME-Type 172 | * @param extension Filename extension (e.g. "txt") 173 | * @param mimeType MIME-Type (e.g. "text/plain") 174 | * @return True if compatible. 175 | */ 176 | public boolean doesExtensionMatchMimeType(String extension, String mimeType) 177 | { 178 | List extensions = getExtensionsCached(mimeType); 179 | 180 | if (extensions == null) 181 | return false; 182 | 183 | return extensions.contains(extension); 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/util/mime/MimeTypeIdentifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | */ 21 | 22 | package de.uni_siegen.wineme.come_in.thumbnailer.util.mime; 23 | 24 | import java.io.File; 25 | import java.util.List; 26 | 27 | /** 28 | * Helper Classes for MimeTypeDetector. 29 | * @author Benjamin 30 | */ 31 | public interface MimeTypeIdentifier { 32 | 33 | /** 34 | * Try to identify the mimeType. 35 | * 36 | * Contract: If the implementing class doesn't know anything, 37 | * it returns the current mimeType. 38 | * 39 | * @param mimeType Currently detected mimeType 40 | * @param bytes 512 Bytes of Header for Magic Detection 41 | * @param file Filename of the File to detect 42 | * @return MIME Type detected. 43 | */ 44 | public String identify(String mimeType, byte[] bytes, File file); 45 | 46 | /** 47 | * Get File Extensions for a known MIME Type. 48 | * @param mimeType 49 | * @return List of file extensions (main extension first). 50 | */ 51 | public List getExtensionsFor(String mimeType); 52 | } 53 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/util/mime/Office2007FileIdentifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | */ 21 | 22 | package de.uni_siegen.wineme.come_in.thumbnailer.util.mime; 23 | 24 | import java.io.BufferedReader; 25 | import java.io.File; 26 | import java.io.IOException; 27 | import java.io.InputStream; 28 | import java.io.InputStreamReader; 29 | import java.util.List; 30 | import java.util.zip.ZipEntry; 31 | import java.util.zip.ZipException; 32 | import java.util.zip.ZipFile; 33 | 34 | import de.uni_siegen.wineme.come_in.thumbnailer.util.IOUtil; 35 | 36 | /** 37 | * Add detection of Office2007 files (and OpenOffice files). 38 | * Magic numbers don't help here, only introspection of the zip. 39 | */ 40 | public class Office2007FileIdentifier implements MimeTypeIdentifier { 41 | 42 | @Override 43 | public String identify(String mimeType, byte[] bytes, File file) { 44 | if (mimeType == null || mimeType.equals("application/zip") || mimeType.startsWith("application/vnd.")) 45 | { 46 | ZipFile zipFile = null; 47 | ZipEntry entry = null; 48 | try { 49 | zipFile = new ZipFile(file); 50 | 51 | entry = zipFile.getEntry("word/document.xml"); 52 | if (entry != null) 53 | return "application/vnd.openxmlformats-officedocument.wordprocessingml"; 54 | 55 | entry = zipFile.getEntry("ppt/presentation.xml"); 56 | if (entry != null) 57 | return "application/vnd.openxmlformats-officedocument.presentationml"; 58 | 59 | entry = zipFile.getEntry("xl/workbook.xml"); 60 | if (entry != null) 61 | return "application/vnd.openxmlformats-officedocument.spreadsheetml"; 62 | 63 | entry = zipFile.getEntry("mimetype"); 64 | if (entry != null) 65 | return detectOpenOfficeMimeType(zipFile.getInputStream(entry)); 66 | } catch (ZipException e) { 67 | return mimeType; // Zip file damaged or whatever. Silently give up. 68 | } catch (IOException e) { 69 | return mimeType; // Zip file damaged or whatever. Silently give up. 70 | } finally { 71 | IOUtil.quietlyClose(zipFile); 72 | } 73 | } 74 | 75 | return mimeType; 76 | 77 | } 78 | 79 | private String detectOpenOfficeMimeType(InputStream inputStream) throws IOException 80 | { 81 | try { 82 | BufferedReader in = new BufferedReader(new InputStreamReader(inputStream)); 83 | return in.readLine(); 84 | } finally { 85 | IOUtil.quietlyClose(inputStream); 86 | } 87 | } 88 | 89 | @Override 90 | public List getExtensionsFor(String mimeType) { 91 | return null; // I don't know - Aperture knows better than me. 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/util/mime/OfficeFileIdentifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | */ 21 | 22 | package de.uni_siegen.wineme.come_in.thumbnailer.util.mime; 23 | 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | 27 | /** 28 | * Improve detection of non-XML Office files. 29 | * 30 | * Requires: 31 | * - POI (version 3.7 or higher) 32 | */ 33 | public abstract class OfficeFileIdentifier implements MimeTypeIdentifier { 34 | 35 | protected static final String PPT_MIME_TYPE = "application/vnd.ms-powerpoint"; 36 | protected static final String XLS_MIME_TYPE = "application/vnd.ms-excel"; 37 | protected static final String DOC_MIME_TYPE = "application/vnd.ms-word"; 38 | 39 | protected static final String MS_OFFICE_MIME_TYPE = "application/vnd.ms-office"; 40 | 41 | 42 | protected List ext; 43 | 44 | public OfficeFileIdentifier() { 45 | ext = new ArrayList(); 46 | } 47 | 48 | @Override 49 | public List getExtensionsFor(String mimeType) { 50 | if (PPT_MIME_TYPE.equals(mimeType)) 51 | { 52 | return ext; 53 | } 54 | return null; // I don't know 55 | } 56 | 57 | protected boolean isOfficeFile(String mimeType) { 58 | if (MS_OFFICE_MIME_TYPE.equals(mimeType)) 59 | return true; 60 | if (mimeType == null) 61 | return false; 62 | if (mimeType.startsWith("application/vnd.ms")) 63 | return true; 64 | if (mimeType.startsWith("application/vnd.openxmlformats")) 65 | return true; 66 | 67 | return false; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/util/mime/PptFileIdentifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | * 21 | * Concept from Nuxeo: 22 | * nuxeo-platform-mimetype-core/src/main/java/org/nuxeo/ecm/platform/mimetype/detectors/PptMimetypeSniffer.java (v5.5) 23 | * Licenced LGPL 2.1 24 | * (C) Copyright 2006-2007 Nuxeo SAS (http://nuxeo.com/) and contributors. 25 | */ 26 | 27 | package de.uni_siegen.wineme.come_in.thumbnailer.util.mime; 28 | 29 | import java.io.File; 30 | import java.io.FileInputStream; 31 | 32 | import org.apache.poi.hslf.usermodel.SlideShow; 33 | 34 | public class PptFileIdentifier extends OfficeFileIdentifier 35 | { 36 | public PptFileIdentifier() 37 | { 38 | super(); 39 | ext.add("ppt"); 40 | ext.add("pps"); 41 | } 42 | 43 | @Override 44 | public String identify(String mimeType, byte[] bytes, File file) { 45 | 46 | if (isOfficeFile(mimeType) && !PPT_MIME_TYPE.equals(mimeType)) 47 | { 48 | try { 49 | FileInputStream stream = new FileInputStream(file); 50 | SlideShow presentation = new SlideShow(stream); 51 | 52 | if (presentation.getSlides().length != 0) { 53 | return PPT_MIME_TYPE; 54 | } 55 | } catch (Throwable e) { 56 | } 57 | } 58 | 59 | return mimeType; 60 | } 61 | 62 | /* Orig: 63 | 64 | public String[] process(byte[] data, int offset, int length, long bitmask, 65 | char comparator, String mimeType, Map params) { 66 | 67 | String[] mimetypes = { "" }; 68 | File file = null; 69 | 70 | try { 71 | file = File.createTempFile("magicdetector", ".ppt"); 72 | FileUtils.writeFile(file, data); 73 | mimetypes = guessPowerpoint(file); 74 | } catch (IOException e) { 75 | log.error(e, e); 76 | } finally { 77 | if (file != null) { 78 | file.delete(); 79 | } 80 | } 81 | 82 | return mimetypes; 83 | } 84 | 85 | public String[] process(File file, int offset, int length, long bitmask, 86 | char comparator, String mimeType, Map params) { 87 | 88 | return guessPowerpoint(file); 89 | } 90 | 91 | public String[] guessPowerpoint(File file) { 92 | 93 | String[] mimetypes = {}; 94 | 95 | try { 96 | FileInputStream stream = new FileInputStream(file); 97 | HSLFSlideShow ppt = new HSLFSlideShow(stream); 98 | SlideShow presentation = new SlideShow(ppt); 99 | 100 | if (presentation.getSlides().length != 0) { 101 | mimetypes = getHandledTypes(); 102 | } 103 | } catch (FileNotFoundException e) { 104 | // This is not powerpoint file 105 | log.debug("MimeType detector : Not a powerpoint file - FileNotFoundException"); 106 | } catch (IOException e) { 107 | // This is not a powerpoint file 108 | log.debug("MimeType detector : Not a powerpoint file - IOException"); 109 | } catch (RuntimeException e) { 110 | // This is not a powerpoint file 111 | log.debug("MimeType detector : Not a powerpoint file - RuntimeException"); 112 | } catch (Exception e) { 113 | log.error(e, e); 114 | } 115 | return mimetypes; 116 | } 117 | 118 | */ 119 | 120 | } 121 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/util/mime/ScratchFileIdentifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | */ 21 | 22 | package de.uni_siegen.wineme.come_in.thumbnailer.util.mime; 23 | 24 | import java.io.File; 25 | import java.io.UnsupportedEncodingException; 26 | import java.util.ArrayList; 27 | import java.util.List; 28 | 29 | import org.apache.commons.io.FilenameUtils; 30 | 31 | /** 32 | * Add detection of Scratch files. 33 | * A MIME Type didn't exist, so I invented "application/x-mit-scratch". 34 | */ 35 | public class ScratchFileIdentifier implements MimeTypeIdentifier { 36 | public static final String SCRATCH_MIME_TYPE = "application/x-mit-scratch"; 37 | public static final String SCRATCH_EXTENSION = "sb"; 38 | private static final String MAGIC_SCRATCH_HEADER = "ScratchV0"; 39 | 40 | @Override 41 | public String identify(String mimeType, byte[] bytes, File file) { 42 | if (mimeType == null && SCRATCH_EXTENSION.equals(FilenameUtils.getExtension(file.getName()))) 43 | return SCRATCH_MIME_TYPE; 44 | 45 | if (startWith(bytes, MAGIC_SCRATCH_HEADER)) 46 | return SCRATCH_MIME_TYPE; 47 | 48 | return mimeType; 49 | } 50 | 51 | private boolean startWith(byte[] haystick, String needle) { 52 | try { 53 | byte[] b_needle = needle.getBytes("US-ASCII"); 54 | 55 | for (int i = 0; i < b_needle.length; i++) 56 | { 57 | if (haystick[i] != b_needle[i]) 58 | return false; 59 | } 60 | return true; 61 | } catch (UnsupportedEncodingException e) { 62 | return false; 63 | } 64 | } 65 | 66 | @Override 67 | public List getExtensionsFor(String mimeType) { 68 | if (SCRATCH_MIME_TYPE.equals(mimeType)) 69 | { 70 | List ext = new ArrayList(); 71 | ext.add(SCRATCH_EXTENSION); 72 | return ext; 73 | } 74 | return null; // I don't know 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/de/uni_siegen/wineme/come_in/thumbnailer/util/mime/XlsFileIdentifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * regain/Thumbnailer - A file search engine providing plenty of formats (Plugin) 3 | * Copyright (C) 2011 Come_IN Computerclubs (University of Siegen) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * Contact: Come_IN-Team 20 | * 21 | * Concept from Nuxeo: 22 | * nuxeo-platform-mimetype-core/src/main/java/org/nuxeo/ecm/platform/mimetype/detectors/XlsMimetypeSniffer.java (v5.5) 23 | * Licenced LGPL 2.1 24 | * (C) Copyright 2006-2007 Nuxeo SAS (http://nuxeo.com/) and contributors. 25 | */ 26 | 27 | package de.uni_siegen.wineme.come_in.thumbnailer.util.mime; 28 | 29 | import java.io.File; 30 | import java.io.FileInputStream; 31 | 32 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; 33 | 34 | public class XlsFileIdentifier extends OfficeFileIdentifier 35 | { 36 | public XlsFileIdentifier() 37 | { 38 | super(); 39 | ext.add("xls"); 40 | } 41 | 42 | @Override 43 | public String identify(String mimeType, byte[] bytes, File file) { 44 | 45 | if (isOfficeFile(mimeType) && !XLS_MIME_TYPE.equals(mimeType)) 46 | { 47 | try { 48 | FileInputStream stream = new FileInputStream(file); 49 | HSSFWorkbook workbook = new HSSFWorkbook(stream); 50 | 51 | if (workbook.getNumberOfSheets() != 0) { 52 | return XLS_MIME_TYPE; 53 | } 54 | } catch (Throwable e) { 55 | 56 | } 57 | } 58 | 59 | return mimeType; 60 | } 61 | 62 | /* Orig: 63 | 64 | public String[] process(byte[] data, int offset, int length, long bitmask, 65 | char comparator, String mimeType, Map params) { 66 | 67 | String[] mimetypes = { "" }; 68 | File file = null; 69 | 70 | try { 71 | file = File.createTempFile("magicdetector", ".xls"); 72 | FileUtils.writeFile(file, data); 73 | mimetypes = guessExcel(file); 74 | } catch (IOException e) { 75 | log.error(e, e); 76 | } finally { 77 | if (file != null) { 78 | file.delete(); 79 | } 80 | } 81 | 82 | return mimetypes; 83 | } 84 | 85 | public String[] process(File file, int offset, int length, long bitmask, 86 | char comparator, String mimeType, Map params) { 87 | 88 | return guessExcel(file); 89 | } 90 | 91 | public String[] guessExcel(File file) { 92 | 93 | String[] mimetypes = {}; 94 | 95 | try { 96 | FileInputStream stream = new FileInputStream(file); 97 | HSSFWorkbook workbook = new HSSFWorkbook(stream); 98 | if (workbook.getNumberOfSheets() != 0) { 99 | mimetypes = getHandledTypes(); 100 | } 101 | } catch (FileNotFoundException e) { 102 | // This is not an excel file 103 | log.debug("MimeType detector : Not an excel file"); 104 | } catch (IOException e) { 105 | // This is not an excel file 106 | log.debug("MimeType detector : Not an excel file"); 107 | } catch (IllegalArgumentException e) { 108 | log.debug("MimeType detector : Not an excel file"); 109 | } catch (Exception e) { 110 | log.error(e, e); 111 | } 112 | 113 | return mimetypes; 114 | } 115 | 116 | */ 117 | 118 | } 119 | -------------------------------------------------------------------------------- /src/jirau/DWGThumbnailer.java: -------------------------------------------------------------------------------- 1 | package jirau; 2 | 3 | import java.awt.image.BufferedImage; 4 | import java.io.ByteArrayInputStream; 5 | import java.io.ByteArrayOutputStream; 6 | import java.io.File; 7 | import java.io.FileInputStream; 8 | import java.io.IOException; 9 | 10 | import javax.imageio.ImageIO; 11 | 12 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.AbstractThumbnailer; 13 | import de.uni_siegen.wineme.come_in.thumbnailer.util.IOUtil; 14 | import de.uni_siegen.wineme.come_in.thumbnailer.util.ResizeImage; 15 | 16 | public class DWGThumbnailer extends AbstractThumbnailer { 17 | 18 | public void generateThumbnail(File input, File output) throws IOException, de.uni_siegen.wineme.come_in.thumbnailer.ThumbnailerException { 19 | //GENERATE FROM EXISTING BITMAP IN DWG 20 | byte[] outputByte = new byte[4096]; 21 | 22 | FileInputStream fis = null; 23 | 24 | try { 25 | fis = new FileInputStream(input); 26 | fis.skip(0x0D); 27 | fis.read(outputByte, 0, 4); 28 | int PosSentinel = (((outputByte[3])&0xFF)*256*256*256)+(((outputByte[2])&0xFF)*256*256)+(((outputByte[1])&0xFF)*256)+((outputByte[0])&0xFF); 29 | fis.skip(PosSentinel-0x0D-4+30); 30 | outputByte[1]=0; 31 | fis.read(outputByte, 0, 1); 32 | int TypePreview = ((outputByte[0])&0xFF); 33 | if (TypePreview==2) { 34 | fis.read(outputByte, 0, 4); 35 | int PosBMP = (((outputByte[3])&0xFF)*256*256*256)+(((outputByte[2])&0xFF)*256*256)+(((outputByte[1])&0xFF)*256)+((outputByte[0])&0xFF); 36 | fis.read(outputByte, 0, 4); 37 | int LenBMP = (((outputByte[3])&0xFF)*256*256*256)+(((outputByte[2])&0xFF)*256*256)+(((outputByte[1])&0xFF)*256)+((outputByte[0])&0xFF); 38 | fis.skip(PosBMP-(PosSentinel+30)-1-4-4+14); 39 | fis.read(outputByte, 0, 2); 40 | int biBitCount = (((outputByte[1])&0xFF)*256)+((outputByte[0])&0xFF); 41 | fis.skip(-16); 42 | int bisSize=0; 43 | int bfSize = 0; 44 | if (biBitCount<9) 45 | bfSize = 54 + 4 * ((int) (Math.pow(2,biBitCount))) + LenBMP ; 46 | else bfSize = 54 + LenBMP ; 47 | //WORD "BM" 48 | outputByte[0]=0x42;outputByte[1]=0x4D; 49 | //DWORD bfSize 50 | outputByte[2]=(byte)(bfSize&0xff);outputByte[3]=(byte)(bfSize>>8&0xff); 51 | outputByte[4]=(byte)(bfSize>>16&0xff);outputByte[5]=(byte)(bfSize>>>24); 52 | //WORD bfReserved1 53 | outputByte[6]=0x00;outputByte[7]=0x00; 54 | //WORD bfReserved2 55 | outputByte[8]=0x00;outputByte[9]=0x00; 56 | //DWORD bfOffBits 57 | outputByte[10]=0x36;outputByte[11]=0x04;outputByte[12]=0x00;outputByte[13]=0x00; 58 | 59 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 60 | baos.write(outputByte,0,14); 61 | while((LenBMP>0) && ((bisSize=fis.read(outputByte, 0, (LenBMP>4096?4096:LenBMP))) != -1)) { 62 | baos.write(outputByte, 0, bisSize); 63 | LenBMP-=bisSize; 64 | } 65 | 66 | ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); 67 | 68 | BufferedImage originalImage = ImageIO.read(bais); 69 | 70 | ResizeImage resizer = new ResizeImage(thumbWidth, thumbHeight); 71 | resizer.setInputImage(originalImage); 72 | resizer.writeOutput(output); 73 | } 74 | } finally { 75 | IOUtil.quietlyClose(fis); 76 | } 77 | } 78 | 79 | public String[] getAcceptedMIMETypes() { 80 | return new String[]{ "image/x-dwg" }; 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /test/lib/commons-exec-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/lib/commons-exec-1.1.jar -------------------------------------------------------------------------------- /test/log4j.properties: -------------------------------------------------------------------------------- 1 | # NOTE: cascaded variable substitution doesn't work! 2 | 3 | # The root category 4 | log4j.rootCategory=INFO, file, stdout 5 | 6 | # Special categories 7 | #log4j.category.net.sf.regain=DEBUG 8 | #log4j.category.net.sf.regain.crawler.Crawler=DEBUG 9 | # The following line enables logging the URL of a document, before the preparation 10 | #log4j.category.net.sf.regain.crawler.IndexWriterManager=DEBUG 11 | # Disable log messages from PDFBox 12 | log4j.category.org.apache.pdfbox=WARN 13 | # Disable Font replacement warnings 14 | log4j.category.org.apache.pdfbox.pdmodel.font.PDSimpleFont=ERROR 15 | # Disable INFO log messages from jaudiotagger 16 | log4j.category.org.jaudiotagger=FATAL 17 | #log4j.category.org.jaudiotagger.audio.AudioFile=FATAL 18 | #log4j.category.org.jaudiotagger.audio.mp3.MP3File=FATAL 19 | 20 | # Disable info messages from JODConverter 21 | log4j.category.com.artofsolving.jodconverter=WARN 22 | 23 | # Enable all debug messages from Thumbnailer 24 | log4j.category.de.uni_siegen.wineme.come_in.thumbnailer.test=TRACE 25 | 26 | # Some layouts 27 | #layout.example.1=%d{dd/MM/yyyy HH:mm:ss} [%-5p](%F:%L) %m%n 28 | #layout.example.2=%d{dd/MM/yyyy HH:mm:ss} [%t] %-5p %c{2} - %m%n 29 | layout.debug=%c [%t] %-5p: %m%n 30 | layout.long=%d{yyyy-MM-dd HH:mm:ss} %c [%t] %-5p: %m%n 31 | layout.medium=%d{HH:mm:ss}: %m%n 32 | layout.short=%m%n 33 | 34 | 35 | # The console appender 36 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 37 | 38 | # The console appender layout 39 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 40 | log4j.appender.stdout.layout.ConversionPattern=${layout.debug} 41 | 42 | # The file appender 43 | log4j.appender.file=org.apache.log4j.RollingFileAppender 44 | 45 | # Log only errors to the log file 46 | log4j.appender.file.Threshold=ERROR 47 | 48 | # The file appender layout 49 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 50 | log4j.appender.file.layout.ConversionPattern=${layout.long} 51 | 52 | # Path of the log-file 53 | log4j.appender.file.File=log/regain_test.log 54 | 55 | # Maximum size of the log-file (only org.apache.log4j.RollingFileAppender) 56 | log4j.appender.file.MaxFileSize=2MB 57 | 58 | # Amount of backup files (only org.apache.log4j.RollingFileAppender) 59 | log4j.appender.file.MaxBackupIndex=2 -------------------------------------------------------------------------------- /test/src/de/uni_siegen/wineme/come_in/thumbnailer/test/ChainedHashtableTest.java: -------------------------------------------------------------------------------- 1 | package de.uni_siegen.wineme.come_in.thumbnailer.test; 2 | 3 | import java.util.Collection; 4 | import java.util.Map; 5 | 6 | import de.uni_siegen.wineme.come_in.thumbnailer.util.ChainedHashMap; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | import static org.junit.Assert.*; 10 | 11 | public class ChainedHashtableTest { 12 | 13 | private ChainedHashMap data; 14 | 15 | @Before 16 | public void setUp() 17 | { 18 | data = new ChainedHashMap(); 19 | } 20 | 21 | @Test 22 | public void testContains() 23 | { 24 | data.put(1, "one"); 25 | data.put(2, "two"); 26 | data.put(2, "zwei"); 27 | 28 | assertTrue("containsValue one didn't work", data.containsValue("one")); 29 | assertTrue(data.containsValue("two")); 30 | assertTrue(data.containsValue("zwei")); 31 | assertTrue(data.containsKey(1)); 32 | assertTrue(data.containsKey(2)); 33 | } 34 | 35 | @Test 36 | public void testRemoveSimple() 37 | { 38 | data.put(2, "two"); 39 | data.put(1, "one"); 40 | 41 | assertNotNull(data.remove(1)); 42 | assertTrue(data.remove(2, "two")); 43 | 44 | assertSize(0, 0, data); 45 | } 46 | 47 | @Test 48 | public void testRemove() 49 | { 50 | data.put(1, "one"); 51 | data.put(2, "two"); 52 | data.put(2, "zwei"); 53 | assertSize(3, 2, data); 54 | 55 | data.remove(1); 56 | assertSize(2, 1, data); 57 | for (String test: data.getIterable(1)) 58 | fail("Key 1 was not empty: " + test); 59 | for (Integer key : data.keySet()) 60 | { 61 | if (key.equals(1)) 62 | fail("keySet contained key 1, which was removed."); 63 | } 64 | assertFalse("containsKey contained key 1, which was removed.", data.containsKey(1)); 65 | assertFalse("!containsValue one", data.containsValue("one")); 66 | 67 | data.clear(); 68 | assertSize(0, 0, data); 69 | assertTrue("isEmpty", data.isEmpty()); 70 | } 71 | 72 | @Test 73 | public void testRemoveValue() 74 | { 75 | data.put(1, "one"); 76 | data.put(2, "two"); 77 | data.put(2, "zwei"); 78 | assertSize(3, 2, data); 79 | 80 | data.remove(1, "one"); 81 | assertSize(2, 1, data); 82 | 83 | data.remove(2, "two"); 84 | assertSize(1, 1, data); 85 | } 86 | 87 | @Test 88 | public void testEntrySetUnsupport() 89 | { 90 | try { 91 | data.entrySet(); 92 | fail("entrySet should raise an unsupported exception"); 93 | } catch (UnsupportedOperationException ex) { 94 | // OK 95 | } 96 | } 97 | 98 | @Test 99 | public void testIdenticalEntries() 100 | { 101 | data.put(1, "one"); 102 | data.put(1, "one"); 103 | data.put(2, "one"); 104 | data.put(1, "two"); 105 | assertSize(4, 2, data); 106 | 107 | int identEntries = 0; 108 | for (Map.Entry entry : data) 109 | { 110 | if (entry.getKey().equals(1) && "one".equals(entry.getValue())) 111 | identEntries++; 112 | } 113 | assertEquals("Pair 1-one was not found 2 times", 2, identEntries); 114 | } 115 | 116 | @Test 117 | public void testCopyConstruct() 118 | { 119 | data.put(1, "one"); 120 | data.put(2, "two"); 121 | data.put(2, "zwei"); 122 | assertSize(3,2, new ChainedHashMap(data)); 123 | } 124 | 125 | @Test 126 | public void testBackingValues() 127 | { 128 | // "The set is backed by the map, so changes to the map are reflected in the set, and vice-versa." 129 | data.put(1, "one"); 130 | data.put(2, "two"); 131 | assertSize(2, 2, data); 132 | 133 | Collection collection = data.values(); 134 | assertTrue(collection.remove("one")); 135 | assertSize(1, 1, data); 136 | 137 | assertTrue(data.remove(2, "two")); 138 | assertSize(0, 0, data); 139 | assertEquals("Hashmap changed, but collection(values()) didn't", 0, collection.size()); 140 | } 141 | 142 | @Test 143 | public void testBackingKeys() 144 | { 145 | // "The set is backed by the map, so changes to the map are reflected in the set, and vice-versa." 146 | data.put(1, "one"); 147 | data.put(2, "two"); 148 | assertSize(2, 2, data); 149 | 150 | Collection collection = data.values(); 151 | assertTrue(collection.remove("one")); 152 | assertSize(1, 1, data); 153 | 154 | assertTrue(data.remove(2, "two")); 155 | assertSize(0, 0, data); 156 | assertEquals("Hashmap changed, but collection(values()) didn't", 0, collection.size()); 157 | } 158 | 159 | @SuppressWarnings("unused") 160 | @Test 161 | public void testBackingIterableKey() 162 | { 163 | data.put(1, "one"); 164 | data.put(2, "two"); 165 | assertSize(2, 2, data); 166 | 167 | Iterable iterable = data.getIterable(2); 168 | data.put(2, "zwei"); 169 | int i = 0; 170 | for (String test : iterable) 171 | i++; 172 | assertEquals("Hashmap changed, but getIterable didn't", 2, i); 173 | } 174 | 175 | @Test 176 | public void testOrder() 177 | { 178 | data.put(2, "two"); 179 | data.put(1, "one"); 180 | data.put(2, "zwei"); 181 | assertEquals("two", data.get(2)); 182 | } 183 | 184 | private void assertSize(int size, int keySize, ChainedHashMap hashy) 185 | { 186 | assertEquals("Size is not correct.\n" + hashy, size, hashy.size()); 187 | assertEquals("Size of Values is not correct.\n" + hashy + "\n" + hashy.values(), size, hashy.values().size()); 188 | 189 | assertEquals("Size of Keys is not correct.\n" + hashy, keySize, hashy.keySet().size()); 190 | } 191 | } 192 | -------------------------------------------------------------------------------- /test/src/de/uni_siegen/wineme/come_in/thumbnailer/test/IOUtilTest.java: -------------------------------------------------------------------------------- 1 | package de.uni_siegen.wineme.come_in.thumbnailer.test; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import de.uni_siegen.wineme.come_in.thumbnailer.util.IOUtil; 7 | import org.junit.Test; 8 | import static org.junit.Assert.*; 9 | 10 | public class IOUtilTest { 11 | @Test 12 | public void testGetRelativePathsUnix() { 13 | assertEquals("stuff/xyz.dat", IOUtil.getRelativeFilename("/var/data/", "/var/data/stuff/xyz.dat")); 14 | assertEquals("stuff/xyz.dat", IOUtil.getRelativeFilename("/var/data", "/var/data/stuff/xyz.dat")); 15 | assertEquals("xyz.dat", IOUtil.getRelativeFilename("/var/data", "/var/data/xyz.dat")); 16 | assertEquals("", IOUtil.getRelativeFilename("/var/data", "/var/data")); 17 | } 18 | 19 | @Test 20 | public void testCurrentPlatformCanonical() throws IOException 21 | { 22 | File here = new File(".").getCanonicalFile(); 23 | File parent = new File("..").getCanonicalFile(); 24 | 25 | System.out.println(parent.getAbsolutePath()); 26 | System.out.println(here.getAbsolutePath()); 27 | assertEquals(here.getName(), IOUtil.getRelativeFilename(parent, here)); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /test/src/de/uni_siegen/wineme/come_in/thumbnailer/test/MimeDetectionTest.java: -------------------------------------------------------------------------------- 1 | package de.uni_siegen.wineme.come_in.thumbnailer.test; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.io.File; 6 | 7 | import de.uni_siegen.wineme.come_in.thumbnailer.util.mime.MimeTypeDetector; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | 11 | public class MimeDetectionTest extends MyTestCase { 12 | private MimeTypeDetector mimeType; 13 | private File parent; 14 | 15 | public MimeDetectionTest() 16 | { 17 | new MimeTypeDetector(); // Initialize beforehand 18 | } 19 | 20 | @Before 21 | public void setUp() 22 | { 23 | mimeType = new MimeTypeDetector(); 24 | parent = new File(TESTFILES_DIR + "wrong_extension"); 25 | } 26 | 27 | @Test 28 | public void testGetExtensionFor() 29 | { 30 | assertEquals("odt", mimeType.getStandardExtensionForMimeType("application/vnd.oasis.opendocument.text")); 31 | assertTrue(mimeType.doesExtensionMatchMimeType("odt", "application/vnd.oasis.opendocument.text")); 32 | } 33 | 34 | @Test 35 | public void testImageFiles() 36 | { 37 | assertMime("image/png", "test2-png.jpg"); 38 | } 39 | @Test 40 | public void testImageFiles2() 41 | { 42 | assertMime("image/jpeg", "test2-jpg.bmp"); 43 | } 44 | @Test 45 | public void testImageFiles3() 46 | { 47 | assertMime("image/bmp", "test2-bmp.png"); 48 | } 49 | @Test 50 | public void testTextFiles() 51 | { 52 | assertMime("text/rtf", "test2-rtf.pdf"); 53 | } 54 | 55 | @Test 56 | public void testTextFiles2() 57 | { 58 | assertMime("application/pdf", "test2-pdf.ps"); 59 | } 60 | 61 | @Test 62 | public void testOpenOfficeFiles() 63 | { 64 | assertMime("application/vnd.oasis.opendocument.presentation", "test2-odp.pps"); 65 | } 66 | 67 | @Test 68 | public void testOpenOfficeFiles2() 69 | { 70 | assertMime("application/vnd.oasis.opendocument.spreadsheet", "test2-ods.xls"); 71 | } 72 | 73 | @Test 74 | public void testOpenOfficeFiles3() 75 | { 76 | assertMime("application/vnd.oasis.opendocument.text", "test2-odt.sxw"); 77 | } 78 | 79 | @Test 80 | public void testOpenOfficeFiles4() 81 | { 82 | assertMime("application/vnd.oasis.opendocument.text", "test2-odt.doc"); 83 | } 84 | 85 | @Test 86 | public void testOffice2007Files() 87 | { 88 | assertMime("application/vnd.openxmlformats-officedocument.wordprocessingml", "test2-docx.doc"); 89 | } 90 | 91 | @Test 92 | public void testOffice2007Files2() 93 | { 94 | assertMime("application/vnd.openxmlformats-officedocument.presentationml", "test2-pptx.ppt"); 95 | } 96 | 97 | @Test 98 | public void testOffice2007Files3() 99 | { 100 | assertMime("application/vnd.openxmlformats-officedocument.spreadsheetml", "test2-xlsx.ods"); 101 | } 102 | 103 | @Test 104 | public void testOffice2007Files4() 105 | { 106 | assertMime("application/vnd.openxmlformats-officedocument.spreadsheetml", "test2-xlsx.ppt"); 107 | } 108 | 109 | @Test 110 | public void testOfficeFiles() 111 | { 112 | assertMime("application/vnd.ms-powerpoint", "test2-ppt.odp"); 113 | } 114 | 115 | @Test 116 | public void testOfficeFiles2() 117 | { 118 | assertMime("application/vnd.ms-word", "test2-doc.ott"); 119 | } 120 | 121 | @Test 122 | public void testOfficeFiles3() 123 | { 124 | assertMime("application/vnd.ms-excel", "test2-xls.odp"); 125 | } 126 | 127 | @Test 128 | public void testScratch() 129 | { 130 | assertEquals("Standard extension of scratch was wrongly returned", "sb", mimeType.getStandardExtensionForMimeType("application/x-mit-scratch")); 131 | assertTrue("doesExtensionMatchMimeType of Scratch didn't return true", mimeType.doesExtensionMatchMimeType("sb", "application/x-mit-scratch")); 132 | assertMime("application/x-mit-scratch", "test2-sb.sbx"); 133 | } 134 | 135 | @Test 136 | public void testAutoCad() 137 | { 138 | assertMime("image/x-dwg", "test2-dwg.doc"); 139 | } 140 | 141 | public void assertMime(String expectedMime, String filename) 142 | { 143 | File file = new File(parent, filename); 144 | if (!file.exists()) 145 | fail("File " + filename + " does not exist"); 146 | 147 | String mime = mimeType.getMimeType(file); 148 | if (!expectedMime.equalsIgnoreCase(mime)) 149 | fail("File " + filename + ": Mime is not equal: expected \"" + expectedMime + "\", but was \"" + mime + "\"."); 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /test/src/de/uni_siegen/wineme/come_in/thumbnailer/test/MyTestCase.java: -------------------------------------------------------------------------------- 1 | package de.uni_siegen.wineme.come_in.thumbnailer.test; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.awt.Image; 6 | import java.io.File; 7 | import java.io.IOException; 8 | import javax.imageio.ImageIO; 9 | 10 | import org.apache.log4j.Logger; 11 | import org.apache.log4j.PropertyConfigurator; 12 | 13 | public class MyTestCase implements TestConfiguration { 14 | 15 | protected static Logger mLog = Logger.getLogger(MyTestCase.class); 16 | 17 | 18 | private static final String LOG4J_CONFIG_FILE = "test/log4j.properties"; 19 | static 20 | { 21 | System.setProperty("log4j.configuration", LOG4J_CONFIG_FILE); 22 | 23 | File logConfigFile = new File(LOG4J_CONFIG_FILE); 24 | if (!logConfigFile.exists()) { 25 | System.out.println("ERROR: Logging configuration file not found: " + logConfigFile.getAbsolutePath()); 26 | System.exit(1); // Abort 27 | } 28 | 29 | PropertyConfigurator.configureAndWatch(logConfigFile.getAbsolutePath(), 10 * 1000); 30 | mLog.info("Logging initialized"); 31 | 32 | } 33 | 34 | public void assertFileExists(File file) 35 | { 36 | assertFileExists("", file); 37 | } 38 | 39 | public static void assertFileExists(String msg, File file) 40 | { 41 | if (!msg.isEmpty()) 42 | msg += ": "; 43 | 44 | assertNotNull(msg + "File is null", file); 45 | assertTrue(msg + "File " + file.getAbsolutePath() + " does not exist", file.exists()); 46 | } 47 | 48 | public static void assertPictureFormat(File file, int width, int height) throws IOException 49 | { 50 | assertFileExists("Picture file does not exist", file); 51 | 52 | Image image = ImageIO.read(file); 53 | assertNotNull("Picture " + file.getAbsolutePath() + " could not be decoded by ImageIO", image); 54 | assertPictureFormat(image, width, height); 55 | } 56 | 57 | public static void assertPictureFormat(Image img, int expectedWidth, int expectedHeight) 58 | { 59 | assertNotNull("Picture is null", img); 60 | int realWidth = img.getWidth(null); 61 | int realHeight = img.getHeight(null); 62 | String realFormat = realWidth + "x" + realHeight; 63 | String expectedFormat = expectedWidth + "x" + expectedHeight; 64 | assertEquals("Picture has not the right width (expected: " + expectedFormat + ", actual: " + realFormat + ")", expectedWidth, realWidth); 65 | assertEquals("Picture has not the right height (expected: " + expectedFormat + ", actual: " + realFormat + ")", expectedHeight, realHeight); 66 | } 67 | 68 | public void testDummy() 69 | { 70 | // Somehow this test needs to be present so that JUnit detects the tests in sub-classes. 71 | assertTrue(true); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /test/src/de/uni_siegen/wineme/come_in/thumbnailer/test/TemporaryFilesManagerTest.java: -------------------------------------------------------------------------------- 1 | package de.uni_siegen.wineme.come_in.thumbnailer.test; 2 | 3 | import java.io.File; 4 | 5 | import de.uni_siegen.wineme.come_in.thumbnailer.util.TemporaryFilesManager; 6 | 7 | import org.apache.commons.io.FilenameUtils; 8 | import org.junit.After; 9 | import org.junit.Before; 10 | import org.junit.Test; 11 | import static org.junit.Assert.*; 12 | 13 | public class TemporaryFilesManagerTest { 14 | 15 | TemporaryFilesManager tfm = null; 16 | 17 | @Before 18 | public void setUp() { 19 | tfm = new TemporaryFilesManager(); 20 | } 21 | 22 | @After 23 | public void tearDown() { 24 | tfm.deleteAllTempfiles(); 25 | } 26 | 27 | @Test 28 | public void test() throws Exception { 29 | File input = File.createTempFile("test-input", ".txt"); 30 | 31 | File output = tfm.createTempfileCopy(input, "bla"); 32 | assertEquals("bla", FilenameUtils.getExtension(output.getName())); 33 | assertFalse("Copy didn't work", input.equals(output)); 34 | assertFalse("Copy/Rename didn't work", FilenameUtils.getBaseName(input.getName()).equals( 35 | FilenameUtils.getBaseName(output.getName()))); 36 | 37 | File output2 = tfm.createTempfileCopy(input, "bla"); 38 | assertEquals(output, output2); 39 | 40 | File output3 = tfm.createTempfileCopy(input, "blub"); 41 | assertEquals(FilenameUtils.getBaseName(output.getName()) + ".blub", output3.getName()); 42 | 43 | File output4 = tfm.createTempfileCopy(input, "blub"); 44 | assertEquals(output3, output4); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test/src/de/uni_siegen/wineme/come_in/thumbnailer/test/TestConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.uni_siegen.wineme.come_in.thumbnailer.test; 2 | 3 | import java.io.File; 4 | 5 | public interface TestConfiguration { 6 | public static final String MY_DIR = "."+ File.separatorChar; 7 | public static final String TESTFILES_DIR = MY_DIR+"test" + File.separatorChar + "testfiles" + File.separatorChar; 8 | 9 | } 10 | -------------------------------------------------------------------------------- /test/src/de/uni_siegen/wineme/come_in/thumbnailer/test/ThumbnailGeneratorBasicTest.java: -------------------------------------------------------------------------------- 1 | package de.uni_siegen.wineme.come_in.thumbnailer.test; 2 | 3 | import java.io.File; 4 | import java.util.Collection; 5 | 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.junit.runners.Parameterized.Parameters; 10 | 11 | 12 | import uk.ac.lkl.common.util.testing.LabelledParameterized; 13 | 14 | @RunWith(LabelledParameterized.class) 15 | public class ThumbnailGeneratorBasicTest extends ThumbnailerFileTestDummy 16 | { 17 | public ThumbnailGeneratorBasicTest(String name, File input) 18 | { 19 | super(input); 20 | } 21 | 22 | @Before 23 | public void setSize() 24 | { 25 | setImageSize(100, 75, 0); 26 | } 27 | 28 | @Test 29 | public void generateThumbnail() throws Exception 30 | { 31 | try { 32 | create_thumbnail(inputFile); 33 | } catch (Exception e) { 34 | throw new Exception("Exception in file " + inputFile.getName() + ":", e); 35 | } 36 | } 37 | 38 | @Parameters 39 | public static Collection listFiles() 40 | { 41 | return getFileList(TESTFILES_DIR); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /test/src/de/uni_siegen/wineme/come_in/thumbnailer/test/ThumbnailGeneratorMIMETest.java: -------------------------------------------------------------------------------- 1 | package de.uni_siegen.wineme.come_in.thumbnailer.test; 2 | 3 | import java.io.File; 4 | import java.util.Collection; 5 | 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.junit.runners.Parameterized.Parameters; 10 | 11 | import uk.ac.lkl.common.util.testing.LabelledParameterized; 12 | 13 | @RunWith(LabelledParameterized.class) 14 | public class ThumbnailGeneratorMIMETest extends ThumbnailerFileTestDummy 15 | { 16 | public ThumbnailGeneratorMIMETest(String name, File input) 17 | { 18 | super(input); 19 | } 20 | 21 | @Test 22 | public void generateThumbnail() throws Exception 23 | { 24 | create_thumbnail(inputFile); 25 | } 26 | 27 | @Parameters 28 | public static Collection listFiles() 29 | { 30 | return getFileList(TESTFILES_DIR + "wrong_extension"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /test/src/de/uni_siegen/wineme/come_in/thumbnailer/test/ThumbnailImageFormatTest.java: -------------------------------------------------------------------------------- 1 | package de.uni_siegen.wineme.come_in.thumbnailer.test; 2 | 3 | import java.io.File; 4 | import java.util.Collection; 5 | 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.junit.runners.Parameterized.Parameters; 9 | 10 | import uk.ac.lkl.common.util.testing.LabelledParameterized; 11 | 12 | @RunWith(LabelledParameterized.class) 13 | public class ThumbnailImageFormatTest extends ThumbnailerFileTestDummy 14 | { 15 | public ThumbnailImageFormatTest(String name, File input) 16 | { 17 | super(input); 18 | } 19 | 20 | @Test 21 | public void generateThumbnail() throws Exception 22 | { 23 | create_thumbnail(inputFile); 24 | } 25 | 26 | @Parameters 27 | public static Collection listFiles() 28 | { 29 | return getFileList(TESTFILES_DIR + "format"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /test/src/de/uni_siegen/wineme/come_in/thumbnailer/test/ThumbnailerFileTestDummy.java: -------------------------------------------------------------------------------- 1 | package de.uni_siegen.wineme.come_in.thumbnailer.test; 2 | 3 | import static org.junit.Assert.*; 4 | import java.io.File; 5 | import java.io.IOException; 6 | import java.util.ArrayList; 7 | import java.util.Collection; 8 | 9 | import jirau.DWGThumbnailer; 10 | 11 | import org.junit.Before; 12 | 13 | import de.uni_siegen.wineme.come_in.thumbnailer.ThumbnailerManager; 14 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.JODConverterThumbnailer; 15 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.JODExcelConverterThumbnailer; 16 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.JODHtmlConverterThumbnailer; 17 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.JODPowerpointConverterThumbnailer; 18 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.JODWordConverterThumbnailer; 19 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.NativeImageThumbnailer; 20 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.OpenOfficeThumbnailer; 21 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.PDFBoxThumbnailer; 22 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.ScratchThumbnailer; 23 | 24 | public class ThumbnailerFileTestDummy extends MyTestCase { 25 | protected File inputFile; 26 | protected int height = 120; 27 | protected int width = 160; 28 | 29 | public ThumbnailerFileTestDummy(File inputFile) { 30 | super(); 31 | this.inputFile = inputFile; 32 | } 33 | 34 | ThumbnailerManager thumbnailer; 35 | 36 | public ThumbnailerFileTestDummy(String name) 37 | { 38 | this(); 39 | } 40 | 41 | public ThumbnailerFileTestDummy() { 42 | super(); 43 | JODConverterThumbnailer.connect(); 44 | } 45 | 46 | @Before 47 | public void setUp() throws Exception 48 | { 49 | thumbnailer = new ThumbnailerManager(); 50 | thumbnailer.setThumbnailFolder("thumbs/"); 51 | 52 | thumbnailer.registerThumbnailer(new NativeImageThumbnailer()); 53 | 54 | 55 | thumbnailer.registerThumbnailer(new OpenOfficeThumbnailer()); 56 | thumbnailer.registerThumbnailer(new PDFBoxThumbnailer()); 57 | 58 | try { 59 | thumbnailer.registerThumbnailer(new JODWordConverterThumbnailer()); 60 | thumbnailer.registerThumbnailer(new JODExcelConverterThumbnailer()); 61 | thumbnailer.registerThumbnailer(new JODPowerpointConverterThumbnailer()); 62 | thumbnailer.registerThumbnailer(new JODHtmlConverterThumbnailer()); 63 | } catch (IOException e) { 64 | mLog.error("Could not initialize JODConverter:", e); 65 | } 66 | 67 | thumbnailer.registerThumbnailer(new ScratchThumbnailer()); 68 | 69 | thumbnailer.registerThumbnailer(new DWGThumbnailer()); 70 | 71 | } 72 | 73 | public void create_thumbnail(File file) throws Exception 74 | { 75 | create_thumbnail(file, thumbnailer.chooseThumbnailFilename(file, false)); 76 | } 77 | 78 | public void create_thumbnail(File input, File output) throws Exception 79 | { 80 | assertFileExists("Input file does not exist", input); 81 | if (output != null && output.exists()) 82 | output.delete(); 83 | 84 | _create_thumbnail(input, output); 85 | 86 | assertFileExists("Output could not be generated", output); 87 | assertFalse("Output file is empty", 0 == output.length()); 88 | assertPictureFormat(output, width, height); 89 | } 90 | 91 | public void _create_thumbnail(File input, File output) throws Exception 92 | { 93 | thumbnailer.generateThumbnail(input, output); 94 | } 95 | 96 | public void setImageSize(int height, int width, int opt) 97 | { 98 | thumbnailer.setImageSize(width, height, opt); 99 | this.height = height; 100 | this.width = width; 101 | } 102 | 103 | 104 | public static Collection getFileList(String path) { 105 | return getFileList(new File(path)); 106 | } 107 | 108 | public static Collection getFileList(File path) { 109 | Collection files = new ArrayList(); 110 | 111 | File[] testfiles = path.listFiles(); 112 | 113 | for(File input : testfiles) 114 | { 115 | if (input.isDirectory()) 116 | continue; 117 | 118 | files.add(new Object[] {getDisplayName(input), input}); 119 | } 120 | return files; 121 | } 122 | 123 | public static String getDisplayName(File inputFile) 124 | { 125 | return inputFile.getName().replaceAll("[^a-zA-Z0-9]", "_"); 126 | } 127 | 128 | 129 | } -------------------------------------------------------------------------------- /test/src/de/uni_siegen/wineme/come_in/thumbnailer/test/ThumbnailerManagerTest.java: -------------------------------------------------------------------------------- 1 | package de.uni_siegen.wineme.come_in.thumbnailer.test; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import de.uni_siegen.wineme.come_in.thumbnailer.ThumbnailerManager; 7 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.OpenOfficeThumbnailer; 8 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.Thumbnailer; 9 | import org.junit.Before; 10 | import org.junit.Test; 11 | import static org.junit.Assert.*; 12 | 13 | public class ThumbnailerManagerTest extends MyTestCase { 14 | 15 | ThumbnailerManager thumbnailer; 16 | 17 | @Before 18 | public void setUp() throws Exception 19 | { 20 | thumbnailer = new ThumbnailerManager(); 21 | thumbnailer.setThumbnailFolder(TESTFILES_DIR); 22 | } 23 | 24 | @Test 25 | public void testSetImageSize() 26 | { 27 | thumbnailer.setImageSize(100, 200, 0); 28 | Thumbnailer newThumbnailer = new OpenOfficeThumbnailer(); 29 | thumbnailer.registerThumbnailer(newThumbnailer); 30 | 31 | assertEquals("Width is not correct!", 100, thumbnailer.getCurrentImageWidth()); 32 | assertEquals("Width is not correct!", 100, newThumbnailer.getCurrentImageWidth()); 33 | 34 | thumbnailer.setImageSize(140, 240, 0); 35 | 36 | assertEquals("Width is not correct!", 140, thumbnailer.getCurrentImageWidth()); 37 | assertEquals("Width is not correct!", 140, newThumbnailer.getCurrentImageWidth()); 38 | } 39 | 40 | @Test 41 | public void testThumbnailerChooseThumbnailNameExists() 42 | { 43 | File first = thumbnailer.chooseThumbnailFilename(new File("abc.png"), true); 44 | try { 45 | first.createNewFile(); 46 | } catch (IOException e) { 47 | fail("The chosen thumbnail File " + first.getAbsolutePath() + " cannot be written."); 48 | } 49 | File second = thumbnailer.chooseThumbnailFilename(new File("abc.png"), true); 50 | assertTrue("The filenames are not unique (second thumbnail would overwrite first).", !first.getAbsolutePath().equals(second.getAbsolutePath())); 51 | first.delete(); 52 | second.delete(); 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /test/src/de/uni_siegen/wineme/come_in/thumbnailer/test/ThumbnailersFailingTest.java: -------------------------------------------------------------------------------- 1 | package de.uni_siegen.wineme.come_in.thumbnailer.test; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import de.uni_siegen.wineme.come_in.thumbnailer.ThumbnailerException; 7 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.JODWordConverterThumbnailer; 8 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.NativeImageThumbnailer; 9 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.OpenOfficeThumbnailer; 10 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.PDFBoxThumbnailer; 11 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.ScratchThumbnailer; 12 | import de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.Thumbnailer; 13 | 14 | import org.junit.After; 15 | import org.junit.Test; 16 | import static org.junit.Assert.*; 17 | 18 | /** 19 | * Failures due to a file type mismatch 20 | * must emit a ThumbnailerException 21 | * 22 | * @author Benjamin 23 | * 24 | */ 25 | public class ThumbnailersFailingTest extends MyTestCase { 26 | 27 | Thumbnailer currentThumbnailer; 28 | 29 | public void assert_fail_generation(File input) throws IOException 30 | { 31 | assertFileExists("Input file does not exist", input); 32 | 33 | File output = null; 34 | try { 35 | output = File.createTempFile("test-tmp", ".png"); 36 | } catch (IOException e1) { 37 | fail("Could not create Temp file"); 38 | } 39 | 40 | currentThumbnailer.setImageSize(160, 120, 0); 41 | try { 42 | currentThumbnailer.generateThumbnail(input, output); 43 | } catch (ThumbnailerException e) { 44 | output.delete(); 45 | return; // OK 46 | } 47 | fail("No Fail-Exception was thrown, but the input file is invalid for this thumbnailer. Output: " + output.getAbsolutePath()); 48 | } 49 | 50 | @After 51 | public void tearDown() 52 | { 53 | try { 54 | if (currentThumbnailer != null) 55 | currentThumbnailer.close(); 56 | } catch (IOException e) { 57 | e.printStackTrace(); 58 | } 59 | } 60 | 61 | @Test 62 | public void testFailingScratch() throws Throwable 63 | { 64 | currentThumbnailer = new ScratchThumbnailer(); 65 | File input = new File(TESTFILES_DIR + "test.txt"); 66 | 67 | assert_fail_generation(input); 68 | } 69 | 70 | @Test 71 | public void testFailingJOD() throws IOException 72 | { 73 | currentThumbnailer = new JODWordConverterThumbnailer(); 74 | File input = new File(TESTFILES_DIR + "test.sb"); 75 | 76 | assert_fail_generation(input); 77 | } 78 | 79 | @Test 80 | public void testFailingOOo() throws IOException 81 | { 82 | currentThumbnailer = new OpenOfficeThumbnailer(); 83 | 84 | File input = new File(TESTFILES_DIR + "test.jpg"); 85 | assert_fail_generation(input); 86 | input = new File(TESTFILES_DIR + "do_not_work_yet" + File.separatorChar + "test.zip"); 87 | assert_fail_generation(input); 88 | } 89 | 90 | @Test 91 | public void testFailingPDFBox() throws IOException 92 | { 93 | currentThumbnailer = new PDFBoxThumbnailer(); 94 | File input = new File(TESTFILES_DIR + "test.jpg"); 95 | 96 | assert_fail_generation(input); 97 | } 98 | 99 | @Test 100 | public void testFailingNativeImage() throws IOException 101 | { 102 | currentThumbnailer = new NativeImageThumbnailer(); 103 | File input = new File(TESTFILES_DIR + "test.doc"); 104 | 105 | assert_fail_generation(input); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /test/src/de/uni_siegen/wineme/come_in/thumbnailer/test/integration/ThumbnailerStandaloneBasicTest.java: -------------------------------------------------------------------------------- 1 | package de.uni_siegen.wineme.come_in.thumbnailer.test.integration; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.File; 5 | import java.io.IOException; 6 | import java.util.Collection; 7 | 8 | import org.apache.commons.exec.CommandLine; 9 | import org.apache.commons.exec.DefaultExecuteResultHandler; 10 | import org.apache.commons.exec.DefaultExecutor; 11 | import org.apache.commons.exec.ExecuteException; 12 | import org.apache.commons.exec.ExecuteWatchdog; 13 | import org.apache.commons.exec.Executor; 14 | import org.apache.commons.exec.PumpStreamHandler; 15 | import org.junit.Before; 16 | import org.junit.Test; 17 | import org.junit.runner.RunWith; 18 | import org.junit.runners.Parameterized.Parameters; 19 | 20 | import de.uni_siegen.wineme.come_in.thumbnailer.test.ThumbnailerFileTestDummy; 21 | 22 | 23 | import uk.ac.lkl.common.util.testing.LabelledParameterized; 24 | 25 | @RunWith(LabelledParameterized.class) 26 | public class ThumbnailerStandaloneBasicTest extends ThumbnailerFileTestDummy 27 | { 28 | private DefaultExecuteResultHandler resultHandler; 29 | private ExecuteWatchdog watchdog; 30 | 31 | 32 | public ThumbnailerStandaloneBasicTest(String name, File input) 33 | { 34 | super(input); 35 | } 36 | 37 | @Before 38 | public void setSize() 39 | { 40 | //setImageSize(160, 120, 0); 41 | } 42 | 43 | @Test 44 | public void generateThumbnail() throws Exception 45 | { 46 | create_thumbnail(inputFile); 47 | } 48 | 49 | @Parameters 50 | public static Collection listFiles() 51 | { 52 | return getFileList(TESTFILES_DIR); 53 | } 54 | 55 | public void _create_thumbnail(File input, File output) throws Exception 56 | { 57 | CommandLine cmd = new CommandLine("java"); 58 | cmd.addArgument("-jar"); 59 | cmd.addArgument("test/build/javathumbnailer-standalone.jar"); 60 | 61 | // cmd.addArgument("-size"); 62 | // cmd.addArgument(width + "x" + height); 63 | 64 | cmd.addArgument(input.getAbsolutePath()); 65 | cmd.addArgument(output.getAbsolutePath()); 66 | 67 | System.out.println(cmd); 68 | 69 | startUp(cmd, new File(MY_DIR), 10, true); 70 | } 71 | 72 | 73 | /** 74 | * Wrapper function for commons-exec: 75 | * Execute a Command as a background or blocking process. 76 | * 77 | * @param cmd Command to execute 78 | * @param workingDir Working directory 79 | * @param timeout Kill process after this time (in sec) (0: no timeout) 80 | * @param blocking Synchronous/blocking (true) or asynchronous/background startup (false). 81 | * @return An outputstream that contains the output of the process into stdout/stderr 82 | * @throws ExecuteException Error during execution 83 | * @throws IOException File does not exist, and so could not be executed. 84 | */ 85 | protected ByteArrayOutputStream startUp(CommandLine cmdLine, File workingDir, int timeout, boolean blocking) throws ExecuteException, IOException 86 | { 87 | Executor executor = new DefaultExecutor(); 88 | resultHandler = new DefaultExecuteResultHandler(); 89 | 90 | if (timeout > 0) 91 | { 92 | watchdog = new ExecuteWatchdog(1000 * timeout); 93 | executor.setWatchdog(watchdog); 94 | } 95 | 96 | /* No live-streaming needed 97 | PipedOutputStream os = new PipedOutputStream(); 98 | InputStream is = new PipedInputStream(os); 99 | executor.setStreamHandler(new PumpStreamHandler(os)); 100 | */ 101 | 102 | ByteArrayOutputStream os = new ByteArrayOutputStream(1024); 103 | executor.setStreamHandler(new PumpStreamHandler(os)); 104 | 105 | executor.setWorkingDirectory(workingDir); 106 | executor.execute(cmdLine, resultHandler); 107 | 108 | if (blocking) 109 | { 110 | while (!resultHandler.hasResult()) { 111 | try { 112 | resultHandler.waitFor(); 113 | } catch (InterruptedException e) { } 114 | } 115 | } 116 | 117 | return os; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /test/src/de/uni_siegen/wineme/come_in/thumbnailer/test/slow/MIMEDectectionExtensiveTest.java: -------------------------------------------------------------------------------- 1 | package de.uni_siegen.wineme.come_in.thumbnailer.test.slow; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.ArrayList; 6 | import java.util.Collection; 7 | 8 | import org.apache.commons.io.FileUtils; 9 | import org.apache.commons.io.FilenameUtils; 10 | 11 | import de.uni_siegen.wineme.come_in.thumbnailer.test.TestConfiguration; 12 | import de.uni_siegen.wineme.come_in.thumbnailer.util.mime.MimeTypeDetector; 13 | 14 | import org.junit.Before; 15 | import org.junit.Test; 16 | import org.junit.runner.RunWith; 17 | import org.junit.runners.Parameterized.Parameters; 18 | 19 | import uk.ac.lkl.common.util.testing.LabelledParameterized; 20 | import static org.junit.Assert.*; 21 | 22 | // Foreach Filename in TestFileDirectory : combine extensions. 23 | @RunWith(LabelledParameterized.class) 24 | // Strange as it sounds, these tests only run inside Eclipse. In Ant, the @RunWith-Annotation seems to go ignored. I'd really like to know why! 25 | public class MIMEDectectionExtensiveTest implements TestConfiguration 26 | { 27 | private MimeTypeDetector mimeType; 28 | private File file; 29 | private String expectedMime; 30 | 31 | public MIMEDectectionExtensiveTest(String name, String expectedMime, File file) 32 | { 33 | this.file = file; 34 | this.expectedMime = expectedMime; 35 | } 36 | 37 | @Before 38 | public void setUp() throws Exception 39 | { 40 | mimeType = new MimeTypeDetector(); 41 | } 42 | 43 | @Test 44 | public void testMime() 45 | { 46 | String mime = mimeType.getMimeType(file); 47 | if (!expectedMime.equalsIgnoreCase(mime)) 48 | fail("File " + file.getName() + ": Mime is not equal: expected \"" + expectedMime + "\", but was \"" + mime + "\"."); 49 | } 50 | 51 | @Parameters 52 | public static Collection suite() throws Exception 53 | { 54 | MimeTypeDetector mimeType = new MimeTypeDetector(); 55 | 56 | File path = new File (TESTFILES_DIR); 57 | File tmpDir = File.createTempFile("test-mime-detection", ""); 58 | File[] testfiles = path.listFiles(); 59 | 60 | tmpDir.delete(); 61 | tmpDir.mkdirs(); 62 | 63 | ArrayList extensions = new ArrayList(testfiles.length); 64 | for(File input : testfiles) 65 | { 66 | if (input.isDirectory() || input.isHidden()) 67 | continue; 68 | 69 | extensions.add(FilenameUtils.getExtension(input.getName())); 70 | } 71 | extensions.add(""); 72 | 73 | Collection param = new ArrayList(); 74 | for (File input : testfiles) 75 | { 76 | if (input.isDirectory() || input.isHidden()) 77 | continue; 78 | 79 | String myName = FilenameUtils.getBaseName(input.getName()); 80 | String myExt = FilenameUtils.getExtension(input.getName()); 81 | final String myMime = mimeType.getMimeType(input); 82 | 83 | for (String otherExt : extensions) 84 | { 85 | String newFilename = tmpDir.getAbsolutePath() + File.separator + myName + "-" + myExt; 86 | if (!otherExt.isEmpty()) 87 | newFilename += "." + otherExt; 88 | 89 | File output = new File(newFilename); 90 | try { 91 | FileUtils.copyFile(input, output); 92 | 93 | param.add(new Object[]{ "test_mime_" + myExt + "_" + otherExt, myMime, output}); 94 | } catch (IOException e) { 95 | System.err.println("Warning: Filename " + output.getName() + " is could not be written."); 96 | } 97 | } 98 | } 99 | 100 | return param; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /test/src/de/uni_siegen/wineme/come_in/thumbnailer/test/slow/ThumbnailImageStrangeFilesTest.java: -------------------------------------------------------------------------------- 1 | package de.uni_siegen.wineme.come_in.thumbnailer.test.slow; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.Collection; 6 | 7 | import org.apache.commons.io.FileUtils; 8 | import org.apache.commons.io.FilenameUtils; 9 | 10 | import de.uni_siegen.wineme.come_in.thumbnailer.test.TestConfiguration; 11 | import de.uni_siegen.wineme.come_in.thumbnailer.test.ThumbnailerFileTestDummy; 12 | 13 | import org.junit.Test; 14 | import org.junit.runner.RunWith; 15 | import org.junit.runners.Parameterized.Parameters; 16 | 17 | import uk.ac.lkl.common.util.testing.LabelledParameterized; 18 | 19 | // Foreach Filename in TestFileDirectory : try to create a thumbnail. assertNoException. 20 | @RunWith(LabelledParameterized.class) 21 | // Strange as it sounds, these tests only run inside Eclipse. In Ant, the @RunWith-Annotation seems to go ignored. I'd really like to know why! 22 | public class ThumbnailImageStrangeFilesTest extends ThumbnailerFileTestDummy implements TestConfiguration 23 | { 24 | public ThumbnailImageStrangeFilesTest(String name, File input) 25 | { 26 | super(input); 27 | } 28 | 29 | @Test 30 | public void generateThumbnail() throws Exception 31 | { 32 | create_thumbnail(inputFile); 33 | } 34 | 35 | // Foreach strange filename: rename the file in the test dir. 36 | final static String STRANGE_FILENAMES[] = new String[] { "test space", "test%prozent", "test\nenter", "testäßumlaut", "....." }; 37 | 38 | @Parameters 39 | public static Collection suite() throws Exception 40 | { 41 | File path = new File (TESTFILES_DIR); 42 | File tmpDir = File.createTempFile("test-strange_files", ""); 43 | File[] testfiles = path.listFiles(); 44 | 45 | tmpDir.delete(); 46 | tmpDir.mkdirs(); 47 | for(File input : testfiles) 48 | { 49 | if (input.isDirectory()) 50 | continue; 51 | 52 | for(String name : STRANGE_FILENAMES) 53 | { 54 | File output = new File(tmpDir.getAbsolutePath() + File.separator + name + "." + FilenameUtils.getExtension(input.getName())); 55 | try { 56 | FileUtils.copyFile(input, output); 57 | } catch (IOException e) { 58 | // Filename invalid on this filesystem. 59 | System.err.println("Warning: Filename " + output.getName() + " is invalid/could not be written."); 60 | } 61 | } 62 | } 63 | 64 | return getFileList(tmpDir); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /test/src/uk/ac/lkl/common/util/testing/LabelledParameterized.java: -------------------------------------------------------------------------------- 1 | /** 2 | * From http://stackoverflow.com/questions/650894/change-test-name-of-parameterized-tests/2052202#2052202 3 | * Licence: GPLv3 4 | * Version: r3789 (Jan 2010) 5 | */ 6 | 7 | package uk.ac.lkl.common.util.testing; 8 | 9 | import java.lang.reflect.Method; 10 | import java.util.ArrayList; 11 | import java.util.Collection; 12 | import java.util.List; 13 | 14 | import org.junit.runner.Description; 15 | import org.junit.runners.Parameterized; 16 | 17 | public class LabelledParameterized extends Parameterized { 18 | 19 | private List labels; 20 | 21 | private Description labelledDescription; 22 | 23 | public LabelledParameterized(Class cl) throws Throwable { 24 | super(cl); 25 | initialiseLabels(); 26 | generateLabelledDescription(); 27 | } 28 | 29 | private void initialiseLabels() throws Exception { 30 | Collection parameterArrays = getParameterArrays(); 31 | labels = new ArrayList(); 32 | for (Object[] parameterArray : parameterArrays) { 33 | String label = parameterArray[0].toString(); 34 | labels.add(label); 35 | } 36 | 37 | } 38 | 39 | private Collection getParameterArrays() throws Exception { 40 | Method testClassMethod = getDeclaredMethod(this.getClass(), 41 | "getTestClass"); 42 | Class returnType = testClassMethod.getReturnType(); 43 | if (returnType == Class.class) 44 | return getParameterArrays4_3(); 45 | else 46 | return getParameterArrays4_4(); 47 | } 48 | 49 | private Collection getParameterArrays4_3() throws Exception { 50 | Object[][] methodCalls = new Object[][] { new Object[] { "getTestClass" } }; 51 | Class cl = invokeMethodChain(this, methodCalls); 52 | Method[] methods = cl.getMethods(); 53 | 54 | Method parametersMethod = null; 55 | for (Method method : methods) { 56 | boolean providesParameters = method 57 | .isAnnotationPresent(Parameters.class); 58 | if (!providesParameters) 59 | continue; 60 | 61 | if (parametersMethod != null) 62 | throw new Exception( 63 | "Only one method should be annotated with @Labels"); 64 | 65 | parametersMethod = method; 66 | } 67 | 68 | if (parametersMethod == null) 69 | throw new Exception("No @Parameters method found"); 70 | 71 | Collection parameterArrays = (Collection) parametersMethod 72 | .invoke(null); 73 | return parameterArrays; 74 | 75 | } 76 | 77 | private Collection getParameterArrays4_4() throws Exception { 78 | Object[][] methodCalls = new Object[][] { 79 | new Object[] { "getTestClass" }, 80 | new Object[] { "getAnnotatedMethods", Class.class, 81 | Parameters.class }, 82 | new Object[] { "get", int.class, 0 }, 83 | // use array type for varargs (equivalent (almost)) 84 | new Object[] { "invokeExplosively", Object.class, null, 85 | Object[].class, new Object[] {} } }; 86 | Collection parameterArrays = invokeMethodChain(this, 87 | methodCalls); 88 | return parameterArrays; 89 | } 90 | 91 | private T invokeMethodChain(Object object, Object[][] methodCalls) 92 | throws Exception { 93 | for (Object[] methodCall : methodCalls) { 94 | String methodName = (String) methodCall[0]; 95 | int parameterCount = (methodCall.length - 1) / 2; 96 | Class[] classes = new Class[parameterCount]; 97 | Object[] arguments = new Object[parameterCount]; 98 | for (int i = 1; i < methodCall.length; i += 2) { 99 | Class cl = (Class) methodCall[i]; 100 | Object argument = methodCall[i + 1]; 101 | int index = (i - 1) / 2; // messy! 102 | classes[index] = cl; 103 | arguments[index] = argument; 104 | } 105 | Method method = getDeclaredMethod(object.getClass(), methodName, 106 | classes); 107 | object = method.invoke(object, arguments); 108 | } 109 | return (T) object; 110 | } 111 | 112 | // iterates through super-classes until found. Throws NoSuchMethodException 113 | // if not 114 | private Method getDeclaredMethod(Class cl, String methodName, 115 | Class... parameterTypes) throws NoSuchMethodException { 116 | do { 117 | try { 118 | Method method = cl 119 | .getDeclaredMethod(methodName, parameterTypes); 120 | return method; 121 | } catch (NoSuchMethodException e) { 122 | // do nothing - just fall through to the below 123 | } 124 | cl = cl.getSuperclass(); 125 | } while (cl != null); 126 | throw new NoSuchMethodException("Method " + methodName 127 | + "() not found in hierarchy"); 128 | } 129 | 130 | private void generateLabelledDescription() throws Exception { 131 | Description originalDescription = super.getDescription(); 132 | labelledDescription = Description 133 | .createSuiteDescription(originalDescription.getDisplayName()); 134 | ArrayList childDescriptions = originalDescription 135 | .getChildren(); 136 | int childCount = childDescriptions.size(); 137 | if (childCount != labels.size()) 138 | throw new Exception( 139 | "Number of labels and number of parameters must match."); 140 | 141 | for (int i = 0; i < childDescriptions.size(); i++) { 142 | Description childDescription = childDescriptions.get(i); 143 | String label = labels.get(i); 144 | Description newDescription = Description 145 | .createSuiteDescription(label); 146 | ArrayList grandChildren = childDescription 147 | .getChildren(); 148 | for (Description grandChild : grandChildren) 149 | newDescription.addChild(grandChild); 150 | labelledDescription.addChild(newDescription); 151 | } 152 | } 153 | 154 | @Override 155 | public Description getDescription() { 156 | return labelledDescription; 157 | } 158 | 159 | } -------------------------------------------------------------------------------- /test/testfiles/do_not_work_yet/test.tiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/do_not_work_yet/test.tiff -------------------------------------------------------------------------------- /test/testfiles/do_not_work_yet/test.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/do_not_work_yet/test.zip -------------------------------------------------------------------------------- /test/testfiles/do_not_work_yet/test2.tiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/do_not_work_yet/test2.tiff -------------------------------------------------------------------------------- /test/testfiles/format/breit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/format/breit.png -------------------------------------------------------------------------------- /test/testfiles/format/hoch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/format/hoch.png -------------------------------------------------------------------------------- /test/testfiles/format/orig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/format/orig.png -------------------------------------------------------------------------------- /test/testfiles/format/small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/format/small.png -------------------------------------------------------------------------------- /test/testfiles/space space.txt: -------------------------------------------------------------------------------- 1 | test 2 | 3 | Das ist ein Testsatz und so weiter. Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter. 4 | 5 | Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter. 6 | 7 | 8 | 9 | 10 | Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter. 11 | 12 | Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter. 13 | 14 | 15 | 16 | Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter. 17 | 18 | 19 | 20 | 21 | Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter. 22 | 23 | 24 | 25 | 26 | Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter. 27 | 28 | 29 | Das ist ein Testsatz und so weiter. 30 | 31 | 32 | Special chars: 33 | !"§$%&/()=?'*#+<>|{[]}\'`áß 34 | -------------------------------------------------------------------------------- /test/testfiles/test.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/test.bmp -------------------------------------------------------------------------------- /test/testfiles/test.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/test.doc -------------------------------------------------------------------------------- /test/testfiles/test.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/test.docx -------------------------------------------------------------------------------- /test/testfiles/test.dwg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/test.dwg -------------------------------------------------------------------------------- /test/testfiles/test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Title 4 | 5 | 12 | 13 |
    Red Color
    Yellow
    14 |
    15 |
    Green Color
    16 | 19 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /test/testfiles/test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/test.jpg -------------------------------------------------------------------------------- /test/testfiles/test.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/test.odp -------------------------------------------------------------------------------- /test/testfiles/test.ods: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/test.ods -------------------------------------------------------------------------------- /test/testfiles/test.odt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/test.odt -------------------------------------------------------------------------------- /test/testfiles/test.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/test.pdf -------------------------------------------------------------------------------- /test/testfiles/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/test.png -------------------------------------------------------------------------------- /test/testfiles/test.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/test.ppt -------------------------------------------------------------------------------- /test/testfiles/test.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/test.pptx -------------------------------------------------------------------------------- /test/testfiles/test.sb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/test.sb -------------------------------------------------------------------------------- /test/testfiles/test.txt: -------------------------------------------------------------------------------- 1 | test 2 | 3 | Das ist ein Testsatz und so weiter. Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter. 4 | 5 | Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter. 6 | 7 | 8 | 9 | 10 | Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter. 11 | 12 | Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter. 13 | 14 | 15 | 16 | Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter. 17 | 18 | 19 | 20 | 21 | Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter. 22 | 23 | 24 | 25 | 26 | Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter.Das ist ein Testsatz und so weiter. 27 | 28 | 29 | Das ist ein Testsatz und so weiter. 30 | -------------------------------------------------------------------------------- /test/testfiles/test.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/test.xls -------------------------------------------------------------------------------- /test/testfiles/test.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/test.xlsx -------------------------------------------------------------------------------- /test/testfiles/test2.dwg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/test2.dwg -------------------------------------------------------------------------------- /test/testfiles/test2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Title 4 | 5 | 13 | 14 |
    Internet:
    Red Color
    Local: 15 |
    16 |
    17 |
    Green Color
    18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /test/testfiles/test3.dwg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/test3.dwg -------------------------------------------------------------------------------- /test/testfiles/tmp/sage.sb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/tmp/sage.sb -------------------------------------------------------------------------------- /test/testfiles/tmp/test_hoch.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/tmp/test_hoch.pdf -------------------------------------------------------------------------------- /test/testfiles/wrong_extension/test2-bmp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/wrong_extension/test2-bmp.png -------------------------------------------------------------------------------- /test/testfiles/wrong_extension/test2-doc.ott: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/wrong_extension/test2-doc.ott -------------------------------------------------------------------------------- /test/testfiles/wrong_extension/test2-docx.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/wrong_extension/test2-docx.doc -------------------------------------------------------------------------------- /test/testfiles/wrong_extension/test2-dwg.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/wrong_extension/test2-dwg.doc -------------------------------------------------------------------------------- /test/testfiles/wrong_extension/test2-jpg.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/wrong_extension/test2-jpg.bmp -------------------------------------------------------------------------------- /test/testfiles/wrong_extension/test2-odp.pps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/wrong_extension/test2-odp.pps -------------------------------------------------------------------------------- /test/testfiles/wrong_extension/test2-ods.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/wrong_extension/test2-ods.xls -------------------------------------------------------------------------------- /test/testfiles/wrong_extension/test2-odt.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/wrong_extension/test2-odt.doc -------------------------------------------------------------------------------- /test/testfiles/wrong_extension/test2-odt.sxw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/wrong_extension/test2-odt.sxw -------------------------------------------------------------------------------- /test/testfiles/wrong_extension/test2-pdf.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/wrong_extension/test2-pdf.ps -------------------------------------------------------------------------------- /test/testfiles/wrong_extension/test2-png.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/wrong_extension/test2-png.jpg -------------------------------------------------------------------------------- /test/testfiles/wrong_extension/test2-ppt.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/wrong_extension/test2-ppt.odp -------------------------------------------------------------------------------- /test/testfiles/wrong_extension/test2-pptx.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/wrong_extension/test2-pptx.ppt -------------------------------------------------------------------------------- /test/testfiles/wrong_extension/test2-sb.sbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/wrong_extension/test2-sb.sbx -------------------------------------------------------------------------------- /test/testfiles/wrong_extension/test2-xls.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/wrong_extension/test2-xls.odp -------------------------------------------------------------------------------- /test/testfiles/wrong_extension/test2-xlsx.ods: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/wrong_extension/test2-xlsx.ods -------------------------------------------------------------------------------- /test/testfiles/wrong_extension/test2-xlsx.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/test/testfiles/wrong_extension/test2-xlsx.ppt -------------------------------------------------------------------------------- /unitth.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Properties file for the Unit test report parser. 3 | # 4 | # This is just an example file. Please adopt it to fit your needs and 5 | # place a copy in either $HOME or in the working folder. 6 | # 7 | 8 | # 9 | # This flag indicates whether execution time graphs shall be 10 | # generated or not for the individual test cases. If omitted 11 | # the default value will be true. 12 | # 13 | unitth.generate.exectimegraphs=true 14 | 15 | # 16 | # This flag indicates the location of the index.html that 17 | # is a part of the JUnit HTML reports. Usually this file 18 | # lies in the same folder as the XML test run files. If 19 | # omitted no links will be generated. 20 | # 21 | # Example 22 | # A JUnit XML test report files are generated in folder YYYY. 23 | # In the same folder the JUnit HTML report has been generated and 24 | # placed in the subfolder XXXX. Then the unitth.html.report.path property 25 | # shall be set to XXXX. 26 | # 27 | # Example 2 Windows path with spaces 28 | # unitth.html.report.path=junit\ html 29 | # 30 | unitth.html.report.path=. 31 | 32 | # 33 | # This flag indicates where the generated HTML history report 34 | # shall end up. If omitted the default value is ./report.th. 35 | # 36 | # Example Windows paths: 37 | # unitth.report.dir=C:\\Documents\ and\ Settings\\UserName\\Desktop\\report.th 38 | # 39 | # Example relative Windows path: 40 | # unitth.report.dir=..\\..\\..\\Documents\ and\ Settings\\UserName\\Desktop\\report.th 41 | # 42 | #unitth.report.dir=../../reports/reports.unitth/report.th 43 | unitth.report.dir=build/report.out 44 | 45 | # 46 | # Use this property to define a filter for which files to be parsed in a report folder. 47 | # The method String.startsWith is used in the file filter. 48 | # 49 | # Example: 50 | # unitth.xml.report.filter=TEST- 51 | # 52 | # Example 53 | # unitth.xml.report.filter=AllTests.xml 54 | # 55 | unitth.xml.report.filter=TEST- 56 | -------------------------------------------------------------------------------- /web/img/_image_missing_orig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/web/img/_image_missing_orig.png -------------------------------------------------------------------------------- /web/img/image_missing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/web/img/image_missing.png -------------------------------------------------------------------------------- /web/img/image_missing2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjaminpick/java-thumbnailer/12c6d926273fd5e37715d4e123e0d4fa8538a7e1/web/img/image_missing2.png -------------------------------------------------------------------------------- /web/search_example.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html; charset=UTF-8" errorPage="errorpage.jsp"%> 2 | <%@taglib uri="regain-search.tld" prefix="search" %> 3 | <%@taglib uri="taglib/regain-thumbnailer.tld" prefix="thumbnailer" %> 4 | 5 | 6 | 7 | regain - <search:msg key="searchFor"/> <search:stats_query/> 8 | 9 | 10 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 34 |
    regain logo 32 | <%@include file="search_form.jsp" %> 33 |
    35 | 36 | 37 | 38 | 41 | 48 | 49 | 50 | 51 | 52 | 53 | 68 | 69 |
    39 | 40 | 42 | - 43 | 44 | 45 | ( ) 46 |   47 |

    54 |
    55 | 56 |
    57 | 58 | 59 | (: )
    60 |
    61 | 62 |
    63 |   64 | - - 65 |
    66 |
    67 |
    70 | 71 | 78 | 79 |
    80 | 81 |
    82 | <%@include file="search_form.jsp" %> 83 |
    84 | 85 | <%@include file="footer.jsp" %> 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /web/search_xml_example.jsp: -------------------------------------------------------------------------------- 1 | 2 | <%@page contentType="text/xml; charset=UTF-8" errorPage="errorpage.jsp"%> 3 | <%@taglib uri="regain-search.tld" prefix="search" %> 4 | <%@taglib uri="taglib/regain-thumbnailer.tld" prefix="thumbnailer" %> 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | <search:hit_field field="title" escape="xml"/> 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /web/taglib/regain-thumbnailer.tld: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 1.0 9 | 1.1 10 | search 11 | TagLib for the regain search engine 12 | 13 | 14 | 15 | Shows generated Thumbnail 16 | 17 | img 18 | de.uni_siegen.wineme.come_in.thumbnailer.plugin.server.taglib.ImgTag 19 | empty 20 | 21 | 22 | Width in Pixel of the Thumbnail Image (default: 160) 23 | 24 | width 25 | false 26 | 27 | 28 | 29 | Height in Pixel of the Thumbnail Image (default: 120) 30 | 31 | height 32 | false 33 | 34 | 35 | 36 | Filename of "Image Missing"-image. If not set, no Img-Tag is 37 | created in case that the thumgnail image does not exist. 38 | 39 | missing 40 | false 41 | 42 | 43 | 44 | Escape output (xml, html, none) (Default: none) 45 | 46 | escape 47 | false 48 | 49 | 50 | 51 | 52 | 53 | --------------------------------------------------------------------------------