Search in sources :

Example 16 with FeedEntryModel

use of com.gitblit.models.FeedEntryModel in project gitblit by gitblit.

the class FeedsPanel method viewTree.

protected void viewTree() {
    FeedEntryModel entry = getSelectedSyndicatedEntry();
    Utils.browse(entry.link.replace("/commit/", "/tree/"));
}
Also used : FeedEntryModel(com.gitblit.models.FeedEntryModel)

Example 17 with FeedEntryModel

use of com.gitblit.models.FeedEntryModel in project gitblit by gitblit.

the class MessageRenderer method getTableCellRendererComponent.

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    if (isSelected)
        setBackground(table.getSelectionBackground());
    else
        setBackground(table.getBackground());
    messageLabel.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
    if (value == null) {
        return this;
    }
    FeedEntryModel entry = (FeedEntryModel) value;
    if (gitblit == null) {
        // no gitblit client, just display message
        messageLabel.setText(entry.title);
    } else {
        // show message in BOLD if its a new entry
        if (entry.published.after(gitblit.getLastFeedRefresh(entry.repository, entry.branch))) {
            messageLabel.setText("<html><body><b>" + entry.title);
        } else {
            messageLabel.setText(entry.title);
        }
    }
    // reset ref label
    resetRef(headLabel);
    resetRef(branchLabel);
    resetRef(remoteLabel);
    resetRef(tagLabel);
    int parentCount = 0;
    if (entry.tags != null) {
        for (String tag : entry.tags) {
            if (tag.startsWith("ref:")) {
                // strip ref:
                tag = tag.substring("ref:".length());
            } else {
                // count parents
                if (tag.startsWith("parent:")) {
                    parentCount++;
                }
            }
            if (tag.equals(entry.branch)) {
                // skip current branch label
                continue;
            }
            if (tag.startsWith(Constants.R_HEADS)) {
                // local branch
                showRef(tag, branchLabel);
            } else if (tag.startsWith(Constants.R_REMOTES)) {
                // remote branch
                showRef(tag, remoteLabel);
            } else if (tag.startsWith(Constants.R_TAGS)) {
                // tag
                showRef(tag, tagLabel);
            } else if (tag.equals(Constants.HEAD)) {
                // HEAD
                showRef(tag, headLabel);
            }
        }
    }
    if (parentCount > 1) {
        // multiple parents, show merge icon
        messageLabel.setIcon(mergeIcon);
    } else {
        messageLabel.setIcon(blankIcon);
    }
    return this;
}
Also used : FeedEntryModel(com.gitblit.models.FeedEntryModel)

Example 18 with FeedEntryModel

use of com.gitblit.models.FeedEntryModel in project gitblit by gitblit.

the class FeedsPanel method viewCommit.

protected void viewCommit() {
    FeedEntryModel entry = getSelectedSyndicatedEntry();
    Utils.browse(entry.link);
}
Also used : FeedEntryModel(com.gitblit.models.FeedEntryModel)

Example 19 with FeedEntryModel

use of com.gitblit.models.FeedEntryModel in project gitblit by gitblit.

the class SyndicationUtils method readFeed.

/**
	 * Reads a Gitblit RSS feed.
	 *
	 * @param url
	 *            the url of the Gitblit server
	 * @param parameters
	 *            the list of RSS parameters
	 * @param repository
	 *            the repository name
	 * @param username
	 * @param password
	 * @return a list of SyndicationModel entries
	 * @throws {@link IOException}
	 */
private static List<FeedEntryModel> readFeed(String url, List<String> parameters, String repository, String branch, String username, char[] password) throws IOException {
    // build url
    StringBuilder sb = new StringBuilder();
    sb.append(MessageFormat.format("{0}" + Constants.SYNDICATION_PATH + "{1}", url, repository));
    if (parameters.size() > 0) {
        boolean first = true;
        for (String parameter : parameters) {
            if (first) {
                sb.append('?');
                first = false;
            } else {
                sb.append('&');
            }
            sb.append(parameter);
        }
    }
    String feedUrl = sb.toString();
    URLConnection conn = ConnectionUtils.openReadConnection(feedUrl, username, password);
    InputStream is = conn.getInputStream();
    SyndFeedInput input = new SyndFeedInput();
    SyndFeed feed = null;
    try {
        feed = input.build(new XmlReader(is));
    } catch (FeedException f) {
        throw new GitBlitException(f);
    }
    is.close();
    List<FeedEntryModel> entries = new ArrayList<FeedEntryModel>();
    for (Object o : feed.getEntries()) {
        SyndEntryImpl entry = (SyndEntryImpl) o;
        FeedEntryModel model = new FeedEntryModel();
        model.repository = repository;
        model.branch = branch;
        model.title = entry.getTitle();
        model.author = entry.getAuthor();
        model.published = entry.getPublishedDate();
        model.link = entry.getLink();
        model.content = entry.getDescription().getValue();
        model.contentType = entry.getDescription().getType();
        if (entry.getCategories() != null && entry.getCategories().size() > 0) {
            List<String> tags = new ArrayList<String>();
            for (Object p : entry.getCategories()) {
                SyndCategory cat = (SyndCategory) p;
                tags.add(cat.getName());
            }
            model.tags = tags;
        }
        entries.add(model);
    }
    return entries;
}
Also used : SyndCategory(com.sun.syndication.feed.synd.SyndCategory) FeedEntryModel(com.gitblit.models.FeedEntryModel) InputStream(java.io.InputStream) FeedException(com.sun.syndication.io.FeedException) ArrayList(java.util.ArrayList) GitBlitException(com.gitblit.GitBlitException) XmlReader(com.sun.syndication.io.XmlReader) URLConnection(java.net.URLConnection) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndFeedInput(com.sun.syndication.io.SyndFeedInput) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl)

Aggregations

FeedEntryModel (com.gitblit.models.FeedEntryModel)19 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)5 Test (org.junit.Test)3 SyndCategory (com.sun.syndication.feed.synd.SyndCategory)2 SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)2 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)2 Date (java.util.Date)2 Constants (com.gitblit.Constants)1 GitBlitException (com.gitblit.GitBlitException)1 FeedModel (com.gitblit.models.FeedModel)1 ProjectModel (com.gitblit.models.ProjectModel)1 RefModel (com.gitblit.models.RefModel)1 RepositoryModel (com.gitblit.models.RepositoryModel)1 UserModel (com.gitblit.models.UserModel)1 AuthenticatedRequest (com.gitblit.servlet.AuthenticationFilter.AuthenticatedRequest)1 BugtraqProcessor (com.gitblit.utils.BugtraqProcessor)1 SyndCategoryImpl (com.sun.syndication.feed.synd.SyndCategoryImpl)1 SyndContent (com.sun.syndication.feed.synd.SyndContent)1 SyndContentImpl (com.sun.syndication.feed.synd.SyndContentImpl)1