Changeset 4800


Ignore:
Timestamp:
2003-06-25T13:55:34+12:00 (21 years ago)
Author:
jmt12
Message:

bug#2030155: Added greenstone collection mapping for world node, and also hid modelcol in greenstone collections

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/file/FileNode.java

    r4686 r4800  
    233233
    234234    public void map() {
    235     // Only map if there are no children.
    236     if(children == null && file != null && getAllowsChildren()) {
    237         ///ystem.err.println("Map: " + this);
     235    if(children == null) {
    238236        children = new ArrayList();
    239         File[] files = file.listFiles();
    240         if(files != null && files.length > 0) {
    241         ArrayTools tools = new ArrayTools();
    242         // Apply the filters set in the model.
    243         FileFilter[] filters = model.getFilters();
    244         for(int i = 0; filters != null && i < filters.length; i++) {
    245             files = tools.filter(files, filters[i].filter, filters[i].exclude);
     237        // Super Special Case: if the name of this node is the Tree.World string, then we actually map the collections installed in greenstone. The file in this case will actually by the collect directory of greenstone.
     238        if(file == null && title.equals(Gatherer.dictionary.get("Tree.World"))) {
     239        ///atherer.println("Map the 'Greenstone Collections' node.");
     240        // For each of the children directories, which are collections...
     241        File start = new File(Utility.getCollectionDir(Gatherer.config.gsdl_path));
     242        File cols[] = start.listFiles();
     243        ArrayTools.sort(cols);
     244        // We add their import and gimport directories, but only if its not our current collection.
     245        for(int i = 0; cols != null && i < cols.length; i++) {
     246            if(!cols[i].getName().equals("modelcol") && (!Gatherer.c_man.ready() || !Gatherer.c_man.getCollectionDirectory().equals(cols[i].getAbsolutePath()))) {
     247            File dirs[] = cols[i].listFiles();
     248            ArrayTools.sort(dirs);
     249            File import_dir = new File(cols[i], "gimport");
     250            if(!import_dir.exists()) {
     251                import_dir = new File(cols[i], "import");
     252            }
     253            if(import_dir.exists()) {
     254                FileNode collection_root = new FileNode(import_dir, cols[i].getName(), true);
     255                collection_root.setParent(this);
     256                children.add(collection_root);
     257                collection_root = null;
     258            }
     259            import_dir = null;
     260            dirs = null;
     261            }
    246262        }
    247         // If this node just happens to be the greenstone collection directory
    248         if(Gatherer.c_man != null && Gatherer.c_man.ready() && file.equals(new File(Utility.getCollectionDir(Gatherer.config.gsdl_path)))) {
    249             // Preclude the directory of any open collection
    250             String collection_name = Gatherer.c_man.getCollection().getName();
    251             for(int j = 0; j < files.length; j++) {
    252             ///ystem.err.println("Does " + files[j].getName() + " equal " + collection_name + "?");
    253             if(files[j].getName().equals(collection_name) || files[j].getName().equals("modelcol")) {
    254                 // Remove the offending directory
    255                 files = ArrayTools.remove(files, j);
    256             }
    257             }
    258         }
    259         // Finally remove any files whose canonical path do not match their absolute one (ie symbolic links). We only do this test under linux, because under windows there is no such thing as a symbolic link, and instead we suffer difficulties with the 16bit truncated file paths not being the same as the canonical ones (i.e Program Files => Progra~1).
    260         if(!Utility.isWindows()) {
    261             for(int k = files.length; k != 0; k--) {
    262             try {
    263                 if(!files[k-1].getAbsolutePath().equals(files[k-1].getCanonicalPath())) {
    264                 ///ystem.err.println("For file: " + files[k-1].getName());
    265                 ///ystem.err.println("Absolute Path:  " + files[k-1].getAbsolutePath());
    266                 ///ystem.err.println("Canonical Path: " + files[k-1].getCanonicalPath());
    267                 files = ArrayTools.remove(files, (k-1));
     263        cols = null;
     264        model.nodeStructureChanged(this);
     265        }
     266        // General case: Only map if there are no children.
     267        else if(file != null && getAllowsChildren()) {
     268        File[] files = file.listFiles();
     269        if(files != null && files.length > 0) {
     270            ArrayTools tools = new ArrayTools();
     271            // Apply the filters set in the model.
     272            FileFilter[] filters = model.getFilters();
     273            for(int i = 0; filters != null && i < filters.length; i++) {
     274            files = tools.filter(files, filters[i].filter, filters[i].exclude);
     275            }
     276            // If this node just happens to be the greenstone collection directory
     277            if(Gatherer.c_man != null && Gatherer.c_man.ready() && file.equals(new File(Utility.getCollectionDir(Gatherer.config.gsdl_path)))) {
     278            // Preclude the directory of any open collection
     279            String collection_name = Gatherer.c_man.getCollection().getName();
     280            for(int j = 0; j < files.length; j++) {
     281                ///ystem.err.println("Does " + files[j].getName() + " equal " + collection_name + "?");
     282                if(files[j].getName().equals(collection_name)) {
     283                // Remove the offending directory
     284                files = ArrayTools.remove(files, j);
    268285                }
    269286            }
    270             catch (IOException exception) {
    271                 Gatherer.printStackTrace(exception);
     287            }
     288            // Finally remove any files whose canonical path do not match their absolute one (ie symbolic links). We only do this test under linux, because under windows there is no such thing as a symbolic link, and instead we suffer difficulties with the 16bit truncated file paths not being the same as the canonical ones (i.e Program Files => Progra~1).
     289            if(!Utility.isWindows()) {
     290            for(int k = files.length; k != 0; k--) {
     291                try {
     292                if(!files[k-1].getAbsolutePath().equals(files[k-1].getCanonicalPath())) {
     293                    ///ystem.err.println("For file: " + files[k-1].getName());
     294                    ///ystem.err.println("Absolute Path:  " + files[k-1].getAbsolutePath());
     295                    ///ystem.err.println("Canonical Path: " + files[k-1].getCanonicalPath());
     296                    files = ArrayTools.remove(files, (k-1));
     297                }
     298                }
     299                catch (IOException exception) {
     300                Gatherer.printStackTrace(exception);
     301                }
    272302            }
    273303            }
     304            // Sort the remaining files.
     305            tools.sort(files, true);
     306            // Now add them to children.
     307            for(int i = 0; i < files.length; i++) {
     308            FileNode child = new FileNode(files[i], model, children_readonly);
     309            child.setParent(this);
     310            children.add(child);
     311            }
    274312        }
    275         // Sort the remaining files.
    276         tools.sort(files, true);
    277         // Now add them to children.
    278         for(int i = 0; i < files.length; i++) {
    279             FileNode child = new FileNode(files[i], model, children_readonly);
    280             child.setParent(this);
    281             children.add(child);
    282         }
    283         }
    284         model.nodeStructureChanged(this);
    285     }
    286     else {
    287         ///ystem.err.println("Can't map: " + this + ". No file or doesn't allow children.");
     313        model.nodeStructureChanged(this);
     314        }
    288315    }
    289316    }
     
    356383    public void unmap() {
    357384    // You cannot unmap nodes that have no file basis.
    358     if(file != null) {
    359                 ///ystem.err.println("Unmap: " + this);
     385    if(file != null || title.equals(Gatherer.dictionary.get("Tree.World"))) {
     386        ///atherer.println("Unmap: " + this);
    360387        children = null;
    361388    }
Note: See TracChangeset for help on using the changeset viewer.