Package com.sun.syndication.feed.atom

Examples of com.sun.syndication.feed.atom.Feed


public class ShoppingCartImpl implements Collection {

    private static Map<String, Entry> cart = new HashMap<String, Entry>();

    public Feed getFeed() {
        Feed feed = new Feed();
        feed.setTitle("shopping cart");
        Content subtitle = new Content();
        subtitle.setValue("Total : " + getTotal());
        feed.setSubtitle(subtitle);
        feed.getEntries().addAll(cart.values());
        return feed;
    }
View Full Code Here


     * @return The exchange rate
     */
    public double getExchangeRate(String currency) {
        try {
            System.out.println("Retrieving exchange rate...");
            Feed feed = exchangeRate.getRates();
            Entry entry = (Entry)feed.getEntries().get(0);
            String rateTable = entry.getSummary().getValue();

            Document doc = builder.parse(new ByteArrayInputStream(rateTable.getBytes()));
            Node node = doc.getDocumentElement();
            XPath path = XPathFactory.newInstance().newXPath();
View Full Code Here

public class ShoppingCartImpl implements Collection {

    private static Map<String, Entry> cart = new HashMap<String, Entry>();

    public Feed getFeed() {
        Feed feed = new Feed();
        feed.setTitle("shopping cart");
        Content subtitle = new Content();
        subtitle.setValue("Total : " + getTotal());
        feed.setSubtitle(subtitle);
        feed.getEntries().addAll(cart.values());
        return feed;
    }
View Full Code Here

                outputter.output(document, getWriter(response));

            } else if (path == null || path.length() == 0 || path.equals("/")) {

                // Return a feed containing the entries in the collection
                Feed feed = null;
                if (supportsFeedEntries) {

                    // The service implementation supports feed entries, invoke its getFeed operation
                    Message requestMessage = messageFactory.createMessage();
                    Message responseMessage = getFeedInvoker.invoke(requestMessage);
                    if (responseMessage.isFault()) {
                        throw new ServletException((Throwable)responseMessage.getBody());
                    }
                    feed = (Feed)responseMessage.getBody();
                   
                } else {

                    // The service implementation does not support feed entries,
                    // invoke its getAll operation to get the data item collection, then create
                    // feed entries from the items
                    Message requestMessage = messageFactory.createMessage();
                    Message responseMessage;
                    if (request.getQueryString() != null) {
                        requestMessage.setBody(new Object[] {request.getQueryString()});
                        responseMessage = queryInvoker.invoke(requestMessage);
                    } else {
                        responseMessage = getAllInvoker.invoke(requestMessage);
                    }
                    if (responseMessage.isFault()) {
                        throw new ServletException((Throwable)responseMessage.getBody());
                    }
                    org.apache.tuscany.sca.implementation.data.collection.Entry<Object, Object>[] collection =
                        (org.apache.tuscany.sca.implementation.data.collection.Entry<Object, Object>[])responseMessage.getBody();
                    if (collection != null) {
                        // Create the feed
                        feed = new Feed();
                        feed.setTitle("Feed");
                        for (org.apache.tuscany.sca.implementation.data.collection.Entry<Object, Object> entry: collection) {
                            Entry feedEntry = createFeedEntry(entry);
                            feed.getEntries().add(feedEntry);
                        }
                    }
                }
                if (feed != null) {
                   
                    // Write the Atom feed
                    response.setContentType("application/atom+xml; charset=utf-8");
                    feed.setFeedType(requestFeedType);
                    WireFeedOutput feedOutput = new WireFeedOutput();
                    try {
                        feedOutput.output(feed, getWriter(response));
                    } catch (FeedException e) {
                        throw new ServletException(e);
                    }
                } else {
                    response.sendError(HttpServletResponse.SC_NOT_FOUND);
                }
               
            } else if (path.startsWith("/")) {

                // Return a specific entry in the collection
                Entry feedEntry;

                // Invoke the get operation on the service implementation
                Message requestMessage = messageFactory.createMessage();
                String id = path.substring(1);
                requestMessage.setBody(new Object[] {id});
                Message responseMessage = getInvoker.invoke(requestMessage);
                if (responseMessage.isFault()) {
                    throw new ServletException((Throwable)responseMessage.getBody());
                }
                if (supportsFeedEntries) {
                   
                    // The service implementation returns a feed entry
                    feedEntry = responseMessage.getBody();
                   
                } else {
                   
                    // The service implementation only returns a data item, create an entry
                    // from it
                    feedEntry = createFeedEntry(new org.apache.tuscany.sca.implementation.data.collection.Entry<Object, Object>(id, responseMessage.getBody()));
                }

                // Write the Atom entry
                if (feedEntry != null) {
                    response.setContentType("application/atom+xml; charset=utf-8");
                    try {
                        AtomFeedEntryUtil.writeFeedEntry(feedEntry, feedType, getWriter(response));
                    } catch (FeedException e) {
                        throw new ServletException(e);
                    }
                } else {
                    response.sendError(HttpServletResponse.SC_NOT_FOUND);
                }

            } else {

                // Path doesn't match any known pattern
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
            }
        } else {

            // Handle an RSS request
            if (path == null || path.length() == 0 || path.equals("/")) {

                // Return an RSS feed containing the entries in the collection
                Feed feed = null;
                if (supportsFeedEntries) {

                    // The service implementation supports feed entries, invoke its getFeed operation
                    Message requestMessage = messageFactory.createMessage();
                    Message responseMessage = getFeedInvoker.invoke(requestMessage);
                    if (responseMessage.isFault()) {
                        throw new ServletException((Throwable)responseMessage.getBody());
                    }
                    feed = (Feed)responseMessage.getBody();
                   
                } else {

                    // The service implementation does not support feed entries, invoke its
                    // getAll operation to get the data item collection. then create feed entries
                    // from the data items
                    Message requestMessage = messageFactory.createMessage();
                    Message responseMessage;
                    if (request.getQueryString() != null) {
                        requestMessage.setBody(new Object[] {request.getQueryString()});
                        responseMessage = queryInvoker.invoke(requestMessage);
                    } else {
                        responseMessage = getAllInvoker.invoke(requestMessage);
                    }
                    if (responseMessage.isFault()) {
                        throw new ServletException((Throwable)responseMessage.getBody());
                    }
                    org.apache.tuscany.sca.implementation.data.collection.Entry<Object, Object>[] collection =
                        (org.apache.tuscany.sca.implementation.data.collection.Entry<Object, Object>[])responseMessage.getBody();
                    if (collection != null) {
                        // Create the feed
                        feed = new Feed();
                        feed.setTitle("Feed");
                        for (org.apache.tuscany.sca.implementation.data.collection.Entry<Object, Object> entry: collection) {
                            Entry feedEntry = createFeedEntry(entry);
                            feed.getEntries().add(feedEntry);
                        }
                    }
                }

                // Convert to an RSS feed
                if (feed != null) {
                    response.setContentType("application/rss+xml; charset=utf-8");
                    feed.setFeedType("atom_1.0");
                    SyndFeed syndFeed = new SyndFeedImpl(feed);
                    syndFeed.setFeedType(requestFeedType);
                    syndFeed.setLink(path);
                    SyndFeedOutput syndOutput = new SyndFeedOutput();
                    try {
View Full Code Here

    @SuppressWarnings("unchecked")
    public Feed getFeed() {
        System.out.println(">>> ResourceCollectionImpl.get collection");

        Feed feed = new Feed();
        feed.setTitle("customers");
        Content subtitle = new Content();
        subtitle.setValue("This is a sample feed");
        feed.setSubtitle(subtitle);
        feed.getEntries().addAll(entries.values());
        return feed;
    }
View Full Code Here

        System.out.println(">>> delete id=" + entry.getId());
        resourceCollection.delete(entry.getId());
        System.out.println("<<< delete id=" + entry.getId());

        System.out.println(">>> get collection");
        Feed feed = resourceCollection.getFeed();
        System.out.println("<<< get collection");
        for (Object o : feed.getEntries()) {
            Entry e = (Entry)o;
            System.out.println("id = " + e.getId() + " entry = " + e.getTitle());
        }
    }
View Full Code Here

                int status = getMethod.getStatusCode();

                // Read the Atom feed
                if (status == 200) {
                    WireFeedInput input = new WireFeedInput();
                    Feed feed = (Feed)input.build(new XmlReader(getMethod.getResponseBodyAsStream()));
                    msg.setBody(feed);

                } else if (status == 404) {
                    msg.setFaultBody(new NotFoundException());
                } else {
View Full Code Here

        FeedException {
        SAXBuilder builder = new SAXBuilder();
        Document document = builder.build(reader);
        Element root = document.getRootElement();
        root.detach();
        Feed feed = new Feed();
        feed.setFeedType(feedType);
        WireFeedOutput wireFeedOutput = new WireFeedOutput();
        document = wireFeedOutput.outputJDom(feed);
        document.getRootElement().addContent(root);
        WireFeedInput input = new WireFeedInput();
        feed = (Feed)input.build(document);
        Entry feedEntry = (Entry)feed.getEntries().get(0);
        if (feedEntry.getContents().size() != 0) {
            Content content = (Content)feedEntry.getContents().get(0);
            if ("text/xml".equals(content.getType())) {
                Element element = root.getChild("content", root.getNamespace());
                if (!element.getChildren().isEmpty()) {
View Full Code Here

     * @throws IOException
     * @throws ServletException
     */
    static void writeFeedEntry(Entry feedEntry, String feedType, Writer writer) throws IllegalArgumentException, FeedException,
        IOException {
        Feed feed = new Feed();
        feed.setFeedType(feedType);
        List<Entry> feedEntries = new ArrayList<Entry>();
        feedEntries.add(feedEntry);
        feed.setEntries(feedEntries);

        WireFeedOutput wireFeedOutput = new WireFeedOutput();
        Document document = wireFeedOutput.outputJDom(feed);
        Element root = document.getRootElement();
        Element element = (Element)root.getChildren().get(0);
View Full Code Here

    public Message invoke(Message msg) {
        try {
            logger.info(">>> RSSBindingInvoker (" + feedType + ") " + uri);

            // Read the configured feed URI into a Feed object
            Feed feed;
            if (feedType.startsWith("atom_")) {

                // Read an Atom feed
                WireFeedInput input = new WireFeedInput();
                feed = (Feed)input.build(new XmlReader(new URL(uri)));
View Full Code Here

TOP

Related Classes of com.sun.syndication.feed.atom.Feed

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.