Changeset 2829


Ignore:
Timestamp:
04/23/13 14:06:35 (11 years ago)
Author:
keeloo
Message:

Added support for search page type of resources.

Location:
vlo/trunk/vlo_web_app/src/main
Files:
4 added
5 edited
1 moved

Legend:

Unmodified
Added
Removed
  • vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/VloWebApplication.properties

    r2788 r2829  
    2525landingPage=Landing page
    2626landingPages= Landing pages
     27searchPage=Landing page
     28searchPages= Landing pages
  • vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/LandingPageLinkPanel.java

    r2788 r2829  
    1 /*
    2  * To change this template, choose Tools | Templates
    3  * and open the template in the editor.
    4  */
     1
    52package eu.clarin.cmdi.vlo.pages;
    63
    7 import eu.clarin.cmdi.vlo.FacetConstants;
    8 import eu.clarin.cmdi.vlo.config.VloConfig;
    9 import java.io.IOException;
    10 import java.net.HttpURLConnection;
    11 import java.net.MalformedURLException;
    12 import java.net.URL;
    13 import java.net.URLConnection;
    144import org.apache.wicket.behavior.SimpleAttributeModifier;
    155import org.apache.wicket.markup.html.basic.Label;
    166import org.apache.wicket.markup.html.image.Image;
    177import org.apache.wicket.markup.html.link.ExternalLink;
    18 import org.apache.wicket.markup.html.panel.Panel;
    198import org.apache.wicket.resource.ContextRelativeResource;
    20 import org.slf4j.Logger;
    21 import org.slf4j.LoggerFactory;
    229
    2310/**
    24  * keeloo: describe this
    25  *
     11 * Panel showing a landing page link.
     12 *
     13 * In the extension of the link panel class, this class adds a label text and
     14 * an icon that is specific for search page links
     15 *
    2616 * @author keeloo
    2717 */
    28 public class LandingPageLinkPanel extends Panel {
    29    
    30     private final static String URN_NBN_RESOLVER_URL = "http://www.nbn-resolving.org/redirect/";
     18public class LandingPageLinkPanel extends LinkPanel {
    3119
    32     private final static Logger LOG = LoggerFactory.getLogger(ResourceLinkPanel.class);
    33     //
    34     private final static ImageResource LANDINGPAGE_ICON =
    35             new ImageResource(new ContextRelativeResource("Images/readme.png"),
     20    private final static ImageResource LANDINGPAGE_ICON =
     21            new ImageResource(new ContextRelativeResource(
     22            "Images/Crystal_Clear_mimetype_readme.png"),
    3623            "Landing page");
    3724
     25    /**
     26     * Panel constructor.
     27     *
     28     * @param id Wicket mark up identifier
     29     * @param resourceLink URL to pointing to the resource.
     30     */
    3831    public LandingPageLinkPanel(String id, String resourceLink) {
     32        // ...
    3933        super(id);
     34       
     35        // add the icon image
    4036        ImageResource imageResouce = LANDINGPAGE_ICON;
    4137        Image resourceImg = new Image("landingPageImage", imageResouce.getResource());
     38       
     39        // add the image's title
    4240        String title;
    4341        title = imageResouce.getTitle();
    4442        resourceImg.add(new SimpleAttributeModifier("title", title));
    4543        resourceImg.add(new SimpleAttributeModifier("alt", title));
     44       
     45        // ...
    4646        String href = getHref(resourceLink);
     47       
     48        // get the name associated with the link
    4749        String name = getNameFromLink(resourceLink);
     50
     51        // ... and add the link itself
    4852        ExternalLink link = new ExternalLink("landingPageLink", href);
    4953        link.add(resourceImg);
     
    5155        add(link);
    5256    }
    53    
    54     // copied from ResourceLinkPanel
    55 
    56     /**
    57      * Modifies resourceLink if necessary (adds support for different URN
    58      * resolvers)
    59      *
    60      * @param resourceLink
    61      * @return Modified resourceLink, if no modifications are necessary original
    62      * parameter resourceLink is returned
    63      */
    64     private String getHref(String resourceLink) {
    65         String result = resourceLink;
    66         if (resourceLink != null) {
    67             if (resourceLink.startsWith(FacetConstants.HANDLE_PREFIX)) {
    68                 String handle = resourceLink.substring(FacetConstants.HANDLE_PREFIX.length());
    69                 result = VloConfig.getHandleServerUrl() + handle;
    70             } else if(resourceLink.startsWith(FacetConstants.URN_NBN_PREFIX)) {
    71                 result = URN_NBN_RESOLVER_URL+resourceLink;
    72             }
    73         }
    74         return result;
    75     }
    76 
    77     // copied from ResourceLinkPanel
    78    
    79     protected String getNameFromLink(String resourceLink) {
    80         String result = resourceLink;
    81         // We ALWAYS backoff to the resourceLink as default thingy.
    82 
    83         // HandleResolver does not work at the moment on the clarin server see http://trac.clarin.eu/ticket/136, Disabled it for the release.
    84 //      if (resourceLink != null) {
    85 //          if (resourceLink.startsWith(FacetConstants.HANDLE_PREFIX)) {
    86 //              try {
    87 //                  String handle = resourceLink.substring(FacetConstants.HANDLE_PREFIX.length());
    88 //                  HandleResolver handleResolver = new HandleResolver();
    89 //                  handleResolver.setTcpTimeout(5000);//5 secs, default is one minute
    90 //                  HandleValue values[] = handleResolver.resolveHandle(handle, new String[] { "URL" }, null);
    91 //
    92 //                  for (HandleValue handleValue : values) {
    93 //                      String url = handleValue.getDataAsString();
    94 //                      int index = url.lastIndexOf('/');
    95 //                      if (index != -1) {
    96 //                          String name = url.substring(index + 1).trim();
    97 //                          if (name.length() > 1) {
    98 //                              result = name + " (" + resourceLink + ")";
    99 //                          }
    100 //                          break;
    101 //                      }
    102 //                  }
    103 //              } catch (HandleException e) {
    104 //                  LOG.warn("Error trying to get the name of the handle", e);
    105 //              }
    106 //          }
    107 //      }
    108 
    109         /** NOTE: We are trying a different approach from the "official" one.
    110          * Will use the REST interface of hdl.handle.net.
    111          */
    112         if (resourceLink != null) {
    113             if (resourceLink.startsWith(FacetConstants.HANDLE_PREFIX)) {
    114                 String handle = resourceLink.substring(FacetConstants.HANDLE_PREFIX.length());
    115                 resourceLink = VloConfig.getHandleServerUrl() + handle;
    116                 // Now points to something like http://hdl.handle.net/1839/00-0000-0000-0004-3357-F
    117                 HttpURLConnection con = null;
    118                 URL u;
    119                 try{
    120                     u = new URL(resourceLink);
    121                     System.out.println(resourceLink);
    122                     URLConnection c = u.openConnection();
    123                     if(c instanceof HttpURLConnection){
    124                         con = (HttpURLConnection) c;
    125                     }
    126                     if(con != null){
    127                         if(con.getResponseCode() == HttpURLConnection.HTTP_MOVED_PERM ||
    128                                 con.getResponseCode() == HttpURLConnection.HTTP_MOVED_TEMP ||
    129                                 con.getResponseCode() == HttpURLConnection.HTTP_SEE_OTHER){
    130                            result = con.getURL().toString();
    131 /*                            for (Map.Entry<String, List<String>> header : con.getHeaderFields().entrySet()) {
    132                                 if(header != null && header.getKey() != null){
    133                                     System.out.println("XXX:" + header.getKey());
    134                                     System.out.println(header.getValue().get(0));
    135                                     if(header.getKey().equals("Location")){
    136                                         result = header.getValue().get(0);
    137                                     }
    138                                 }
    139                             }*/
    140                         }
    141                     }
    142                 } catch (MalformedURLException e) {
    143                     LOG.warn("Error trying to get the name of the handle", e);
    144                 } catch (IOException e) {
    145                     LOG.warn("Error trying to get the name of the handle", e);
    146                 }
    147             }
    148         }
    149         return result;
    150     }
    151    
    152 
    15357}
  • vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/ResourceLinkPanel.java

    r2768 r2829  
     1
    12package eu.clarin.cmdi.vlo.pages;
    23
    34import eu.clarin.cmdi.vlo.CommonUtils;
    45import eu.clarin.cmdi.vlo.FacetConstants;
    5 import eu.clarin.cmdi.vlo.config.VloConfig;
    6 import java.io.IOException;
    7 import java.net.HttpURLConnection;
    8 import java.net.MalformedURLException;
    9 import java.net.URL;
    10 import java.net.URLConnection;
    116import java.util.HashMap;
    127import java.util.Map;
     
    1510import org.apache.wicket.markup.html.image.Image;
    1611import org.apache.wicket.markup.html.link.ExternalLink;
    17 import org.apache.wicket.markup.html.panel.Panel;
    1812import org.apache.wicket.resource.ContextRelativeResource;
    1913import org.slf4j.Logger;
    2014import org.slf4j.LoggerFactory;
    2115
    22 public class ResourceLinkPanel extends Panel {
    2316
    24     private final static Logger LOG = LoggerFactory.getLogger(ResourceLinkPanel.class);
     17/**
     18 * Panel showing a resource link.
     19 *
     20 * In the extension of the link panel class, this class adds a label text and
     21 * an icon that is specific for search page links.
     22 */
     23public class ResourceLinkPanel extends LinkPanel {
     24
     25    private final static Logger LOG =
     26            LoggerFactory.getLogger(ResourceLinkPanel.class);
    2527
    2628    private static final long serialVersionUID = 1L;
    2729
    28     private final static String URN_NBN_RESOLVER_URL = "http://www.nbn-resolving.org/redirect/";
     30    private final static String URN_NBN_RESOLVER_URL =
     31            "http://www.nbn-resolving.org/redirect/";
    2932
    30     private final static ImageResource ANNOTATION = new ImageResource(new ContextRelativeResource("Images/text-x-log.png"),
    31             "Annotation file");
    32     private final static ImageResource AUDIO = new ImageResource(new ContextRelativeResource("Images/audio-x-generic.png"), "Audio file");
    33     private final static ImageResource IMAGE = new ImageResource(new ContextRelativeResource("Images/image-x-generic.png"), "Image file");
    34     private final static ImageResource TEXT = new ImageResource(new ContextRelativeResource("Images/text-x-generic.png"), "Text file");
    35     private final static ImageResource VIDEO = new ImageResource(new ContextRelativeResource("Images/video-x-generic.png"), "Video file");
     33    private final static ImageResource ANNOTATION = new ImageResource(new
     34            ContextRelativeResource("Images/text-x-log.png"), "Annotation file");
     35    private final static ImageResource AUDIO = new ImageResource(new
     36            ContextRelativeResource("Images/audio-x-generic.png"), "Audio file");
     37    private final static ImageResource IMAGE = new ImageResource(new
     38            ContextRelativeResource("Images/image-x-generic.png"), "Image file");
     39    private final static ImageResource TEXT = new  ImageResource(new
     40            ContextRelativeResource("Images/text-x-generic.png"), "Text file");
     41    private final static ImageResource VIDEO = new ImageResource(new
     42            ContextRelativeResource("Images/video-x-generic.png"), "Video file");
    3643
    37     private final static Map<String, ImageResource> ICON_MAP = new HashMap<String, ImageResource>();
     44    private final static Map<String, ImageResource> ICON_MAP = new
     45            HashMap<String, ImageResource>();
    3846    static {
    3947        ICON_MAP.put(FacetConstants.RESOURCE_TYPE_AUDIO, AUDIO);
     
    4351        ICON_MAP.put(FacetConstants.RESOURCE_TYPE_ANNOTATION, ANNOTATION);
    4452    }
    45 
     53   
     54    /**
     55     * Panel constructor
     56     *
     57     * @param id Wicket mark up identifier
     58     * @param mimeType mime type of the resource indicated
     59     * @param resourceLink URL to pointing to the resource
     60     */
    4661    public ResourceLinkPanel(String id, String mimeType, String resourceLink) {
    4762        super(id);
     
    5873        add(link);
    5974    }
    60 
    61     /**
    62      * Modifies resourceLink if necessary (adds support for different URN resolvers)
    63      * @param resourceLink
    64      * @return Modified resourceLink, if no modifications are necessary original parameter resourceLink is returned
    65      */
    66     private String getHref(String resourceLink) {
    67         String result = resourceLink;
    68         if (resourceLink != null) {
    69             if (resourceLink.startsWith(FacetConstants.HANDLE_PREFIX)) {
    70                 String handle = resourceLink.substring(FacetConstants.HANDLE_PREFIX.length());
    71                 result = VloConfig.getHandleServerUrl() + handle;
    72             } else if(resourceLink.startsWith(FacetConstants.URN_NBN_PREFIX)) {
    73                 result = URN_NBN_RESOLVER_URL+resourceLink;
    74             }
    75         }
    76         return result;
    77     }
    78 
    79     protected String getNameFromLink(String resourceLink) {
    80         String result = resourceLink;
    81         // We ALWAYS backoff to the resourceLink as default thingy.
    82 
    83 
    84 
    85      // HandleResolver does not work at the moment on the clarin server see http://trac.clarin.eu/ticket/136, Disabled it for the release.
    86 //      if (resourceLink != null) {
    87 //          if (resourceLink.startsWith(FacetConstants.HANDLE_PREFIX)) {
    88 //              try {
    89 //                  String handle = resourceLink.substring(FacetConstants.HANDLE_PREFIX.length());
    90 //                  HandleResolver handleResolver = new HandleResolver();
    91 //                  handleResolver.setTcpTimeout(5000);//5 secs, default is one minute
    92 //                  HandleValue values[] = handleResolver.resolveHandle(handle, new String[] { "URL" }, null);
    93 //
    94 //                  for (HandleValue handleValue : values) {
    95 //                      String url = handleValue.getDataAsString();
    96 //                      int index = url.lastIndexOf('/');
    97 //                      if (index != -1) {
    98 //                          String name = url.substring(index + 1).trim();
    99 //                          if (name.length() > 1) {
    100 //                              result = name + " (" + resourceLink + ")";
    101 //                          }
    102 //                          break;
    103 //                      }
    104 //                  }
    105 //              } catch (HandleException e) {
    106 //                  LOG.warn("Error trying to get the name of the handle", e);
    107 //              }
    108 //          }
    109 //      }
    110 
    111         /** NOTE: We are trying a different approach from the "official" one.
    112          * Will use the REST interface of hdl.handle.net.
    113          */
    114         if (resourceLink != null) {
    115             if (resourceLink.startsWith(FacetConstants.HANDLE_PREFIX)) {
    116                 String handle = resourceLink.substring(FacetConstants.HANDLE_PREFIX.length());
    117                 resourceLink = VloConfig.getHandleServerUrl() + handle;
    118                 // Now points to something like http://hdl.handle.net/1839/00-0000-0000-0004-3357-F
    119                 HttpURLConnection con = null;
    120                 URL u;
    121                 try{
    122                     u = new URL(resourceLink);
    123                     System.out.println(resourceLink);
    124                     URLConnection c = u.openConnection();
    125                     if(c instanceof HttpURLConnection){
    126                         con = (HttpURLConnection) c;
    127                     }
    128                     if(con != null){
    129                         if(con.getResponseCode() == HttpURLConnection.HTTP_MOVED_PERM ||
    130                                 con.getResponseCode() == HttpURLConnection.HTTP_MOVED_TEMP ||
    131                                 con.getResponseCode() == HttpURLConnection.HTTP_SEE_OTHER){
    132                            result = con.getURL().toString();
    133 /*                            for (Map.Entry<String, List<String>> header : con.getHeaderFields().entrySet()) {
    134                                 if(header != null && header.getKey() != null){
    135                                     System.out.println("XXX:" + header.getKey());
    136                                     System.out.println(header.getValue().get(0));
    137                                     if(header.getKey().equals("Location")){
    138                                         result = header.getValue().get(0);
    139                                     }
    140                                 }
    141                             }*/
    142                         }
    143                     }
    144                 } catch (MalformedURLException e) {
    145                     LOG.warn("Error trying to get the name of the handle", e);
    146                 } catch (IOException e) {
    147                     LOG.warn("Error trying to get the name of the handle", e);
    148                 }
    149             }
    150         }
    151         return result;
    152     }
    153 
     75   
    15476    private ImageResource getImage(String mimeType) {
    15577        ImageResource image = ICON_MAP.get(CommonUtils.normalizeMimeType(mimeType));
  • vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/ShowResultPage.html

    r2804 r2829  
    3939                </ul>
    4040            </div>
     41            <!-- add a label to be shown in case there is one search  page -->
     42            <div wicket:id="oneSearchPage">[Search page]</div>
     43            <!-- add a label to be shown in case there are more search pages -->
     44            <div wicket:id="moreSearchPages">[Search pages]</div>
     45            <!-- Add the list of search page links. Again, use the same layout
     46            as in the case of the resource list. -->
     47            <div class="searchPageList">
     48                <ul class="resultItem" >
     49                    <li wicket:id="searchPageList"></li>
     50                </ul>
     51            </div>
    4152            <div class="resourceList"><span><wicket:message key="resources">[Resources]</wicket:message>:</span>
    4253                <ul class="resultItem" >
  • vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/ShowResultPage.java

    r2811 r2829  
    8888            }
    8989            addAttributesTable(solrDocument);
     90           
     91            /* If there are any, add the link or links to landing pages
     92             * contained in the solr document.
     93             */
    9094            addLandingPageLinks(solrDocument);
     95           
     96            // also, if there are any, add the link or links to search pages
     97            addSearchPageLinks(solrDocument);
     98
     99            // add the rest of the resource links to the result page
    91100            addResourceLinks(solrDocument);
     101           
    92102            addSearchServiceForm(solrDocument);
    93103            addCompleteCmdiView(solrDocument);
     
    109119        }
    110120
    111         // add feedback link
     121        // add the feedback link to the result page
    112122        addFeedbackLink(parameters);
    113123    }
     
    201211   
    202212    /**
    203      * Add links to landing pages to the results shown.<br><br>
    204      *
    205      * Depending on the number of links to be shown, at most one of the labels
    206      * in the accompanying HTML page that is subject to Wicket is made
    207      * visible.<br><br>
     213     * Add landing page links to the result page.
    208214     *
    209      * @param solrDocument the document to add the landing page links to
     215     * @param solrDocument the document to get the links from
    210216     */
    211     @SuppressWarnings("serial")
    212217    private void addLandingPageLinks(SolrDocument solrDocument) {
    213 
    214         // add the labels defined in the HTML page
     218       
    215219        Label oneLandingPageText;
    216         oneLandingPageText = new Label("oneLandingPage", 
     220        oneLandingPageText = new Label("oneLandingPage",
    217221                new ResourceModel(Resources.LANDING_PAGE).getObject() + ":");
    218222        this.add(oneLandingPageText);
    219223
    220224        Label moreLandingPagesText;
    221         moreLandingPagesText = new Label("moreLandingPages", 
     225        moreLandingPagesText = new Label("moreLandingPages",
    222226                new ResourceModel(Resources.LANDING_PAGES).getObject() + ":");
    223227        this.add(moreLandingPagesText);
    224228
    225         // also, add the list of links
    226229        RepeatingView repeatingView = new RepeatingView("landingPageList");
    227230        add(repeatingView);
    228231
     232        /*
     233         * Depending on the number of links to be shown, at most one of the
     234         * labels in the accompanying HTML page that is subject to Wicket is
     235         * made visible.
     236         */
    229237        if (!solrDocument.containsKey(FacetConstants.FIELD_LANDINGPAGE)) {
    230238           
     
    255263                landingPage = it.next();
    256264
    257                 // keeloo: describe this
     265                // add a link to the list
    258266                repeatingView.add(
    259267                        new AjaxLazyLoadPanel(repeatingView.newChildId()) {
     
    262270                                String landingPageLink;
    263271                                landingPageLink = landingPage.toString();
    264                                
    265                                 // create a landing page link panel
     272
     273                                // create a panel for the link
    266274                                return new LandingPageLinkPanel(markupId,
    267275                                        landingPage.toString());
     
    271279        }
    272280    }
    273 
    274     @SuppressWarnings("serial")
     281   
     282    /**
     283     * Add search page links to the result page.
     284     *
     285     * @param solrDocument the document to get the links from
     286     */
     287    private void addSearchPageLinks(SolrDocument solrDocument) {
     288       
     289        Label oneSearchPageText;
     290        oneSearchPageText = new Label("oneSearchPage",
     291                new ResourceModel(Resources.SEARCH_PAGE).getObject() + ":");
     292        this.add(oneSearchPageText);
     293
     294        Label moreSearchPagesText;
     295        moreSearchPagesText = new Label("moreSearchPages",
     296                new ResourceModel(Resources.SEARCH_PAGES).getObject() + ":");
     297        this.add(moreSearchPagesText);
     298
     299        RepeatingView repeatingView = new RepeatingView("searchPageList");
     300        add(repeatingView);
     301
     302        /*
     303         * Depending on the number of links to be shown, at most one of the
     304         * labels in the accompanying HTML page that is subject to Wicket is
     305         * made visible.
     306         */
     307        if (!solrDocument.containsKey(FacetConstants.FIELD_SEARCHPAGE)) {
     308           
     309            /* Since there are no links to be shown, make both labels defined in
     310             * the page invisible
     311             */
     312            oneSearchPageText.setVisible(false);
     313            moreSearchPagesText.setVisible(false);
     314        } else {
     315            //  make one of the two labels invisible
     316
     317            Collection<Object> searchPages =
     318                    solrDocument.getFieldValues(FacetConstants.FIELD_SEARCHPAGE);
     319            if (searchPages.size() > 1) {
     320               
     321                // the list will contain more than one landing page link
     322                oneSearchPageText.setVisible(false);
     323                moreSearchPagesText.setVisible(true);
     324            } else {
     325                // the list will contain exactly one landing page link.
     326                oneSearchPageText.setVisible(true);
     327                moreSearchPagesText.setVisible(false);
     328            }
     329           
     330            // generate the list of links
     331            for (Iterator<Object> it = searchPages.iterator(); it.hasNext();) {
     332                final Object searchPage;
     333                searchPage = it.next();
     334
     335                // add a link to the list
     336                repeatingView.add(
     337                        new AjaxLazyLoadPanel(repeatingView.newChildId()) {
     338                            @Override
     339                            public Component getLazyLoadComponent(String markupId) {
     340                                String searchPageLink;
     341                                searchPageLink = searchPage.toString();
     342
     343                                // create a panel for the link
     344                                return new SearchPageLinkPanel(markupId,
     345                                        searchPage.toString());
     346                            }
     347                        });
     348            }
     349        }
     350    }
     351
     352    /**
     353     * Add links to resources other than search or landing pages to the result
     354     * page.
     355     *
     356     * @param solrDocument the document to get the links from
     357     */
    275358    private void addResourceLinks(SolrDocument solrDocument) {
    276359        RepeatingView repeatingView = new RepeatingView("resourceList");
Note: See TracChangeset for help on using the changeset viewer.