public Object get()

in jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/message/MessageHelperMap.java [69:163]


    public Object get(Object arg)
    {
        Serializable argument;

        if(arg instanceof Serializable)
        {
            argument = (Serializable)arg;
        }
        else if(arg instanceof Localizable)
        {
            argument = ((Localizable)arg).toString(this.messageContext);
        }
        else
        {
            argument = arg.toString();
        }

        if("toText".equals(argument))
        {
            return  getToText();
        }

        if("toMessage".equals(argument))
        {
            return  getToMessage();
        }

        if(this.messageKey == null)
        {
            this.messageKey = "{" + argument + "}"; //always use a key - a hardcoded msg wouldn't be useful in this case

            return this;
        }

        String argumentKey = null;
        Object argumentValue = null;
        String stringArgument;
        if(argument instanceof String && ((String)argument).contains(":"))
        {
            stringArgument = ((String)argument);
            String[] keyValuePair = stringArgument.split(":");

            if(keyValuePair.length > 1)
            {
                String key = keyValuePair[0];

                if(!key.contains(" "))
                {
                    argumentKey = key;
                }
                argumentValue = stringArgument.substring(stringArgument.indexOf(":") + 1);
                String expression = argumentValue.toString().trim();
                if(expression.startsWith("#{") && expression.endsWith("}"))
                {
                    FacesContext facesContext = FacesContext.getCurrentInstance();
                    argumentValue = facesContext.getApplication()
                            .evaluateExpressionGet(facesContext, expression, Object.class);
                }
            }
        }

        if(argumentValue == null)
        {
            argumentValue = argument;
        }

        Serializable value;

        if(argumentValue instanceof Serializable)
        {
            value = (Serializable)argumentValue;
        }
        else if(argumentValue instanceof Localizable)
        {
            value = ((Localizable)argumentValue).toString(this.messageContext);
        }
        else if(argumentValue != null)
        {
            value = argumentValue.toString();
        }
        else
        {
            value = null;
        }

        if(argumentKey == null)
        {
            this.numberedArgument.add(value);
        }
        else
        {
            this.namedArgument.put(argumentKey, value);
        }
        return this;
    }