Search in sources :

Example 56 with ResourceBundle

use of java.util.ResourceBundle in project OpenAM by OpenRock.

the class Main method main.

public static void main(String[] args) {
    ResourceBundle bundle = ResourceBundle.getBundle(System.getProperty(SETUP_PROPERTIES_FILE, DEFAULT_PROPERTIES_FILE));
    if ((System.getProperty(PRINT_HELP) != null) && System.getProperty(PRINT_HELP).equals(YES)) {
        SetupUtils.printUsage(bundle);
        System.exit(0);
    }
    if (System.getProperty(CHECK_VERSION) != null) {
        if (System.getProperty(CHECK_VERSION).equals(YES)) {
            System.exit(VersionCheck.isValid());
        }
    }
    boolean acceptLicense = false;
    for (String arg : args) {
        if (arg.equals(ACCEPT_LICENSE)) {
            acceptLicense = true;
            break;
        }
    }
    try {
        LICENSE_PRESENTER.presentLicenses(acceptLicense);
    } catch (LicenseRejectedException e) {
        System.out.println(bundle.getString("message.error.license"));
        System.exit(0);
    }
    boolean loadConfig = (System.getProperty(CONFIG_LOAD) != null) && System.getProperty(CONFIG_LOAD).equals(YES);
    String currentOS = SetupUtils.determineOS();
    Properties configProp = null;
    String debugPath = null;
    String logPath = null;
    if (loadConfig) {
        String configPath = System.getProperty(AMCONFIG_PATH);
        debugPath = System.getProperty(DEBUG_PATH);
        logPath = System.getProperty(LOG_PATH);
        String currentDir = System.getProperty("user.dir");
        try {
            if ((configPath == null) || (configPath.length() == 0)) {
                configPath = SetupUtils.getUserInput(bundle.getString(currentOS + QUESTION), System.getProperty("user.home") + File.separator + "openam");
                if (!(new File(configPath).isAbsolute())) {
                    System.out.println(bundle.getString("message.error.dir.absolute"));
                    System.exit(1);
                }
                if ((debugPath == null) || (debugPath.length() == 0)) {
                    debugPath = SetupUtils.getUserInput(bundle.getString(currentOS + ".debug.dir"), currentDir + File.separator + "debug");
                }
                if (!(new File(debugPath).isAbsolute())) {
                    System.out.println(bundle.getString("message.error.dir.absolute"));
                    System.exit(1);
                }
                if (!isWriteable(debugPath)) {
                    System.out.println(bundle.getString("message.error.debug.dir.not.writable"));
                    System.exit(1);
                }
                if ((logPath == null) || (logPath.length() == 0)) {
                    logPath = SetupUtils.getUserInput(bundle.getString(currentOS + ".log.dir"), currentDir + File.separator + "log");
                }
                if (!(new File(logPath).isAbsolute())) {
                    System.out.println(bundle.getString("message.error.dir.absolute"));
                    System.exit(1);
                }
                if (!isWriteable(logPath)) {
                    System.out.println(bundle.getString("message.error.log.dir.not.writable"));
                    System.exit(1);
                }
            } else {
                String toolsHome = new File(".").getCanonicalPath();
                toolsHome = toolsHome.replaceAll("\\\\", "/");
                if ((debugPath == null) || (debugPath.length() == 0)) {
                    debugPath = toolsHome + "/debug";
                }
                if ((logPath == null) || (logPath.length() == 0)) {
                    logPath = toolsHome + "/log";
                }
            }
            configProp = Bootstrap.load(configPath, false);
            if (configProp == null) {
                System.out.println(bundle.getString("message.error.dir"));
                System.exit(1);
            }
            File path = new File(debugPath);
            boolean created = path.exists() || path.mkdirs();
            if (!created) {
                System.out.println(bundle.getString("message.error.debug.dir.not.writable"));
                System.exit(1);
            }
            path = new File(logPath);
            created = path.exists() || path.mkdirs();
            if (!created) {
                System.out.println(bundle.getString("message.error.log.dir.not.writable"));
                System.exit(1);
            }
            if (!configPath.endsWith(FILE_SEPARATOR)) {
                configPath = configPath + FILE_SEPARATOR;
            }
            configProp.setProperty(USER_INPUT, configPath.substring(0, configPath.length() - 1));
            configProp.setProperty("LogDir", logPath);
            configProp.setProperty("DebugDir", debugPath);
            configProp.setProperty(CURRENT_PLATFORM, currentOS);
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
            System.exit(1);
        }
    } else {
        configProp = new Properties();
    }
    SetupUtils.evaluateBundleValues(bundle, configProp);
    try {
        SetupUtils.copyAndFilterScripts(bundle, configProp);
        if (loadConfig) {
            Object[] p = { debugPath };
            System.out.println(MessageFormat.format(bundle.getString("message.info.debug.dir"), p));
            p[0] = logPath;
            System.out.println(MessageFormat.format(bundle.getString("message.info.log.dir"), p));
            System.out.println(bundle.getString("message.info.version.tools") + " " + bundle.getString(TOOLS_VERSION));
            System.out.println(bundle.getString("message.info.version.am") + " " + SystemProperties.get("com.iplanet.am.version"));
        }
    } catch (IOException ex) {
        System.out.println(bundle.getString("message.error.copy"));
        System.exit(1);
    }
    System.exit(0);
}
Also used : LicenseRejectedException(org.forgerock.openam.license.LicenseRejectedException) ResourceBundle(java.util.ResourceBundle) IOException(java.io.IOException) Properties(java.util.Properties) SystemProperties(com.iplanet.am.util.SystemProperties) File(java.io.File) LicenseRejectedException(org.forgerock.openam.license.LicenseRejectedException) IOException(java.io.IOException)

Example 57 with ResourceBundle

use of java.util.ResourceBundle in project OpenAM by OpenRock.

the class ServerConfiguration method getNewServerDefaults.

public static Map<String, String> getNewServerDefaults(SSOToken ssoToken) throws SMSException, SSOException {
    boolean bCreated = false;
    ServiceConfig sc = getRootServerConfig(ssoToken);
    try {
        bCreated = (sc.getSubConfig(DEFAULT_SERVER_CONFIG) != null);
    } catch (SMSException smse) {
    // ignore, default is not created.
    }
    if (bCreated) {
        ResourceBundle res = ResourceBundle.getBundle(SERVER_DEFAULTS);
        Map<String, String> newValues = new HashMap<String, String>();
        for (Enumeration<String> i = res.getKeys(); i.hasMoreElements(); ) {
            String key = i.nextElement();
            String val = res.getString(key);
            if (val.equals("@" + SetupConstants.CONFIG_VAR_PLATFORM_LOCALE + "@")) {
                val = Locale.getDefault().toString();
            }
            newValues.put(key, val);
        }
        newValues.put(Constants.PROPERTY_NAME_LB_COOKIE_VALUE, DEFAULT_SERVER_ID);
        return newValues;
    } else {
        return Collections.EMPTY_MAP;
    }
}
Also used : ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) HashMap(java.util.HashMap) ResourceBundle(java.util.ResourceBundle)

Example 58 with ResourceBundle

use of java.util.ResourceBundle in project OpenAM by OpenRock.

the class AMModelBase method getServiceResourceBundle.

protected ResourceBundle getServiceResourceBundle(String serviceName) {
    ResourceBundle rb = null;
    try {
        ServiceSchemaManager mgr = new ServiceSchemaManager(serviceName, ssoToken);
        String rbName = mgr.getI18NFileName();
        if ((rbName != null) && (rbName.trim().length() > 0)) {
            rb = AMResBundleCacher.getBundle(rbName, locale);
        }
    } catch (SSOException e) {
        debug.warning("AMModelBase.getServiceResourceBundle", e);
    } catch (SMSException e) {
        debug.warning("AMModelBase.getServiceResourceBundle", e);
    }
    return rb;
}
Also used : SMSException(com.sun.identity.sm.SMSException) ResourceBundle(java.util.ResourceBundle) SSOException(com.iplanet.sso.SSOException) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

Example 59 with ResourceBundle

use of java.util.ResourceBundle in project OpenAM by OpenRock.

the class PolicyModelImpl method getSvcTypeNameToActionsMap.

private Map getSvcTypeNameToActionsMap(Policy policy, String realmName) {
    if (mapSvcTypeNameToActions == null) {
        try {
            Set serviceTypeNames = getServiceTypeNames().keySet();
            int sz = serviceTypeNames.size();
            mapSvcTypeNameToActions = new HashMap(sz * 2);
            mapSvcTypeNameToResBundle = new HashMap(sz * 2);
            ServiceTypeManager mgr = getServiceTypeManager();
            for (Iterator i = serviceTypeNames.iterator(); i.hasNext(); ) {
                String serviceTypeName = (String) i.next();
                ServiceType serviceType = mgr.getServiceType(serviceTypeName);
                if (serviceType != null) {
                    ResourceBundle rb = getResourceBundle(serviceType, getUserLocale());
                    if (rb != null) {
                        mapSvcTypeNameToResBundle.put(serviceTypeName, rb);
                        Set as = getActionSchemas(serviceType);
                        filterActionSchemaWithI18nKey(as);
                        if ((as != null) && !as.isEmpty()) {
                            mapSvcTypeNameToActions.put(serviceTypeName, as);
                            if (requiresResourceName(policy, realmName, serviceTypeName, as, true)) {
                                requiredResourceNameService.add(serviceTypeName);
                            }
                            if (requiresResourceName(policy, realmName, serviceTypeName, as, false)) {
                                notRequiredResourceNameService.add(serviceTypeName);
                            }
                        }
                    }
                }
            }
        } catch (AMConsoleException e) {
            debug.warning("PolicyModelImppl.getSvcTypeNameToActionsMap", e);
        } catch (SSOException e) {
            debug.warning("PolicyModelImppl.getSvcTypeNameToActionsMap", e);
        } catch (NameNotFoundException e) {
            debug.warning("PolicyModelImppl.getSvcTypeNameToActionsMap", e);
        }
    }
    return mapSvcTypeNameToActions;
}
Also used : ServiceTypeManager(com.sun.identity.policy.ServiceTypeManager) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) NameNotFoundException(com.sun.identity.policy.NameNotFoundException) ServiceType(com.sun.identity.policy.ServiceType) Iterator(java.util.Iterator) ResourceBundle(java.util.ResourceBundle) SSOException(com.iplanet.sso.SSOException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Example 60 with ResourceBundle

use of java.util.ResourceBundle in project OpenAM by OpenRock.

the class LoginLogoutMapping method init.

/** 
     * Initializes the servlet.
     *
     * @param servletCtx servlet config
     * @throws ServletException if it fails to get servlet context.
    */
public void init(ServletContext servletCtx) throws ServletException {
    if (isProductInitialize) {
        boolean initialized = initializeAuth(servletCtx);
        if (!initialized) {
            Locale locale = java.util.Locale.getDefault();
            ResourceBundle rb = ResourceBundle.getBundle(bundleName, locale);
            throw new ServletException(rb.getString(CANNOT_INIT_AUTH));
        }
    }
}
Also used : Locale(java.util.Locale) ResourceBundle(java.util.ResourceBundle)

Aggregations

ResourceBundle (java.util.ResourceBundle)1189 Locale (java.util.Locale)180 MissingResourceException (java.util.MissingResourceException)150 Test (org.junit.Test)100 ArrayList (java.util.ArrayList)71 HashMap (java.util.HashMap)70 IOException (java.io.IOException)67 PropertyResourceBundle (java.util.PropertyResourceBundle)56 URL (java.net.URL)48 File (java.io.File)47 Map (java.util.Map)45 InputStream (java.io.InputStream)43 Enumeration (java.util.Enumeration)34 HashSet (java.util.HashSet)30 Test (org.junit.jupiter.api.Test)30 ActionMessage (org.apache.struts.action.ActionMessage)29 MessageFormat (java.text.MessageFormat)28 ListResourceBundle (java.util.ListResourceBundle)28 Set (java.util.Set)26 Preferences (java.util.prefs.Preferences)21