1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 10:49:24 +02:00

refactoring UrlInfoWithDate is a subclass of UrlInfo

This commit is contained in:
Nikolay Pultsin 2011-04-16 01:16:53 +01:00
parent aa590a5002
commit 6b7ece0f88
14 changed files with 91 additions and 126 deletions

View file

@ -39,8 +39,7 @@ import org.geometerplus.zlibrary.ui.android.R;
import org.geometerplus.fbreader.network.*; import org.geometerplus.fbreader.network.*;
import org.geometerplus.fbreader.network.opds.OPDSCustomLink; import org.geometerplus.fbreader.network.opds.OPDSCustomLink;
import org.geometerplus.fbreader.network.urlInfo.UrlInfo; import org.geometerplus.fbreader.network.urlInfo.*;
import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate;
import org.geometerplus.android.util.UIUtil; import org.geometerplus.android.util.UIUtil;
@ -90,7 +89,7 @@ public class AddCustomCatalogActivity extends Activity {
final Uri uri = intent.getData(); final Uri uri = intent.getData();
if (myLink != null) { if (myLink != null) {
setTextById(R.id.add_custom_catalog_url, myLink.getUrlInfo(UrlInfo.Type.Catalog).URL); setTextById(R.id.add_custom_catalog_url, myLink.getUrl(UrlInfo.Type.Catalog));
setTextById(R.id.add_custom_catalog_title, myLink.getTitle()); setTextById(R.id.add_custom_catalog_title, myLink.getTitle());
setTextById(R.id.add_custom_catalog_summary, myLink.getSummary()); setTextById(R.id.add_custom_catalog_summary, myLink.getSummary());
setExtraFieldsVisibility(true); setExtraFieldsVisibility(true);
@ -241,8 +240,8 @@ public class AddCustomCatalogActivity extends Activity {
setErrorByKey("invalidUrl"); setErrorByKey("invalidUrl");
return; return;
} }
final HashMap<UrlInfo.Type,UrlInfoWithDate> infos = new HashMap<UrlInfo.Type,UrlInfoWithDate>(); final UrlInfoCollection<UrlInfoWithDate> infos = new UrlInfoCollection<UrlInfoWithDate>();
infos.put(UrlInfo.Type.Catalog, new UrlInfoWithDate(textUrl)); infos.addInfo(new UrlInfoWithDate(UrlInfo.Type.Catalog, textUrl));
myLink = new OPDSCustomLink( myLink = new OPDSCustomLink(
ICustomNetworkLink.INVALID_ID, siteName, null, null, infos ICustomNetworkLink.INVALID_ID, siteName, null, null, infos
); );

View file

@ -41,8 +41,7 @@ import org.geometerplus.android.util.UIUtil;
import org.geometerplus.fbreader.network.*; import org.geometerplus.fbreader.network.*;
import org.geometerplus.fbreader.network.opds.OPDSCustomLink; import org.geometerplus.fbreader.network.opds.OPDSCustomLink;
import org.geometerplus.fbreader.network.urlInfo.UrlInfo; import org.geometerplus.fbreader.network.urlInfo.*;
import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate;
public class NetworkLibraryActivity extends NetworkBaseActivity { public class NetworkLibraryActivity extends NetworkBaseActivity {
static final String ADD_CATALOG = "android.fbreader.action.ADD_CATALOG"; static final String ADD_CATALOG = "android.fbreader.action.ADD_CATALOG";
@ -53,7 +52,7 @@ public class NetworkLibraryActivity extends NetworkBaseActivity {
private static final String ADD_CATALOG_URLS_MAP_KEY = "urls"; private static final String ADD_CATALOG_URLS_MAP_KEY = "urls";
static void addLinkToIntent(Intent intent, ICustomNetworkLink link) { static void addLinkToIntent(Intent intent, ICustomNetworkLink link) {
final String textUrl = link.getUrlInfo(UrlInfo.Type.Catalog).URL; final String textUrl = link.getUrl(UrlInfo.Type.Catalog);
intent.setData(Uri.parse(textUrl)); intent.setData(Uri.parse(textUrl));
intent intent
.putExtra(ADD_CATALOG_TITLE_KEY, link.getTitle()) .putExtra(ADD_CATALOG_TITLE_KEY, link.getTitle())
@ -73,7 +72,7 @@ public class NetworkLibraryActivity extends NetworkBaseActivity {
uri.getHost(), uri.getHost(),
intent.getStringExtra(ADD_CATALOG_TITLE_KEY), intent.getStringExtra(ADD_CATALOG_TITLE_KEY),
intent.getStringExtra(ADD_CATALOG_SUMMARY_KEY), intent.getStringExtra(ADD_CATALOG_SUMMARY_KEY),
(HashMap<UrlInfo.Type,UrlInfoWithDate>)intent.getSerializableExtra(ADD_CATALOG_URLS_MAP_KEY) (UrlInfoCollection<UrlInfoWithDate>)intent.getSerializableExtra(ADD_CATALOG_URLS_MAP_KEY)
); );
} }

View file

@ -30,8 +30,7 @@ import org.geometerplus.zlibrary.ui.android.library.ZLAndroidApplication;
import org.geometerplus.fbreader.network.ICustomNetworkLink; import org.geometerplus.fbreader.network.ICustomNetworkLink;
import org.geometerplus.fbreader.network.NetworkDatabase; import org.geometerplus.fbreader.network.NetworkDatabase;
import org.geometerplus.fbreader.network.urlInfo.UrlInfo; import org.geometerplus.fbreader.network.urlInfo.*;
import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate;
import org.geometerplus.android.util.SQLiteUtil; import org.geometerplus.android.util.SQLiteUtil;
@ -78,7 +77,7 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
@Override @Override
protected void loadCustomLinks(ICustomLinksHandler handler) { protected void loadCustomLinks(ICustomLinksHandler handler) {
final Cursor cursor = myDatabase.rawQuery("SELECT link_id,title,site_name,summary FROM Links", null); final Cursor cursor = myDatabase.rawQuery("SELECT link_id,title,site_name,summary FROM Links", null);
final HashMap<UrlInfo.Type,UrlInfoWithDate> linksMap = new HashMap<UrlInfo.Type,UrlInfoWithDate>(); final UrlInfoCollection<UrlInfoWithDate> linksMap = new UrlInfoCollection<UrlInfoWithDate>();
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
final int id = cursor.getInt(0); final int id = cursor.getInt(0);
final String title = cursor.getString(1); final String title = cursor.getString(1);
@ -88,9 +87,9 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
linksMap.clear(); linksMap.clear();
final Cursor linksCursor = myDatabase.rawQuery("SELECT key,url,update_time FROM LinkUrls WHERE link_id = " + id, null); final Cursor linksCursor = myDatabase.rawQuery("SELECT key,url,update_time FROM LinkUrls WHERE link_id = " + id, null);
while (linksCursor.moveToNext()) { while (linksCursor.moveToNext()) {
linksMap.put( linksMap.addInfo(
UrlInfo.Type.fromFixedName(linksCursor.getString(0)),
new UrlInfoWithDate( new UrlInfoWithDate(
UrlInfo.Type.fromFixedName(linksCursor.getString(0)),
linksCursor.getString(1), linksCursor.getString(1),
SQLiteUtil.getDate(linksCursor, 2) SQLiteUtil.getDate(linksCursor, 2)
) )
@ -135,7 +134,8 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
SQLiteUtil.bindString(statement, 3, link.getSummary()); SQLiteUtil.bindString(statement, 3, link.getSummary());
final long id; final long id;
final HashMap<UrlInfo.Type,UrlInfoWithDate> linksMap = new HashMap<UrlInfo.Type,UrlInfoWithDate>(); final UrlInfoCollection<UrlInfoWithDate> linksMap =
new UrlInfoCollection<UrlInfoWithDate>();
if (statement == myInsertCustomLinkStatement) { if (statement == myInsertCustomLinkStatement) {
id = statement.executeInsert(); id = statement.executeInsert();
@ -147,9 +147,9 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
final Cursor linksCursor = myDatabase.rawQuery("SELECT key,url,update_time FROM LinkUrls WHERE link_id = " + link.getId(), null); final Cursor linksCursor = myDatabase.rawQuery("SELECT key,url,update_time FROM LinkUrls WHERE link_id = " + link.getId(), null);
while (linksCursor.moveToNext()) { while (linksCursor.moveToNext()) {
linksMap.put( linksMap.addInfo(
UrlInfo.Type.fromFixedName(linksCursor.getString(0)),
new UrlInfoWithDate( new UrlInfoWithDate(
UrlInfo.Type.fromFixedName(linksCursor.getString(0)),
linksCursor.getString(1), linksCursor.getString(1),
SQLiteUtil.getDate(linksCursor, 2) SQLiteUtil.getDate(linksCursor, 2)
) )
@ -160,7 +160,8 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
for (UrlInfo.Type key : link.getUrlKeys()) { for (UrlInfo.Type key : link.getUrlKeys()) {
final UrlInfoWithDate info = link.getUrlInfo(key); final UrlInfoWithDate info = link.getUrlInfo(key);
final UrlInfoWithDate dbInfo = linksMap.remove(key); final UrlInfoWithDate dbInfo = linksMap.getInfo(key);
linksMap.removeAllInfos(key);
final SQLiteStatement urlStatement; final SQLiteStatement urlStatement;
if (dbInfo == null) { if (dbInfo == null) {
if (myInsertCustomLinkUrlStatement == null) { if (myInsertCustomLinkUrlStatement == null) {
@ -177,19 +178,19 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
} else { } else {
continue; continue;
} }
SQLiteUtil.bindString(urlStatement, 1, info.URL); SQLiteUtil.bindString(urlStatement, 1, info.Url);
SQLiteUtil.bindDate(urlStatement, 2, info.Updated); SQLiteUtil.bindDate(urlStatement, 2, info.Updated);
urlStatement.bindLong(3, id); urlStatement.bindLong(3, id);
urlStatement.bindString(4, key.getFixedName()); urlStatement.bindString(4, key.getFixedName());
urlStatement.execute(); urlStatement.execute();
} }
for (UrlInfo.Type key: linksMap.keySet()) { for (UrlInfo info : linksMap.getAllInfos()) {
if (myDeleteCustomLinkUrlStatement == null) { if (myDeleteCustomLinkUrlStatement == null) {
myDeleteCustomLinkUrlStatement = myDatabase.compileStatement( myDeleteCustomLinkUrlStatement = myDatabase.compileStatement(
"DELETE FROM LinkUrls WHERE link_id = ? AND key = ?"); "DELETE FROM LinkUrls WHERE link_id = ? AND key = ?");
} }
myDeleteCustomLinkUrlStatement.bindLong(1, id); myDeleteCustomLinkUrlStatement.bindLong(1, id);
myDeleteCustomLinkUrlStatement.bindString(2, key.getFixedName()); myDeleteCustomLinkUrlStatement.bindString(2, info.InfoType.getFixedName());
myDeleteCustomLinkUrlStatement.execute(); myDeleteCustomLinkUrlStatement.execute();
} }
} }

View file

@ -54,7 +54,7 @@ abstract class Util implements UserRegistrationConstants {
return testService( return testService(
activity, activity,
REGISTRATION_ACTION, REGISTRATION_ACTION,
link.getUrlInfo(UrlInfo.Type.SignUp).URL link.getUrl(UrlInfo.Type.SignUp)
); );
} }
@ -62,12 +62,12 @@ abstract class Util implements UserRegistrationConstants {
try { try {
final Intent intent = new Intent( final Intent intent = new Intent(
REGISTRATION_ACTION, REGISTRATION_ACTION,
Uri.parse(link.getUrlInfo(UrlInfo.Type.SignUp).URL) Uri.parse(link.getUrl(UrlInfo.Type.SignUp))
); );
if (PackageUtil.canBeStarted(activity, intent, true)) { if (PackageUtil.canBeStarted(activity, intent, true)) {
activity.startActivityForResult(new Intent( activity.startActivityForResult(new Intent(
REGISTRATION_ACTION, REGISTRATION_ACTION,
Uri.parse(link.getUrlInfo(UrlInfo.Type.SignUp).URL) Uri.parse(link.getUrl(UrlInfo.Type.SignUp))
), USER_REGISTRATION_REQUEST_CODE); ), USER_REGISTRATION_REQUEST_CODE);
} }
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
@ -100,7 +100,7 @@ abstract class Util implements UserRegistrationConstants {
return testService( return testService(
activity, activity,
action, action,
link.getUrlInfo(UrlInfo.Type.Catalog).URL link.getUrl(UrlInfo.Type.Catalog)
); );
} }
@ -108,7 +108,7 @@ abstract class Util implements UserRegistrationConstants {
try { try {
final Intent intent = new Intent( final Intent intent = new Intent(
action, action,
Uri.parse(link.getUrlInfo(UrlInfo.Type.Catalog).URL) Uri.parse(link.getUrl(UrlInfo.Type.Catalog))
); );
final NetworkAuthenticationManager mgr = link.authenticationManager(); final NetworkAuthenticationManager mgr = link.authenticationManager();
if (mgr != null) { if (mgr != null) {
@ -124,7 +124,7 @@ abstract class Util implements UserRegistrationConstants {
} }
static boolean isBrowserTopupSupported(Activity activity, INetworkLink link) { static boolean isBrowserTopupSupported(Activity activity, INetworkLink link) {
return link.getUrlInfo(UrlInfo.Type.TopUp).URL != null; return link.getUrl(UrlInfo.Type.TopUp) != null;
} }
static void openInBrowser(Context context, String url) { static void openInBrowser(Context context, String url) {

View file

@ -24,15 +24,14 @@ import java.util.*;
import org.geometerplus.zlibrary.core.util.ZLMiscUtil; import org.geometerplus.zlibrary.core.util.ZLMiscUtil;
import org.geometerplus.zlibrary.core.options.ZLStringListOption; import org.geometerplus.zlibrary.core.options.ZLStringListOption;
import org.geometerplus.fbreader.network.urlInfo.UrlInfo; import org.geometerplus.fbreader.network.urlInfo.*;
import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate;
public abstract class AbstractNetworkLink implements INetworkLink, Basket { public abstract class AbstractNetworkLink implements INetworkLink, Basket {
protected String mySiteName; protected String mySiteName;
protected String myTitle; protected String myTitle;
protected String mySummary; protected String mySummary;
protected final String myLanguage; protected final String myLanguage;
protected final TreeMap<UrlInfo.Type,UrlInfoWithDate> myInfos; protected final UrlInfoCollection<UrlInfoWithDate> myInfos;
private ZLStringListOption myBooksInBasketOption; private ZLStringListOption myBooksInBasketOption;
@ -45,12 +44,12 @@ public abstract class AbstractNetworkLink implements INetworkLink, Basket {
* @param language language of the catalog. If <code>null</code> we assume this catalog is multilanguage. * @param language language of the catalog. If <code>null</code> we assume this catalog is multilanguage.
* @param infos collection of URL infos; must always contain one URL with <code>UrlInfo.Type.Catalog</code> identifier * @param infos collection of URL infos; must always contain one URL with <code>UrlInfo.Type.Catalog</code> identifier
*/ */
public AbstractNetworkLink(String siteName, String title, String summary, String language, Map<UrlInfo.Type,UrlInfoWithDate> infos) { public AbstractNetworkLink(String siteName, String title, String summary, String language, UrlInfoCollection<UrlInfoWithDate> infos) {
mySiteName = siteName; mySiteName = siteName;
myTitle = title; myTitle = title;
mySummary = summary; mySummary = summary;
myLanguage = language != null ? language : "multi"; myLanguage = language != null ? language : "multi";
myInfos = new TreeMap<UrlInfo.Type,UrlInfoWithDate>(infos); myInfos = new UrlInfoCollection<UrlInfoWithDate>(infos);
} }
public final String getSiteName() { public final String getSiteName() {
@ -69,17 +68,25 @@ public abstract class AbstractNetworkLink implements INetworkLink, Basket {
return myLanguage; return myLanguage;
} }
public final HashMap<UrlInfo.Type,UrlInfoWithDate> urlInfoMap() { public final UrlInfoCollection<UrlInfoWithDate> urlInfoMap() {
return new HashMap<UrlInfo.Type,UrlInfoWithDate>(myInfos); return new UrlInfoCollection<UrlInfoWithDate>(myInfos);
}
public final String getUrl(UrlInfo.Type type) {
return getUrlInfo(type).Url;
} }
public final UrlInfoWithDate getUrlInfo(UrlInfo.Type type) { public final UrlInfoWithDate getUrlInfo(UrlInfo.Type type) {
final UrlInfoWithDate info = myInfos.get(type); final UrlInfoWithDate info = myInfos.getInfo(type);
return info != null ? info : UrlInfoWithDate.NULL; return info != null ? info : UrlInfoWithDate.NULL;
} }
public final Set<UrlInfo.Type> getUrlKeys() { public final Set<UrlInfo.Type> getUrlKeys() {
return myInfos.keySet(); final HashSet<UrlInfo.Type> set = new HashSet<UrlInfo.Type>();
for (UrlInfo info : myInfos.getAllInfos()) {
set.add(info.InfoType);
}
return set;
} }
public final void setSupportsBasket() { public final void setSupportsBasket() {
@ -137,7 +144,7 @@ public abstract class AbstractNetworkLink implements INetworkLink, Basket {
@Override @Override
public String toString() { public String toString() {
String icon = getUrlInfo(UrlInfo.Type.Catalog).URL; String icon = getUrl(UrlInfo.Type.Catalog);
if (icon != null) { if (icon != null) {
if (icon.length() > 64) { if (icon.length() > 64) {
icon = icon.substring(0, 61) + "..."; icon = icon.substring(0, 61) + "...";
@ -152,23 +159,4 @@ public abstract class AbstractNetworkLink implements INetworkLink, Basket {
+ "; infos=" + myInfos + "; infos=" + myInfos
+ "}"; + "}";
} }
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof AbstractNetworkLink)) {
return false;
}
final AbstractNetworkLink lnk = (AbstractNetworkLink) o;
if (!mySiteName.equals(lnk.mySiteName)
|| !myTitle.equals(lnk.myTitle)
|| !ZLMiscUtil.equals(mySummary, lnk.mySummary)
|| !ZLMiscUtil.mapsEquals(myInfos, lnk.myInfos)) {
return false;
}
return true;
}
} }

View file

@ -23,8 +23,7 @@ import java.util.HashMap;
import org.geometerplus.zlibrary.core.network.ZLNetworkException; import org.geometerplus.zlibrary.core.network.ZLNetworkException;
import org.geometerplus.fbreader.network.urlInfo.UrlInfo; import org.geometerplus.fbreader.network.urlInfo.*;
import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate;
public interface ICustomNetworkLink extends INetworkLink { public interface ICustomNetworkLink extends INetworkLink {
public static final int INVALID_ID = -1; public static final int INVALID_ID = -1;
@ -36,7 +35,7 @@ public interface ICustomNetworkLink extends INetworkLink {
void setTitle(String title); void setTitle(String title);
void setSummary(String summary); void setSummary(String summary);
HashMap<UrlInfo.Type,UrlInfoWithDate> urlInfoMap(); UrlInfoCollection<UrlInfoWithDate> urlInfoMap();
void setUrl(UrlInfo.Type type, String url); void setUrl(UrlInfo.Type type, String url);
void removeUrl(UrlInfo.Type type); void removeUrl(UrlInfo.Type type);

View file

@ -32,6 +32,7 @@ public interface INetworkLink {
String getTitle(); String getTitle();
String getSummary(); String getSummary();
String getUrl(UrlInfo.Type type);
UrlInfoWithDate getUrlInfo(UrlInfo.Type type); UrlInfoWithDate getUrlInfo(UrlInfo.Type type);
Set<UrlInfo.Type> getUrlKeys(); Set<UrlInfo.Type> getUrlKeys();

View file

@ -21,8 +21,7 @@ package org.geometerplus.fbreader.network;
import java.util.Map; import java.util.Map;
import org.geometerplus.fbreader.network.urlInfo.UrlInfo; import org.geometerplus.fbreader.network.urlInfo.*;
import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate;
public abstract class NetworkDatabase { public abstract class NetworkDatabase {
private static NetworkDatabase ourInstance; private static NetworkDatabase ourInstance;
@ -38,7 +37,7 @@ public abstract class NetworkDatabase {
protected abstract void executeAsATransaction(Runnable actions); protected abstract void executeAsATransaction(Runnable actions);
public interface ICustomLinksHandler { public interface ICustomLinksHandler {
void handleCustomLinkData(int id, String siteName, String title, String summary, Map<UrlInfo.Type,UrlInfoWithDate> infos); void handleCustomLinkData(int id, String siteName, String title, String summary, UrlInfoCollection<UrlInfoWithDate> infos);
} }
protected abstract void loadCustomLinks(ICustomLinksHandler handler); protected abstract void loadCustomLinks(ICustomLinksHandler handler);

View file

@ -33,8 +33,7 @@ import org.geometerplus.fbreader.tree.FBTree;
import org.geometerplus.fbreader.network.tree.*; import org.geometerplus.fbreader.network.tree.*;
import org.geometerplus.fbreader.network.opds.OPDSCustomLink; import org.geometerplus.fbreader.network.opds.OPDSCustomLink;
import org.geometerplus.fbreader.network.opds.OPDSLinkReader; import org.geometerplus.fbreader.network.opds.OPDSLinkReader;
import org.geometerplus.fbreader.network.urlInfo.UrlInfo; import org.geometerplus.fbreader.network.urlInfo.*;
import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate;
public class NetworkLibrary { public class NetworkLibrary {
private static NetworkLibrary ourInstance; private static NetworkLibrary ourInstance;
@ -181,10 +180,10 @@ public class NetworkLibrary {
db.loadCustomLinks( db.loadCustomLinks(
new NetworkDatabase.ICustomLinksHandler() { new NetworkDatabase.ICustomLinksHandler() {
public void handleCustomLinkData(int id, String siteName, public void handleCustomLinkData(int id, String siteName,
String title, String summary, Map<UrlInfo.Type,UrlInfoWithDate> infos) { String title, String summary, UrlInfoCollection<UrlInfoWithDate> infos) {
if (title != null && if (title != null &&
siteName != null && siteName != null &&
infos.get(UrlInfo.Type.Catalog) != null) { infos.getInfo(UrlInfo.Type.Catalog) != null) {
final ICustomNetworkLink link = new OPDSCustomLink( final ICustomNetworkLink link = new OPDSCustomLink(
id, siteName, title, summary, infos id, siteName, title, summary, infos
); );

View file

@ -90,7 +90,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager {
sid = mySidOption.getValue(); sid = mySidOption.getValue();
} }
String url = Link.getUrlInfo(UrlInfo.Type.SignIn).URL; String url = Link.getUrl(UrlInfo.Type.SignIn);
if (url == null) { if (url == null) {
throw new ZLNetworkException(NetworkException.ERROR_UNSUPPORTED_OPERATION); throw new ZLNetworkException(NetworkException.ERROR_UNSUPPORTED_OPERATION);
} }
@ -120,7 +120,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager {
@Override @Override
public void authorise(String password) throws ZLNetworkException { public void authorise(String password) throws ZLNetworkException {
String url = Link.getUrlInfo(UrlInfo.Type.SignIn).URL; String url = Link.getUrl(UrlInfo.Type.SignIn);
if (url == null) { if (url == null) {
throw new ZLNetworkException(NetworkException.ERROR_UNSUPPORTED_OPERATION); throw new ZLNetworkException(NetworkException.ERROR_UNSUPPORTED_OPERATION);
} }
@ -240,7 +240,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager {
if (sid.length() == 0) { if (sid.length() == 0) {
return null; return null;
} }
final String url = Link.getUrlInfo(UrlInfo.Type.TopUp).URL; final String url = Link.getUrl(UrlInfo.Type.TopUp);
if (url == null) { if (url == null) {
return null; return null;
} }
@ -400,7 +400,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager {
@Override @Override
public void recoverPassword(String email) throws ZLNetworkException { public void recoverPassword(String email) throws ZLNetworkException {
String url = Link.getUrlInfo(UrlInfo.Type.RecoverPassword).URL; String url = Link.getUrl(UrlInfo.Type.RecoverPassword);
if (url == null) { if (url == null) {
throw new ZLNetworkException(NetworkException.ERROR_UNSUPPORTED_OPERATION); throw new ZLNetworkException(NetworkException.ERROR_UNSUPPORTED_OPERATION);
} }

View file

@ -31,8 +31,7 @@ import org.geometerplus.zlibrary.core.util.ZLMiscUtil;
import org.geometerplus.fbreader.network.ICustomNetworkLink; import org.geometerplus.fbreader.network.ICustomNetworkLink;
import org.geometerplus.fbreader.network.NetworkException; import org.geometerplus.fbreader.network.NetworkException;
import org.geometerplus.fbreader.network.urlInfo.UrlInfo; import org.geometerplus.fbreader.network.urlInfo.*;
import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate;
public class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLink { public class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLink {
private int myId; private int myId;
@ -46,7 +45,7 @@ public class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLin
return siteName; return siteName;
} }
public OPDSCustomLink(int id, String siteName, String title, String summary, Map<UrlInfo.Type,UrlInfoWithDate> infos) { public OPDSCustomLink(int id, String siteName, String title, String summary, UrlInfoCollection<UrlInfoWithDate> infos) {
super(removeWWWPrefix(siteName), title, summary, null, infos, false); super(removeWWWPrefix(siteName), title, summary, null, infos, false);
myId = id; myId = id;
} }
@ -83,13 +82,13 @@ public class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLin
} }
public final void setUrl(UrlInfo.Type type, String url) { public final void setUrl(UrlInfo.Type type, String url) {
myInfos.put(type, new UrlInfoWithDate(url, new Date())); myInfos.addInfo(new UrlInfoWithDate(type, url));
myHasChanges = true; myHasChanges = true;
} }
public final void removeUrl(UrlInfo.Type type) { public final void removeUrl(UrlInfo.Type type) {
final UrlInfoWithDate oldUrl = myInfos.remove(type); myHasChanges = myHasChanges || myInfos.getInfo(type) != null;
myHasChanges = myHasChanges || oldUrl != null; myInfos.removeAllInfos(type);
} }
public boolean isObsolete(long milliSeconds) { public boolean isObsolete(long milliSeconds) {
@ -114,7 +113,7 @@ public class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLin
ZLNetworkException error = null; ZLNetworkException error = null;
try { try {
ZLNetworkManager.Instance().perform(new ZLNetworkRequest(getUrlInfo(UrlInfo.Type.Catalog).URL) { ZLNetworkManager.Instance().perform(new ZLNetworkRequest(getUrl(UrlInfo.Type.Catalog)) {
@Override @Override
public void handleStream(URLConnection connection, InputStream inputStream) throws IOException, ZLNetworkException { public void handleStream(URLConnection connection, InputStream inputStream) throws IOException, ZLNetworkException {
final CatalogInfoReader info = new CatalogInfoReader(URL, OPDSCustomLink.this, opensearchDescriptionURLs); final CatalogInfoReader info = new CatalogInfoReader(URL, OPDSCustomLink.this, opensearchDescriptionURLs);

View file

@ -32,8 +32,7 @@ import org.geometerplus.fbreader.network.atom.ATOMLink;
import org.geometerplus.fbreader.network.atom.ATOMUpdated; import org.geometerplus.fbreader.network.atom.ATOMUpdated;
import org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager; import org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager;
import org.geometerplus.fbreader.network.authentication.litres.LitResAuthenticationManager; import org.geometerplus.fbreader.network.authentication.litres.LitResAuthenticationManager;
import org.geometerplus.fbreader.network.urlInfo.UrlInfo; import org.geometerplus.fbreader.network.urlInfo.*;
import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate;
class OPDSLinkXMLReader extends OPDSXMLReader implements OPDSConstants, MimeTypes { class OPDSLinkXMLReader extends OPDSXMLReader implements OPDSConstants, MimeTypes {
private static class LinkReader implements OPDSFeedReader { private static class LinkReader implements OPDSFeedReader {
@ -98,7 +97,8 @@ class OPDSLinkXMLReader extends OPDSXMLReader implements OPDSConstants, MimeType
final String summary = entry.Content; final String summary = entry.Content;
final String language = entry.DCLanguage; final String language = entry.DCLanguage;
final HashMap<UrlInfo.Type,UrlInfoWithDate> infos = new HashMap<UrlInfo.Type,UrlInfoWithDate>(); final UrlInfoCollection<UrlInfoWithDate> infos =
new UrlInfoCollection<UrlInfoWithDate>();
final HashMap<String,NetworkCatalogItem.Accessibility> urlConditions = final HashMap<String,NetworkCatalogItem.Accessibility> urlConditions =
new HashMap<String,NetworkCatalogItem.Accessibility>(); new HashMap<String,NetworkCatalogItem.Accessibility>();
for (ATOMLink link: entry.Links) { for (ATOMLink link: entry.Links) {
@ -107,34 +107,34 @@ class OPDSLinkXMLReader extends OPDSXMLReader implements OPDSConstants, MimeType
final String rel = link.getRel(); final String rel = link.getRel();
if (rel == REL_IMAGE_THUMBNAIL || rel == REL_THUMBNAIL) { if (rel == REL_IMAGE_THUMBNAIL || rel == REL_THUMBNAIL) {
if (type == MIME_IMAGE_PNG || type == MIME_IMAGE_JPEG) { if (type == MIME_IMAGE_PNG || type == MIME_IMAGE_JPEG) {
infos.put(UrlInfo.Type.Thumbnail, new UrlInfoWithDate(href)); infos.addInfo(new UrlInfoWithDate(UrlInfo.Type.Thumbnail, href));
} }
} else if ((rel != null && rel.startsWith(REL_IMAGE_PREFIX)) || rel == REL_COVER) { } else if ((rel != null && rel.startsWith(REL_IMAGE_PREFIX)) || rel == REL_COVER) {
if (type == MIME_IMAGE_PNG || type == MIME_IMAGE_JPEG) { if (type == MIME_IMAGE_PNG || type == MIME_IMAGE_JPEG) {
infos.put(UrlInfo.Type.Image, new UrlInfoWithDate(href)); infos.addInfo(new UrlInfoWithDate(UrlInfo.Type.Image, href));
} }
} else if (rel == null) { } else if (rel == null) {
if (type == MIME_APP_ATOM) { if (type == MIME_APP_ATOM) {
infos.put(UrlInfo.Type.Catalog, new UrlInfoWithDate(href)); infos.addInfo(new UrlInfoWithDate(UrlInfo.Type.Catalog, href));
} }
} else if (rel == "search") { } else if (rel == "search") {
if (type == MIME_APP_ATOM) { if (type == MIME_APP_ATOM) {
final OpenSearchDescription descr = OpenSearchDescription.createDefault(href); final OpenSearchDescription descr = OpenSearchDescription.createDefault(href);
if (descr.isValid()) { if (descr.isValid()) {
// TODO: May be do not use '%s'??? Use Description instead??? (this needs to rewrite SEARCH engine logic a little) // TODO: May be do not use '%s'??? Use Description instead??? (this needs to rewrite SEARCH engine logic a little)
infos.put(UrlInfo.Type.Search, new UrlInfoWithDate(descr.makeQuery("%s"))); infos.addInfo(new UrlInfoWithDate(UrlInfo.Type.Search, descr.makeQuery("%s")));
} }
} }
} else if (rel == REL_LINK_SIGN_IN) { } else if (rel == REL_LINK_SIGN_IN) {
infos.put(UrlInfo.Type.SignIn, new UrlInfoWithDate(href)); infos.addInfo(new UrlInfoWithDate(UrlInfo.Type.SignIn, href));
} else if (rel == REL_LINK_SIGN_OUT) { } else if (rel == REL_LINK_SIGN_OUT) {
infos.put(UrlInfo.Type.SignOut, new UrlInfoWithDate(href)); infos.addInfo(new UrlInfoWithDate(UrlInfo.Type.SignOut, href));
} else if (rel == REL_LINK_SIGN_UP) { } else if (rel == REL_LINK_SIGN_UP) {
infos.put(UrlInfo.Type.SignUp, new UrlInfoWithDate(href)); infos.addInfo(new UrlInfoWithDate(UrlInfo.Type.SignUp, href));
} else if (rel == REL_LINK_TOPUP) { } else if (rel == REL_LINK_TOPUP) {
infos.put(UrlInfo.Type.TopUp, new UrlInfoWithDate(href)); infos.addInfo(new UrlInfoWithDate(UrlInfo.Type.TopUp, href));
} else if (rel == REL_LINK_RECOVER_PASSWORD) { } else if (rel == REL_LINK_RECOVER_PASSWORD) {
infos.put(UrlInfo.Type.RecoverPassword, new UrlInfoWithDate(href)); infos.addInfo(new UrlInfoWithDate(UrlInfo.Type.RecoverPassword, href));
} else if (rel == REL_CONDITION_NEVER) { } else if (rel == REL_CONDITION_NEVER) {
urlConditions.put(href, NetworkCatalogItem.Accessibility.NEVER); urlConditions.put(href, NetworkCatalogItem.Accessibility.NEVER);
} else if (rel == REL_CONDITION_SIGNED_IN) { } else if (rel == REL_CONDITION_SIGNED_IN) {
@ -164,11 +164,11 @@ class OPDSLinkXMLReader extends OPDSXMLReader implements OPDSConstants, MimeType
String title, String title,
String summary, String summary,
String language, String language,
Map<UrlInfo.Type,UrlInfoWithDate> infos, UrlInfoCollection<UrlInfoWithDate> infos,
HashMap<String,NetworkCatalogItem.Accessibility> urlConditions, HashMap<String,NetworkCatalogItem.Accessibility> urlConditions,
String sslCertificate String sslCertificate
) { ) {
if (siteName == null || title == null || infos.get(UrlInfo.Type.Catalog) == null) { if (siteName == null || title == null || infos.getInfo(UrlInfo.Type.Catalog) == null) {
return null; return null;
} }

View file

@ -45,7 +45,7 @@ public class OPDSNetworkLink extends AbstractNetworkLink {
private final boolean myHasStableIdentifiers; private final boolean myHasStableIdentifiers;
OPDSNetworkLink(String siteName, String title, String summary, String language, OPDSNetworkLink(String siteName, String title, String summary, String language,
Map<UrlInfo.Type,UrlInfoWithDate> infos, boolean hasStableIdentifiers) { UrlInfoCollection<UrlInfoWithDate> infos, boolean hasStableIdentifiers) {
super(siteName, title, summary, language, infos); super(siteName, title, summary, language, infos);
myHasStableIdentifiers = hasStableIdentifiers; myHasStableIdentifiers = hasStableIdentifiers;
} }
@ -118,7 +118,7 @@ public class OPDSNetworkLink extends AbstractNetworkLink {
} }
public ZLNetworkRequest simpleSearchRequest(String pattern, NetworkOperationData data) { public ZLNetworkRequest simpleSearchRequest(String pattern, NetworkOperationData data) {
final String url = getUrlInfo(UrlInfo.Type.Search).URL; final String url = getUrl(UrlInfo.Type.Search);
if (url == null) { if (url == null) {
return null; return null;
} }
@ -135,8 +135,9 @@ public class OPDSNetworkLink extends AbstractNetworkLink {
public NetworkCatalogItem libraryItem() { public NetworkCatalogItem libraryItem() {
final UrlInfoCollection urlMap = new UrlInfoCollection(); final UrlInfoCollection urlMap = new UrlInfoCollection();
urlMap.addInfo(new UrlInfo(UrlInfo.Type.Catalog, getUrlInfo(UrlInfo.Type.Catalog).URL)); urlMap.addInfo(getUrlInfo(UrlInfo.Type.Catalog));
urlMap.addInfo(new UrlInfo(UrlInfo.Type.Image, getUrlInfo(UrlInfo.Type.Image).URL)); urlMap.addInfo(getUrlInfo(UrlInfo.Type.Image));
urlMap.addInfo(getUrlInfo(UrlInfo.Type.Thumbnail));
return new OPDSCatalogItem(this, getTitle(), getSummary(), urlMap, myExtraData); return new OPDSCatalogItem(this, getTitle(), getSummary(), urlMap, myExtraData);
} }
@ -193,26 +194,4 @@ public class OPDSNetworkLink extends AbstractNetworkLink {
+ "; rewritingRules=" + myUrlRewritingRules + "; rewritingRules=" + myUrlRewritingRules
+ "}"; + "}";
} }
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof OPDSNetworkLink)) {
return false;
}
if (!super.equals(o)) {
return false;
}
final OPDSNetworkLink lnk = (OPDSNetworkLink) o;
if (myHasStableIdentifiers != lnk.myHasStableIdentifiers
|| !ZLMiscUtil.mapsEquals(myRelationAliases, lnk.myRelationAliases)
|| !ZLMiscUtil.mapsEquals(myUrlConditions, lnk.myUrlConditions)
|| !ZLMiscUtil.listsEquals(myUrlRewritingRules, lnk.myUrlRewritingRules)
|| myAuthenticationManager != lnk.myAuthenticationManager) {
return false;
}
return true;
}
} }

View file

@ -24,21 +24,20 @@ import java.io.Serializable;
import org.geometerplus.zlibrary.core.util.ZLMiscUtil; import org.geometerplus.zlibrary.core.util.ZLMiscUtil;
public final class UrlInfoWithDate implements Serializable { public final class UrlInfoWithDate extends UrlInfo {
private static final long serialVersionUID = -893514485257787222L; private static final long serialVersionUID = -896768978957787222L;
public static final UrlInfoWithDate NULL = new UrlInfoWithDate(null, null); public static final UrlInfoWithDate NULL = new UrlInfoWithDate(null, null);
public final String URL;
public final Date Updated; public final Date Updated;
public UrlInfoWithDate(String url, Date updated) { public UrlInfoWithDate(Type type, String url, Date updated) {
URL = url; super(type, url);
Updated = updated; Updated = updated;
} }
public UrlInfoWithDate(String url) { public UrlInfoWithDate(Type type, String url) {
this(url, new Date()); this(type, url, new Date());
} }
@Override @Override
@ -51,11 +50,14 @@ public final class UrlInfoWithDate implements Serializable {
} }
final UrlInfoWithDate info = (UrlInfoWithDate)o; final UrlInfoWithDate info = (UrlInfoWithDate)o;
return ZLMiscUtil.equals(URL, info.URL) && ZLMiscUtil.equals(Updated, info.Updated); return
InfoType == info.InfoType &&
ZLMiscUtil.equals(Url, info.Url) &&
ZLMiscUtil.equals(Updated, info.Updated);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return ZLMiscUtil.hashCode(URL) + ZLMiscUtil.hashCode(Updated); return InfoType.hashCode() + ZLMiscUtil.hashCode(Url) + ZLMiscUtil.hashCode(Updated);
} }
} }