com.skplanet.tcloud.common.ParamAdvice.java Source code

Java tutorial

Introduction

Here is the source code for com.skplanet.tcloud.common.ParamAdvice.java

Source

/*
* Copyright (c) 2013 SK planet.
* All right reserved.
*
* This software is the confidential and proprietary information of SK planet.
* 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 SK planet.
*/
package com.skplanet.tcloud.common;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.ProceedingJoinPoint;

import tframe.common.util.StringUtils;

import com.skplanet.tcloud.common.annotation.TCParam;
import com.skplanet.tcloud.common.util.CommonUtil;

/**
 * @author JM
 *
 */
public class ParamAdvice {

    /** LOG4J ?  Log ? */
    protected final Log logger = LogFactory.getLog(getClass());

    public Object doParamFilter(ProceedingJoinPoint joinPoint) throws Throwable {
        TCParam controllerTcParam = joinPoint.getTarget().getClass().getAnnotation(TCParam.class);
        String targetMethodName = StringUtils.nvlStr(joinPoint.getSignature().getName()); // ex) 
        Object[] argObjs = joinPoint.getArgs(); //  ? ? ??
        //boolean isProceed            = false;                                 //  ? 
        String[] filterTypes = null;
        String[] methodNames = null;

        logger.debug("controllerTcParam : " + controllerTcParam + " >> targetMethodName : " + targetMethodName);

        try {
            if (controllerTcParam != null) {
                filterTypes = controllerTcParam.filterTypes();
                methodNames = controllerTcParam.methodNames();

                for (String methodName : methodNames) {
                    if (targetMethodName.contains(methodName))
                        doParamProcess(filterTypes, argObjs);
                }
            }
        } catch (Exception e) {
            logger.error("? AOP  !!!", e);
        }

        return joinPoint.proceed();
    }

    public void doParamProcess(String[] filterTypes, Object[] argObjs) {
        for (String filterType : filterTypes) {
            if (filterType.equals("XSS"))
                CommonUtil.filterXss(argObjs, logger);
        }
    }
}