Search in sources :

Example 1 with L10NMessage

use of com.sun.identity.shared.locale.L10NMessage in project OpenAM by OpenRock.

the class ChainedException method getCompleteL10NMessage.

/**
     * Returns localized error message.
     * 
     * @param locale
     *            Input locale.
     * @see #ChainedException(String, String, Object[], Throwable)
     * @return localized error message.
     */
public String getCompleteL10NMessage(java.util.Locale locale) {
    String result = _errorCode;
    if (_bundleName != null && locale != null) {
        _bundle = amCache.getResBundle(_bundleName, locale);
        String mid = _bundle.getString(_errorCode);
        if (_args == null || _args.length == 0) {
            result = mid;
        } else {
            result = MessageFormat.format(mid, _args);
        }
    }
    String chainedMessage = null;
    if (_nestedException != null) {
        if (_nestedException instanceof L10NMessage) {
            L10NMessage lex = (L10NMessage) _nestedException;
            chainedMessage = lex.getL10NMessage(locale);
        } else {
            chainedMessage = _nestedException.getMessage();
        }
    }
    if (chainedMessage != null) {
        result = result + "\n" + chainedMessage;
    }
    return result;
}
Also used : L10NMessage(com.sun.identity.shared.locale.L10NMessage)

Example 2 with L10NMessage

use of com.sun.identity.shared.locale.L10NMessage in project OpenAM by OpenRock.

the class AddCircleOfTrustMembers method handleRequest.

/**
     * Adds member to a circle of trust.
     *
     * @param rc Request Context.
     * @throws CLIException if unable to process this request.
     */
@Override
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();
    realm = getStringOptionValue(FedCLIConstants.ARGUMENT_REALM, "/");
    cot = getStringOptionValue(FedCLIConstants.ARGUMENT_COT);
    spec = FederationManager.getIDFFSubCommandSpecification(rc);
    entityID = getStringOptionValue(FedCLIConstants.ARGUMENT_ENTITY_ID);
    String[] params = { realm, entityID, cot, spec };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_COT_MEMBER", params);
    try {
        CircleOfTrustManager cotManager = new CircleOfTrustManager(ssoToken);
        cotManager.addCircleOfTrustMember(realm, cot, spec, entityID);
        Object[] objs = { spec, cot, entityID, realm };
        getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("add-circle-of-trust-member-succeeded"), objs));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_ADD_COT_MEMBER", params);
    } catch (COTException e) {
        debugWarning("AddCircleOfTrustMembers.handleRequest", e);
        if (e instanceof L10NMessage) {
            String[] args = { realm, entityID, cot, spec, ((L10NMessage) e).getL10NMessage(getCommandManager().getLocale()) };
            writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_COT_MEMBER", args);
            throw new CLIException(((L10NMessage) e).getL10NMessage(getCommandManager().getLocale()), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        } else {
            String[] args = { realm, entityID, cot, spec, e.getMessage() };
            writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_COT_MEMBER", args);
            throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
    }
}
Also used : CircleOfTrustManager(com.sun.identity.cot.CircleOfTrustManager) L10NMessage(com.sun.identity.shared.locale.L10NMessage) CLIException(com.sun.identity.cli.CLIException) COTException(com.sun.identity.cot.COTException)

Example 3 with L10NMessage

use of com.sun.identity.shared.locale.L10NMessage in project OpenAM by OpenRock.

the class ChainedException method getCompleteL10NMessage.

/**
     * @param locale <code>Locale</code> to be used.
     * @return String localized error message.
     * @see #ChainedException(String, String, Object[], Throwable)
     */
public String getCompleteL10NMessage(java.util.Locale locale) {
    String result = _message;
    if (_errorCode != null && _bundleName != null && locale != null) {
        _bundle = amCache.getResBundle(_bundleName, locale);
        String mid = _bundle.getString(_errorCode);
        if (_args == null || _args.length == 0) {
            result = mid;
        } else {
            result = MessageFormat.format(mid, _args);
        }
    }
    String chainedMessage = null;
    if (_nestedException != null) {
        if (_nestedException instanceof L10NMessage) {
            L10NMessage lex = (L10NMessage) _nestedException;
            chainedMessage = lex.getL10NMessage(locale);
        } else {
            chainedMessage = _nestedException.getMessage();
        }
    }
    if (chainedMessage != null) {
        if (result != null) {
            result = result + "\n" + chainedMessage;
        } else {
            result = chainedMessage;
        }
    }
    return result;
}
Also used : L10NMessage(com.sun.identity.shared.locale.L10NMessage)

Example 4 with L10NMessage

use of com.sun.identity.shared.locale.L10NMessage in project OpenAM by OpenRock.

the class AuthenticationServiceV1 method getLocalizedMessage.

/**
     * Get the localized message for the requested language if the given exception or its cause
     * is an instance of <code>L10NMessage</code>.
     *
     * @param exception The exception that contains the localized message.
     *
     * @return The localized message.
     */
protected String getLocalizedMessage(Request request, Exception exception) {
    AcceptLanguageHeader languages = null;
    try {
        languages = request.getHeaders().get(AcceptLanguageHeader.class);
    } catch (MalformedHeaderException e) {
        DEBUG.warning("Could not parse accept language header", e);
    }
    String message = null;
    L10NMessage localizedException = null;
    if (exception instanceof L10NMessage) {
        localizedException = (L10NMessage) exception;
    } else if (exception.getCause() instanceof L10NMessage) {
        localizedException = (L10NMessage) exception.getCause();
    }
    if (localizedException != null) {
        if (languages == null) {
            message = localizeMessage(localizedException, Locale.getDefaultLocale());
        } else {
            for (java.util.Locale language : languages.getLocales().getLocales()) {
                message = localizeMessage(localizedException, language);
                if (message != null) {
                    break;
                }
            }
        }
    }
    if (message == null) {
        message = exception.getMessage();
    }
    return message;
}
Also used : L10NMessage(com.sun.identity.shared.locale.L10NMessage) AcceptLanguageHeader(org.forgerock.http.header.AcceptLanguageHeader) MalformedHeaderException(org.forgerock.http.header.MalformedHeaderException)

Example 5 with L10NMessage

use of com.sun.identity.shared.locale.L10NMessage in project OpenAM by OpenRock.

the class AuthLoginException method getL10NMessage.

/**
     * Returns the localized message of the given locale.
     *
     * @param locale
     *            the locale in which the message will be returned.
     * @return String localized error message.
     *
     * @supported.api
     */
public String getL10NMessage(Locale locale) {
    String result = super.getMessage();
    if (_bundleName != null && locale != null && _errorCode != null) {
        _bundle = amCache.getResBundle(_bundleName, locale);
        String mid = _bundle.getString(_errorCode);
        if (_args == null || _args.length == 0) {
            result = mid;
        } else {
            result = MessageFormat.format(mid, _args);
        }
    }
    String chainedMessage = null;
    Throwable nestedException = getCause();
    if (nestedException != null) {
        if (nestedException instanceof L10NMessage) {
            L10NMessage lex = (L10NMessage) nestedException;
            chainedMessage = lex.getL10NMessage(locale);
        } else {
            chainedMessage = nestedException.getMessage();
        }
    }
    if (result == null) {
        result = chainedMessage;
    } else if (chainedMessage != null) {
        result = result + "\n" + chainedMessage;
    }
    return result;
}
Also used : L10NMessage(com.sun.identity.shared.locale.L10NMessage)

Aggregations

L10NMessage (com.sun.identity.shared.locale.L10NMessage)6 CLIException (com.sun.identity.cli.CLIException)1 COTException (com.sun.identity.cot.COTException)1 CircleOfTrustManager (com.sun.identity.cot.CircleOfTrustManager)1 AcceptLanguageHeader (org.forgerock.http.header.AcceptLanguageHeader)1 MalformedHeaderException (org.forgerock.http.header.MalformedHeaderException)1