Search in sources :

Example 6 with SyndContent

use of com.rometools.rome.feed.synd.SyndContent in project blogwt by billy1380.

the class FeedServlet method getFeed.

protected SyndFeed getFeed(HttpServletRequest request) throws IOException, FeedException {
    SyndFeed feed = new SyndFeedImpl();
    String url = ServletHelper.constructBaseUrl(request);
    feed.setTitle(PropertyServiceProvider.provide().getNamedProperty(PropertyHelper.TITLE).value);
    feed.setLink(url + "/feed");
    feed.setDescription(PropertyServiceProvider.provide().getNamedProperty(PropertyHelper.EXTENDED_TITLE).value);
    List<Post> posts;
    Pager pager = PagerHelper.createDefaultPager();
    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    SyndEntry entry;
    SyndContent description;
    MarkdownProcessor processor = new MarkdownProcessor();
    do {
        posts = PostServiceProvider.provide().getPosts(Boolean.FALSE, Boolean.FALSE, pager.start, pager.count, PostSortType.PostSortTypePublished, SortDirectionType.SortDirectionTypeDescending);
        if (posts != null) {
            PagerHelper.moveForward(pager);
            for (Post post : posts) {
                entry = new SyndEntryImpl();
                entry.setTitle(post.title);
                entry.setLink(url + "/#" + PageType.PostDetailPageType.asTargetHistoryToken(post.slug));
                entry.setPublishedDate(post.published);
                description = new SyndContentImpl();
                description.setType("text/HTML");
                description.setValue(processor.process(post.summary));
                entry.setDescription(description);
                entries.add(entry);
            }
        }
    } while (posts != null && posts.size() >= pager.count.intValue());
    feed.setEntries(entries);
    return feed;
}
Also used : Post(com.willshex.blogwt.shared.api.datatype.Post) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) ArrayList(java.util.ArrayList) MarkdownProcessor(org.markdown4j.server.MarkdownProcessor) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndContent(com.rometools.rome.feed.synd.SyndContent) Pager(com.willshex.blogwt.shared.api.Pager) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl)

Example 7 with SyndContent

use of com.rometools.rome.feed.synd.SyndContent in project nutch by apache.

the class FeedParser method addToMap.

private void addToMap(ParseResult parseResult, SyndFeed feed, String feedLink, SyndEntry entry, Content content) {
    String link = entry.getLink(), text = null, title = null;
    Metadata parseMeta = new Metadata(), contentMeta = content.getMetadata();
    Parse parse = null;
    SyndContent description = entry.getDescription();
    try {
        link = normalizers.normalize(link, URLNormalizers.SCOPE_OUTLINK);
        if (link != null)
            link = filters.filter(link);
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }
    if (link == null)
        return;
    title = stripTags(entry.getTitleEx());
    if (feedLink != null)
        parseMeta.set("feed", feedLink);
    addFields(parseMeta, contentMeta, feed, entry);
    // some item descriptions contain markup text in them,
    // so we temporarily set their content-type to parse them
    // with another plugin
    String contentType = contentMeta.get(Response.CONTENT_TYPE);
    if (description != null)
        text = description.getValue();
    if (text == null) {
        List<?> contents = entry.getContents();
        StringBuilder buf = new StringBuilder();
        for (Object syndContent : contents) {
            buf.append(((SyndContent) syndContent).getValue());
        }
        text = buf.toString();
    }
    try {
        Parser parser = parserFactory.getParsers(contentType, link)[0];
        parse = parser.getParse(new Content(link, link, text.getBytes(), contentType, contentMeta, conf)).get(link);
    } catch (ParserNotFound e) {
    /* ignore */
    }
    if (parse != null) {
        ParseData data = parse.getData();
        data.getContentMeta().remove(Response.CONTENT_TYPE);
        mergeMetadata(data.getParseMeta(), parseMeta);
        parseResult.put(link, new ParseText(parse.getText()), new ParseData(ParseStatus.STATUS_SUCCESS, title, data.getOutlinks(), data.getContentMeta(), data.getParseMeta()));
    } else {
        contentMeta.remove(Response.CONTENT_TYPE);
        parseResult.put(link, new ParseText(text), new ParseData(ParseStatus.STATUS_FAILURE, title, new Outlink[0], contentMeta, parseMeta));
    }
}
Also used : Outlink(org.apache.nutch.parse.Outlink) ParserNotFound(org.apache.nutch.parse.ParserNotFound) Parse(org.apache.nutch.parse.Parse) Metadata(org.apache.nutch.metadata.Metadata) Parser(org.apache.nutch.parse.Parser) ParseText(org.apache.nutch.parse.ParseText) SyndContent(com.rometools.rome.feed.synd.SyndContent) ParseData(org.apache.nutch.parse.ParseData) Content(org.apache.nutch.protocol.Content) SyndContent(com.rometools.rome.feed.synd.SyndContent)

Example 8 with SyndContent

use of com.rometools.rome.feed.synd.SyndContent in project OpenOLAT by OpenOLAT.

the class RomeFeedFetcher method convertEntry.

/**
 * Converts a <code>SyndEntry</code> into an <code>Item</code>
 *
 * @param entry
 * @return
 */
protected Item convertEntry(Feed feed, SyndEntry entry) {
    Item item = new ItemImpl(feed);
    item.setAuthor(entry.getAuthor());
    item.setExternalLink(entry.getLink());
    item.setGuid(entry.getUri());
    item.setLastModified(entry.getUpdatedDate());
    item.setPublishDate(entry.getPublishedDate());
    item.setTitle(entry.getTitle());
    if (entry.getDescription() != null) {
        item.setDescription(entry.getDescription().getValue());
    }
    List<SyndContent> contents = entry.getContents();
    item.setContent(joinContents(contents));
    List<SyndEnclosure> enclosures = entry.getEnclosures();
    item.setEnclosure(convertEnclosures(enclosures));
    return item;
}
Also used : Item(org.olat.modules.webFeed.Item) SyndContent(com.rometools.rome.feed.synd.SyndContent) ItemImpl(org.olat.modules.webFeed.model.ItemImpl) SyndEnclosure(com.rometools.rome.feed.synd.SyndEnclosure)

Example 9 with SyndContent

use of com.rometools.rome.feed.synd.SyndContent in project onebusaway-application-modules by camsys.

the class MonitoringAlertsUpdateAction method execute.

@Override
public String execute() {
    _feed = new SyndFeedImpl();
    StringBuilder title = new StringBuilder();
    title.append("OneBusAway System Monitoring");
    HttpServletRequest request = ServletActionContext.getRequest();
    StringBuilder b = new StringBuilder();
    b.append("http://");
    b.append(request.getServerName());
    if (request.getServerPort() != 80)
        b.append(":").append(request.getServerPort());
    if (request.getContextPath() != null)
        b.append(request.getContextPath());
    String baseUrl = b.toString();
    _feed.setTitle(title.toString());
    _feed.setLink(baseUrl);
    _feed.setDescription("System Monitoring");
    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    // Add Icinga Alerts
    SyndEntry icingaEntry = new SyndEntryImpl();
    SyndContent icingaContent = new SyndContentImpl();
    StatusGroup icingaGroup = _statusProvider.getIcingaStatus();
    StatusGroup icingaProblems = new StatusGroup();
    icingaProblems.setTitle(icingaGroup.getTitle());
    // Only report items where status is not "OK"
    for (StatusItem icingaItem : icingaGroup.getItems()) {
        if (icingaItem.getStatus() != StatusItem.Status.OK) {
            icingaProblems.addItem(icingaItem);
        }
    }
    if (icingaProblems.getItems().size() == 0) {
        icingaEntry = new SyndEntryImpl();
        icingaEntry.setTitle("All systems operational");
        entries.add(icingaEntry);
    } else {
        for (StatusItem icingaItem : icingaProblems.getItems()) {
            icingaEntry = new SyndEntryImpl();
            icingaEntry.setTitle(icingaItem.getTitle());
            icingaContent = new SyndContentImpl();
            icingaContent.setValue(icingaItem.getStatus() + ": " + icingaItem.getDescription());
            icingaEntry.setDescription(icingaContent);
            entries.add(icingaEntry);
        }
    }
    _feed.setEntries(entries);
    return SUCCESS;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) StatusItem(org.onebusaway.enterprise.webapp.actions.status.model.StatusItem) SyndContent(com.rometools.rome.feed.synd.SyndContent) StatusGroup(org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup) 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)

Example 10 with SyndContent

use of com.rometools.rome.feed.synd.SyndContent in project onebusaway-application-modules by camsys.

the class ServiceAlertsUpdateAction method execute.

@Override
public String execute() {
    _feed = new SyndFeedImpl();
    StringBuilder title = new StringBuilder();
    title.append("OneBusAway Agency Advisories");
    HttpServletRequest request = ServletActionContext.getRequest();
    StringBuilder b = new StringBuilder();
    b.append("http://");
    b.append(request.getServerName());
    if (request.getServerPort() != 80)
        b.append(":").append(request.getServerPort());
    if (request.getContextPath() != null)
        b.append(request.getContextPath());
    String baseUrl = b.toString();
    _feed.setTitle(title.toString());
    _feed.setLink(baseUrl);
    _feed.setDescription("Service Alerts");
    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    // Add Service Alerts
    SyndEntry serviceAlertEntry = new SyndEntryImpl();
    SyndContent saContent = new SyndContentImpl();
    StatusGroup saGroup = _statusProvider.getAgencyServiceAlertStatus();
    if (saGroup.getItems().size() == 0) {
        serviceAlertEntry = new SyndEntryImpl();
        serviceAlertEntry.setTitle("All systems operational");
        entries.add(serviceAlertEntry);
    } else {
        for (StatusItem saItem : saGroup.getItems()) {
            serviceAlertEntry = new SyndEntryImpl();
            serviceAlertEntry.setTitle(saItem.getTitle());
            saContent = new SyndContentImpl();
            saContent.setValue(saItem.getDescription());
            serviceAlertEntry.setDescription(saContent);
            entries.add(serviceAlertEntry);
        }
    }
    _feed.setEntries(entries);
    return SUCCESS;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) StatusItem(org.onebusaway.enterprise.webapp.actions.status.model.StatusItem) SyndContent(com.rometools.rome.feed.synd.SyndContent) StatusGroup(org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup) 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

SyndContent (com.rometools.rome.feed.synd.SyndContent)23 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)15 SyndContentImpl (com.rometools.rome.feed.synd.SyndContentImpl)13 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)13 ArrayList (java.util.ArrayList)12 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)9 SyndFeedImpl (com.rometools.rome.feed.synd.SyndFeedImpl)9 SyndEnclosure (com.rometools.rome.feed.synd.SyndEnclosure)5 Date (java.util.Date)5 Item (org.olat.modules.webFeed.Item)4 StatusGroup (org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup)4 StatusItem (org.onebusaway.enterprise.webapp.actions.status.model.StatusItem)4 SyndFeedOutput (com.rometools.rome.io.SyndFeedOutput)3 SProject (org.bimserver.interfaces.objects.SProject)3 SyndCategory (com.rometools.rome.feed.synd.SyndCategory)2 SyndPerson (com.rometools.rome.feed.synd.SyndPerson)2 FeedException (com.rometools.rome.io.FeedException)2 SyndFeedInput (com.rometools.rome.io.SyndFeedInput)2 Metacard (ddf.catalog.data.Metacard)2 Result (ddf.catalog.data.Result)2