Changeset 6f5739b


Ignore:
Timestamp:
Sep 14, 2015 11:06:35 AM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
7912d765
Parents:
ed3e444
Message:

News: Store/load individual news entries as XML in separate files by UUID.
WIP, not yet hooked in.

Location:
apps/routerconsole/java/src/net/i2p/router/news
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/src/net/i2p/router/news/NewsXMLParser.java

    red3e444 r6f5739b  
    248248    }
    249249
     250    /**
     251     *  This does not check for any missing values.
     252     *  Any fields in any NewsEntry may be null.
     253     */
    250254    private List<NewsEntry> extractNewsEntries(Node feed) throws I2PParserException {
    251255        List<NewsEntry> rv = new ArrayList<NewsEntry>();
     
    346350    /**
    347351     *  Helper to get all Nodes matching the name
    348      */
    349     private static List<Node> getNodes(Node node, String name) {
     352     *
     353     *  @return non-null
     354     */
     355    static List<Node> getNodes(Node node, String name) {
    350356        List<Node> rv = new ArrayList<Node>();
    351357        int count = node.getNNodes();
     
    433439
    434440    public static void main(String[] args) {
    435         if (args.length != 1) {
    436             System.err.println("Usage: NewsXMLParser file.xml");
     441        if (args.length <= 0 || args.length > 2) {
     442            System.err.println("Usage: NewsXMLParser file.xml [parserMode]");
    437443            System.exit(1);
    438444        }
     
    455461            System.out.println("Feed timestamp: " + ud.feedUpdated);
    456462            System.out.println("Found " + entries.size() + " news entries");
     463            Set<String> uuids = new HashSet<String>(entries.size());
    457464            for (int i = 0; i < entries.size(); i++) {
    458465                NewsEntry e = entries.get(i);
    459                 System.out.println("News #" + (i+1) + ": " + e.title + '\n' + e.content);
     466                System.out.println("\n****** News #" + (i+1) + ": " + e.title + '\n' + e.content);
     467                if (e.id == null)
     468                    throw new IOException("missing ID");
     469                if (e.title == null)
     470                    throw new IOException("missing title");
     471                if (e.content == null)
     472                    throw new IOException("missing content");
     473                if (e.authorName == null)
     474                    throw new IOException("missing author");
     475                if (e.updated == 0)
     476                    throw new IOException("missing updated");
     477                if (!uuids.add(e.id))
     478                    throw new IOException("duplicate ID");
    460479            }
    461480        } catch (IOException ioe) {
Note: See TracChangeset for help on using the changeset viewer.