delicious-java-discuss Mailing List for del.icio.us Java API
Brought to you by:
czarneckid
You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(9) |
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(4) |
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
2009 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Discussion l. f. delicious-j. <del...@li...> - 2009-02-23 20:04:54
|
Hi, I have a problem when trying to log, I get this error: WARNING: Cookie rejected: "$Version=0; delicious_us_production=....; $Path=/; $Domain=.delicious.com". Illegal domain attribute ".delicious.com". Domain of origin: "api.del.icio.us" What's the way to make it work correctly? Thanks Raphaël -- Web database: http://www.myowndb.com Free Software Developers Meeting: http://www.fosdem.org |
From: Discussion l. f. delicious-j. <del...@li...> - 2008-09-23 08:33:38
|
I am facing a problem that is a little strange. Whe I iterate over some existing delicious accounts and call the method getAllPosts() I get the following exception: SEVERE: org.xml.sax.SAXParseException: The markup in the document preceding the root element must be well-formed. Exception in thread "main" del.icio.us.DeliciousException: Response parsing error at del.icio.us.Delicious.getAllPosts(Delicious.java:625) at delicious.DeliciousData.getAllPostDel(DeliciousData.java:71) My sample code is: for (int i = 1; i < 10; i++) { Delicious del = new Delicious("user_"+i, "password"); int numOfPost = del.getAllPosts().size(); } Am I doing something wrong ? Best, Fred Durão |
From: Discussion l. f. delicious-j. <del...@li...> - 2008-07-30 00:11:47
|
Thanks. I filled in the missing pieces, but the changes have been checked into CVS. On 7/15/08 5:21 PM, "Discussion list for delicious-java" <del...@li...> wrote: > I only changed two files, delicious.java and post.java. I have attached the > two files. > > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > > _______________________________________________ > Delicious-java-discuss mailing list > Del...@li... > https://lists.sourceforge.net/lists/listinfo/delicious-java-discuss |
From: Discussion l. f. delicious-j. <del...@li...> - 2008-07-15 21:21:54
|
/** * Copyright (c) 2004-2007, David A. Czarnecki * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the "David A. Czarnecki" nor the names of * its contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package del.icio.us; import del.icio.us.beans.*; import org.apache.commons.httpclient.*; import org.apache.commons.httpclient.auth.AuthScope; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.params.HttpClientParams; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.StringReader; import java.net.HttpURLConnection; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * Delicious is a class for accessing the <a href="http://del.icio.us/doc/api">del.icio.us API</a>. * * @author David Czarnecki * @version $Id: Delicious.java,v 1.24 2007/01/19 00:14:43 czarneckid Exp $ * @since 1.0 */ public class Delicious { private Log logger = LogFactory.getLog(Delicious.class); private HttpClient httpClient; private DocumentBuilder documentBuilder; private String apiEndpoint; private int httpResult; private Object resultMetaInformation; /** * Create an object to interact with del.icio.us. API endpoint defaults to: http://del.icio.us/api/ * * @param username del.icio.us username * @param password del.icio.us password */ public Delicious(String username, String password) { this(username, password, DeliciousConstants.API_ENDPOINT); } /** * Create an object to interact with del.icio.us * * @param username del.icio.us username * @param password del.icio.us password * @param apiEndpoint del.icio.us API endpoint */ public Delicious(String username, String password, String apiEndpoint) { this.apiEndpoint = apiEndpoint; httpClient = new HttpClient(); HttpClientParams httpClientParams = new HttpClientParams(); DefaultHttpMethodRetryHandler defaultHttpMethodRetryHandler = new DefaultHttpMethodRetryHandler(0, false); httpClientParams.setParameter(DeliciousConstants.USER_AGENT_HEADER, DeliciousConstants.USER_AGENT_VALUE); httpClientParams.setParameter(HttpClientParams.RETRY_HANDLER, defaultHttpMethodRetryHandler); httpClient.setParams(httpClientParams); httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setValidating(false); documentBuilderFactory.setIgnoringElementContentWhitespace(true); documentBuilderFactory.setIgnoringComments(true); documentBuilderFactory.setCoalescing(true); documentBuilderFactory.setNamespaceAware(false); try { documentBuilder = documentBuilderFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { logger.error(e); } } /** * Create an object to interact with del.icio.us * * @param username del.icio.us username * @param password del.icio.us password * @param apiEndpoint del.icio.us API endpoint * @param proxyHost Proxy host * @param proxyPort Proxy port * @since 1.1 */ public Delicious(String username, String password, String apiEndpoint, String proxyHost, int proxyPort) { this(username, password, apiEndpoint); setProxyConfiguration(proxyHost, proxyPort); } /** * Sets proxy configuration information. This method must be called before * any calls to the API if you require proxy configuration. * * @param proxyHost Proxy host * @param proxyPort Proxy port * @since 1.1 */ public void setProxyConfiguration(String proxyHost, int proxyPort) { HostConfiguration hostConfiguration = new HostConfiguration(); hostConfiguration.setProxy(proxyHost, proxyPort); httpClient.setHostConfiguration(hostConfiguration); } /** * Sets proxy authentication information. This method must be called before any * calls to the API if you require proxy authentication. * * @param proxyUsername Username to access proxy * @param proxyPassword Password to access proxy * @since 1.8 */ public void setProxyAuthenticationConfiguration(String proxyUsername, String proxyPassword) { httpClient.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(proxyUsername, proxyPassword)); } /** * Set a new API endpoint which may be different from the default {@link DeliciousConstants.API_ENDPOINT} * * @param apiEndpoint New API endpoint * @since 2.0 */ public void setApiEndpoint(String apiEndpoint) { this.apiEndpoint = apiEndpoint; } /** * Return the HTTP status code of the last operation * * @return HTTP status code */ public int getHttpResult() { return httpResult; } /** * Return list of {@link DeliciousDate} objects * * @param tag Filter by this tag (optional) * @return List of {@link DeliciousDate} objects */ public List getDatesWithPost(String tag) { clearResultMetaInformation(); List dates = new ArrayList(); StringBuffer result = new StringBuffer(); GetMethod get = new GetMethod(apiEndpoint + DeliciousConstants.POSTS_DATES); get.setDoAuthentication(true); if (!DeliciousUtils.checkNullOrBlank(tag)) { NameValuePair tagParam = new NameValuePair(DeliciousConstants.TAG_PARAMETER, tag); get.setQueryString(new NameValuePair[]{tagParam}); } try { httpResult = httpClient.executeMethod(get); checkNotAuthorized(httpResult); logger.debug("Result: " + httpResult); if (get.getResponseBodyAsStream() != null) { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream(), DeliciousUtils.UTF_8)); String input; while ((input = bufferedReader.readLine()) != null) { result.append(input).append(DeliciousUtils.LINE_SEPARATOR); } get.releaseConnection(); Document document = documentBuilder.parse(new InputSource(new StringReader(result.toString()))); NodeList dateItems = document.getElementsByTagName(DeliciousConstants.DATE_TAG); if (dateItems != null && dateItems.getLength() > 0) { for (int i = 0; i < dateItems.getLength(); i++) { Node dateItem = dateItems.item(i); DeliciousDate date; String count = dateItem.getAttributes().getNamedItem(DeliciousConstants.COUNT_ATTRIBUTE).getNodeValue(); String dateAttribute = dateItem.getAttributes().getNamedItem(DeliciousConstants.DATE_ATTRIBUTE).getNodeValue(); date = new DeliciousDate(Integer.parseInt(count), dateAttribute); dates.add(date); } } } } catch (IOException e) { logger.error(e); } catch (SAXException e) { logger.error(e); throw new DeliciousException("Response parsing error", e); } return dates; } /** * Return list of {@link DeliciousDate} objects * * @return List of {@link DeliciousDate} objects * @since 2.0 */ public List getDatesWithPost() { return getDatesWithPost(null); } /** * Return a list of {@link Tag} objects * * @return List of {@link Tag} objects */ public List getTags() { clearResultMetaInformation(); List tags = new ArrayList(); StringBuffer result = new StringBuffer(); GetMethod get = new GetMethod(apiEndpoint + DeliciousConstants.TAGS_GET); get.setDoAuthentication(true); try { httpResult = httpClient.executeMethod(get); checkNotAuthorized(httpResult); logger.debug("Result: " + httpResult); if (get.getResponseBodyAsStream() != null) { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream(), DeliciousUtils.UTF_8)); String input; while ((input = bufferedReader.readLine()) != null) { result.append(input).append(DeliciousUtils.LINE_SEPARATOR); } get.releaseConnection(); Document document = documentBuilder.parse(new InputSource(new StringReader(result.toString()))); NodeList tagItems = document.getElementsByTagName(DeliciousConstants.TAG_TAG); if (tagItems != null && tagItems.getLength() > 0) { for (int i = 0; i < tagItems.getLength(); i++) { Node tagItem = tagItems.item(i); Tag tag; String count = tagItem.getAttributes().getNamedItem(DeliciousConstants.COUNT_ATTRIBUTE).getNodeValue(); String tagAttribute = tagItem.getAttributes().getNamedItem(DeliciousConstants.TAG_ATTRIBUTE).getNodeValue(); tag = new Tag(Integer.parseInt(count), tagAttribute); tags.add(tag); } } } } catch (IOException e) { logger.error(e); } catch (SAXException e) { logger.error(e); throw new DeliciousException("Response parsing error", e); } return tags; } /** * Return a list of {@link Post} objects * * @param filterTag filter by this tag (optional) * @param date Filter by this date * @param url URL of post to retrieve (if present, only retrieves a single {@link Post} object * @return List of {@link Post} objects * @since 1.8 */ public List getPosts(String filterTag, Date date, String url) { clearResultMetaInformation(); List posts = new ArrayList(); StringBuffer result = new StringBuffer(); GetMethod get = new GetMethod(apiEndpoint + DeliciousConstants.POSTS_GET); get.setDoAuthentication(true); List params = new ArrayList(); if (!DeliciousUtils.checkNullOrBlank(filterTag)) { NameValuePair tag = new NameValuePair(DeliciousConstants.TAG_PARAMETER, filterTag); params.add(tag); } if (date != null) { NameValuePair dt = new NameValuePair(DeliciousConstants.DT_PARAMETER, DeliciousUtils.getDeliciousDate(date)); params.add(dt); } if (!DeliciousUtils.checkNullOrBlank(url)) { NameValuePair urlParam = new NameValuePair(DeliciousConstants.URL_PARAMETER, url); params.add(urlParam); } if (params.size() > 0) { get.setQueryString((NameValuePair[]) params.toArray(new NameValuePair[params.size()])); } try { httpResult = httpClient.executeMethod(get); checkNotAuthorized(httpResult); logger.debug("Result: " + httpResult); if (get.getResponseBodyAsStream() != null) { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream(), DeliciousUtils.UTF_8)); String input; while ((input = bufferedReader.readLine()) != null) { result.append(input).append(DeliciousUtils.LINE_SEPARATOR); } get.releaseConnection(); Document document = documentBuilder.parse(new InputSource(new StringReader(result.toString()))); NodeList postItems = document.getElementsByTagName(DeliciousConstants.POST_TAG); if (postItems != null && postItems.getLength() > 0) { for (int i = 0; i < postItems.getLength(); i++) { Node postItem = postItems.item(i); Post post; String href = postItem.getAttributes().getNamedItem(DeliciousConstants.HREF_ATTRIBUTE).getNodeValue(); String description = postItem.getAttributes().getNamedItem(DeliciousConstants.DESCRIPTION_ATTRIBUTE).getNodeValue(); String hash = postItem.getAttributes().getNamedItem(DeliciousConstants.HASH_ATTRIBUTE).getNodeValue(); String tag = postItem.getAttributes().getNamedItem(DeliciousConstants.TAG_ATTRIBUTE).getNodeValue(); String time = postItem.getAttributes().getNamedItem(DeliciousConstants.TIME_ATTRIBUTE).getNodeValue(); String extended = null; if (postItem.getAttributes().getNamedItem(DeliciousConstants.EXTENDED_ATTRIBUTE) != null) { extended = postItem.getAttributes().getNamedItem(DeliciousConstants.EXTENDED_ATTRIBUTE).getNodeValue(); } boolean shared = true; if (postItem.getAttributes().getNamedItem(DeliciousConstants.SHARED_PARAMETER) != null) { shared = Boolean.valueOf(postItem.getAttributes().getNamedItem(DeliciousConstants.SHARED_PARAMETER).getNodeValue()).booleanValue(); } int others = 0; try { if(postItem.getAttributes().getNamedItem(DeliciousConstants.OTHERS_ATTRIBUTE) != null) { others = Integer.parseInt(postItem.getAttributes().getNamedItem(DeliciousConstants.OTHERS_ATTRIBUTE).getNodeValue()); } } catch(NumberFormatException e) { others = 0; } post = new Post(href, description, extended, hash, tag, time, shared, others); posts.add(post); } } } } catch (IOException e) { logger.error(e); } catch (SAXException e) { logger.error(e); throw new DeliciousException("Response parsing error", e); } return posts; } /** * Return a list of {@link Post} objects * * @param filterTag filter by this tag (optional) * @param date Filter by this date * @return List of {@link Post} objects */ public List getPostsForDate(String filterTag, Date date) { return getPosts(filterTag, date, null); } /** * Return a list of {@link Post} objects * * @return List of {@link Post} objects * @since 2.0 */ public List getPosts() { return getPosts(null, null, null); } /** * Return a list of {@link Post} objects for a given URL * * @param url Filter by this URL * @return List of {@link Post} objects for a given URL * @since 1.8 */ public List getPostForURL(String url) { return getPosts(null, null, url); } /** * Return a list of {@link Post} objects for a given tag * * @param tag Filter by this tag * @return List of {@link Post} objects for a given tag * @since 1.8 */ public List getPostsForTag(String tag) { return getPosts(tag, null, null); } /** * Return a list of {@link Post} objects for a given set of tags. Calls {@link #getPostsForTag(String)} for each tag. * * @param tags Filter by these tags * @return List of {@link Post} objects for the given set of tags * @since 1.8 */ public List getPostsForTags(String[] tags) { if (tags == null) { return new ArrayList(); } List postsForTags = new ArrayList(tags.length); List posts; for (int i = 0; i < tags.length; i++) { String tag = tags[i]; posts = getPostsForTag(tag); for (int j = 0; j < posts.size(); j++) { Post post = (Post) posts.get(j); postsForTags.add(post); } } return postsForTags; } /** * Return a list of {@link Post} objects * * @param filterTag filter by this tag (optional) * @param count Must be > 0 and < 100 * @return List of {@link Post} objects */ public List getRecentPosts(String filterTag, int count) { clearResultMetaInformation(); List posts = new ArrayList(); StringBuffer result = new StringBuffer(); if (count <= 0) { count = DeliciousConstants.DEFAULT_POST_COUNT; } if (count > DeliciousConstants.MAXIMUM_POST_COUNT) { count = DeliciousConstants.MAXIMUM_POST_COUNT; } GetMethod get = new GetMethod(apiEndpoint + DeliciousConstants.POSTS_RECENT); get.setDoAuthentication(true); List params = new ArrayList(); NameValuePair countParam = new NameValuePair(DeliciousConstants.COUNT_PARAMETER, Integer.toString(count)); params.add(countParam); if (!DeliciousUtils.checkNullOrBlank(filterTag)) { NameValuePair tagParam = new NameValuePair(DeliciousConstants.TAG_PARAMETER, filterTag); params.add(tagParam); } if (params.size() > 0) { get.setQueryString((NameValuePair[]) params.toArray(new NameValuePair[params.size()])); } try { httpResult = httpClient.executeMethod(get); checkNotAuthorized(httpResult); logger.debug("Result: " + httpResult); if (get.getResponseBodyAsStream() != null) { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream(), DeliciousUtils.UTF_8)); String input; while ((input = bufferedReader.readLine()) != null) { result.append(input).append(DeliciousUtils.LINE_SEPARATOR); } get.releaseConnection(); Document document = documentBuilder.parse(new InputSource(new StringReader(result.toString()))); NodeList postItems = document.getElementsByTagName(DeliciousConstants.POST_TAG); if (postItems != null && postItems.getLength() > 0) { for (int i = 0; i < postItems.getLength(); i++) { Node postItem = postItems.item(i); Post post; String href = postItem.getAttributes().getNamedItem(DeliciousConstants.HREF_ATTRIBUTE).getNodeValue(); String description = postItem.getAttributes().getNamedItem(DeliciousConstants.DESCRIPTION_ATTRIBUTE).getNodeValue(); String hash = postItem.getAttributes().getNamedItem(DeliciousConstants.HASH_ATTRIBUTE).getNodeValue(); String tag = postItem.getAttributes().getNamedItem(DeliciousConstants.TAG_ATTRIBUTE).getNodeValue(); String time = postItem.getAttributes().getNamedItem(DeliciousConstants.TIME_ATTRIBUTE).getNodeValue(); String extended = null; if (postItem.getAttributes().getNamedItem(DeliciousConstants.EXTENDED_ATTRIBUTE) != null) { extended = postItem.getAttributes().getNamedItem(DeliciousConstants.EXTENDED_ATTRIBUTE).getNodeValue(); } boolean shared = true; if (postItem.getAttributes().getNamedItem(DeliciousConstants.SHARED_PARAMETER) != null) { shared = Boolean.valueOf(postItem.getAttributes().getNamedItem(DeliciousConstants.SHARED_PARAMETER).getNodeValue()).booleanValue(); } int others = 0; try { if(postItem.getAttributes().getNamedItem(DeliciousConstants.OTHERS_ATTRIBUTE) != null) { others = Integer.parseInt(postItem.getAttributes().getNamedItem(DeliciousConstants.OTHERS_ATTRIBUTE).getNodeValue()); } } catch(NumberFormatException e) { others = 0; } post = new Post(href, description, extended, hash, tag, time, shared, others); posts.add(post); } } } } catch (IOException e) { logger.error(e); } catch (SAXException e) { logger.error(e); throw new DeliciousException("Response parsing error", e); } return posts; } /** * Return a list of {@link Post} objects * * @param filterTag filter by this tag (optional) * @return List of {@link Post} objects */ public List getRecentPosts(String filterTag) { return getRecentPosts(filterTag, DeliciousConstants.DEFAULT_POST_COUNT); } /** * Return a list of recent {@link Post} objects; uses default number of items to retrieve {@link DeliciousConstants#DEFAULT_POST_COUNT} * * @return List of {@link Post} objects * @since 2.0 */ public List getRecentPosts() { return getRecentPosts(null, DeliciousConstants.DEFAULT_POST_COUNT); } /** * Return a list of all {@link Post} objects. This method populates the result meta information * field with a {@link Date} object containing the last update time. * * @param filterTag Filter by this tag * @return List of all {@link Post} objects */ public List getAllPosts(String filterTag) { clearResultMetaInformation(); List posts = new ArrayList(); StringBuffer result = new StringBuffer(); GetMethod get = new GetMethod(apiEndpoint + DeliciousConstants.POSTS_ALL); if (!DeliciousUtils.checkNullOrBlank(filterTag)) { get.setQueryString(new NameValuePair[] {new NameValuePair(DeliciousConstants.TAG_PARAMETER, filterTag)}); } get.setDoAuthentication(true); try { httpResult = httpClient.executeMethod(get); checkNotAuthorized(httpResult); logger.debug("Result: " + httpResult); if (get.getResponseBodyAsStream() != null) { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream(), DeliciousUtils.UTF_8)); String input; while ((input = bufferedReader.readLine()) != null) { result.append(input).append(DeliciousUtils.LINE_SEPARATOR); } get.releaseConnection(); Document document = documentBuilder.parse(new InputSource(new StringReader(result.toString()))); // Parse the <posts .../> item for meta information (update attribute) NodeList postsTag = document.getElementsByTagName(DeliciousConstants.POSTS_TAG); if (postsTag != null && postsTag.getLength() > 0) { Node postsItem = postsTag.item(0); String updateTime = postsItem.getAttributes().getNamedItem(DeliciousConstants.UPDATE_ATTRIBUTE).getNodeValue(); resultMetaInformation = DeliciousUtils.getDateFromUTCString(updateTime); } // Parse the <post .../> items NodeList postItems = document.getElementsByTagName(DeliciousConstants.POST_TAG); if (postItems != null && postItems.getLength() > 0) { for (int i = 0; i < postItems.getLength(); i++) { Node postItem = postItems.item(i); Post post; String href = postItem.getAttributes().getNamedItem(DeliciousConstants.HREF_ATTRIBUTE).getNodeValue(); String description = postItem.getAttributes().getNamedItem(DeliciousConstants.DESCRIPTION_ATTRIBUTE).getNodeValue(); String hash = postItem.getAttributes().getNamedItem(DeliciousConstants.HASH_ATTRIBUTE).getNodeValue(); String tag = postItem.getAttributes().getNamedItem(DeliciousConstants.TAG_ATTRIBUTE).getNodeValue(); String time = postItem.getAttributes().getNamedItem(DeliciousConstants.TIME_ATTRIBUTE).getNodeValue(); String extended = null; if (postItem.getAttributes().getNamedItem(DeliciousConstants.EXTENDED_ATTRIBUTE) != null) { extended = postItem.getAttributes().getNamedItem(DeliciousConstants.EXTENDED_ATTRIBUTE).getNodeValue(); } boolean shared = true; if (postItem.getAttributes().getNamedItem(DeliciousConstants.SHARED_PARAMETER) != null) { shared = Boolean.valueOf(postItem.getAttributes().getNamedItem(DeliciousConstants.SHARED_PARAMETER).getNodeValue()).booleanValue(); } int others = 0; try { if(postItem.getAttributes().getNamedItem(DeliciousConstants.OTHERS_ATTRIBUTE) != null) { others = Integer.parseInt(postItem.getAttributes().getNamedItem(DeliciousConstants.OTHERS_ATTRIBUTE).getNodeValue()); } } catch(NumberFormatException e) { others = 0; } post = new Post(href, description, extended, hash, tag, time, shared, others); posts.add(post); } } } } catch (IOException e) { logger.error(e); } catch (SAXException e) { logger.error(e); throw new DeliciousException("Response parsing error", e); } return posts; } /** * Return a list of all {@link Post} objects. This method populates the result meta information * field with a {@link Date} object containing the last update time. * * @return List of all {@link Post} objects */ public List getAllPosts() { return getAllPosts(null); } /** * Make a post to del.icio.us. If either the <code>url</code> or <code>description</code> parameters are null or * blank, this method immediately returns <code>false</code>. * * @param url URL for post * @param description Description for post * @param extended Extended for post * @param tags Space-delimited list of tags * @param date Date for post * @param replace <code>true</code> if call should replace post * @param shared Make the item private * @return <code>true</code> if posted, <code>false</code> otherwise * @since 1.8 */ public boolean addPost(String url, String description, String extended, String tags, Date date, boolean replace, boolean shared) { clearResultMetaInformation(); boolean addPostResult = false; StringBuffer result = new StringBuffer(); PostMethod post = new PostMethod(apiEndpoint + DeliciousConstants.POSTS_ADD); post.setDoAuthentication(true); if (DeliciousUtils.checkNullOrBlank(url)) { return false; } if (DeliciousUtils.checkNullOrBlank(description)) { return false; } NameValuePair urlParam = new NameValuePair(DeliciousConstants.URL_PARAMETER, url); post.addParameter(urlParam); NameValuePair descriptionParam = new NameValuePair(DeliciousConstants.DESCRIPTION_PARAMETER, description); post.addParameter(descriptionParam); if (!DeliciousUtils.checkNullOrBlank(extended)) { NameValuePair extendedParam = new NameValuePair(DeliciousConstants.EXTENDED_PARAMETER, extended); post.addParameter(extendedParam); } if (!DeliciousUtils.checkNullOrBlank(tags)) { NameValuePair tagsParam = new NameValuePair(DeliciousConstants.TAGS_PARAMETER, tags); post.addParameter(tagsParam); } if (date != null) { NameValuePair dtParam = new NameValuePair(DeliciousConstants.DT_PARAMETER, DeliciousUtils.getUTCDate(date)); post.addParameter(dtParam); } NameValuePair replaceParam = new NameValuePair(); replaceParam.setName(DeliciousConstants.REPLACE_PARAMETER); replaceParam.setValue(DeliciousConstants.NO); if (replace) { replaceParam.setValue(DeliciousConstants.YES); post.addParameter(replaceParam); } if (!shared) { NameValuePair sharedParam = new NameValuePair(); sharedParam.setName(DeliciousConstants.SHARED_PARAMETER); sharedParam.setValue(DeliciousConstants.NO); post.addParameter(sharedParam); } try { post.addRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); httpResult = httpClient.executeMethod(post); checkNotAuthorized(httpResult); logger.debug("Result: " + httpResult); if (post.getResponseBodyAsStream() != null) { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(post.getResponseBodyAsStream(), DeliciousUtils.UTF_8)); String input; while ((input = bufferedReader.readLine()) != null) { result.append(input).append(DeliciousUtils.LINE_SEPARATOR); } post.releaseConnection(); if (result.indexOf(DeliciousConstants.CODE_DONE) != -1) { addPostResult = true; } } } catch (IOException e) { logger.error(e); } return addPostResult; } /** * Make a post to del.icio.us * * @param url URL for post * @param description Description for post * @param extended Extended for post * @param tags Space-delimited list of tags * @param date Date for post * @return <code>true</code> if posted, <code>false</code> otherwise */ public boolean addPost(String url, String description, String extended, String tags, Date date) { return addPost(url, description, extended, tags, date, false, true); } /** * Make a post to del.icio.us * * @param url URL for post * @param description Description for post * @return <code>true</code> if posted, <code>false</code> otherwise * @since 2.0 */ public boolean addPost(String url, String description) { return addPost(url, description, null, null, null, false, true); } /** * Deletes a post * * @param url URL for post * @return <code>true</code> if post deleted, <code>false</code> otherwise */ public boolean deletePost(String url) { clearResultMetaInformation(); boolean deletePostResult = false; StringBuffer result = new StringBuffer(); GetMethod get = new GetMethod(apiEndpoint + DeliciousConstants.POSTS_DELETE); get.setDoAuthentication(true); NameValuePair urlParam = new NameValuePair(DeliciousConstants.URL_PARAMETER, url); get.setQueryString(new NameValuePair[]{urlParam}); try { httpResult = httpClient.executeMethod(get); checkNotAuthorized(httpResult); logger.debug("Result: " + httpResult); if (get.getResponseBodyAsStream() != null) { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream(), DeliciousUtils.UTF_8)); String input; while ((input = bufferedReader.readLine()) != null) { result.append(input).append(DeliciousUtils.LINE_SEPARATOR); } get.releaseConnection(); if (result.indexOf(DeliciousConstants.CODE_DONE) != -1) { deletePostResult = true; } } } catch (IOException e) { logger.error(e); } return deletePostResult; } /** * Renames a tag * * @param oldTag Old tag * @param newTag New tag * @return <code>true</code> if tag renamed, <code>false</code> otherwise */ public boolean renameTag(String oldTag, String newTag) { clearResultMetaInformation(); boolean renameTagResult = false; StringBuffer result = new StringBuffer(); GetMethod get = new GetMethod(apiEndpoint + DeliciousConstants.TAGS_RENAME); get.setDoAuthentication(true); NameValuePair oldParam = new NameValuePair(DeliciousConstants.OLD_PARAMETER, oldTag); NameValuePair newParam = new NameValuePair(DeliciousConstants.NEW_PARAMETER, newTag); get.setQueryString(new NameValuePair[]{oldParam, newParam}); try { get.addRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); httpResult = httpClient.executeMethod(get); checkNotAuthorized(httpResult); logger.debug("Result: " + httpResult); if (get.getResponseBodyAsStream() != null) { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream(), DeliciousUtils.UTF_8)); String input; while ((input = bufferedReader.readLine()) != null) { result.append(input).append(DeliciousUtils.LINE_SEPARATOR); } get.releaseConnection(); if (result.indexOf(DeliciousConstants.CODE_DONE) != -1) { renameTagResult = true; } } } catch (IOException e) { logger.error(e); } return renameTagResult; } /** * Return a list of {@link Post} items in your inbox * * @param date Filter by this date * @return List of {@link Post} items in your inbox */ public List getInboxEntries(Date date) { clearResultMetaInformation(); List posts = new ArrayList(); StringBuffer result = new StringBuffer(); GetMethod get = new GetMethod(apiEndpoint + DeliciousConstants.INBOX_GET); get.setDoAuthentication(true); if (date != null) { NameValuePair dateParam = new NameValuePair(DeliciousConstants.DT_PARAMETER, DeliciousUtils.getDeliciousDate(date)); get.setQueryString(new NameValuePair[]{dateParam}); } try { httpResult = httpClient.executeMethod(get); checkNotAuthorized(httpResult); logger.debug("Result: " + httpResult); if (get.getResponseBodyAsStream() != null) { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream(), DeliciousUtils.UTF_8)); String input; while ((input = bufferedReader.readLine()) != null) { result.append(input).append(DeliciousUtils.LINE_SEPARATOR); } get.releaseConnection(); Document document = documentBuilder.parse(new InputSource(new StringReader(result.toString()))); NodeList postItems = document.getElementsByTagName(DeliciousConstants.POST_TAG); if (postItems != null && postItems.getLength() > 0) { for (int i = 0; i < postItems.getLength(); i++) { Node postItem = postItems.item(i); Post post; String href = postItem.getAttributes().getNamedItem(DeliciousConstants.HREF_ATTRIBUTE).getNodeValue(); String description = postItem.getAttributes().getNamedItem(DeliciousConstants.DESCRIPTION_ATTRIBUTE).getNodeValue(); String hash = postItem.getAttributes().getNamedItem(DeliciousConstants.HASH_ATTRIBUTE).getNodeValue(); String tag = postItem.getAttributes().getNamedItem(DeliciousConstants.TAG_ATTRIBUTE).getNodeValue(); String time = postItem.getAttributes().getNamedItem(DeliciousConstants.TIME_ATTRIBUTE).getNodeValue(); String extended = null; if (postItem.getAttributes().getNamedItem(DeliciousConstants.EXTENDED_ATTRIBUTE) != null) { extended = postItem.getAttributes().getNamedItem(DeliciousConstants.EXTENDED_ATTRIBUTE).getNodeValue(); } boolean shared = true; if (postItem.getAttributes().getNamedItem(DeliciousConstants.SHARED_PARAMETER) != null) { shared = Boolean.valueOf(postItem.getAttributes().getNamedItem(DeliciousConstants.SHARED_PARAMETER).getNodeValue()).booleanValue(); } int others = 0; try { if(postItem.getAttributes().getNamedItem(DeliciousConstants.OTHERS_ATTRIBUTE) != null) { others = Integer.parseInt(postItem.getAttributes().getNamedItem(DeliciousConstants.OTHERS_ATTRIBUTE).getNodeValue()); } } catch(NumberFormatException e) { others = 0; } post = new Post(href, description, extended, hash, tag, time, shared, others); posts.add(post); } } } } catch (IOException e) { logger.error(e); } catch (SAXException e) { logger.error(e); throw new DeliciousException("Response parse error", e); } return posts; } /** * Return a list of {@link DeliciousDate} objects containing inbox entries * * @return List of {@link DeliciousDate} objects containing inbox entries */ public List getDatesWithInboxEntries() { clearResultMetaInformation(); List dates = new ArrayList(); StringBuffer result = new StringBuffer(); GetMethod get = new GetMethod(apiEndpoint + DeliciousConstants.INBOX_DATES); get.setDoAuthentication(true); try { httpResult = httpClient.executeMethod(get); checkNotAuthorized(httpResult); logger.debug("Result: " + httpResult); if (get.getResponseBodyAsStream() != null) { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream(), DeliciousUtils.UTF_8)); String input; while ((input = bufferedReader.readLine()) != null) { result.append(input).append(DeliciousUtils.LINE_SEPARATOR); } get.releaseConnection(); Document document = documentBuilder.parse(new InputSource(new StringReader(result.toString()))); NodeList dateItems = document.getElementsByTagName(DeliciousConstants.DATE_TAG); if (dateItems != null && dateItems.getLength() > 0) { for (int i = 0; i < dateItems.getLength(); i++) { Node dateItem = dateItems.item(i); DeliciousDate date; String count = dateItem.getAttributes().getNamedItem(DeliciousConstants.COUNT_ATTRIBUTE).getNodeValue(); String dateAttribute = dateItem.getAttributes().getNamedItem(DeliciousConstants.DATE_ATTRIBUTE).getNodeValue(); date = new DeliciousDate(Integer.parseInt(count), dateAttribute); dates.add(date); } } } } catch (IOException e) { logger.error(e); } catch (SAXException e) { logger.error(e); throw new DeliciousException("Response parse error", e); } return dates; } /** * Return a list of {@link Subscription} objects * * @return List of {@link Subscription} objects */ public List getSubscriptions() { clearResultMetaInformation(); List subscriptions = new ArrayList(); StringBuffer result = new StringBuffer(); GetMethod get = new GetMethod(apiEndpoint + DeliciousConstants.INBOX_SUBS); get.setDoAuthentication(true); try { httpResult = httpClient.executeMethod(get); checkNotAuthorized(httpResult); logger.debug("Result: " + httpResult); if (get.getResponseBodyAsStream() != null) { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream(), DeliciousUtils.UTF_8)); String input; while ((input = bufferedReader.readLine()) != null) { result.append(input).append(DeliciousUtils.LINE_SEPARATOR); } get.releaseConnection(); Document document = documentBuilder.parse(new InputSource(new StringReader(result.toString()))); NodeList subItems = document.getElementsByTagName(DeliciousConstants.SUB_TAG); if (subItems != null && subItems.getLength() > 0) { for (int i = 0; i < subItems.getLength(); i++) { Node subItem = subItems.item(i); Subscription subscription; String tag = subItem.getAttributes().getNamedItem(DeliciousConstants.TAG_ATTRIBUTE).getNodeValue(); String user = subItem.getAttributes().getNamedItem(DeliciousConstants.USER_ATTRIBUTE).getNodeValue(); subscription = new Subscription(tag, user); subscriptions.add(subscription); } } } } catch (IOException e) { logger.error(e); } catch (SAXException e) { logger.error(e); throw new DeliciousException("Response parse error", e); } return subscriptions; } /** * Return a list of {@link Bundle} objects * * @return List of {@link Bundle} objects * @since 1.9 */ public List getBundles() { clearResultMetaInformation(); List bundles = new ArrayList(); StringBuffer result = new StringBuffer(); GetMethod get = new GetMethod(apiEndpoint + DeliciousConstants.BUNDLES_ALL); get.setDoAuthentication(true); try { httpResult = httpClient.executeMethod(get); checkNotAuthorized(httpResult); logger.debug("Result: " + httpResult); if (get.getResponseBodyAsStream() != null) { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream(), DeliciousUtils.UTF_8)); String input; while ((input = bufferedReader.readLine()) != null) { result.append(input).append(DeliciousUtils.LINE_SEPARATOR); } get.releaseConnection(); Document document = documentBuilder.parse(new InputSource(new StringReader(result.toString()))); NodeList bundleItems = document.getElementsByTagName(DeliciousConstants.BUNDLE_TAG); if (bundleItems != null && bundleItems.getLength() > 0) { for (int i = 0; i < bundleItems.getLength(); i++) { Node bundleItem = bundleItems.item(i); Bundle bundle; String name = bundleItem.getAttributes().getNamedItem(DeliciousConstants.BUNDLE_NAME_ATTRIBUTE).getNodeValue(); String tags = bundleItem.getAttributes().getNamedItem(DeliciousConstants.BUNDLE_TAGS_ATTRIBUTE).getNodeValue(); bundle = new Bundle(name, tags); bundles.add(bundle); } } } } catch (IOException e) { logger.error(e); } catch (SAXException e) { logger.error(e); throw new DeliciousException("Response parse error", e); } return bundles; } /** * Add a new tag bundle. If either the bundle name or tags is blank or null, <code>false</code> is returned immediately * * @param bundleName Bundle name * @param tags Space-separated list of tags * @return <code>true</code> if the bundle was created, <code>false</code> otherwise * @since 1.9 */ public boolean addBundle(String bundleName, String tags) { clearResultMetaInformation(); boolean addBundleResult = false; StringBuffer result = new StringBuffer(); PostMethod post = new PostMethod(apiEndpoint + DeliciousConstants.BUNDLES_SET); post.setDoAuthentication(true); if (DeliciousUtils.checkNullOrBlank(bundleName)) { return false; } if (DeliciousUtils.checkNullOrBlank(tags)) { return false; } NameValuePair bundleNameParam = new NameValuePair(DeliciousConstants.BUNDLE_PARAMETER, bundleName); NameValuePair tagsParam = new NameValuePair(DeliciousConstants.BUNDLE_TAGS_ATTRIBUTE, tags); post.setQueryString(new NameValuePair[]{bundleNameParam, tagsParam}); try { post.addRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); httpResult = httpClient.executeMethod(post); checkNotAuthorized(httpResult); logger.debug("Result: " + httpResult); if (post.getResponseBodyAsStream() != null) { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(post.getResponseBodyAsStream(), DeliciousUtils.UTF_8)); String input; while ((input = bufferedReader.readLine()) != null) { result.append(input).append(DeliciousUtils.LINE_SEPARATOR); } post.releaseConnection(); if (result.indexOf(DeliciousConstants.CODE_OK_STANDALONE) != -1) { addBundleResult = true; } } } catch (IOException e) { logger.error(e); } return addBundleResult; } /** * Delete a bundle of the given name * * @param bundleName Bundle to delete * @return <code>true</code> if the bundle was deleted, false otherwise * @since 1.9 */ public boolean deleteBundle(String bundleName) { clearResultMetaInformation(); boolean deleteBundleResult = false; StringBuffer result = new StringBuffer(); GetMethod get = new GetMethod(apiEndpoint + DeliciousConstants.BUNDLES_DELETE); get.setDoAuthentication(true); NameValuePair bundleNameParam = new NameValuePair(DeliciousConstants.BUNDLE_PARAMETER, bundleName); get.setQueryString(new NameValuePair[]{bundleNameParam}); try { httpResult = httpClient.executeMethod(get); checkNotAuthorized(httpResult); logger.debug("Result: " + httpResult); if (get.getResponseBodyAsStream() != null) { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream(), DeliciousUtils.UTF_8)); String input; while ((input = bufferedReader.readLine()) != null) { result.append(input).append(DeliciousUtils.LINE_SEPARATOR); } get.releaseConnection(); if (result.indexOf(DeliciousConstants.CODE_OK_STANDALONE) != -1) { deleteBundleResult = true; } } } catch (IOException e) { logger.error(e); } return deleteBundleResult; } /** * Add or remove a subscription * * @param user Username * @param tag Optional, set to <code>null</code> for all posts * @param unsubscribe If you want to unsubscribe * @return <code>true</code> if add/remove subscription successful, <code>false</code> otherwise */ public boolean subs(String user, String tag, boolean unsubscribe) { clearResultMetaInformation(); boolean subscribeResult = false; StringBuffer result = new StringBuffer(); GetMethod get; if (!unsubscribe) { get = new GetMethod(apiEndpoint + DeliciousConstants.INBOX_SUB); } else { get = new GetMethod(apiEndpoint + DeliciousConstants.INBOX_UNSUB); } get.setDoAuthentication(true); List params = new ArrayList(); NameValuePair userParam = new NameValuePair(DeliciousConstants.USER_PARAMETER, user); params.add(userParam); if (!DeliciousUtils.checkNullOrBlank(tag)) { NameValuePair tagParam = new NameValuePair(DeliciousConstants.TAG_PARAMETER, tag); params.add(tagParam); } if (params.size() > 0) { get.setQueryString((NameValuePair[]) params.toArray(new NameValuePair[params.size()])); } try { httpResult = httpClient.executeMethod(get); checkNotAuthorized(httpResult); logger.debug("Result: " + httpResult); if (get.getResponseBodyAsStream() != null) { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream(), DeliciousUtils.UTF_8)); String input; while ((input = bufferedReader.readLine()) != null) { result.append(input).append(DeliciousUtils.LINE_SEPARATOR); } get.releaseConnection(); if (result.indexOf(DeliciousConstants.CODE_OK) != -1) { subscribeResult = true; } } } catch (IOException e) { logger.error(e); } return subscribeResult; } /** * Get the time of the last update * * @return {@link Date} object of last update time or <code>null</code> if there was an error in the call * @since 1.3 */ public Date getLastUpdate() { clearResultMetaInformation(); StringBuffer result = new StringBuffer(); GetMethod get = new GetMethod(apiEndpoint + DeliciousConstants.POSTS_UPDATE); get.setDoAuthentication(true); try { httpResult = httpClient.executeMethod(get); checkNotAuthorized(httpResult); logger.debug("Result: " + httpResult); if (get.getResponseBodyAsStream() != null) { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream(), DeliciousUtils.UTF_8)); String input; while ((input = bufferedReader.readLine()) != null) { result.append(input).append(DeliciousUtils.LINE_SEPARATOR); } get.releaseConnection(); Document document = documentBuilder.parse(new InputSource(new StringReader(result.toString()))); NodeList updateItems = document.getElementsByTagName(DeliciousConstants.UPDATE_TAG); if (updateItems != null && updateItems.getLength() > 0) { Node updateItem = updateItems.item(0); String updateTime = updateItem.getAttributes().getNamedItem(DeliciousConstants.TIME_ATTRIBUTE).getNodeValue(); return DeliciousUtils.getDateFromUTCString(updateTime); } } } catch (IOException e) { logger.error(e); } catch (SAXException e) { logger.error(e); throw new DeliciousException("Response parse error", e); } return null; } /** * Check to see if the user is not authorized. If result is 401 (NOT_AUTHORIZED) a * {@link DeliciousNotAuthorizedException} is thrown * * @param result Result code from executing HTTP method * @since 1.4 */ protected void checkNotAuthorized(int result) { if (result == HttpURLConnection.HTTP_UNAUTHORIZED) { throw new DeliciousNotAuthorizedException(); } } /** * Clear the result meta information by setting the object to <code>null</code>. * * @since 1.3 */ protected void clearResultMetaInformation() { resultMetaInformation = null; } /** * Retrieve an object containing meta information about the last call. Only certain methods * actually populate the result meta information such as the {@link #getAllPosts()} method. * * @return Object containing meta information about the last call * @since 1.3 */ public Object getResultMetaInformation() { return resultMetaInformation; } } |
From: Discussion l. f. delicious-j. <del...@li...> - 2008-07-13 03:21:26
|
Yes, the project is still alive. Submit the patch here and I¹ll get in integrated. Thanks. -David On 7/10/08 5:51 PM, "Discussion list for delicious-java" <del...@li...> wrote: > Is this project still alive? I have written a patch that adds the inclusion > of the amount of other people who have favorited a link to the Post class. Is > there someone to send it to? > > -Zack Gomez > > > ------------------------------------------------------------------------- > Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! > Studies have shown that voting for your favorite open source project, > along with a healthy diet, reduces your potential for chronic lameness > and boredom. Vote Now at http://www.sourceforge.net/community/cca08 > > _______________________________________________ > Delicious-java-discuss mailing list > Del...@li... > https://lists.sourceforge.net/lists/listinfo/delicious-java-discuss |
From: Discussion l. f. delicious-j. <del...@li...> - 2008-07-10 21:52:05
|
Is this project still alive? I have written a patch that adds the inclusion of the amount of other people who have favorited a link to the Post class. Is there someone to send it to? -Zack Gomez |
From: Discussion l. f. delicious-j. <del...@li...> - 2006-06-06 13:19:07
|
Hmmmm, I'm really not sure on this one if it's working for the first set of posts. You might try writing to the del.icio.us support and see for your username and the time that you're trying to do the update if anything is going awry on their end. I would've expected that the delay of 2 secs in there would be sufficient, but maybe try bumping it up to 4 or 5 secs. On 6/4/06 7:55 PM, "Discussion list for delicious-java" <del...@li...> wrote: > Hi, > I am still trying to work through the problem I'm having with the > addPost() method ceasing to work after updating the 29th post. I've > creaed a stripped down version of my program as an example of the > problem. I've copied it below (it can also be seen here http:// > boydstudio.ca/p5/deliciousExample1.pde ). > > This example program tried up add a tag called 'deleteLater' to all > the Posts. Running on my computer it stalls after the 28th or 29th post. > > If you have any suggestions or ideas I'd appreciate hearing them. I'm > out of ideas at this point. > > thanks, > Steve > > > /** > * I've used some code from Marius Watz's example found > * here http://processinghacks.com/hacks:delicious > * (specifically the connection code and casting the bookmarks as Post > objects) > */ > > Delicious delicious; // create Delicious object called delicious > Object[] o; // simple object array to be used to hold the bookmark > posts to be downloaded from delicious > Post[] posts; // Post array to eventually hold the bookmark posts > (after they're cast into Post objects) > String newTag = "deleteLater"; // for the purposes of this example > this is a new tag I want to add to all my bookmarks > > int currentPost = 0; // current post being used > int startTime; // obvious > > void setup() { > // Initiate Delicious object. Replace username and password with > your own info. > delicious=new Delicious("yourUsername","yourPassword"); > delay(2000); // add in a delay ensure we're not breaking the 1 > transaction/second rule > // I doubt its necessary here but im adding it in to be safe. > > getMyPosts(); // function to go and grab some bookmarks > > startTime=millis(); // set startTime to equal the time after the > bookmarks have been grabbed. > println(""); > for(int i = 0; i < posts.length; i++) { // run through each post > float telp=(millis()-startTime)/1000.0; // telp = total elapsed time > since the grabbing the bookmarks > println("Processing post number "+i+" of "+posts.length); > processPost(posts[i]); > } > } > > void draw(){} // vestigial draw function. nothing doing here. > everything happens in setup > > void getMyPosts(){ > // Choose one of the two lines below for getting either all the > posts just a subset of the posts > // o=delicious.getAllPosts().toArray(); > o=delicious.getRecentPosts("",35).toArray(); > delay(2000); // add in a delay ensure we're not breaking the 1 > transaction/second rule > // again probably but adding it anyway > > // Convert the Objects to Posts > posts=new Post[o.length]; // set the size of the Post array > println("Del.icio.us posts retrieved: "+posts.length); > for(int i=0; i<posts.length; i++) posts[i]=(Post)o[i]; // cast > the bookmark Objects as Post objects > // back to setup() > } > > > // process one post at a time > void processPost(Post _post){ > Post currPost = _post; //currPost is the post we're operating on atm > String[] tags = currPost.getTagsAsArray(" "); // grab the tags for > this post into an array called tags > String tagString=""; > for(int i = 0; i < tags.length; i++) tagString+=tags[i]+" "; > tagString += newTag; // add the new tag to the tag list > updatePost(currPost, tagString); // send this post and its new set > of tags to be updated > } > > void updatePost(Post _p, String _cts){ > Post p = _p; > String cts = _cts; > > p.setTag(cts); // set the new tags for this post object > > println("run time just before update is sent to del.icio.us is: "+ > (millis()-startTime)/1000.0); > boolean sent = delicious.addPost(p.getHref(), p.getDescription(), > p.getExtended(), p.getTag(), p.getTimeAsDate(),true,true); > // the above line (hopefully) updates the post to del.icio.us > using the addPost method. > delay(2000); // again, delay for 2 secs to avoid getting throttled. > println("run time after sending the addPost update and running 2 > sec delay: "+(millis()-startTime)/1000.0); > println(" "); > } > > > > _______________________________________________ > Delicious-java-discuss mailing list > Del...@li... > https://lists.sourceforge.net/lists/listinfo/delicious-java-discuss -- David Czarnecki http://www.blojsom.com/blog/ | http://blojsom.sf.net |
From: Discussion l. f. delicious-j. <del...@li...> - 2006-06-06 03:02:23
|
Hi, I am still trying to work through the problem I'm having with the addPost() method ceasing to work after updating the 29th post. I've creaed a stripped down version of my program as an example of the problem. I've copied it below (it can also be seen here http:// boydstudio.ca/p5/deliciousExample1.pde ). This example program tried up add a tag called 'deleteLater' to all the Posts. Running on my computer it stalls after the 28th or 29th post. If you have any suggestions or ideas I'd appreciate hearing them. I'm out of ideas at this point. thanks, Steve /** * I've used some code from Marius Watz's example found * here http://processinghacks.com/hacks:delicious * (specifically the connection code and casting the bookmarks as Post objects) */ Delicious delicious; // create Delicious object called delicious Object[] o; // simple object array to be used to hold the bookmark posts to be downloaded from delicious Post[] posts; // Post array to eventually hold the bookmark posts (after they're cast into Post objects) String newTag = "deleteLater"; // for the purposes of this example this is a new tag I want to add to all my bookmarks int currentPost = 0; // current post being used int startTime; // obvious void setup() { // Initiate Delicious object. Replace username and password with your own info. delicious=new Delicious("yourUsername","yourPassword"); delay(2000); // add in a delay ensure we're not breaking the 1 transaction/second rule // I doubt its necessary here but im adding it in to be safe. getMyPosts(); // function to go and grab some bookmarks startTime=millis(); // set startTime to equal the time after the bookmarks have been grabbed. println(""); for(int i = 0; i < posts.length; i++) { // run through each post float telp=(millis()-startTime)/1000.0; // telp = total elapsed time since the grabbing the bookmarks println("Processing post number "+i+" of "+posts.length); processPost(posts[i]); } } void draw(){} // vestigial draw function. nothing doing here. everything happens in setup void getMyPosts(){ // Choose one of the two lines below for getting either all the posts just a subset of the posts // o=delicious.getAllPosts().toArray(); o=delicious.getRecentPosts("",35).toArray(); delay(2000); // add in a delay ensure we're not breaking the 1 transaction/second rule // again probably but adding it anyway // Convert the Objects to Posts posts=new Post[o.length]; // set the size of the Post array println("Del.icio.us posts retrieved: "+posts.length); for(int i=0; i<posts.length; i++) posts[i]=(Post)o[i]; // cast the bookmark Objects as Post objects // back to setup() } // process one post at a time void processPost(Post _post){ Post currPost = _post; //currPost is the post we're operating on atm String[] tags = currPost.getTagsAsArray(" "); // grab the tags for this post into an array called tags String tagString=""; for(int i = 0; i < tags.length; i++) tagString+=tags[i]+" "; tagString += newTag; // add the new tag to the tag list updatePost(currPost, tagString); // send this post and its new set of tags to be updated } void updatePost(Post _p, String _cts){ Post p = _p; String cts = _cts; p.setTag(cts); // set the new tags for this post object println("run time just before update is sent to del.icio.us is: "+ (millis()-startTime)/1000.0); boolean sent = delicious.addPost(p.getHref(), p.getDescription(), p.getExtended(), p.getTag(), p.getTimeAsDate(),true,true); // the above line (hopefully) updates the post to del.icio.us using the addPost method. delay(2000); // again, delay for 2 secs to avoid getting throttled. println("run time after sending the addPost update and running 2 sec delay: "+(millis()-startTime)/1000.0); println(" "); } |
From: <del...@li...> - 2006-05-26 23:28:52
|
Hello again (Dave), I'm not sure if I've found a bug or just something I need to work =20 around. When I process a post which has '=BB' (») in its Description, =20= the entire Description String is replaced with "BADSTRING". This url is an example of a website with a Description that gets =20 changed: http://spacing.ca/photoblog/?page_id=3D42 Is this working as intended? If so, is there a list of characters =20 that are acceptable that I can use as a filter in my program? One more question. I am trying to add Date/Time tags to all my post. =20 My program's methodology is to download all my posts and then process =20= and repost each one on a 2 second delay so that I don't get throttled =20= by the api. Everything is working fine until I get to the 28th post. =20= At that point, I get nothing in response from del.icio.us, it =20 basically just seems to stall. Have you encountered this before? I'm fairly sure its not a bug on my end (although Im first to admit =20 I've said that before and been wrong!). I have tested it on three =20 different accounts and gotten the same result so I'm fairly sure the =20 issue is not with the content of a particular post. Weird. Thanks again, stephen http://boydstudio.ca/ |
From: <del...@li...> - 2006-05-18 22:27:42
|
sweet! thanks very much. that did it. Im retagging all my bookmarks to include date/time info. On 18/05/06, del...@li... < del...@li...> wrote: > > The signature for the addPost method is: > > > public boolean addPost(String url, String description, String > extended, > String tags, Date date, boolean replace, > boolean shared) > > The 5th parameter needs to be a Date object, not a String. Try > p.getTimeAsDate(): > > boolean sent =3D delicious.addPost(p.getHref(), p.getDescription (), > p.getExtended(), p.getTag(), p.getTimeAsDate(),replace,true); > > That should work. Don't know why I didn't spot this before. Maybe it > sneaked past if you weren't using an IDE that could do type checking sinc= e > that should've caught it. > > > On 5/18/06 3:40 PM, "del...@li..." = < > del...@li...> wrote: > > Hi David, > I've downloaded 1.12 and put in sketch's code folder (im using Processing > 115) > My new addPost() looks like this: > > boolean replace =3D true; > boolean sent =3D delicious.addPost(p.getHref(), p.getDescription (), > p.getExtended(), p.getTag(), p.getTime(),replace,true); > > > I'm getting a similar error: > /tmp/build49099.tmp/Temporary_6850_6591.java:102:16:102:120: Semantic > Error: No applicable overload for a method with signature "addPost( > java.lang.String, java.lang.String , java.lang.String, java.lang.String, > java.lang.String, boolean, boolean)" was found in type " > del.icio.us.Delicious". Perhaps you wanted the overloaded version "boolea= n > addPost(java.lang.String $1, java.lang.String $2, java.lang.String $3, > java.lang.String $4, java.util.Date $5, boolean $6, boolean $7);" instead= ? > > btw: I'm using OS X, 10.4.5, java ver 1.4.2_09 > > Are there restrictions on how the strings are formatted? > > thanks, > steve > > > On 17/05/06, *Stephen Boyd* <ss...@gm... <mailto:ss...@gm...= ><ss...@gm...>> wrote: > > Ok. thanks. I'll give it a shot. > > On 17/05/06, del...@li... > <mailto:del...@li...><delicious-jav= a-d...@li...> > > < del...@li... > <mailto:del...@li...><delicious-jav= a-d...@li...>> wrote: > > The addPost method in the latest release (1.12 - just released about 20 > min > > ago) has the following signature: > > > > public boolean addPost(String url, String description, String extended, > > String tags, Date date, boolean replace, > boolean > > shared) > > > > So, you'd need to make a call like: > > > > boolean replace =3D true; > > boolean sent =3D delicious.addPost (p.getHref(), p.getDescription(), > > p.getExtended(), p.getTag(), p.getTime(), replace, true); > > > > > > On 5/17/06 11:04 AM, " > del...@li... > <mailto:del...@li...><delicious-jav= a-d...@li...>" > > > <del...@li...> wrote: > > > > > Semantic Error: No applicable overload for a method with signature > > > > -- > > David Czarnecki > > http://www.blojsom.com/blog/ | http://blojsom.sf.net > |
From: <del...@li...> - 2006-05-18 20:38:03
|
The signature for the addPost method is: public boolean addPost(String url, String description, String extended, String tags, Date date, boolean replace, boolean shared) The 5th parameter needs to be a Date object, not a String. Try p.getTimeAsDate(): boolean sent =3D delicious.addPost(p.getHref(), p.getDescription (), p.getExtended(), p.getTag(), p.getTimeAsDate(),replace,true); That should work. Don=B9t know why I didn=B9t spot this before. Maybe it sneake= d past if you weren=B9t using an IDE that could do type checking since that should=B9ve caught it. On 5/18/06 3:40 PM, "del...@li..." <del...@li...> wrote: > Hi David, > I've downloaded 1.12 and put in sketch's code folder (im using Processing= 115) > My new addPost() looks like this: >=20 > boolean replace =3D true; > boolean sent =3D delicious.addPost(p.getHref(), p.getDescription (), > p.getExtended(), p.getTag(), p.getTime(),replace,true); >=20 >=20 > I'm getting a similar error: > /tmp/build49099.tmp/Temporary_6850_6591.java:102:16:102:120: Semantic Err= or: > No applicable overload for a method with signature "addPost(java.lang.Str= ing, > java.lang.String , java.lang.String, java.lang.String, java.lang.String, > boolean, boolean)" was found in type "del.icio.us.Delicious". Perhaps you > wanted the overloaded version "boolean addPost(java.lang.String $1, > java.lang.String $2, java.lang.String $3, java.lang.String $4, java.util= .Date > $5, boolean $6, boolean $7);" instead? >=20 > btw: I'm using OS X, 10.4.5, java ver 1.4.2_09 >=20 > Are there restrictions on how the strings are formatted? >=20 > thanks, > steve >=20 >=20 > On 17/05/06, Stephen Boyd <ss...@gm... <mailto:ss...@gm...> = > > wrote: >> Ok. thanks. I'll give it a shot. >>=20 >> On 17/05/06, del...@li... >> <mailto:del...@li...> >> < del...@li... >> <mailto:del...@li...> > wrote: >>> > The addPost method in the latest release (1.12 - just released about = 20 >>> min >>> > ago) has the following signature: >>> > >>> > public boolean addPost(String url, String description, String extende= d, >>> > String tags, Date date, boolean replace, >>> boolean >>> > shared) >>> > >>> > So, you'd need to make a call like: >>> > >>> > boolean replace =3D true; >>> > boolean sent =3D delicious.addPost (p.getHref(), p.getDescription(), >>> > p.getExtended(), p.getTag(), p.getTime(), replace, true); >>> > >>> > >>> > On 5/17/06 11:04 AM, " del...@li...urceforge= .net >>> <mailto:del...@li...> " >>> > <del...@li...> wrote: >>> > >>>> > > Semantic Error: No applicable overload for a method with signature >=20 --=20 David Czarnecki http://www.blojsom.com/blog/ | http://blojsom.sf.net |
From: <del...@li...> - 2006-05-18 19:40:32
|
Hi David, I've downloaded 1.12 and put in sketch's code folder (im using Processing 115) My new addPost() looks like this: boolean replace =3D true; boolean sent =3D delicious.addPost(p.getHref(), p.getDescription(), p.getExtended(), p.getTag(), p.getTime(),replace,true); I'm getting a similar error: /tmp/build49099.tmp/Temporary_6850_6591.java:102:16:102:120: Semantic Error= : No applicable overload for a method with signature "addPost(java.lang.Strin= g, java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean, boolean)" was found in type "del.icio.us.Delicious". Perhaps you wanted the overloaded version "boolean addPost(java.lang.String $1, java.lang.String $2, java.lang.String $3, java.lang.String $4, java.util.Date $5, boolean $6, boolean $7);" instead? btw: I'm using OS X, 10.4.5, java ver 1.4.2_09 Are there restrictions on how the strings are formatted? thanks, steve On 17/05/06, Stephen Boyd <ss...@gm...> wrote: > > Ok. thanks. I'll give it a shot. > > On 17/05/06, del...@li... > < del...@li...> wrote: > > The addPost method in the latest release (1.12 - just released about 20 > min > > ago) has the following signature: > > > > public boolean addPost(String url, String description, String extended, > > String tags, Date date, boolean replace, > boolean > > shared) > > > > So, you'd need to make a call like: > > > > boolean replace =3D true; > > boolean sent =3D delicious.addPost (p.getHref(), p.getDescription(), > > p.getExtended(), p.getTag(), p.getTime(), replace, true); > > > > > > On 5/17/06 11:04 AM, "del...@li...= t > " > > <del...@li...> wrote: > > > > > Semantic Error: No applicable overload for a method with signature |
From: <del...@li...> - 2006-05-17 15:15:45
|
Ok. thanks. I'll give it a shot. On 17/05/06, del...@li... <del...@li...> wrote: > The addPost method in the latest release (1.12 - just released about 20 m= in > ago) has the following signature: > > public boolean addPost(String url, String description, String extended, > String tags, Date date, boolean replace, boole= an > shared) > > So, you'd need to make a call like: > > boolean replace =3D true; > boolean sent =3D delicious.addPost(p.getHref(), p.getDescription(), > p.getExtended(), p.getTag(), p.getTime(), replace, true); > > > On 5/17/06 11:04 AM, "del...@li..." > <del...@li...> wrote: > > > Semantic Error: No applicable overload for a method with signature > > -- > David Czarnecki > > http://www.blojsom.com/blog/ | http://blojsom.sf.net > > > > > ------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job ea= sier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronim= o > http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat= =3D121642 > _______________________________________________ > Delicious-java-discuss mailing list > Del...@li... > https://lists.sourceforge.net/lists/listinfo/delicious-java-discuss > |
From: <del...@li...> - 2006-05-17 15:13:17
|
The addPost method in the latest release (1.12 - just released about 20 min ago) has the following signature: public boolean addPost(String url, String description, String extended, String tags, Date date, boolean replace, boolean shared) So, you'd need to make a call like: boolean replace = true; boolean sent = delicious.addPost(p.getHref(), p.getDescription(), p.getExtended(), p.getTag(), p.getTime(), replace, true); On 5/17/06 11:04 AM, "del...@li..." <del...@li...> wrote: > Semantic Error: No applicable overload for a method with signature -- David Czarnecki http://www.blojsom.com/blog/ | http://blojsom.sf.net |
From: <del...@li...> - 2006-05-17 15:04:25
|
Ha. That would explain the lack of an archive! Thanks for the response. I am trying to modify a post object and the use the addPost() method to upload the changes I've made. This is the code I'm using for addPost(), where p is a post object: boolean replace =3D true; boolean sent =3D delicious.addPost(p.getHref(), p.getDescription(), p.getExtended(), p.getTag(), p.getTime(),replace); This is the error I'm receiving: Semantic Error: No applicable overload for a method with signature "addPost(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean)" was found in type "del.icio.us.Delicious". Perhaps you wanted the overloaded version "boolean addPost(java.lang.String $1, java.lang.String $2, java.lang.String $3, java.lang.String $4, java.util.Date $5, boolean $6);" instead? I am relatively new to using libraries so I suspect there is something I'm missing here. Thanks in advance. steve On 08/05/06, del...@li... <del...@li...> wrote: > Steve- > > You could be the first post to the list which is why it's not archived. W= hat > error are you seeing with addPost? > > |
From: <del...@li...> - 2006-05-08 08:30:14
|
Steve- You could be the first post to the list which is why it's not archived. What error are you seeing with addPost? On 5/8/06 1:55 AM, "del...@li..." <del...@li...> wrote: > Hi, > I just joined the mailing list to check the archives. According to > sourceforge the archives don't exist. > > Is this list active? Im hoping to get some help with an error Im > running into with addPost(); > > Steve > > > ------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642 > _______________________________________________ > Delicious-java-discuss mailing list > Del...@li... > https://lists.sourceforge.net/lists/listinfo/delicious-java-discuss -- David Czarnecki http://www.blojsom.com/blog/ | http://blojsom.sf.net |
From: <del...@li...> - 2006-05-08 05:55:06
|
Hi, I just joined the mailing list to check the archives. According to sourceforge the archives don't exist. Is this list active? Im hoping to get some help with an error Im running into with addPost(); Steve |