Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Tuesday, January 21, 2014

[JAVA] Automatic Mapping ValueObject(VO) Example

It was very useful.
On spring framework.



source code:
package com.kaudo.common.util;

import org.apache.commons.collections.map.ListOrderedMap;

public class DataMap extends ListOrderedMap {

    private static final long serialVersionUID=6723434363565852261L;

    @Override
    public Object put(Object key, Object value){
        return super.put(convert2CamelCase((String)key),value);
    }

    public static String convert2CamelCase(String underScore){
        if (underScore.indexOf('_') < 0
            && Character.isLowerCase(underScore.charAt(0))){
            return underScore;
        }
        StringBuilder result = new StringBuilder();
        boolean nextUpper = false;
        int len = underScore.length();
        for (int i = 0; i < len; i++){
            char currentChar = underScore.charAt(i);
            if (currentChar == '_'){
                nextUpper = true;
            } else {
                if (nextUpper){
                    result.append(Character.toUpperCase(currentChar));
                    nextUpper = false;
                } else {
                    result.append(Character.toLowerCase(currentChar));
                }
            }
        }
        return result.toString();
    }
}
when used in ibatis xml
<sqlMap namespace="LolDao">

 <typeAlias  alias="lolVo" type="com.kaudo.www.lol.vo.LolVo"/>
 <typeAlias  alias="dataMap" type="com.kaudo.common.util.DataMap"/>
...
...
...
 <select id="selChampionList" resultClass="dataMap"  parameterClass="lolVo">
  <![CDATA[
  SELECT /*+ LolDao.selChampionList 목록 조회 */
   id,
   name,
   displayName,
   title,
...
...
when used in dao
...
...
 @SuppressWarnings("unchecked")
 public List selChampionList(LolVo lolVo) throws SQLException {
  return (List)this.getSqlMapClient().queryForList("LolDao.selChampionList",lolVo);
 }
...
...
...

[JAVA] Login Interceptor Example

Login Interceptor Example
On Spring Framework

package com.kaudo.common.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

@Service
public class LoginCheckInterceptor extends HandlerInterceptorAdapter {

 private static final Logger logger = Logger.getLogger(SecurityInterceptor.class);

  @Override
 public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
  HttpSession session=request.getSession(false);
  @SuppressWarnings("unused")
  String referer=request.getHeader("referer");
  //logger.info(referer);
  if(session==null){
   logger.info("Intercepted by session: "+session);
   response.sendRedirect("/interceptor?url=/");
   return false;
  }
  String userid=(String)session.getAttribute("userid");
  String usertype=(String)session.getAttribute("usertype");
  if(userid==null || usertype==null || ("").equals(userid) || ("").equals(usertype)){
   logger.info("Intercepted by userid: "+userid+", usertype: "+usertype);
   response.sendRedirect("/interceptor?url=/");
   return false;
  }
  return true;
 }
}

Friday, January 17, 2014

[JAVASCRIPT/JQUERY] COOKIE FUNCTIONS setcookie, getcookie, deletecookie

Can create, modify, delete cookies.
This codes is required to jqeury library.


source code
$.setCookie=function(cookieName, cookieValue, cookieExpire, cookiePath, cookieDomain, cookieSecure){
    var cookieText=escape(cookieName)+'='+escape(cookieValue);
    cookieText+=(cookieExpire ? '; EXPIRES='+cookieExpire.toGMTString() : '');
    cookieText+=(cookiePath ? '; PATH='+cookiePath : '');
    cookieText+=(cookieDomain ? '; DOMAIN='+cookieDomain : '');
    cookieText+=(cookieSecure ? '; SECURE' : '');
    document.cookie=cookieText;
};
 
$.getCookie=function(cookieName){
    var cookieValue=null;
    if(document.cookie){
        var array=document.cookie.split((escape(cookieName)+'=')); 
        if(array.length >= 2){
            var arraySub=array[1].split(';');
            cookieValue=unescape(arraySub[0]);
        }
    }
    return cookieValue;
};
 
$.deleteCookie=function(cookieName){
    var temp=getCookie(cookieName);
    if(temp){
        setCookie(cookieName,temp,(new Date(1)));
    }
};

Monday, May 10, 2010

[SYNTAXHIGHLIGHTER] BLOG'S CODE VIEWER TOOL

아래와 같이 화면에 보여질 거예요. ^^


/**
 * SyntaxHighlighter
 */
function foo()
{
 if(counter <= 10)
  return;
 // it works!
}