Ignore:
Timestamp:
08/30/12 12:16:14 (12 years ago)
Author:
zastrow
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • SRUAggregator/trunk/src/java/clarind/fcs/Aggregator.java

    r2171 r2175  
    3333import org.zkoss.zul.Column;
    3434import org.zkoss.zul.Vbox;
     35import org.zkoss.zul.Iframe;
     36import org.zkoss.zul.Window;
    3537
    3638public class Aggregator extends SelectorComposer<Component> {
    37 
     39   
    3840    @Wire
    3941    private Grid anzeigeGrid;
     
    5658    @Wire
    5759    private Button deselectAll;
    58 
     60    @Wire
     61    private Window mainWindow;
     62   
     63   
    5964    @Override
    6065    public void doAfterCompose(Component comp) throws Exception {
     
    6368
    6469        languageSelect.setSelectedItem(german);
    65 
     70       
    6671        Harvester harv = new Harvester();
    6772        ArrayList<Endpoint> ep = harv.getEndpoints();
    68 
     73       
    6974        int i, i2;
    70 
     75       
    7176        for (i = 0; i < ep.size(); i++) {
    72 
     77           
    7378            System.out.println("Calling corpora ...: " + ep.get(i).getUrl());
    7479            ArrayList<Corpus> corpora = harv.getCorporaOfAnEndpoint(ep.get(i).getUrl());
    75 
     80           
    7681            if (corpora.size() == 0) {
    7782                Checkbox cb = new Checkbox();
     
    8085                //"?operation=searchRetrieve&version=1.2"
    8186                cb.setLabel(ep.get(i).getUrl());
    82 
     87               
    8388                allCorpora.getChildren().add(cb);
    8489                allCorpora.getChildren().add(new Separator());
    85 
     90               
    8691                System.out.println("CHECKBOX: " + cb.getId());
    8792            } else {
    8893                Label l = new Label(ep.get(i).getUrl() + ":");
    89 
     94               
    9095                l.setStyle("font-weight:bold");
    91 
     96               
    9297                allCorpora.getChildren().add(l);
    9398                allCorpora.getChildren().add(new Separator());
    9499                for (i2 = 0; i2 < corpora.size(); i2++) {
    95100                    Checkbox cb = new Checkbox();
    96 
     101                   
    97102                    cb.setId(ep.get(i).getUrl() + "\t" + corpora.get(i2).getValue());
    98103                    cb.setLabel(corpora.get(i2).getDisplayTerm());
    99 
     104                   
    100105                    allCorpora.getChildren().add(cb);
    101106                    allCorpora.getChildren().add(new Separator());
    102 
     107                   
    103108                    System.out.println("CHECKBOX: " + cb.getId());
    104109                } // for i2 ...
     
    106111
    107112            Separator sep = new Separator();
    108 
     113           
    109114            sep.setBar(true);
    110115            allCorpora.getChildren().add(sep);
    111 
     116           
    112117        } // for i ...
    113118
    114119    }
    115 
     120   
    116121    @Listen("onClick = #selectAll")
    117122    public void onSelectAll(Event ev) {
    118123        int i;
    119 
     124       
    120125        for (i = 0; i < allCorpora.getChildren().size(); i++) {
    121126            if (allCorpora.getChildren().get(i) instanceof Checkbox) {
     
    129134    public void onDeselectAll(Event ev) {
    130135        int i;
    131 
     136       
    132137        for (i = 0; i < allCorpora.getChildren().size(); i++) {
    133138            if (allCorpora.getChildren().get(i) instanceof Checkbox) {
     
    145150        }
    146151    }
    147 
     152   
    148153    @Listen("onClick=#clearResults")
    149154    public void onClearResults(Event ev) {
    150155        resultsVbox.getChildren().clear();
    151156    }
    152 
    153     @Listen("onClick=#exportResults")
    154     public void onExportResults(Event ev) {
    155 
     157   
     158    @Listen("onClick=#showHelp")
     159    public void onShowHelp(Event ev) {
     160        resultsVbox.getChildren().clear();
     161        Iframe help = new Iframe();
     162        help.setWidth("100%");
     163        help.setHeight("100%");
     164        help.setSrc("help.html");
     165        resultsVbox.appendChild(help);       
     166    }
     167   
     168    @Listen("onClick=#exportResultsCSV")
     169    public void onExportResultsCSV(Event ev) {
     170       
    156171        int i, i2, i3;
    157172        String temp = "";
    158 
     173        boolean somethingToExport = false;
     174       
    159175        for (i = 0; i < resultsVbox.getChildren().size(); i++) {
    160176            if (resultsVbox.getChildren().get(i) instanceof Grid) {
     177                somethingToExport = true;
    161178                Grid aGrid = (Grid) resultsVbox.getChildren().get(i);
    162179                Rows rows = aGrid.getRows();
    163 
     180               
    164181                for (i2 = 0; i2 < rows.getChildren().size(); i2++) {
    165182                    Row r = (Row) rows.getChildren().get(i2);
    166 
     183                   
    167184                    for (i3 = 0; i3 < r.getChildren().size(); i3++) {
    168185                        Label l = (Label) r.getChildren().get(i3);
     
    177194
    178195        } // for i ...
    179         Filedownload.save(temp, "text/plain", "table.csv");
    180     }
    181 
     196       
     197        if (somethingToExport) {
     198           
     199            Filedownload.save(temp, "text/plain", "ClarinDFederatedContentSearch.csv");
     200        } else {
     201            Messagebox.show("Nothing to export!");
     202        }
     203    }
     204   
     205   
     206     @Listen("onClick=#exportResultsTCF")
     207    public void onExportResultsTCF(Event ev) {
     208       
     209        int i, i2, i3;
     210        String temp = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><D-Spin xmlns=\"http://www.dspin.de/data\" version=\"0.4\">\n<MetaData xmlns=\"http://www.dspin.de/data/metadata\">\n";
     211        temp = temp  + "<source>CLARIN-D Federated Content Search</source>\n</MetaData>\n  <TextCorpus xmlns=\"http://www.dspin.de/data/textcorpus\">\n<text>";
     212       
     213       
     214        boolean somethingToExport = false;
     215       
     216        for (i = 0; i < resultsVbox.getChildren().size(); i++) {
     217            if (resultsVbox.getChildren().get(i) instanceof Grid) {
     218                somethingToExport = true;
     219                Grid aGrid = (Grid) resultsVbox.getChildren().get(i);
     220                Rows rows = aGrid.getRows();
     221               
     222                for (i2 = 0; i2 < rows.getChildren().size(); i2++) {
     223                    Row r = (Row) rows.getChildren().get(i2);
     224                   
     225                    for (i3 = 0; i3 < r.getChildren().size(); i3++) {
     226                        Label l = (Label) r.getChildren().get(i3);
     227                        temp = temp + l.getValue() + " ";
     228                    } //for i3
     229                    temp = temp + "\n";
     230                } // for i2
     231            } // if grid
     232
     233        } // for i ...
     234       
     235        if (somethingToExport) {
     236            temp = temp + "</text>\n</TextCorpus>\n</D-Spin>";
     237            Filedownload.save(temp, "text/tcf+xml", "ClarinDFederatedContentSearch.xml");
     238        } else {
     239            Messagebox.show("Nothing to export!");
     240        }
     241    }
     242     
     243   
     244   
    182245    @Listen("onClick = #searchButton")
    183246    public void onExecuteSearch(Event ev) {
    184 
     247       
    185248        try {
    186 
     249           
    187250            if (languageSelect.getText().trim().equals("")) {
    188251                Messagebox.show("Please select a language.");
    189252                return;
    190253            }
    191 
     254           
    192255            int i, i2;
    193 
    194 
     256           
     257           
    195258            resultsVbox.getChildren().clear();
    196 
    197 
    198 
    199 
     259           
     260           
     261            boolean isACorpusSelected = false;
     262           
    200263            for (i = 0; i < allCorpora.getChildren().size(); i++) {
    201264                if (allCorpora.getChildren().get(i) instanceof Checkbox) {
     
    203266                    if (cb.isChecked()) {
    204267                        // now execute the search:
    205 
     268                       
     269                        isACorpusSelected = true;
     270                       
    206271                        System.out.println("---- THE SEARCH ----");
    207 
     272                       
    208273                        String endpointURL = null;
    209274                        String corpus = null;
    210 
     275                       
    211276                        if (cb.getId().contains("\t")) {
    212277                            endpointURL = cb.getId().split("\t")[0];
     
    215280                            endpointURL = cb.getId();
    216281                        }
    217 
     282                       
    218283                        System.out.println("enddpointURL: " + endpointURL);
    219284                        System.out.println("corpus: " + corpus);
    220285                        SRUSearch srusearch = new SRUSearch();
    221286                        System.out.println("Calling the client ");
    222 
     287                       
    223288                        resultsVbox.appendChild(new Label("Query: " + searchString.getText()));
    224289                        resultsVbox.appendChild(new Label("Endpoint: " + endpointURL));
    225290                        resultsVbox.appendChild(new Label("Corpus: " + corpus));
    226 
    227 
     291                       
     292                       
    228293                        ArrayList<Row> zeilen = srusearch.execute(searchString.getText(), endpointURL, corpus, 10);
    229 
     294                       
    230295                        if (zeilen.size() > 0) {
    231 
     296                           
    232297                            Grid g = new Grid();
    233 
     298                           
    234299                            g.setMold("paging");
    235300                            g.setPageSize(10);
    236 
     301                           
    237302                            Columns columns = new Columns();
    238 
     303                           
    239304                            Column c = new Column();
    240305                            c.setLabel("Left");
    241 
     306                           
    242307                            columns.appendChild(c);
    243 
     308                           
    244309                            c = new Column();
    245310                            c.setLabel("Hit");
    246311                            c.setHflex("min");
    247312                            columns.appendChild(c);
    248 
     313                           
    249314                            c = new Column();
    250315                            c.setLabel("Right");
    251316                            columns.appendChild(c);
    252 
     317                           
    253318                            g.appendChild(columns);
    254 
     319                           
    255320                            Rows rows = new Rows();
    256 
     321                           
    257322                            for (i2 = 0; i2 < zeilen.size(); i2++) {
    258323                                System.out.println("Adding row " + i2);
     
    262327
    263328                            g.appendChild(rows);
    264 
     329                           
    265330                            resultsVbox.appendChild(g);
    266331                        } else {
    267332                            resultsVbox.appendChild(new Label("Sorry there were no results!"));
    268 
     333                           
    269334                        } // if zeilen > 0
    270335
     
    275340                }
    276341            } // for i ...
    277             System.out.println("Done");
    278 
     342           
     343            if (!isACorpusSelected) {
     344               
     345                Messagebox.show("Please select at least one corpus!", "CLARIN-D FCS Aggregator", 0, Messagebox.EXCLAMATION);
     346            }
     347           
     348           
     349            System.out.println("Search is done.");
     350           
    279351        } catch (Exception ex) {
    280352            System.out.println(ex.getMessage());
    281353        }
    282 
     354       
    283355    }
    284356}
Note: See TracChangeset for help on using the changeset viewer.