com.fastchar.captcha.FastCaptchaConfig Maven / Gradle / Ivy
package com.fastchar.captcha;
import com.fastchar.interfaces.IFastConfig;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
public class FastCaptchaConfig implements IFastConfig {
public FastCaptchaConfig() {
for (int i = 1; i <= 2; i++) {
addCaptchaFont(FastCaptchaConfig.class.getResource("/font_family_" + i + ".ttf"));
}
for (int i = 1; i <= 15; i++) {
addCaptchaBackgroundImage(FastCaptchaConfig.class.getResource("/img_bg_" + i + ".jpeg"));
}
simpleFontURL = FastCaptchaConfig.class.getResource("/font_family_simple.ttf");
}
private final List captchaBackgroundImages = new ArrayList<>(16);
private final List captchaFonts = new ArrayList<>(16);
private boolean simple = false;
private URL simpleFontURL;
public List getCaptchaBackgroundImages() {
return captchaBackgroundImages;
}
public List getCaptchaFonts() {
return captchaFonts;
}
public FastCaptchaConfig addCaptchaBackgroundImage(URL imageURL) {
captchaBackgroundImages.add(imageURL);
return this;
}
public FastCaptchaConfig addCaptchaBackgroundImage(String imagePath) {
try {
captchaBackgroundImages.add(new File(imagePath).toURI().toURL());
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
return this;
}
public FastCaptchaConfig addCaptchaFont(URL fontURL) {
captchaFonts.add(fontURL);
return this;
}
public FastCaptchaConfig addCaptchaFont(String fontPath) throws MalformedURLException {
captchaFonts.add(new File(fontPath).toURI().toURL());
return this;
}
public boolean isSimple() {
return simple;
}
public FastCaptchaConfig setSimple(boolean simple) {
this.simple = simple;
return this;
}
public URL getSimpleFontURL() {
return simpleFontURL;
}
public FastCaptchaConfig setSimpleFontURL(URL simpleFontURL) {
this.simpleFontURL = simpleFontURL;
return this;
}
}