Search in sources :

Example 16 with SyndContentImpl

use of com.rometools.rome.feed.synd.SyndContentImpl in project nci-ctd2-dashboard by CBIIT.

the class RssController method generateFeed.

private String generateFeed(List<? extends DashboardEntity> dashboardEntities, String rssTitlePostfix, String rssDescription, String rssLink) {
    String dashboardUrl = context.getScheme() + "://" + context.getServerName() + context.getContextPath() + "/";
    // Set the stage and define metadata on the RSS feed
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType("rss_2.0");
    feed.setTitle("CTD^2 Dashboard - " + rssTitlePostfix);
    feed.setDescription(rssDescription);
    feed.setLink(rssLink);
    // We will have two major categories: Subject and Submission
    // and will have subcategories of Subject for each particular subject
    List<SyndCategory> categories = new ArrayList<SyndCategory>();
    SyndCategory subjectCategory = new SyndCategoryImpl();
    subjectCategory.setName("Subject");
    categories.add(subjectCategory);
    SyndCategory submissionCategory = new SyndCategoryImpl();
    submissionCategory.setName("Submission");
    categories.add(submissionCategory);
    feed.setCategories(categories);
    feed.setLanguage("en");
    feed.setManagingEditor("ocg@mail.nih.gov (CTD^2 Network)");
    SyndImage feedImg = new SyndImageImpl();
    feedImg.setTitle("CTD^2 Logo");
    feedImg.setUrl(dashboardUrl + "img/logos/ctd2_overall.png");
    feedImg.setLink(dashboardUrl);
    feed.setImage(feedImg);
    // And prepare the items to be put into the RSS
    List<SyndEntry> rssItems = new ArrayList<SyndEntry>();
    for (DashboardEntity entity : dashboardEntities) {
        if (entity instanceof Subject) {
            Subject subject = (Subject) entity;
            // Collect all role & submission pairs for this particular subject
            Map<Submission, Set<String>> roleMap = new HashMap<Submission, Set<String>>();
            Map<Submission, Set<ObservedSubject>> osMap = new HashMap<Submission, Set<ObservedSubject>>();
            List<ObservedSubject> sObservations = dashboardDao.findObservedSubjectBySubject((Subject) entity);
            for (ObservedSubject sObservation : sObservations) {
                String role = sObservation.getObservedSubjectRole().getSubjectRole().getDisplayName();
                Submission submission = sObservation.getObservation().getSubmission();
                Set<String> roles = roleMap.get(submission);
                if (roles == null) {
                    roles = new HashSet<String>();
                    roleMap.put(submission, roles);
                }
                roles.add(role);
                Set<ObservedSubject> oses = osMap.get(submission);
                if (oses == null) {
                    oses = new HashSet<ObservedSubject>();
                    osMap.put(submission, oses);
                }
                oses.add(sObservation);
            }
            // These will always belong to "Subject"
            List<SyndCategory> sCategories = new ArrayList<SyndCategory>();
            sCategories.add(subjectCategory);
            // and "Subject/<name>" categories
            SyndCategory sCategory = new SyndCategoryImpl();
            sCategory.setName(subjectCategory.getName() + "/" + entity.getDisplayName());
            categories.add(sCategory);
            // Also add this specific category to the global list
            sCategories.add(sCategory);
            // And now combine this information into individual items around submissions/subject
            for (Submission submission : roleMap.keySet()) {
                Set<String> roles = roleMap.get(submission);
                assert roles != null;
                Set<ObservedSubject> oses = osMap.get(submission);
                assert oses != null;
                SyndEntry item = new SyndEntryImpl();
                item.setCategories(sCategories);
                // Construct title
                ObservationTemplate observationTemplate = submission.getObservationTemplate();
                String description = observationTemplate.getDescription();
                Integer tier = observationTemplate.getTier();
                String combinedRoles = StringUtils.join(roles, ", ");
                String name = subject.getDisplayName();
                int noOfObservations = oses.size();
                StringBuilder title = new StringBuilder();
                title.append("Role '").append(combinedRoles).append("'").append(": ").append(description).append(" ").append("(").append("Tier ").append(tier).append(" - ").append(noOfObservations).append(" ").append(noOfObservations > 1 ? "observations" : "observation").append(" on ").append(name).append(")");
                item.setTitle(title.toString());
                String centerName = observationTemplate.getSubmissionCenter().getDisplayName();
                item.setAuthor(centerName);
                item.setPublishedDate(submission.getSubmissionDate());
                String submissionDescription = observationTemplate.getSubmissionDescription();
                StringBuilder itemDescStr = new StringBuilder();
                itemDescStr.append("<b>Project</b>: ").append(observationTemplate.getProject()).append("<br />");
                if (submissionDescription != null && !submissionDescription.isEmpty()) {
                    itemDescStr.append("<b>Summary</b>: ").append(submissionDescription);
                }
                SyndContent itemDesc = new SyndContentImpl();
                itemDesc.setType("text/html");
                itemDesc.setValue(itemDescStr.toString());
                item.setDescription(itemDesc);
                // Create a link to the subject page with filters enabled
                item.setLink(dashboardUrl + "#subject/" + subject.getId() + "/" + combinedRoles + "/" + tier);
                item.setUri(String.format("#ctd2#subject#%s#%d", name, title.hashCode() & Integer.MAX_VALUE));
                rssItems.add(item);
            }
        // End of subject-centered items
        } else if (entity instanceof Submission) {
            Submission submission = (Submission) entity;
            SyndEntry item = new SyndEntryImpl();
            ObservationTemplate observationTemplate = submission.getObservationTemplate();
            int noOfObservations = dashboardDao.findObservationsBySubmission(submission).size();
            StringBuilder title = new StringBuilder();
            Boolean isStory = observationTemplate.getIsSubmissionStory();
            title.append(isStory ? "Story" : "Submission").append(": ");
            title.append(observationTemplate.getDescription().replaceAll("\\.$", "")).append(" (").append("Tier ").append(observationTemplate.getTier()).append(" - ").append(noOfObservations).append(" ").append(noOfObservations > 1 ? "observations" : "observation").append(")");
            item.setTitle(title.toString());
            String submissionDescription = observationTemplate.getSubmissionDescription();
            StringBuilder itemDescStr = new StringBuilder();
            itemDescStr.append("<b>Project</b>: ").append(observationTemplate.getProject()).append("<br />");
            if (submissionDescription != null && !submissionDescription.isEmpty()) {
                itemDescStr.append("<b>Summary</b>: ").append(submissionDescription);
            }
            SyndContent itemDesc = new SyndContentImpl();
            itemDesc.setType("text/html");
            itemDesc.setValue(itemDescStr.toString());
            item.setDescription(itemDesc);
            item.setPublishedDate(submission.getSubmissionDate());
            String centerName = observationTemplate.getSubmissionCenter().getDisplayName();
            item.setAuthor(centerName);
            item.setLink(dashboardUrl + "#submission/" + submission.getId());
            item.setUri(String.format("ctd2#submission#%d", title.hashCode() & Integer.MAX_VALUE));
            rssItems.add(item);
        }
    // End of submission item(s)
    }
    // Add all items into the feed
    feed.setEntries(rssItems);
    // And print the XML/RSS version out
    SyndFeedOutput feedOutput = new SyndFeedOutput();
    String feedStr = null;
    try {
        feedStr = feedOutput.outputString(feed, true);
    } catch (FeedException e) {
        e.printStackTrace();
    }
    return feedStr;
}
Also used : SyndCategory(com.rometools.rome.feed.synd.SyndCategory) SyndImageImpl(com.rometools.rome.feed.synd.SyndImageImpl) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) ArrayList(java.util.ArrayList) SyndFeedOutput(com.rometools.rome.io.SyndFeedOutput) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) DashboardEntity(gov.nih.nci.ctd2.dashboard.model.DashboardEntity) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) SyndImage(com.rometools.rome.feed.synd.SyndImage) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) Submission(gov.nih.nci.ctd2.dashboard.model.Submission) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) FeedException(com.rometools.rome.io.FeedException) Subject(gov.nih.nci.ctd2.dashboard.model.Subject) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) SyndCategoryImpl(com.rometools.rome.feed.synd.SyndCategoryImpl) SyndContent(com.rometools.rome.feed.synd.SyndContent) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject)

Example 17 with SyndContentImpl

use of com.rometools.rome.feed.synd.SyndContentImpl in project commafeed by Athou.

the class Entry method asRss.

public SyndEntry asRss() {
    SyndEntry entry = new SyndEntryImpl();
    entry.setUri(getGuid());
    entry.setTitle(getTitle());
    entry.setAuthor(getAuthor());
    SyndContentImpl content = new SyndContentImpl();
    content.setValue(getContent());
    entry.setContents(Arrays.<SyndContent>asList(content));
    if (getEnclosureUrl() != null) {
        SyndEnclosureImpl enclosure = new SyndEnclosureImpl();
        enclosure.setType(getEnclosureType());
        enclosure.setUrl(getEnclosureUrl());
        entry.setEnclosures(Arrays.<SyndEnclosure>asList(enclosure));
    }
    entry.setLink(getUrl());
    entry.setPublishedDate(getDate());
    return entry;
}
Also used : SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) SyndEnclosureImpl(com.rometools.rome.feed.synd.SyndEnclosureImpl)

Example 18 with SyndContentImpl

use of com.rometools.rome.feed.synd.SyndContentImpl in project Silverpeas-Components by Silverpeas.

the class RssLastPublicationsServlet method toSyndEntry.

public SyndEntry toSyndEntry(PublicationDetail publication, String serverURL, String lang) throws MalformedURLException {
    final int maxUrlLength = 256;
    SyndEntry entry = new SyndEntryImpl();
    entry.setTitle(publication.getTitle());
    StringBuilder url = new StringBuilder(maxUrlLength);
    url.append(serverURL);
    url.append(URLUtil.getSimpleURL(URLUtil.URL_PUBLI, publication.getPK().getId()));
    entry.setLink(url.toString());
    entry.setPublishedDate(publication.getCreationDate());
    entry.setUpdatedDate(publication.getLastUpdateDate());
    SyndContent description = new SyndContentImpl();
    description.setType("text/plan");
    description.setValue(publication.getDescription(lang));
    entry.setDescription(description);
    String creatorId = publication.getUpdaterId();
    if (StringUtil.isDefined(creatorId)) {
        UserDetail creator = adminController.getUserDetail(creatorId);
        if (creator != null) {
            entry.setAuthor(creator.getDisplayedName());
        }
    }
    return entry;
}
Also used : UserDetail(org.silverpeas.core.admin.user.model.UserDetail) SyndContent(com.rometools.rome.feed.synd.SyndContent) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl)

Example 19 with SyndContentImpl

use of com.rometools.rome.feed.synd.SyndContentImpl in project BIMserver by opensourceBIM.

the class SyndicationServlet method writeRevisionsFeed.

private void writeRevisionsFeed(HttpServletRequest request, HttpServletResponse response, ServiceMap serviceMap) throws IOException, FeedException, ServiceException, PublicInterfaceNotFoundException {
    long poid = Long.parseLong(request.getParameter("poid"));
    SProject sProject = serviceMap.getServiceInterface().getProjectByPoid(poid);
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType(FEED_TYPE);
    feed.setTitle("BIMserver.org revisions feed for project '" + sProject.getName() + "'");
    feed.setLink(request.getContextPath());
    feed.setDescription("This feed represents all the revisions of project '" + sProject.getName() + "'");
    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    try {
        List<SRevision> allRevisionsOfProject = serviceMap.getServiceInterface().getAllRevisionsOfProject(poid);
        Collections.sort(allRevisionsOfProject, new SRevisionIdComparator(false));
        for (SRevision sVirtualRevision : allRevisionsOfProject) {
            SUser user = serviceMap.getServiceInterface().getUserByUoid(sVirtualRevision.getUserId());
            SyndEntry entry = new SyndEntryImpl();
            entry.setTitle("Revision " + sVirtualRevision.getOid());
            entry.setLink(request.getContextPath() + "/revision.jsp?poid=" + sVirtualRevision.getOid() + "&roid=" + sVirtualRevision.getOid());
            entry.setPublishedDate(sVirtualRevision.getDate());
            SyndContent description = new SyndContentImpl();
            description.setType("text/html");
            description.setValue("<table><tr><td>User</td><td>" + user.getUsername() + "</td></tr><tr><td>Comment</td><td>" + sVirtualRevision.getComment() + "</td></tr></table>");
            entry.setDescription(description);
            entries.add(entry);
        }
    } catch (ServiceException e) {
        LOGGER.error("", e);
    }
    feed.setEntries(entries);
    SyndFeedOutput output = new SyndFeedOutput();
    output.output(feed, response.getWriter());
}
Also used : SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) SUser(org.bimserver.interfaces.objects.SUser) ArrayList(java.util.ArrayList) SyndFeedOutput(com.rometools.rome.io.SyndFeedOutput) SProject(org.bimserver.interfaces.objects.SProject) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SRevision(org.bimserver.interfaces.objects.SRevision) SyndContent(com.rometools.rome.feed.synd.SyndContent) ServiceException(org.bimserver.shared.exceptions.ServiceException) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) SRevisionIdComparator(org.bimserver.shared.comparators.SRevisionIdComparator)

Example 20 with SyndContentImpl

use of com.rometools.rome.feed.synd.SyndContentImpl in project asterixdb by apache.

the class RSSFeedServlet method getFeed.

protected SyndFeed getFeed(IServletRequest req) throws IOException, FeedException, ParseException {
    SyndFeed feed = new SyndFeedImpl();
    feed.setTitle("Sample Feed (created with ROME)");
    feed.setLink("http://rome.dev.java.net");
    feed.setDescription("This feed has been created using ROME (Java syndication utilities");
    List<SyndEntry> entries = new ArrayList<>();
    SyndEntry entry;
    SyndContent description;
    entry = new SyndEntryImpl();
    entry.setTitle("AsterixDB 0.8.7");
    entry.setLink("http://http://asterixdb.apache.org/docs/0.8.7-incubating/index.html");
    entry.setPublishedDate(DATE_PARSER.parse("2012-06-08"));
    description = new SyndContentImpl();
    description.setType("text/plain");
    description.setValue("AsterixDB 0.8.7 Release");
    entry.setDescription(description);
    entries.add(entry);
    entry = new SyndEntryImpl();
    entry.setTitle("Couchbase 4.1");
    entry.setLink("http://blog.couchbase.com/2015/december/introducing-couchbase-server-4.1");
    entry.setPublishedDate(DATE_PARSER.parse("2015-12-09"));
    description = new SyndContentImpl();
    description.setType("text/plain");
    description.setValue("Couchbase Server 4.1 Release. Bug fixes, minor API changes and some new features");
    entry.setDescription(description);
    entries.add(entry);
    entry = new SyndEntryImpl();
    entry.setTitle("ROME v0.3");
    entry.setLink("http://wiki.java.net/bin/view/Javawsxml/rome03");
    entry.setPublishedDate(DATE_PARSER.parse("2004-07-27"));
    description = new SyndContentImpl();
    description.setType("text/html");
    description.setValue("<p>Bug fixes, API changes, some new features and some Unit testing</p>" + "<p>For details check the <a href=\"https://rometools.jira.com/wiki/display/ROME/Change+Log#" + "ChangeLog-Changesmadefromv0.3tov0.4\">Changes Log for 0.3</a></p>");
    entry.setDescription(description);
    entries.add(entry);
    entry = new SyndEntryImpl();
    entry.setTitle("ROME v0.4");
    entry.setLink("http://wiki.java.net/bin/view/Javawsxml/rome04");
    entry.setPublishedDate(DATE_PARSER.parse("2004-09-24"));
    description = new SyndContentImpl();
    description.setType("text/html");
    description.setValue("<p>Bug fixes, API changes, some new features, Unit testing completed</p>" + "<p>For details check the <a href=\"https://rometools.jira.com/wiki/display/ROME/Change+Log#" + "ChangeLog-Changesmadefromv0.4tov0.5\">Changes Log for 0.4</a></p>");
    entry.setDescription(description);
    entries.add(entry);
    feed.setEntries(entries);
    return feed;
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndContent(com.rometools.rome.feed.synd.SyndContent) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) ArrayList(java.util.ArrayList) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl)

Aggregations

SyndContentImpl (com.rometools.rome.feed.synd.SyndContentImpl)32 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)28 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)26 SyndContent (com.rometools.rome.feed.synd.SyndContent)24 SyndFeedImpl (com.rometools.rome.feed.synd.SyndFeedImpl)15 ArrayList (java.util.ArrayList)14 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)13 SyndFeedOutput (com.rometools.rome.io.SyndFeedOutput)5 StatusGroup (org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup)4 StatusItem (org.onebusaway.enterprise.webapp.actions.status.model.StatusItem)4 SyndCategory (com.rometools.rome.feed.synd.SyndCategory)3 SyndImageImpl (com.rometools.rome.feed.synd.SyndImageImpl)3 SProject (org.bimserver.interfaces.objects.SProject)3 Preconditions (com.google.common.base.Preconditions)2 Hashing (com.google.common.hash.Hashing)2 MediaType (com.google.common.net.MediaType)2 SyndCategoryImpl (com.rometools.rome.feed.synd.SyndCategoryImpl)2 SyndImage (com.rometools.rome.feed.synd.SyndImage)2 SyndPerson (com.rometools.rome.feed.synd.SyndPerson)2 SyndPersonImpl (com.rometools.rome.feed.synd.SyndPersonImpl)2