2011-04-29 52 views
1

我想使用作爲Google日曆API一部分提供的新查詢繁忙時間API檢索用戶的繁忙時間。結果是一個包含忙次用戶的塊只讀飼料,看起來像下面這樣:閱讀來自Google日曆服務與Java的XML響應

<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gCal="http://schemas.google.com/gCal/2005" 
xmlns:gd="http://schemas.google.com/g/2005" 
gd:kind='calendar#freebusy' > 
    <id>http://www.google.com/calendar/feeds/default/freebusy/busy-times/liz%40example.com</id> 
    <updated>2010-03-13T00:00:00.000Z</udpated> 
    <link rel='self' 
    href='https://www.google.com/calendar/feeds/default/freebusy/busy-times/liz%40example.com' /> 
    <author> 
    <name>[email protected]</name> 
    <email>[email protected]</email> 
    </author> 
    <gCal:timeRange> 
    <gd:when startTime='2010-03-13T00:00:00Z' endTime='2010-03-14T00:00:00Z'/> 
    <gCal:timeRange> 
    <gCal:busy> 
    <gd:when startTime='2010-03-13T14:00Z' endTime='2010-03-13T14:30Z'/> 
    </gCal:busy> 
    <gCal:busy> 
    <gd:when startTime='2010-03-13T16:00Z' endTime='2010-03-13T16:30Z'/> 
    </gCal:busy> 
</entry> 

基於上述回輸,我該如何使用日曆數據API for Java來獲得的每塊忙碌的時間,以便我可以閱讀和做他們喜歡打印到終端的東西?這個返回的Feed的類型是什麼,CalendarEventFeed,CalendarFeed,...?

CalendarService service = new CalendarService("myapp-v1");   
service.setOAuthCredentials(oauthParameters, new OAuthHmacSha1Signer());  
URL feedUrl = new URL(METAFEED_URL_BASE+FREEBUSY_FEED_URL_SUFFIX+user.username()); 
CalendarEventFeed resultFeed = service.getFeed(feedUrl, CalendarEventFeed.class); 

回答

2

AppEngine支持(自1.2.8開始)JAXB XML到對象的數據綁定API。 Web上有很多示例和教程(儘管大多數注重於從XML模式生成自動類 - 您不需要這樣做)。示例:http://www.vogella.de/articles/JAXB/article.html

或者,您可以使用Calendar Data API for Java,並完全放棄XML轉換步驟。

+0

謝謝,你的回答非常有幫助,但我意識到我提出了錯誤的問題。我已編輯並重新命名我的帖子。非常感謝你讓我朝着正確的方向思考。 – mcorley 2011-05-03 03:35:46