Package org.apache.abdera.parser

Examples of org.apache.abdera.parser.Parser


        try {
            syndOutput.output(syndFeed, new OutputStreamWriter(bos, "UTF-8"));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        Parser parser = Abdera.getNewParser();
        Document<Feed> document = parser.parse(new ByteArrayInputStream(bos.toByteArray()));
       
        return document.getRoot();
    }
View Full Code Here


  @SuppressWarnings("unchecked")
  public ResponseContext createEntry(
    RequestContext request) {
      Abdera abdera = request.getAbdera();
      Factory factory = abdera.getFactory();
      Parser parser = abdera.getParser();
      try {
        MimeType contentType = request.getContentType();
        String ctype = (contentType != null) ? contentType.toString() : null;
        if (ctype != null && !MimeTypeHelper.isAtom(ctype) && !MimeTypeHelper.isXml(ctype))
          return new EmptyResponseContext(415);
View Full Code Here

  @SuppressWarnings("unchecked")
  public ResponseContext updateEntry(
    RequestContext request) {
      Abdera abdera = request.getAbdera();
      Parser parser = abdera.getParser();
      Factory factory = abdera.getFactory();
      Entry orig_entry = getAbderaEntry(request);
      if (orig_entry != null) {
        try {
          MimeType contentType = request.getContentType();
View Full Code Here

    @SuppressWarnings("unchecked")
    public static void main(String... args) throws Exception {

        String html = "<html><body><p>this is <i>html</i></body></html>";
        Abdera abdera = Abdera.getInstance();
        Parser parser = abdera.getParserFactory().getParser("html");
        Document<Element> doc = parser.parse(new StringReader(html));
        Element root = doc.getRoot();
        root.writeTo(System.out);
        System.out.println();

        XPath xpath = abdera.getXPath();
View Full Code Here

*/
public class PrintTitles {
    public static void main(String args[]) {
        InputStream input;

        Parser parser = Abdera.getNewParser();

        try {
            input = new URL(args[0]).openStream();
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }

        ParserOptions opts = parser.getDefaultParserOptions();

        ListParseFilter filter = new WhiteListParseFilter();
        filter.add(Constants.FEED);
        filter.add(Constants.ENTRY);
        filter.add(Constants.TITLE);
        opts.setParseFilter(filter);

        Document<Feed> doc;

        try {
            doc = parser.parse(input, "", opts);
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }

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

     * @throws IOException is thrown if error reading from the uri
     * @throws ParseException is thrown if the parsing failed
     */
    public static Document<Feed> parseDocument(String uri) throws IOException, ParseException {
        InputStream in = new URL(uri).openStream();
        Parser parser = getAtomParser();
        // set the thread context loader with the ParserClassLoader
        ClassLoader old = Thread.currentThread().getContextClassLoader();
        try {
            Thread.currentThread().setContextClassLoader(parser.getClass().getClassLoader());
            return parser.parse(in);
        } finally {
            Thread.currentThread().setContextClassLoader(old);
        }
           
    }
View Full Code Here

public class UnacceptableElementsExample {

  public static void main(String[] args) throws Exception {
   
    Parser parser = Abdera.getNewParser();
   
    /**
     * By subclassing BlackListParseFilter, we can throw an error
     * when the parsed XML contains any content we don't want
     */
    ListParseFilter exceptionFilter = new BlackListParseFilter() {
      @Override
      public boolean acceptable(QName qname) {
        boolean answer = super.acceptable(qname);
        if (!(answer)) {
          throw new FOMException("Unacceptable element ::" + qname);
        }
        return answer;
      }

      @Override
      public boolean acceptable(QName qname, QName attribute) {
        return true;
      }
    };
    exceptionFilter.add(new QName("http://example.org", "a"));
   
    ParserOptions options = parser.getDefaultParserOptions();
    options.setParseFilter(exceptionFilter);
    Document<Feed> doc = parser.parse(
      UnacceptableElementsExample.class.getResourceAsStream("/xmlcontent.xml"),
      null, options);
   
    // this will throw a FOMException
    doc.writeTo(System.out);
View Full Code Here

public class Parse {

  public static void main(String[] args) throws Exception {
   
    Parser parser = Abdera.getNewParser();
   
    InputStream in = Parse.class.getResourceAsStream("/simple.xml");
    Document<Feed> doc = parser.parse(in);
    Feed feed = doc.getRoot();
   
    System.out.println(feed.getTitle());
    System.out.println(feed.getTitleType());
    System.out.println(feed.getAlternateLink().getResolvedHref());
View Full Code Here

*/
public class PrintTitles {
  public static void main(String args[]) {
    InputStream input;

    Parser parser = Abdera.getNewParser();
   
    try {
      input = new URL(args[0]).openStream();
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }

    ParserOptions opts = parser.getDefaultParserOptions();

    ListParseFilter filter = new WhiteListParseFilter();
    filter.add(Constants.FEED);
    filter.add(Constants.ENTRY);
    filter.add(Constants.TITLE);
    opts.setParseFilter(filter);

    Document<Feed> doc;

    try {
      doc = parser.parse(input, "", opts);
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }

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.