Package org.internna.iwebmvc.spring.binding

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

/*
* 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.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.internna.iwebmvc.core.context.ContextHolder;
import org.internna.iwebmvc.core.crypto.Cipherer;
import org.internna.iwebmvc.core.crypto.Decipherer;
import org.internna.iwebmvc.core.dao.DAO;
import org.internna.iwebmvc.model.Locatable;
import org.internna.iwebmvc.model.core.Color;
import org.internna.iwebmvc.model.core.Audio;
import org.internna.iwebmvc.model.core.address.Address;
import org.internna.iwebmvc.model.core.address.AddressList;
import org.internna.iwebmvc.model.core.Document;
import org.internna.iwebmvc.model.core.I18nText;
import org.internna.iwebmvc.model.core.Image;
import org.internna.iwebmvc.model.core.PlayList;
import org.internna.iwebmvc.model.core.ImageGallery;
import org.internna.iwebmvc.model.core.MultiDocument;
import org.internna.iwebmvc.model.core.Rating;
import org.internna.iwebmvc.model.core.RichText;
import org.internna.iwebmvc.model.core.Video;
import org.internna.iwebmvc.model.core.hierarchy.AbstractHierarchy;
import org.internna.iwebmvc.spring.io.LocatableClasspathScanner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

/**
* Registers IWebMvc specific binders
*
* @author Jose Noheda
* @since 1.0
*/
public abstract class AbstractBinderRegister {

    @Autowired protected LocatableClasspathScanner scanner;
    @Autowired protected ContextHolder context;
    @Autowired protected Decipherer decipherer;
    @Autowired protected Cipherer cipherer;
    @Autowired @Qualifier("persistenceFacade") protected DAO dao;

    @InitBinder
    protected void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
        binder.registerCustomEditor(String.class, new StringBinder(decipherer));
        binder.registerCustomEditor(List.class, new ListBinder(dao, decipherer));
        binder.registerCustomEditor(Color.class, new ColorBinder());
        binder.registerCustomEditor(Rating.class, new RatingBinder());
        binder.registerCustomEditor(RichText.class, new RichTextBinder());
        binder.registerCustomEditor(Audio.class, new AudioBinder(decipherer));
        binder.registerCustomEditor(Image.class, new ImageBinder(decipherer));
        binder.registerCustomEditor(Document.class, new DocumentBinder(decipherer));
        binder.registerCustomEditor(MultiDocument.class, new MultiDocumentBinder(decipherer));
        binder.registerCustomEditor(ImageGallery.class, new ImageGalleryBinder(decipherer));
        binder.registerCustomEditor(PlayList.class, new PlayListBinder(decipherer));
        binder.registerCustomEditor(Video.class, new VideoBinder(decipherer));
        binder.registerCustomEditor(I18nText.class, new I18nTextBinder(context));
        binder.registerCustomEditor(AbstractHierarchy.class, new HierarchyBinder(dao, decipherer));
        binder.registerCustomEditor(Address.class, new AddressBinder(dao, decipherer));
        binder.registerCustomEditor(AddressList.class, new AddressListBinder(dao, decipherer));
        for (Class<? extends Locatable> locatable : scanner.getCandidates())
            binder.registerCustomEditor(locatable, new DomainEntityBinder(locatable, dao, decipherer));
    }

}
TOP

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

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.