Changeset 4223


Ignore:
Timestamp:
01/07/14 12:57:26 (10 years ago)
Author:
twagoo
Message:

Replaced usage of toAbsolutePath() with method on URL renderer

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  
    5151import org.apache.wicket.model.IModel;
    5252import org.apache.wicket.model.ResourceModel;
    53 import org.apache.wicket.protocol.http.RequestUtils;
     53import org.apache.wicket.request.Url;
    5454import org.apache.wicket.request.cycle.RequestCycle;
    5555import org.apache.wicket.util.encoding.UrlDecoder;
     
    6060/**
    6161 * Page showing VLO search results
    62  * 
     62 *
    6363 * @author keeloo, for the addLandingPage links method and annotations
    6464 */
     
    6868    public static final String PARAM_DOC_ID = "docId";
    6969    public static final String feedbackfromURL = VloConfig.getFeedbackFromUrl();
    70    
     70
    7171    private final URL xslFile = getClass().getResource("/cmdi2xhtml.xsl");
    72    
     72
    7373    @SuppressWarnings("serial")
    74     public ShowResultPage(final PageParameters currentParam) {       
     74    public ShowResultPage(final PageParameters currentParam) {
    7575        super(currentParam);
    7676        //TODO: Is encoding/decoding of the page parameter required (or can it be automated?)
    7777        final String docId = UrlDecoder.QUERY_INSTANCE.decode(
    78                 getPageParameters().get(PARAM_DOC_ID).toString(), 
     78                getPageParameters().get(PARAM_DOC_ID).toString(),
    7979                Application.get().getRequestCycleSettings().getResponseRequestEncoding()); // get current character set from request cycle
    8080        SolrDocument solrDocument = DaoLocator.getSearchResultsDao().getSolrDocument(docId);
    8181        if (solrDocument != null) {
    8282            final SearchPageQuery query = new SearchPageQuery(currentParam);
    83            
     83
    8484            // create parameters from the query, and merge them with session related parameters
    85             VloPageParameters newParam; 
    86             newParam = new VloPageParameters (query.getPageParameters());
    87            
     85            VloPageParameters newParam;
     86            newParam = new VloPageParameters(query.getPageParameters());
     87
    8888            BookmarkablePageLink<String> backLink = new BookmarkablePageLink<String>("backLink", FacetedSearchPage.class, newParam);
    8989            add(backLink);
     
    9595            }
    9696            addAttributesTable(solrDocument);
    97            
     97
    9898            /* If there are any, add the link or links to landing pages
    9999             * contained in the solr document.
    100100             */
    101101            addLandingPageLinks(solrDocument);
    102            
     102
    103103            // also, if there are any, add the link or links to search pages
    104104            addSearchPageLinks(solrDocument);
     
    106106            // add the rest of the resource links to the result page
    107107            addResourceLinks(solrDocument);
    108            
     108
    109109            addSearchServiceForm(solrDocument);
    110110            addCompleteCmdiView(solrDocument);
    111            
     111
    112112            add(new AjaxLazyLoadPanel("prevNextHeader") {
    113113
     
    168168        // associate css with table
    169169        table.setTableBodyCss("attributesTbody");
    170         table.addTopToolbar(new HeadersToolbar(table, null)); 
     170        table.addTopToolbar(new HeadersToolbar(table, null));
    171171        // add table to page
    172172        add(table);
     
    174174
    175175    /**
    176      * Create the columns for the table. 
    177      * 
     176     * Create the columns for the table.
     177     *
    178178     * Create one column for the attributes and one column for their values.
    179      * 
     179     *
    180180     * @newParam
    181181     */
     
    185185        // create the column for the attribute names
    186186        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") {
    188188
    189189            @Override
     
    192192            }
    193193        };
    194         columns.add (column);
     194        columns.add(column);
    195195
    196196        // create the column for the values of the attributes
     
    245245            }
    246246        };
    247         columns.add (column);
     247        columns.add(column);
    248248
    249249        return columns;
    250250    }
    251    
     251
    252252    /**
    253253     * Add landing page links to the result page.
     
    256256     */
    257257    private void addLandingPageLinks(SolrDocument solrDocument) {
    258        
     258
    259259        Label oneLandingPageText;
    260260        oneLandingPageText = new Label("oneLandingPage",
     
    276276         */
    277277        if (!solrDocument.containsKey(FacetConstants.FIELD_LANDINGPAGE)) {
    278            
     278
    279279            /* Since there are no links to be shown, make both labels defined in
    280280             * the page invisible
     
    285285            //  make one of the two labels invisible
    286286
    287             Collection<Object> landingPages =
    288                     solrDocument.getFieldValues(FacetConstants.FIELD_LANDINGPAGE);
     287            Collection<Object> landingPages
     288                    = solrDocument.getFieldValues(FacetConstants.FIELD_LANDINGPAGE);
    289289            if (landingPages.size() > 1) {
    290                
     290
    291291                // the list will contain more than one landing page link
    292292                oneLandingPageText.setVisible(false);
     
    297297                moreLandingPagesText.setVisible(false);
    298298            }
    299            
     299
    300300            // generate the list of links
    301301            for (Iterator<Object> it = landingPages.iterator(); it.hasNext();) {
     
    319319        }
    320320    }
    321    
     321
    322322    /**
    323323     * Add search page links to the result page.
     
    326326     */
    327327    private void addSearchPageLinks(SolrDocument solrDocument) {
    328        
     328
    329329        Label oneSearchPageText;
    330330        oneSearchPageText = new Label("oneSearchPage",
     
    346346         */
    347347        if (!solrDocument.containsKey(FacetConstants.FIELD_SEARCHPAGE)) {
    348            
     348
    349349            /* Since there are no links to be shown, make both labels defined in
    350350             * the page invisible
     
    355355            //  make one of the two labels invisible
    356356
    357             Collection<Object> searchPages =
    358                     solrDocument.getFieldValues(FacetConstants.FIELD_SEARCHPAGE);
     357            Collection<Object> searchPages
     358                    = solrDocument.getFieldValues(FacetConstants.FIELD_SEARCHPAGE);
    359359            if (searchPages.size() > 1) {
    360                
     360
    361361                // the list will contain more than one landing page link
    362362                oneSearchPageText.setVisible(false);
     
    367367                moreSearchPagesText.setVisible(false);
    368368            }
    369            
     369
    370370            // generate the list of links
    371371            for (Iterator<Object> it = searchPages.iterator(); it.hasNext();) {
     
    399399        RepeatingView repeatingView = new RepeatingView("resourceList");
    400400        add(repeatingView);
    401         if (solrDocument.containsKey(FacetConstants.FIELD_RESOURCE)) {     
     401        if (solrDocument.containsKey(FacetConstants.FIELD_RESOURCE)) {
    402402            Collection<Object> resources = solrDocument.getFieldValues(FacetConstants.FIELD_RESOURCE);
    403403            if (resources.size() > 1) {
     
    422422        }
    423423    }
    424    
     424
    425425    private void addFeedbackLink(final PageParameters parameters) {
    426        
     426
    427427        // 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
    431434        try {
    432             thisURL = URLEncoder.encode(thisURL,"UTF-8");
     435            thisURL = URLEncoder.encode(thisURL, "UTF-8");
    433436        } catch (UnsupportedEncodingException e) {
    434437            LOG.error(e.toString());
    435438        }
    436        
     439
    437440        // Image resourceImg = new Image("feedbackImage", FEEDBACK_IMAGE.getResource());
    438441        // String title = "Report an error";
    439442        // resourceImg.add(new SimpleAttributeModifier("title", title));
    440443        // 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;
    443446        ExternalLink link = new ExternalLink("feedbackLink", href, "found an error?");
    444447        // link.add(resourceImg);
     
    453456        newParam = new VloPageParameters(query.getPageParameters());
    454457        newParam.add(ShowResultPage.PARAM_DOC_ID, UrlEncoder.QUERY_INSTANCE.encode(
    455                 docId, 
     458                docId,
    456459                Application.get().getRequestCycleSettings().getResponseRequestEncoding())); // get current character set from request cycle
    457460
     
    460463        return docLink;
    461464    }
    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();
    495500
    496501        final Processor proc = new Processor(false);
     
    498503
    499504        try {
    500                 final XsltExecutable exp = comp.compile(new StreamSource(xslFile.getFile()));
    501                 final XdmNode source = proc.newDocumentBuilder().build(
    502                                 new StreamSource(new InputStreamReader(new URL(solrDocument.getFirstValue(FacetConstants.FIELD_COMPLETE_METADATA).toString()).openStream())));
    503                 final Serializer out = new Serializer();
    504                 out.setOutputProperty(Serializer.Property.METHOD, "html");
    505                 out.setOutputProperty(Serializer.Property.INDENT, "yes");
    506                 out.setOutputProperty(Serializer.Property.ENCODING, "UTF-8");
    507                 out.setOutputWriter(strWriter);
    508                 final XsltTransformer trans = exp.load();
    509 
    510                 trans.setInitialContextNode(source);
    511                 trans.setDestination(out);
    512                 trans.transform();
     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();
    513518        } catch (Exception e) {
    514                 LOG.error("Couldn't create CMDI metadata: " + e.getMessage());
    515                 strWriter = new StringWriter().append("<b>Could not load complete CMDI metadata</b>");
    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
    518523        Label completeCmdiLabel = new Label("completeCmdi", strWriter.toString());
    519                 completeCmdiLabel.setEscapeModelStrings(false);
    520                 add(completeCmdiLabel);
    521                
    522                 // remove complete CMDI view on page load
    523                 add(new Behavior() {
    524                         private static final long serialVersionUID = 1865219352602175954L;
    525 
    526                         public void renderHead(IHeaderResponse response) {
    527                             response.render(JavaScriptHeaderItem.forScript("toogleDiv('completeCmdi', 'toogleLink')", null));
    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    }
    531536}
Note: See TracChangeset for help on using the changeset viewer.