Changeset 24976


Ignore:
Timestamp:
2012-01-26T10:35:28+13:00 (12 years ago)
Author:
sjm84
Message:

Reformatting this file ahead of some changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/DocumentBasket.java

    r24509 r24976  
    5151import org.apache.log4j.*;
    5252
    53 public class DocumentBasket extends ServiceRack {
    54 
    55     static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.DocumentBasket.class.getName());
    56 
    57     // the services on offer
    58     // these strings must match what is found in the properties file
    59     protected static final String ADD_ITEM_SERVICE = "AddDocument";
    60     protected static final String DISPLAY_ITEMS_SERVICE = "DisplayDocumentList";
    61     protected static final String ITEM_NUM_SERVICE = "GetDocuments";
    62     protected static final String DELETE_ITEMS_SERVICE = "DeleteDocuments"; 
    63     protected static final String DELETE_ITEM_SERVICE = "DeleteDocument";
     53public class DocumentBasket extends ServiceRack
     54{
     55
     56    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.DocumentBasket.class.getName());
     57
     58    // the services on offer
     59    // these strings must match what is found in the properties file
     60    protected static final String ADD_ITEM_SERVICE = "AddDocument";
     61    protected static final String DISPLAY_ITEMS_SERVICE = "DisplayDocumentList";
     62    protected static final String ITEM_NUM_SERVICE = "GetDocuments";
     63    protected static final String DELETE_ITEMS_SERVICE = "DeleteDocuments";
     64    protected static final String DELETE_ITEM_SERVICE = "DeleteDocument";
    6465    //added
    6566    protected static final String MERGE_ITEM_SERVICE = "MergeDocument";
    6667    protected static final String ITEM_PARAM = "item";
    67     protected static final String delimiter ="|";
    68     protected static final int delay = 1800000;
    69    
    70     protected static final String BASKET_BOOK = "documentBasketBook";
    71 
    72     protected Hashtable userMap = null;
    73     protected Hashtable timerMap = null;
    74     protected String username="";
    75     protected String password="";
    76 
    77     /** constructor */
    78     public DocumentBasket()
    79     {
    80         userMap =  new Hashtable();
    81         timerMap = new Hashtable();
    82     }
    83 
    84     private Hashtable updateDocMap(Element request)
     68    protected static final String delimiter = "|";
     69    protected static final int delay = 1800000;
     70
     71    protected static final String BASKET_BOOK = "documentBasketBook";
     72
     73    protected Hashtable userMap = null;
     74    protected Hashtable timerMap = null;
     75    protected String username = "";
     76    protected String password = "";
     77
     78    /** constructor */
     79    public DocumentBasket()
     80    {
     81        userMap = new Hashtable();
     82        timerMap = new Hashtable();
     83    }
     84
     85    private Hashtable updateDocMap(Element request)
    8586    {
    8687        String id = request.getAttribute("uid");
    8788
    88         if (userMap.containsKey(id)){   
    89             if (timerMap.containsKey(id)){
    90                 UserTimer timer = (UserTimer)timerMap.get(id);
     89        if (userMap.containsKey(id))
     90        {
     91            if (timerMap.containsKey(id))
     92            {
     93                UserTimer timer = (UserTimer) timerMap.get(id);
    9194                timer.restart();
    92             }   
     95            }
    9396            return (Hashtable) userMap.get(id);
    9497        }
    9598        else
    9699        {
    97             UserTimer timer = new UserTimer(delay,id);
    98             timerMap.put(id,timer);
     100            UserTimer timer = new UserTimer(delay, id);
     101            timerMap.put(id, timer);
    99102            timer.start();
    100             Hashtable newDocs= new Hashtable();
    101             userMap.put(id,newDocs);
     103            Hashtable newDocs = new Hashtable();
     104            userMap.put(id, newDocs);
    102105            return newDocs;
    103         }   
    104     }
    105 
    106    
    107     /** configure this service */
    108     public boolean configure(Element info, Element extra_info)
    109     {
     106        }
     107    }
     108
     109    /** configure this service */
     110    public boolean configure(Element info, Element extra_info)
     111    {
    110112        logger.info("Configuring DocumentBasket...");
    111113        this.config_info = info;
     
    117119        this.short_service_info.appendChild(add_service);
    118120
    119        
    120121        // set up short_service_info_ - for now just has name and type
    121122        Element disp_service = this.doc.createElement(GSXML.SERVICE_ELEM);
     
    130131        this.short_service_info.appendChild(num_service);
    131132
    132             // set up short_service_info_ - for now just has name and type
     133        // set up short_service_info_ - for now just has name and type
    133134        Element delete_service = this.doc.createElement(GSXML.SERVICE_ELEM);
    134135        delete_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
     
    136137        this.short_service_info.appendChild(delete_service);
    137138
    138             // set up short_service_info_ - for now just has name and type
     139        // set up short_service_info_ - for now just has name and type
    139140        Element deleteone_service = this.doc.createElement(GSXML.SERVICE_ELEM);
    140141        deleteone_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
    141142        deleteone_service.setAttribute(GSXML.NAME_ATT, DELETE_ITEM_SERVICE);
    142143        this.short_service_info.appendChild(deleteone_service);
    143        
     144
    144145        // set up short_service_info_ - for now just has name and type
    145146        Element merge_service = this.doc.createElement(GSXML.SERVICE_ELEM);
     
    148149        this.short_service_info.appendChild(merge_service);
    149150
    150         return true;       
    151     }
    152 
    153     /** returns a specific service description */
    154     protected Element getServiceDescription(String service_id, String lang, String subset)
    155     {
    156         if (service_id.equals(ADD_ITEM_SERVICE)) {
     151        return true;
     152    }
     153
     154    /** returns a specific service description */
     155    protected Element getServiceDescription(String service_id, String lang, String subset)
     156    {
     157        if (service_id.equals(ADD_ITEM_SERVICE))
     158        {
    157159            Element add_service = this.doc.createElement(GSXML.SERVICE_ELEM);
    158160            add_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
     
    160162            return add_service;
    161163        }
    162         if (service_id.equals(DISPLAY_ITEMS_SERVICE)) {
    163            
     164        if (service_id.equals(DISPLAY_ITEMS_SERVICE))
     165        {
     166
    164167            Element disp_service = this.doc.createElement(GSXML.SERVICE_ELEM);
    165168            disp_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
     
    168171        }
    169172
    170         if (service_id.equals(ITEM_NUM_SERVICE)) {
    171            
     173        if (service_id.equals(ITEM_NUM_SERVICE))
     174        {
     175
    172176            Element num_service = this.doc.createElement(GSXML.SERVICE_ELEM);
    173177            num_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
     
    176180        }
    177181
    178         if (service_id.equals(DELETE_ITEMS_SERVICE)) {
    179            
     182        if (service_id.equals(DELETE_ITEMS_SERVICE))
     183        {
     184
    180185            Element del_service = this.doc.createElement(GSXML.SERVICE_ELEM);
    181186            del_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
     
    184189        }
    185190
    186         if (service_id.equals(DELETE_ITEM_SERVICE)) {
    187            
     191        if (service_id.equals(DELETE_ITEM_SERVICE))
     192        {
     193
    188194            Element delone_service = this.doc.createElement(GSXML.SERVICE_ELEM);
    189195            delone_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
     
    191197            return delone_service;
    192198        }
    193         if (service_id.equals(MERGE_ITEM_SERVICE)) {
     199        if (service_id.equals(MERGE_ITEM_SERVICE))
     200        {
    194201            Element merge_service = this.doc.createElement(GSXML.SERVICE_ELEM);
    195202            merge_service.setAttribute(GSXML.TYPE_ATT, "gather"); // what??
     
    198205        }
    199206        return null;
    200     }
    201 
    202     protected Element processAddDocument(Element request) {
     207    }
     208
     209    protected Element processAddDocument(Element request)
     210    {
    203211        //System.err.println("REQUEST = " + GSXML.xmlNodeToString(request));
    204         Hashtable docsMap = updateDocMap(request);
     212        Hashtable docsMap = updateDocMap(request);
    205213        //System.err.println("DOCSMAP = " + docsMap);
    206214        // Create a new (empty) result message
    207215        Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
    208        
     216
    209217        // Get the parameters of the request
    210         Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    211         if (param_list == null) {
     218        Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     219        if (param_list == null)
     220        {
    212221            logger.error("DocumentBasket Error: AddDocument request had no paramList.");
    213             return result;  // Return the empty result
    214         }
    215        
     222            return result; // Return the empty result
     223        }
     224
    216225        HashMap params = GSXML.extractParams(param_list, false);
    217226        //System.err.println("PARAMS = " + params);
    218         String item = (String)params.get("item");
    219        
     227        String item = (String) params.get("item");
     228
    220229        int startIndex = item.startsWith(BASKET_BOOK) ? BASKET_BOOK.length() : 0;
    221        
     230
    222231        String collection = "";
    223232        int pos = item.indexOf(":");
    224         if (pos != -1) {
    225             collection = item.substring(startIndex,pos);
    226             item = item.substring(pos+1);
     233        if (pos != -1)
     234        {
     235            collection = item.substring(startIndex, pos);
     236            item = item.substring(pos + 1);
    227237        }
    228238        //logger.error("COLLECTION = " + collection + " *** ITEM = " + item);
    229         if (docsMap.containsKey(collection)){
     239        if (docsMap.containsKey(collection))
     240        {
    230241            Hashtable items = (Hashtable) docsMap.get(collection);
    231             if (!items.containsKey(item)){
    232                 Item newItem = generateItem(collection,item);
     242            if (!items.containsKey(item))
     243            {
     244                Item newItem = generateItem(collection, item);
    233245                items.put(item, newItem);
    234246                result.appendChild(newItem.wrapIntoElement());
    235247            }
    236248        }
    237         else{
     249        else
     250        {
    238251            Hashtable items = new Hashtable();
    239             Item newItem = generateItem(collection,item);
     252            Item newItem = generateItem(collection, item);
    240253            items.put(item, newItem);
    241             docsMap.put(collection,items);
     254            docsMap.put(collection, items);
    242255            result.appendChild(newItem.wrapIntoElement());
    243256        }
    244        
     257
    245258        return result;
    246     }
    247    
     259    }
     260
    248261    protected Element processMergeDocument(Element request)
    249262    {
    250263        // Get the parameters of the request
    251         Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    252         if (param_list == null) {
     264        Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     265        if (param_list == null)
     266        {
    253267            logger.error("DocumentBasket Error: MergeDocument request had no paramList.");
    254             return null;  // Return the empty result
    255         }
    256        
     268            return null; // Return the empty result
     269        }
     270
    257271        HashMap params = GSXML.extractParams(param_list, false);
    258        
    259         String docString = (String)params.get("docs");
     272
     273        String docString = (String) params.get("docs");
    260274        String[] docs = docString.split("-");
    261        
    262         for(String d : docs)
     275
     276        for (String d : docs)
    263277        {
    264278            logger.error("DOC = " + d);
    265279        }
    266        
    267 /*     
    268         try{
    269             System.out.println("Concatenate Two PDF");
    270             PdfReader reader1 = new PdfReader("3A01-01_Part_1-001.pdf");
    271             PdfReader reader2 = new PdfReader("3A01-01_Part_1-017.pdf");
    272             PdfCopyFields copy =
    273             new PdfCopyFields(new FileOutputStream("concatenatedPDF.pdf"));
    274             copy.addDocument(reader1);
    275             copy.addDocument(reader2);
    276             copy.close();
    277         }
    278         catch(Exception ex)
     280
     281        /*
     282         * try{ System.out.println("Concatenate Two PDF"); PdfReader reader1 =
     283         * new PdfReader("3A01-01_Part_1-001.pdf"); PdfReader reader2 = new
     284         * PdfReader("3A01-01_Part_1-017.pdf"); PdfCopyFields copy = new
     285         * PdfCopyFields(new FileOutputStream("concatenatedPDF.pdf"));
     286         * copy.addDocument(reader1); copy.addDocument(reader2); copy.close(); }
     287         * catch(Exception ex) { ex.printStackTrace(); }
     288         */
     289        // added -->
     290
     291        try
     292        {
     293            {
     294                PrintWriter pw = new PrintWriter(new FileOutputStream("G:/output1.xml"));
     295                File file = new File("G:/greenstone3-svn/web/sites/localsite/collect/peij21/archives/HASH0189.dir/");
     296                File[] files = file.listFiles();
     297
     298                for (int i = 0; i < files.length; i++)
     299                {
     300
     301                    //System.out.println(files[i].getName());
     302                    String fileName = files[i].getName();
     303
     304                    if (fileName.equals("doc.xml"))
     305                    {
     306
     307                        System.out.println("Processing " + files[i].getPath() + "... ");
     308                        BufferedReader br = new BufferedReader(new FileReader(files[i].getPath()));
     309                        String line = br.readLine();
     310                        while (line != null)
     311                        {
     312                            pw.println(line);
     313                            line = br.readLine();
     314                        }
     315                        br.close();
     316
     317                    }
     318
     319                }
     320
     321                File file1 = new File("G:/greenstone3-svn/web/sites/localsite/collect/peij21/archives/HASHfdc0.dir/");
     322                File[] files1 = file1.listFiles();
     323
     324                for (int i = 0; i < files1.length; i++)
     325                {
     326
     327                    //System.out.println(files[i].getName());
     328                    String fileName = files1[i].getName();
     329
     330                    if (fileName.equals("doc.xml"))
     331                    {
     332
     333                        System.out.println("Processing " + files1[i].getPath() + "... ");
     334                        BufferedReader br = new BufferedReader(new FileReader(files1[i].getPath()));
     335                        String line = br.readLine();
     336                        while (line != null)
     337                        {
     338                            pw.println(line);
     339                            line = br.readLine();
     340                        }
     341                        br.close();
     342
     343                    }
     344
     345                }
     346
     347                pw.close();
     348
     349                System.out.println("All doc.xml files have been concatenated into output1.xml");
     350            }
     351        }
     352        catch (Exception ex)
    279353        {
    280354            ex.printStackTrace();
    281355        }
    282         */
    283 // added -->
    284 
    285 try{
    286 {
    287     PrintWriter pw = new PrintWriter(new FileOutputStream("G:/output1.xml"));
    288     File file = new File("G:/greenstone3-svn/web/sites/localsite/collect/peij21/archives/HASH0189.dir/");
    289     File[] files = file.listFiles();
    290 
    291     for (int i = 0; i < files.length; i++)
    292     {
    293 
    294         //System.out.println(files[i].getName());
    295         String fileName= files[i].getName();
    296 
    297         if (fileName.equals("doc.xml")) {
    298 
    299             System.out.println("Processing " + files[i].getPath() + "... ");
    300             BufferedReader br = new BufferedReader(new FileReader(files[i].getPath()));
    301             String line = br.readLine();
    302             while (line != null)
    303                 {
    304                 pw.println(line);
    305                 line = br.readLine();
    306                 }
    307             br.close();
    308 
    309         }
    310 
    311     }
    312 
    313 
    314 
    315     File file1 = new File("G:/greenstone3-svn/web/sites/localsite/collect/peij21/archives/HASHfdc0.dir/");
    316     File[] files1 = file1.listFiles();
    317 
    318     for (int i = 0; i < files1.length; i++)
    319     {
    320 
    321         //System.out.println(files[i].getName());
    322         String fileName= files1[i].getName();
    323 
    324         if (fileName.equals("doc.xml")) {
    325 
    326             System.out.println("Processing " + files1[i].getPath() + "... ");
    327             BufferedReader br = new BufferedReader(new FileReader(files1[i].getPath()));
    328             String line = br.readLine();
    329             while (line != null)
    330                 {
    331                 pw.println(line);
    332                 line = br.readLine();
    333                 }
    334             br.close();
    335 
    336         }
    337 
    338     }
    339 
    340 
    341 pw.close();
    342 
    343     System.out.println("All doc.xml files have been concatenated into output1.xml");
    344 }
    345 } catch(Exception ex)
    346 {
    347     ex.printStackTrace();
    348 }
    349 return null;
    350 }
    351 
    352 
    353 //end
    354     private Item generateItem(String collection, String id){
     356        return null;
     357    }
     358
     359    //end
     360    private Item generateItem(String collection, String id)
     361    {
    355362        Item item = new Item(collection, id);
    356363        String to = GSPath.appendLink(collection, "DocumentMetadataRetrieve");
    357364        ArrayList tmp = new ArrayList();
    358         tmp.add(id); 
    359         Element response = getDocumentMetadata(to,"en","dumy", tmp.iterator());
    360         Element doc_node = (Element)response.getElementsByTagName(GSXML.DOC_NODE_ELEM).item(0);
     365        tmp.add(id);
     366        Element response = getDocumentMetadata(to, "en", "dumy", tmp.iterator());
     367        Element doc_node = (Element) response.getElementsByTagName(GSXML.DOC_NODE_ELEM).item(0);
    361368
    362369        String node_id = doc_node.getAttribute(GSXML.NODE_ID_ATT);
    363         Element metadata_list = (Element)doc_node.getElementsByTagName(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER).item(0);
     370        Element metadata_list = (Element) doc_node.getElementsByTagName(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER).item(0);
    364371
    365372        //assign title metadata if any
    366         Element metadata = GSXML.getNamedElement(metadata_list,"metadata","name","Title");
    367         if (metadata != null){
     373        Element metadata = GSXML.getNamedElement(metadata_list, "metadata", "name", "Title");
     374        if (metadata != null)
     375        {
    368376            item.title = GSXML.getNodeText(metadata).trim();
    369         } 
     377        }
    370378        //assign date metadata if any
    371         metadata = GSXML.getNamedElement(metadata_list,"metadata","name","Date");
    372         if (metadata != null){
     379        metadata = GSXML.getNamedElement(metadata_list, "metadata", "name", "Date");
     380        if (metadata != null)
     381        {
    373382            item.date = GSXML.getNodeText(metadata).trim();
    374         }   
    375        
     383        }
     384
    376385        //assign root title metadata if any
    377         metadata = GSXML.getNamedElement(metadata_list,"metadata","name","root_Title");
    378         if (metadata != null){
    379                 String rootTitle = GSXML.getNodeText(metadata).trim();
    380                 if (!rootTitle.equals(item.title)){
    381                   item.rootTitle = rootTitle;
    382             }
    383            
     386        metadata = GSXML.getNamedElement(metadata_list, "metadata", "name", "root_Title");
     387        if (metadata != null)
     388        {
     389            String rootTitle = GSXML.getNodeText(metadata).trim();
     390            if (!rootTitle.equals(item.title))
     391            {
     392                item.rootTitle = rootTitle;
     393            }
     394
    384395        }
    385396
    386397        return item;
    387     }
    388 
    389 
    390     protected Element processDeleteDocuments(Element request) {
    391           Hashtable docsMap = updateDocMap(request);
    392    
     398    }
     399
     400    protected Element processDeleteDocuments(Element request)
     401    {
     402        Hashtable docsMap = updateDocMap(request);
     403
    393404        // Create a new (empty) result message
    394405        Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
    395        
     406
    396407        // Get the parameters of the request
    397         Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    398            
    399             //GSXML.printXMLNode(param_list);
    400 
    401         if (param_list == null) {
     408        Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     409
     410        //GSXML.printXMLNode(param_list);
     411
     412        if (param_list == null)
     413        {
    402414            logger.error("DocumentBasket Error: DeleteDocument request had no paramList.");
    403             return result;  // Return the empty result
     415            return result; // Return the empty result
    404416        }
    405417
    406418        HashMap params = GSXML.extractParams(param_list, false);
    407          
    408         String param = (String)params.get("items");
    409      
    410         if (param == null) return result;     
     419
     420        String param = (String) params.get("items");
     421
     422        if (param == null)
     423            return result;
    411424
    412425        String[] items = param.split("\\|");
    413      
    414         for (int i=0; i<items.length; i++)
     426
     427        for (int i = 0; i < items.length; i++)
    415428        {
    416429            String item = items[i];
    417             if (item.trim().length() == 0) continue;
    418            
     430            if (item.trim().length() == 0)
     431                continue;
     432
    419433            String collection = "";
    420434            int pos = item.indexOf(":");
    421             if (pos != -1) {
    422                 collection = item.substring(0,pos);
    423                 item = item.substring(pos+1);
    424             }
    425          
    426             if (docsMap.containsKey(collection)){
     435            if (pos != -1)
     436            {
     437                collection = item.substring(0, pos);
     438                item = item.substring(pos + 1);
     439            }
     440
     441            if (docsMap.containsKey(collection))
     442            {
    427443                Hashtable itemMap = (Hashtable) docsMap.get(collection);
    428                 if (itemMap.containsKey(item)){
     444                if (itemMap.containsKey(item))
     445                {
    429446                    itemMap.remove(item);
    430447                }
    431                 if (itemMap.size()==0){
     448                if (itemMap.size() == 0)
     449                {
    432450                    docsMap.remove(collection);
    433451                }
     
    436454
    437455        return result;
    438     }
    439 
    440      protected Element processDeleteDocument(Element request) {
    441           Hashtable docsMap = updateDocMap(request);
    442    
     456    }
     457
     458    protected Element processDeleteDocument(Element request)
     459    {
     460        Hashtable docsMap = updateDocMap(request);
     461
    443462        // Create a new (empty) result message
    444463        Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
    445        
     464
    446465        // Get the parameters of the request
    447         Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    448            
    449             //GSXML.printXMLNode(param_list);
    450 
    451         if (param_list == null) {
     466        Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     467
     468        //GSXML.printXMLNode(param_list);
     469
     470        if (param_list == null)
     471        {
    452472            logger.error("DocumentBasket Error: DeleteDocument request had no paramList.");
    453             return result;  // Return the empty result
     473            return result; // Return the empty result
    454474        }
    455475
    456476        HashMap params = GSXML.extractParams(param_list, false);
    457          
    458         String param = (String)params.get("item");
    459      
    460         if (param == null) return result;     
     477
     478        String param = (String) params.get("item");
     479
     480        if (param == null)
     481            return result;
    461482
    462483        String item = param;
    463      
     484
    464485        String collection = "";
    465486        int pos = item.indexOf(":");
    466        
    467         if (pos != -1) {
    468             collection = item.substring(0,pos);
    469             item = item.substring(pos+1);
    470         }
    471        
    472         if (docsMap.containsKey(collection)){
     487
     488        if (pos != -1)
     489        {
     490            collection = item.substring(0, pos);
     491            item = item.substring(pos + 1);
     492        }
     493
     494        if (docsMap.containsKey(collection))
     495        {
    473496            Hashtable itemMap = (Hashtable) docsMap.get(collection);
    474             if (itemMap.containsKey(item)){
     497            if (itemMap.containsKey(item))
     498            {
    475499                itemMap.remove(item);
    476500            }
    477             if (itemMap.size()==0){
     501            if (itemMap.size() == 0)
     502            {
    478503                docsMap.remove(collection);
    479504            }
    480         }       
     505        }
    481506
    482507        return result;
    483     }
    484 
    485 
    486     protected Element processGetDocuments(Element request){
    487         // GSXML.printXMLNode(request);
     508    }
     509
     510    protected Element processGetDocuments(Element request)
     511    {
     512        // GSXML.printXMLNode(request);
    488513        Hashtable docsMap = updateDocMap(request);
    489514
    490515        // Create a new (empty) result message
    491516        Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
    492    
    493         int size = 0;
    494         String ids ="";   
    495         Iterator keys = docsMap.keySet().iterator();
    496    
    497         while(keys.hasNext()){ 
    498             Hashtable items = (Hashtable) docsMap.get((String)keys.next());
    499             size+=items.size();
     517
     518        int size = 0;
     519        String ids = "";
     520        Iterator keys = docsMap.keySet().iterator();
     521
     522        while (keys.hasNext())
     523        {
     524            Hashtable items = (Hashtable) docsMap.get((String) keys.next());
     525            size += items.size();
    500526            Iterator values = items.values().iterator();
    501             while(values.hasNext()){
    502                 Item item = (Item)values.next();
    503                 result.appendChild(item.wrapIntoElement());
    504            
    505         }
    506 
    507         Element selement = this.doc.createElement("size");
    508         selement.setAttribute("value",size+"");
    509         result.appendChild(selement);
    510        
    511         return result;
    512     }
    513 
    514    
    515    
    516     private Element getDocumentMetadata(String to, String lang, String uid, Iterator ids){
    517    
    518         // Build a request to obtain some document metadata
     527            while (values.hasNext())
     528            {
     529                Item item = (Item) values.next();
     530                result.appendChild(item.wrapIntoElement());
     531            }
     532        }
     533
     534        Element selement = this.doc.createElement("size");
     535        selement.setAttribute("value", size + "");
     536        result.appendChild(selement);
     537
     538        return result;
     539    }
     540
     541    private Element getDocumentMetadata(String to, String lang, String uid, Iterator ids)
     542    {
     543
     544        // Build a request to obtain some document metadata
    519545        Element dm_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    520546        Element dm_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, lang, uid);
     
    524550        HashSet meta_names = new HashSet();
    525551        meta_names.add("Title"); // the default
    526         meta_names.add("root_Title");
    527         meta_names.add("Date");
    528 
    529 
    530         Element param_list  = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    531    
     552        meta_names.add("root_Title");
     553        meta_names.add("Date");
     554
     555        Element param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     556
    532557        Element param = null;
    533558        Iterator i = meta_names.iterator();
    534         while (i.hasNext()) {
    535             String name = (String)i.next();
     559        while (i.hasNext())
     560        {
     561            String name = (String) i.next();
    536562            param = this.doc.createElement(GSXML.PARAM_ELEM);
    537563            param_list.appendChild(param);
     
    539565            param.setAttribute(GSXML.VALUE_ATT, name);
    540566        }
    541    
     567
    542568        dm_request.appendChild(param_list);
    543    
     569
    544570        // create the doc node list for the metadata request
    545         Element dm_doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
     571        Element dm_doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
    546572        dm_request.appendChild(dm_doc_list);
    547573
    548         while (ids.hasNext()){
     574        while (ids.hasNext())
     575        {
    549576            // Add the documentNode to the list
    550577            Element dm_doc_node = this.doc.createElement(GSXML.DOC_NODE_ELEM);
    551578            dm_doc_list.appendChild(dm_doc_node);
    552             dm_doc_node.setAttribute(GSXML.NODE_ID_ATT,(String)ids.next());
     579            dm_doc_node.setAttribute(GSXML.NODE_ID_ATT, (String) ids.next());
    553580        }
    554581
    555582        return (Element) this.router.process(dm_message);
    556     }
    557 
    558 
    559     protected Element processDisplayDocumentList(Element request) {
    560         Hashtable docsMap = updateDocMap(request);
     583    }
     584
     585    protected Element processDisplayDocumentList(Element request)
     586    {
     587        Hashtable docsMap = updateDocMap(request);
    561588
    562589        // Create a new (empty) result message
    563590        Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
    564    
    565         Iterator keys = docsMap.keySet().iterator();
    566    
    567         while(keys.hasNext()){     
    568             String collection = (String)keys.next();
    569             Hashtable items = (Hashtable)docsMap.get(collection);
     591
     592        Iterator keys = docsMap.keySet().iterator();
     593
     594        while (keys.hasNext())
     595        {
     596            String collection = (String) keys.next();
     597            Hashtable items = (Hashtable) docsMap.get(collection);
    570598            Iterator itemItr = items.values().iterator();
    571            
     599
    572600            Element collectionNode = this.doc.createElement("documentList");
    573             collectionNode.setAttribute("name",collection);
     601            collectionNode.setAttribute("name", collection);
    574602            result.appendChild(collectionNode);
    575            
    576             while(itemItr.hasNext()){ 
    577                 Item item = (Item)itemItr.next();
     603
     604            while (itemItr.hasNext())
     605            {
     606                Item item = (Item) itemItr.next();
    578607                Element itemElement = this.doc.createElement("item");
    579            
     608
    580609                collectionNode.appendChild(itemElement);
    581610                itemElement.setAttribute("name", item.docid);
    582611                itemElement.setAttribute("collection", item.collection);
    583                 itemElement.setAttribute("title",item.title);
    584                 itemElement.setAttribute("date",item.date);
    585                 itemElement.setAttribute("root_title",item.rootTitle);               
    586             }       
    587         }
    588        
     612                itemElement.setAttribute("title", item.title);
     613                itemElement.setAttribute("date", item.date);
     614                itemElement.setAttribute("root_title", item.rootTitle);
     615            }
     616        }
     617
    589618        return result;
    590     }
    591 
    592     protected class Item {
     619    }
     620
     621    protected class Item
     622    {
    593623        public String collection;
    594624        public String docid;
    595         public String title="";
    596         public String query="";
    597         public String date="";
    598         public String rootTitle="";
    599        
    600         public Item(String coll, String id) {
     625        public String title = "";
     626        public String query = "";
     627        public String date = "";
     628        public String rootTitle = "";
     629
     630        public Item(String coll, String id)
     631        {
    601632            this.collection = coll;
    602633            this.docid = id;
    603634        }
    604635
    605         public boolean equals(Object o){
    606             if (! (o instanceof Item)){
     636        public boolean equals(Object o)
     637        {
     638            if (!(o instanceof Item))
     639            {
    607640                return false;
    608641            }
    609            
    610             Item item = (Item)o;
    611             String id = collection+":"+docid;
    612             String idin = item.collection+":"+item.docid;
     642
     643            Item item = (Item) o;
     644            String id = collection + ":" + docid;
     645            String idin = item.collection + ":" + item.docid;
    613646            return id.equals(idin);
    614         }   
    615 
    616         public String toString(){   
    617             return collection+":"+docid+":"+"["+((!rootTitle.equals(""))?(rootTitle+":"):"")+title+"]";
    618         }       
    619 
    620         public Element wrapIntoElement(){
    621             Element itemElement = doc.createElement("item"); 
     647        }
     648
     649        public String toString()
     650        {
     651            return collection + ":" + docid + ":" + "[" + ((!rootTitle.equals("")) ? (rootTitle + ":") : "") + title + "]";
     652        }
     653
     654        public Element wrapIntoElement()
     655        {
     656            Element itemElement = doc.createElement("item");
    622657            itemElement.setAttribute("name", docid);
    623658            itemElement.setAttribute("collection", collection);
    624             itemElement.setAttribute("title",title);
    625             itemElement.setAttribute("date",date);
    626             itemElement.setAttribute("root_title",rootTitle);
    627             return itemElement;           
    628         }
    629     }
    630    
     659            itemElement.setAttribute("title", title);
     660            itemElement.setAttribute("date", date);
     661            itemElement.setAttribute("root_title", rootTitle);
     662            return itemElement;
     663        }
     664    }
     665
    631666    private class UserTimer extends Timer implements ActionListener
    632667    {
    633         String id="";
    634 
    635         public UserTimer(int delay, String id){
    636             super(delay,(ActionListener)null);
     668        String id = "";
     669
     670        public UserTimer(int delay, String id)
     671        {
     672            super(delay, (ActionListener) null);
    637673            addActionListener(this);
    638             this.id=id;
    639         }
    640 
    641         public void actionPerformed(ActionEvent e){
    642             userMap.remove(id);           
     674            this.id = id;
     675        }
     676
     677        public void actionPerformed(ActionEvent e)
     678        {
     679            userMap.remove(id);
    643680            timerMap.remove(id);
    644681            stop();
Note: See TracChangeset for help on using the changeset viewer.