diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/AbstractService.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/AbstractService.java
index a9c4f0f..ac3a1b3 100644
--- a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/AbstractService.java
+++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/AbstractService.java
@@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory;
import com.rogiel.httpchannel.captcha.Captcha;
import com.rogiel.httpchannel.captcha.CaptchaService;
import com.rogiel.httpchannel.captcha.exception.UnsolvableCaptchaServiceException;
+import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.exception.NoCaptchaServiceException;
/**
@@ -41,9 +42,9 @@ public abstract class AbstractService implements Service {
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
/**
- * The currently active service mode
+ * The currently active account
*/
- protected ServiceMode serviceMode = ServiceMode.UNAUTHENTICATED;
+ protected AccountDetails account;
/**
* This service {@link CaptchaService} that is used to resolve CAPTCHAS
@@ -52,7 +53,16 @@ public abstract class AbstractService implements Service {
@Override
public ServiceMode getServiceMode() {
- return serviceMode;
+ if (account == null) {
+ return ServiceMode.UNAUTHENTICATED;
+ } else {
+ if (account.is(PremiumAccountDetails.class)) {
+ return (account.as(PremiumAccountDetails.class).isPremium() ? ServiceMode.PREMIUM
+ : ServiceMode.NON_PREMIUM);
+ } else {
+ return ServiceMode.NON_PREMIUM;
+ }
+ }
}
@Override
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/AccountDetails.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/AccountDetails.java
index beab719..e2fed88 100644
--- a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/AccountDetails.java
+++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/AccountDetails.java
@@ -4,10 +4,149 @@
package com.rogiel.httpchannel.service;
/**
+ * An {@link AccountDetails} instance can provide several information about an
+ * authenticated account. This instance itself provides little information,
+ * restricted to whether the account {@link #isActive() is active} and its
+ * {@link #getUsername() username}. More details are provided by additional
+ * interfaces:
+ *
+ * - {@link PremiumAccountDetails} - for services that provide premium
+ * accounts
+ * - {@link DiskQuotaAccountDetails} - for services that have limited disk
+ * quota
+ * - {@link BandwidthQuotaAccountDetails} - for services that have limited
+ * bandwidth quota
+ *
+ * You should not try to cast instances by yourself, instead they should be
+ * safely casted as such:
+ *
+ *
+ * final {@link AccountDetails} details = ...;
+ * if(details.{@link #is(Class) is}({@link PremiumAccountDetails}.class)) {
+ * details.{@link #as(Class) as}({@link PremiumAccountDetails}.class).{@link PremiumAccountDetails#isPremium() isPremium()};
+ * }
+ *
+ *
+ * A single {@link AccountDetails} can implement none, one extended or even more
+ * than one extended details interfaces, however all instances are required to
+ * implement at least the basic methods defined in this interface.
+ *
+ * Services could implement their own methods for details, but this should be
+ * avoided because it would make user code dependent on implementation meta data
+ * which is not stable and could break compatibility with other implementation
+ * versions. If possible, it is recommended to add a new interface into the API
+ * module.
+ *
* @author Rogiel
+ * @since 1.0
*/
public interface AccountDetails {
+ /**
+ * @return the account username
+ */
String getUsername();
-
+
+ /**
+ * @return true if the account is currently active
+ */
+ boolean isActive();
+
+ /**
+ * @return the service that provided this account
+ */
AuthenticationService> getService();
+
+ /**
+ * Checks whether the account object can be casted to type
+ *
+ * @param type
+ * the casting type
+ * @return true if this object can be casted to
+ * type
+ */
+ boolean is(Class extends AccountDetails> type);
+
+ /**
+ * Casts this object to type. If cannot be casted,
+ * null is returned.
+ *
+ * @param type
+ * the casting type
+ * @return the casted account
+ */
+ T as(Class type);
+
+ /**
+ * Service accounts that has premium accounts must implement this interface
+ *
+ * @author Rogiel
+ */
+ public interface PremiumAccountDetails extends AccountDetails {
+ /**
+ * @return true if the account is premium
+ */
+ boolean isPremium();
+ }
+
+ /**
+ * Service accounts that has accounts with limited disk space should
+ * implement this interface
+ *
+ * @author Rogiel
+ */
+ public interface DiskQuotaAccountDetails extends AccountDetails {
+ /**
+ * @return the currently free disk space. -1 means no limit
+ */
+ long getFreeDiskSpace();
+
+ /**
+ * @return the currently used disk space. Cannot be negative.
+ */
+ long getUsedDiskSpace();
+
+ /**
+ * @return the maximum amount of disk space. -1 means no
+ * limit
+ */
+ long getMaximumDiskSpace();
+ }
+
+ /**
+ * Service accounts that has accounts with limited bandwidth should
+ * implement this interface
+ *
+ * @author Rogiel
+ */
+ public interface BandwidthQuotaAccountDetails extends AccountDetails {
+ /**
+ * @return the currently free bandwidth. -1 means no limit
+ */
+ long getFreeBandwidth();
+
+ /**
+ * @return the currently used bandwidth. Cannot be negative.
+ */
+ long getUsedBandwidth();
+
+ /**
+ * @return the maximum amount of bandwidth available. -1
+ * means no limit
+ */
+ long getMaximumBandwidth();
+ }
+
+ /**
+ * Service accounts that has accounts with limited bandwidth should
+ * implement this interface
+ *
+ * @author Rogiel
+ */
+ public interface FilesizeLimitAccountDetails extends AccountDetails {
+ /**
+ * @return the maximum filesize for the account. -1 means
+ * no limit
+ */
+ long getMaximumFilesize();
+ }
}
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/AuthenticationService.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/AuthenticationService.java
index 0cf0039..017bda5 100644
--- a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/AuthenticationService.java
+++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/AuthenticationService.java
@@ -69,4 +69,10 @@ public interface AuthenticationService
* @see AuthenticatorCapability
*/
CapabilityMatrix getAuthenticationCapability();
+
+ /**
+ * @return the currently authenticated account. Can be null and
+ * this indicates that the service is not authenticated.
+ */
+ AccountDetails getAccountDetails();
}
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Authenticator.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Authenticator.java
index 7ffd0f6..57f97d1 100644
--- a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Authenticator.java
+++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Authenticator.java
@@ -38,6 +38,16 @@ public interface Authenticator {
* persistent for the entire service's operation.
* Note: If you want to logout the user, see
* {@link Authenticator#logout()}
+ *
+ * Return null is only allowed if
+ * {@link AuthenticatorCapability#ACCOUNT_DETAILS} is not supported by the
+ * service.
+ *
+ * @return the authenticated account {@link AccountDetails}. If
+ * {@link AuthenticationService#getAuthenticationCapability()}
+ * contains {@link AuthenticatorCapability#ACCOUNT_DETAILS}
+ * null cannot be returned. Otherwise,
+ * null should always be returned.
*
* @throws IOException
* if any IO error occur
@@ -51,7 +61,8 @@ public interface Authenticator {
* if the service required an {@link CaptchaService}
* implementation to be present, but none was available
*/
- void login() throws IOException, AuthenticationInvalidCredentialException,
+ AccountDetails login() throws IOException,
+ AuthenticationInvalidCredentialException,
UnsolvableCaptchaServiceException, NoCaptchaServiceException;
/**
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/AuthenticatorCapability.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/AuthenticatorCapability.java
index b9140cb..3359074 100644
--- a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/AuthenticatorCapability.java
+++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/AuthenticatorCapability.java
@@ -26,7 +26,7 @@ package com.rogiel.httpchannel.service;
*/
public enum AuthenticatorCapability {
/**
- * Mark an {@link Authenticator} capable of fetching account information.
+ * Mark an {@link Authenticator} capable of providing account details.
*/
- FETCH_ACCOUNT_INFORMATION;
+ ACCOUNT_DETAILS;
}
diff --git a/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/AccountItemArray.java b/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/AccountItemArray.java
index 8bac423..2bb37fa 100644
--- a/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/AccountItemArray.java
+++ b/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/AccountItemArray.java
@@ -3,6 +3,7 @@ package com.pmstation.shared.soap.client;
import java.util.ArrayList;
import java.util.List;
+
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
diff --git a/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/DirHistoryDTOArray.java b/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/DirHistoryDTOArray.java
index 8e71ddc..0fb50c7 100644
--- a/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/DirHistoryDTOArray.java
+++ b/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/DirHistoryDTOArray.java
@@ -3,6 +3,7 @@ package com.pmstation.shared.soap.client;
import java.util.ArrayList;
import java.util.List;
+
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
diff --git a/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/DirHistoryDTOArrayArray.java b/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/DirHistoryDTOArrayArray.java
index 9c954fa..1906735 100644
--- a/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/DirHistoryDTOArrayArray.java
+++ b/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/DirHistoryDTOArrayArray.java
@@ -3,6 +3,7 @@ package com.pmstation.shared.soap.client;
import java.util.ArrayList;
import java.util.List;
+
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
diff --git a/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/ExifInfoArray.java b/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/ExifInfoArray.java
index 5244308..3ed0a35 100644
--- a/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/ExifInfoArray.java
+++ b/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/ExifInfoArray.java
@@ -3,6 +3,7 @@ package com.pmstation.shared.soap.client;
import java.util.ArrayList;
import java.util.List;
+
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
diff --git a/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/LongArray.java b/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/LongArray.java
index 4538086..1c08b48 100644
--- a/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/LongArray.java
+++ b/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/LongArray.java
@@ -3,6 +3,7 @@ package com.pmstation.shared.soap.client;
import java.util.ArrayList;
import java.util.List;
+
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
diff --git a/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/Mp3InfoArray.java b/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/Mp3InfoArray.java
index 0820f54..070c5fd 100644
--- a/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/Mp3InfoArray.java
+++ b/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/Mp3InfoArray.java
@@ -3,6 +3,7 @@ package com.pmstation.shared.soap.client;
import java.util.ArrayList;
import java.util.List;
+
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
diff --git a/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/SettingsGroupArray.java b/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/SettingsGroupArray.java
index 498939d..17c95b2 100644
--- a/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/SettingsGroupArray.java
+++ b/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/SettingsGroupArray.java
@@ -3,6 +3,7 @@ package com.pmstation.shared.soap.client;
import java.util.ArrayList;
import java.util.List;
+
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
diff --git a/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/SharedFolderPropertiesArray.java b/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/SharedFolderPropertiesArray.java
index 67275b6..61c9b1b 100644
--- a/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/SharedFolderPropertiesArray.java
+++ b/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/SharedFolderPropertiesArray.java
@@ -3,6 +3,7 @@ package com.pmstation.shared.soap.client;
import java.util.ArrayList;
import java.util.List;
+
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
diff --git a/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/StringArray.java b/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/StringArray.java
index 510d8cc..1a70f62 100644
--- a/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/StringArray.java
+++ b/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/StringArray.java
@@ -3,6 +3,7 @@ package com.pmstation.shared.soap.client;
import java.util.ArrayList;
import java.util.List;
+
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
diff --git a/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/UserSetting.java b/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/UserSetting.java
index 3ea497b..0c406a0 100644
--- a/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/UserSetting.java
+++ b/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/UserSetting.java
@@ -3,6 +3,7 @@ package com.pmstation.shared.soap.client;
import java.util.ArrayList;
import java.util.List;
+
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
diff --git a/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/UserSettings.java b/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/UserSettings.java
index cdf4089..72d927b 100644
--- a/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/UserSettings.java
+++ b/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/UserSettings.java
@@ -3,6 +3,7 @@ package com.pmstation.shared.soap.client;
import java.util.ArrayList;
import java.util.List;
+
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
diff --git a/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/UserSettingsArray.java b/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/UserSettingsArray.java
index 0b873d8..d8d9688 100644
--- a/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/UserSettingsArray.java
+++ b/httpchannel-service/httpchannel-service-4shared/src/main/java/com/pmstation/shared/soap/client/UserSettingsArray.java
@@ -3,6 +3,7 @@ package com.pmstation.shared.soap.client;
import java.util.ArrayList;
import java.util.List;
+
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
diff --git a/httpchannel-service/httpchannel-service-4shared/src/main/java/org/httpchannel/service/fourshared/FourSharedService.java b/httpchannel-service/httpchannel-service-4shared/src/main/java/org/httpchannel/service/fourshared/FourSharedService.java
index e411cef..09ab43b 100644
--- a/httpchannel-service/httpchannel-service-4shared/src/main/java/org/httpchannel/service/fourshared/FourSharedService.java
+++ b/httpchannel-service/httpchannel-service-4shared/src/main/java/org/httpchannel/service/fourshared/FourSharedService.java
@@ -25,9 +25,14 @@ import java.util.concurrent.Future;
import com.pmstation.shared.soap.client.ApiException;
import com.pmstation.shared.soap.client.DesktopAppJax2;
import com.pmstation.shared.soap.client.DesktopAppJax2Service;
+import com.rogiel.httpchannel.service.AbstractAccountDetails;
import com.rogiel.httpchannel.service.AbstractAuthenticator;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
+import com.rogiel.httpchannel.service.AccountDetails;
+import com.rogiel.httpchannel.service.AccountDetails.DiskQuotaAccountDetails;
+import com.rogiel.httpchannel.service.AccountDetails.FilesizeLimitAccountDetails;
+import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
@@ -45,7 +50,6 @@ import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadCh
import com.rogiel.httpchannel.service.config.NullAuthenticatorConfiguration;
import com.rogiel.httpchannel.service.config.NullUploaderConfiguration;
import com.rogiel.httpchannel.service.exception.AuthenticationInvalidCredentialException;
-import com.rogiel.httpchannel.service.exception.AuthenticationServiceException;
import com.rogiel.httpchannel.service.exception.ChannelServiceException;
import com.rogiel.httpchannel.service.exception.DownloadLinkNotFoundException;
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
@@ -67,9 +71,6 @@ public class FourSharedService extends AbstractHttpService implements Service,
private final DesktopAppJax2 api = new DesktopAppJax2Service()
.getDesktopAppJax2Port();
- private String username;
- private String password;
-
@Override
public ServiceID getServiceID() {
return SERVICE_ID;
@@ -110,16 +111,16 @@ public class FourSharedService extends AbstractHttpService implements Service,
@Override
public long getMaximumFilesize() {
- try {
- final long free = api.getFreeSpace(username, password);
- final long max = api.getMaxFileSize(username, password);
- if (max < free)
- return max;
- else
- return free;
- } catch (ApiException e) {
- return 0;
- }
+ final long max = account.as(FilesizeLimitAccountDetails.class)
+ .getMaximumFilesize();
+ if(max <= -1)
+ return -1;
+ final long free = account.as(DiskQuotaAccountDetails.class)
+ .getFreeDiskSpace();
+ if (max < free)
+ return max;
+ else
+ return free;
}
@Override
@@ -154,10 +155,16 @@ public class FourSharedService extends AbstractHttpService implements Service,
@Override
public CapabilityMatrix getAuthenticationCapability() {
- return new CapabilityMatrix();
+ return new CapabilityMatrix(
+ AuthenticatorCapability.ACCOUNT_DETAILS);
}
- protected class UploaderImpl extends
+ @Override
+ public AccountDetails getAccountDetails() {
+ return account;
+ }
+
+ private class UploaderImpl extends
AbstractUploader implements
Uploader,
LinkedUploadChannelCloseCallback {
@@ -172,14 +179,14 @@ public class FourSharedService extends AbstractHttpService implements Service,
public UploadChannel openChannel() throws IOException {
try {
logger.debug("Starting upload to 4shared.com");
- final String sessionID = api.createUploadSessionKey(username,
- password, -1);
+ final String sessionID = api.createUploadSessionKey(
+ account.getUsername(), getPassword(), -1);
logger.debug("SessionID: {}", sessionID);
if (sessionID == null || sessionID.length() == 0)
throw new ChannelServiceException("SessionID is invalid");
- final long datacenterID = api.getNewFileDataCenter(username,
- password);
+ final long datacenterID = api.getNewFileDataCenter(
+ account.getUsername(), getPassword());
logger.debug("DatacenterID: {}", datacenterID);
if (datacenterID <= 0)
throw new ChannelServiceException("DatacenterID is invalid");
@@ -205,7 +212,8 @@ public class FourSharedService extends AbstractHttpService implements Service,
try {
final long linkID = Long.parseLong(uploadFuture.get()
.getInputValueById("uploadedFileId"));
- return api.getFileDownloadLink(username, password, linkID);
+ return api.getFileDownloadLink(account.getUsername(),
+ getPassword(), linkID);
} catch (InterruptedException e) {
return null;
} catch (ExecutionException e) {
@@ -216,7 +224,7 @@ public class FourSharedService extends AbstractHttpService implements Service,
}
}
- protected class AuthenticatorImpl extends
+ private class AuthenticatorImpl extends
AbstractAuthenticator implements
Authenticator {
public AuthenticatorImpl(Credential credential,
@@ -225,31 +233,90 @@ public class FourSharedService extends AbstractHttpService implements Service,
}
@Override
- public void login() throws IOException {
+ public AccountDetails login() throws IOException {
logger.debug("Logging to 4shared.com");
final String response = api.login(credential.getUsername(),
credential.getPassword());
- username = credential.getUsername();
- password = credential.getPassword();
-
- try {
- if (api.isAccountPremium(username, password))
- serviceMode = ServiceMode.PREMIUM;
- else
- serviceMode = ServiceMode.NON_PREMIUM;
- } catch (ApiException e) {
- throw new AuthenticationServiceException(e);
- }
if (!response.isEmpty())
throw new AuthenticationInvalidCredentialException();
+ return (account = new AccountDetailsImpl(credential.getUsername(),
+ credential.getPassword()));
}
@Override
public void logout() throws IOException {
- username = null;
- password = null;
+ account = null;
+ }
+ }
+
+ private class AccountDetailsImpl extends AbstractAccountDetails implements
+ PremiumAccountDetails, DiskQuotaAccountDetails,
+ FilesizeLimitAccountDetails {
+ private final String password;
+
+ private AccountDetailsImpl(String username, String password) {
+ super(FourSharedService.this, username);
+ this.password = password;
+ }
+
+ @Override
+ public boolean isActive() {
+ try {
+ return api.isAccountActive(username, password);
+ } catch (ApiException e) {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean isPremium() {
+ try {
+ return api.isAccountPremium(username, password);
+ } catch (ApiException e) {
+ return false;
+ }
+ }
+
+ @Override
+ public long getFreeDiskSpace() {
+ try {
+ return api.getFreeSpace(username, password);
+ } catch (ApiException e) {
+ return -1;
+ }
+ }
+
+ @Override
+ public long getUsedDiskSpace() {
+ return getMaximumDiskSpace() - getFreeDiskSpace();
+ }
+
+ @Override
+ public long getMaximumDiskSpace() {
+ try {
+ return api.getSpaceLimit(username, password);
+ } catch (ApiException e) {
+ return -1;
+ }
+ }
+
+ @Override
+ public long getMaximumFilesize() {
+ try {
+ return api.getMaxFileSize(username, password);
+ } catch (ApiException e) {
+ return -1;
+ }
+ }
+ }
+
+ private String getPassword() {
+ if (account == null) {
+ return null;
+ } else {
+ return ((AccountDetailsImpl) account).password;
}
}
diff --git a/httpchannel-service/httpchannel-service-archetype/pom.xml b/httpchannel-service/httpchannel-service-archetype/pom.xml
index aa24f79..8b09802 100644
--- a/httpchannel-service/httpchannel-service-archetype/pom.xml
+++ b/httpchannel-service/httpchannel-service-archetype/pom.xml
@@ -1,31 +1,32 @@
-
- 4.0.0
+
+ 4.0.0
- com.rogiel.httpchannel.services
- httpchannel-service-archetype
- 1.0.1-SNAPSHOT
- maven-archetype
+ com.rogiel.httpchannel.services
+ httpchannel-service-archetype
+ 1.0.1-SNAPSHOT
+ maven-archetype
- HttpChannel/Service/Archetype
- Provides an maven archetype for service creation
+ HttpChannel/Service/Archetype
+ Provides an maven archetype for service creation
-
-
-
- org.apache.maven.archetype
- archetype-packaging
- 2.2
-
-
+
+
+
+ org.apache.maven.archetype
+ archetype-packaging
+ 2.2
+
+
-
-
-
- maven-archetype-plugin
- 2.2
-
-
-
-
+
+
+
+ maven-archetype-plugin
+ 2.2
+
+
+
+
diff --git a/httpchannel-service/httpchannel-service-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml b/httpchannel-service/httpchannel-service-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
index 3fe0f9c..9a48c8c 100644
--- a/httpchannel-service/httpchannel-service-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
+++ b/httpchannel-service/httpchannel-service-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
@@ -4,6 +4,10 @@
name="httpchannel-service-archetype"
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+
+
+
src/main/java
@@ -17,18 +21,5 @@
**/*.Service
-
- .settings
-
- **/*.prefs
-
-
-
-
-
- .classpath
- .project
-
-
diff --git a/httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/pom.xml b/httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/pom.xml
index e03635e..d8fd44f 100644
--- a/httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/pom.xml
+++ b/httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/pom.xml
@@ -1,5 +1,6 @@
-
+
4.0.0
httpchannel-service
@@ -9,7 +10,7 @@
${artifactId}
${groupId}
- HttpChannel/Service/MyService
- Provides an maven archetype for service creation
+ HttpChannel/Service/${serviceName}
+ Provides download and upload access for ${serviceName}
${version}
diff --git a/httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/src/main/java/MyServiceService.java b/httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/src/main/java/${serviceName}Service.java
similarity index 91%
rename from httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/src/main/java/MyServiceService.java
rename to httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/src/main/java/${serviceName}Service.java
index 0c80f50..0d0e29f 100644
--- a/httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/src/main/java/MyServiceService.java
+++ b/httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/src/main/java/${serviceName}Service.java
@@ -41,17 +41,17 @@ import com.rogiel.httpchannel.service.config.NullUploaderConfiguration;
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
/**
- * This service handles uploads to MyService.com.
+ * This service handles uploads to ${serviceName}.
*
* @author Rogiel
* @since 1.0
*/
-public class MyServiceService extends AbstractHttpService implements
+public class ${serviceName}Service extends AbstractHttpService implements
Service, UploadService {
/**
* This service ID
*/
- public static final ServiceID SERVICE_ID = ServiceID.create("myservice");
+ public static final ServiceID SERVICE_ID = ServiceID.create("${serviceID}");
@Override
public ServiceID getServiceID() {
@@ -122,7 +122,7 @@ public class MyServiceService extends AbstractHttpService implements
@Override
public UploadChannel openChannel() throws IOException {
- logger.debug("Starting upload to myservice.com");
+ logger.debug("Starting upload to ${serviceName}");
final HTMLPage page = get("http://www.example.com/").asPage();
// locate upload uri
diff --git a/httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/src/main/resources/META-INF/services/com.rogiel.httpchannel.service.Service b/httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/src/main/resources/META-INF/services/com.rogiel.httpchannel.service.Service
index caaa717..5dde9b7 100644
--- a/httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/src/main/resources/META-INF/services/com.rogiel.httpchannel.service.Service
+++ b/httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/src/main/resources/META-INF/services/com.rogiel.httpchannel.service.Service
@@ -1 +1 @@
-com.rogiel.httpchannel.service.impl.MyService
\ No newline at end of file
+${package}.${serviceName}Service
\ No newline at end of file
diff --git a/httpchannel-service/httpchannel-service-archetype/src/test/resources/projects/basic/archetype.properties b/httpchannel-service/httpchannel-service-archetype/src/test/resources/projects/basic/archetype.properties
index 1872146..91c1d1a 100644
--- a/httpchannel-service/httpchannel-service-archetype/src/test/resources/projects/basic/archetype.properties
+++ b/httpchannel-service/httpchannel-service-archetype/src/test/resources/projects/basic/archetype.properties
@@ -3,3 +3,5 @@ package=it.pkg
version=0.1-SNAPSHOT
groupId=archetype.it
artifactId=basic
+serviceName = TestService
+serviceID = testservice
\ No newline at end of file
diff --git a/httpchannel-service/httpchannel-service-depositfiles/src/main/java/com/rogiel/httpchannel/service/depositfiles/DepositFilesService.java b/httpchannel-service/httpchannel-service-depositfiles/src/main/java/com/rogiel/httpchannel/service/depositfiles/DepositFilesService.java
index 4c679fa..6f596f5 100644
--- a/httpchannel-service/httpchannel-service-depositfiles/src/main/java/com/rogiel/httpchannel/service/depositfiles/DepositFilesService.java
+++ b/httpchannel-service/httpchannel-service-depositfiles/src/main/java/com/rogiel/httpchannel/service/depositfiles/DepositFilesService.java
@@ -26,9 +26,11 @@ import java.util.regex.Pattern;
import com.rogiel.httpchannel.captcha.ImageCaptcha;
import com.rogiel.httpchannel.captcha.ReCaptchaExtractor;
import com.rogiel.httpchannel.captcha.exception.UnsolvableCaptchaServiceException;
+import com.rogiel.httpchannel.service.AbstractAccountDetails;
import com.rogiel.httpchannel.service.AbstractAuthenticator;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
+import com.rogiel.httpchannel.service.AccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
@@ -145,10 +147,15 @@ public class DepositFilesService extends AbstractHttpService implements
@Override
public CapabilityMatrix getAuthenticationCapability() {
- return new CapabilityMatrix();
+ return new CapabilityMatrix(AuthenticatorCapability.ACCOUNT_DETAILS);
+ }
+
+ @Override
+ public AccountDetails getAccountDetails() {
+ return account;
}
- protected class UploaderImpl extends
+ private class UploaderImpl extends
AbstractUploader implements
Uploader,
LinkedUploadChannelCloseCallback {
@@ -195,7 +202,7 @@ public class DepositFilesService extends AbstractHttpService implements
}
}
- protected class AuthenticatorImpl extends
+ private class AuthenticatorImpl extends
AbstractAuthenticator implements
Authenticator {
public AuthenticatorImpl(Credential credential,
@@ -204,7 +211,7 @@ public class DepositFilesService extends AbstractHttpService implements
}
@Override
- public void login() throws IOException {
+ public AccountDetails login() throws IOException {
logger.debug("Authenticating into depositfiles.com");
HTMLPage page = post("http://depositfiles.com/login.php?return=%2F")
.parameter("go", true)
@@ -234,8 +241,7 @@ public class DepositFilesService extends AbstractHttpService implements
captchaService.valid(captcha);
if (!page.contains(VALID_LOGIN_REDIRECT))
throw new AuthenticationInvalidCredentialException();
- serviceMode = ServiceMode.NON_PREMIUM;
- return;
+ return (account = new AccountDetailsImpl(credential.getUsername()));
}
}
@@ -246,4 +252,14 @@ public class DepositFilesService extends AbstractHttpService implements
// TODO check logout status
}
}
+
+ private class AccountDetailsImpl extends AbstractAccountDetails {
+ /**
+ * @param username
+ * the account username
+ */
+ public AccountDetailsImpl(String username) {
+ super(DepositFilesService.this, username);
+ }
+ }
}
diff --git a/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/service/filesonic/FileSonicService.java b/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/service/filesonic/FileSonicService.java
index 8ddd3f0..8de8480 100644
--- a/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/service/filesonic/FileSonicService.java
+++ b/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/service/filesonic/FileSonicService.java
@@ -23,9 +23,12 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.regex.Pattern;
+import com.rogiel.httpchannel.service.AbstractAccountDetails;
import com.rogiel.httpchannel.service.AbstractAuthenticator;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
+import com.rogiel.httpchannel.service.AccountDetails;
+import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
@@ -146,10 +149,15 @@ public class FileSonicService extends AbstractHttpService implements Service,
@Override
public CapabilityMatrix getAuthenticationCapability() {
- return new CapabilityMatrix();
+ return new CapabilityMatrix(AuthenticatorCapability.ACCOUNT_DETAILS);
+ }
+
+ @Override
+ public AccountDetails getAccountDetails() {
+ return account;
}
- protected class UploaderImpl extends
+ private class UploaderImpl extends
AbstractUploader implements
Uploader,
LinkedUploadChannelCloseCallback {
@@ -182,7 +190,7 @@ public class FileSonicService extends AbstractHttpService implements Service,
}
}
- protected class AuthenticatorImpl extends
+ private class AuthenticatorImpl extends
AbstractAuthenticator implements
Authenticator {
public AuthenticatorImpl(Credential credential,
@@ -191,12 +199,10 @@ public class FileSonicService extends AbstractHttpService implements Service,
}
@Override
- public void login() throws IOException {
+ public AccountDetails login() throws IOException {
logger.debug("Logging to filesonic.com");
api.login(credential.getUsername(), credential.getPassword());
- serviceMode = ServiceMode.NON_PREMIUM;
- // if (username == null)
- // throw new AuthenticationInvalidCredentialException();
+ return (account = new AccountDetailsImpl(credential.getUsername()));
}
@Override
@@ -205,6 +211,22 @@ public class FileSonicService extends AbstractHttpService implements Service,
}
}
+ private class AccountDetailsImpl extends AbstractAccountDetails implements PremiumAccountDetails {
+ /**
+ * @param username
+ * the username
+ */
+ public AccountDetailsImpl(String username) {
+ super(FileSonicService.this, username);
+ }
+
+ @Override
+ public boolean isPremium() {
+ //TODO implement this
+ return false;
+ }
+ }
+
@Override
public String toString() {
return this.getClass().getSimpleName() + " " + getMajorVersion() + "."
diff --git a/httpchannel-service/httpchannel-service-hotfile/src/main/java/com/rogiel/httpchannel/service/hotfile/HotFileService.java b/httpchannel-service/httpchannel-service-hotfile/src/main/java/com/rogiel/httpchannel/service/hotfile/HotFileService.java
index f1e44a6..c7903b9 100644
--- a/httpchannel-service/httpchannel-service-hotfile/src/main/java/com/rogiel/httpchannel/service/hotfile/HotFileService.java
+++ b/httpchannel-service/httpchannel-service-hotfile/src/main/java/com/rogiel/httpchannel/service/hotfile/HotFileService.java
@@ -27,10 +27,13 @@ import java.util.regex.Pattern;
import org.apache.http.client.ClientProtocolException;
import org.htmlparser.Tag;
+import com.rogiel.httpchannel.service.AbstractAccountDetails;
import com.rogiel.httpchannel.service.AbstractAuthenticator;
import com.rogiel.httpchannel.service.AbstractHttpDownloader;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
+import com.rogiel.httpchannel.service.AccountDetails;
+import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
@@ -186,7 +189,12 @@ public class HotFileService extends AbstractHttpService implements Service,
@Override
public CapabilityMatrix getAuthenticationCapability() {
- return new CapabilityMatrix();
+ return new CapabilityMatrix(AuthenticatorCapability.ACCOUNT_DETAILS);
+ }
+
+ @Override
+ public AccountDetails getAccountDetails() {
+ return account;
}
protected class UploaderImpl extends
@@ -273,7 +281,8 @@ public class HotFileService extends AbstractHttpService implements Service,
}
@Override
- public void login() throws ClientProtocolException, IOException {
+ public AccountDetails login() throws ClientProtocolException,
+ IOException {
logger.debug("Authenticating hotfile.com");
HTMLPage page = post("http://www.hotfile.com/login.php")
.parameter("returnto", "/index.php")
@@ -283,7 +292,7 @@ public class HotFileService extends AbstractHttpService implements Service,
final Tag accountTag = page.getTagByID("account");
if (accountTag == null)
throw new AuthenticationInvalidCredentialException();
- serviceMode = ServiceMode.NON_PREMIUM;
+ return (account = new AccountDetailsImpl(credential.getUsername()));
}
@Override
@@ -294,6 +303,23 @@ public class HotFileService extends AbstractHttpService implements Service,
}
}
+ private class AccountDetailsImpl extends AbstractAccountDetails implements
+ PremiumAccountDetails {
+ /**
+ * @param username
+ * the username
+ */
+ public AccountDetailsImpl(String username) {
+ super(HotFileService.this, username);
+ }
+
+ @Override
+ public boolean isPremium() {
+ // TODO implement this
+ return false;
+ }
+ }
+
@Override
public String toString() {
return this.getClass().getSimpleName() + " " + getMajorVersion() + "."
diff --git a/httpchannel-service/httpchannel-service-megaupload/src/main/java/com/rogiel/httpchannel/service/megaupload/MegaUploadService.java b/httpchannel-service/httpchannel-service-megaupload/src/main/java/com/rogiel/httpchannel/service/megaupload/MegaUploadService.java
index 7b7163c..113f750 100644
--- a/httpchannel-service/httpchannel-service-megaupload/src/main/java/com/rogiel/httpchannel/service/megaupload/MegaUploadService.java
+++ b/httpchannel-service/httpchannel-service-megaupload/src/main/java/com/rogiel/httpchannel/service/megaupload/MegaUploadService.java
@@ -28,10 +28,13 @@ import org.apache.commons.io.FilenameUtils;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
+import com.rogiel.httpchannel.service.AbstractAccountDetails;
import com.rogiel.httpchannel.service.AbstractAuthenticator;
import com.rogiel.httpchannel.service.AbstractHttpDownloader;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
+import com.rogiel.httpchannel.service.AccountDetails;
+import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
@@ -198,7 +201,12 @@ public class MegaUploadService extends AbstractHttpService implements Service,
@Override
public CapabilityMatrix getAuthenticationCapability() {
- return new CapabilityMatrix();
+ return new CapabilityMatrix(AuthenticatorCapability.ACCOUNT_DETAILS);
+ }
+
+ @Override
+ public AccountDetails getAccountDetails() {
+ return account;
}
protected class UploaderImpl extends
@@ -312,7 +320,7 @@ public class MegaUploadService extends AbstractHttpService implements Service,
}
@Override
- public void login() throws IOException {
+ public AccountDetails login() throws IOException {
logger.debug("Starting login to megaupload.com");
final HTMLPage page = post("http://www.megaupload.com/?c=login")
.parameter("login", true)
@@ -322,7 +330,7 @@ public class MegaUploadService extends AbstractHttpService implements Service,
String username = page.findScript(LOGIN_USERNAME_PATTERN, 1);
if (username == null)
throw new AuthenticationInvalidCredentialException();
- serviceMode = ServiceMode.NON_PREMIUM;
+ return (account = new AccountDetailsImpl(credential.getUsername()));
}
@Override
@@ -333,6 +341,23 @@ public class MegaUploadService extends AbstractHttpService implements Service,
}
}
+ private class AccountDetailsImpl extends AbstractAccountDetails implements
+ PremiumAccountDetails {
+ /**
+ * @param username
+ * the username
+ */
+ public AccountDetailsImpl(String username) {
+ super(MegaUploadService.this, username);
+ }
+
+ @Override
+ public boolean isPremium() {
+ // TODO implement this
+ return false;
+ }
+ }
+
@Override
public String toString() {
return this.getClass().getSimpleName() + " " + getMajorVersion() + "."
diff --git a/httpchannel-service/httpchannel-service-multiupload/src/main/java/com/rogiel/httpchannel/service/multiupload/MultiUploadService.java b/httpchannel-service/httpchannel-service-multiupload/src/main/java/com/rogiel/httpchannel/service/multiupload/MultiUploadService.java
index bc29bbe..9643205 100644
--- a/httpchannel-service/httpchannel-service-multiupload/src/main/java/com/rogiel/httpchannel/service/multiupload/MultiUploadService.java
+++ b/httpchannel-service/httpchannel-service-multiupload/src/main/java/com/rogiel/httpchannel/service/multiupload/MultiUploadService.java
@@ -25,10 +25,13 @@ import java.util.concurrent.Future;
import java.util.regex.Pattern;
import com.rogiel.httpchannel.http.PostMultipartRequest;
+import com.rogiel.httpchannel.service.AbstractAccountDetails;
import com.rogiel.httpchannel.service.AbstractAuthenticator;
import com.rogiel.httpchannel.service.AbstractHttpDownloader;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
+import com.rogiel.httpchannel.service.AccountDetails;
+import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
@@ -50,15 +53,16 @@ import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
import com.rogiel.httpchannel.service.config.NullAuthenticatorConfiguration;
import com.rogiel.httpchannel.service.config.NullDownloaderConfiguration;
-import com.rogiel.httpchannel.service.exception.AuthenticationInvalidCredentialException;
import com.rogiel.httpchannel.service.exception.DownloadLimitExceededException;
import com.rogiel.httpchannel.service.exception.DownloadLinkNotFoundException;
import com.rogiel.httpchannel.service.exception.DownloadNotAuthorizedException;
import com.rogiel.httpchannel.service.exception.DownloadNotResumableException;
+import com.rogiel.httpchannel.service.exception.AuthenticationInvalidCredentialException;
import com.rogiel.httpchannel.service.multiupload.MultiUploadUploaderConfiguration.MultiUploadMirrorService;
import com.rogiel.httpchannel.util.PatternUtils;
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
+
/**
* This service handles uploads to MultiUpload.com.
*
@@ -192,7 +196,12 @@ public class MultiUploadService extends AbstractHttpService implements Service,
@Override
public CapabilityMatrix getAuthenticationCapability() {
- return new CapabilityMatrix();
+ return new CapabilityMatrix(AuthenticatorCapability.ACCOUNT_DETAILS);
+ }
+
+ @Override
+ public AccountDetails getAccountDetails() {
+ return account;
}
protected class UploaderImpl extends
@@ -282,14 +291,14 @@ public class MultiUploadService extends AbstractHttpService implements Service,
}
@Override
- public void login() throws IOException {
+ public AccountDetails login() throws IOException {
final HTMLPage page = post("http://www.multiupload.com/login")
.parameter("username", credential.getUsername())
.parameter("password", credential.getPassword()).asPage();
if (!page.containsIgnoreCase(credential.getUsername()))
throw new AuthenticationInvalidCredentialException();
- serviceMode = ServiceMode.NON_PREMIUM;
+ return (account = new AccountDetailsImpl(credential.getUsername()));
}
@Override
@@ -299,4 +308,21 @@ public class MultiUploadService extends AbstractHttpService implements Service,
// TODO check logout status
}
}
+
+ private class AccountDetailsImpl extends AbstractAccountDetails implements
+ PremiumAccountDetails {
+ /**
+ * @param username
+ * the username
+ */
+ public AccountDetailsImpl(String username) {
+ super(MultiUploadService.this, username);
+ }
+
+ @Override
+ public boolean isPremium() {
+ // TODO implement this
+ return false;
+ }
+ }
}
diff --git a/httpchannel-service/httpchannel-service-uploadhere/src/main/java/com/rogiel/httpchannel/service/uploadhere/UploadHereService.java b/httpchannel-service/httpchannel-service-uploadhere/src/main/java/com/rogiel/httpchannel/service/uploadhere/UploadHereService.java
index 8504e84..12f78ba 100644
--- a/httpchannel-service/httpchannel-service-uploadhere/src/main/java/com/rogiel/httpchannel/service/uploadhere/UploadHereService.java
+++ b/httpchannel-service/httpchannel-service-uploadhere/src/main/java/com/rogiel/httpchannel/service/uploadhere/UploadHereService.java
@@ -26,10 +26,13 @@ import java.util.regex.Pattern;
import com.rogiel.httpchannel.captcha.ImageCaptcha;
import com.rogiel.httpchannel.captcha.ReCaptchaExtractor;
+import com.rogiel.httpchannel.service.AbstractAccountDetails;
import com.rogiel.httpchannel.service.AbstractAuthenticator;
import com.rogiel.httpchannel.service.AbstractHttpDownloader;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
+import com.rogiel.httpchannel.service.AccountDetails;
+import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
@@ -191,7 +194,12 @@ public class UploadHereService extends AbstractHttpService implements Service,
@Override
public CapabilityMatrix getAuthenticationCapability() {
- return new CapabilityMatrix();
+ return new CapabilityMatrix(AuthenticatorCapability.ACCOUNT_DETAILS);
+ }
+
+ @Override
+ public AccountDetails getAccountDetails() {
+ return account;
}
protected class UploaderImpl extends
@@ -300,14 +308,14 @@ public class UploadHereService extends AbstractHttpService implements Service,
}
@Override
- public void login() throws IOException {
+ public AccountDetails login() throws IOException {
final HTMLPage page = post("http://www.uploadhere.com/login")
.parameter("do", "login")
.parameter("username", credential.getUsername())
.parameter("password", credential.getPassword()).asPage();
if (page.contains(INVALID_LOGIN_STRING))
throw new AuthenticationInvalidCredentialException();
- serviceMode = ServiceMode.NON_PREMIUM;
+ return (account = new AccountDetailsImpl(credential.getUsername()));
}
@Override
@@ -317,4 +325,21 @@ public class UploadHereService extends AbstractHttpService implements Service,
// TODO check logout status
}
}
+
+ private class AccountDetailsImpl extends AbstractAccountDetails implements
+ PremiumAccountDetails {
+ /**
+ * @param username
+ * the username
+ */
+ public AccountDetailsImpl(String username) {
+ super(UploadHereService.this, username);
+ }
+
+ @Override
+ public boolean isPremium() {
+ // TODO implement this
+ return false;
+ }
+ }
}
diff --git a/httpchannel-service/httpchannel-service-uploadking/src/main/java/com/rogiel/httpchannel/service/uploadking/UploadKingService.java b/httpchannel-service/httpchannel-service-uploadking/src/main/java/com/rogiel/httpchannel/service/uploadking/UploadKingService.java
index dc995e1..c8ca826 100644
--- a/httpchannel-service/httpchannel-service-uploadking/src/main/java/com/rogiel/httpchannel/service/uploadking/UploadKingService.java
+++ b/httpchannel-service/httpchannel-service-uploadking/src/main/java/com/rogiel/httpchannel/service/uploadking/UploadKingService.java
@@ -26,10 +26,13 @@ import java.util.regex.Pattern;
import com.rogiel.httpchannel.captcha.ImageCaptcha;
import com.rogiel.httpchannel.captcha.ReCaptchaExtractor;
+import com.rogiel.httpchannel.service.AbstractAccountDetails;
import com.rogiel.httpchannel.service.AbstractAuthenticator;
import com.rogiel.httpchannel.service.AbstractHttpDownloader;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
+import com.rogiel.httpchannel.service.AccountDetails;
+import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
@@ -191,7 +194,12 @@ public class UploadKingService extends AbstractHttpService implements Service,
@Override
public CapabilityMatrix getAuthenticationCapability() {
- return new CapabilityMatrix();
+ return new CapabilityMatrix(AuthenticatorCapability.ACCOUNT_DETAILS);
+ }
+
+ @Override
+ public AccountDetails getAccountDetails() {
+ return account;
}
protected class UploaderImpl extends
@@ -297,14 +305,14 @@ public class UploadKingService extends AbstractHttpService implements Service,
}
@Override
- public void login() throws IOException {
+ public AccountDetails login() throws IOException {
final HTMLPage page = post("http://www.uploadking.com/login")
.parameter("do", "login")
.parameter("username", credential.getUsername())
.parameter("password", credential.getPassword()).asPage();
if (page.contains(INVALID_LOGIN_STRING))
throw new AuthenticationInvalidCredentialException();
- serviceMode = ServiceMode.NON_PREMIUM;
+ return (account = new AccountDetailsImpl(credential.getUsername()));
}
@Override
@@ -314,4 +322,21 @@ public class UploadKingService extends AbstractHttpService implements Service,
// TODO check logout status
}
}
+
+ private class AccountDetailsImpl extends AbstractAccountDetails implements
+ PremiumAccountDetails {
+ /**
+ * @param username
+ * the username
+ */
+ public AccountDetailsImpl(String username) {
+ super(UploadKingService.this, username);
+ }
+
+ @Override
+ public boolean isPremium() {
+ // TODO implement this
+ return false;
+ }
+ }
}
diff --git a/httpchannel-service/httpchannel-service-wupload/src/main/java/com/rogiel/httpchannel/service/wupload/WUploadService.java b/httpchannel-service/httpchannel-service-wupload/src/main/java/com/rogiel/httpchannel/service/wupload/WUploadService.java
index 1f860c2..b854ceb 100644
--- a/httpchannel-service/httpchannel-service-wupload/src/main/java/com/rogiel/httpchannel/service/wupload/WUploadService.java
+++ b/httpchannel-service/httpchannel-service-wupload/src/main/java/com/rogiel/httpchannel/service/wupload/WUploadService.java
@@ -23,9 +23,12 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.regex.Pattern;
+import com.rogiel.httpchannel.service.AbstractAccountDetails;
import com.rogiel.httpchannel.service.AbstractAuthenticator;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
+import com.rogiel.httpchannel.service.AccountDetails;
+import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
@@ -146,7 +149,13 @@ public class WUploadService extends AbstractHttpService implements Service,
@Override
public CapabilityMatrix getAuthenticationCapability() {
- return new CapabilityMatrix();
+ return new CapabilityMatrix(
+ AuthenticatorCapability.ACCOUNT_DETAILS);
+ }
+
+ @Override
+ public AccountDetails getAccountDetails() {
+ return account;
}
protected class UploaderImpl extends
@@ -191,10 +200,10 @@ public class WUploadService extends AbstractHttpService implements Service,
}
@Override
- public void login() throws IOException {
+ public AccountDetails login() throws IOException {
logger.debug("Logging to wupload.com");
api.login(credential.getUsername(), credential.getPassword());
- serviceMode = ServiceMode.NON_PREMIUM;
+ return (account = new AccountDetailsImpl(credential.getUsername()));
}
@Override
@@ -203,6 +212,23 @@ public class WUploadService extends AbstractHttpService implements Service,
}
}
+ private class AccountDetailsImpl extends AbstractAccountDetails implements
+ PremiumAccountDetails {
+ /**
+ * @param username
+ * the username
+ */
+ public AccountDetailsImpl(String username) {
+ super(WUploadService.this, username);
+ }
+
+ @Override
+ public boolean isPremium() {
+ // TODO implement this
+ return false;
+ }
+ }
+
@Override
public String toString() {
return this.getClass().getSimpleName() + " " + getMajorVersion() + "."
diff --git a/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractAccountDetails.java b/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractAccountDetails.java
new file mode 100644
index 0000000..664d539
--- /dev/null
+++ b/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractAccountDetails.java
@@ -0,0 +1,46 @@
+/**
+ *
+ */
+package com.rogiel.httpchannel.service;
+
+/**
+ * @author Rogiel
+ *
+ */
+public class AbstractAccountDetails implements AccountDetails {
+ protected final String username;
+ protected final AuthenticationService> service;
+
+ public AbstractAccountDetails(AuthenticationService> service,
+ String username) {
+ this.service = service;
+ this.username = username;
+ }
+
+ @Override
+ public String getUsername() {
+ return username;
+ }
+
+ @Override
+ public AuthenticationService> getService() {
+ return service;
+ }
+
+ @Override
+ public boolean is(Class extends AccountDetails> type) {
+ return type.isAssignableFrom(this.getClass());
+ }
+
+ @Override
+ public T as(Class type) {
+ if (!is(type))
+ return null;
+ return type.cast(this);
+ }
+
+ @Override
+ public boolean isActive() {
+ return true;
+ }
+}