use of password.pwm.i18n.PwmLocaleBundle in project pwm by pwm-project.
the class ConfigEditorServlet method restMenuTreeData.
@ActionHandler(action = "menuTreeData")
private ProcessStatus restMenuTreeData(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
final Instant startTime = Instant.now();
final ConfigManagerBean configManagerBean = getBean(pwmRequest);
final ArrayList<NavTreeItem> navigationData = new ArrayList<>();
final Map<String, Object> inputParameters = pwmRequest.readBodyAsJsonMap(PwmHttpRequestWrapper.Flag.BypassValidation);
final boolean modifiedSettingsOnly = (boolean) inputParameters.get("modifiedSettingsOnly");
final double level = (double) inputParameters.get("level");
final String filterText = (String) inputParameters.get("text");
{
// root node
final NavTreeItem categoryInfo = new NavTreeItem();
categoryInfo.setId("ROOT");
categoryInfo.setName("ROOT");
navigationData.add(categoryInfo);
}
{
final StoredConfigurationImpl storedConfiguration = configManagerBean.getStoredConfiguration();
final List<PwmSettingCategory> categories = NavTreeHelper.filteredCategories(pwmRequest.getPwmApplication(), storedConfiguration, pwmRequest.getLocale(), modifiedSettingsOnly, level, filterText);
navigationData.addAll(NavTreeHelper.makeSettingNavItems(categories, storedConfiguration, pwmRequest.getLocale()));
}
boolean includeDisplayText = true;
if (level >= 1) {
for (final PwmLocaleBundle localeBundle : PwmLocaleBundle.values()) {
if (!localeBundle.isAdminOnly()) {
final Set<String> modifiedKeys = new TreeSet<>();
if (modifiedSettingsOnly) {
modifiedKeys.addAll(NavTreeHelper.determineModifiedKeysSettings(localeBundle, pwmRequest.getConfig(), configManagerBean.getStoredConfiguration()));
}
if (!modifiedSettingsOnly || !modifiedKeys.isEmpty()) {
final NavTreeItem categoryInfo = new NavTreeItem();
categoryInfo.setId(localeBundle.toString());
categoryInfo.setName(localeBundle.getTheClass().getSimpleName());
categoryInfo.setParent("DISPLAY_TEXT");
categoryInfo.setType(NavTreeHelper.NavItemType.displayText);
categoryInfo.setKeys(new TreeSet<>(modifiedSettingsOnly ? modifiedKeys : localeBundle.getKeys()));
navigationData.add(categoryInfo);
includeDisplayText = true;
}
}
}
}
if (includeDisplayText) {
final NavTreeItem categoryInfo = new NavTreeItem();
categoryInfo.setId("DISPLAY_TEXT");
categoryInfo.setName("Display Text");
categoryInfo.setType(NavTreeHelper.NavItemType.navigation);
categoryInfo.setParent("ROOT");
navigationData.add(categoryInfo);
}
NavTreeHelper.moveNavItemToTopOfList(PwmSettingCategory.NOTES.toString(), navigationData);
NavTreeHelper.moveNavItemToTopOfList(PwmSettingCategory.TEMPLATES.toString(), navigationData);
LOGGER.trace(pwmRequest, "completed navigation tree data request in " + TimeDuration.fromCurrent(startTime).asCompactString());
pwmRequest.outputJsonResult(RestResultBean.withData(navigationData));
return ProcessStatus.Halt;
}
use of password.pwm.i18n.PwmLocaleBundle in project pwm by pwm-project.
the class ConfigEditorServlet method generateSettingData.
public static Map<String, Object> generateSettingData(final PwmApplication pwmApplication, final StoredConfigurationImpl storedConfiguration, final SessionLabel sessionLabel, final Locale locale) throws PwmUnrecoverableException {
final LinkedHashMap<String, Object> returnMap = new LinkedHashMap<>();
final MacroMachine macroMachine = MacroMachine.forNonUserSpecific(pwmApplication, sessionLabel);
final PwmSettingTemplateSet template = storedConfiguration.getTemplateSet();
{
final LinkedHashMap<String, Object> settingMap = new LinkedHashMap<>();
for (final PwmSetting setting : PwmSetting.values()) {
settingMap.put(setting.getKey(), SettingInfo.forSetting(setting, template, macroMachine, locale));
}
returnMap.put("settings", settingMap);
}
{
final LinkedHashMap<String, Object> categoryMap = new LinkedHashMap<>();
for (final PwmSettingCategory category : PwmSettingCategory.values()) {
categoryMap.put(category.getKey(), CategoryInfo.forCategory(category, macroMachine, locale));
}
returnMap.put("categories", categoryMap);
}
{
final LinkedHashMap<String, Object> labelMap = new LinkedHashMap<>();
for (final PwmLocaleBundle localeBundle : PwmLocaleBundle.values()) {
final LocaleInfo localeInfo = new LocaleInfo();
localeInfo.description = localeBundle.getTheClass().getSimpleName();
localeInfo.key = localeBundle.toString();
localeInfo.adminOnly = localeBundle.isAdminOnly();
labelMap.put(localeBundle.getTheClass().getSimpleName(), localeInfo);
}
returnMap.put("locales", labelMap);
}
{
final LinkedHashMap<String, Object> varMap = new LinkedHashMap<>();
varMap.put("ldapProfileIds", storedConfiguration.readSetting(PwmSetting.LDAP_PROFILE_LIST).toNativeObject());
varMap.put("currentTemplate", storedConfiguration.getTemplateSet());
varMap.put("configurationNotes", storedConfiguration.readConfigProperty(ConfigurationProperty.NOTES));
returnMap.put("var", varMap);
}
return Collections.unmodifiableMap(returnMap);
}
use of password.pwm.i18n.PwmLocaleBundle in project pwm by pwm-project.
the class ConfigEditorServlet method restResetSetting.
@ActionHandler(action = "resetSetting")
private ProcessStatus restResetSetting(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
final ConfigManagerBean configManagerBean = getBean(pwmRequest);
final StoredConfigurationImpl storedConfig = configManagerBean.getStoredConfiguration();
final UserIdentity loggedInUser = pwmRequest.getUserInfoIfLoggedIn();
final String key = pwmRequest.readParameterAsString("key");
final PwmSetting setting = PwmSetting.forKey(key);
if (key.startsWith("localeBundle")) {
final StringTokenizer st = new StringTokenizer(key, "-");
st.nextToken();
final PwmLocaleBundle bundleName = PwmLocaleBundle.valueOf(st.nextToken());
final String keyName = st.nextToken();
storedConfig.resetLocaleBundleMap(bundleName.getTheClass().getName(), keyName);
} else {
final String profileID = setting.getCategory().hasProfiles() ? pwmRequest.readParameterAsString("profile") : null;
storedConfig.resetSetting(setting, profileID, loggedInUser);
}
pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
return ProcessStatus.Halt;
}
use of password.pwm.i18n.PwmLocaleBundle in project pwm by pwm-project.
the class LocaleHelper method getModifiedKeysInConfig.
public static Map<PwmLocaleBundle, Map<String, List<Locale>>> getModifiedKeysInConfig(final Configuration configuration) {
final Map<PwmLocaleBundle, Map<String, List<Locale>>> returnObj = new LinkedHashMap<>();
for (final PwmLocaleBundle pwmLocaleBundle : PwmLocaleBundle.values()) {
for (final String key : pwmLocaleBundle.getKeys()) {
for (final Locale locale : configuration.getKnownLocales()) {
final String defaultValue = LocaleHelper.getLocalizedMessage(locale, key, null, pwmLocaleBundle.getTheClass());
final String customizedValue = LocaleHelper.getLocalizedMessage(locale, key, configuration, pwmLocaleBundle.getTheClass());
if (defaultValue != null && !defaultValue.equals(customizedValue)) {
if (!returnObj.containsKey(pwmLocaleBundle)) {
returnObj.put(pwmLocaleBundle, new LinkedHashMap<String, List<Locale>>());
}
if (!returnObj.get(pwmLocaleBundle).containsKey(key)) {
returnObj.get(pwmLocaleBundle).put(key, new ArrayList<Locale>());
}
returnObj.get(pwmLocaleBundle).get(key).add(locale);
}
}
}
}
return returnObj;
}
use of password.pwm.i18n.PwmLocaleBundle in project pwm by pwm-project.
the class StoredConfigurationImpl method writeLocaleBundleMap.
public void writeLocaleBundleMap(final String bundleName, final String keyName, final Map<String, String> localeMap) {
ResourceBundle theBundle = null;
for (final PwmLocaleBundle bundle : PwmLocaleBundle.values()) {
if (bundle.getTheClass().getName().equals(bundleName)) {
theBundle = ResourceBundle.getBundle(bundleName);
}
}
if (theBundle == null) {
LOGGER.info("ignoring unknown locale bundle for bundle=" + bundleName + ", key=" + keyName);
return;
}
if (theBundle.getString(keyName) == null) {
LOGGER.info("ignoring unknown key for bundle=" + bundleName + ", key=" + keyName);
return;
}
resetLocaleBundleMap(bundleName, keyName);
if (localeMap == null || localeMap.isEmpty()) {
LOGGER.info("cleared locale bundle map for bundle=" + bundleName + ", key=" + keyName);
return;
}
preModifyActions();
changeLog.updateChangeLog(bundleName, keyName, localeMap);
try {
domModifyLock.writeLock().lock();
final Element localeBundleElement = new Element("localeBundle");
localeBundleElement.setAttribute("bundle", bundleName);
localeBundleElement.setAttribute("key", keyName);
for (final Map.Entry<String, String> entry : localeMap.entrySet()) {
final String locale = entry.getKey();
final String value = entry.getValue();
final Element valueElement = new Element("value");
if (locale != null && locale.length() > 0) {
valueElement.setAttribute("locale", locale);
}
valueElement.setContent(new CDATA(value));
localeBundleElement.addContent(valueElement);
}
localeBundleElement.setAttribute(XML_ATTRIBUTE_MODIFY_TIME, JavaHelper.toIsoDate(Instant.now()));
document.getRootElement().addContent(localeBundleElement);
} finally {
domModifyLock.writeLock().unlock();
}
}
Aggregations