📄 doubanservice.java
字号:
* @param q * 查询关键字 * @param startIndex * 开始索引 * @param maxResult * 最大返回结果数目 */ public UserFeed findUser(String q, int startIndex, int maxResult) throws IOException, ServiceException { DoubanQuery query = new DoubanQuery(new URL(Namespaces.userURLSlash)); query.setFullTextQuery(q); query.setStartIndex(startIndex); query.setMaxResults(maxResult); return query(query, UserFeed.class); } /** * 获得用户的朋友信息 * * @param userId * 要查询的用户id * @param startIndex * 开始索引 * @param maxResult * 最大返回结果数目 */ public UserFeed getUserFriends(String userId,int startIndex, int maxResult) throws IOException, ServiceException { String url = Namespaces.userURL + "/" + userId + "/friends"; DoubanQuery query = new DoubanQuery(new URL(url)); query.setStartIndex(startIndex); query.setMaxResults(maxResult); return getFeed(query, UserFeed.class); } /** * 获得图书条目信息 * * @param bookId * 要查询的图书id字符串 */ public SubjectEntry getBook(String bookId) throws IOException, ServiceException { String url = bookId; if (url.lastIndexOf("http") != 0) { url = Namespaces.bookSubjectURL + "/" + bookId; } return getEntry(url, SubjectEntry.class); } /** * 获得图书条目信息 * * @param bookId * 要查询的图书id数值 */ public SubjectEntry getBook(int bookId) throws IOException, ServiceException { String url = Namespaces.bookSubjectURL + "/" + bookId; return getEntry(url, SubjectEntry.class); } /** * 获得音乐条目信息 * * @param musicId * 要查询的音乐id字符串 */ public SubjectEntry getMusic(String musicId) throws IOException, ServiceException { String url = musicId; if (url.lastIndexOf("http") != 0) { url = Namespaces.musicSubjectURL + "/" + musicId; } return getEntry(url, SubjectEntry.class); } /** * 获得音乐条目信息 * * @param musicId * 要查询的音乐id数值 */ public SubjectEntry getMusic(int musicId) throws IOException, ServiceException { String url = Namespaces.musicSubjectURL + "/" + musicId; return getEntry(url, SubjectEntry.class); } /** * 获得电影条目信息 * * @param movieId * 要查询的电影id字符串 */ public SubjectEntry getMovie(String movieId) throws IOException, ServiceException { String url = movieId; if (url.lastIndexOf("http") != 0) { url = Namespaces.movieSubjectURL + "/" + movieId; } return getEntry(url, SubjectEntry.class); } /** * 获得电影条目信息 * * @param movieId * 要查询的电影id数值 */ public SubjectEntry getMovie(int movieId) throws IOException, ServiceException { String url = Namespaces.movieSubjectURL + "/" + movieId; return getEntry(url, SubjectEntry.class); } /** * 获得日记信息 * * @param noteId * 要查询的日记id字符串 */ public NoteEntry getNote(String noteId) throws IOException, ServiceException { String url = Namespaces.noteURL + "/" + noteId; return getEntry(url, NoteEntry.class); } /** * 获得用户的日记信息 * * @param userId * 要查询的用户id * @param startIndex * 开始索引 * @param maxResult * 最大返回结果数目 */ public NoteFeed getUserNotes(String userId, int startIndex, int maxResult) throws IOException, ServiceException { String url = Namespaces.userURL + "/" + userId + "/notes"; DoubanQuery query = new DoubanQuery(new URL(url)); query.setStartIndex(startIndex); query.setMaxResults(maxResult); return query(query, NoteFeed.class); } /** * 创建日记 * * @param title * 标题 * @param content * 内容 * @param privacy * 隐私设置(public|private|friend) * @param can_reply * 是否可以回复(yes|no) */ public NoteEntry createNote( TextConstruct title, TextConstruct content, String privacy, String can_reply) throws IOException, ServiceException { String url = Namespaces.noteCreateURL; NoteEntry ne = new NoteEntry(); if (title != null) { ne.setTitle(title); } if (content != null) { ne.setContent(content); } ArrayList<Attribute> atts = new ArrayList<Attribute>(2); Attribute a1 = new Attribute(); a1.setName("privacy"); a1.setContent(privacy); Attribute a2 = new Attribute(); a2.setName("can_reply"); a2.setContent(can_reply); atts.add(a1); atts.add(a2); ne.setAttributes(atts); return insert(new URL(url), ne); } /** * 更新日记 * * @param ne * 更新的日记条目 * @param title * 标题 * @param content * 内容 * @param privacy * 隐私设置(public|private|friend) * @param can_reply * 是否可以回复(yes|no) */ public NoteEntry updateNote(NoteEntry ne, TextConstruct title, TextConstruct content, String privacy, String can_reply) throws MalformedURLException, IOException, ServiceException { if (title != null) { ne.setTitle(title); } if (content != null) { ne.setContent(content); } ArrayList<Attribute> atts = new ArrayList<Attribute>(2); Attribute a1 = new Attribute(); a1.setName("privacy"); a1.setContent(privacy); Attribute a2 = new Attribute(); a2.setName("can_reply"); a2.setContent(can_reply); atts.add(a1); atts.add(a2); ne.setAttributes(atts); return update(new URL(ne.getId()), ne); } /** * 删除日记 * * @param ne * 删除的日记条目 */ public void deleteNote(NoteEntry ne) throws MalformedURLException, IOException, ServiceException { delete(new URL(ne.getId())); } /** * 获得用户的迷你博客信息 * * @param userId * 要查询的用户id * @param startIndex * 开始索引 * @param maxResult * 最大返回结果数目 */ public MiniblogFeed getUserMiniblogs(String userId, int startIndex, int maxResult) throws IOException, ServiceException { String url = Namespaces.userURL + "/" + userId + "/miniblog"; DoubanQuery query = new DoubanQuery(new URL(url)); query.setStartIndex(startIndex); query.setMaxResults(maxResult); return query(query, MiniblogFeed.class); } /** * 获得友邻的迷你博客信息 * * @param userId * 要查询的用户id * @param startIndex * 开始索引 * @param maxResult * 最大返回结果数目 */ public MiniblogFeed getContactsMiniblogs(String userId, int startIndex, int maxResult) throws IOException, ServiceException { String url = Namespaces.userURL + "/" + userId + "/miniblog/contacts"; DoubanQuery query = new DoubanQuery(new URL(url)); query.setStartIndex(startIndex); query.setMaxResults(maxResult); return query(query, MiniblogFeed.class); } /** * 创建我说 * * @param content * 我说的内容 */ public MiniblogEntry createSaying( TextConstruct content) throws IOException, ServiceException { String url = Namespaces.sayingCreateURL; MiniblogEntry me = new MiniblogEntry(); if (content != null) { me.setContent(content); } return insert(new URL(url), me); } /** * 删除我说 * * @param me * 删除的我说条目 */ public void deleteMiniblog(MiniblogEntry me) throws MalformedURLException, IOException, ServiceException { delete(new URL(me.getId())); } /** * 查找图书 * * @param q * 查询关键字 * @param tag * 标记的tag * @param startIndex * 开始索引 * @param maxResult * 最大返回结果数目 */ public SubjectFeed findBook(String q, String tag, int startIndex, int maxResult) throws IOException, ServiceException { SubjectQuery query = new SubjectQuery(new URL( Namespaces.bookSubjectsURL)); query.setFullTextQuery(q); query.setStartIndex(startIndex); query.setMaxResults(maxResult); query.setTag(tag); return query(query, SubjectFeed.class); } /** * 查找电影 * * @param q * 查询关键字 * @param tag * 标记的tag * @param startIndex * 开始索引 * @param maxResult * 最大返回结果数目 */ public SubjectFeed findMovie(String q, String tag, int startIndex, int maxResult) throws IOException, ServiceException { SubjectQuery query = new SubjectQuery(new URL( Namespaces.movieSubjectsURL)); query.setFullTextQuery(q); query.setStartIndex(startIndex); query.setMaxResults(maxResult); query.setTag(tag); return query(query, SubjectFeed.class); } /** * 查找音乐 * * @param q * 查询关键字 * @param tag * 标记的tag * @param startIndex * 开始索引 * @param maxResult * 最大返回结果数目 */ public SubjectFeed findMusic(String q, String tag, int startIndex, int maxResult) throws IOException, ServiceException { SubjectQuery query = new SubjectQuery(new URL( Namespaces.musicSubjectsURL)); query.setFullTextQuery(q); query.setStartIndex(startIndex); query.setMaxResults(maxResult); query.setTag(tag); return query(query, SubjectFeed.class); } /** * @deprecated 受限制的api,如果需要使用请联系douban开发团队 * 得到图书的相关条目信息 * * @param bookId * 图书id * @param startIndex * 开始索引 * @param maxResult * 最大返回结果数目 */ public SubjectFeed getBookRelated(String bookId, int startIndex, int maxResult) throws IOException, ServiceException { SubjectQuery query = new SubjectQuery(new URL(Namespaces.bookSubjectURL + "/" + bookId + "/related")); query.setStartIndex(startIndex); query.setMaxResults(maxResult); return query(query, SubjectFeed.class); } /** * @deprecated 受限制的api,如果需要使用请联系douban开发团队 * 得到电影的相关条目信息 * * @param movieId * 电影id * @param startIndex * 开始索引 * @param maxResult * 最大返回结果数目 */ public SubjectFeed getMovieRelated(String movieId, int startIndex, int maxResult) throws IOException, ServiceException { SubjectQuery query = new SubjectQuery(new URL( Namespaces.movieSubjectURL + "/" + movieId + "/related")); query.setStartIndex(startIndex);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -