mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-06 03:50:19 +02:00
host name constant in litres code
This commit is contained in:
parent
ee06eaa579
commit
c773e35d98
7 changed files with 16 additions and 35 deletions
|
@ -79,9 +79,9 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager {
|
|||
public LitResAuthenticationManager(OPDSNetworkLink link) {
|
||||
super(link);
|
||||
|
||||
mySidOption = new ZLStringOption(link.getSiteName(), "sid", "");
|
||||
myUserIdOption = new ZLStringOption(link.getSiteName(), "userId", "");
|
||||
myCanRebillOption = new ZLBooleanOption(link.getSiteName(), "canRebill", false);
|
||||
mySidOption = new ZLStringOption(LitResUtil.HOST_NAME, "sid", "");
|
||||
myUserIdOption = new ZLStringOption(LitResUtil.HOST_NAME, "userId", "");
|
||||
myCanRebillOption = new ZLBooleanOption(LitResUtil.HOST_NAME, "canRebill", false);
|
||||
}
|
||||
|
||||
public synchronized boolean initUser(String username, String sid, String userId, boolean canRebill) {
|
||||
|
@ -149,7 +149,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager {
|
|||
}
|
||||
|
||||
try {
|
||||
final LitResLoginXMLReader xmlReader = new LitResLoginXMLReader(Link.getSiteName());
|
||||
final LitResLoginXMLReader xmlReader = new LitResLoginXMLReader();
|
||||
final Map<String,String> params = new HashMap<String,String>();
|
||||
final String url = parseUrl(Link.getUrl(UrlInfo.Type.SignIn), params);
|
||||
if (url == null) {
|
||||
|
@ -183,7 +183,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager {
|
|||
}
|
||||
|
||||
try {
|
||||
final LitResLoginXMLReader xmlReader = new LitResLoginXMLReader(Link.getSiteName());
|
||||
final LitResLoginXMLReader xmlReader = new LitResLoginXMLReader();
|
||||
final LitResNetworkRequest request = new LitResNetworkRequest(url, xmlReader);
|
||||
for (Map.Entry<String,String> entry : params.entrySet()) {
|
||||
request.addPostParameter(entry.getKey(), entry.getValue());
|
||||
|
@ -236,7 +236,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager {
|
|||
throw ZLNetworkException.forCode(NetworkException.ERROR_BOOK_NOT_PURCHASED); // TODO: more correct error message???
|
||||
}
|
||||
|
||||
final LitResPurchaseXMLReader xmlReader = new LitResPurchaseXMLReader(Link.getSiteName());
|
||||
final LitResPurchaseXMLReader xmlReader = new LitResPurchaseXMLReader();
|
||||
|
||||
ZLNetworkException exception = null;
|
||||
try {
|
||||
|
@ -260,7 +260,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager {
|
|||
throw exception;
|
||||
}
|
||||
if (xmlReader.BookId == null || !xmlReader.BookId.equals(book.Id)) {
|
||||
throw ZLNetworkException.forCode(NetworkException.ERROR_SOMETHING_WRONG, Link.getSiteName());
|
||||
throw ZLNetworkException.forCode(NetworkException.ERROR_SOMETHING_WRONG, LitResUtil.HOST_NAME);
|
||||
}
|
||||
myPurchasedBooks.addToStart(book);
|
||||
final BasketItem basket = book.Link.getBasketItem();
|
||||
|
@ -441,7 +441,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager {
|
|||
|
||||
final LitResNetworkRequest request = new LitResNetworkRequest(
|
||||
LitResUtil.url(Link, query),
|
||||
new LitResPurchaseXMLReader(Link.getSiteName())
|
||||
new LitResPurchaseXMLReader()
|
||||
);
|
||||
request.addPostParameter("sid", sid);
|
||||
request.addPostParameter("art", "0");
|
||||
|
@ -459,7 +459,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager {
|
|||
if (url == null) {
|
||||
throw ZLNetworkException.forCode(NetworkException.ERROR_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
final LitResPasswordRecoveryXMLReader xmlReader = new LitResPasswordRecoveryXMLReader(Link.getSiteName());
|
||||
final LitResPasswordRecoveryXMLReader xmlReader = new LitResPasswordRecoveryXMLReader();
|
||||
final LitResNetworkRequest request = new LitResNetworkRequest(url, xmlReader);
|
||||
request.addPostParameter("mail", email);
|
||||
myNetworkContext.perform(request);
|
||||
|
|
|
@ -23,12 +23,6 @@ import org.geometerplus.zlibrary.core.xml.ZLXMLReaderAdapter;
|
|||
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
||||
|
||||
class LitResAuthenticationXMLReader extends ZLXMLReaderAdapter {
|
||||
public final String HostName;
|
||||
|
||||
public LitResAuthenticationXMLReader(String hostName) {
|
||||
HostName = hostName;
|
||||
}
|
||||
|
||||
private ZLNetworkException myException;
|
||||
|
||||
protected void setException(ZLNetworkException e) {
|
||||
|
|
|
@ -33,10 +33,6 @@ class LitResLoginXMLReader extends LitResAuthenticationXMLReader {
|
|||
public String Sid;
|
||||
public boolean CanRebill;
|
||||
|
||||
public LitResLoginXMLReader(String hostName) {
|
||||
super(hostName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startElementHandler(String tag, ZLStringMap attributes) {
|
||||
tag = tag.toLowerCase().intern();
|
||||
|
@ -53,7 +49,7 @@ class LitResLoginXMLReader extends LitResAuthenticationXMLReader {
|
|||
}
|
||||
CanRebill = stringCanRebill != null && !"0".equals(stringCanRebill) && !"no".equalsIgnoreCase(stringCanRebill);
|
||||
} else {
|
||||
setException(ZLNetworkException.forCode(ZLNetworkException.ERROR_SOMETHING_WRONG, HostName));
|
||||
setException(ZLNetworkException.forCode(ZLNetworkException.ERROR_SOMETHING_WRONG, LitResUtil.HOST_NAME));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -28,10 +28,6 @@ class LitResPasswordRecoveryXMLReader extends LitResAuthenticationXMLReader {
|
|||
private static final String TAG_PASSWORD_RECOVERY_OK = "catalit-pass-recover-ok";
|
||||
private static final String TAG_PASSWORD_RECOVERY_FAILED = "catalit-pass-recover-failed";
|
||||
|
||||
public LitResPasswordRecoveryXMLReader(String hostName) {
|
||||
super(hostName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startElementHandler(String tag, ZLStringMap attributes) {
|
||||
tag = tag.toLowerCase().intern();
|
||||
|
@ -47,7 +43,7 @@ class LitResPasswordRecoveryXMLReader extends LitResAuthenticationXMLReader {
|
|||
} else if (TAG_PASSWORD_RECOVERY_OK == tag) {
|
||||
// NOP
|
||||
} else {
|
||||
setException(ZLNetworkException.forCode(NetworkException.ERROR_SOMETHING_WRONG, HostName));
|
||||
setException(ZLNetworkException.forCode(NetworkException.ERROR_SOMETHING_WRONG, LitResUtil.HOST_NAME));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -34,10 +34,6 @@ class LitResPurchaseXMLReader extends LitResAuthenticationXMLReader {
|
|||
public String Account;
|
||||
public String BookId;
|
||||
|
||||
public LitResPurchaseXMLReader(String hostName) {
|
||||
super(hostName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startElementHandler(String tag, ZLStringMap attributes) {
|
||||
tag = tag.toLowerCase().intern();
|
||||
|
@ -60,7 +56,7 @@ class LitResPurchaseXMLReader extends LitResAuthenticationXMLReader {
|
|||
setException(ZLNetworkException.forCode(NetworkException.ERROR_INTERNAL));
|
||||
}
|
||||
} else {
|
||||
setException(ZLNetworkException.forCode(NetworkException.ERROR_SOMETHING_WRONG, HostName));
|
||||
setException(ZLNetworkException.forCode(NetworkException.ERROR_SOMETHING_WRONG, LitResUtil.HOST_NAME));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -25,16 +25,16 @@ import org.geometerplus.fbreader.network.INetworkLink;
|
|||
|
||||
|
||||
class LitResUtil {
|
||||
public static final String HOST_NAME = "litres.ru";
|
||||
|
||||
public static String url(String path) {
|
||||
String url = "://robot.litres.ru/" + path;
|
||||
final String url = "://robot.litres.ru/" + path;
|
||||
if (ZLNetworkUtil.hasParameter(url, "sid") ||
|
||||
ZLNetworkUtil.hasParameter(url, "pwd")) {
|
||||
url = "https" + url;
|
||||
return "https" + url;
|
||||
} else {
|
||||
url = "http" + url;
|
||||
return "http" + url;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
public static String url(INetworkLink link, String path) {
|
||||
|
|
|
@ -55,7 +55,6 @@ class LitResXMLReader extends LitResAuthenticationXMLReader {
|
|||
private LinkedList<String> myTags = new LinkedList<String>();
|
||||
|
||||
public LitResXMLReader(OPDSNetworkLink link) {
|
||||
super(link.getSiteName());
|
||||
Link = link;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue