package textbender.a.u.transfer.clipboard; // Copyright 2007, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Textbender Software"), to deal in the Textbender Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Textbender Software, and to permit persons to whom the Textbender Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Textbender Software. THE TEXTBENDER SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TEXTBENDER SOFTWARE OR THE USE OR OTHER DEALINGS IN THE TEXTBENDER SOFTWARE. import java.io.*; import textbender.a.r.desk.*; import textbender.g.lang.ThreadSafe; /** Modelling the... [Probably only filename() is needed. So this class is superfluous. FIX.] */ @ThreadSafe final class SourceDocumentFile extends File { /** Constructs an instance of SourceDocumentFile in the {@linkplain #DIRECTORY directory}. * * @param clipIndex0 designating the {@linkplain IndexBlock index block} * with which this file is associated (1:1), * and from which its name is formed * @param keySD containing other key particulars of this file * @param clipIndexEncoder to use */ SourceDocumentFile( long clipIndex0, IndexBlockMapW.KeySD keySD, ClipIndexEncoder clipIndexEncoder ) { super( DIRECTORY, filename( clipIndex0, clipIndexEncoder )); // (radix 36; since base 64 would fail in case insensitive file systems)[padded to] this.keySD = keySD; } // ------------------------------------------------------------------------------------ static final File DIRECTORY = new File( IndexBlockMap.PACKAGE_DIRECTORY, "sOURCEdOCUMENT" ); static String filename( final long clipIndex0, final ClipIndexEncoder clipIndexEncoder ) { StringBuilder b = new StringBuilder(); final char padChar; if( Run.i().isFileSystemCaseSensitive() ) { b.append( clipIndexEncoder.cOf( clipIndex0 )); // preferable, consistency aids in debugging padChar = '-'; } else { b.append( Long.toString( clipIndex0, /*radix*/36 )); padChar = '0'; } while( b.length() < filenameLength ) { b.insert( 0, padChar ); } return b.toString(); } /** Re-index counter of the document, per attribute 'gR' of element 'gg'. */ String gR() { return keySD.gR(); } /** Revision-line ID of the document. */ String revisionLineID() { return keySD.revisionLineID(); } //// P r i v a t e /////////////////////////////////////////////////////////////////////// private static final int filenameLength; static { final String longestFilename; final Long clipIndexMax = Long.MAX_VALUE; if( Run.i().isFileSystemCaseSensitive() ) { ClipIndexEncoder clipIndexEncoder = new ClipIndexEncoder(); longestFilename = clipIndexEncoder.cOf( clipIndexMax ); } else longestFilename = Long.toString( clipIndexMax, /*radix*/36 ); filenameLength = longestFilename.length(); } private final IndexBlockMapW.KeySD keySD; }