diff --git a/src/org/geometerplus/android/fbreader/network/AddCustomCatalogActivity.java b/src/org/geometerplus/android/fbreader/network/AddCustomCatalogActivity.java index 609bc2d48..9d391a87d 100644 --- a/src/org/geometerplus/android/fbreader/network/AddCustomCatalogActivity.java +++ b/src/org/geometerplus/android/fbreader/network/AddCustomCatalogActivity.java @@ -39,6 +39,7 @@ import org.geometerplus.zlibrary.ui.android.R; import org.geometerplus.fbreader.network.*; import org.geometerplus.fbreader.network.opds.OPDSCustomLink; +import org.geometerplus.fbreader.network.urlInfo.UrlInfo; import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate; import org.geometerplus.android.util.UIUtil; @@ -89,7 +90,7 @@ public class AddCustomCatalogActivity extends Activity { final Uri uri = intent.getData(); if (myLink != null) { - setTextById(R.id.add_custom_catalog_url, myLink.getUrlInfo(INetworkLink.URL_MAIN).URL); + setTextById(R.id.add_custom_catalog_url, myLink.getUrlInfo(UrlInfo.Type.Catalog).URL); setTextById(R.id.add_custom_catalog_title, myLink.getTitle()); setTextById(R.id.add_custom_catalog_summary, myLink.getSummary()); setExtraFieldsVisibility(true); @@ -130,7 +131,7 @@ public class AddCustomCatalogActivity extends Activity { } else { myLink.setTitle(title); myLink.setSummary(summary); - myLink.setUrl(INetworkLink.URL_MAIN, uri.toString()); + myLink.setUrl(UrlInfo.Type.Catalog, uri.toString()); Intent intent = new Intent( NetworkLibraryActivity.ADD_CATALOG, @@ -240,8 +241,8 @@ public class AddCustomCatalogActivity extends Activity { setErrorByKey("invalidUrl"); return; } - final HashMap infos = new HashMap(); - infos.put(INetworkLink.URL_MAIN, new UrlInfoWithDate(textUrl)); + final HashMap infos = new HashMap(); + infos.put(UrlInfo.Type.Catalog, new UrlInfoWithDate(textUrl)); myLink = new OPDSCustomLink( ICustomNetworkLink.INVALID_ID, siteName, null, null, infos ); diff --git a/src/org/geometerplus/android/fbreader/network/NetworkLibraryActivity.java b/src/org/geometerplus/android/fbreader/network/NetworkLibraryActivity.java index f8245e6d5..d84c061fc 100644 --- a/src/org/geometerplus/android/fbreader/network/NetworkLibraryActivity.java +++ b/src/org/geometerplus/android/fbreader/network/NetworkLibraryActivity.java @@ -41,6 +41,7 @@ import org.geometerplus.android.util.UIUtil; import org.geometerplus.fbreader.network.*; import org.geometerplus.fbreader.network.opds.OPDSCustomLink; +import org.geometerplus.fbreader.network.urlInfo.UrlInfo; import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate; public class NetworkLibraryActivity extends NetworkBaseActivity { @@ -52,7 +53,7 @@ public class NetworkLibraryActivity extends NetworkBaseActivity { private static final String ADD_CATALOG_URLS_MAP_KEY = "urls"; static void addLinkToIntent(Intent intent, ICustomNetworkLink link) { - final String textUrl = link.getUrlInfo(INetworkLink.URL_MAIN).URL; + final String textUrl = link.getUrlInfo(UrlInfo.Type.Catalog).URL; intent.setData(Uri.parse(textUrl)); intent .putExtra(ADD_CATALOG_TITLE_KEY, link.getTitle()) @@ -72,7 +73,7 @@ public class NetworkLibraryActivity extends NetworkBaseActivity { uri.getHost(), intent.getStringExtra(ADD_CATALOG_TITLE_KEY), intent.getStringExtra(ADD_CATALOG_SUMMARY_KEY), - (HashMap)intent.getSerializableExtra(ADD_CATALOG_URLS_MAP_KEY) + (HashMap)intent.getSerializableExtra(ADD_CATALOG_URLS_MAP_KEY) ); } diff --git a/src/org/geometerplus/android/fbreader/network/SQLiteNetworkDatabase.java b/src/org/geometerplus/android/fbreader/network/SQLiteNetworkDatabase.java index 9f9823131..2df8a959d 100644 --- a/src/org/geometerplus/android/fbreader/network/SQLiteNetworkDatabase.java +++ b/src/org/geometerplus/android/fbreader/network/SQLiteNetworkDatabase.java @@ -30,6 +30,7 @@ import org.geometerplus.zlibrary.ui.android.library.ZLAndroidApplication; import org.geometerplus.fbreader.network.ICustomNetworkLink; import org.geometerplus.fbreader.network.NetworkDatabase; +import org.geometerplus.fbreader.network.urlInfo.UrlInfo; import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate; import org.geometerplus.android.util.SQLiteUtil; @@ -77,7 +78,7 @@ class SQLiteNetworkDatabase extends NetworkDatabase { @Override protected void loadCustomLinks(ICustomLinksHandler handler) { final Cursor cursor = myDatabase.rawQuery("SELECT link_id,title,site_name,summary FROM Links", null); - final HashMap linksMap = new HashMap(); + final HashMap linksMap = new HashMap(); while (cursor.moveToNext()) { final int id = cursor.getInt(0); final String title = cursor.getString(1); @@ -88,7 +89,7 @@ class SQLiteNetworkDatabase extends NetworkDatabase { final Cursor linksCursor = myDatabase.rawQuery("SELECT key,url,update_time FROM LinkUrls WHERE link_id = " + id, null); while (linksCursor.moveToNext()) { linksMap.put( - linksCursor.getString(0), + UrlInfo.Type.fromFixedName(linksCursor.getString(0)), new UrlInfoWithDate( linksCursor.getString(1), SQLiteUtil.getDate(linksCursor, 2) @@ -134,7 +135,7 @@ class SQLiteNetworkDatabase extends NetworkDatabase { SQLiteUtil.bindString(statement, 3, link.getSummary()); final long id; - final HashMap linksMap = new HashMap(); + final HashMap linksMap = new HashMap(); if (statement == myInsertCustomLinkStatement) { id = statement.executeInsert(); @@ -147,7 +148,7 @@ class SQLiteNetworkDatabase extends NetworkDatabase { final Cursor linksCursor = myDatabase.rawQuery("SELECT key,url,update_time FROM LinkUrls WHERE link_id = " + link.getId(), null); while (linksCursor.moveToNext()) { linksMap.put( - linksCursor.getString(0), + UrlInfo.Type.fromFixedName(linksCursor.getString(0)), new UrlInfoWithDate( linksCursor.getString(1), SQLiteUtil.getDate(linksCursor, 2) @@ -157,7 +158,7 @@ class SQLiteNetworkDatabase extends NetworkDatabase { linksCursor.close(); } - for (String key : link.getUrlKeys()) { + for (UrlInfo.Type key : link.getUrlKeys()) { final UrlInfoWithDate info = link.getUrlInfo(key); final UrlInfoWithDate dbInfo = linksMap.remove(key); final SQLiteStatement urlStatement; @@ -179,16 +180,16 @@ class SQLiteNetworkDatabase extends NetworkDatabase { SQLiteUtil.bindString(urlStatement, 1, info.URL); SQLiteUtil.bindDate(urlStatement, 2, info.Updated); urlStatement.bindLong(3, id); - urlStatement.bindString(4, key); + urlStatement.bindString(4, key.getFixedName()); urlStatement.execute(); } - for (String key: linksMap.keySet()) { + for (UrlInfo.Type key: linksMap.keySet()) { if (myDeleteCustomLinkUrlStatement == null) { myDeleteCustomLinkUrlStatement = myDatabase.compileStatement( "DELETE FROM LinkUrls WHERE link_id = ? AND key = ?"); } myDeleteCustomLinkUrlStatement.bindLong(1, id); - myDeleteCustomLinkUrlStatement.bindString(2, key); + myDeleteCustomLinkUrlStatement.bindString(2, key.getFixedName()); myDeleteCustomLinkUrlStatement.execute(); } } diff --git a/src/org/geometerplus/android/fbreader/network/Util.java b/src/org/geometerplus/android/fbreader/network/Util.java index 405190475..ad6dd3fbf 100644 --- a/src/org/geometerplus/android/fbreader/network/Util.java +++ b/src/org/geometerplus/android/fbreader/network/Util.java @@ -32,6 +32,7 @@ import org.geometerplus.zlibrary.core.network.ZLNetworkException; import org.geometerplus.fbreader.network.*; import org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager; import org.geometerplus.fbreader.network.tree.NetworkBookTree; +import org.geometerplus.fbreader.network.urlInfo.UrlInfo; import org.geometerplus.android.util.PackageUtil; @@ -53,7 +54,7 @@ abstract class Util implements UserRegistrationConstants { return testService( activity, REGISTRATION_ACTION, - link.getUrlInfo(INetworkLink.URL_SIGN_UP).URL + link.getUrlInfo(UrlInfo.Type.SignUp).URL ); } @@ -61,12 +62,12 @@ abstract class Util implements UserRegistrationConstants { try { final Intent intent = new Intent( REGISTRATION_ACTION, - Uri.parse(link.getUrlInfo(INetworkLink.URL_SIGN_UP).URL) + Uri.parse(link.getUrlInfo(UrlInfo.Type.SignUp).URL) ); if (PackageUtil.canBeStarted(activity, intent, true)) { activity.startActivityForResult(new Intent( REGISTRATION_ACTION, - Uri.parse(link.getUrlInfo(INetworkLink.URL_SIGN_UP).URL) + Uri.parse(link.getUrlInfo(UrlInfo.Type.SignUp).URL) ), USER_REGISTRATION_REQUEST_CODE); } } catch (ActivityNotFoundException e) { @@ -99,7 +100,7 @@ abstract class Util implements UserRegistrationConstants { return testService( activity, action, - link.getUrlInfo(INetworkLink.URL_MAIN).URL + link.getUrlInfo(UrlInfo.Type.Catalog).URL ); } @@ -107,7 +108,7 @@ abstract class Util implements UserRegistrationConstants { try { final Intent intent = new Intent( action, - Uri.parse(link.getUrlInfo(INetworkLink.URL_MAIN).URL) + Uri.parse(link.getUrlInfo(UrlInfo.Type.Catalog).URL) ); final NetworkAuthenticationManager mgr = link.authenticationManager(); if (mgr != null) { @@ -123,7 +124,7 @@ abstract class Util implements UserRegistrationConstants { } static boolean isBrowserTopupSupported(Activity activity, INetworkLink link) { - return link.getUrlInfo(INetworkLink.URL_TOPUP).URL != null; + return link.getUrlInfo(UrlInfo.Type.TopUp).URL != null; } static void openInBrowser(Context context, String url) { diff --git a/src/org/geometerplus/fbreader/network/AbstractNetworkLink.java b/src/org/geometerplus/fbreader/network/AbstractNetworkLink.java index 33fc99bd7..3cbf51a42 100644 --- a/src/org/geometerplus/fbreader/network/AbstractNetworkLink.java +++ b/src/org/geometerplus/fbreader/network/AbstractNetworkLink.java @@ -24,6 +24,7 @@ import java.util.*; import org.geometerplus.zlibrary.core.util.ZLMiscUtil; import org.geometerplus.zlibrary.core.options.ZLStringListOption; +import org.geometerplus.fbreader.network.urlInfo.UrlInfo; import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate; public abstract class AbstractNetworkLink implements INetworkLink, Basket { @@ -31,7 +32,7 @@ public abstract class AbstractNetworkLink implements INetworkLink, Basket { protected String myTitle; protected String mySummary; protected final String myLanguage; - protected final TreeMap myInfos; + protected final TreeMap myInfos; private ZLStringListOption myBooksInBasketOption; @@ -42,14 +43,14 @@ public abstract class AbstractNetworkLink implements INetworkLink, Basket { * @param title title of the corresponding library item. Must be not null. * @param summary description of the corresponding library item. Can be null. * @param language language of the catalog. If null we assume this catalog is multilanguage. - * @param infos map contains URL infos with their identifiers; must always contain one URL with URL_MAIN identifier + * @param infos collection of URL infos; must always contain one URL with UrlInfo.Type.Catalog identifier */ - public AbstractNetworkLink(String siteName, String title, String summary, String language, Map infos) { + public AbstractNetworkLink(String siteName, String title, String summary, String language, Map infos) { mySiteName = siteName; myTitle = title; mySummary = summary; myLanguage = language != null ? language : "multi"; - myInfos = new TreeMap(infos); + myInfos = new TreeMap(infos); } public final String getSiteName() { @@ -68,16 +69,16 @@ public abstract class AbstractNetworkLink implements INetworkLink, Basket { return myLanguage; } - public final HashMap urlInfoMap() { - return new HashMap(myInfos); + public final HashMap urlInfoMap() { + return new HashMap(myInfos); } - public final UrlInfoWithDate getUrlInfo(String urlKey) { - final UrlInfoWithDate info = myInfos.get(urlKey); + public final UrlInfoWithDate getUrlInfo(UrlInfo.Type type) { + final UrlInfoWithDate info = myInfos.get(type); return info != null ? info : UrlInfoWithDate.NULL; } - public final Set getUrlKeys() { + public final Set getUrlKeys() { return myInfos.keySet(); } @@ -136,7 +137,7 @@ public abstract class AbstractNetworkLink implements INetworkLink, Basket { @Override public String toString() { - String icon = getUrlInfo(URL_ICON).URL; + String icon = getUrlInfo(UrlInfo.Type.Catalog).URL; if (icon != null) { if (icon.length() > 64) { icon = icon.substring(0, 61) + "..."; diff --git a/src/org/geometerplus/fbreader/network/ICustomNetworkLink.java b/src/org/geometerplus/fbreader/network/ICustomNetworkLink.java index 2eec9873d..a563d098f 100644 --- a/src/org/geometerplus/fbreader/network/ICustomNetworkLink.java +++ b/src/org/geometerplus/fbreader/network/ICustomNetworkLink.java @@ -23,6 +23,7 @@ import java.util.HashMap; import org.geometerplus.zlibrary.core.network.ZLNetworkException; +import org.geometerplus.fbreader.network.urlInfo.UrlInfo; import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate; public interface ICustomNetworkLink extends INetworkLink { @@ -35,9 +36,9 @@ public interface ICustomNetworkLink extends INetworkLink { void setTitle(String title); void setSummary(String summary); - HashMap urlInfoMap(); - void setUrl(String urlKey, String url); - void removeUrl(String urlKey); + HashMap urlInfoMap(); + void setUrl(UrlInfo.Type type, String url); + void removeUrl(UrlInfo.Type type); boolean isObsolete(long milliSeconds); void reloadInfo(boolean urlsOnly) throws ZLNetworkException; diff --git a/src/org/geometerplus/fbreader/network/INetworkLink.java b/src/org/geometerplus/fbreader/network/INetworkLink.java index 965548710..d0cf5b721 100644 --- a/src/org/geometerplus/fbreader/network/INetworkLink.java +++ b/src/org/geometerplus/fbreader/network/INetworkLink.java @@ -24,24 +24,16 @@ import java.util.*; import org.geometerplus.zlibrary.core.network.ZLNetworkRequest; import org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager; +import org.geometerplus.fbreader.network.urlInfo.UrlInfo; import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate; public interface INetworkLink { - String URL_MAIN = "main"; - String URL_SEARCH = "search"; - String URL_ICON = "icon"; - String URL_SIGN_IN = "signIn"; - String URL_SIGN_OUT = "signOut"; - String URL_SIGN_UP = "signUp"; - String URL_TOPUP = "topup"; - String URL_RECOVER_PASSWORD = "recoverPassword"; - String getSiteName(); String getTitle(); String getSummary(); - UrlInfoWithDate getUrlInfo(String urlKey); - Set getUrlKeys(); + UrlInfoWithDate getUrlInfo(UrlInfo.Type type); + Set getUrlKeys(); /** * @return 2-letters language code or special token "multi" diff --git a/src/org/geometerplus/fbreader/network/NetworkDatabase.java b/src/org/geometerplus/fbreader/network/NetworkDatabase.java index aa3a075ae..72f23860c 100644 --- a/src/org/geometerplus/fbreader/network/NetworkDatabase.java +++ b/src/org/geometerplus/fbreader/network/NetworkDatabase.java @@ -21,6 +21,7 @@ package org.geometerplus.fbreader.network; import java.util.Map; +import org.geometerplus.fbreader.network.urlInfo.UrlInfo; import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate; public abstract class NetworkDatabase { @@ -37,7 +38,7 @@ public abstract class NetworkDatabase { protected abstract void executeAsATransaction(Runnable actions); public interface ICustomLinksHandler { - void handleCustomLinkData(int id, String siteName, String title, String summary, Map infos); + void handleCustomLinkData(int id, String siteName, String title, String summary, Map infos); } protected abstract void loadCustomLinks(ICustomLinksHandler handler); diff --git a/src/org/geometerplus/fbreader/network/NetworkLibrary.java b/src/org/geometerplus/fbreader/network/NetworkLibrary.java index ecc78ac85..3d29f111f 100644 --- a/src/org/geometerplus/fbreader/network/NetworkLibrary.java +++ b/src/org/geometerplus/fbreader/network/NetworkLibrary.java @@ -33,6 +33,7 @@ import org.geometerplus.fbreader.tree.FBTree; import org.geometerplus.fbreader.network.tree.*; import org.geometerplus.fbreader.network.opds.OPDSCustomLink; import org.geometerplus.fbreader.network.opds.OPDSLinkReader; +import org.geometerplus.fbreader.network.urlInfo.UrlInfo; import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate; public class NetworkLibrary { @@ -180,10 +181,10 @@ public class NetworkLibrary { db.loadCustomLinks( new NetworkDatabase.ICustomLinksHandler() { public void handleCustomLinkData(int id, String siteName, - String title, String summary, Map infos) { + String title, String summary, Map infos) { if (title != null && siteName != null && - infos.get(INetworkLink.URL_MAIN) != null) { + infos.get(UrlInfo.Type.Catalog) != null) { final ICustomNetworkLink link = new OPDSCustomLink( id, siteName, title, summary, infos ); diff --git a/src/org/geometerplus/fbreader/network/authentication/litres/LitResAuthenticationManager.java b/src/org/geometerplus/fbreader/network/authentication/litres/LitResAuthenticationManager.java index f82b9d4a0..151847d97 100644 --- a/src/org/geometerplus/fbreader/network/authentication/litres/LitResAuthenticationManager.java +++ b/src/org/geometerplus/fbreader/network/authentication/litres/LitResAuthenticationManager.java @@ -90,7 +90,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager { sid = mySidOption.getValue(); } - String url = Link.getUrlInfo(INetworkLink.URL_SIGN_IN).URL; + String url = Link.getUrlInfo(UrlInfo.Type.SignIn).URL; if (url == null) { throw new ZLNetworkException(NetworkException.ERROR_UNSUPPORTED_OPERATION); } @@ -120,7 +120,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager { @Override public void authorise(String password) throws ZLNetworkException { - String url = Link.getUrlInfo(INetworkLink.URL_SIGN_IN).URL; + String url = Link.getUrlInfo(UrlInfo.Type.SignIn).URL; if (url == null) { throw new ZLNetworkException(NetworkException.ERROR_UNSUPPORTED_OPERATION); } @@ -240,7 +240,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager { if (sid.length() == 0) { return null; } - final String url = Link.getUrlInfo(INetworkLink.URL_TOPUP).URL; + final String url = Link.getUrlInfo(UrlInfo.Type.TopUp).URL; if (url == null) { return null; } @@ -400,7 +400,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager { @Override public void recoverPassword(String email) throws ZLNetworkException { - String url = Link.getUrlInfo(INetworkLink.URL_RECOVER_PASSWORD).URL; + String url = Link.getUrlInfo(UrlInfo.Type.RecoverPassword).URL; if (url == null) { throw new ZLNetworkException(NetworkException.ERROR_UNSUPPORTED_OPERATION); } diff --git a/src/org/geometerplus/fbreader/network/opds/OPDSCustomLink.java b/src/org/geometerplus/fbreader/network/opds/OPDSCustomLink.java index c711ec72e..711092507 100644 --- a/src/org/geometerplus/fbreader/network/opds/OPDSCustomLink.java +++ b/src/org/geometerplus/fbreader/network/opds/OPDSCustomLink.java @@ -31,6 +31,7 @@ import org.geometerplus.zlibrary.core.util.ZLMiscUtil; import org.geometerplus.fbreader.network.ICustomNetworkLink; import org.geometerplus.fbreader.network.NetworkException; +import org.geometerplus.fbreader.network.urlInfo.UrlInfo; import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate; public class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLink { @@ -45,7 +46,7 @@ public class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLin return siteName; } - public OPDSCustomLink(int id, String siteName, String title, String summary, Map infos) { + public OPDSCustomLink(int id, String siteName, String title, String summary, Map infos) { super(removeWWWPrefix(siteName), title, summary, null, infos, false); myId = id; } @@ -81,26 +82,26 @@ public class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLin myTitle = title; } - public final void setUrl(String urlKey, String url) { - myInfos.put(urlKey, new UrlInfoWithDate(url, new Date())); + public final void setUrl(UrlInfo.Type type, String url) { + myInfos.put(type, new UrlInfoWithDate(url, new Date())); myHasChanges = true; } - public final void removeUrl(String urlKey) { - final UrlInfoWithDate oldUrl = myInfos.remove(urlKey); + public final void removeUrl(UrlInfo.Type type) { + final UrlInfoWithDate oldUrl = myInfos.remove(type); myHasChanges = myHasChanges || oldUrl != null; } public boolean isObsolete(long milliSeconds) { final long old = System.currentTimeMillis() - milliSeconds; - final Date searchUpdateDate = getUrlInfo(URL_SEARCH).Updated; - if (searchUpdateDate == null || searchUpdateDate.getTime() < old) { + Date updateDate = getUrlInfo(UrlInfo.Type.Search).Updated; + if (updateDate == null || updateDate.getTime() < old) { return true; } - final Date iconUpdateDate = getUrlInfo(URL_ICON).Updated; - if (iconUpdateDate == null || iconUpdateDate.getTime() < old) { + updateDate = getUrlInfo(UrlInfo.Type.Image).Updated; + if (updateDate == null || updateDate.getTime() < old) { return true; } @@ -113,7 +114,7 @@ public class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLin ZLNetworkException error = null; try { - ZLNetworkManager.Instance().perform(new ZLNetworkRequest(getUrlInfo(URL_MAIN).URL) { + ZLNetworkManager.Instance().perform(new ZLNetworkRequest(getUrlInfo(UrlInfo.Type.Catalog).URL) { @Override public void handleStream(URLConnection connection, InputStream inputStream) throws IOException, ZLNetworkException { final CatalogInfoReader info = new CatalogInfoReader(URL, OPDSCustomLink.this, opensearchDescriptionURLs); @@ -125,7 +126,7 @@ public class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLin if (info.Title == null) { throw new ZLNetworkException(NetworkException.ERROR_NO_REQUIRED_INFORMATION); } - setUrl(URL_ICON, info.Icon); + setUrl(UrlInfo.Type.Image, info.Icon); if (info.DirectOpenSearchDescription != null) { descriptions.add(info.DirectOpenSearchDescription); } @@ -161,9 +162,9 @@ public class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLin if (!descriptions.isEmpty()) { // TODO: May be do not use '%s'??? Use Description instead??? (this needs to rewrite SEARCH engine logic a little) - setUrl(URL_SEARCH, descriptions.get(0).makeQuery("%s")); + setUrl(UrlInfo.Type.Search, descriptions.get(0).makeQuery("%s")); } else { - setUrl(URL_SEARCH, null); + setUrl(UrlInfo.Type.Search, null); } if (error != null) { throw error; diff --git a/src/org/geometerplus/fbreader/network/opds/OPDSLinkXMLReader.java b/src/org/geometerplus/fbreader/network/opds/OPDSLinkXMLReader.java index 4d787e44a..ebf6c1902 100644 --- a/src/org/geometerplus/fbreader/network/opds/OPDSLinkXMLReader.java +++ b/src/org/geometerplus/fbreader/network/opds/OPDSLinkXMLReader.java @@ -32,6 +32,7 @@ import org.geometerplus.fbreader.network.atom.ATOMLink; import org.geometerplus.fbreader.network.atom.ATOMUpdated; import org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager; import org.geometerplus.fbreader.network.authentication.litres.LitResAuthenticationManager; +import org.geometerplus.fbreader.network.urlInfo.UrlInfo; import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate; class OPDSLinkXMLReader extends OPDSXMLReader implements OPDSConstants, MimeTypes { @@ -97,7 +98,7 @@ class OPDSLinkXMLReader extends OPDSXMLReader implements OPDSConstants, MimeType final String summary = entry.Content; final String language = entry.DCLanguage; - final HashMap infos = new HashMap(); + final HashMap infos = new HashMap(); final HashMap urlConditions = new HashMap(); for (ATOMLink link: entry.Links) { @@ -106,35 +107,34 @@ class OPDSLinkXMLReader extends OPDSXMLReader implements OPDSConstants, MimeType final String rel = link.getRel(); if (rel == REL_IMAGE_THUMBNAIL || rel == REL_THUMBNAIL) { if (type == MIME_IMAGE_PNG || type == MIME_IMAGE_JPEG) { - infos.put(INetworkLink.URL_ICON, new UrlInfoWithDate(href)); + infos.put(UrlInfo.Type.Thumbnail, new UrlInfoWithDate(href)); } } else if ((rel != null && rel.startsWith(REL_IMAGE_PREFIX)) || rel == REL_COVER) { - if (infos.get(INetworkLink.URL_ICON) == null && - (type == MIME_IMAGE_PNG || type == MIME_IMAGE_JPEG)) { - infos.put(INetworkLink.URL_ICON, new UrlInfoWithDate(href)); + if (type == MIME_IMAGE_PNG || type == MIME_IMAGE_JPEG) { + infos.put(UrlInfo.Type.Image, new UrlInfoWithDate(href)); } } else if (rel == null) { if (type == MIME_APP_ATOM) { - infos.put(INetworkLink.URL_MAIN, new UrlInfoWithDate(href)); + infos.put(UrlInfo.Type.Catalog, new UrlInfoWithDate(href)); } } else if (rel == "search") { if (type == MIME_APP_ATOM) { final OpenSearchDescription descr = OpenSearchDescription.createDefault(href); if (descr.isValid()) { // TODO: May be do not use '%s'??? Use Description instead??? (this needs to rewrite SEARCH engine logic a little) - infos.put(INetworkLink.URL_SEARCH, new UrlInfoWithDate(descr.makeQuery("%s"))); + infos.put(UrlInfo.Type.Search, new UrlInfoWithDate(descr.makeQuery("%s"))); } } } else if (rel == REL_LINK_SIGN_IN) { - infos.put(INetworkLink.URL_SIGN_IN, new UrlInfoWithDate(href)); + infos.put(UrlInfo.Type.SignIn, new UrlInfoWithDate(href)); } else if (rel == REL_LINK_SIGN_OUT) { - infos.put(INetworkLink.URL_SIGN_OUT, new UrlInfoWithDate(href)); + infos.put(UrlInfo.Type.SignOut, new UrlInfoWithDate(href)); } else if (rel == REL_LINK_SIGN_UP) { - infos.put(INetworkLink.URL_SIGN_UP, new UrlInfoWithDate(href)); + infos.put(UrlInfo.Type.SignUp, new UrlInfoWithDate(href)); } else if (rel == REL_LINK_TOPUP) { - infos.put(INetworkLink.URL_TOPUP, new UrlInfoWithDate(href)); + infos.put(UrlInfo.Type.TopUp, new UrlInfoWithDate(href)); } else if (rel == REL_LINK_RECOVER_PASSWORD) { - infos.put(INetworkLink.URL_RECOVER_PASSWORD, new UrlInfoWithDate(href)); + infos.put(UrlInfo.Type.RecoverPassword, new UrlInfoWithDate(href)); } else if (rel == REL_CONDITION_NEVER) { urlConditions.put(href, NetworkCatalogItem.Accessibility.NEVER); } else if (rel == REL_CONDITION_SIGNED_IN) { @@ -164,11 +164,11 @@ class OPDSLinkXMLReader extends OPDSXMLReader implements OPDSConstants, MimeType String title, String summary, String language, - Map infos, + Map infos, HashMap urlConditions, String sslCertificate ) { - if (siteName == null || title == null || infos.get(INetworkLink.URL_MAIN) == null) { + if (siteName == null || title == null || infos.get(UrlInfo.Type.Catalog) == null) { return null; } diff --git a/src/org/geometerplus/fbreader/network/opds/OPDSNetworkLink.java b/src/org/geometerplus/fbreader/network/opds/OPDSNetworkLink.java index e7e2521ad..41e05ffce 100644 --- a/src/org/geometerplus/fbreader/network/opds/OPDSNetworkLink.java +++ b/src/org/geometerplus/fbreader/network/opds/OPDSNetworkLink.java @@ -45,7 +45,7 @@ public class OPDSNetworkLink extends AbstractNetworkLink { private final boolean myHasStableIdentifiers; OPDSNetworkLink(String siteName, String title, String summary, String language, - Map infos, boolean hasStableIdentifiers) { + Map infos, boolean hasStableIdentifiers) { super(siteName, title, summary, language, infos); myHasStableIdentifiers = hasStableIdentifiers; } @@ -118,7 +118,7 @@ public class OPDSNetworkLink extends AbstractNetworkLink { } public ZLNetworkRequest simpleSearchRequest(String pattern, NetworkOperationData data) { - final String url = getUrlInfo(URL_SEARCH).URL; + final String url = getUrlInfo(UrlInfo.Type.Search).URL; if (url == null) { return null; } @@ -135,8 +135,8 @@ public class OPDSNetworkLink extends AbstractNetworkLink { public NetworkCatalogItem libraryItem() { final UrlInfoCollection urlMap = new UrlInfoCollection(); - urlMap.addInfo(new UrlInfo(UrlInfo.Type.Catalog, getUrlInfo(URL_MAIN).URL)); - urlMap.addInfo(new UrlInfo(UrlInfo.Type.Image, getUrlInfo(URL_ICON).URL)); + urlMap.addInfo(new UrlInfo(UrlInfo.Type.Catalog, getUrlInfo(UrlInfo.Type.Catalog).URL)); + urlMap.addInfo(new UrlInfo(UrlInfo.Type.Image, getUrlInfo(UrlInfo.Type.Image).URL)); return new OPDSCatalogItem(this, getTitle(), getSummary(), urlMap, myExtraData); } diff --git a/src/org/geometerplus/fbreader/network/urlInfo/UrlInfo.java b/src/org/geometerplus/fbreader/network/urlInfo/UrlInfo.java index a252873e8..bc7275778 100644 --- a/src/org/geometerplus/fbreader/network/urlInfo/UrlInfo.java +++ b/src/org/geometerplus/fbreader/network/urlInfo/UrlInfo.java @@ -25,16 +25,45 @@ public class UrlInfo implements Serializable { private static final long serialVersionUID = -893514485257788222L; public static enum Type { - Catalog, + Catalog("main"), HtmlPage, - Image, + Image("icon"), Thumbnail, + Search("search"), + SignIn, + SignOut, + SignUp, + TopUp, + RecoverPassword, Book, BookConditional, BookDemo, BookFullOrDemo, BookBuy, - BookBuyInBrowser + BookBuyInBrowser; + + public static Type fromFixedName(String fixedName) { + for (Type t : values()) { + if (t.getFixedName().equals(fixedName)) { + return t; + } + } + return null; + } + + private final String myFixedName; + + Type(String fixedName) { + myFixedName = fixedName; + } + + Type() { + myFixedName = null; + } + + public String getFixedName() { + return myFixedName != null ? myFixedName : toString(); + } } public final Type InfoType; diff --git a/src/org/geometerplus/fbreader/network/urlInfo/UrlInfoCollection.java b/src/org/geometerplus/fbreader/network/urlInfo/UrlInfoCollection.java index 16e8d682b..79e110841 100644 --- a/src/org/geometerplus/fbreader/network/urlInfo/UrlInfoCollection.java +++ b/src/org/geometerplus/fbreader/network/urlInfo/UrlInfoCollection.java @@ -20,8 +20,11 @@ package org.geometerplus.fbreader.network.urlInfo; import java.util.*; +import java.io.Serializable; + +public class UrlInfoCollection implements Serializable { + private static final long serialVersionUID = -834589080548958222L; -public class UrlInfoCollection { private final LinkedList myInfos = new LinkedList(); public UrlInfoCollection() {