Package org.apache.abdera.parser

Examples of org.apache.abdera.parser.Parser


public class XPathExample {

  public static void main(String[] args) throws Exception {
   
    Abdera abdera = new Abdera();
    Parser parser = abdera.getParser();
    XPath xpath = abdera.getXPath();
   
    InputStream in = XPathExample.class.getResourceAsStream("/simple.xml");
    Document<Feed> doc = parser.parse(in);
    Feed feed = doc.getRoot();
   
    System.out.println(xpath.evaluate("count(/a:feed)", feed));         // 1.0
    System.out.println(xpath.numericValueOf("count(/a:feed)", feed));   // 1.0
    System.out.println(xpath.booleanValueOf("/a:feed/a:entry", feed));          // true (the feed has an entry)
View Full Code Here


public class XsltExample {

  public static void main(String[] args) {
   
    Parser parser = Abdera.getNewParser();
   
    try {
     
      // Apply an XSLT transform to the entire Feed
      TransformerFactory factory = TransformerFactory.newInstance();
     
      // Abdera is capable of parsing any well-formed XML document, even XSLT
      Document xslt = parser.parse(XsltExample.class.getResourceAsStream("/test.xslt"));
      AbderaSource xsltSource = new AbderaSource(xslt);
      Transformer transformer = factory.newTransformer(xsltSource);
     
      // Now let's get the feed we're going to transform
      Document<Feed> feed = parser.parse(XsltExample.class.getResourceAsStream("/simple.xml"));
      AbderaSource feedSource = new AbderaSource(feed);
     
      // Prepare the output
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      Result result = new StreamResult(out);
      transformer.transform(feedSource, result);
      System.out.println(out); // "This is a test urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6"
     
      // Apply an XSLT transform to XML in the content element
      xslt = parser.parse(XsltExample.class.getResourceAsStream("/content.xslt"));
      xsltSource = new AbderaSource(xslt);
      transformer = factory.newTransformer(xsltSource);
     
      feed = parser.parse(XsltExample.class.getResourceAsStream("/xmlcontent.xml"));
      Entry entry = feed.getRoot().getEntries().get(0);
      Content content = entry.getContentElement();
      AbderaSource contentSource = new AbderaSource(content.getValueElement());
     
      // Note that the AbderaSource is set to the value element of atom:content!!
View Full Code Here

  public <T extends Parser>T getParser() {
    return (T)getAbdera().getParser();
  }

  public <T extends Parser>T getParser(String name) {
    Parser parser = (T)((name != null) ?
      getParsers().get(name.toLowerCase()) : getParser());
    if (parser instanceof AbstractParser) {
      ((AbstractParser)parser).setAbdera(abdera);
    }
    return (T) parser;
View Full Code Here

 
 
  protected Element _parse(String value, IRI baseUri) throws ParseException, UnsupportedEncodingException {
    if (value == null) return null;
    FOMFactory fomfactory = (FOMFactory) factory;
    Parser parser = fomfactory.newParser();
    ByteArrayInputStream bais = new ByteArrayInputStream(value.getBytes(getXMLStreamReader().getCharacterEncodingScheme()));
    ParserOptions options = parser.getDefaultParserOptions();
    options.setCharset(getXMLStreamReader().getCharacterEncodingScheme());
    options.setFactory(fomfactory);
    Document doc = parser.parse(bais, (baseUri != null) ? baseUri.toString() : null, options);
    return doc.getRoot();
  }
View Full Code Here

    }
   
    public T readFrom(Class<T> clazz, Type t, Annotation[] a, MediaType mt,
                         MultivaluedMap<String, String> headers, InputStream is)
        throws IOException {
        Parser parser = ATOM_ENGINE.getParser();
        synchronized (parser) {
            ParserOptions options = parser.getDefaultParserOptions();
            if (options != null) {
                options.setAutodetectCharset(autodetectCharset);
            }
        }
        Document<T> doc = parser.parse(is);
        return doc.getRoot();
    }
View Full Code Here

    @Override
    public Object doTransform(Object src, String outputEncoding) throws TransformerException
    {
        try
        {
            Parser parser = Abdera.getInstance().getParser();
            Document<Element> doc;
            if (src instanceof InputStream)
            {
                doc = parser.parse((InputStream) src, outputEncoding);
            }
            else if (src instanceof byte[])
            {
                doc = parser.parse(new ByteArrayInputStream((byte[]) src), outputEncoding);
            }
            else
            {
                doc = parser.parse(new StringReader((String) src));
            }
           
            //we only need to check for the registered source types
            return doc.getRoot();
        }
View Full Code Here

                                 " for: " + feedUrl, e);
            return null;
        }

        Abdera abdera = new Abdera();
        Parser parser = abdera.getParser();
        org.apache.abdera.model.Document<org.apache.abdera.model.Feed> rssDoc = parser
                .parse(new StringReader(rawActivityResponse));
        org.apache.abdera.model.Feed rssFeed = rssDoc.getRoot();

        return rssFeed.getEntries();
    }
View Full Code Here

                                 " for: " + requestUrl, e);
            return null;
        }

        Abdera abdera = new Abdera();
        Parser parser = abdera.getParser();
        org.apache.abdera.model.Document<org.apache.abdera.model.Feed> rssDoc = parser
                .parse(new StringReader(rawActivityResponse));
        org.apache.abdera.model.Feed rssFeed = rssDoc.getRoot();

        return rssFeed.getEntries();
    }
View Full Code Here

    }

    public Collection<CollectionInfo> getCollections(RequestContext request) {
        LinkedList<CollectionInfo> result = new LinkedList<CollectionInfo>();
        Feed feed;
        Parser parser = Abdera.getInstance().getParser();
        CollectionInfo info;
        Storage storage = getStorage();
        for (String id : getFeedIds(request)) {
            try {
                feed = (Feed) parser.parse(
                        new StringReader(storage.readFeed(id))).getRoot();
                String title = feed.getTitle();
                // default title to id if null
                if (title == null) {
                    title = id;
View Full Code Here

        return new ByteArrayInputStream(base64.decode(bo.toByteArray()));
    }

    private <T extends Element> Document<T> getEntry(InputStream stream,
            RequestContext request) throws ParseException, IOException {
        Parser parser = request.getAbdera().getParser();
        if (parser == null)
            throw new IllegalArgumentException(
                    "No Parser implementation was provided");
        Document<?> document = parser.parse(stream, request.getResolvedUri()
                .toString(), parser.getDefaultParserOptions());
        return (Document<T>) document;
    }
View Full Code Here

TOP

Related Classes of org.apache.abdera.parser.Parser

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.