본문 바로가기

Java

StringTokenizer 사용기

  protected SSO10Principal getPrincipalParameter(String prin){
 StringTokenizer st = new StringTokenizer(prin, "$");          // 디폴트로 공백이 구분자로 사용됨. 여기선 "$"이 딜리미터
 
 SSO10Principal tempPrin = new SSO10Principal(
 (st.nextToken()).trim(),
 (st.nextToken()).trim(),
 (st.nextToken()).trim(),
 (st.nextToken()).trim(),
 (st.nextToken()).trim(),
 (st.nextToken()).trim(),
 (st.nextToken()).trim(),
 (st.nextToken()).trim(),
 (st.nextToken()).trim()
 );

 String atti = st.nextToken();
//  System.out.println("  ::" + atti);



//아래와 같은 모양을 hash로 키, 벨류 값으로 파싱하고자함.
 //{deptNm=2222, jblnCd=ssss, ofcpsCd=dddd, userNmE=dudaji, empNo=1111111, schafsAuthor=, userNmC=dudaji, dftGrp=, administAuthor=, clsfCd=aaaa, userId=dudaji, gradeCd=3333, cprSeCd=, userNmK=dudaji, deptNo=2222, sclpstCd=zzzz}


 if (atti.indexOf("{") >= 0 ) //맨앞에 중괄호 삭제
 st = new StringTokenizer(atti, "{");
 
 atti = (st.nextToken()).trim();
 String[] temp = {"",""};
 while (atti.equals("") == false ) {
 int idx = atti.indexOf("=");
 int idx2 = 0;
 if((idx2 = atti.indexOf(",")) < 0){ //idx2가 0인 경우는 토큰의 종료를 뜻함.
 //idx2 = atti.indexOf("}");
 return tempPrin;
 }
//  System.out.println("idx : " + idx + "idx2 :" + idx2 + "atti" + atti);
 temp[0] = atti.substring(0, idx);
 temp[1] = atti.substring(idx, idx2);
 tempPrin.addAttribute(temp[0], temp[1]);
 
     //System.out.println(st.nextToken());
 atti = (atti.substring(idx2)).trim();
 if((atti.indexOf(",")) == 0){
 atti = (atti.substring(1)).trim();
 }
 }
 
 return tempPrin;
  }

'Java' 카테고리의 다른 글

(펌)jad  (0) 2011.03.28
ArrayList Vector, HashMap HashTable  (0) 2011.01.31
(펌)자바 객체 직렬화  (0) 2010.11.30
서버와 통신 중에 parameter의 한글 깨짐이 발생할 경우  (0) 2010.11.30
jad 클래스 디렉토리 풀기  (0) 2010.11.25