lishengzhao
11 years ago
17 changed files with 2 additions and 510 deletions
@ -1,44 +0,0 @@
|
||||
/* |
||||
* Copyright (c) 2013 Honyee Industry Group Co., Ltd |
||||
* www.honyee.biz |
||||
* All rights reserved. |
||||
* |
||||
* This software is the confidential and proprietary information of |
||||
* Honyee Industry Group Co., Ltd ("Confidential Information"). |
||||
* You shall not disclose such Confidential Information and shall use |
||||
* it only in accordance with the terms of the license agreement you |
||||
* entered into with Honyee Industry Group Co., Ltd. |
||||
*/ |
||||
package cc.wdcy.domain.shared; |
||||
|
||||
import org.springframework.context.ApplicationContext; |
||||
|
||||
/** |
||||
* @author Shengzhao Li |
||||
*/ |
||||
public abstract class BeanProvider { |
||||
|
||||
private static ApplicationContext applicationContext; |
||||
|
||||
|
||||
public static void initialize(ApplicationContext applicationContext) { |
||||
BeanProvider.applicationContext = applicationContext; |
||||
} |
||||
|
||||
/** |
||||
* Get Bean by clazz. |
||||
* |
||||
* @param clazz Class |
||||
* @param <T> class type |
||||
* @return Bean instance |
||||
*/ |
||||
public static <T> T getBean(Class<T> clazz) { |
||||
return applicationContext.getBean(clazz); |
||||
} |
||||
|
||||
@SuppressWarnings("unchecked") |
||||
public static <T> T getBean(String beanId) { |
||||
return (T) applicationContext.getBean(beanId); |
||||
} |
||||
|
||||
} |
@ -1,179 +0,0 @@
|
||||
/* |
||||
* Copyright (c) 2013 Honyee Industry Group Co., Ltd |
||||
* www.honyee.biz |
||||
* All rights reserved. |
||||
* |
||||
* This software is the confidential and proprietary information of |
||||
* Honyee Industry Group Co., Ltd ("Confidential Information"). |
||||
* You shall not disclose such Confidential Information and shall use |
||||
* it only in accordance with the terms of the license agreement you |
||||
* entered into with Honyee Industry Group Co., Ltd. |
||||
*/ |
||||
package cc.wdcy.domain.shared.paginated; |
||||
|
||||
import cc.wdcy.domain.shared.security.SecurityUtils; |
||||
import org.displaytag.pagination.PaginatedList; |
||||
import org.displaytag.properties.SortOrderEnum; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author Shengzhao Li |
||||
*/ |
||||
public class DefaultPaginated<T> implements Paginated<T>, PaginatedList { |
||||
|
||||
public static final int DEFAULT_PER_PAGE_SIZE = 20; |
||||
|
||||
protected List<T> list = new ArrayList<T>(); |
||||
protected int perPageSize; |
||||
protected int totalSize = 0; |
||||
protected int pageNumber = 1; |
||||
|
||||
protected String sortName; |
||||
protected PaginatedSort sort; |
||||
|
||||
protected String sortCriterion; |
||||
private SortOrderEnum sortOrderEnum; |
||||
private String searchId; |
||||
|
||||
|
||||
public DefaultPaginated() { |
||||
this(DEFAULT_PER_PAGE_SIZE); |
||||
} |
||||
|
||||
public DefaultPaginated(int perPageSize) { |
||||
this.perPageSize = perPageSize; |
||||
} |
||||
|
||||
@Override |
||||
public List<T> getList() { |
||||
return list; |
||||
} |
||||
|
||||
public Map<String, Object> defaultQueryMap() { |
||||
Map<String, Object> map = new HashMap<>(); |
||||
map.put("user", SecurityUtils.currentUser()); |
||||
map.put("perPageSize", getPerPageSize()); |
||||
map.put("startIndex", getStartIndex()); |
||||
return map; |
||||
} |
||||
|
||||
public int getTotalPages() { |
||||
if (totalSize % perPageSize == 0) { |
||||
return (totalSize / perPageSize); |
||||
} else { |
||||
return (totalSize / perPageSize) + 1; |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public int getPageNumber() { |
||||
return pageNumber; |
||||
} |
||||
|
||||
@Override |
||||
public int getObjectsPerPage() { |
||||
return perPageSize; |
||||
} |
||||
|
||||
@Override |
||||
public int getFullListSize() { |
||||
return totalSize; |
||||
} |
||||
|
||||
@Override |
||||
public String getSortCriterion() { |
||||
return sortCriterion; |
||||
} |
||||
|
||||
public void setSortCriterion(String sortCriterion) { |
||||
this.sortCriterion = sortCriterion; |
||||
} |
||||
|
||||
@Override |
||||
public SortOrderEnum getSortDirection() { |
||||
return sortOrderEnum; |
||||
} |
||||
|
||||
@Override |
||||
public String getSearchId() { |
||||
return searchId; |
||||
} |
||||
|
||||
@Override |
||||
public int getPerPageSize() { |
||||
return perPageSize; |
||||
} |
||||
|
||||
@Override |
||||
public int getTotalSize() { |
||||
return totalSize; |
||||
} |
||||
|
||||
@Override |
||||
public String getSortName() { |
||||
return sortName; |
||||
} |
||||
|
||||
@Override |
||||
public PaginatedSort getSort() { |
||||
return sort; |
||||
} |
||||
|
||||
public int getStartIndex() { |
||||
return (getPageNumber() - 1) * getPerPageSize(); |
||||
} |
||||
|
||||
@SuppressWarnings("unchecked") |
||||
public <K extends Paginated> K load(PaginatedLoader<T> paginatedLoader) { |
||||
if (this.totalSize == 0) { |
||||
this.totalSize = paginatedLoader.loadTotalSize(); |
||||
} |
||||
this.list = paginatedLoader.loadList(); |
||||
afterLoad(); |
||||
return (K) this; |
||||
} |
||||
|
||||
public void afterLoad() { |
||||
// Callback after load data.
|
||||
} |
||||
|
||||
public void setPerPageSize(int perPageSize) { |
||||
this.perPageSize = perPageSize; |
||||
} |
||||
|
||||
public void setTotalSize(int totalSize) { |
||||
this.totalSize = totalSize; |
||||
} |
||||
|
||||
public void setPageNumber(int pageNumber) { |
||||
this.pageNumber = pageNumber; |
||||
} |
||||
|
||||
public void setSortName(String sortName) { |
||||
this.sortName = sortName; |
||||
} |
||||
|
||||
public void setSort(PaginatedSort sort) { |
||||
this.sort = sort; |
||||
} |
||||
|
||||
public boolean isHasNext() { |
||||
return (getStartIndex() + this.perPageSize < totalSize); |
||||
} |
||||
|
||||
public boolean isHasPrevious() { |
||||
return getStartIndex() != 0; |
||||
} |
||||
|
||||
public void setSortOrderEnum(SortOrderEnum sortOrderEnum) { |
||||
this.sortOrderEnum = sortOrderEnum; |
||||
} |
||||
|
||||
public void setSearchId(String searchId) { |
||||
this.searchId = searchId; |
||||
} |
||||
} |
@ -1,35 +0,0 @@
|
||||
/* |
||||
* Copyright (c) 2013 Honyee Industry Group Co., Ltd |
||||
* www.honyee.biz |
||||
* All rights reserved. |
||||
* |
||||
* This software is the confidential and proprietary information of |
||||
* Honyee Industry Group Co., Ltd ("Confidential Information"). |
||||
* You shall not disclose such Confidential Information and shall use |
||||
* it only in accordance with the terms of the license agreement you |
||||
* entered into with Honyee Industry Group Co., Ltd. |
||||
*/ |
||||
package cc.wdcy.domain.shared.paginated; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author Shengzhao Li |
||||
*/ |
||||
|
||||
public interface Paginated<T> { |
||||
|
||||
List<T> getList(); |
||||
|
||||
int getPageNumber(); |
||||
|
||||
int getPerPageSize(); |
||||
|
||||
int getTotalSize(); |
||||
|
||||
String getSortName(); |
||||
|
||||
PaginatedSort getSort(); |
||||
|
||||
int getTotalPages(); |
||||
} |
@ -1,26 +0,0 @@
|
||||
/* |
||||
* Copyright (c) 2013 Honyee Industry Group Co., Ltd |
||||
* www.honyee.biz |
||||
* All rights reserved. |
||||
* |
||||
* This software is the confidential and proprietary information of |
||||
* Honyee Industry Group Co., Ltd ("Confidential Information"). |
||||
* You shall not disclose such Confidential Information and shall use |
||||
* it only in accordance with the terms of the license agreement you |
||||
* entered into with Honyee Industry Group Co., Ltd. |
||||
*/ |
||||
package cc.wdcy.domain.shared.paginated; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author Shengzhao Li |
||||
*/ |
||||
|
||||
public interface PaginatedLoader<T> { |
||||
|
||||
List<T> loadList(); |
||||
|
||||
int loadTotalSize(); |
||||
|
||||
} |
@ -1,30 +0,0 @@
|
||||
/* |
||||
* Copyright (c) 2013 Honyee Industry Group Co., Ltd |
||||
* www.honyee.biz |
||||
* All rights reserved. |
||||
* |
||||
* This software is the confidential and proprietary information of |
||||
* Honyee Industry Group Co., Ltd ("Confidential Information"). |
||||
* You shall not disclose such Confidential Information and shall use |
||||
* it only in accordance with the terms of the license agreement you |
||||
* entered into with Honyee Industry Group Co., Ltd. |
||||
*/ |
||||
package cc.wdcy.domain.shared.paginated; |
||||
|
||||
/** |
||||
* @author Shengzhao Li |
||||
*/ |
||||
public enum PaginatedSort { |
||||
ASC("asc"), |
||||
DESC("desc"); |
||||
|
||||
private String label; |
||||
|
||||
PaginatedSort(String label) { |
||||
this.label = label; |
||||
} |
||||
|
||||
public String getLabel() { |
||||
return label; |
||||
} |
||||
} |
@ -1,22 +0,0 @@
|
||||
/* |
||||
* Copyright (c) 2013 Honyee Industry Group Co., Ltd |
||||
* www.honyee.biz |
||||
* All rights reserved. |
||||
* |
||||
* This software is the confidential and proprietary information of |
||||
* Honyee Industry Group Co., Ltd ("Confidential Information"). |
||||
* You shall not disclose such Confidential Information and shall use |
||||
* it only in accordance with the terms of the license agreement you |
||||
* entered into with Honyee Industry Group Co., Ltd. |
||||
*/ |
||||
package cc.wdcy.domain.shared.security; |
||||
|
||||
/** |
||||
* @author Shengzhao Li |
||||
*/ |
||||
|
||||
public interface SecurityHolder { |
||||
|
||||
WdcyUserDetails userDetails(); |
||||
|
||||
} |
@ -1,31 +0,0 @@
|
||||
/* |
||||
* Copyright (c) 2013 Honyee Industry Group Co., Ltd |
||||
* www.honyee.biz |
||||
* All rights reserved. |
||||
* |
||||
* This software is the confidential and proprietary information of |
||||
* Honyee Industry Group Co., Ltd ("Confidential Information"). |
||||
* You shall not disclose such Confidential Information and shall use |
||||
* it only in accordance with the terms of the license agreement you |
||||
* entered into with Honyee Industry Group Co., Ltd. |
||||
*/ |
||||
package cc.wdcy.domain.shared.security; |
||||
|
||||
import cc.wdcy.domain.user.User; |
||||
|
||||
/** |
||||
* @author Shengzhao Li |
||||
*/ |
||||
public class SecurityUtils { |
||||
|
||||
private static SecurityHolder securityHolder; |
||||
|
||||
public void setSecurityHolder(SecurityHolder securityHolder) { |
||||
SecurityUtils.securityHolder = securityHolder; |
||||
} |
||||
|
||||
public static User currentUser() { |
||||
WdcyUserDetails userDetails = securityHolder.userDetails(); |
||||
return (userDetails != null ? userDetails.user() : null); |
||||
} |
||||
} |
@ -1,33 +0,0 @@
|
||||
/* |
||||
* Copyright (c) 2013 Honyee Industry Group Co., Ltd |
||||
* www.honyee.biz |
||||
* All rights reserved. |
||||
* |
||||
* This software is the confidential and proprietary information of |
||||
* Honyee Industry Group Co., Ltd ("Confidential Information"). |
||||
* You shall not disclose such Confidential Information and shall use |
||||
* it only in accordance with the terms of the license agreement you |
||||
* entered into with Honyee Industry Group Co., Ltd. |
||||
*/ |
||||
package cc.wdcy.web.context; |
||||
|
||||
import cc.wdcy.domain.shared.BeanProvider; |
||||
import org.springframework.web.context.ContextLoaderListener; |
||||
import org.springframework.web.context.WebApplicationContext; |
||||
import org.springframework.web.context.support.WebApplicationContextUtils; |
||||
|
||||
import javax.servlet.ServletContextEvent; |
||||
|
||||
/** |
||||
* @author Shengzhao Li |
||||
*/ |
||||
public class BeanContextLoaderListener extends ContextLoaderListener { |
||||
|
||||
|
||||
@Override |
||||
public void contextInitialized(ServletContextEvent event) { |
||||
super.contextInitialized(event); |
||||
WebApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(event.getServletContext()); |
||||
BeanProvider.initialize(applicationContext); |
||||
} |
||||
} |
@ -1,36 +0,0 @@
|
||||
/* |
||||
* Copyright (c) 2013 Honyee Industry Group Co., Ltd |
||||
* www.honyee.biz |
||||
* All rights reserved. |
||||
* |
||||
* This software is the confidential and proprietary information of |
||||
* Honyee Industry Group Co., Ltd ("Confidential Information"). |
||||
* You shall not disclose such Confidential Information and shall use |
||||
* it only in accordance with the terms of the license agreement you |
||||
* entered into with Honyee Industry Group Co., Ltd. |
||||
*/ |
||||
package cc.wdcy.web.context; |
||||
|
||||
import cc.wdcy.domain.shared.security.WdcyUserDetails; |
||||
import cc.wdcy.domain.shared.security.SecurityHolder; |
||||
import org.springframework.security.core.Authentication; |
||||
import org.springframework.security.core.context.SecurityContextHolder; |
||||
|
||||
/** |
||||
* @author Shengzhao Li |
||||
*/ |
||||
public class SpringSecurityHolder implements SecurityHolder { |
||||
|
||||
@Override |
||||
public WdcyUserDetails userDetails() { |
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); |
||||
if (authentication == null) { |
||||
return null; |
||||
} |
||||
Object principal = authentication.getPrincipal(); |
||||
if (principal instanceof WdcyUserDetails) { |
||||
return (WdcyUserDetails) principal; |
||||
} |
||||
return null; |
||||
} |
||||
} |
Loading…
Reference in new issue