Changeset 18354

Show
Ignore:
Timestamp:
12.01.2009 11:17:50 (10 years ago)
Author:
kjdon
Message:

updated the rtl-gli branch with files from trunk. Result of a merge 14807:18318

Location:
gli/branches/rtl-gli/src/org/greenstone/gatherer/file
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • gli/branches/rtl-gli/src/org/greenstone/gatherer/file/FileManager.java

    r13605 r18354  
    4545import org.greenstone.gatherer.collection.CollectionTreeNode; 
    4646import org.greenstone.gatherer.gui.ExplodeMetadataDatabasePrompt; 
     47import org.greenstone.gatherer.gui.ReplaceSrcDocWithHtmlPrompt;  
    4748import org.greenstone.gatherer.gui.GProgressBar; 
    4849import org.greenstone.gatherer.gui.NewFolderOrFilePrompt; 
     
    179180                source_files[i] = source_nodes[i].getFile(); 
    180181            } 
    181             RemoteGreenstoneServer.uploadFilesIntoCollection(collection_name, source_files, target_node.getFile()); 
     182            Gatherer.remoteGreenstoneServer.uploadFilesIntoCollection(collection_name, source_files, target_node.getFile()); 
    182183            } 
    183184            else if (type == FileJob.DELETE) { 
    184185            // Deletes: delete each top-level file/directory one at a time 
    185186            for (int i = 0; i < source_nodes.length; i++) { 
    186                 RemoteGreenstoneServer.deleteCollectionFile(collection_name, source_nodes[i].getFile()); 
     187                Gatherer.remoteGreenstoneServer.deleteCollectionFile(collection_name, source_nodes[i].getFile()); 
    187188            } 
    188189            } 
     
    190191            // Moves: move each top-level file/directory one at a time 
    191192            for (int i = 0; i < source_nodes.length; i++) { 
    192                 RemoteGreenstoneServer.moveCollectionFile(collection_name, source_nodes[i].getFile(), target_node.getFile()); 
     193                Gatherer.remoteGreenstoneServer.moveCollectionFile( 
     194                                     collection_name, source_nodes[i].getFile(), target_node.getFile()); 
    193195            } 
    194196            } 
     
    201203    } 
    202204 
    203  
    204205    public void explodeMetadataDatabase(File file) 
    205206    { 
     
    208209    } 
    209210 
     211    // Works with replace_srcdoc_with_html.pl 
     212    public void replaceSrcDocWithHtml(File[] files) 
     213    { 
     214    // This must go in a separate thread because we need the progress bar to work (remote Greenstone server) 
     215    new ReplaceSrcDocWithHtmlPromptTask(files).start(); 
     216    } 
    210217 
    211218    private class ExplodeMetadataDatabasePromptTask 
     
    222229    { 
    223230        ExplodeMetadataDatabasePrompt emp = new ExplodeMetadataDatabasePrompt(metadata_database_file); 
     231    } 
     232    } 
     233 
     234    // Works with replace_srcdoc_with_html.pl 
     235    private class ReplaceSrcDocWithHtmlPromptTask 
     236    extends Thread 
     237    { 
     238    private File[] replace_these_srcdoc_files = null; 
     239 
     240    public ReplaceSrcDocWithHtmlPromptTask(File[] replace_these_srcdoc_files) 
     241    { 
     242        this.replace_these_srcdoc_files = replace_these_srcdoc_files; 
     243    } 
     244 
     245    public void run() 
     246    { 
     247        ReplaceSrcDocWithHtmlPrompt prompt = new ReplaceSrcDocWithHtmlPrompt(replace_these_srcdoc_files); 
    224248    } 
    225249    } 
     
    249273        // ... but only if it is inside the collection and we haven't already downloaded it 
    250274        if (file.getAbsolutePath().startsWith(Gatherer.getCollectDirectoryPath()) && file.length() == 0) { 
    251             if (RemoteGreenstoneServer.downloadCollectionFile(CollectionManager.getLoadedCollectionName(), file).equals("")) { 
     275            if (Gatherer.remoteGreenstoneServer.downloadCollectionFile( 
     276                                 CollectionManager.getLoadedCollectionName(), file).equals("")) { 
    252277            // Something has gone wrong downloading the file 
    253278            return; 
     
    324349                folder_file.createNewFile(); 
    325350                if (Gatherer.isGsdlRemote) { 
    326                 RemoteGreenstoneServer.uploadCollectionFile(CollectionManager.getLoadedCollectionName(), folder_file); 
     351                Gatherer.remoteGreenstoneServer.uploadCollectionFile( 
     352                                         CollectionManager.getLoadedCollectionName(), folder_file); 
    327353                } 
    328354            } 
     
    330356                folder_file.mkdirs(); 
    331357                if (Gatherer.isGsdlRemote) { 
    332                 RemoteGreenstoneServer.newCollectionDirectory(CollectionManager.getLoadedCollectionName(), folder_file); 
     358                Gatherer.remoteGreenstoneServer.newCollectionDirectory( 
     359                                         CollectionManager.getLoadedCollectionName(), folder_file); 
    333360                } 
    334361            } 
     
    390417        file_queue.addJob(System.currentTimeMillis(), collection_tree, new FileNode[] { collection_tree_node }, collection_tree, new_collection_tree_node, FileJob.RENAME); 
    391418        if (Gatherer.isGsdlRemote) { 
    392             RemoteGreenstoneServer.moveCollectionFile(CollectionManager.getLoadedCollectionName(), collection_file, new_collection_file); 
     419            Gatherer.remoteGreenstoneServer.moveCollectionFile( 
     420                             CollectionManager.getLoadedCollectionName(), collection_file, new_collection_file); 
    393421        } 
    394422        } 
     
    439467        file_queue.addJob(System.currentTimeMillis(), Gatherer.g_man.gather_pane.workspace_tree, new FileNode[] { source_node }, collection_tree, (FileNode)collection_tree_node.getParent(),  FileJob.COPY_FILE_ONLY); 
    440468        if (Gatherer.isGsdlRemote) { 
    441         RemoteGreenstoneServer.uploadFilesIntoCollection(CollectionManager.getLoadedCollectionName(), new File[] { new_file }, target_directory); 
     469        Gatherer.remoteGreenstoneServer.uploadFilesIntoCollection( 
     470                         CollectionManager.getLoadedCollectionName(), new File[] { new_file }, target_directory); 
    442471        } 
    443472        // do a replace of old file with new file 
  • gli/branches/rtl-gli/src/org/greenstone/gatherer/file/FileNode.java

    r11762 r18354  
    2020    protected FileSystemModel model = null; 
    2121    protected MutableTreeNode parent = null; 
     22    /** The string that is displayed as the filename. Attempts to be in the correct encoding. */ 
     23    protected String displayFileName = null; 
    2224 
    2325 
     
    2729 
    2830    // Files cannot have children 
    29     if (file != null && file.isFile()) { 
     31    if (file != null && !file.isDirectory()) { //file.isFile()) { 
    3032        // Cache this result to prevent unceasing missing disk messages being thrown if the 
    3133        // removable media was, um, removed after directory mapped 
    3234        this.allows_children = false; 
    33     } 
    34     } 
    35  
     35        displayFileName = calcDisplayString(); 
     36    }    
     37    } 
     38 
     39 
     40     /** This method returns a string representation of the filenodes in the Collection 
     41     * Tree, that can then be displayed in the tree.  
     42     * We'll initially assume that the filenames are utf8 encoded and so convert the 
     43     * filename into utf8 for proper presentation in the Collection tree pane. 
     44     * If the filenames are not utf8, then the conversion would have introduced funny 
     45     * characters. Therefore, when converting to utf8, if the converted filename  
     46     * contains the special character '\ufffd', then we know the conversion did not work 
     47     * and we return the original string which may or may not be properly presented by 
     48     * default. 
     49     * See http://java.sun.com/j2se/1.4.2/docs/api/java/nio/charset/CharsetDecoder.html 
     50     * which says "How a decoding error is handled depends upon the action requested for  
     51     * that type of error, which is described by an instance of the CodingErrorAction class. 
     52     * The possible error actions are to ignore the erroneous input, report the error to 
     53     * the invoker via the returned CoderResult object, or replace the erroneous input with 
     54     * the current value of the replacement string. The replacement has the initial value  
     55     * "\uFFFD"; its value may be changed via the replaceWith method." 
     56     * The following made me think that String(byte[], String charsetName) constructor may 
     57     * use the replacement value \uFFFD. 
     58     * http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20512969.html 
     59     * mentions the following which made me think of this:  
     60     * convertedStr = convertedStr.replace('\ufffd', ' '); 
     61     */ 
     62    protected String calcDisplayString() { 
     63    String filename = file.getName(); 
     64    try{ 
     65        String utf8filename = new String(filename.getBytes(), "UTF8"); 
     66        if(utf8filename.indexOf('\ufffd') == -1) { 
     67        return utf8filename; 
     68        } else { // contains the character indicating that it's invalid utf8 
     69        // return the original string 
     70        return filename; 
     71        } 
     72    } catch(java.io.UnsupportedEncodingException e) { 
     73        return filename; 
     74    } 
     75    } 
    3676 
    3777    /** Returns the children of the node as an Enumeration. */ 
     
    312352    } 
    313353    else { 
    314         return file.getName(); 
     354        if(displayFileName == null) {     
     355        displayFileName = calcDisplayString(); 
     356        } 
     357        return displayFileName; //return file.getName();         
    315358    } 
    316359    }