Example usage for twitter4j URLEntity getURL

List of usage examples for twitter4j URLEntity getURL

Introduction

In this page you can find the example usage for twitter4j URLEntity getURL.

Prototype

String getURL();

Source Link

Document

Returns the URL mentioned in the tweet.

Usage

From source file:com.freshdigitable.udonroad.module.realm.URLEntityRealm.java

License:Apache License

@NonNull
static URLEntityRealm findOrCreateFromRealm(URLEntity urlEntity, Realm realm) {
    final URLEntityRealm found = realm.where(URLEntityRealm.class).equalTo("url", urlEntity.getURL())
            .findFirst();/*from  w ww  .j ava2  s  .  c o  m*/
    if (found != null) {
        if (hasDisplayUrl(found)) {
            return found;
        }
        final URLEntityRealm expanded = findExpandedUrl(urlEntity, realm);
        if (expanded == null) {
            return found;
        }
        found.displayUrl = expanded.getDisplayURL();
        found.expandedUrl = expanded.getExpandedURL();
        return found;
    } else {
        if (hasDisplayUrl(urlEntity)) {
            return createFromRealm(urlEntity, realm);
        }
        final URLEntityRealm expanded = findExpandedUrl(urlEntity, realm);
        if (expanded != null) {
            return expanded;
        }
        return createFromRealm(urlEntity, realm);
    }
}

From source file:com.freshdigitable.udonroad.module.realm.URLEntityRealm.java

License:Apache License

@NonNull
private static URLEntityRealm createFromRealm(URLEntity urlEntity, Realm realm) {
    final URLEntityRealm created = realm.createObject(URLEntityRealm.class, urlEntity.getURL());
    created.displayUrl = urlEntity.getDisplayURL();
    created.expandedUrl = urlEntity.getExpandedURL();
    return created;
}

From source file:com.freshdigitable.udonroad.module.realm.URLEntityRealm.java

License:Apache License

@Nullable
private static URLEntityRealm findExpandedUrl(URLEntity urlEntity, Realm realm) {
    if (urlEntity.getExpandedURL() != null) {
        return null;
    }//ww w  .j  av  a  2  s .  com
    return realm.where(URLEntityRealm.class).equalTo("expandedUrl", urlEntity.getURL()).findFirst();
}

From source file:com.freshdigitable.udonroad.module.realm.UserRealm.java

License:Apache License

private boolean isNewUrlEntity(@NonNull URLEntity urlEntity) {
    if (this.urlEntity == null) {
        return true;
    }//from w w w. java  2s . c  o  m
    final String url = urlEntity.getURL();
    if (url.equals(this.urlEntity.getURL()) || url.equals(this.urlEntity.getExpandedURL())) {
        return false;
    } else {
        return true;
    }
}

From source file:com.freshdigitable.udonroad.QuotedStatusView.java

License:Apache License

@Override
protected CharSequence parseText(Status status) {
    String text = getBindingStatus(status).getText();
    final URLEntity[] urlEntities = status.getURLEntities();
    for (URLEntity u : urlEntities) {
        text = text.replace(u.getURL(), u.getDisplayURL());
    }/*from   w w  w.jav  a 2s.  c o  m*/
    return removeMediaUrl(text, status.getExtendedMediaEntities());
}

From source file:com.freshdigitable.udonroad.SpannableStringUtil.java

License:Apache License

private static List<SpanningInfo> createURLSpanningInfo(final String text, URLEntity[] urlEntities,
        @Nullable String quotedStatusIdStr) {
    List<SpanningInfo> info = new ArrayList<>(urlEntities.length);
    for (URLEntity u : urlEntities) {
        int start = text.indexOf(u.getURL());
        int end = start + u.getURL().length();
        if (isInvalidRange(text, start, end)) {
            if (TextUtils.isEmpty(u.getExpandedURL())) {
                continue;
            }//from   w w w.  j ava 2  s  . c om
            start = text.indexOf(u.getExpandedURL());
            end = start + u.getExpandedURL().length();
            if (isInvalidRange(text, start, end)) {
                continue;
            }
        }
        if (!TextUtils.isEmpty(quotedStatusIdStr) && u.getExpandedURL().contains(quotedStatusIdStr)) {
            info.add(new SpanningInfo(null, start, end, ""));
        }
        info.add(new SpanningInfo(new URLSpan(u.getExpandedURL()), start, end, u.getDisplayURL()));
    }
    return info;
}

From source file:com.freshdigitable.udonroad.StatusView.java

License:Apache License

@Override
protected String parseText(Status status) {
    final Status bindingStatus = getBindingStatus(status);
    String text = bindingStatus.getText();
    final String quotedStatusIdStr = Long.toString(bindingStatus.getQuotedStatusId());
    final URLEntity[] urlEntities = bindingStatus.getURLEntities();
    for (URLEntity u : urlEntities) {
        if (bindingStatus.getQuotedStatus() != null && u.getExpandedURL().contains(quotedStatusIdStr)) {
            text = text.replace(u.getURL(), "");
        } else {// w w  w  .ja v a  2 s.  c  o m
            text = text.replace(u.getURL(), u.getDisplayURL());
        }
    }
    return removeMediaUrl(text, bindingStatus.getExtendedMediaEntities());
}

From source file:com.freshdigitable.udonroad.UserInfoView.java

License:Apache License

private void bindURL(User user) {
    final URLEntity urlEntity = user.getURLEntity();
    if (urlEntity != null) {
        final String displayURL = urlEntity.getDisplayURL();
        final String expandedURL = urlEntity.getExpandedURL();
        final String plainUrl = urlEntity.getURL();
        bindURL(displayURL != null ? displayURL : plainUrl, expandedURL != null ? expandedURL : plainUrl);
        return;/*from   www  .j  av a 2 s .  c  o  m*/
    }
    final String url = user.getURL();
    if (!TextUtils.isEmpty(url)) {
        bindURL(url, url);
        return;
    }
    urlIcon.setVisibility(GONE);
    this.url.setVisibility(GONE);
}

From source file:com.github.daytron.twaattin.ui.tabledecorator.TweetColumnDecorator.java

License:Open Source License

void createFragmentsWithUrl(URLEntity[] urls) {

    if (urls != null) {

        for (URLEntity url : urls) {

            String expandedUrl = url.getExpandedURL();

            int start = url.getStart();
            int end = url.getEnd();

            String href = "<a href='" + expandedUrl + "' target='_blank' + title='" + expandedUrl + "'>";

            TweetFragment fragment = new TweetFragment(start, end, href + url.getURL() + "</a>");

            fragments.add(fragment);//from   w w w .  ja  v  a 2  s.c o  m
        }
    }
}

From source file:com.github.jcustenborder.kafka.connect.twitter.StatusConverter.java

License:Apache License

static Struct convertURLEntity(URLEntity uRLEntity) {
    return new Struct(SCHEMA_URL_ENTITY).put("URL", uRLEntity.getURL()).put("Text", uRLEntity.getText())
            .put("ExpandedURL", uRLEntity.getExpandedURL()).put("Start", uRLEntity.getStart())
            .put("End", uRLEntity.getEnd()).put("DisplayURL", uRLEntity.getDisplayURL());
}