=== modified file 'jsword/src/main/java/org/crosswire/jsword/book/sword/AbstractBackend.java' --- old/jsword/src/main/java/org/crosswire/jsword/book/sword/AbstractBackend.java 2009-10-30 01:15:14 +0000 +++ new/jsword/src/main/java/org/crosswire/jsword/book/sword/AbstractBackend.java 2009-11-04 17:55:32 +0000 @@ -147,6 +147,15 @@ } /** + * Sets alias for a comment on a verse range + * I.e. setRawText() was for verse range Gen.1.1-3 then setAliasKey should be called for Gen.1.1.2 and Gen.1.1.3 + * @param alias Alias Key + * @param source Source Key + * @throws IOException Exception when anything goes wrong on writing thr alias + */ + public void setAliasKey(Key alias, Key source) throws IOException {} + + /** * Create the directory to hold the Book if it does not exist. * * @throws IOException === modified file 'jsword/src/main/java/org/crosswire/jsword/book/sword/RawFileBackend.java' --- old/jsword/src/main/java/org/crosswire/jsword/book/sword/RawFileBackend.java 2009-10-30 01:15:14 +0000 +++ new/jsword/src/main/java/org/crosswire/jsword/book/sword/RawFileBackend.java 2009-11-04 18:06:35 +0000 @@ -126,10 +126,22 @@ encipher(textData); writeTextDataFile(dataFile, textData); - if (oIndex >= this.incfileValue) { - this.incfileValue = oIndex + 1; - writeIncfile(this.incfileValue); - } + checkAndIncrementIncfile(oIndex); + } + + public void setAliasKey(Key alias, Key source) throws IOException { + Verse aliasVerse = KeyUtil.getVerse(alias); + Verse sourceVerse = KeyUtil.getVerse(source); + int testament = SwordConstants.getTestament(aliasVerse); + long aliasIndex = SwordConstants.getIndex(aliasVerse); + //long sourceIndex = SwordConstants.getIndex(sourceVerse); + int aliasOIndex = aliasVerse.getOrdinal() - 1; + int sourceOIndex = sourceVerse.getOrdinal() - 1; + + updateIndexFile(testament, aliasIndex); + updateDataFile(testament, sourceOIndex); + + checkAndIncrementIncfile(aliasOIndex); } private void initIncFile() { @@ -209,6 +221,13 @@ } } + private void checkAndIncrementIncfile(int index) throws IOException { + if (index >= this.incfileValue) { + this.incfileValue = index + 1; + writeIncfile(this.incfileValue); + } + } + /* * (non-Javadoc) * === modified file 'jsword/src/main/java/org/crosswire/jsword/book/sword/SwordBook.java' --- old/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordBook.java 2009-11-03 20:29:55 +0000 +++ new/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordBook.java 2009-11-04 17:33:13 +0000 @@ -193,7 +193,11 @@ * .Key, org.crosswire.jsword.passage.Key) */ public void setAliasKey(Key alias, Key source) throws BookException { - throw new BookException(Msg.DRIVER_READONLY); + try { + backend.setAliasKey(alias, source); + } catch(IOException e) { + throw new BookException(Msg.UNABLE_TO_SAVE_VERSE, new Object[] {alias.getOsisID()}); + } } /* === modified file 'jsword/src/test/java/org/crosswire/jsword/book/sword/RawFileBackendTest.java' --- old/jsword/src/test/java/org/crosswire/jsword/book/sword/RawFileBackendTest.java 2009-10-30 01:15:14 +0000 +++ new/jsword/src/test/java/org/crosswire/jsword/book/sword/RawFileBackendTest.java 2009-11-04 18:00:38 +0000 @@ -28,8 +28,7 @@ import junit.framework.TestCase; import org.crosswire.jsword.book.BookException; -import org.crosswire.jsword.passage.NoSuchVerseException; -import org.crosswire.jsword.passage.Verse; +import org.crosswire.jsword.passage.*; /** * A Raw File format that allows for each verse to have it's own storage. @@ -97,4 +96,18 @@ assertEquals(backend.getRawText(ntVerse3), "Hello NT3"); //$NON-NLS-1$ assertEquals(backend.getRawText(ntVerse4), "Hello NT4"); //$NON-NLS-1$ } + + public void testSetAliasKey() throws NoSuchVerseException, IOException, BookException { + Verse source = VerseFactory.fromString("Gen 1:1"); + Verse alias1 = VerseFactory.fromString("Gen 1:2"); + Verse alias2 = VerseFactory.fromString("Gen 1:3"); + + backend.setRawText(source, "Hello Alias test!"); + backend.setAliasKey(alias1, source); + backend.setAliasKey(alias2, source); + + assertEquals(backend.getRawText(source), "Hello Alias test!"); + assertEquals(backend.getRawText(alias1), "Hello Alias test!"); + assertEquals(backend.getRawText(alias2), "Hello Alias test!"); + } }