Package org.apache.abdera

Examples of org.apache.abdera.Abdera


  private PipedOutputStream pipeout;
  private PipedInputStream pipein;
  private Document<?> doc;
 
  public AbderaResult() {
    this(new Abdera());
  }
View Full Code Here


    public static void registerAsDefault() {
        System.setProperty(OMAbstractFactory.META_FACTORY_NAME_PROPERTY, FOMFactory.class.getName());
    }

    public FOMFactory() {
        this(new Abdera());
    }
View Full Code Here

public class RssTest extends Assert {

  @Test
  public void testRSS1() {
   
    Abdera abdera = new Abdera();
   
    InputStream in = RssTest.class.getResourceAsStream("/rss1.rdf");
   
    Document<Feed> doc = abdera.getParser().parse(in);
   
    Feed feed = doc.getRoot();
   
    assertEquals("XML.com",feed.getTitle());
    assertEquals("http://xml.com/pub", feed.getAlternateLinkResolvedHref().toASCIIString());
View Full Code Here

        String contribution = ContributionLocationHelper.getContributionLocation(ProviderEntryEntityTagsTestCase.class);

        scaProviderNode = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/atom/Provider.composite", new Contribution("provider", contribution));
        scaProviderNode.start();

        abdera = new Abdera();
        client = new AbderaClient(abdera);
        abderaParser = Abdera.getNewParser();
    }
View Full Code Here

        String contribution = ContributionLocationHelper.getContributionLocation(ProviderEntryEntityTagsTestCase.class);

        scaProviderNode = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/atom/Provider.composite", new Contribution("provider", contribution));
        scaProviderNode.start();

        abdera = new Abdera();
        client = new AbderaClient(abdera);
        abderaParser = Abdera.getNewParser();
    }
View Full Code Here

                if (( preferredType != null ) && ((preferredType.indexOf( "json") > -1) || (preferredType.indexOf( "JSON") > -1 ))) {
                    // JSON response body
                    response.setContentType("application/json;type=feed");

                    try {
                        Abdera abdera = new Abdera();
                        WriterFactory wf = abdera.getWriterFactory();
                        org.apache.abdera.writer.Writer json = wf.getWriter("json");
                        feed.writeTo(json, response.getWriter());
                    } catch (Exception e) {
                        throw new ServletException(e);
                    }              

                } else {
                    // Write the Atom feed
                    response.setContentType("application/atom+xml;type=feed");
                    try {
                        feed.getDocument().writeTo(response.getOutputStream());
                    } catch (IOException ioe) {
                        throw new ServletException(ioe);
                    }
                }
            } else {
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
            }

        } else if (path.startsWith("/")) {
            // Return a specific entry in the collection
            org.apache.abdera.model.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()) {
                Object body = responseMessage.getBody();
                if (body.getClass().getName().endsWith(".NotFoundException")) {
                    response.sendError(HttpServletResponse.SC_NOT_FOUND);
                    return;
                } else {
                    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
                Entry<Object, Object> entry = new Entry<Object, Object>(id, responseMessage.getBody());
                feedEntry = feedEntry(entry, itemClassType, itemXMLType, mediator, abderaFactory);
            }
            // Write the Atom entry
            if (feedEntry != null) {
                String entryETag = null;
                if (feedEntry.getId() != null)
                    entryETag = feedEntry.getId().toString();
                Date entryUpdated = feedEntry.getUpdated();
                if ( entryUpdated != null )
                    response.addHeader(LASTMODIFIED, dateFormat.format( entryUpdated ));
                // TODO Check If-Modified-Since If-Unmodified-Since predicates against LASTMODIFIED.
                // If true return 304 and null body.

                Link link = feedEntry.getSelfLink();
                if (link != null) {
                    response.addHeader(LOCATION, link.getHref().toString());
                } else {
                    link = feedEntry.getLink( "Edit" );
                    if (link != null) {
                        response.addHeader(LOCATION, link.getHref().toString());
                    }
                }

                // Test request for predicates.
                String predicate = request.getHeader( "If-Match" );
                if (( predicate != null ) && ( !predicate.equals(entryETag) )) {
                    // No match, should short circuit
                    response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
                    return;
                }
                predicate = request.getHeader( "If-None-Match" );
                if (( predicate != null ) && ( predicate.equals(entryETag) )) {
                    // Match, should short circuit
                    response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
                    return;
                }
                if ( entryUpdated != null ) {
                    predicate = request.getHeader( "If-Unmodified-Since" );               
                    if ( predicate != null ) {
                        try {
                            Date predicateDate = dateFormat.parse( predicate );
                            if ( predicateDate.compareTo( entryUpdated ) < 0 ) {
                                // Match, should short circuit
                                response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
                                return;
                            }                
                        } catch ( java.text.ParseException e ) {
                            // Ignore and move on
                        }
                    }
                    predicate = request.getHeader( "If-Modified-Since" );               
                    if ( predicate != null ) {
                        try {
                            Date predicateDate = dateFormat.parse( predicate );
                            if ( predicateDate.compareTo( entryUpdated ) > 0 ) {
                                // Match, should short circuit
                                response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
                                return;
                            }                
                        } catch ( java.text.ParseException e ) {
                            // Ignore and move on
                        }
                    }
                }
                // Provide Etag based on Id and time if given.
                // Ignore if not given. (Browser may cache if trivial ETag is given.)
                if (entryETag != null) {
                    response.addHeader(ETAG, entryETag );
                }
                if ( entryUpdated != null ) {
                    response.addHeader(LASTMODIFIED, dateFormat.format( entryUpdated ));
                }

                // Content negotiation
                String acceptType = request.getHeader( "Accept" );
                String preferredType = getContentPreference( acceptType );
                if (( preferredType != null ) && ((preferredType.indexOf( "json") > -1) || (preferredType.indexOf( "JSON") > -1 ))) {
                    // JSON response body
                    response.setContentType("application/json;type=entry");
                    try {
                        Abdera abdera = new Abdera();
                        WriterFactory wf = abdera.getWriterFactory();
                        org.apache.abdera.writer.Writer json = wf.getWriter("json");
                        feedEntry.writeTo(json, response.getWriter());
                    } catch (Exception e) {
                        throw new ServletException(e);
                    }              
View Full Code Here

            String contribution = ContributionLocationHelper.getContributionLocation(MediaCollectionTestCase.class);

            scaProviderNode = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/atom/ReceiptProvider.composite", new Contribution("provider", contribution));
            scaProviderNode.start();

            abdera = new Abdera();
            client = new AbderaClient(abdera);
            abderaParser = Abdera.getNewParser();
        } catch(Exception e) {
            e.printStackTrace();
        }
View Full Code Here

            String contribution = ContributionLocationHelper.getContributionLocation(ContentNegotiationTest.class);

            scaProviderNode = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/atom/Provider.composite", new Contribution("provider", contribution));
            scaProviderNode.start();

            abdera = new Abdera();
            client = new AbderaClient(abdera);
            abderaParser = Abdera.getNewParser();
        } catch(Exception e) {
            e.printStackTrace();
        }
View Full Code Here

        }
        return notificationUrl;
    }

    public static String getAnnouncementHtml(String url) {
        Abdera abdera = new Abdera();
        AbderaClient client = new AbderaClient(abdera);
        ClientResponse resp = client.get(url);
        Feed feed;
        if (resp.getType() == Response.ResponseType.SUCCESS) {
            Document<Feed> respDoc = resp.getDocument();
View Full Code Here

     * Passes if the test does not throw a parse exception
     */
  @Test
    public void testXMLRestrictedChar() throws Exception {
      String s = "<?xml version='1.1'?><t t='\u007f' />";
      Abdera abdera = new Abdera();
      Parser parser = abdera.getParser();
      ParserOptions options = parser.getDefaultParserOptions();
      options.setFilterRestrictedCharacters(true);
      Document<Element> doc = parser.parse(new StringReader(s), null, options);
      doc.getRoot().toString();
    }
View Full Code Here

TOP

Related Classes of org.apache.abdera.Abdera

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.