com.composum.platform.models.simple.SimpleModel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of composum-platform-models-bundle Show documentation
Show all versions of composum-platform-models-bundle Show documentation
Bundle containing features for the general use of Models incl. Sling-Models bundled as a
package
The newest version!
package com.composum.platform.models.simple;
import com.composum.platform.models.annotations.InternationalizationStrategy;
import com.composum.sling.core.AbstractServletBean;
import org.apache.sling.api.SlingHttpServletRequest;
import java.util.List;
import java.util.Locale;
import java.util.Map;
/**
* a simple model for property access with I18N support as used in 'Pages'
*/
public class SimpleModel extends AbstractServletBean {
private transient Map propertiesMap;
private transient Map inheritedMap;
private transient List i18nPaths;
private transient Locale locale;
/**
* the generic map for direct use in templates
*/
public Map getProperties() {
if (propertiesMap == null) {
propertiesMap = new GenericProperties();
}
return propertiesMap;
}
/**
* the generic map for direct use in templates
*/
public Map getInherited() {
if (inheritedMap == null) {
inheritedMap = new GenericInherited();
}
return inheritedMap;
}
protected List getI18nPaths() {
if (i18nPaths == null) {
i18nPaths = InternationalizationStrategy.I18NFOLDER.getI18nPaths(getLocale());
}
return i18nPaths;
}
public Locale getLocale() {
if (locale == null) {
SlingHttpServletRequest request = getRequest();
locale = request != null ? getRequest().getLocale() : Locale.getDefault();
}
return locale;
}
public class GenericProperties extends GenericMap {
public GenericProperties() {
super(getI18nPaths());
}
@Override
public Object getValue(String key) {
return getProperty(key, Object.class);
}
}
public class GenericInherited extends GenericMap {
public GenericInherited() {
super(getI18nPaths());
}
@Override
public Object getValue(String key) {
return getInherited(key, Object.class);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy