Skip to content

Commit 3e360f4

Browse files
committed
Merge branch 'main' of github.com:opendocument-app/OpenDocument.droid into core-http
2 parents ade4a5b + fc1b249 commit 3e360f4

File tree

12 files changed

+85
-231
lines changed

12 files changed

+85
-231
lines changed

app/src/main/cpp/CoreWrapper.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jclass
7070
jfieldID txtField = env->GetFieldID(optionsClass, "txt", "Z");
7171
jboolean txt = env->GetBooleanField(options, txtField);
7272

73+
jfieldID pdfField = env->GetFieldID(optionsClass, "pdf", "Z");
74+
jboolean pdf = env->GetBooleanField(options, pdfField);
75+
7376
jfieldID pagingField = env->GetFieldID(optionsClass, "paging", "Z");
7477
jboolean paging = env->GetBooleanField(options, pagingField);
7578

@@ -114,6 +117,11 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jclass
114117
return result;
115118
}
116119

120+
if (!pdf && file.file_type() == odr::FileType::portable_document_format) {
121+
env->SetIntField(result, errorField, -5);
122+
return result;
123+
}
124+
117125
odr::HtmlConfig config;
118126
config.editable = editable;
119127

app/src/main/java/at/tomtasche/reader/background/CoreWrapper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public static class CoreOptions {
106106

107107
public boolean ooxml;
108108
public boolean txt;
109+
public boolean pdf;
109110

110111
public boolean editable;
111112

app/src/main/java/at/tomtasche/reader/background/FileLoader.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
public abstract class FileLoader {
1919

2020
public enum LoaderType {
21-
ODF,
22-
DOC,
23-
OOXML,
24-
PDF,
21+
CORE,
22+
WVWARE,
23+
PDF2HTMLEX,
2524
ONLINE,
2625
RAW,
2726
METADATA

app/src/main/java/at/tomtasche/reader/background/LoaderService.java

Lines changed: 30 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ public class LoaderService extends Service implements FileLoader.FileLoaderListe
3434
private AnalyticsManager analyticsManager;
3535

3636
private MetadataLoader metadataLoader;
37-
private OdfLoader odfLoader;
38-
private PdfLoader pdfLoader;
39-
private OoxmlLoader ooxmlLoader;
40-
private DocLoader docLoader;
37+
private OdrCoreLoader odrCoreLoader;
38+
private Pdf2htmlExLoader pdf2htmlExLoader;
39+
private WvwareDocLoader wvwareDocLoader;
4140
private RawLoader rawLoader;
4241
private OnlineLoader onlineLoader;
4342
private CoreHttpLoader coreHttpLoader;
@@ -64,22 +63,19 @@ public synchronized void onCreate() {
6463
metadataLoader = new MetadataLoader(context);
6564
metadataLoader.initialize(this, mainHandler, backgroundHandler, analyticsManager, crashManager);
6665

67-
odfLoader = new OdfLoader(context, configManager);
68-
odfLoader.initialize(this, mainHandler, backgroundHandler, analyticsManager, crashManager);
66+
odrCoreLoader = new OdrCoreLoader(context, configManager, true);
67+
odrCoreLoader.initialize(this, mainHandler, backgroundHandler, analyticsManager, crashManager);
6968

70-
pdfLoader = new PdfLoader(context);
71-
pdfLoader.initialize(this, mainHandler, backgroundHandler, analyticsManager, crashManager);
69+
pdf2htmlExLoader = new Pdf2htmlExLoader(context);
70+
pdf2htmlExLoader.initialize(this, mainHandler, backgroundHandler, analyticsManager, crashManager);
7271

73-
ooxmlLoader = new OoxmlLoader(context);
74-
ooxmlLoader.initialize(this, mainHandler, backgroundHandler, analyticsManager, crashManager);
75-
76-
docLoader = new DocLoader(context);
77-
docLoader.initialize(this, mainHandler, backgroundHandler, analyticsManager, crashManager);
72+
wvwareDocLoader = new WvwareDocLoader(context);
73+
wvwareDocLoader.initialize(this, mainHandler, backgroundHandler, analyticsManager, crashManager);
7874

7975
rawLoader = new RawLoader(context);
8076
rawLoader.initialize(this, mainHandler, backgroundHandler, analyticsManager, crashManager);
8177

82-
onlineLoader = new OnlineLoader(context, odfLoader);
78+
onlineLoader = new OnlineLoader(context, odrCoreLoader);
8379
onlineLoader.initialize(this, mainHandler, backgroundHandler, analyticsManager, crashManager);
8480

8581
coreHttpLoader = new CoreHttpLoader(context, configManager);
@@ -138,17 +134,14 @@ private void logMissingListener() {
138134
public synchronized void loadWithType(FileLoader.LoaderType loaderType, FileLoader.Options options) {
139135
FileLoader loader;
140136
switch (loaderType) {
141-
case ODF:
142-
loader = coreHttpLoader;
143-
break;
144-
case DOC:
145-
loader = coreHttpLoader;
137+
case CORE:
138+
loader = odrCoreLoader;
146139
break;
147-
case OOXML:
148-
loader = coreHttpLoader;
140+
case WVWARE:
141+
loader = wvwareDocLoader;
149142
break;
150-
case PDF:
151-
loader = coreHttpLoader;
143+
case PDF2HTMLEX:
144+
loader = pdf2htmlExLoader;
152145
break;
153146
case ONLINE:
154147
loader = onlineLoader;
@@ -170,12 +163,12 @@ public synchronized void loadWithType(FileLoader.LoaderType loaderType, FileLoad
170163
public void onSuccess(FileLoader.Result result) {
171164
FileLoader.Options options = result.options;
172165
if (result.loaderType == FileLoader.LoaderType.METADATA) {
173-
if (!odfLoader.isSupported(options)) {
166+
if (!odrCoreLoader.isSupported(options)) {
174167
crashManager.log("we do not expect this file to be an ODF: " + options.originalUri.toString());
175168
analyticsManager.report("load_odf_error_expected", FirebaseAnalytics.Param.CONTENT_TYPE, options.fileType);
176169
}
177170

178-
loadWithType(FileLoader.LoaderType.ODF, options);
171+
loadWithType(FileLoader.LoaderType.CORE, options);
179172
} else {
180173
analyticsManager.report("load_success", FirebaseAnalytics.Param.CONTENT_TYPE, options.fileType, FirebaseAnalytics.Param.CONTENT, result.loaderType.toString());
181174

@@ -204,15 +197,13 @@ public void onError(FileLoader.Result result, Throwable error) {
204197
return;
205198
}
206199

207-
if (result.loaderType == FileLoader.LoaderType.ODF) {
200+
if (result.loaderType == FileLoader.LoaderType.CORE) {
208201
analyticsManager.report("load_odf_error", FirebaseAnalytics.Param.CONTENT_TYPE, options.fileType);
209202

210-
if (pdfLoader.isSupported(options)) {
211-
loadWithType(FileLoader.LoaderType.PDF, options);
212-
} else if (ooxmlLoader.isSupported(options)) {
213-
loadWithType(FileLoader.LoaderType.OOXML, options);
214-
} else if (docLoader.isSupported(options)) {
215-
loadWithType(FileLoader.LoaderType.DOC, options);
203+
if (pdf2htmlExLoader.isSupported(options)) {
204+
loadWithType(FileLoader.LoaderType.PDF2HTMLEX, options);
205+
} else if (wvwareDocLoader.isSupported(options)) {
206+
loadWithType(FileLoader.LoaderType.WVWARE, options);
216207
} else if (rawLoader.isSupported(options)) {
217208
loadWithType(FileLoader.LoaderType.RAW, options);
218209
} else {
@@ -257,7 +248,7 @@ private void saveSync(FileLoader.Result lastResult, Uri outFile, String htmlDiff
257248
try {
258249
File fileToSave;
259250
if (htmlDiff != null) {
260-
fileToSave = odfLoader.retranslate(lastResult.options, htmlDiff);
251+
fileToSave = odrCoreLoader.retranslate(lastResult.options, htmlDiff);
261252
if (fileToSave == null) {
262253
throw new RuntimeException("retranslate failed");
263254
}
@@ -299,20 +290,16 @@ public void onDestroy() {
299290
metadataLoader.close();
300291
}
301292

302-
if (odfLoader != null) {
303-
odfLoader.close();
304-
}
305-
306-
if (pdfLoader != null) {
307-
pdfLoader.close();
293+
if (odrCoreLoader != null) {
294+
odrCoreLoader.close();
308295
}
309296

310-
if (ooxmlLoader != null) {
311-
ooxmlLoader.close();
297+
if (pdf2htmlExLoader != null) {
298+
pdf2htmlExLoader.close();
312299
}
313300

314-
if (docLoader != null) {
315-
docLoader.close();
301+
if (wvwareDocLoader != null) {
302+
wvwareDocLoader.close();
316303
}
317304

318305
if (rawLoader != null) {
@@ -323,18 +310,8 @@ public void onDestroy() {
323310
onlineLoader.close();
324311
}
325312

326-
if (coreHttpLoader != null) {
327-
coreHttpLoader.close();
328-
}
329-
330313
backgroundThread.quit();
331314

332-
if (httpThread != null) {
333-
CoreWrapper.stopServer();
334-
httpThread.interrupt();
335-
httpThread = null;
336-
}
337-
338315
super.onDestroy();
339316
}
340317

app/src/main/java/at/tomtasche/reader/background/OdfLoader.java renamed to app/src/main/java/at/tomtasche/reader/background/OdrCoreLoader.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,33 @@
88

99
import at.tomtasche.reader.nonfree.ConfigManager;
1010

11-
public class OdfLoader extends FileLoader {
11+
public class OdrCoreLoader extends FileLoader {
1212

1313
private final ConfigManager configManager;
1414

1515
private CoreWrapper lastCore;
1616
private CoreWrapper.CoreOptions lastCoreOptions;
1717

18-
public OdfLoader(Context context, ConfigManager configManager) {
19-
super(context, LoaderType.ODF);
18+
private final boolean doOoxml;
19+
20+
public OdrCoreLoader(Context context, ConfigManager configManager, boolean doOOXML) {
21+
super(context, LoaderType.CORE);
2022

2123
this.configManager = configManager;
24+
this.doOoxml = doOOXML;
2225
}
2326

2427
@Override
2528
public boolean isSupported(Options options) {
26-
return options.fileType.startsWith("application/vnd.oasis.opendocument") || options.fileType.startsWith("application/x-vnd.oasis.opendocument") || options.fileType.startsWith("application/vnd.oasis.opendocument.text-master");
29+
return options.fileType.startsWith("application/vnd.oasis.opendocument") ||
30+
options.fileType.startsWith("application/x-vnd.oasis.opendocument") ||
31+
options.fileType.startsWith("application/vnd.oasis.opendocument.text-master") ||
32+
(this.doOoxml && (
33+
options.fileType.startsWith("application/vnd.openxmlformats-officedocument.wordprocessingml.document")
34+
// TODO: enable xlsx and pptx too
35+
//options.fileType.startsWith("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") ||
36+
//options.fileType.startsWith("application/vnd.openxmlformats-officedocument.spreadsheetml.presentation");
37+
));
2738
}
2839

2940
@Override
@@ -67,7 +78,9 @@ private void translate(Options options, Result result) throws Exception {
6778
coreOptions.outputPath = cacheDirectory.getPath();
6879
coreOptions.password = options.password;
6980
coreOptions.editable = options.translatable;
70-
coreOptions.ooxml = false;
81+
coreOptions.ooxml = doOoxml;
82+
coreOptions.txt = false;
83+
coreOptions.pdf = false;
7184

7285
Boolean usePaging = configManager.getBooleanConfig("use_paging");
7386
if (usePaging == null || usePaging) {

app/src/main/java/at/tomtasche/reader/background/OnlineLoader.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,13 @@
2323
import java.io.PrintWriter;
2424
import java.io.UnsupportedEncodingException;
2525
import java.net.HttpURLConnection;
26-
import java.net.MalformedURLException;
2726
import java.net.URL;
28-
import java.net.URLConnection;
2927
import java.net.URLEncoder;
3028
import java.nio.file.Files;
3129
import java.util.UUID;
3230
import java.util.concurrent.ExecutionException;
3331

3432
import at.tomtasche.reader.nonfree.AnalyticsManager;
35-
import at.tomtasche.reader.nonfree.ConfigManager;
3633
import at.tomtasche.reader.nonfree.CrashManager;
3734

3835
public class OnlineLoader extends FileLoader {
@@ -77,14 +74,14 @@ public class OnlineLoader extends FileLoader {
7774
public static final String GOOGLE_VIEWER_URL = "https://docs.google.com/viewer?embedded=true&url=";
7875
public static final String MICROSOFT_VIEWER_URL = "https://view.officeapps.live.com/op/view.aspx?src=";
7976

80-
private final OdfLoader odfLoader;
77+
private final OdrCoreLoader odrCoreLoader;
8178

8279
private StorageReference storage;
8380
private FirebaseAuth auth;
8481

85-
public OnlineLoader(Context context, OdfLoader odfLoader) {
82+
public OnlineLoader(Context context, OdrCoreLoader odrCoreLoader) {
8683
super(context, LoaderType.ONLINE);
87-
this.odfLoader = odfLoader;
84+
this.odrCoreLoader = odrCoreLoader;
8885
}
8986

9087
@Override
@@ -129,7 +126,7 @@ public void loadSync(Options options) {
129126
try {
130127
Uri viewerUri;
131128
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
132-
("text/rtf".equals(options.fileType) || "application/vnd.wordperfect".equals(options.fileType) || odfLoader.isSupported(options) || "application/vnd.ms-excel".equals(options.fileType) || "application/msword".equals(options.fileType) || "application/vnd.ms-powerpoint".equals(options.fileType) || options.fileType.startsWith("application/vnd.openxmlformats-officedocument.") || options.fileType.equals("application/pdf"))) {
129+
("text/rtf".equals(options.fileType) || "application/vnd.wordperfect".equals(options.fileType) || odrCoreLoader.isSupported(options) || "application/vnd.ms-excel".equals(options.fileType) || "application/msword".equals(options.fileType) || "application/vnd.ms-powerpoint".equals(options.fileType) || options.fileType.startsWith("application/vnd.openxmlformats-officedocument.") || options.fileType.equals("application/pdf"))) {
133130
viewerUri = doOnlineConvert(options);
134131
} else {
135132
viewerUri = doFirebaseConvert(options);
@@ -209,7 +206,7 @@ private Uri doFirebaseConvert(Options options) throws ExecutionException, Interr
209206

210207
if (uploadTask.isSuccessful()) {
211208
Uri viewerUri;
212-
if (odfLoader.isSupported(options)) {
209+
if (odrCoreLoader.isSupported(options)) {
213210
// ODF does not seem to be supported by google docs viewer
214211
String downloadUrl = "https://us-central1-admob-app-id-9025061963.cloudfunctions.net/download?filePath=" + filePath;
215212

0 commit comments

Comments
 (0)