Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/intabulas/sandler/parser/AtomParser.java


1   /**
2    * Copyright (c) 2003, Mark Lussier
3    * All rights reserved.
4    *
5    * Portions Copyright (c) 2003 by David A. Czarnecki
6    *
7    * Redistribution and use in source and binary forms, with or without
8    * modification, are permitted provided that the following conditions are met:
9    *
10   * Redistributions of source code must retain the above copyright notice,
11   *      this list of conditions and the following disclaimer.
12   * Redistributions in binary form must reproduce the above copyright notice,
13   *      this list of conditions and the following disclaimer in the documentation
14   *      and/or other materials provided with the distribution.
15   * Neither the name of the "Mark Lussier" and "Sandler" nor the names of
16   * its contributors may be used to endorse or promote products derived from
17   * this software without specific prior written permission.
18   * Products derived from this software may not be called "Sandler",
19   * nor may "Sandler" appear in their name, without prior written permission of
20   * Mark Lussier
21   *
22   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
23   * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
24   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25   * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
26   * EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
27   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29   * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
31   * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35   */
36  package org.intabulas.sandler.parser;
37  
38  import org.intabulas.sandler.elements.Entry;
39  import org.intabulas.sandler.elements.Feed;
40  import org.intabulas.sandler.elements.impl.EntryImpl;
41  import org.intabulas.sandler.elements.impl.FeedImpl;
42  import org.xmlpull.v1.XmlPullParser;
43  import org.xmlpull.v1.XmlPullParserException;
44  import org.xmlpull.v1.XmlPullParserFactory;
45  
46  import java.io.InputStream;
47  import java.io.InputStreamReader;
48  
49  
50  /**
51   * AtomParser
52   *
53   * @author Mark Lussier
54   * @version $Id: AtomParser.java,v 1.2 2003/09/10 16:21:22 intabulas Exp $
55   */
56  public class AtomParser {
57  
58  
59      public AtomParser() {
60  
61      }
62  
63      public Feed parseInput(InputStream in) throws XmlPullParserException {
64          Feed result = null;
65          XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
66  
67          factory.setNamespaceAware(true);
68          XmlPullParser parser = factory.newPullParser();
69          parser.setInput(new InputStreamReader(in));
70  
71          result = new FeedImpl();
72          result.loadDocument(parser);
73  
74          return result;
75      }
76  
77      public Entry parseEntryInput(InputStream in) throws XmlPullParserException {
78          Entry result = null;
79          XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
80  
81          factory.setNamespaceAware(true);
82          XmlPullParser parser = factory.newPullParser();
83          parser.setInput(new InputStreamReader(in));
84  
85          result = new EntryImpl();
86          result.loadDocument(parser);
87  
88          return result;
89      }
90  
91  
92  }