2012-05-30 3 views
1

JSON 개체를 통해받은 문자열을 iCalendar 개체로 변환하는 방법을 구현하는 작업이 주어졌습니다. iCal4j 라이브러리를 찾았으며이를 파서로 사용하려고 시도했습니다. CalendarBuilder는 InputStream을 사용하는 것으로 보입니다.문자열을 iCalendar (ics) 객체로 변환하려면 어떻게해야합니까?

어떻게 진행합니까?

String response = jsonObj.getString("icalendar"); 

CalendarBuilder calBuiler = new CalendarBuilder(); 
Calendar calendar = calBuilder.build("???"); 
.... 

편집 : 작동 여부 :

public Calendar convertStringtoCalendar(String arg) 
{ 
    CalendarBuilder calBuiler = new CalendarBuilder(); 
    InputStream is; 
    try { 
     is = new ByteArrayInputStream(arg.getBytes("UTF-8")); 
     return calBuiler.build(is); 

    } catch (UnsupportedEncodingException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (ParserException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

    return null; 
} 
+0

에서 다운로드 할 수 있습니다 http://jfxtras.org/

에 그것을 확인하실 수 있습니다 - 그것은 어떤 일정 요소로 문자열을 구문 분석 할 수 있습니까? 문자열이 이미 전체 icalander 파일이면 충분해야하며, InputStream이 아닌 reder 여야합니다. ''StringReader reader = new StringReader (응답);''다음에''calBuilder.build (reader);'' – timaschew

답변

1

다음을 수행하여 문제를 해결했습니다.

public static Component getCalendarEvent(String myCalendarString) 
{ 
    try { 
     StringReader sin = new StringReader(myCalendarString); 
     CalendarBuilder builder = new CalendarBuilder(); 
     Calendar calendar = builder.build(sin); 

     return (Component)calendar.getComponent("VEVENT"); 

    } catch (Exception e) {e.printStackTrace();} 

    return null; 
} 
관련 문제