Skip to content

Commit

Permalink
loading localization in following order
Browse files Browse the repository at this point in the history
1/ ${midpoint.home}/localization/midpoint_LOCALE.properties
2/ ${midpoint.home}/localization/schema_LOCALE.properties
3/ classpath:/localization/midpoint_LOCALE.properties
4/ classpath:/localization/schema_LOCALE.properties
  • Loading branch information
1azyman committed Sep 2, 2017
1 parent 91fe8ec commit dee536f
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 77 deletions.
Expand Up @@ -16,36 +16,36 @@

package com.evolveum.midpoint.web.security;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import com.evolveum.midpoint.common.configuration.api.MidpointConfiguration;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.model.api.*;
import com.evolveum.midpoint.model.common.SystemObjectCache;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.crypto.Protector;
import com.evolveum.midpoint.prism.match.MatchingRuleRegistry;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.repo.common.expression.ExpressionFactory;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.SchemaDebugUtil;
import com.evolveum.midpoint.security.api.AuthorizationConstants;
import com.evolveum.midpoint.security.api.SecurityEnforcer;
import com.evolveum.midpoint.task.api.TaskManager;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.application.DescriptorLoader;
import com.evolveum.midpoint.web.component.GuiComponents;
import com.evolveum.midpoint.web.page.admin.home.PageDashboard;
import com.evolveum.midpoint.web.page.error.*;
import com.evolveum.midpoint.web.page.login.PageLogin;
import com.evolveum.midpoint.web.page.self.PageSelfDashboard;
import com.evolveum.midpoint.web.resource.img.ImgResources;
import com.evolveum.midpoint.web.util.Utf8BundleStringResourceLoader;
import com.evolveum.midpoint.wf.api.WorkflowManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType;
import org.apache.commons.configuration.Configuration;
Expand All @@ -54,10 +54,6 @@
import org.apache.wicket.authroles.authentication.AbstractAuthenticatedWebSession;
import org.apache.wicket.authroles.authentication.AuthenticatedWebApplication;
import org.apache.wicket.core.request.mapper.MountedMapper;
import org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream;
import org.apache.wicket.core.util.objects.checker.IObjectChecker;
import org.apache.wicket.core.util.objects.checker.NotDetachedModelChecker;
import org.apache.wicket.core.util.objects.checker.ObjectSerializationChecker;
import org.apache.wicket.markup.head.PriorityFirstComparator;
import org.apache.wicket.markup.html.SecurePackageResourceGuard;
import org.apache.wicket.markup.html.WebPage;
Expand All @@ -66,7 +62,6 @@
import org.apache.wicket.request.resource.PackageResourceReference;
import org.apache.wicket.request.resource.SharedResourceReference;
import org.apache.wicket.resource.loader.IStringResourceLoader;
import org.apache.wicket.serialize.java.JavaSerializer;
import org.apache.wicket.settings.ApplicationSettings;
import org.apache.wicket.settings.ResourceSettings;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
Expand All @@ -76,29 +71,11 @@
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.stereotype.Component;

import com.evolveum.midpoint.common.configuration.api.MidpointConfiguration;
import com.evolveum.midpoint.repo.common.expression.ExpressionFactory;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.model.api.ModelAuditService;
import com.evolveum.midpoint.model.api.ModelInteractionService;
import com.evolveum.midpoint.model.api.ModelService;
import com.evolveum.midpoint.model.api.TaskService;
import com.evolveum.midpoint.model.api.WorkflowService;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.crypto.Protector;
import com.evolveum.midpoint.security.api.AuthorizationConstants;
import com.evolveum.midpoint.task.api.TaskManager;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.application.DescriptorLoader;
import com.evolveum.midpoint.web.component.GuiComponents;
import com.evolveum.midpoint.web.page.admin.home.PageDashboard;
import com.evolveum.midpoint.web.page.login.PageLogin;
import com.evolveum.midpoint.web.page.self.PageSelfDashboard;
import com.evolveum.midpoint.web.resource.img.ImgResources;
import com.evolveum.midpoint.web.util.Utf8BundleStringResourceLoader;
import java.io.*;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.*;

/**
* @author lazyman
Expand Down Expand Up @@ -198,24 +175,24 @@ public class MidPointApplication extends AuthenticatedWebApplication {
transient TaskService taskService;
@Autowired
transient PrismContext prismContext;
@Autowired
transient ExpressionFactory expressionFactory;
@Autowired
transient ExpressionFactory expressionFactory;
@Autowired
transient TaskManager taskManager;
@Autowired
transient ModelAuditService auditService;
@Autowired
transient private RepositoryService repositoryService; // temporary
@Autowired
transient private RepositoryService repositoryService; // temporary
@Autowired
transient private WorkflowService workflowService;
@Autowired
transient private WorkflowManager workflowManager;
@Autowired
transient private WorkflowManager workflowManager;
@Autowired
transient MidpointConfiguration configuration;
@Autowired
transient Protector protector;
@Autowired
transient MatchingRuleRegistry matchingRuleRegistry;
@Autowired
transient MatchingRuleRegistry matchingRuleRegistry;
@Autowired
transient SecurityEnforcer securityEnforcer;
@Autowired
Expand Down Expand Up @@ -258,9 +235,14 @@ public void init() {
SecurePackageResourceGuard guard = (SecurePackageResourceGuard) resourceSettings.getPackageResourceGuard();
guard.addPattern("+*.woff2");

URL url = buildMidpointHomeLocalizationFolderUrl();
ClassLoader classLoader = new URLClassLoader(new URL[]{url});

List<IStringResourceLoader> resourceLoaders = resourceSettings.getStringResourceLoaders();
resourceLoaders.add(0, new Utf8BundleStringResourceLoader("localization/Midpoint"));
resourceLoaders.add(1, new Utf8BundleStringResourceLoader(SchemaConstants.SCHEMA_LOCALIZATION_PROPERTIES_RESOURCE_BASE_PATH));
resourceLoaders.add(0, new Utf8BundleStringResourceLoader("Midpoint", classLoader));
resourceLoaders.add(1, new Utf8BundleStringResourceLoader(SchemaConstants.BUNDLE_NAME, classLoader));
resourceLoaders.add(2, new Utf8BundleStringResourceLoader("localization/Midpoint"));
resourceLoaders.add(3, new Utf8BundleStringResourceLoader(SchemaConstants.SCHEMA_LOCALIZATION_PROPERTIES_RESOURCE_BASE_PATH));

resourceSettings.setThrowExceptionOnMissingResource(false);
getMarkupSettings().setStripWicketTags(true);
Expand Down Expand Up @@ -294,6 +276,17 @@ public void init() {
new DescriptorLoader().loadData(this);
}

private URL buildMidpointHomeLocalizationFolderUrl() {
String midpointHome = System.getProperty(WebApplicationConfiguration.MIDPOINT_HOME);

File file = new File(midpointHome, "localization");
try {
return file.toURI().toURL();
} catch (IOException ex) {
throw new SystemException("Couldn't transform localization folder file to url", ex);
}
}

private void initializeDevelopmentSerializers() {
// JavaSerializer javaSerializer = new JavaSerializer( getApplicationKey() ) {
// @Override
Expand All @@ -307,10 +300,10 @@ private void initializeDevelopmentSerializers() {
// }
// };
// getFrameworkSettings().setSerializer( javaSerializer );

}

private void mountFiles(String path, Class<?> clazz) {
}

private void mountFiles(String path, Class<?> clazz) {
try {
List<Resource> list = new ArrayList<>();
String packagePath = clazz.getPackage().getName().replace('.', '/');
Expand Down Expand Up @@ -359,9 +352,9 @@ public ModelAuditService getAuditService() {
return auditService;
}

public RepositoryService getRepositoryService() {
return repositoryService;
}
public RepositoryService getRepositoryService() {
return repositoryService;
}

public TaskService getTaskService() {
return taskService;
Expand All @@ -372,8 +365,8 @@ public PrismContext getPrismContext() {
}

public ExpressionFactory getExpressionFactory() {
return expressionFactory;
}
return expressionFactory;
}

public Protector getProtector() {
return protector;
Expand All @@ -393,11 +386,11 @@ public WorkflowService getWorkflowService() {
return workflowService;
}

public WorkflowManager getWorkflowManager() {
return workflowManager;
}
public WorkflowManager getWorkflowManager() {
return workflowManager;
}

public ModelInteractionService getModelInteractionService() {
public ModelInteractionService getModelInteractionService() {
return modelInteractionService;
}

Expand Down Expand Up @@ -425,9 +418,9 @@ public static Locale getDefaultLocale() {
return new Locale("en", "US");
}

public MatchingRuleRegistry getMatchingRuleRegistry() {
return matchingRuleRegistry;
}
public MatchingRuleRegistry getMatchingRuleRegistry() {
return matchingRuleRegistry;
}

public SystemConfigurationType getSystemConfiguration() throws SchemaException {
PrismObject<SystemConfigurationType> config = systemObjectCache.getSystemConfiguration(new OperationResult("dummy"));
Expand Down
Expand Up @@ -30,7 +30,8 @@ public class WebApplicationConfiguration implements Serializable {

private static final Trace LOGGER = TraceManager.getTrace(WebApplicationConfiguration.class);

private static final String MIDPOINT_HOME = "midpoint.home"; //todo move somewhere
public static final String MIDPOINT_HOME = "midpoint.home"; //todo move somewhere

private String importFolder;
private String exportFolder;
private int progressRefreshInterval; // how often to refresh 'progress table' (in milliseconds; 0 means this feature is disabled)
Expand Down
Expand Up @@ -38,8 +38,15 @@ public class Utf8BundleStringResourceLoader implements IStringResourceLoader {

private final String bundleName;

private ClassLoader classLoader;

public Utf8BundleStringResourceLoader(String bundleName) {
this(bundleName, null);
}

public Utf8BundleStringResourceLoader(String bundleName, ClassLoader classLoader) {
this.bundleName = bundleName;
this.classLoader = classLoader;
}

@Override
Expand All @@ -55,8 +62,16 @@ public String loadStringResource(Component component, String key, Locale locale,

ResourceBundle.Control control = new UTF8Control();
try {
return ResourceBundle.getBundle(bundleName, locale, control).getString(key);
if (classLoader == null) {
return ResourceBundle.getBundle(bundleName, locale, control).getString(key);
} else {
return ResourceBundle.getBundle(bundleName, locale, classLoader, control).getString(key);
}
} catch (MissingResourceException ex) {
if (classLoader != null) {
return null;
}

try {
return ResourceBundle.getBundle(bundleName, locale,
Thread.currentThread().getContextClassLoader(), control).getString(key);
Expand Down
Expand Up @@ -513,8 +513,9 @@ public abstract class SchemaConstants {
public static final QName SAMPLES_DOMAIN = new QName(SchemaConstants.NS_SAMPLES_EXTENSION, "domain");

// Misc

public static String SCHEMA_LOCALIZATION_PROPERTIES_RESOURCE_BASE_PATH = "localization/schema";

public static String BUNDLE_NAME = "schema";
public static String SCHEMA_LOCALIZATION_PROPERTIES_RESOURCE_BASE_PATH = "localization/" + BUNDLE_NAME;
public static final QName APPROVAL_LEVEL_OUTCOME_TYPE_COMPLEX_TYPE = new QName(SchemaConstants.NS_C, ApprovalLevelOutcomeType.class.getSimpleName());

// registration
Expand Down

0 comments on commit dee536f

Please sign in to comment.