mirror of
https://github.com/Rogiel/httpchannel
synced 2025-12-05 23:22:51 +00:00
Modularize in maven projects the httpchannel library
This commit creates several maven modules for each segment of the library. Now it is possible to include only individual services to the classpath instead of the full library.
This commit is contained in:
10
httpchannel-api/pom.xml
Normal file
10
httpchannel-api/pom.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>httpchannel</artifactId>
|
||||
<groupId>com.rogiel.httpchannel</groupId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>httpchannel-api</artifactId>
|
||||
</project>
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service;
|
||||
|
||||
import com.rogiel.httpchannel.service.config.ServiceConfiguration;
|
||||
|
||||
/**
|
||||
* This is an abstract {@link Service} implementation.
|
||||
*
|
||||
* @author Rogiel
|
||||
* @version 1.0
|
||||
* @param <T>
|
||||
* The {@link ServiceConfiguration} <b>interface</b> type used by the
|
||||
* {@link Service}. Note that this <b>must</b> be an interface!s
|
||||
* @see ServiceConfiguration ServiceConfiguration for details on the configuration interface.
|
||||
*/
|
||||
public abstract class AbstractService<T extends ServiceConfiguration>
|
||||
implements Service {
|
||||
protected final T configuration;
|
||||
|
||||
protected AbstractService(T configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getServiceConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service;
|
||||
|
||||
/**
|
||||
* Implements an service capable of authenticating into an account.
|
||||
*
|
||||
* @author Rogiel
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface AuthenticationService extends Service {
|
||||
/**
|
||||
* Creates {@link Authenticator} instance for this service. This instance is
|
||||
* attached to an {@link Credential} and to its parent {@link Service}.
|
||||
*
|
||||
* @param credential
|
||||
* the credential
|
||||
* @return an new {@link Authenticator} instance
|
||||
*/
|
||||
Authenticator getAuthenticator(Credential credential);
|
||||
|
||||
/**
|
||||
* Return the matrix of capabilities for this {@link Authenticator}.
|
||||
*
|
||||
* @return {@link CapabilityMatrix} with all capabilities of this
|
||||
* {@link Authenticator}.
|
||||
* @see AuthenticatorCapability
|
||||
*/
|
||||
CapabilityMatrix<AuthenticatorCapability> getAuthenticationCapability();
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.rogiel.httpchannel.service.exception.AuthenticationInvalidCredentialException;
|
||||
|
||||
/**
|
||||
* This interfaces provides authentication for an service.
|
||||
*
|
||||
* @author Rogiel
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface Authenticator {
|
||||
/**
|
||||
* Login into the {@link Service}. Once the authentication is done, it is
|
||||
* persistent for the entire service's operation.<br>
|
||||
* <b>Note</b>: If you want to logout the user, see
|
||||
* {@link Authenticator#logout()}
|
||||
*
|
||||
* @throws IOException
|
||||
* if any IO error occur
|
||||
* @throws AuthenticationInvalidCredentialException
|
||||
* if the credentials are not valid or cannot be used
|
||||
*/
|
||||
void login() throws IOException, AuthenticationInvalidCredentialException;
|
||||
|
||||
/**
|
||||
* Logout into the {@link Service}. The session is restored to an not
|
||||
* logged-in state.
|
||||
*
|
||||
* @throws IOException
|
||||
* if any IO error occur
|
||||
*/
|
||||
void logout() throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service;
|
||||
|
||||
/**
|
||||
* Capability an certain {@link Authenticator} can have.
|
||||
*
|
||||
* @author Rogiel
|
||||
* @since 1.0
|
||||
*/
|
||||
public enum AuthenticatorCapability {
|
||||
/**
|
||||
* Mark an {@link Authenticator} capable of fetching account information.
|
||||
*/
|
||||
FETCH_ACCOUNT_INFORMATION;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service;
|
||||
|
||||
/**
|
||||
* This is an utility class to help manage Capabilities of all the services.
|
||||
*
|
||||
* @author Rogiel
|
||||
* @param <T>
|
||||
* the capability enumeration
|
||||
* @since 1.0
|
||||
*/
|
||||
public class CapabilityMatrix<T> {
|
||||
/**
|
||||
* The list of all supported capabilities
|
||||
*/
|
||||
private final T[] matrix;
|
||||
|
||||
/**
|
||||
* Creates a new matrix of capabilities
|
||||
*
|
||||
* @param matrix
|
||||
* all the capabilities this service support
|
||||
*/
|
||||
@SafeVarargs
|
||||
public CapabilityMatrix(T... matrix) {
|
||||
this.matrix = matrix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether an certatin capability is in the matrix or not.
|
||||
*
|
||||
* @param capability
|
||||
* the capability being searched in the matrix
|
||||
* @return true if existent, false otherwise
|
||||
*/
|
||||
public boolean has(T capability) {
|
||||
for (final T capScan : matrix) {
|
||||
if (capScan == capability) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service;
|
||||
|
||||
/**
|
||||
* Pair of username-password used for authenticating into services.
|
||||
*
|
||||
* @author Rogiel
|
||||
* @since 1.0
|
||||
*/
|
||||
public class Credential {
|
||||
private final String username;
|
||||
private final String password;
|
||||
|
||||
/**
|
||||
* Creates a new pair of username-password credential
|
||||
*
|
||||
* @param username
|
||||
* the username
|
||||
* @param password
|
||||
* the password
|
||||
*/
|
||||
public Credential(String username, String password) {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the username
|
||||
*
|
||||
* @return the username
|
||||
*/
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the password
|
||||
*
|
||||
* @return the password
|
||||
*/
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service;
|
||||
|
||||
import java.nio.channels.Channel;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
|
||||
/**
|
||||
* This is an {@link Channel} for downloads. Any data to be downloaded, must be
|
||||
* Redden from this channel.
|
||||
* <p>
|
||||
* Since this {@link Channel} <tt>implements</tt> {@link ReadableByteChannel}
|
||||
* you can treat it as any other regular IO {@link Channel}.
|
||||
* <p>
|
||||
* <b>Remember</b>: always close the {@link Channel}, if you do otherwise, the
|
||||
* resources will not be freed and will consume machine resources.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface DownloadChannel extends ReadableByteChannel {
|
||||
/**
|
||||
* @return the file size
|
||||
*/
|
||||
long getFilesize();
|
||||
|
||||
/**
|
||||
* @return the file name
|
||||
*/
|
||||
String getFilename();
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service;
|
||||
|
||||
/**
|
||||
* This listener keeps an track on the progress on an {@link Downloader}
|
||||
* service.
|
||||
*
|
||||
* @author Rogiel
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface DownloadListener {
|
||||
/**
|
||||
* Inform that the downloader will be waiting for an certain amount of time
|
||||
* due to an timer in the download site.
|
||||
*
|
||||
* @param time
|
||||
* the time in ms in which the service will be be waiting.
|
||||
* @return true if desires to wait, false otherwise
|
||||
*/
|
||||
boolean timer(long time);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import javax.tools.FileObject;
|
||||
|
||||
/**
|
||||
* Implements an service capable of downloading a file.
|
||||
*
|
||||
* @author Rogiel
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface DownloadService extends Service {
|
||||
/**
|
||||
* Creates a new instance of the {@link Downloader}. This instance will be
|
||||
* attached to the {@link URL}, {@link FileObject} provided through the the
|
||||
* arguments and the parent {@link Service} instance.
|
||||
*
|
||||
* @param url
|
||||
* the url to be downloaded
|
||||
* @param file
|
||||
* the destination file
|
||||
* @return an new instance of {@link Downloader}
|
||||
*/
|
||||
Downloader getDownloader(URL url);
|
||||
|
||||
/**
|
||||
* Check if this {@link Service} can download from this URL. Implemtations
|
||||
* might or might not perform network activity.
|
||||
* <p>
|
||||
* <b>Please note</b> that the value returned by this method may vary based
|
||||
* on it's state (i.e. premium or not).
|
||||
*
|
||||
* @param url
|
||||
* the {@link URL} to be tested.
|
||||
* @return true if supported, false otherwise.
|
||||
*/
|
||||
boolean matchURL(URL url);
|
||||
|
||||
/**
|
||||
* Return the matrix of capabilities for this {@link Downloader}.
|
||||
*
|
||||
* @return {@link CapabilityMatrix} with all capabilities of this
|
||||
* {@link Downloader}.
|
||||
* @see DownloaderCapability
|
||||
*/
|
||||
CapabilityMatrix<DownloaderCapability> getDownloadCapabilities();
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.rogiel.httpchannel.service.exception.DownloadLimitExceededException;
|
||||
import com.rogiel.httpchannel.service.exception.DownloadLinkNotFoundException;
|
||||
|
||||
/**
|
||||
* This interfaces provides downloading for an service.
|
||||
*
|
||||
* @author Rogiel
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface Downloader {
|
||||
/**
|
||||
* Starts the download process.
|
||||
*
|
||||
* @param listener
|
||||
* the listener to keep a track on the download progress
|
||||
* @param position
|
||||
* the download start position. If seek is supported by service.
|
||||
*
|
||||
* @return the {@link DownloadChannel} instance
|
||||
* @throws IOException
|
||||
* if any IO error occur
|
||||
* @throws DownloadLinkNotFoundException
|
||||
* if the direct download link cannot be found (the file could
|
||||
* have been deleted)
|
||||
* @throws DownloadLimitExceededException
|
||||
* if the download limit has been exceed, most times thrown when
|
||||
* downloading as a non-premium user
|
||||
*/
|
||||
DownloadChannel download(DownloadListener listener, long position)
|
||||
throws IOException, DownloadLinkNotFoundException,
|
||||
DownloadLimitExceededException;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service;
|
||||
|
||||
/**
|
||||
* Capability an certain {@link Downloader} can have.
|
||||
*
|
||||
* @author Rogiel
|
||||
* @since 1.0
|
||||
*/
|
||||
public enum DownloaderCapability {
|
||||
/**
|
||||
* Can download files while not authenticated
|
||||
*/
|
||||
UNAUTHENTICATED_DOWNLOAD,
|
||||
/**
|
||||
* Can download files while authenticated with non-premium account
|
||||
*/
|
||||
NON_PREMIUM_ACCOUNT_DOWNLOAD,
|
||||
/**
|
||||
* Can download files while authenticated with premium account
|
||||
*/
|
||||
PREMIUM_ACCOUNT_DOWNLOAD,
|
||||
/**
|
||||
* Resume interrupted downloads are possible and supported.
|
||||
*/
|
||||
RESUME,
|
||||
/**
|
||||
* Can check the status of the given link before starting download.
|
||||
*/
|
||||
STATUS_CHECK;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service;
|
||||
|
||||
import com.rogiel.httpchannel.service.config.ServiceConfiguration;
|
||||
|
||||
/**
|
||||
* Base interface for all the services. Whenever the operation suported by the
|
||||
* {@link Service} it must implement this interface. Most of implementations
|
||||
* will benefit from abstract instances of this interface:
|
||||
* <ul>
|
||||
* <li>{@link AbstractHttpService}: provides an basic support for HTTP services.
|
||||
* </li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Rogiel
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface Service {
|
||||
/**
|
||||
* Get the ServiceID.
|
||||
*
|
||||
* @return the id of the service
|
||||
*/
|
||||
String getID();
|
||||
|
||||
/**
|
||||
* Get Major version of this service
|
||||
*
|
||||
* @return the major version
|
||||
*/
|
||||
int getMajorVersion();
|
||||
|
||||
/**
|
||||
* Get the minor version of this service
|
||||
*
|
||||
* @return the minor version
|
||||
*/
|
||||
int getMinorVersion();
|
||||
|
||||
/**
|
||||
* Returns this {@link ServiceConfiguration} instance
|
||||
*
|
||||
* @return the {@link ServiceConfiguration} instance
|
||||
*/
|
||||
ServiceConfiguration getServiceConfiguration();
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class ServiceHelper {
|
||||
private final Service service;
|
||||
|
||||
/**
|
||||
* @param service
|
||||
* the service
|
||||
*/
|
||||
public ServiceHelper(Service service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
public UploadChannel upload(Path path, String description)
|
||||
throws IOException {
|
||||
return ((UploadService) service).getUploader(
|
||||
path.getFileName().toString(), Files.size(path), description)
|
||||
.upload();
|
||||
}
|
||||
|
||||
public UploadChannel upload(File file, String description)
|
||||
throws IOException {
|
||||
return ((UploadService) service).getUploader(file.getName(),
|
||||
file.length(), description).upload();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.Channel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
|
||||
import com.rogiel.httpchannel.service.exception.UploadLinkNotFoundException;
|
||||
|
||||
/**
|
||||
* This is an {@link Channel} for uploads. Any data to be uploaded, must be
|
||||
* written into this channel.
|
||||
* <p>
|
||||
* Since this {@link Channel} <tt>implements</tt> {@link WritableByteChannel}
|
||||
* you can treat it as any other regular IO {@link Channel}.
|
||||
* <p>
|
||||
* <b>Remember</b>: always close the {@link Channel}, if you do otherwise, your
|
||||
* upload will not finish and will never return the link.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface UploadChannel extends WritableByteChannel {
|
||||
/**
|
||||
* @return the file size
|
||||
*/
|
||||
long getFilesize();
|
||||
|
||||
/**
|
||||
* @return the file name
|
||||
*/
|
||||
String getFilename();
|
||||
|
||||
/**
|
||||
* The link is located after you call {@link UploadChannel#close()}, but it
|
||||
* can only be retrieved by calling this method. If {@link #close()} throwed
|
||||
* an exception, this method might return <tt>null</tt>.
|
||||
*
|
||||
* @return the download link for this upload
|
||||
*/
|
||||
String getDownloadLink();
|
||||
|
||||
/**
|
||||
* @throws UploadLinkNotFoundException
|
||||
* if after the upload, the download link cannot be found
|
||||
*/
|
||||
@Override
|
||||
void close() throws IOException, UploadLinkNotFoundException;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service;
|
||||
|
||||
/**
|
||||
* Implements an service capable of uploading a file.
|
||||
*
|
||||
* @author Rogiel
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface UploadService extends Service {
|
||||
/**
|
||||
* Creates a new instance of {@link Uploader}. This instance is attached
|
||||
* with the parent {@link Service} instance.<br>
|
||||
* <b>Note</b>: not all services might support <tt>description</tt>
|
||||
*
|
||||
* @param filename
|
||||
* the name of the file to be uploaded
|
||||
* @param filesize
|
||||
* the size of the file to be uploaded. This must be exact.
|
||||
* @param description
|
||||
* the description of the upload. If supported.
|
||||
* @return the new {@link Uploader} instance
|
||||
*/
|
||||
Uploader getUploader(String filename, long filesize, String description);
|
||||
|
||||
/**
|
||||
* Get the maximum upload file size supported by this service.
|
||||
* <p>
|
||||
* <b>Please note</b> that the value returned by this method may vary based
|
||||
* on it's state (i.e. premium or not).
|
||||
*
|
||||
* @return the maximum filesize supported
|
||||
*/
|
||||
long getMaximumFilesize();
|
||||
|
||||
/**
|
||||
* Get the list of all supported extensions. Might return <tt>null</tt> if
|
||||
* there is no restriction.
|
||||
* <p>
|
||||
* <b>Please note</b> that the value returned by this method may vary based
|
||||
* on it's state (i.e. premium or not).
|
||||
*
|
||||
* @return the list of supported file extensions. Can return <tt>null</tt>
|
||||
* if there is not restriction
|
||||
*/
|
||||
String[] getSupportedExtensions();
|
||||
|
||||
/**
|
||||
* Return the matrix of capabilities for this {@link Uploader}.
|
||||
*
|
||||
* @return {@link CapabilityMatrix} with all capabilities of this
|
||||
* {@link Uploader}.
|
||||
* @see UploaderCapability
|
||||
*/
|
||||
CapabilityMatrix<UploaderCapability> getUploadCapabilities();
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* This interfaces provides uploading for an service.
|
||||
*
|
||||
* @author Rogiel
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface Uploader {
|
||||
/**
|
||||
* Starts the upload process on this service.
|
||||
*
|
||||
* @return the {@link UploadChannel} instance
|
||||
* @throws IOException
|
||||
* if any IO error occur
|
||||
*/
|
||||
UploadChannel upload() throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service;
|
||||
|
||||
/**
|
||||
* Capability an certain {@link Uploader} can have.
|
||||
*
|
||||
* @author Rogiel
|
||||
* @since 1.0
|
||||
*/
|
||||
public enum UploaderCapability {
|
||||
/**
|
||||
* Can upload while not authenticated into any account
|
||||
*/
|
||||
UNAUTHENTICATED_UPLOAD,
|
||||
/**
|
||||
* Can upload while authenticated with a non-premium account
|
||||
*/
|
||||
NON_PREMIUM_ACCOUNT_UPLOAD,
|
||||
/**
|
||||
* Can upload while authenticated with a premium account
|
||||
*/
|
||||
PREMIUM_ACCOUNT_UPLOAD;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.captcha;
|
||||
|
||||
/**
|
||||
* @author Rogiel
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface Captcha {
|
||||
String getAnswer();
|
||||
void setAnswer(String answer);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.captcha;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public interface CaptchaResolver {
|
||||
/**
|
||||
* Passes an captcha by parameter and waits for the response of the
|
||||
* challenge.
|
||||
*
|
||||
* @param captcha
|
||||
* the captcha challenge
|
||||
*/
|
||||
String resolve(Captcha captcha);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.captcha;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* @author Rogiel
|
||||
* @since 1.0
|
||||
*/
|
||||
public class ImageCaptcha implements Captcha {
|
||||
private URL url;
|
||||
|
||||
private String answer;
|
||||
|
||||
public URL getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(URL url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAnswer() {
|
||||
return answer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAnswer(String answer) {
|
||||
this.answer = answer;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.channel;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
|
||||
import com.rogiel.httpchannel.service.DownloadChannel;
|
||||
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public class InputStreamDownloadChannel implements DownloadChannel {
|
||||
private final ReadableByteChannel channel;
|
||||
|
||||
private final long length;
|
||||
private final String filename;
|
||||
|
||||
public InputStreamDownloadChannel(InputStream in, final long length,
|
||||
final String filename) {
|
||||
this.channel = Channels.newChannel(in);
|
||||
this.length = length;
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(ByteBuffer dst) throws IOException {
|
||||
return channel.read(dst);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen() {
|
||||
return channel.isOpen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
channel.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getFilesize() {
|
||||
return length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return filename;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.channel;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
|
||||
import com.rogiel.httpchannel.service.UploadChannel;
|
||||
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public class LinkedUploadChannel implements UploadChannel {
|
||||
private WritableByteChannel channel;
|
||||
private final LinkedUploadChannelCloseCallback closeCallback;
|
||||
|
||||
private final long length;
|
||||
private final String filename;
|
||||
private String downloadLink;
|
||||
|
||||
private boolean open = true;
|
||||
|
||||
public LinkedUploadChannel(LinkedUploadChannelCloseCallback closeCallback,
|
||||
long filesize, String filename) {
|
||||
this.closeCallback = closeCallback;
|
||||
this.filename = filename;
|
||||
this.length = filesize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int write(ByteBuffer src) throws IOException {
|
||||
if (channel == null)
|
||||
throw new IOException("Channel is not linked yet");
|
||||
return channel.write(src);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen() {
|
||||
return (channel != null ? channel.isOpen() : true) && open;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
open = false;
|
||||
downloadLink = closeCallback.finish();
|
||||
}
|
||||
|
||||
public interface LinkedUploadChannelCloseCallback {
|
||||
String finish() throws IOException;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getFilesize() {
|
||||
return length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return filename;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDownloadLink() {
|
||||
return downloadLink;
|
||||
}
|
||||
|
||||
public void linkChannel(WritableByteChannel channel) throws IOException {
|
||||
if(this.channel != null)
|
||||
throw new IOException("This channel is already linked.");
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
public boolean isLinked() {
|
||||
return channel != null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.channel;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
|
||||
import org.apache.http.entity.mime.content.AbstractContentBody;
|
||||
import org.apache.http.entity.mime.content.ContentBody;
|
||||
|
||||
import com.rogiel.httpchannel.service.Uploader;
|
||||
|
||||
/**
|
||||
* {@link ContentBody} used to upload files in {@link Uploader} implementations.
|
||||
*
|
||||
* @author Rogiel
|
||||
* @since 1.0
|
||||
*/
|
||||
public class LinkedUploadChannelContentBody extends AbstractContentBody {
|
||||
private final LinkedUploadChannel channel;
|
||||
|
||||
public LinkedUploadChannelContentBody(LinkedUploadChannel channel) {
|
||||
super("application/octet-stream");
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return channel.getFilename();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(OutputStream out) throws IOException {
|
||||
final WritableByteChannel outputChannel = Channels.newChannel(out);
|
||||
channel.linkChannel(outputChannel);
|
||||
|
||||
while (channel.isOpen() && outputChannel.isOpen()) {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCharset() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getContentLength() {
|
||||
return channel.getFilesize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTransferEncoding() {
|
||||
return "binary";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.config;
|
||||
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
import com.rogiel.httpchannel.util.transformer.Transformer;
|
||||
|
||||
|
||||
/**
|
||||
* This is an flag interface to indicate that an certain Interface is the
|
||||
* configuration for the service.<br>
|
||||
* <br>
|
||||
* Every service must create an <tt>interface</tt> with the configuration
|
||||
* methods, additionally an Annotation informing the default value.
|
||||
* ServiceConfiguration implementations might use reflection ({@link Proxy}),
|
||||
* hard-coding or any other way for fetching the data.<br>
|
||||
* <br>
|
||||
* String data stored in the annotation is converted to Java Types using the
|
||||
* {@link Transformer} class.
|
||||
*
|
||||
* @author Rogiel
|
||||
* @version 1.0
|
||||
* @see Transformer
|
||||
*/
|
||||
public interface ServiceConfiguration {
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.rogiel.httpchannel.util.transformer.TransformerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* Helper class for {@link ServiceConfiguration} system.
|
||||
*
|
||||
* @author Rogiel
|
||||
* @since 1.0
|
||||
*/
|
||||
public class ServiceConfigurationHelper {
|
||||
/**
|
||||
* Creates a Proxy Class that returns all the default values of
|
||||
* configuration interfaces. The values are mapped by
|
||||
* {@link ServiceConfigurationProperty} annotation.
|
||||
*
|
||||
* @param <T>
|
||||
* the interface extending {@link ServiceConfiguration}. Service
|
||||
* specific.
|
||||
* @param type
|
||||
* the type Class representing T.
|
||||
* @return the proxied {@link ServiceConfiguration} instance.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends ServiceConfiguration> T defaultConfiguration(
|
||||
Class<T> type) {
|
||||
return (T) Proxy.newProxyInstance(
|
||||
ServiceConfiguration.class.getClassLoader(),
|
||||
new Class<?>[] { type }, new InvocationHandler() {
|
||||
@Override
|
||||
public Object invoke(Object object, Method method,
|
||||
Object[] arguments) throws Throwable {
|
||||
final ServiceConfigurationProperty property = method
|
||||
.getAnnotation(ServiceConfigurationProperty.class);
|
||||
if (property != null)
|
||||
return TransformerFactory.getTransformer(
|
||||
method.getReturnType()).transform(
|
||||
property.defaultValue());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Proxy Class that returns all the default values of
|
||||
* configuration interfaces. The values are mapped by
|
||||
* {@link ServiceConfigurationProperty} annotation.
|
||||
*
|
||||
* @param <T>
|
||||
* the interface extending {@link ServiceConfiguration}. Service
|
||||
* specific.
|
||||
* @param type
|
||||
* the type Class representing T.
|
||||
* @return the proxied {@link ServiceConfiguration} instance.
|
||||
* @throws IOException
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends ServiceConfiguration> T file(Class<T> type,
|
||||
File file) throws FileNotFoundException, IOException {
|
||||
final Properties properties = new Properties();
|
||||
properties.load(new FileInputStream(file));
|
||||
|
||||
return (T) Proxy.newProxyInstance(
|
||||
ServiceConfiguration.class.getClassLoader(),
|
||||
new Class<?>[] { type }, new InvocationHandler() {
|
||||
@Override
|
||||
public Object invoke(Object object, Method method,
|
||||
Object[] arguments) throws Throwable {
|
||||
final ServiceConfigurationProperty property = method
|
||||
.getAnnotation(ServiceConfigurationProperty.class);
|
||||
if (property != null)
|
||||
return TransformerFactory.getTransformer(
|
||||
method.getReturnType()).transform(
|
||||
get(property));
|
||||
return null;
|
||||
}
|
||||
|
||||
private String get(ServiceConfigurationProperty property) {
|
||||
String value = properties.getProperty(property.key());
|
||||
if (value == null)
|
||||
value = property.defaultValue();
|
||||
return value;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.config;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Annotation that defines the default value for an {@link ServiceConfiguration}
|
||||
* method.<br>
|
||||
* <br>
|
||||
* <h1>Usage example</h1>
|
||||
*
|
||||
* <pre>
|
||||
* public interface DummyServiceConfiguration extends ServiceConfiguration {
|
||||
* @ServiceConfigurationProperty(defaultValue = "true")
|
||||
* boolean retryAllowed();
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* The default implementation created by
|
||||
* {@link ServiceConfigurationHelper#defaultConfiguration()} will always return
|
||||
* the <tt>defaultValue</tt>.
|
||||
*
|
||||
* @author Rogiel
|
||||
* @version 1.0
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
@Documented
|
||||
public @interface ServiceConfigurationProperty {
|
||||
String key();
|
||||
String defaultValue();
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.exception;
|
||||
|
||||
/**
|
||||
* Exception thrown if the authentication credential is not valid.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class AuthenticationInvalidCredentialException extends
|
||||
AuthenticationServiceException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Creates a new empty instance of this exception
|
||||
*/
|
||||
public AuthenticationInvalidCredentialException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* the message
|
||||
* @param cause
|
||||
* the root cause
|
||||
*/
|
||||
public AuthenticationInvalidCredentialException(String message,
|
||||
Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* the message
|
||||
*/
|
||||
public AuthenticationInvalidCredentialException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cause
|
||||
* the root cause
|
||||
*/
|
||||
public AuthenticationInvalidCredentialException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.exception;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public class AuthenticationServiceException extends ChannelServiceException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public AuthenticationServiceException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* @param cause
|
||||
*/
|
||||
public AuthenticationServiceException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
*/
|
||||
public AuthenticationServiceException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cause
|
||||
*/
|
||||
public AuthenticationServiceException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.exception;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public class ChannelServiceException extends IOException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ChannelServiceException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* @param cause
|
||||
*/
|
||||
public ChannelServiceException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
*/
|
||||
public ChannelServiceException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cause
|
||||
*/
|
||||
public ChannelServiceException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.exception;
|
||||
|
||||
import com.rogiel.httpchannel.service.captcha.CaptchaResolver;
|
||||
|
||||
/**
|
||||
* Exception thrown if the {@link CaptchaResolver} has returned an invalid
|
||||
* captcha
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class DownloadInvalidCaptchaException extends DownloadServiceException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Creates a new empty instance of this exception
|
||||
*/
|
||||
public DownloadInvalidCaptchaException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* the message
|
||||
* @param cause
|
||||
* the root cause
|
||||
*/
|
||||
public DownloadInvalidCaptchaException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* the message
|
||||
*/
|
||||
public DownloadInvalidCaptchaException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cause
|
||||
* the root cause
|
||||
*/
|
||||
public DownloadInvalidCaptchaException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.exception;
|
||||
|
||||
/**
|
||||
* Exception thrown if the download limit has been exceeded.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class DownloadLimitExceededException extends DownloadServiceException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Creates a new empty instance of this exception
|
||||
*/
|
||||
public DownloadLimitExceededException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* the message
|
||||
* @param cause
|
||||
* the root cause
|
||||
*/
|
||||
public DownloadLimitExceededException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* the message
|
||||
*/
|
||||
public DownloadLimitExceededException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cause
|
||||
* the root cause
|
||||
*/
|
||||
public DownloadLimitExceededException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.exception;
|
||||
|
||||
/**
|
||||
* Exception thrown if the direct download link could not be found.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class DownloadLinkNotFoundException extends DownloadServiceException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Creates a new empty instance of this exception
|
||||
*/
|
||||
public DownloadLinkNotFoundException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* the message
|
||||
* @param cause
|
||||
* the root cause
|
||||
*/
|
||||
public DownloadLinkNotFoundException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* the message
|
||||
*/
|
||||
public DownloadLinkNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cause
|
||||
* the root cause
|
||||
*/
|
||||
public DownloadLinkNotFoundException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.exception;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public class DownloadServiceException extends ChannelServiceException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public DownloadServiceException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* @param cause
|
||||
*/
|
||||
public DownloadServiceException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
*/
|
||||
public DownloadServiceException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cause
|
||||
*/
|
||||
public DownloadServiceException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.exception;
|
||||
|
||||
/**
|
||||
* Exception thrown if the download link could not be located after the upload.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class UploadLinkNotFoundException extends UploadServiceException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Creates a new empty instance of this exception
|
||||
*/
|
||||
public UploadLinkNotFoundException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* the message
|
||||
* @param cause
|
||||
* the root cause
|
||||
*/
|
||||
public UploadLinkNotFoundException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* the message
|
||||
*/
|
||||
public UploadLinkNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cause
|
||||
* the root cause
|
||||
*/
|
||||
public UploadLinkNotFoundException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.exception;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public class UploadServiceException extends ChannelServiceException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public UploadServiceException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* @param cause
|
||||
*/
|
||||
public UploadServiceException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
*/
|
||||
public UploadServiceException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cause
|
||||
*/
|
||||
public UploadServiceException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.util.transformer;
|
||||
|
||||
/**
|
||||
* @author Rogiel
|
||||
* @since 1.0
|
||||
*/
|
||||
public class TransformationException extends Exception {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public TransformationException() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* the message
|
||||
*/
|
||||
public TransformationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cause
|
||||
* the cause
|
||||
*/
|
||||
public TransformationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* the message
|
||||
* @param cause
|
||||
* the cause
|
||||
*/
|
||||
public TransformationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.util.transformer;
|
||||
|
||||
/**
|
||||
* @author rogiel
|
||||
*
|
||||
*/
|
||||
public interface Transformer<O> {
|
||||
O transform(String data) throws TransformationException;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.util.transformer;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import com.rogiel.httpchannel.util.transformer.impl.BooleanTransformer;
|
||||
import com.rogiel.httpchannel.util.transformer.impl.IntegerTransformer;
|
||||
import com.rogiel.httpchannel.util.transformer.impl.LongTransformer;
|
||||
import com.rogiel.httpchannel.util.transformer.impl.StringTransformer;
|
||||
import com.rogiel.httpchannel.util.transformer.impl.URLTransformer;
|
||||
|
||||
|
||||
/**
|
||||
* @author Rogiel
|
||||
* @since 1.0
|
||||
*/
|
||||
public class TransformerFactory {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> Transformer<T> getTransformer(Class<T> type) {
|
||||
if (String.class.isAssignableFrom(type)) {
|
||||
return (Transformer<T>) new StringTransformer();
|
||||
} else if (Boolean.class.isAssignableFrom(type) || type == Boolean.TYPE) {
|
||||
return (Transformer<T>) new BooleanTransformer();
|
||||
} else if (Integer.class.isAssignableFrom(type) || type == Integer.TYPE) {
|
||||
return (Transformer<T>) new IntegerTransformer();
|
||||
} else if (Long.class.isAssignableFrom(type) || type == Long.TYPE) {
|
||||
return (Transformer<T>) new LongTransformer();
|
||||
} else if (URL.class.isAssignableFrom(type)) {
|
||||
return (Transformer<T>) new URLTransformer();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.util.transformer.impl;
|
||||
|
||||
import com.rogiel.httpchannel.util.transformer.Transformer;
|
||||
|
||||
/**
|
||||
* @author rogiel
|
||||
*
|
||||
*/
|
||||
public class BooleanTransformer implements Transformer<Boolean> {
|
||||
@Override
|
||||
public Boolean transform(String data) {
|
||||
return Boolean.parseBoolean(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.util.transformer.impl;
|
||||
|
||||
import com.rogiel.httpchannel.util.transformer.Transformer;
|
||||
|
||||
/**
|
||||
* @author rogiel
|
||||
*
|
||||
*/
|
||||
public class IntegerTransformer implements Transformer<Integer> {
|
||||
@Override
|
||||
public Integer transform(String data) {
|
||||
return Integer.parseInt(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.util.transformer.impl;
|
||||
|
||||
import com.rogiel.httpchannel.util.transformer.Transformer;
|
||||
|
||||
/**
|
||||
* @author rogiel
|
||||
*
|
||||
*/
|
||||
public class LongTransformer implements Transformer<Long> {
|
||||
@Override
|
||||
public Long transform(String data) {
|
||||
return Long.parseLong(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.util.transformer.impl;
|
||||
|
||||
import com.rogiel.httpchannel.util.transformer.Transformer;
|
||||
|
||||
/**
|
||||
* @author rogiel
|
||||
*
|
||||
*/
|
||||
public class StringTransformer implements Transformer<String> {
|
||||
@Override
|
||||
public String transform(String data) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox 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 seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.util.transformer.impl;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import com.rogiel.httpchannel.util.transformer.TransformationException;
|
||||
import com.rogiel.httpchannel.util.transformer.Transformer;
|
||||
|
||||
|
||||
/**
|
||||
* @author rogiel
|
||||
*
|
||||
*/
|
||||
public class URLTransformer implements Transformer<URL> {
|
||||
@Override
|
||||
public URL transform(String data) throws TransformationException {
|
||||
try {
|
||||
return new URL(data);
|
||||
} catch (MalformedURLException e) {
|
||||
throw new TransformationException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user