Erweiterungen
This commit is contained in:
20
src/main/java/util/PreferencesKeyValueStore.java
Normal file
20
src/main/java/util/PreferencesKeyValueStore.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package util;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
@Service
|
||||
public class PreferencesKeyValueStore {
|
||||
|
||||
private final Preferences prefs = Preferences.userRoot().node("emulatorstation");
|
||||
|
||||
public void put(String key, String value) {
|
||||
prefs.put(key, value);
|
||||
}
|
||||
|
||||
public Optional<String> get(String key) {
|
||||
return Optional.ofNullable(prefs.get(key, null));
|
||||
}
|
||||
}
|
||||
19
src/main/java/util/Util.java
Normal file
19
src/main/java/util/Util.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package util;
|
||||
|
||||
import com.vaadin.flow.component.UI;
|
||||
import com.vaadin.flow.component.applayout.AppLayout;
|
||||
import com.vaadin.flow.server.VaadinSession;
|
||||
import com.vaadin.flow.server.WrappedSession;
|
||||
|
||||
|
||||
public class Util {
|
||||
public static String getSessionAttributeWithDefault(WrappedSession currentSession, String key, String defaultValue) {
|
||||
var result = defaultValue;
|
||||
|
||||
try {
|
||||
result = currentSession.getAttribute(key).toString();
|
||||
} catch (Exception e) {}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user