return save(support.process(url, pg), null);
}
+ /**
+ * Import the story from one library to another, and keep the same LUID.
+ *
+ * @param other
+ * the other library to import from
+ * @param luid
+ * the Library UID
+ * @param pg
+ * the optional progress reporter
+ *
+ * @throws IOException
+ * in case of I/O error
+ */
+ public void imprt(BasicLibrary other, String luid, Progress pg)
+ throws IOException {
+ Progress pgGetStory = new Progress();
+ Progress pgSave = new Progress();
+ if (pg == null) {
+ pg = new Progress();
+ }
+
+ pg.setMinMax(0, 2);
+ pg.addProgress(pgGetStory, 1);
+ pg.addProgress(pgSave, 1);
+
+ Story story = other.getStory(luid, pgGetStory);
+ if (story != null) {
+ story = this.save(story, luid, pgSave);
+ pg.done();
+ } else {
+ pg.done();
+ throw new IOException("Cannot find story in Library: " + luid);
+ }
+ }
+
/**
* Export the {@link Story} to the given target in the given format.
*
}
}
+ @Override
+ public void imprt(BasicLibrary other, String luid, Progress pg)
+ throws IOException {
+ if (pg == null) {
+ pg = new Progress();
+ }
+
+ // Check if we can simply copy the files instead of the whole process
+ if (other instanceof LocalLibrary) {
+ LocalLibrary otherLibrary = (LocalLibrary) other;
+ MetaData meta = otherLibrary.getInfo(luid);
+ String expectedType = "" + (meta.isImageDocument() ? image : text);
+ if (meta.getType().equals(expectedType)) {
+ File from = otherLibrary.getExpectedDir(meta.getSource());
+ File to = this.getExpectedDir(meta.getSource());
+ List<File> sources = otherLibrary.getRelatedFiles(luid);
+ if (!sources.isEmpty()) {
+ pg.setMinMax(0, sources.size());
+ }
+
+ for (File source : sources) {
+ File target = new File(source.getAbsolutePath().replace(
+ from.getAbsolutePath(), to.getAbsolutePath()));
+ if (!source.equals(target)) {
+ InputStream in = null;
+ try {
+ in = new FileInputStream(source);
+ IOUtils.write(in, target);
+ } catch (IOException e) {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (Exception ee) {
+ }
+ }
+
+ pg.done();
+ throw e;
+ }
+ }
+
+ pg.add(1);
+ }
+
+ clearCache();
+ pg.done();
+ return;
+ }
+ }
+
+ super.imprt(other, luid, pg);
+ }
+
/**
* Return the {@link OutputType} for this {@link Story}.
*
* in case of I/O error
*/
public void imprt(String luid, Progress pg) throws IOException {
- Progress pgGetStory = new Progress();
- Progress pgSave = new Progress();
- if (pg != null) {
- pg.setMax(2);
- pg.addProgress(pgGetStory, 1);
- pg.addProgress(pgSave, 1);
- }
-
try {
- Story story = getLibrary().getStory(luid, pgGetStory);
- if (story != null) {
- story = localLibrary.save(story, luid, pgSave);
- } else {
- throw new IOException("Cannot find story in Library: " + luid);
- }
+ localLibrary.imprt(getLibrary(), luid, pg);
} catch (IOException e) {
throw new IOException(
"Cannot import story from library to LocalReader library: "