Changeset 2171


Ignore:
Timestamp:
08/29/12 12:46:08 (12 years ago)
Author:
zastrow
Message:
 
Location:
SRUAggregator/trunk
Files:
3 edited

Legend:

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

    r2161 r2171  
    11package clarind.fcs;
    22
    3 import eu.clarin.sru.client.SRUClient;
    4 import eu.clarin.sru.client.SRUClientException;
    5 import eu.clarin.sru.client.SRUDefaultHandlerAdapter;
    6 import eu.clarin.sru.client.SRURecordData;
    7 import eu.clarin.sru.client.SRUSearchRetrieveRequest;
    8 import eu.clarin.sru.client.SRUVersion;
    9 import eu.clarin.sru.fcs.ClarinFederatedContentSearchRecordData;
    10 import eu.clarin.sru.fcs.ClarinFederatedContentSearchRecordParser;
     3//import eu.clarin.sru.client.SRUClient;
     4//import eu.clarin.sru.client.SRUClientException;
     5//import eu.clarin.sru.client.SRUDefaultHandlerAdapter;
     6//import eu.clarin.sru.client.SRURecordData;
     7//import eu.clarin.sru.client.SRUSearchRetrieveRequest;
     8//import eu.clarin.sru.client.SRUVersion;
     9//import eu.clarin.sru.fcs.ClarinFederatedContentSearchRecordData;
     10//import eu.clarin.sru.fcs.ClarinFederatedContentSearchRecordParser;
    1111import java.util.ArrayList;
     12import org.zkoss.zhtml.Filedownload;
    1213import org.zkoss.zk.ui.Component;
    1314import org.zkoss.zk.ui.event.Event;
     
    2526import org.zkoss.zul.Separator;
    2627import org.zkoss.zul.Label;
    27 import org.zkoss.zul.Html;
     28//import org.zkoss.zul.Html;
    2829import org.zkoss.zul.Comboitem;
    2930import org.zkoss.zul.Grid;
     31//import org.zkoss.zul.Panelchildren;
     32import org.zkoss.zul.Columns;
     33import org.zkoss.zul.Column;
     34import org.zkoss.zul.Vbox;
    3035
    3136public class Aggregator extends SelectorComposer<Component> {
     
    4651    private Comboitem german;
    4752    @Wire
    48     private Html anzeigeResults;
     53    private Vbox resultsVbox;
     54    @Wire
     55    private Button selectAll;
     56    @Wire
     57    private Button deselectAll;
    4958
    5059    @Override
     
    7988                Label l = new Label(ep.get(i).getUrl() + ":");
    8089
     90                l.setStyle("font-weight:bold");
     91
    8192                allCorpora.getChildren().add(l);
    8293                allCorpora.getChildren().add(new Separator());
     
    8495                    Checkbox cb = new Checkbox();
    8596
    86                     //http://clarinws.informatik.uni-leipzig.de:8080/CQL?operation=searchRetrieve&version=1.2&query=Boppard&x-context=11858/00-229C-0000-0003-174F-D&maximumRecords=2
    87 
    8897                    cb.setId(ep.get(i).getUrl() + "\t" + corpora.get(i2).getValue());
    8998                    cb.setLabel(corpora.get(i2).getDisplayTerm());
     
    95104                } // for i2 ...
    96105            } // if corpora.size else
     106
     107            Separator sep = new Separator();
     108
     109            sep.setBar(true);
     110            allCorpora.getChildren().add(sep);
     111
    97112        } // for i ...
    98     }
     113
     114    }
     115
     116    @Listen("onClick = #selectAll")
     117    public void onSelectAll(Event ev) {
     118        int i;
     119
     120        for (i = 0; i < allCorpora.getChildren().size(); i++) {
     121            if (allCorpora.getChildren().get(i) instanceof Checkbox) {
     122                Checkbox cb = (Checkbox) allCorpora.getChildren().get(i);
     123                cb.setChecked(true);
     124            }
     125        }
     126    } //onSelectAll
     127
     128    @Listen("onClick = #deselectAll")
     129    public void onDeselectAll(Event ev) {
     130        int i;
     131
     132        for (i = 0; i < allCorpora.getChildren().size(); i++) {
     133            if (allCorpora.getChildren().get(i) instanceof Checkbox) {
     134                Checkbox cb = (Checkbox) allCorpora.getChildren().get(i);
     135                cb.setChecked(false);
     136            }
     137        }
     138    } //onDeselectAll
    99139
    100140    @Listen("onSelect = #languageSelect")
     
    106146    }
    107147
     148    @Listen("onClick=#clearResults")
     149    public void onClearResults(Event ev) {
     150        resultsVbox.getChildren().clear();
     151    }
     152
     153    @Listen("onClick=#exportResults")
     154    public void onExportResults(Event ev) {
     155
     156        int i, i2, i3;
     157        String temp = "";
     158
     159        for (i = 0; i < resultsVbox.getChildren().size(); i++) {
     160            if (resultsVbox.getChildren().get(i) instanceof Grid) {
     161                Grid aGrid = (Grid) resultsVbox.getChildren().get(i);
     162                Rows rows = aGrid.getRows();
     163
     164                for (i2 = 0; i2 < rows.getChildren().size(); i2++) {
     165                    Row r = (Row) rows.getChildren().get(i2);
     166
     167                    for (i3 = 0; i3 < r.getChildren().size(); i3++) {
     168                        Label l = (Label) r.getChildren().get(i3);
     169                        temp = temp + l.getValue();
     170                        if (i3 < r.getChildren().size() - 1) {
     171                            temp = temp + "\t";
     172                        } //if i3
     173                    } //for i3
     174                    temp = temp + "\n";
     175                } // for i2
     176            } // if grid
     177
     178        } // for i ...
     179        Filedownload.save(temp, "text/plain", "table.csv");
     180    }
     181
    108182    @Listen("onClick = #searchButton")
    109183    public void onExecuteSearch(Event ev) {
    110 //        try {
    111 //            ExecuteSRUSearch.execute();
    112 //        } catch (Exception ex){
    113 //            System.out.println(ex.getMessage());
    114 //        }
    115 
    116 
    117184
    118185        try {
     
    123190            }
    124191
    125             anzeigeResults.setContent("");
    126            
    127192            int i, i2;
     193
     194
     195            resultsVbox.getChildren().clear();
     196
     197
     198
    128199
    129200            for (i = 0; i < allCorpora.getChildren().size(); i++) {
     
    132203                    if (cb.isChecked()) {
    133204                        // now execute the search:
    134 //                        String query = cb.getId() + "&maximumRecords=10&query=" + searchString.getText();
    135 //                        display = display + query + "\n";
     205
    136206                        System.out.println("---- THE SEARCH ----");
    137207
     
    149219                        System.out.println("corpus: " + corpus);
    150220                        SRUSearch srusearch = new SRUSearch();
    151                         anzeigeResults.setContent(anzeigeResults.getContent() + srusearch.execute(searchString.getText(), endpointURL, corpus, 10, anzeigeResults, anzeigeGrid).toString());
    152 
    153 
    154 
     221                        System.out.println("Calling the client ");
     222
     223                        resultsVbox.appendChild(new Label("Query: " + searchString.getText()));
     224                        resultsVbox.appendChild(new Label("Endpoint: " + endpointURL));
     225                        resultsVbox.appendChild(new Label("Corpus: " + corpus));
     226
     227
     228                        ArrayList<Row> zeilen = srusearch.execute(searchString.getText(), endpointURL, corpus, 10);
     229
     230                        if (zeilen.size() > 0) {
     231
     232                            Grid g = new Grid();
     233
     234                            g.setMold("paging");
     235                            g.setPageSize(10);
     236
     237                            Columns columns = new Columns();
     238
     239                            Column c = new Column();
     240                            c.setLabel("Left");
     241
     242                            columns.appendChild(c);
     243
     244                            c = new Column();
     245                            c.setLabel("Hit");
     246                            c.setHflex("min");
     247                            columns.appendChild(c);
     248
     249                            c = new Column();
     250                            c.setLabel("Right");
     251                            columns.appendChild(c);
     252
     253                            g.appendChild(columns);
     254
     255                            Rows rows = new Rows();
     256
     257                            for (i2 = 0; i2 < zeilen.size(); i2++) {
     258                                System.out.println("Adding row " + i2);
     259                                System.out.println("ROW: " + zeilen.get(i2));
     260                                rows.appendChild(zeilen.get(i2));
     261                            } // for i2 ...
     262
     263                            g.appendChild(rows);
     264
     265                            resultsVbox.appendChild(g);
     266                        } else {
     267                            resultsVbox.appendChild(new Label("Sorry there were no results!"));
     268
     269                        } // if zeilen > 0
     270
     271                        Separator sep = new Separator();
     272                        sep.setSpacing("20px");
     273                        resultsVbox.appendChild(sep);
    155274                    }
    156275                }
    157276            } // for i ...
    158277            System.out.println("Done");
    159             //Messagebox.show(display);
    160278
    161279        } catch (Exception ex) {
  • SRUAggregator/trunk/src/java/clarind/fcs/SRUSearch.java

    r2161 r2171  
    55import eu.clarin.sru.fcs.ClarinFederatedContentSearchRecordData;
    66import eu.clarin.sru.fcs.ClarinFederatedContentSearchRecordParser;
    7 import org.xml.sax.helpers.DefaultHandler;
     7//import org.xml.sax.helpers.DefaultHandler;
    88
    9 import org.zkoss.zul.Html;
    10 import org.zkoss.zul.Grid;
    11 import org.zkoss.zul.Rows;
    129import org.zkoss.zul.Row;
    1310import org.zkoss.zul.Label;
    1411
     12import java.util.*;
    1513
    1614public class SRUSearch {
    17     private StringBuilder sb;
    18    
    19     public  StringBuilder execute(String query, String endpointURL, String corpus, int maximumRecords, Html results, final Grid grid) throws Exception {
    20         sb = new StringBuilder();
    21         sb.append("URL: "+ endpointURL + "<br>");
    22         sb.append("CORPUS: " + corpus + "<br><hr>");
    23        
    24        
     15
     16    private ArrayList<Row> zeilen;
     17
     18    public ArrayList<Row> execute(String query, String endpointURL, String corpus, int maximumRecords) throws Exception {
     19        zeilen  = new ArrayList<Row>();
     20
    2521        SRUClient client = new SRUClient();
    2622        client.registerRecordParser(new ClarinFederatedContentSearchRecordParser());
     
    3632
    3733        }
    38 
     34        try {
    3935        client.searchRetrieve(request, new SRUDefaultHandlerAdapter() {
    4036            @Override
     
    4541                    String hit = record.getKeyword();
    4642                    String right = record.getRight();
    47                    
    48                     System.out.print("LEFT: " + left);
    49                     System.out.println("HIT: " + hit);
    50                     System.out.println("RIGHT: " + right);
    51                    
    52                     sb.append(left);
    53                     sb.append("<font color='red'>");
    54                     sb.append(" " + hit + " ");
    55                     sb.append("</font>");
    56                     sb.append(right);
    57                     sb.append("<br><br>");
    58                    
    59 //                    Rows rows = grid.getRows();
    60 //                    Row r = new Row();
    61 //                    r.appendChild(new Label(left));
    62 //                    r.appendChild(new Label(hit));
    63 //                    r.appendChild(new Label(right));
    64 //                   
    65 //                    rows.appendChild(r);
    66                    
    67                    
     43
     44//                    System.out.print("LEFT: " + left);
     45//                    System.out.println("HIT: " + hit);
     46//                    System.out.println("RIGHT: " + right);
     47
     48                    Row r = new Row();
     49                    r.appendChild(new Label(left));
     50                    r.appendChild(new Label(hit));
     51                    r.appendChild(new Label(right));
     52
     53                    zeilen.add(r);
    6854                }
    6955            }
    7056        });
    71         sb.append("<hr>");
    72         return sb;
     57        } catch (Exception ex){
     58            System.out.println(ex.getMessage());
     59        }
     60
     61       
     62//        System.out.println("NUMBER of LINES: " + zeilen.size());
     63       
     64        return zeilen;
    7365    }
    7466
    7567    public static void main(String[] args) throws Exception {
    76 
    77    
    78 
    79 
    8068    } // main
    8169}
  • SRUAggregator/trunk/web/index.zul

    r2161 r2171  
    44        <borderlayout sclass="complex-layout"  >
    55            <!-- Kopf -->
    6             <north height="100px">
    7                
     6            <north height="65px">
     7                <image src="clarindLogo.png"/>
    88            </north>
    99           
     
    1818                    <panelchildren style="margin-top:10px;margin-left:10px;margin-right:10px;border:0;">                   
    1919                        <textbox id="searchString" value="Elefant" />
    20                         <button id="searchButton"  label="Search" />     
     20                        <button id="searchButton"  label="Search" image="buttonSearch.png"/>     
    2121                        <!-- forward ="onExecuteSearch"-->
    2222                        <separator />
    23                         <label>Language:</label>
     23                       
     24                       
     25                        <groupbox mold="3d" id="allCorpora">
     26                            <caption>All Corpora</caption>   
     27                             <label>Select by Language:</label>
    2428                        <combobox id="languageSelect" width="150px" value="German">                                                                                                                   
    2529                            <!--<template name="model"> -->
     
    3135                        </combobox>
    3236                       
     37                         <separator />
     38                       
     39                        <button id="selectAll" label="Select All" image="buttonSelectAll.png"/>                                           
     40                       
     41                        <button id="deselectAll" label="Deselect All" image="buttonDeselectAll.png"/>
     42                       
    3343                        <separator />
    34                        
    35                         <groupbox mold="3d" id="allCorpora">
    36                             <caption>All Corpora</caption>                           
     44                                                   
     45                                                                           
     46                                                                                                                            
    3747                        </groupbox>
    3848                    </panelchildren>
     
    4353            <center  flex="true"  margins="0,5,0,0" autoscroll="true" >
    4454                <panel>
    45                     <panelchildren style="overflow: auto">
     55                    <panelchildren  id="resultsPanel" style="overflow: auto">
     56                        <toolbar id="resultsToolbar"  height="20px">
     57                            <toolbarbutton id="clearResults" label="Clear Results" image="buttonDelete.png"/>
     58                            <toolbarbutton id="exportResults" label="Export Results" image="buttonExport.png"/>
     59                               
     60                        </toolbar>
     61                        <vbox id="resultsVbox">
    4662                        <grid id="anzeigeGrid">
    4763                            <columns>
     
    5066                                <column></column>                                       
    5167                            </columns>
     68                            <rows></rows>
    5269                        </grid>
    5370                        <html id="anzeigeResults" />
     71                        </vbox>
    5472                    </panelchildren>
    5573                   
Note: See TracChangeset for help on using the changeset viewer.