1 package net.pterodactylus.sone.core;
3 import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired;
4 import net.pterodactylus.util.config.Configuration;
5 import net.pterodactylus.util.config.ConfigurationException;
8 * Loads preferences stored in a {@link Configuration} into a {@link
11 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
13 public class PreferencesLoader {
15 private final Preferences preferences;
17 public PreferencesLoader(Preferences preferences) {
18 this.preferences = preferences;
21 public void loadFrom(Configuration configuration) {
22 loadInsertionDelay(configuration);
23 loadPostsPerPage(configuration);
24 loadImagesPerPage(configuration);
25 loadCharactersPerPost(configuration);
26 loadPostCutOffLength(configuration);
27 loadRequireFullAccess(configuration);
28 loadPositiveTrust(configuration);
29 loadNegativeTrust(configuration);
30 loadTrustComment(configuration);
31 loadFcpInterfaceActive(configuration);
32 loadFcpFullAccessRequired(configuration);
35 private void loadInsertionDelay(Configuration configuration) {
36 preferences.setInsertionDelay(configuration.getIntValue(
37 "Option/InsertionDelay").getValue(null));
40 private void loadPostsPerPage(Configuration configuration) {
41 preferences.setPostsPerPage(
42 configuration.getIntValue("Option/PostsPerPage")
46 private void loadImagesPerPage(Configuration configuration) {
47 preferences.setImagesPerPage(
48 configuration.getIntValue("Option/ImagesPerPage")
52 private void loadCharactersPerPost(Configuration configuration) {
53 preferences.setCharactersPerPost(
54 configuration.getIntValue("Option/CharactersPerPost")
58 private void loadPostCutOffLength(Configuration configuration) {
59 preferences.setPostCutOffLength(
60 configuration.getIntValue("Option/PostCutOffLength")
64 private void loadRequireFullAccess(Configuration configuration) {
65 preferences.setRequireFullAccess(
66 configuration.getBooleanValue("Option/RequireFullAccess")
70 private void loadPositiveTrust(Configuration configuration) {
71 preferences.setPositiveTrust(
72 configuration.getIntValue("Option/PositiveTrust")
76 private void loadNegativeTrust(Configuration configuration) {
77 preferences.setNegativeTrust(
78 configuration.getIntValue("Option/NegativeTrust")
82 private void loadTrustComment(Configuration configuration) {
83 preferences.setTrustComment(
84 configuration.getStringValue("Option/TrustComment")
88 private void loadFcpInterfaceActive(Configuration configuration) {
89 preferences.setFcpInterfaceActive(configuration.getBooleanValue(
90 "Option/ActivateFcpInterface").getValue(null));
93 private void loadFcpFullAccessRequired(Configuration configuration) {
94 Integer fullAccessRequiredInteger = configuration
95 .getIntValue("Option/FcpFullAccessRequired").getValue(null);
96 preferences.setFcpFullAccessRequired(
97 (fullAccessRequiredInteger == null) ? null :
98 FullAccessRequired.values()[fullAccessRequiredInteger]);