Package com.sun.syndication.feed.atom

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


     */
    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();
            XPathExpression exp = path.compile("/TABLE/TR[TD[1]='" + currency.toUpperCase() + "']/TD[2]");
View Full Code Here


                    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);
                        }
                    }
                }
View Full Code Here

        Object key = entry.getKey();
        Object data = entry.getData();
        if (data instanceof Item) {
            Item item = (Item)data;
           
            Entry feedEntry = new Entry();
            feedEntry.setId(key.toString());
            feedEntry.setTitle(item.getTitle());
   
            String value = item.getContents();
            if (value != null) {
                Content content = new Content();
                content.setType("text/xml");
                content.setValue(value);
                List<Content> contents = new ArrayList<Content>();
                contents.add(content);
                feedEntry.setContents(contents);
            }
   
            String href = item.getLink();
            if (href == null) {
                href = key.toString();
            }
            Link link = new Link();
            link.setRel("edit");
            link.setHref(href);
            feedEntry.getOtherLinks().add(link);
            link = new Link();
            link.setRel("alternate");
            link.setHref(href);
            feedEntry.getAlternateLinks().add(link);
   
            Date date = item.getDate();
            if (date == null) {
                date = new Date();
            }
            feedEntry.setCreated(date);
            return feedEntry;
           
        } else if (data != null) {
            Entry feedEntry = new Entry();
            feedEntry.setId(key.toString());
            feedEntry.setTitle("item");
   
            // Convert the item to XML
            String value = mediator.mediate(data, itemClassType, itemXMLType, null).toString();
           
            Content content = new Content();
            content.setType("text/xml");
            content.setValue(value);
            List<Content> contents = new ArrayList<Content>();
            contents.add(content);
            feedEntry.setContents(contents);
   
            Link link = new Link();
            link.setRel("edit");
            link.setHref(key.toString());
            feedEntry.getOtherLinks().add(link);
            link = new Link();
            link.setRel("alternate");
            link.setHref(key.toString());
            feedEntry.getAlternateLinks().add(link);
   
            feedEntry.setCreated(new Date());
            return feedEntry;
        } else {
            return null;
        }
    }
View Full Code Here

        // Get the request path
        String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8");

        if (path == null || path.length() == 0 || path.equals("/")) {
            Entry createdFeedEntry = null;

            // Create a new Atom entry
            String contentType = request.getContentType();
            if (contentType.startsWith("application/atom+xml")) {

                // Read the entry from the request
                Entry feedEntry;
                try {
                    feedEntry = AtomFeedEntryUtil.readFeedEntry(feedType, request.getReader());
                } catch (JDOMException e) {
                    throw new ServletException(e);
                } catch (FeedException e) {
View Full Code Here

            // Update an Atom entry
            String contentType = request.getContentType();
            if (contentType.startsWith("application/atom+xml")) {

                // Read the entry from the request
                Entry feedEntry;
                try {
                    feedEntry = AtomFeedEntryUtil.readFeedEntry(feedType, request.getReader());
                } catch (JDOMException e) {
                    throw new ServletException(e);
                } catch (FeedException e) {
View Full Code Here

    public CustomerCollectionImpl() {

        for (int i = 0; i < 4; i++) {
            String id = "urn:uuid:customer-" + UUID.randomUUID().toString();

            Entry entry = new Entry();
            entry.setTitle("customer " + "Jane Doe_" + String.valueOf(i));
            entry.setId(id);

            Content content = new Content();
            content.setValue("Jane Doe_" + String.valueOf(i));
            content.setType(Content.TEXT);
            entry.setContents(Collections.singletonList(content));

            List<Link> links = new ArrayList<Link>();
            Link link = new Link();
            link.setRel("edit");
            link.setHref("" + id);
            links.add(link);
            entry.setOtherLinks(links);

            links = new ArrayList<Link>();
            link = new Link();
            link.setRel("alternate");
            link.setHref("" + id);
            links.add(link);
            entry.setAlternateLinks(links);

            entry.setCreated(new Date());

            entries.put(id, entry);
            System.out.println(">>> id=" + id);
        }
    }
View Full Code Here

    @Reference
    public Collection resourceCollection;

    public void testCustomerCollection() throws Exception {

        Entry newEntry = newEntry("Sponge Bob");
        System.out.println(">>> post entry=" + newEntry.getTitle());
        newEntry = resourceCollection.post(newEntry);
        System.out.println("<<< post id=" + newEntry.getId() + " entry=" + newEntry.getTitle());

        newEntry = newEntry("Jane Bond");
        System.out.println(">>> post entry=" + newEntry.getTitle());
        newEntry = resourceCollection.post(newEntry);
        System.out.println("<<< post id=" + newEntry.getId() + " entry=" + newEntry.getTitle());

        System.out.println(">>> get id=" + newEntry.getId());
        Entry entry = resourceCollection.get(newEntry.getId());
        System.out.println("<<< get id=" + entry.getId() + " entry=" + entry.getTitle());

        System.out.println(">>> put id=" + newEntry.getId() + " entry=" + entry.getTitle());
        resourceCollection.put(entry.getId(), updateEntry(entry, "James Bond"));
        System.out.println("<<< put id=" + entry.getId() + " entry=" + entry.getTitle());

        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

        }
    }

    private Entry newEntry(String value) {

        Entry entry = new Entry();
        entry.setTitle("customer " + value);

        Content content = new Content();
        content.setValue(value);
        content.setType(Content.TEXT);
        List<Object> list = new ArrayList<Object>();
        list.add(content);
        entry.setContents(list);

        return entry;
    }
View Full Code Here

                httpClient.executeMethod(getMethod);
                int status = getMethod.getStatusCode();

                // Read the Atom entry
                if (status == 200) {
                    Entry feedEntry =
                        AtomFeedEntryUtil.readFeedEntry("atom_1.0", new InputStreamReader(getMethod.getResponseBodyAsStream()));
                    msg.setBody(feedEntry);

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

        @Override
        public Message invoke(Message msg) {

            // Post an entry
            Entry feedEntry = (Entry)((Object[])msg.getBody())[0];

            // Send an HTTP POST
            PostMethod postMethod = new PostMethod(uri);
            postMethod.setRequestHeader("Authorization", authorizationHeader);
            try {

                // Write the Atom entry
                StringWriter writer = new StringWriter();
                AtomFeedEntryUtil.writeFeedEntry(feedEntry, "atom_1.0", writer);
                postMethod.setRequestHeader("Content-type", "application/atom+xml; charset=utf-8");
                postMethod.setRequestEntity(new StringRequestEntity(writer.toString()));

                httpClient.executeMethod(postMethod);
                int status = postMethod.getStatusCode();

                // Read the Atom entry
                if (status == 200 || status == 201) {
                    Entry createdEntry =
                        AtomFeedEntryUtil
                            .readFeedEntry("atom_1.0", new InputStreamReader(postMethod.getResponseBodyAsStream()));
                    msg.setBody(createdEntry);

                } else if (status == 404) {
View Full Code Here

TOP

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

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.