Changeset 2829
- Timestamp:
- 04/23/13 14:06:35 (11 years ago)
- 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 25 25 landingPage=Landing page 26 26 landingPages= Landing pages 27 searchPage=Landing page 28 searchPages= 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 5 2 package eu.clarin.cmdi.vlo.pages; 6 3 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;14 4 import org.apache.wicket.behavior.SimpleAttributeModifier; 15 5 import org.apache.wicket.markup.html.basic.Label; 16 6 import org.apache.wicket.markup.html.image.Image; 17 7 import org.apache.wicket.markup.html.link.ExternalLink; 18 import org.apache.wicket.markup.html.panel.Panel;19 8 import org.apache.wicket.resource.ContextRelativeResource; 20 import org.slf4j.Logger;21 import org.slf4j.LoggerFactory;22 9 23 10 /** 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 * 26 16 * @author keeloo 27 17 */ 28 public class LandingPageLinkPanel extends Panel { 29 30 private final static String URN_NBN_RESOLVER_URL = "http://www.nbn-resolving.org/redirect/"; 18 public class LandingPageLinkPanel extends LinkPanel { 31 19 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"), 36 23 "Landing page"); 37 24 25 /** 26 * Panel constructor. 27 * 28 * @param id Wicket mark up identifier 29 * @param resourceLink URL to pointing to the resource. 30 */ 38 31 public LandingPageLinkPanel(String id, String resourceLink) { 32 // ... 39 33 super(id); 34 35 // add the icon image 40 36 ImageResource imageResouce = LANDINGPAGE_ICON; 41 37 Image resourceImg = new Image("landingPageImage", imageResouce.getResource()); 38 39 // add the image's title 42 40 String title; 43 41 title = imageResouce.getTitle(); 44 42 resourceImg.add(new SimpleAttributeModifier("title", title)); 45 43 resourceImg.add(new SimpleAttributeModifier("alt", title)); 44 45 // ... 46 46 String href = getHref(resourceLink); 47 48 // get the name associated with the link 47 49 String name = getNameFromLink(resourceLink); 50 51 // ... and add the link itself 48 52 ExternalLink link = new ExternalLink("landingPageLink", href); 49 53 link.add(resourceImg); … … 51 55 add(link); 52 56 } 53 54 // copied from ResourceLinkPanel55 56 /**57 * Modifies resourceLink if necessary (adds support for different URN58 * resolvers)59 *60 * @param resourceLink61 * @return Modified resourceLink, if no modifications are necessary original62 * parameter resourceLink is returned63 */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 ResourceLinkPanel78 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 minute90 // 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-F117 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 153 57 } -
vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/ResourceLinkPanel.java
r2768 r2829 1 1 2 package eu.clarin.cmdi.vlo.pages; 2 3 3 4 import eu.clarin.cmdi.vlo.CommonUtils; 4 5 import 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;11 6 import java.util.HashMap; 12 7 import java.util.Map; … … 15 10 import org.apache.wicket.markup.html.image.Image; 16 11 import org.apache.wicket.markup.html.link.ExternalLink; 17 import org.apache.wicket.markup.html.panel.Panel;18 12 import org.apache.wicket.resource.ContextRelativeResource; 19 13 import org.slf4j.Logger; 20 14 import org.slf4j.LoggerFactory; 21 15 22 public class ResourceLinkPanel extends Panel {23 16 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 */ 23 public class ResourceLinkPanel extends LinkPanel { 24 25 private final static Logger LOG = 26 LoggerFactory.getLogger(ResourceLinkPanel.class); 25 27 26 28 private static final long serialVersionUID = 1L; 27 29 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/"; 29 32 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"); 36 43 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>(); 38 46 static { 39 47 ICON_MAP.put(FacetConstants.RESOURCE_TYPE_AUDIO, AUDIO); … … 43 51 ICON_MAP.put(FacetConstants.RESOURCE_TYPE_ANNOTATION, ANNOTATION); 44 52 } 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 */ 46 61 public ResourceLinkPanel(String id, String mimeType, String resourceLink) { 47 62 super(id); … … 58 73 add(link); 59 74 } 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 154 76 private ImageResource getImage(String mimeType) { 155 77 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 39 39 </ul> 40 40 </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> 41 52 <div class="resourceList"><span><wicket:message key="resources">[Resources]</wicket:message>:</span> 42 53 <ul class="resultItem" > -
vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/ShowResultPage.java
r2811 r2829 88 88 } 89 89 addAttributesTable(solrDocument); 90 91 /* If there are any, add the link or links to landing pages 92 * contained in the solr document. 93 */ 90 94 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 91 100 addResourceLinks(solrDocument); 101 92 102 addSearchServiceForm(solrDocument); 93 103 addCompleteCmdiView(solrDocument); … … 109 119 } 110 120 111 // add feedback link121 // add the feedback link to the result page 112 122 addFeedbackLink(parameters); 113 123 } … … 201 211 202 212 /** 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. 208 214 * 209 * @param solrDocument the document to add the landing page links to215 * @param solrDocument the document to get the links from 210 216 */ 211 @SuppressWarnings("serial")212 217 private void addLandingPageLinks(SolrDocument solrDocument) { 213 214 // add the labels defined in the HTML page 218 215 219 Label oneLandingPageText; 216 oneLandingPageText = new Label("oneLandingPage", 220 oneLandingPageText = new Label("oneLandingPage", 217 221 new ResourceModel(Resources.LANDING_PAGE).getObject() + ":"); 218 222 this.add(oneLandingPageText); 219 223 220 224 Label moreLandingPagesText; 221 moreLandingPagesText = new Label("moreLandingPages", 225 moreLandingPagesText = new Label("moreLandingPages", 222 226 new ResourceModel(Resources.LANDING_PAGES).getObject() + ":"); 223 227 this.add(moreLandingPagesText); 224 228 225 // also, add the list of links226 229 RepeatingView repeatingView = new RepeatingView("landingPageList"); 227 230 add(repeatingView); 228 231 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 */ 229 237 if (!solrDocument.containsKey(FacetConstants.FIELD_LANDINGPAGE)) { 230 238 … … 255 263 landingPage = it.next(); 256 264 257 // keeloo: describe this265 // add a link to the list 258 266 repeatingView.add( 259 267 new AjaxLazyLoadPanel(repeatingView.newChildId()) { … … 262 270 String landingPageLink; 263 271 landingPageLink = landingPage.toString(); 264 265 // create a landing page link panel272 273 // create a panel for the link 266 274 return new LandingPageLinkPanel(markupId, 267 275 landingPage.toString()); … … 271 279 } 272 280 } 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 */ 275 358 private void addResourceLinks(SolrDocument solrDocument) { 276 359 RepeatingView repeatingView = new RepeatingView("resourceList");
Note: See TracChangeset
for help on using the changeset viewer.