Skip to content

Commit e0a73db

Browse files
committed
programm now recognize, which type of extractor is usefull
1 parent 71367f4 commit e0a73db

File tree

6 files changed

+78
-6
lines changed

6 files changed

+78
-6
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import com.typesafe.sbt.SbtNativePackager.autoImport._
22

33
name := "doc2text"
44

5-
version := "1.0"
5+
version := "1.1"
66

77
scalaVersion := "2.10.6"
88

src/main/scala/p1tt187/doc2text/Doc2TextApp.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,23 @@ package p1tt187.doc2text
33
import java.io.{File, FileInputStream, FileNotFoundException, FileOutputStream}
44
import java.util.Formatter
55

6-
import org.apache.poi.hwpf.extractor.WordExtractor
6+
import p1tt187.doc2text.extractor.ExtractorChooser
77

88
/**
99
* @author fabian
1010
* on 18.10.15.
1111
*/
12-
13-
1412
object Doc2TextApp extends App {
13+
1514
val results = args.map { arg =>
1615
try {
17-
val wordExtractor = new WordExtractor(new FileInputStream(arg))
16+
val wordExtractor = ExtractorChooser(new FileInputStream(arg))
1817
val tmpFile = File.createTempFile(arg, ".txt")
1918
val output = new Formatter(new FileOutputStream(tmpFile))
2019
output.format("%s", wordExtractor.getText)
2120
output.flush()
2221
output.close()
23-
wordExtractor.close()
22+
wordExtractor.close
2423
tmpFile.getAbsolutePath
2524
} catch {
2625
case ex: FileNotFoundException =>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package p1tt187.doc2text.extractor
2+
3+
import java.io.FileInputStream
4+
5+
/**
6+
* @author fabian
7+
* on 07.11.15.
8+
*/
9+
object ExtractorChooser {
10+
def apply( fileInputStream: FileInputStream ):TExtractor={
11+
try {
12+
new WExtractor(fileInputStream)
13+
} catch {
14+
case _: Exception =>
15+
new W6Extractor(fileInputStream)
16+
}
17+
}
18+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package p1tt187.doc2text.extractor
2+
3+
/**
4+
* @author fabian
5+
* on 07.11.15.
6+
*/
7+
trait TExtractor {
8+
9+
def getText:String
10+
11+
def close:Unit
12+
13+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package p1tt187.doc2text.extractor
2+
3+
import java.io.FileInputStream
4+
5+
import org.apache.poi.hwpf.extractor.Word6Extractor
6+
7+
/**
8+
* @author fabian
9+
* on 07.11.15.
10+
*/
11+
class W6Extractor(fileInputStream: FileInputStream) extends TExtractor{
12+
13+
private val word6Extractor = new Word6Extractor(fileInputStream)
14+
15+
override def close: Unit = {word6Extractor.close()}
16+
17+
override def getText: String = {
18+
word6Extractor.getText
19+
}
20+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package p1tt187.doc2text.extractor
2+
3+
import java.io.FileInputStream
4+
5+
import org.apache.poi.hwpf.extractor.WordExtractor
6+
7+
/**
8+
* @author fabian
9+
* on 07.11.15.
10+
*/
11+
class WExtractor(fileInputStream: FileInputStream) extends TExtractor{
12+
13+
private val wordExtractor: WordExtractor = new WordExtractor(fileInputStream)
14+
15+
override def close: Unit = {
16+
wordExtractor.close()
17+
}
18+
19+
override def getText: String = {
20+
wordExtractor.getText
21+
}
22+
}

0 commit comments

Comments
 (0)