mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
Some logical changes to the fbreader/network core
Conflicts: TODO.SOAP
This commit is contained in:
parent
97b9107ea4
commit
3bf2d0ef8b
9 changed files with 72 additions and 61 deletions
8
TODO.SOAP
Normal file
8
TODO.SOAP
Normal file
|
@ -0,0 +1,8 @@
|
|||
* response parser: add namespaces processing
|
||||
* return full result from response parser
|
||||
* full SOAP types list: support in request and in parser
|
||||
|
||||
|
||||
** коды возврата для работы приложения не требуются: при возникновении ошибок на стороне сервера перехватывать их и отправлять по SOAP в событии fault
|
||||
** какой vendor_id ?????
|
||||
** что такое marketplace_id ?????
|
|
@ -52,37 +52,36 @@ public abstract class AbstractNetworkLink implements INetworkLink {
|
|||
myLinks = new TreeMap<String, String>(links);
|
||||
}
|
||||
|
||||
public String getSiteName() {
|
||||
public final String getSiteName() {
|
||||
return mySiteName;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
public final String getTitle() {
|
||||
return myTitle;
|
||||
}
|
||||
|
||||
public String getSummary() {
|
||||
public final String getSummary() {
|
||||
return mySummary;
|
||||
}
|
||||
|
||||
public String getIcon() {
|
||||
public final String getIcon() {
|
||||
return myIcon;
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
public final String getLanguage() {
|
||||
return myLanguage;
|
||||
}
|
||||
|
||||
public String getLink(String urlKey) {
|
||||
public final String getLink(String urlKey) {
|
||||
return myLinks.get(urlKey);
|
||||
}
|
||||
|
||||
public Set<String> getLinkKeys() {
|
||||
public final Set<String> getLinkKeys() {
|
||||
return myLinks.keySet();
|
||||
}
|
||||
|
||||
public NetworkOperationData createOperationData(INetworkLink link,
|
||||
NetworkOperationData.OnNewItemListener listener) {
|
||||
return new NetworkOperationData(link, listener);
|
||||
public NetworkOperationData createOperationData(NetworkOperationData.OnNewItemListener listener) {
|
||||
return new NetworkOperationData(this, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -41,12 +41,19 @@ public interface INetworkLink {
|
|||
String getSummary();
|
||||
String getIcon();
|
||||
String getLink(String urlKey);
|
||||
|
||||
/**
|
||||
* @return 2-letters language code or special token "multi"
|
||||
*/
|
||||
String getLanguage();
|
||||
|
||||
Set<String> getLinkKeys();
|
||||
|
||||
NetworkOperationData createOperationData(INetworkLink link,
|
||||
NetworkOperationData.OnNewItemListener listener);
|
||||
/**
|
||||
* @param listener Network operation listener
|
||||
* @return instance, which represents the state of the network operation.
|
||||
*/
|
||||
NetworkOperationData createOperationData(NetworkOperationData.OnNewItemListener listener);
|
||||
|
||||
ZLNetworkRequest simpleSearchRequest(String pattern, NetworkOperationData data);
|
||||
ZLNetworkRequest resume(NetworkOperationData data);
|
||||
|
|
|
@ -23,6 +23,8 @@ import java.util.*;
|
|||
|
||||
import org.geometerplus.zlibrary.core.util.ZLBoolean3;
|
||||
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
||||
import org.geometerplus.zlibrary.core.network.ZLNetworkManager;
|
||||
import org.geometerplus.zlibrary.core.network.ZLNetworkRequest;
|
||||
|
||||
public abstract class NetworkCatalogItem extends NetworkLibraryItem {
|
||||
|
||||
|
@ -56,21 +58,6 @@ public abstract class NetworkCatalogItem extends NetworkLibraryItem {
|
|||
this(link, title, summary, cover, urlByType, VISIBLE_ALWAYS, CATALOG_OTHER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new NetworkCatalogItem instance with specified visibility and <code>CATALOG_OTHER</code> type.
|
||||
*
|
||||
* @param link corresponding NetworkLink object. Must be not <code>null</code>.
|
||||
* @param title title of this library item. Must be not <code>null</code>.
|
||||
* @param summary description of this library item. Can be <code>null</code>.
|
||||
* @param cover cover url. Can be <code>null</code>.
|
||||
* @param urlByType map contains URLs and their types. Must be not <code>null</code>.
|
||||
* @param visibility value defines when this library item will be shown in the network library.
|
||||
* Can be one of the VISIBLE_* values.
|
||||
*/
|
||||
public NetworkCatalogItem(INetworkLink link, String title, String summary, String cover, Map<Integer, String> urlByType, int visibility) {
|
||||
this(link, title, summary, cover, urlByType, visibility, CATALOG_OTHER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new NetworkCatalogItem instance with specified visibility and type.
|
||||
*
|
||||
|
@ -113,6 +100,9 @@ public abstract class NetworkCatalogItem extends NetworkLibraryItem {
|
|||
public void onDisplayItem() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return visibility status: on of the values from <code>ZLBoolean3</code> class.
|
||||
*/
|
||||
public int getVisibility() {
|
||||
if (Visibility == VISIBLE_ALWAYS) {
|
||||
return ZLBoolean3.B3_TRUE;
|
||||
|
@ -130,4 +120,24 @@ public abstract class NetworkCatalogItem extends NetworkLibraryItem {
|
|||
}
|
||||
return ZLBoolean3.B3_FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs all necessary operations with NetworkOperationData and NetworkRequest
|
||||
* to complete loading children items.
|
||||
*
|
||||
* @param data Network operation data instance
|
||||
* @param networkRequest initial network request
|
||||
*
|
||||
* @throws ZLNetworkException when network operation couldn't be completed
|
||||
*/
|
||||
protected final void doLoadChildren(NetworkOperationData data,
|
||||
ZLNetworkRequest networkRequest) throws ZLNetworkException {
|
||||
while (networkRequest != null) {
|
||||
ZLNetworkManager.Instance().perform(networkRequest);
|
||||
if (data.Listener.confirmInterrupt()) {
|
||||
return;
|
||||
}
|
||||
networkRequest = data.resume();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -442,7 +442,7 @@ public class NetworkLibrary {
|
|||
|
||||
synchronized (myLinks) {
|
||||
for (INetworkLink link : activeLinks()) {
|
||||
final NetworkOperationData data = link.createOperationData(link, synchronizedListener);
|
||||
final NetworkOperationData data = link.createOperationData(synchronizedListener);
|
||||
final ZLNetworkRequest request = link.simpleSearchRequest(pattern, data);
|
||||
if (request != null) {
|
||||
dataList.add(data);
|
||||
|
|
|
@ -29,8 +29,12 @@ public class NetworkOperationData {
|
|||
|
||||
void commitItems(INetworkLink link);
|
||||
|
||||
// returns true to confirm interrupt reading; return false to continue reading.
|
||||
// once true has been returned, all next calls must return true.
|
||||
/**
|
||||
* @return <code>true</code> to confirm interrupt reading;
|
||||
* <code>false</code> to continue reading.
|
||||
* Once <code>true</code> has been returned,
|
||||
* all next calls MUST return <code>true</code>.
|
||||
*/
|
||||
boolean confirmInterrupt();
|
||||
}
|
||||
|
||||
|
@ -43,11 +47,11 @@ public class NetworkOperationData {
|
|||
Listener = listener;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
protected void clear() {
|
||||
ResumeURI = null;
|
||||
}
|
||||
|
||||
public ZLNetworkRequest resume() {
|
||||
public final ZLNetworkRequest resume() {
|
||||
final ZLNetworkRequest request = Link.resume(this);
|
||||
clear();
|
||||
return request;
|
||||
|
|
|
@ -49,16 +49,8 @@ class SortedCatalogItem extends NetworkCatalogItem {
|
|||
public class LitResBookshelfItem extends NetworkCatalogItem {
|
||||
private boolean myForceReload;
|
||||
|
||||
public LitResBookshelfItem(INetworkLink link, String title, String summary, String cover, Map<Integer, String> urlByType) {
|
||||
super(link, title, summary, cover, urlByType);
|
||||
}
|
||||
|
||||
public LitResBookshelfItem(INetworkLink link, String title, String summary, String cover, Map<Integer, String> urlByType, int visibility) {
|
||||
super(link, title, summary, cover, urlByType, visibility);
|
||||
}
|
||||
|
||||
public LitResBookshelfItem(INetworkLink link, String title, String summary, String cover, Map<Integer, String> urlByType, int visibility, int catalogType) {
|
||||
super(link, title, summary, cover, urlByType, visibility, catalogType);
|
||||
super(link, title, summary, cover, urlByType, visibility, CATALOG_OTHER);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.geometerplus.fbreader.network.opds;
|
|||
|
||||
import java.util.*;
|
||||
|
||||
import org.geometerplus.zlibrary.core.network.ZLNetworkManager;
|
||||
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
||||
import org.geometerplus.zlibrary.core.network.ZLNetworkRequest;
|
||||
|
||||
|
@ -49,19 +48,12 @@ class OPDSCatalogItem extends NetworkCatalogItem {
|
|||
myExtraData = null;
|
||||
}
|
||||
|
||||
private void doLoadChildren(NetworkOperationData.OnNewItemListener listener,
|
||||
ZLNetworkRequest networkRequest) throws ZLNetworkException {
|
||||
while (networkRequest != null) {
|
||||
try {
|
||||
ZLNetworkManager.Instance().perform(networkRequest);
|
||||
} catch (ZLNetworkException e) {
|
||||
myLoadingState = null;
|
||||
throw e;
|
||||
}
|
||||
if (listener.confirmInterrupt()) {
|
||||
return;
|
||||
}
|
||||
networkRequest = myLoadingState.resume();
|
||||
private void doLoadChildren(ZLNetworkRequest networkRequest) throws ZLNetworkException {
|
||||
try {
|
||||
super.doLoadChildren(myLoadingState, networkRequest);
|
||||
} catch (ZLNetworkException e) {
|
||||
myLoadingState = null;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,12 +66,12 @@ class OPDSCatalogItem extends NetworkCatalogItem {
|
|||
public final void loadChildren(NetworkOperationData.OnNewItemListener listener) throws ZLNetworkException {
|
||||
OPDSNetworkLink opdsLink = (OPDSNetworkLink) Link;
|
||||
|
||||
myLoadingState = opdsLink.createOperationData(Link, listener);
|
||||
myLoadingState = opdsLink.createOperationData(listener);
|
||||
|
||||
ZLNetworkRequest networkRequest =
|
||||
opdsLink.createNetworkData(URLByType.get(URL_CATALOG), myLoadingState);
|
||||
|
||||
doLoadChildren(listener, networkRequest);
|
||||
doLoadChildren(networkRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -92,7 +84,7 @@ class OPDSCatalogItem extends NetworkCatalogItem {
|
|||
if (myLoadingState != null) {
|
||||
myLoadingState.Listener = listener;
|
||||
ZLNetworkRequest networkRequest = myLoadingState.resume();
|
||||
doLoadChildren(listener, networkRequest);
|
||||
doLoadChildren(networkRequest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -121,9 +121,8 @@ class OPDSNetworkLink extends AbstractNetworkLink {
|
|||
}
|
||||
|
||||
@Override
|
||||
public OPDSCatalogItem.State createOperationData(INetworkLink link,
|
||||
NetworkOperationData.OnNewItemListener listener) {
|
||||
return new OPDSCatalogItem.State(link, listener);
|
||||
public OPDSCatalogItem.State createOperationData(NetworkOperationData.OnNewItemListener listener) {
|
||||
return new OPDSCatalogItem.State(this, listener);
|
||||
}
|
||||
|
||||
public ZLNetworkRequest simpleSearchRequest(String pattern, NetworkOperationData data) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue