Skip to content

Commit

Permalink
fix svm and document translation
Browse files Browse the repository at this point in the history
  • Loading branch information
TomTasche committed Sep 11, 2013
1 parent b34b283 commit eaeee4b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 34 deletions.
1 change: 1 addition & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/commons"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/OpenDocument.java"/>
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/svm"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
6 changes: 3 additions & 3 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="at.tomtasche.reader"
android:installLocation="auto"
android:versionCode="46"
android:versionName="2.11" >
android:versionCode="47"
android:versionName="2.11.1" >

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down Expand Up @@ -173,4 +173,4 @@
android:exported="true" />
</application>

</manifest>
</manifest>
2 changes: 1 addition & 1 deletion odf2html
Submodule odf2html updated from c63201 to 545b2d
58 changes: 28 additions & 30 deletions src/at/tomtasche/reader/background/DocumentLoader.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package at.tomtasche.reader.background;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import android.content.Context;
import android.net.Uri;
import android.support.v4.content.AsyncTaskLoader;
import at.stefl.commons.lwxml.writer.LWXMLStreamWriter;
import at.stefl.commons.lwxml.writer.LWXMLWriter;
import at.stefl.commons.math.vector.Vector2i;
import at.stefl.commons.util.collection.OrderedPair;
import at.stefl.opendocument.java.odf.LocatedOpenDocumentFile;
import at.stefl.opendocument.java.odf.OpenDocument;
import at.stefl.opendocument.java.odf.OpenDocumentPresentation;
Expand All @@ -21,6 +19,7 @@
import at.stefl.opendocument.java.translator.document.BulkPresentationTranslator;
import at.stefl.opendocument.java.translator.document.BulkSpreadsheetTranslator;
import at.stefl.opendocument.java.translator.document.DocumentTranslatorUtil;
import at.stefl.opendocument.java.translator.document.DocumentTranslatorUtil.BulkOutput;
import at.stefl.opendocument.java.translator.document.GenericBulkDocumentTranslator;
import at.stefl.opendocument.java.translator.document.GenericDocumentTranslator;
import at.stefl.opendocument.java.translator.document.TextTranslator;
Expand Down Expand Up @@ -171,46 +170,45 @@ public Document loadInBackground() {
document.setLimited(true);
}

List<String> pageNames = null;
if (openDocument instanceof OpenDocumentText) {
pageNames = new LinkedList<String>();
pageNames.add("Document");
File htmlFile = cache.create("temp.html");
FileWriter writer = new FileWriter(htmlFile);
LWXMLWriter out = new LWXMLStreamWriter(writer);
try {
translator = new TextTranslator();

translator.translate(openDocument, out, settings);
} finally {
out.close();
writer.close();
}

translator = new TextTranslator();
document.addPage(new Page("Document", htmlFile.toURI(), 0));
} else {
GenericBulkDocumentTranslator<?, ?, ?> bulkTranslator = null;
if (openDocument instanceof OpenDocumentSpreadsheet) {
bulkTranslator = new BulkSpreadsheetTranslator();

OpenDocumentSpreadsheet spreadsheet = (OpenDocumentSpreadsheet) openDocument;

pageNames = new ArrayList<String>(
spreadsheet.getTableNames());
} else if (openDocument instanceof OpenDocumentPresentation) {
bulkTranslator = new BulkPresentationTranslator();

OpenDocumentPresentation presentation = (OpenDocumentPresentation) openDocument;

pageNames = new ArrayList<String>(
presentation.getPageNames());
}

translator = bulkTranslator;
}

OrderedPair<String[], LWXMLWriter> output = DocumentTranslatorUtil
.provideOutput(openDocument, cache, "temp", ".html");
try {
translator.translate(openDocument, output.getElement2(),
settings);
} finally {
output.getElement2().close();
}
BulkOutput output = DocumentTranslatorUtil.provideBulkOutput(
openDocument, cache, "temp", ".html");
try {
translator.translate(openDocument, output.getWriter(),
settings);
} finally {
output.getWriter().close();
}

for (int i = 0; i < output.getElement1().length; i++) {
File htmlFile = cache.getFile(output.getElement1()[i]);
for (int i = 0; i < output.getNames().size(); i++) {
File htmlFile = cache.getFile(output.getNames().get(i));

document.addPage(new Page(pageNames.get(i), htmlFile.toURI(), i));
document.addPage(new Page(output.getTitles().get(i),
htmlFile.toURI(), i));
}
}

return document;
Expand Down

0 comments on commit eaeee4b

Please sign in to comment.