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) {
60 preferences.setPostCutOffLength(
61 configuration.getIntValue("Option/PostCutOffLength")
63 } catch (IllegalArgumentException iae1) {
64 /* previous versions allowed -1, ignore and use default. */
68 private void loadRequireFullAccess(Configuration configuration) {
69 preferences.setRequireFullAccess(
70 configuration.getBooleanValue("Option/RequireFullAccess")
74 private void loadPositiveTrust(Configuration configuration) {
75 preferences.setPositiveTrust(
76 configuration.getIntValue("Option/PositiveTrust")
80 private void loadNegativeTrust(Configuration configuration) {
81 preferences.setNegativeTrust(
82 configuration.getIntValue("Option/NegativeTrust")
86 private void loadTrustComment(Configuration configuration) {
87 preferences.setTrustComment(
88 configuration.getStringValue("Option/TrustComment")
92 private void loadFcpInterfaceActive(Configuration configuration) {
93 preferences.setFcpInterfaceActive(configuration.getBooleanValue(
94 "Option/ActivateFcpInterface").getValue(null));
97 private void loadFcpFullAccessRequired(Configuration configuration) {
98 Integer fullAccessRequiredInteger = configuration
99 .getIntValue("Option/FcpFullAccessRequired").getValue(null);
100 preferences.setFcpFullAccessRequired(
101 (fullAccessRequiredInteger == null) ? null :
102 FullAccessRequired.values()[fullAccessRequiredInteger]);