Dumb file persistence for small nodes and test cases. This will get you up and running quickly, but you'll want to replace it with an implementation backed by some kind of database or document store. Files are placed in a "trsstd" directory inside of your home directory, or inside the directory in
| 49 | * @author mpowers |
| 50 | */ |
| 51 | public class FileStorage implements Storage { |
| 52 | |
| 53 | public static final String FEED_XML = "feed.xml"; |
| 54 | public static final String ENTRY_SUFFIX = ".atom"; |
| 55 | public static final String ENCODING = "UTF-8"; |
| 56 | |
| 57 | private File root; |
| 58 | |
| 59 | public FileStorage() { |
| 60 | this(Common.getServerRoot()); |
| 61 | } |
| 62 | |
| 63 | public FileStorage(File root) { |
| 64 | this.root = root; |
| 65 | System.err.println("File storage serving from: " + root); |
| 66 | } |
| 67 | |
| 68 | public String[] getFeedIds(int start, int length) { |
| 69 | /* Returns feeds for which we have a keystore. */ |
| 70 | File[] files = root.listFiles(); |
| 71 | if (files == null) { |
| 72 | return new String[0]; |
| 73 | } |
| 74 | List<String> result = new LinkedList<String>(); |
| 75 | int i; |
| 76 | for (File f : files) { |
| 77 | i = f.getName().indexOf(Common.KEY_EXTENSION); |
| 78 | if (i != -1) { |
| 79 | result.add(Common.unescapeHTML(f.getName().substring(0, i))); |
| 80 | } |
| 81 | } |
| 82 | return result.toArray(new String[0]); |
| 83 | } |
| 84 | |
| 85 | public String[] getCategories(int start, int length) { |
| 86 | |
| 87 | // TODO: implement category trackers |
| 88 | |
| 89 | return new String[0]; |
| 90 | } |
| 91 | |
| 92 | public int getEntryCount(Date after, Date before, String query, |
| 93 | String[] mentions, String[] tags, String verb) { |
| 94 | // not supported |
| 95 | return -1; |
| 96 | } |
| 97 | |
| 98 | public String[] getEntryIds(int start, int length, Date after, Date before, |
| 99 | String query, String[] mentions, String[] tags, String verb) { |
| 100 | // not supported |
| 101 | return null; |
| 102 | } |
| 103 | |
| 104 | public int getEntryCountForFeedId(String feedId, Date after, Date before, |
| 105 | String query, String[] mentions, String[] tags, String verb) { |
| 106 | File[] files = new File(root, feedId).listFiles(new FileFilter() { |
| 107 | public boolean accept(File file) { |
| 108 | return file.getName().toLowerCase().endsWith(ENTRY_SUFFIX); |
nothing calls this directly
no outgoing calls
no test coverage detected