List of usage examples for twitter4j URLEntity getDisplayURL
String getDisplayURL();
From source file:com.javielinux.utils.Utils.java
License:Apache License
static public String getTwitLoger(twitter4j.Status st) { String out = ""; String link = ""; if (st.getText().contains("(cont) http://t.co/")) { URLEntity[] urls = st.getURLEntities(); if (urls == null || urls.length <= 0) return out; for (URLEntity url : urls) { if (url.getDisplayURL() != null) { if (url.getDisplayURL().contains("tl.gd")) { link = url.getDisplayURL(); }/*from w w w.j a v a2 s . c om*/ } } if (!link.equals("")) { String id = link.substring(link.lastIndexOf("/") + 1); String strURL = "http://www.twitlonger.com/api_read/" + id; Document doc = null; try { URL url; URLConnection urlConn = null; url = new URL(strURL); urlConn = url.openConnection(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); doc = db.parse(urlConn.getInputStream()); } catch (IOException ioe) { } catch (ParserConfigurationException pce) { } catch (SAXException se) { } if (doc != null) { try { //String content = doc.getElementsByTagName("content").item(0).getChildNodes().getLength()+"";//.getFirstChild().getNodeValue(); String content = ""; NodeList nodes = doc.getElementsByTagName("content").item(0).getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { content += nodes.item(i).getNodeValue(); } if (!content.equals("")) { return content; } } catch (Exception e) { } } } } return out; }
From source file:com.mothsoft.alexis.engine.retrieval.TwitterRetrievalTaskImpl.java
License:Apache License
private List<TweetLink> readLinks(Status status) { final List<TweetLink> links = new ArrayList<TweetLink>(); if (status.getURLEntities() != null) { for (final URLEntity entity : status.getURLEntities()) { final String displayUrl = entity.getDisplayURL(); final String expandedUrl = entity.getExpandedURL(); final String url = entity.getURL(); final TweetLink link = new TweetLink((short) entity.getStart(), (short) entity.getEnd(), displayUrl, expandedUrl, url);// www. j ava2s . c o m links.add(link); } } return links; }
From source file:de.vanita5.twittnuker.util.TwitterContentUtils.java
License:Open Source License
public static String formatUserDescription(final User user) { if (user == null) return null; final String text = user.getDescription(); if (text == null) return null; final HtmlBuilder builder = new HtmlBuilder(text, false, true, true); final URLEntity[] urls = user.getDescriptionEntities(); if (urls != null) { for (final URLEntity url : urls) { final URL expanded_url = url.getExpandedURL(); if (expanded_url != null) { builder.addLink(ParseUtils.parseString(expanded_url), url.getDisplayURL(), url.getStart(), url.getEnd());/*from w w w. j av a 2 s. c o m*/ } } } return builder.build().replace("\n", "<br/>"); }
From source file:de.vanita5.twittnuker.util.TwitterContentUtils.java
License:Open Source License
private static void parseEntities(final HtmlBuilder builder, final EntitySupport entities) { // Format media. final MediaEntity[] mediaEntities = entities.getMediaEntities(); if (mediaEntities != null) { for (final MediaEntity mediaEntity : mediaEntities) { final int start = mediaEntity.getStart(), end = mediaEntity.getEnd(); final URL mediaUrl = mediaEntity.getMediaURL(); if (mediaUrl != null && start >= 0 && end >= 0) { builder.addLink(ParseUtils.parseString(mediaUrl), mediaEntity.getDisplayURL(), start, end); }/*from w w w. j a v a 2 s .com*/ } } final URLEntity[] urlEntities = entities.getURLEntities(); if (urlEntities != null) { for (final URLEntity urlEntity : urlEntities) { final int start = urlEntity.getStart(), end = urlEntity.getEnd(); final URL expandedUrl = urlEntity.getExpandedURL(); if (expandedUrl != null && start >= 0 && end >= 0) { builder.addLink(ParseUtils.parseString(expandedUrl), urlEntity.getDisplayURL(), start, end); } } } }
From source file:de.vanita5.twittnuker.util.Utils.java
License:Open Source License
public static String parseURLEntities(String text, final URLEntity[] entities) { for (URLEntity entity : entities) { final int start = entity.getStart(), end = entity.getEnd(); final String displayUrl = entity.getDisplayURL(); if (displayUrl != null && !displayUrl.isEmpty() && start >= 0 && end >= 0) { StringBuffer bf = new StringBuffer(text); return bf.replace(start, end, displayUrl).toString(); }/*from w w w . j a v a 2s. c o m*/ } return text; }
From source file:net.lacolaco.smileessence.twitter.util.TwitterUtils.java
License:Open Source License
/** * Replace urls by entities/*ww w . j ava 2 s. c om*/ * * @param text raw text * @param entities url entities * @param expand if true, use expanded url * @return replaced text */ public static String replaceURLEntities(String text, URLEntity[] entities, boolean expand) { if (TextUtils.isEmpty(text)) { return ""; } else if (entities == null) { return text; } if (entities.length == 0) { return text; } for (URLEntity entity : entities) { text = text.replace(entity.getURL(), expand ? entity.getExpandedURL() : entity.getDisplayURL()); } return text; }
From source file:net.nokok.twitduke.core.view.tweetcell.TweetPanelFactoryImpl.java
License:Open Source License
/** * ?????/*www.j a va 2s . c o m*/ * * @return ? */ @Override public Component createTweetTextArea() { String text = activeStatus.getText(); for (URLEntity entity : status.getURLEntities()) { text = text.replaceAll(entity.getURL(), entity.getDisplayURL()); } for (MediaEntity entity : status.getMediaEntities()) { text = text.replace(entity.getURL(), entity.getDisplayURL()); } JTextArea textArea = TWTextArea.newNotEditableTextArea(text); return textArea; }
From source file:net.nokok.twitduke.core.view.tweetcell.URLSlimButton.java
License:Open Source License
public URLSlimButton(URLEntity entity) { this(entity.getExpandedURL()); setText(entity.getDisplayURL()); }
From source file:nz.net.speakman.android.dreamintweets.twitterstream.TwitterStreamAdapter.java
License:Apache License
private String getClickableUrl(URLEntity entity) { return getClickableUrl(entity.getURL(), entity.getDisplayURL()); }
From source file:org.getlantern.firetweet.util.TwitterContentUtils.java
License:Open Source License
public static String formatUserDescription(final User user) { if (user == null) return null; final String text = user.getDescription(); if (text == null) return null; final HtmlBuilder builder = new HtmlBuilder(text, false, true, true); final URLEntity[] urls = user.getDescriptionEntities(); if (urls != null) { for (final URLEntity url : urls) { final String expanded_url = url.getExpandedURL(); if (expanded_url != null) { builder.addLink(expanded_url, url.getDisplayURL(), url.getStart(), url.getEnd()); }//from w w w .java 2 s.c o m } } return builder.build().replace("\n", "<br/>"); }