Change logger names.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / PreferencesLoader.java
1 package net.pterodactylus.sone.core;
2
3 import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired;
4 import net.pterodactylus.util.config.Configuration;
5 import net.pterodactylus.util.config.ConfigurationException;
6
7 /**
8  * Loads preferences stored in a {@link Configuration} into a {@link
9  * Preferences} object.
10  *
11  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
12  */
13 public class PreferencesLoader {
14
15         private final Preferences preferences;
16
17         public PreferencesLoader(Preferences preferences) {
18                 this.preferences = preferences;
19         }
20
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);
33         }
34
35         private void loadInsertionDelay(Configuration configuration) {
36                 preferences.setInsertionDelay(configuration.getIntValue(
37                                 "Option/InsertionDelay").getValue(null));
38         }
39
40         private void loadPostsPerPage(Configuration configuration) {
41                 preferences.setPostsPerPage(
42                                 configuration.getIntValue("Option/PostsPerPage")
43                                                 .getValue(null));
44         }
45
46         private void loadImagesPerPage(Configuration configuration) {
47                 preferences.setImagesPerPage(
48                                 configuration.getIntValue("Option/ImagesPerPage")
49                                                 .getValue(null));
50         }
51
52         private void loadCharactersPerPost(Configuration configuration) {
53                 preferences.setCharactersPerPost(
54                                 configuration.getIntValue("Option/CharactersPerPost")
55                                                 .getValue(null));
56         }
57
58         private void loadPostCutOffLength(Configuration configuration) {
59                 preferences.setPostCutOffLength(
60                                 configuration.getIntValue("Option/PostCutOffLength")
61                                                 .getValue(null));
62         }
63
64         private void loadRequireFullAccess(Configuration configuration) {
65                 preferences.setRequireFullAccess(
66                                 configuration.getBooleanValue("Option/RequireFullAccess")
67                                                 .getValue(null));
68         }
69
70         private void loadPositiveTrust(Configuration configuration) {
71                 preferences.setPositiveTrust(
72                                 configuration.getIntValue("Option/PositiveTrust")
73                                                 .getValue(null));
74         }
75
76         private void loadNegativeTrust(Configuration configuration) {
77                 preferences.setNegativeTrust(
78                                 configuration.getIntValue("Option/NegativeTrust")
79                                                 .getValue(null));
80         }
81
82         private void loadTrustComment(Configuration configuration) {
83                 preferences.setTrustComment(
84                                 configuration.getStringValue("Option/TrustComment")
85                                                 .getValue(null));
86         }
87
88         private void loadFcpInterfaceActive(Configuration configuration) {
89                 preferences.setFcpInterfaceActive(configuration.getBooleanValue(
90                                 "Option/ActivateFcpInterface").getValue(null));
91         }
92
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]);
99         }
100
101 }