Package org.internna.iwebmvc.spring.binding

Source Code of org.internna.iwebmvc.spring.binding.LocaleBinder

/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache license, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.internna.iwebmvc.spring.binding;

import java.beans.PropertyEditorSupport;
import java.util.HashMap;
import java.util.Map;
import org.internna.iwebmvc.core.dao.DAO;
import org.internna.iwebmvc.model.core.Locale;
import org.internna.iwebmvc.model.core.Locale;
import org.internna.iwebmvc.utils.StringUtils;

/**
* Binder for Locale strings
*
* @author Jose Noheda
* @since 1.0
*/
public class LocaleBinder extends PropertyEditorSupport {

    protected DAO dao;
   
    public LocaleBinder(DAO dao) {
        this.dao = dao;
    }

    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        Locale l = (Locale) getValue();
        if (StringUtils.hasText(text)) {
            Map<String, Object> parameters = new HashMap<String, Object>(1);
            parameters.put("locale", text);
            l = (Locale) dao.findByNamedQuery(Locale.FIND_BY_LOCALE, 0, 1, parameters).get(0);
        }
        setValue(l);
    }

}
TOP

Related Classes of org.internna.iwebmvc.spring.binding.LocaleBinder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.