Changeset 4223
- Timestamp:
- 01/07/14 12:57:26 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vlo/branches/to-wicket-1.6/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/ShowResultPage.java
r4222 r4223 51 51 import org.apache.wicket.model.IModel; 52 52 import org.apache.wicket.model.ResourceModel; 53 import org.apache.wicket. protocol.http.RequestUtils;53 import org.apache.wicket.request.Url; 54 54 import org.apache.wicket.request.cycle.RequestCycle; 55 55 import org.apache.wicket.util.encoding.UrlDecoder; … … 60 60 /** 61 61 * Page showing VLO search results 62 * 62 * 63 63 * @author keeloo, for the addLandingPage links method and annotations 64 64 */ … … 68 68 public static final String PARAM_DOC_ID = "docId"; 69 69 public static final String feedbackfromURL = VloConfig.getFeedbackFromUrl(); 70 70 71 71 private final URL xslFile = getClass().getResource("/cmdi2xhtml.xsl"); 72 72 73 73 @SuppressWarnings("serial") 74 public ShowResultPage(final PageParameters currentParam) { 74 public ShowResultPage(final PageParameters currentParam) { 75 75 super(currentParam); 76 76 //TODO: Is encoding/decoding of the page parameter required (or can it be automated?) 77 77 final String docId = UrlDecoder.QUERY_INSTANCE.decode( 78 getPageParameters().get(PARAM_DOC_ID).toString(), 78 getPageParameters().get(PARAM_DOC_ID).toString(), 79 79 Application.get().getRequestCycleSettings().getResponseRequestEncoding()); // get current character set from request cycle 80 80 SolrDocument solrDocument = DaoLocator.getSearchResultsDao().getSolrDocument(docId); 81 81 if (solrDocument != null) { 82 82 final SearchPageQuery query = new SearchPageQuery(currentParam); 83 83 84 84 // create parameters from the query, and merge them with session related parameters 85 VloPageParameters newParam; 86 newParam = new VloPageParameters 87 85 VloPageParameters newParam; 86 newParam = new VloPageParameters(query.getPageParameters()); 87 88 88 BookmarkablePageLink<String> backLink = new BookmarkablePageLink<String>("backLink", FacetedSearchPage.class, newParam); 89 89 add(backLink); … … 95 95 } 96 96 addAttributesTable(solrDocument); 97 97 98 98 /* If there are any, add the link or links to landing pages 99 99 * contained in the solr document. 100 100 */ 101 101 addLandingPageLinks(solrDocument); 102 102 103 103 // also, if there are any, add the link or links to search pages 104 104 addSearchPageLinks(solrDocument); … … 106 106 // add the rest of the resource links to the result page 107 107 addResourceLinks(solrDocument); 108 108 109 109 addSearchServiceForm(solrDocument); 110 110 addCompleteCmdiView(solrDocument); 111 111 112 112 add(new AjaxLazyLoadPanel("prevNextHeader") { 113 113 … … 168 168 // associate css with table 169 169 table.setTableBodyCss("attributesTbody"); 170 table.addTopToolbar(new HeadersToolbar(table, null)); 170 table.addTopToolbar(new HeadersToolbar(table, null)); 171 171 // add table to page 172 172 add(table); … … 174 174 175 175 /** 176 * Create the columns for the table. 177 * 176 * Create the columns for the table. 177 * 178 178 * Create one column for the attributes and one column for their values. 179 * 179 * 180 180 * @newParam 181 181 */ … … 185 185 // create the column for the attribute names 186 186 IColumn column = null; 187 column = new PropertyColumn<Object, Object>(new ResourceModel(Resources.FIELD), "field") {187 column = new PropertyColumn<Object, Object>(new ResourceModel(Resources.FIELD), "field") { 188 188 189 189 @Override … … 192 192 } 193 193 }; 194 columns.add 194 columns.add(column); 195 195 196 196 // create the column for the values of the attributes … … 245 245 } 246 246 }; 247 columns.add 247 columns.add(column); 248 248 249 249 return columns; 250 250 } 251 251 252 252 /** 253 253 * Add landing page links to the result page. … … 256 256 */ 257 257 private void addLandingPageLinks(SolrDocument solrDocument) { 258 258 259 259 Label oneLandingPageText; 260 260 oneLandingPageText = new Label("oneLandingPage", … … 276 276 */ 277 277 if (!solrDocument.containsKey(FacetConstants.FIELD_LANDINGPAGE)) { 278 278 279 279 /* Since there are no links to be shown, make both labels defined in 280 280 * the page invisible … … 285 285 // make one of the two labels invisible 286 286 287 Collection<Object> landingPages =288 solrDocument.getFieldValues(FacetConstants.FIELD_LANDINGPAGE);287 Collection<Object> landingPages 288 = solrDocument.getFieldValues(FacetConstants.FIELD_LANDINGPAGE); 289 289 if (landingPages.size() > 1) { 290 290 291 291 // the list will contain more than one landing page link 292 292 oneLandingPageText.setVisible(false); … … 297 297 moreLandingPagesText.setVisible(false); 298 298 } 299 299 300 300 // generate the list of links 301 301 for (Iterator<Object> it = landingPages.iterator(); it.hasNext();) { … … 319 319 } 320 320 } 321 321 322 322 /** 323 323 * Add search page links to the result page. … … 326 326 */ 327 327 private void addSearchPageLinks(SolrDocument solrDocument) { 328 328 329 329 Label oneSearchPageText; 330 330 oneSearchPageText = new Label("oneSearchPage", … … 346 346 */ 347 347 if (!solrDocument.containsKey(FacetConstants.FIELD_SEARCHPAGE)) { 348 348 349 349 /* Since there are no links to be shown, make both labels defined in 350 350 * the page invisible … … 355 355 // make one of the two labels invisible 356 356 357 Collection<Object> searchPages =358 solrDocument.getFieldValues(FacetConstants.FIELD_SEARCHPAGE);357 Collection<Object> searchPages 358 = solrDocument.getFieldValues(FacetConstants.FIELD_SEARCHPAGE); 359 359 if (searchPages.size() > 1) { 360 360 361 361 // the list will contain more than one landing page link 362 362 oneSearchPageText.setVisible(false); … … 367 367 moreSearchPagesText.setVisible(false); 368 368 } 369 369 370 370 // generate the list of links 371 371 for (Iterator<Object> it = searchPages.iterator(); it.hasNext();) { … … 399 399 RepeatingView repeatingView = new RepeatingView("resourceList"); 400 400 add(repeatingView); 401 if (solrDocument.containsKey(FacetConstants.FIELD_RESOURCE)) { 401 if (solrDocument.containsKey(FacetConstants.FIELD_RESOURCE)) { 402 402 Collection<Object> resources = solrDocument.getFieldValues(FacetConstants.FIELD_RESOURCE); 403 403 if (resources.size() > 1) { … … 422 422 } 423 423 } 424 424 425 425 private void addFeedbackLink(final PageParameters parameters) { 426 426 427 427 // create VloPageParameters in orde to be able to convert to old style parameters 428 VloPageParameters newParam = new VloPageParameters (parameters); 429 430 String thisURL = RequestUtils.toAbsolutePath(RequestCycle.get().urlFor(ShowResultPage.class, newParam.convert()).toString(),null); 428 VloPageParameters newParam = new VloPageParameters(parameters); 429 430 final RequestCycle reqCycle = getRequestCycle(); 431 final Url reqUrl = Url.parse(reqCycle.urlFor(ShowResultPage.class, newParam.convert())); 432 String thisURL = reqCycle.getUrlRenderer().renderFullUrl(reqUrl); 433 431 434 try { 432 thisURL = URLEncoder.encode(thisURL, "UTF-8");435 thisURL = URLEncoder.encode(thisURL, "UTF-8"); 433 436 } catch (UnsupportedEncodingException e) { 434 437 LOG.error(e.toString()); 435 438 } 436 439 437 440 // Image resourceImg = new Image("feedbackImage", FEEDBACK_IMAGE.getResource()); 438 441 // String title = "Report an error"; 439 442 // resourceImg.add(new SimpleAttributeModifier("title", title)); 440 443 // resourceImg.add(new SimpleAttributeModifier("alt", title)); 441 String href = getHref(feedbackfromURL +thisURL);442 String name = feedbackfromURL +thisURL;444 String href = getHref(feedbackfromURL + thisURL); 445 String name = feedbackfromURL + thisURL; 443 446 ExternalLink link = new ExternalLink("feedbackLink", href, "found an error?"); 444 447 // link.add(resourceImg); … … 453 456 newParam = new VloPageParameters(query.getPageParameters()); 454 457 newParam.add(ShowResultPage.PARAM_DOC_ID, UrlEncoder.QUERY_INSTANCE.encode( 455 docId, 458 docId, 456 459 Application.get().getRequestCycleSettings().getResponseRequestEncoding())); // get current character set from request cycle 457 460 … … 460 463 return docLink; 461 464 } 462 463 /** 464 * Add contentSearch form (FCS) 465 * @newParam solrDocument 466 */ 467 private void addSearchServiceForm(final SolrDocument solrDocument) { 468 final WebMarkupContainer contentSearchContainer = new WebMarkupContainer("contentSearch"); 469 add(contentSearchContainer); 470 471 if (solrDocument.containsKey(FacetConstants.FIELD_SEARCH_SERVICE)) { 472 try { 473 // building map (CQL endpoint -> List with resource ID) 474 HashMap<String, List<String>> aggregrationContextMap = new HashMap<String, List<String>>(); 475 List<String> idList = new ArrayList<String>(); 476 idList.add(solrDocument.getFirstValue(FacetConstants.FIELD_ID).toString()); 477 aggregrationContextMap.put(solrDocument.getFirstValue(FacetConstants.FIELD_SEARCH_SERVICE).toString(), idList); 478 Label contentSearchLabel = new Label("contentSearchForm", HtmlFormCreator.getContentSearchForm(aggregrationContextMap, "Plain text search via Federated Content Search")); 479 contentSearchLabel.setEscapeModelStrings(false); 480 contentSearchContainer.add(contentSearchLabel); 481 } catch (UnsupportedEncodingException uee) { 482 contentSearchContainer.setVisible(false); 483 } 484 } else { 485 contentSearchContainer.setVisible(false); 486 } 487 } 488 489 /** 490 * Add complete CMDI view 491 * @newParam solrDocument 492 */ 493 private void addCompleteCmdiView(final SolrDocument solrDocument) { 494 StringWriter strWriter = new StringWriter(); 465 466 /** 467 * Add contentSearch form (FCS) 468 * 469 * @newParam solrDocument 470 */ 471 private void addSearchServiceForm(final SolrDocument solrDocument) { 472 final WebMarkupContainer contentSearchContainer = new WebMarkupContainer("contentSearch"); 473 add(contentSearchContainer); 474 475 if (solrDocument.containsKey(FacetConstants.FIELD_SEARCH_SERVICE)) { 476 try { 477 // building map (CQL endpoint -> List with resource ID) 478 HashMap<String, List<String>> aggregrationContextMap = new HashMap<String, List<String>>(); 479 List<String> idList = new ArrayList<String>(); 480 idList.add(solrDocument.getFirstValue(FacetConstants.FIELD_ID).toString()); 481 aggregrationContextMap.put(solrDocument.getFirstValue(FacetConstants.FIELD_SEARCH_SERVICE).toString(), idList); 482 Label contentSearchLabel = new Label("contentSearchForm", HtmlFormCreator.getContentSearchForm(aggregrationContextMap, "Plain text search via Federated Content Search")); 483 contentSearchLabel.setEscapeModelStrings(false); 484 contentSearchContainer.add(contentSearchLabel); 485 } catch (UnsupportedEncodingException uee) { 486 contentSearchContainer.setVisible(false); 487 } 488 } else { 489 contentSearchContainer.setVisible(false); 490 } 491 } 492 493 /** 494 * Add complete CMDI view 495 * 496 * @newParam solrDocument 497 */ 498 private void addCompleteCmdiView(final SolrDocument solrDocument) { 499 StringWriter strWriter = new StringWriter(); 495 500 496 501 final Processor proc = new Processor(false); … … 498 503 499 504 try { 500 501 502 503 504 505 506 507 508 509 510 511 512 505 final XsltExecutable exp = comp.compile(new StreamSource(xslFile.getFile())); 506 final XdmNode source = proc.newDocumentBuilder().build( 507 new StreamSource(new InputStreamReader(new URL(solrDocument.getFirstValue(FacetConstants.FIELD_COMPLETE_METADATA).toString()).openStream()))); 508 final Serializer out = new Serializer(); 509 out.setOutputProperty(Serializer.Property.METHOD, "html"); 510 out.setOutputProperty(Serializer.Property.INDENT, "yes"); 511 out.setOutputProperty(Serializer.Property.ENCODING, "UTF-8"); 512 out.setOutputWriter(strWriter); 513 final XsltTransformer trans = exp.load(); 514 515 trans.setInitialContextNode(source); 516 trans.setDestination(out); 517 trans.transform(); 513 518 } catch (Exception e) { 514 515 516 517 519 LOG.error("Couldn't create CMDI metadata: " + e.getMessage()); 520 strWriter = new StringWriter().append("<b>Could not load complete CMDI metadata</b>"); 521 } 522 518 523 Label completeCmdiLabel = new Label("completeCmdi", strWriter.toString()); 519 520 521 522 523 524 525 526 527 528 529 530 524 completeCmdiLabel.setEscapeModelStrings(false); 525 add(completeCmdiLabel); 526 527 // remove complete CMDI view on page load 528 add(new Behavior() { 529 private static final long serialVersionUID = 1865219352602175954L; 530 531 public void renderHead(IHeaderResponse response) { 532 response.render(JavaScriptHeaderItem.forScript("toogleDiv('completeCmdi', 'toogleLink')", null)); 533 } 534 }); 535 } 531 536 }
Note: See TracChangeset
for help on using the changeset viewer.