1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 02:09:35 +02:00

URLInfo -> UrlInfo

This commit is contained in:
Nikolay Pultsin 2011-03-04 16:04:58 +00:00
parent 401b38d746
commit 16fd2dd17e
11 changed files with 103 additions and 36 deletions

View file

@ -30,7 +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;
import org.geometerplus.fbreader.network.UrlInfo;
import org.geometerplus.android.util.SQLiteUtil;
@ -75,7 +75,7 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
@Override
protected void loadCustomLinks(ICustomLinksHandler handler) {
final Cursor cursor = myDatabase.rawQuery("SELECT link_id,title,site_name,summary,icon FROM CustomLinks", null);
final HashMap<String,URLInfo> linksMap = new HashMap<String,URLInfo>();
final HashMap<String,UrlInfo> linksMap = new HashMap<String,UrlInfo>();
while (cursor.moveToNext()) {
final int id = cursor.getInt(0);
final String title = cursor.getString(1);
@ -88,7 +88,7 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
while (linksCursor.moveToNext()) {
linksMap.put(
linksCursor.getString(0),
new URLInfo(
new UrlInfo(
linksCursor.getString(1),
SQLiteUtil.getDate(linksCursor, 2)
)
@ -134,7 +134,7 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
SQLiteUtil.bindString(statement, 4, link.getIcon());
final long id;
final HashMap<String,URLInfo> linksMap = new HashMap<String,URLInfo>();
final HashMap<String,UrlInfo> linksMap = new HashMap<String,UrlInfo>();
if (statement == myInsertCustomLinkStatement) {
id = statement.executeInsert();
@ -148,7 +148,7 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
while (linksCursor.moveToNext()) {
linksMap.put(
linksCursor.getString(0),
new URLInfo(
new UrlInfo(
linksCursor.getString(1),
SQLiteUtil.getDate(linksCursor, 2)
)
@ -158,8 +158,8 @@ class SQLiteNetworkDatabase extends NetworkDatabase {
}
for (String key : link.getUrlKeys()) {
final URLInfo info = link.getUrlInfo(key);
final URLInfo dbInfo = linksMap.remove(key);
final UrlInfo info = link.getUrlInfo(key);
final UrlInfo dbInfo = linksMap.remove(key);
final SQLiteStatement urlStatement;
if (dbInfo == null) {
if (myInsertCustomLinkUrlStatement == null) {

View file

@ -29,7 +29,7 @@ public abstract class AbstractNetworkLink implements INetworkLink {
protected String mySummary;
protected String myIcon;
protected final String myLanguage;
protected final TreeMap<String,URLInfo> myInfos;
protected final TreeMap<String,UrlInfo> myInfos;
/**
* Creates new NetworkLink instance.
@ -41,13 +41,13 @@ public abstract class AbstractNetworkLink implements INetworkLink {
* @param language language of the catalog. If <code>null</code> we assume this catalog is multilanguage.
* @param infos map contains URL infos with their identifiers; must always contain one URL with <code>URL_MAIN</code> identifier
*/
public AbstractNetworkLink(String siteName, String title, String summary, String icon, String language, Map<String,URLInfo> infos) {
public AbstractNetworkLink(String siteName, String title, String summary, String icon, String language, Map<String,UrlInfo> infos) {
mySiteName = siteName;
myTitle = title;
mySummary = summary;
myIcon = icon;
myLanguage = language != null ? language : "multi";
myInfos = new TreeMap<String,URLInfo>(infos);
myInfos = new TreeMap<String,UrlInfo>(infos);
}
public final String getSiteName() {
@ -70,9 +70,13 @@ public abstract class AbstractNetworkLink implements INetworkLink {
return myLanguage;
}
public final URLInfo getUrlInfo(String urlKey) {
final URLInfo info = myInfos.get(urlKey);
return info != null ? info : URLInfo.NULL;
public final HashMap<String,UrlInfo> urlInfoMap() {
return new HashMap(myInfos);
}
public final UrlInfo getUrlInfo(String urlKey) {
final UrlInfo info = myInfos.get(urlKey);
return info != null ? info : UrlInfo.NULL;
}
public final Set<String> getUrlKeys() {

View file

@ -19,8 +19,7 @@
package org.geometerplus.fbreader.network;
import java.util.List;
import java.util.Set;
import java.util.*;
import org.geometerplus.zlibrary.core.network.ZLNetworkRequest;
@ -41,7 +40,8 @@ public interface INetworkLink {
String getSummary();
String getIcon();
URLInfo getUrlInfo(String urlKey);
HashMap<String,UrlInfo> urlInfoMap();
UrlInfo getUrlInfo(String urlKey);
Set<String> getUrlKeys();
/**

View file

@ -35,7 +35,7 @@ public abstract class NetworkDatabase {
protected abstract void executeAsATransaction(Runnable actions);
public interface ICustomLinksHandler {
void handleCustomLinkData(int id, String siteName, String title, String summary, String icon, Map<String,URLInfo> infos);
void handleCustomLinkData(int id, String siteName, String title, String summary, String icon, Map<String,UrlInfo> infos);
}
protected abstract void loadCustomLinks(ICustomLinksHandler handler);

View file

@ -179,7 +179,7 @@ public class NetworkLibrary {
db.loadCustomLinks(
new NetworkDatabase.ICustomLinksHandler() {
public void handleCustomLinkData(int id, String siteName,
String title, String summary, String icon, Map<String,URLInfo> infos) {
String title, String summary, String icon, Map<String,UrlInfo> infos) {
final ICustomNetworkLink link = OPDSLinkReader.createCustomLink(id, siteName, title, summary, icon, infos);
if (link != null) {
addLinkInternal(link);

View file

@ -0,0 +1,59 @@
/*
* Copyright (C) 2010-2011 Geometer Plus <contact@geometerplus.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
package org.geometerplus.fbreader.network;
import java.util.Date;
import java.io.Serializable;
import org.geometerplus.zlibrary.core.util.ZLMiscUtil;
public final class UrlInfo implements Serializable {
public static final UrlInfo NULL = new UrlInfo(null, null);
public final String URL;
public final Date Updated;
public UrlInfo(String url, Date updated) {
URL = url;
Updated = updated;
}
public UrlInfo(String url) {
this(url, new Date());
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (!(o instanceof UrlInfo)) {
return false;
}
final UrlInfo info = (UrlInfo)o;
return ZLMiscUtil.equals(URL, info.URL) && ZLMiscUtil.equals(Updated, info.Updated);
}
@Override
public int hashCode() {
return ZLMiscUtil.hashCode(URL) + ZLMiscUtil.hashCode(Updated);
}
}

View file

@ -32,14 +32,14 @@ import org.geometerplus.zlibrary.core.util.ZLMiscUtil;
import org.geometerplus.fbreader.network.ICustomNetworkLink;
import org.geometerplus.fbreader.network.INetworkLink;
import org.geometerplus.fbreader.network.NetworkException;
import org.geometerplus.fbreader.network.URLInfo;
import org.geometerplus.fbreader.network.UrlInfo;
class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLink {
private int myId;
private boolean myHasChanges;
OPDSCustomLink(int id, String siteName, String title, String summary, String icon, Map<String,URLInfo> infos) {
OPDSCustomLink(int id, String siteName, String title, String summary, String icon, Map<String,UrlInfo> infos) {
super(siteName, title, summary, icon, null, infos, false);
myId = id;
}
@ -81,12 +81,12 @@ class OPDSCustomLink extends OPDSNetworkLink implements ICustomNetworkLink {
}
public final void setUrl(String urlKey, String url) {
myInfos.put(urlKey, new URLInfo(url, new Date()));
myInfos.put(urlKey, new UrlInfo(url, new Date()));
myHasChanges = true;
}
public final void removeUrl(String urlKey) {
final URLInfo oldUrl = myInfos.remove(urlKey);
final UrlInfo oldUrl = myInfos.remove(urlKey);
myHasChanges = myHasChanges || oldUrl != null;
}

View file

@ -39,7 +39,7 @@ import org.geometerplus.fbreader.network.atom.ATOMUpdated;
public class OPDSLinkReader {
static final String CATALOGS_URL = "http://data.fbreader.org/catalogs/generic-1.2.xml";
public static ICustomNetworkLink createCustomLink(int id, String siteName, String title, String summary, String icon, Map<String,URLInfo> infos) {
public static ICustomNetworkLink createCustomLink(int id, String siteName, String title, String summary, String icon, Map<String,UrlInfo> infos) {
if (siteName == null || title == null || infos.get(INetworkLink.URL_MAIN) == null) {
return null;
}
@ -47,8 +47,8 @@ public class OPDSLinkReader {
}
public static ICustomNetworkLink createCustomLink(int id, String siteName, String title, String summary, String icon, String url) {
final HashMap<String,URLInfo> infos = new HashMap<String,URLInfo>();
infos.put(INetworkLink.URL_MAIN, new URLInfo(url));
final HashMap<String,UrlInfo> infos = new HashMap<String,UrlInfo>();
infos.put(INetworkLink.URL_MAIN, new UrlInfo(url));
return new OPDSCustomLink(id, siteName, title, summary, icon, infos);
}

View file

@ -30,7 +30,7 @@ import org.geometerplus.zlibrary.core.xml.ZLStringMap;
import org.geometerplus.fbreader.network.INetworkLink;
import org.geometerplus.fbreader.network.NetworkLibrary;
import org.geometerplus.fbreader.network.NetworkCatalogItem;
import org.geometerplus.fbreader.network.URLInfo;
import org.geometerplus.fbreader.network.UrlInfo;
import org.geometerplus.fbreader.network.atom.ATOMLink;
import org.geometerplus.fbreader.network.atom.ATOMUpdated;
import org.geometerplus.fbreader.network.authentication.NetworkAuthenticationManager;
@ -100,7 +100,7 @@ class OPDSLinkXMLReader extends OPDSXMLReader implements OPDSConstants, MimeType
final String language = entry.DCLanguage;
String icon = null;
final HashMap<String,URLInfo> infos = new HashMap<String,URLInfo>();
final HashMap<String,UrlInfo> infos = new HashMap<String,UrlInfo>();
final HashMap<String,NetworkCatalogItem.Accessibility> urlConditions =
new HashMap<String,NetworkCatalogItem.Accessibility>();
for (ATOMLink link: entry.Links) {
@ -117,26 +117,26 @@ class OPDSLinkXMLReader extends OPDSXMLReader implements OPDSConstants, MimeType
}
} else if (rel == null) {
if (type == MIME_APP_ATOM) {
infos.put(INetworkLink.URL_MAIN, new URLInfo(href));
infos.put(INetworkLink.URL_MAIN, new UrlInfo(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 URLInfo(descr.makeQuery("%s")));
infos.put(INetworkLink.URL_SEARCH, new UrlInfo(descr.makeQuery("%s")));
}
}
} else if (rel == REL_LINK_SIGN_IN) {
infos.put(INetworkLink.URL_SIGN_IN, new URLInfo(href));
infos.put(INetworkLink.URL_SIGN_IN, new UrlInfo(href));
} else if (rel == REL_LINK_SIGN_OUT) {
infos.put(INetworkLink.URL_SIGN_OUT, new URLInfo(href));
infos.put(INetworkLink.URL_SIGN_OUT, new UrlInfo(href));
} else if (rel == REL_LINK_SIGN_UP) {
infos.put(INetworkLink.URL_SIGN_UP, new URLInfo(href));
infos.put(INetworkLink.URL_SIGN_UP, new UrlInfo(href));
} else if (rel == REL_LINK_REFILL_ACCOUNT) {
infos.put(INetworkLink.URL_REFILL_ACCOUNT, new URLInfo(href));
infos.put(INetworkLink.URL_REFILL_ACCOUNT, new UrlInfo(href));
} else if (rel == REL_LINK_RECOVER_PASSWORD) {
infos.put(INetworkLink.URL_RECOVER_PASSWORD, new URLInfo(href));
infos.put(INetworkLink.URL_RECOVER_PASSWORD, new UrlInfo(href));
} else if (rel == REL_CONDITION_NEVER) {
urlConditions.put(href, NetworkCatalogItem.Accessibility.NEVER);
} else if (rel == REL_CONDITION_SIGNED_IN) {
@ -167,7 +167,7 @@ class OPDSLinkXMLReader extends OPDSXMLReader implements OPDSConstants, MimeType
String summary,
String icon,
String language,
Map<String,URLInfo> infos,
Map<String,UrlInfo> infos,
HashMap<String,NetworkCatalogItem.Accessibility> urlConditions,
String sslCertificate
) {

View file

@ -49,7 +49,7 @@ public class OPDSNetworkLink extends AbstractNetworkLink {
private final boolean myHasStableIdentifiers;
OPDSNetworkLink(String siteName, String title, String summary, String icon, String language,
Map<String,URLInfo> infos, boolean hasStableIdentifiers) {
Map<String,UrlInfo> infos, boolean hasStableIdentifiers) {
super(siteName, title, summary, icon, language, infos);
myHasStableIdentifiers = hasStableIdentifiers;
myBooksInBasketOption = new ZLStringListOption(siteName, "Basket", null);

View file

@ -27,6 +27,10 @@ public abstract class ZLMiscUtil {
return (o0 == null) ? (o1 == null) : o0.equals(o1);
}
public static int hashCode(Object o) {
return o != null ? o.hashCode() : 0;
}
public static <T> boolean listsEquals(List<T> list1, List<T> list2) {
if (list1 == null) {
return list2 == null || list2.isEmpty();