File feedFile = new File(dir,".feed.atom");
org.atomojo.app.db.Feed feed = null;
if (feedFile.exists()) {
// exists, so we'll import it
Document doc = loader.load(feedFile.toURI());
Feed feedObj = new Feed(doc);
String idS = feedObj.getId();
if (!idS.startsWith("urn:uuid:")) {
throw new IOException("Bad feed id: "+idS);
}
try {
UUID id = UUID.fromString(idS.substring(9));
feed = parent.createChild(dir.getName(), id);
} catch (IllegalArgumentException ex) {
throw new IOException(ex.getMessage());
}
} else {
// create new feed
feed = parent.createChild(dir.getName());
// create feed document
Document doc = AtomResource.createFeedDocument(dir.getName(),feed.getUUID(),feed.getCreated());
Writer out = new OutputStreamWriter(new FileOutputStream(feedFile),"UTF-8");
XMLWriter.writeDocument(doc, out);
out.close();
}