+ public Story save(Story story) throws IOException {
+ return save(story, null);
+ }
+
+ /**
+ * Save a {@link Story} to the {@link Library} -- the LUID <b>must</b> be
+ * correct, or NULL to get the next free one.
+ *
+ * @param story
+ * the {@link Story} to save
+ * @param luid
+ * the <b>correct</b> LUID or NULL to get the next free one
+ *
+ * @return the same {@link Story}, whose LUID may have changed
+ *
+ * @throws IOException
+ * in case of I/O error
+ */
+ private Story save(Story story, String luid) throws IOException {
+ // Do not change the original metadata, but change the original story
+ MetaData key = story.getMeta().clone();
+ story.setMeta(key);
+
+ if (luid == null || luid.isEmpty()) {
+ getStories(); // refresh lastId if needed
+ key.setLuid(String.format("%03d", (++lastId)));
+ } else {
+ key.setLuid(luid);
+ }