204 lines
4.9 KiB
Java
204 lines
4.9 KiB
Java
/**
|
|
* Copyright (C) 2019-2021 Christian Pierre MOMON <cmomon@april.org>
|
|
*
|
|
* This file is part of (April) Hebdobot.
|
|
*
|
|
* Hebdobot is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Hebdobot 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 Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with Hebdobot. If not, see <http://www.gnu.org/licenses/>
|
|
*/
|
|
package org.april.hebdobot.privatebin;
|
|
|
|
import java.net.URL;
|
|
|
|
/**
|
|
* The Class PrivatebinSettings
|
|
*/
|
|
public class PrivatebinSettings
|
|
{
|
|
protected URL serverUrl;
|
|
protected Compression compression;
|
|
protected Expiration expiration;
|
|
protected BurnAfterReading burnAfterReading;
|
|
protected OpenDiscussion openDiscussion;
|
|
protected Formatter formatter;
|
|
protected String password;
|
|
|
|
/**
|
|
* Instantiates a new Privatebin settings.
|
|
*/
|
|
public PrivatebinSettings()
|
|
{
|
|
this.serverUrl = null;
|
|
this.compression = Compression.ZLIB;
|
|
this.expiration = Expiration.DAY_1;
|
|
this.burnAfterReading = BurnAfterReading.OFF;
|
|
this.openDiscussion = OpenDiscussion.OFF;
|
|
this.formatter = Formatter.PLAINTEXT;
|
|
this.password = "";
|
|
}
|
|
|
|
/**
|
|
* Instantiates a new privatebin settings.
|
|
*
|
|
* @param settings
|
|
* the settings
|
|
*/
|
|
public PrivatebinSettings(final PrivatebinSettings settings)
|
|
{
|
|
this.serverUrl = settings.serverUrl;
|
|
this.compression = settings.compression;
|
|
this.expiration = settings.expiration;
|
|
this.burnAfterReading = settings.burnAfterReading;
|
|
this.openDiscussion = settings.openDiscussion;
|
|
this.formatter = settings.formatter;
|
|
this.password = settings.password;
|
|
}
|
|
|
|
public BurnAfterReading getBurnAfterReading()
|
|
{
|
|
return this.burnAfterReading;
|
|
}
|
|
|
|
public Compression getCompression()
|
|
{
|
|
return this.compression;
|
|
}
|
|
|
|
public Expiration getExpiration()
|
|
{
|
|
return this.expiration;
|
|
}
|
|
|
|
public Formatter getFormatter()
|
|
{
|
|
return this.formatter;
|
|
}
|
|
|
|
public OpenDiscussion getOpenDiscussion()
|
|
{
|
|
return this.openDiscussion;
|
|
}
|
|
|
|
public String getPassword()
|
|
{
|
|
return this.password;
|
|
}
|
|
|
|
public URL getServerUrl()
|
|
{
|
|
return this.serverUrl;
|
|
}
|
|
|
|
/**
|
|
* Checks if is valid.
|
|
*
|
|
* @return true, if is valid
|
|
*/
|
|
public boolean isValid()
|
|
{
|
|
boolean result;
|
|
|
|
if (this.serverUrl == null)
|
|
{
|
|
result = false;
|
|
}
|
|
else if ((this.burnAfterReading == BurnAfterReading.ON) && (this.openDiscussion == OpenDiscussion.ON))
|
|
{
|
|
// Burn after reading cannot be active if opendiscussion is.
|
|
result = false;
|
|
}
|
|
else
|
|
{
|
|
result = true;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
public void setBurnAfterReading(final BurnAfterReading burnAfterReading)
|
|
{
|
|
if (burnAfterReading != null)
|
|
{
|
|
this.burnAfterReading = burnAfterReading;
|
|
}
|
|
}
|
|
|
|
public void setCompression(final Compression compression)
|
|
{
|
|
if (compression != null)
|
|
{
|
|
this.compression = compression;
|
|
}
|
|
}
|
|
|
|
public void setExpiration(final Expiration expiration)
|
|
{
|
|
if (expiration != null)
|
|
{
|
|
this.expiration = expiration;
|
|
}
|
|
}
|
|
|
|
public void setFormatter(final Formatter formatter)
|
|
{
|
|
if (formatter != null)
|
|
{
|
|
this.formatter = formatter;
|
|
}
|
|
}
|
|
|
|
public void setOpenDiscussion(final OpenDiscussion openDiscussion)
|
|
{
|
|
if (openDiscussion != null)
|
|
{
|
|
this.openDiscussion = openDiscussion;
|
|
}
|
|
}
|
|
|
|
public void setPassword(final String password)
|
|
{
|
|
if (password == null)
|
|
{
|
|
this.password = "";
|
|
}
|
|
else
|
|
{
|
|
this.password = password;
|
|
}
|
|
}
|
|
|
|
public void setServerUrl(final URL serverUrl)
|
|
{
|
|
this.serverUrl = serverUrl;
|
|
}
|
|
|
|
/**
|
|
* To string.
|
|
*
|
|
* @return the string
|
|
*/
|
|
@Override
|
|
public String toString()
|
|
{
|
|
String result;
|
|
|
|
result = String.format("valid=%b, url=%s, formatter=%s, compression=%s, expiration=%s, burnafterreading=%s, opendiscussion=%s, password=%s",
|
|
isValid(), this.serverUrl, this.formatter, this.compression, this.expiration, this.burnAfterReading, this.openDiscussion,
|
|
this.password);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
}
|