mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
rewriteUrl for external links
git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@1146 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
547c8545d0
commit
e4edf5aade
7 changed files with 41 additions and 9 deletions
|
@ -11,6 +11,9 @@ DONE постепенная асинхронная загрузка катало
|
||||||
DELAYED нормальная архитектура для асинхронной загрузки каталогов
|
DELAYED нормальная архитектура для асинхронной загрузки каталогов
|
||||||
DELAYED асинхронная работа с сетью
|
DELAYED асинхронная работа с сетью
|
||||||
* использование rewriteUrl
|
* использование rewriteUrl
|
||||||
|
DONE link from a Book (reading mode) -- external
|
||||||
|
DONE link from a Network Library -- external
|
||||||
|
** link from a Network Library -- internal
|
||||||
|
|
||||||
* загрузка иконок:
|
* загрузка иконок:
|
||||||
* книг
|
* книг
|
||||||
|
|
|
@ -197,6 +197,7 @@ public class NetworkLibraryActivity extends ListActivity implements MenuItem.OnM
|
||||||
|
|
||||||
public void openInBrowser(String url) {
|
public void openInBrowser(String url) {
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
|
url = NetworkLibrary.Instance().rewriteUrl(url, true);
|
||||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
|
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.filesystem.*;
|
import org.geometerplus.zlibrary.core.filesystem.*;
|
||||||
|
import org.geometerplus.zlibrary.core.util.ZLNetworkUtil;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.tree.FBTree;
|
import org.geometerplus.fbreader.tree.FBTree;
|
||||||
import org.geometerplus.fbreader.network.tree.*;
|
import org.geometerplus.fbreader.network.tree.*;
|
||||||
|
@ -87,6 +88,16 @@ public class NetworkLibrary {
|
||||||
return Collections.unmodifiableList(myLinks);
|
return Collections.unmodifiableList(myLinks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String rewriteUrl(String url, boolean externalUrl) {
|
||||||
|
final String host = ZLNetworkUtil.hostFromUrl(url).toLowerCase();
|
||||||
|
for (NetworkLink link: myLinks) {
|
||||||
|
if (host.contains(link.SiteName)) {
|
||||||
|
url = link.rewriteUrl(url, externalUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
public void invalidate() {
|
public void invalidate() {
|
||||||
myUpdateChildren = true;
|
myUpdateChildren = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@ import java.util.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.core.util.ZLNetworkUtil;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.network.*;
|
import org.geometerplus.fbreader.network.*;
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,12 +84,7 @@ class OPDSCatalogItem extends NetworkCatalogItem {
|
||||||
} catch (SocketTimeoutException ex) {
|
} catch (SocketTimeoutException ex) {
|
||||||
return NetworkErrors.errorMessage("operationTimedOutMessage");
|
return NetworkErrors.errorMessage("operationTimedOutMessage");
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
try {
|
return NetworkErrors.errorMessage(NetworkErrors.ERROR_SOMETHING_WRONG, ZLNetworkUtil.hostFromUrl(urlString));
|
||||||
return NetworkErrors.errorMessage(NetworkErrors.ERROR_SOMETHING_WRONG, new URL(urlString).getHost());
|
|
||||||
} catch (MalformedURLException ex2) {
|
|
||||||
// return error???
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,6 +84,9 @@ class OPDSLink extends NetworkLink {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String rewriteUrl(String url, boolean isUrlExternal) {
|
public String rewriteUrl(String url, boolean isUrlExternal) {
|
||||||
|
if (myUrlRewritingRules == null) {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
for (URLRewritingRule rule: myUrlRewritingRules) {
|
for (URLRewritingRule rule: myUrlRewritingRules) {
|
||||||
if (rule.Apply != URLRewritingRule.APPLY_ALWAYS) {
|
if (rule.Apply != URLRewritingRule.APPLY_ALWAYS) {
|
||||||
if ((rule.Apply == URLRewritingRule.APPLY_EXTERNAL && !isUrlExternal)
|
if ((rule.Apply == URLRewritingRule.APPLY_EXTERNAL && !isUrlExternal)
|
||||||
|
|
|
@ -99,6 +99,19 @@ public class ZLNetworkUtil {
|
||||||
return new StringBuilder(url).append(delimiter).append(name).append('=').append(value).toString();
|
return new StringBuilder(url).append(delimiter).append(name).append('=').append(value).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String hostFromUrl(String url) {
|
||||||
|
String host = url;
|
||||||
|
int index = host.indexOf("://");
|
||||||
|
if (index != -1) {
|
||||||
|
host = host.substring(index + 3);
|
||||||
|
}
|
||||||
|
index = host.indexOf("/");
|
||||||
|
if (index != -1) {
|
||||||
|
host = host.substring(0, index);
|
||||||
|
}
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
public static String getUserAgent(String versionName) {
|
public static String getUserAgent(String versionName) {
|
||||||
return "FBReader/" + versionName + "(java)";
|
return "FBReader/" + versionName + "(java)";
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,8 @@ import org.geometerplus.zlibrary.ui.android.view.ZLAndroidPaintContext;
|
||||||
import org.geometerplus.zlibrary.ui.android.view.ZLAndroidWidget;
|
import org.geometerplus.zlibrary.ui.android.view.ZLAndroidWidget;
|
||||||
import org.geometerplus.zlibrary.ui.android.dialogs.ZLAndroidDialogManager;
|
import org.geometerplus.zlibrary.ui.android.dialogs.ZLAndroidDialogManager;
|
||||||
|
|
||||||
|
import org.geometerplus.fbreader.network.NetworkLibrary;
|
||||||
|
|
||||||
import org.geometerplus.android.fbreader.network.BookDownloader;
|
import org.geometerplus.android.fbreader.network.BookDownloader;
|
||||||
|
|
||||||
public final class ZLAndroidLibrary extends ZLibrary {
|
public final class ZLAndroidLibrary extends ZLibrary {
|
||||||
|
@ -72,11 +74,13 @@ public final class ZLAndroidLibrary extends ZLibrary {
|
||||||
|
|
||||||
public void openInBrowser(String reference) {
|
public void openInBrowser(String reference) {
|
||||||
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
final Uri uri = Uri.parse(reference);
|
boolean externalUrl = true;
|
||||||
if (BookDownloader.acceptsUri(uri)) {
|
if (BookDownloader.acceptsUri(Uri.parse(reference))) {
|
||||||
intent.setClass(myActivity, BookDownloader.class);
|
intent.setClass(myActivity, BookDownloader.class);
|
||||||
|
externalUrl = false;
|
||||||
}
|
}
|
||||||
intent.setData(uri);
|
reference = NetworkLibrary.Instance().rewriteUrl(reference, externalUrl);
|
||||||
|
intent.setData(Uri.parse(reference));
|
||||||
myActivity.startActivity(intent);
|
myActivity.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue