-
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathWvwareDocLoader.java
More file actions
60 lines (43 loc) · 1.72 KB
/
WvwareDocLoader.java
File metadata and controls
60 lines (43 loc) · 1.72 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package at.tomtasche.reader.background;
import android.content.Context;
import android.net.Uri;
import com.viliussutkus89.android.wvware.wvWare;
import java.io.File;
public class WvwareDocLoader extends FileLoader {
public WvwareDocLoader(Context context) {
super(context, LoaderType.WVWARE);
}
@Override
public boolean isSupported(Options options) {
return options.fileType.startsWith("application/msword");
}
@Override
public void loadSync(Options options) {
final Result result = new Result();
result.options = options;
result.loaderType = type;
try {
File cacheFile = AndroidFileCache.getCacheFile(context, options.cacheUri);
File cacheDirectory = AndroidFileCache.getCacheDirectory(cacheFile);
wvWare docConverter = new wvWare(context).setInputDOC(cacheFile);
if (options.password != null) {
docConverter.setPassword(options.password);
}
File output = docConverter.convertToHTML();
File htmlFile = new File(cacheDirectory, "doc.html");
StreamUtil.copy(output, htmlFile);
// library does not delete output files automatically
output.delete();
Uri finalUri = Uri.fromFile(htmlFile);
options.fileType = "application/msword";
result.partTitles.add(null);
result.partUris.add(finalUri);
callOnSuccess(result);
} catch (Throwable e) {
if (e instanceof wvWare.PasswordRequiredException || e instanceof wvWare.WrongPasswordException) {
e = new EncryptedDocumentException();
}
callOnError(result, e);
}
}
}