Search in sources :

Example 1 with SyndContent

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

the class SyndicationServlet method writeCheckoutsFeed.

private void writeCheckoutsFeed(HttpServletRequest request, HttpServletResponse response, ServiceMap serviceMap) throws ServiceException, IOException, FeedException, 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 checkouts feed for project '" + sProject.getName() + "'");
    feed.setLink(request.getContextPath());
    feed.setDescription("This feed represents all the checkouts of project '" + sProject.getName() + "'");
    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    try {
        List<SCheckout> allCheckoutsOfProject = serviceMap.getServiceInterface().getAllCheckoutsOfProjectAndSubProjects(poid);
        for (SCheckout sCheckout : allCheckoutsOfProject) {
            SRevision revision = serviceMap.getServiceInterface().getRevision(sCheckout.getRevision().getOid());
            SProject project = serviceMap.getServiceInterface().getProjectByPoid(sCheckout.getProjectId());
            SUser user = serviceMap.getServiceInterface().getUserByUoid(sCheckout.getUserId());
            SyndEntry entry = new SyndEntryImpl();
            entry.setTitle("Checkout on " + project.getName() + ", revision " + revision.getId());
            entry.setLink(request.getContextPath() + "/project.jsp?poid=" + sProject.getOid());
            entry.setPublishedDate(sCheckout.getDate());
            SyndContent description = new SyndContentImpl();
            description.setType("text/plain");
            description.setValue("<table><tr><td>User</td><td>" + user.getUsername() + "</td></tr><tr><td>Revision</td><td>" + sCheckout.getRevision().getOid() + "</td></tr></table>");
            entry.setDescription(description);
            entries.add(entry);
        }
    } catch (UserException 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) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) UserException(org.bimserver.shared.exceptions.UserException) SCheckout(org.bimserver.interfaces.objects.SCheckout)

Example 2 with SyndContent

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

the class SyndicationServlet method writeProjectsFeed.

private void writeProjectsFeed(HttpServletRequest request, HttpServletResponse response, ServiceMap serviceMap) throws UserException, IOException, FeedException, PublicInterfaceNotFoundException {
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType(FEED_TYPE);
    feed.setTitle("BIMserver.org projects feed");
    feed.setLink(request.getContextPath());
    feed.setDescription("This feed represents all your available projects within this BIMserver");
    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    try {
        List<SProject> allProjects = serviceMap.getServiceInterface().getAllProjects(false, true);
        for (SProject sProject : allProjects) {
            SyndEntry entry = new SyndEntryImpl();
            entry.setAuthor(serviceMap.getServiceInterface().getUserByUoid(sProject.getCreatedById()).getName());
            entry.setTitle(sProject.getName());
            entry.setLink(request.getContextPath() + "/project.jsp?poid=" + sProject.getOid());
            entry.setPublishedDate(sProject.getCreatedDate());
            SyndContent description = new SyndContentImpl();
            description.setType("text/plain");
            description.setValue(sProject.getDescription());
            entry.setDescription(description);
            entries.add(entry);
        }
        if (allProjects.size() == 0) {
            SyndEntry entry = new SyndEntryImpl();
            entry.setTitle("No projects found");
            entry.setLink(request.getContextPath() + "/main.jsp");
            entry.setPublishedDate(new Date());
            SyndContent description = new SyndContentImpl();
            description.setType("text/plain");
            description.setValue("No projects found");
            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) ArrayList(java.util.ArrayList) SyndFeedOutput(com.rometools.rome.io.SyndFeedOutput) SProject(org.bimserver.interfaces.objects.SProject) Date(java.util.Date) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) 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)

Example 3 with SyndContent

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

the class OpenSearchSource method createResponseFromEntry.

/**
     * Creates a single response from input parameters. Performs XPath operations on the document to
     * retrieve data not passed in.
     *
     * @param entry a single Atom entry
     * @return single response
     * @throws ddf.catalog.source.UnsupportedQueryException
     */
private List<Result> createResponseFromEntry(SyndEntry entry) throws UnsupportedQueryException {
    String id = entry.getUri();
    if (id != null && !id.isEmpty()) {
        id = id.substring(id.lastIndexOf(':') + 1);
    }
    List<SyndContent> contents = entry.getContents();
    List<SyndCategory> categories = entry.getCategories();
    List<Metacard> metacards = new ArrayList<>();
    List<Element> foreignMarkup = entry.getForeignMarkup();
    String relevance = "";
    String source = "";
    for (Element element : foreignMarkup) {
        if (element.getName().equals("score")) {
            relevance = element.getContent(0).getValue();
        }
    }
    //we currently do not support downloading content via an RSS enclosure, this support can be added at a later date if we decide to include it
    for (SyndContent content : contents) {
        MetacardImpl metacard = getMetacardImpl(parseContent(content.getValue(), id));
        metacard.setSourceId(this.shortname);
        String title = metacard.getTitle();
        if (StringUtils.isEmpty(title)) {
            metacard.setTitle(entry.getTitle());
        }
        if (!source.isEmpty()) {
            metacard.setSourceId(source);
        }
        metacards.add(metacard);
    }
    for (int i = 0; i < categories.size() && i < metacards.size(); i++) {
        SyndCategory category = categories.get(i);
        Metacard metacard = metacards.get(i);
        if (StringUtils.isBlank(metacard.getContentTypeName())) {
            ((MetacardImpl) metacard).setContentTypeName(category.getName());
        }
    }
    List<Result> results = new ArrayList<>();
    for (Metacard metacard : metacards) {
        ResultImpl result = new ResultImpl(metacard);
        if (relevance == null || relevance.isEmpty()) {
            LOGGER.debug("couldn't find valid relevance. Setting relevance to 0");
            relevance = "0";
        }
        result.setRelevanceScore(new Double(relevance));
        results.add(result);
    }
    return results;
}
Also used : SyndCategory(com.rometools.rome.feed.synd.SyndCategory) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) SyndContent(com.rometools.rome.feed.synd.SyndContent)

Example 4 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 5 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)

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