-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
263 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 2 additions & 34 deletions
36
fj-doc-val/src/main/java/org/fugerit/java/doc/val/pdf/boc/PdfboxValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,6 @@ | ||
package org.fugerit.java.doc.val.pdf.boc; | ||
|
||
import java.io.InputStream; | ||
|
||
import org.apache.pdfbox.pdmodel.PDDocument; | ||
import org.fugerit.java.doc.val.core.DocTypeValidationResult; | ||
import org.fugerit.java.doc.val.core.DocTypeValidator; | ||
import org.fugerit.java.doc.val.core.basic.AbstractDocTypeValidator; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class PdfboxValidator extends AbstractDocTypeValidator { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger( PdfboxValidator.class ); | ||
|
||
public static final String EXTENSION = "PDF"; | ||
|
||
public static final String MIME_TYPE = "application/pdf"; | ||
|
||
public static final DocTypeValidator DEFAULT = new PdfboxValidator(); | ||
|
||
public PdfboxValidator() { | ||
super( MIME_TYPE, EXTENSION ); | ||
} | ||
|
||
@Override | ||
public DocTypeValidationResult validate(InputStream is) { | ||
DocTypeValidationResult result = DocTypeValidationResult.newFail(); | ||
try { | ||
PDDocument.load( is ); | ||
result = DocTypeValidationResult.newOk(); | ||
} catch (Exception e) { | ||
logger.warn( "Failed check on pdf : "+e ); | ||
} | ||
return result; | ||
} | ||
@Deprecated | ||
public class PdfboxValidator extends org.fugerit.java.doc.val.pdf.box.PdfboxValidator { | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
fj-doc-val/src/main/java/org/fugerit/java/doc/val/pdf/box/PdfboxValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.fugerit.java.doc.val.pdf.box; | ||
|
||
import java.io.InputStream; | ||
|
||
import org.apache.pdfbox.pdmodel.PDDocument; | ||
import org.fugerit.java.doc.val.core.DocTypeValidationResult; | ||
import org.fugerit.java.doc.val.core.DocTypeValidator; | ||
import org.fugerit.java.doc.val.core.basic.AbstractDocTypeValidator; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class PdfboxValidator extends AbstractDocTypeValidator { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger( PdfboxValidator.class ); | ||
|
||
public static final String EXTENSION = "PDF"; | ||
|
||
public static final String MIME_TYPE = "application/pdf"; | ||
|
||
public static final DocTypeValidator DEFAULT = new PdfboxValidator(); | ||
|
||
public PdfboxValidator() { | ||
super( MIME_TYPE, EXTENSION ); | ||
} | ||
|
||
@Override | ||
public DocTypeValidationResult validate(InputStream is) { | ||
DocTypeValidationResult result = DocTypeValidationResult.newFail(); | ||
try { | ||
PDDocument.load( is ); | ||
result = DocTypeValidationResult.newOk(); | ||
} catch (Exception e) { | ||
logger.warn( "Failed check on pdf : "+e ); | ||
} | ||
return result; | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
fj-doc-val/src/main/java/org/fugerit/java/doc/val/poi/DocValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.fugerit.java.doc.val.poi; | ||
|
||
import java.io.InputStream; | ||
|
||
import org.apache.poi.hwpf.HWPFDocument; | ||
import org.fugerit.java.doc.val.core.DocTypeValidationResult; | ||
import org.fugerit.java.doc.val.core.DocTypeValidator; | ||
import org.fugerit.java.doc.val.core.basic.AbstractDocTypeValidator; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class DocValidator extends AbstractDocTypeValidator { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger( DocValidator.class ); | ||
|
||
public static final String EXTENSION = "DOC"; | ||
|
||
public static final String MIME_TYPE = "application/msword"; | ||
|
||
public static final DocTypeValidator DEFAULT = new DocValidator(); | ||
|
||
public DocValidator() { | ||
super( MIME_TYPE, EXTENSION ); | ||
} | ||
|
||
@Override | ||
public DocTypeValidationResult validate(InputStream is) { | ||
DocTypeValidationResult result = DocTypeValidationResult.newFail(); | ||
try ( HWPFDocument workbook = new HWPFDocument( is ) ) { | ||
result = DocTypeValidationResult.newOk(); | ||
} catch (Exception e) { | ||
logger.warn( "Failed check on pdf : "+e ); | ||
} | ||
return result; | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
fj-doc-val/src/main/java/org/fugerit/java/doc/val/poi/DocxValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.fugerit.java.doc.val.poi; | ||
|
||
import java.io.InputStream; | ||
|
||
import org.apache.poi.xwpf.usermodel.XWPFDocument; | ||
import org.fugerit.java.doc.val.core.DocTypeValidationResult; | ||
import org.fugerit.java.doc.val.core.DocTypeValidator; | ||
import org.fugerit.java.doc.val.core.basic.AbstractDocTypeValidator; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class DocxValidator extends AbstractDocTypeValidator { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger( DocxValidator.class ); | ||
|
||
public static final String EXTENSION = "DOCX"; | ||
|
||
public static final String MIME_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; | ||
|
||
public static final DocTypeValidator DEFAULT = new DocxValidator(); | ||
|
||
public DocxValidator() { | ||
super( MIME_TYPE, EXTENSION ); | ||
} | ||
|
||
@Override | ||
public DocTypeValidationResult validate(InputStream is) { | ||
DocTypeValidationResult result = DocTypeValidationResult.newFail(); | ||
try ( XWPFDocument workbook = new XWPFDocument( is ) ) { | ||
result = DocTypeValidationResult.newOk(); | ||
} catch (Exception e) { | ||
logger.warn( "Failed check on pdf : "+e ); | ||
} | ||
return result; | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
fj-doc-val/src/main/java/org/fugerit/java/doc/val/poi/XlsValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.fugerit.java.doc.val.poi; | ||
|
||
import java.io.InputStream; | ||
|
||
import org.apache.poi.hssf.usermodel.HSSFWorkbook; | ||
import org.fugerit.java.doc.val.core.DocTypeValidationResult; | ||
import org.fugerit.java.doc.val.core.DocTypeValidator; | ||
import org.fugerit.java.doc.val.core.basic.AbstractDocTypeValidator; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class XlsValidator extends AbstractDocTypeValidator { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger( XlsValidator.class ); | ||
|
||
public static final String EXTENSION = "XLS"; | ||
|
||
public static final String MIME_TYPE = "application/vnd.ms-excel"; | ||
|
||
public static final DocTypeValidator DEFAULT = new XlsValidator(); | ||
|
||
public XlsValidator() { | ||
super( MIME_TYPE, EXTENSION ); | ||
} | ||
|
||
@Override | ||
public DocTypeValidationResult validate(InputStream is) { | ||
DocTypeValidationResult result = DocTypeValidationResult.newFail(); | ||
try ( HSSFWorkbook workbook = new HSSFWorkbook( is ) ) { | ||
result = DocTypeValidationResult.newOk(); | ||
} catch (Exception e) { | ||
logger.warn( "Failed check on pdf : "+e ); | ||
} | ||
return result; | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
fj-doc-val/src/main/java/org/fugerit/java/doc/val/poi/XlsxValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.fugerit.java.doc.val.poi; | ||
|
||
import java.io.InputStream; | ||
|
||
import org.apache.poi.xssf.usermodel.XSSFWorkbook; | ||
import org.fugerit.java.doc.val.core.DocTypeValidationResult; | ||
import org.fugerit.java.doc.val.core.DocTypeValidator; | ||
import org.fugerit.java.doc.val.core.basic.AbstractDocTypeValidator; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class XlsxValidator extends AbstractDocTypeValidator { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger( XlsxValidator.class ); | ||
|
||
public static final String EXTENSION = "XLSX"; | ||
|
||
public static final String MIME_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; | ||
|
||
public static final DocTypeValidator DEFAULT = new XlsxValidator(); | ||
|
||
public XlsxValidator() { | ||
super( MIME_TYPE, EXTENSION ); | ||
} | ||
|
||
@Override | ||
public DocTypeValidationResult validate(InputStream is) { | ||
DocTypeValidationResult result = DocTypeValidationResult.newFail(); | ||
try ( XSSFWorkbook workbook = new XSSFWorkbook( is ) ) { | ||
result = DocTypeValidationResult.newOk(); | ||
} catch (Exception e) { | ||
logger.warn( "Failed check on pdf : "+e ); | ||
} | ||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
fj-doc-val/src/test/java/test/org/fugerit/java/doc/val/TestPdfBoxValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
fj-doc-val/src/test/java/test/org/fugerit/java/doc/val/TestPoiValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package test.org.fugerit.java.doc.val; | ||
|
||
import org.fugerit.java.doc.val.core.DocValidatorFacade; | ||
import org.fugerit.java.doc.val.poi.DocValidator; | ||
import org.fugerit.java.doc.val.poi.DocxValidator; | ||
import org.fugerit.java.doc.val.poi.XlsValidator; | ||
import org.fugerit.java.doc.val.poi.XlsxValidator; | ||
import org.junit.Test; | ||
|
||
public class TestPoiValidator extends TestDocValidatorFacade { | ||
|
||
private static final DocValidatorFacade FACADE = DocValidatorFacade.newFacadeStrict( | ||
DocxValidator.DEFAULT, | ||
DocValidator.DEFAULT, | ||
XlsxValidator.DEFAULT, | ||
XlsValidator.DEFAULT | ||
); | ||
|
||
@Test | ||
public void testDocAsDoc() { | ||
this.worker(FACADE, "doc_as_doc.doc", true ); | ||
} | ||
|
||
@Test | ||
public void testDocxAsDocx() { | ||
this.worker(FACADE, "docx_as_docx.docx", true ); | ||
} | ||
|
||
@Test | ||
public void testXlsAsXls() { | ||
this.worker(FACADE, "xls_as_xls.xls", true ); | ||
} | ||
|
||
@Test | ||
public void testXlsxAsXlsx() { | ||
this.worker(FACADE, "xlsx_as_xlsx.xlsx", true ); | ||
} | ||
|
||
@Test | ||
public void testDocxAsDoc() { | ||
this.worker(FACADE, "docx_as_doc.doc", false ); | ||
} | ||
|
||
@Test | ||
public void testJpgAsXlsx() { | ||
this.worker(FACADE, "jpg_as_xlsx.xlsx", false ); | ||
} | ||
|
||
@Test | ||
public void testXlsxAsXls() { | ||
this.worker(FACADE, "xlsx_as_xls.xls", false ); | ||
} | ||
|
||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.