Changeset 2057


Ignore:
Timestamp:
07/31/12 14:27:41 (12 years ago)
Author:
herste
Message:

trying to solve ticket 136; also fixed a test (the references component in the componentregistry was changed causing (undeserved) test failure)

Location:
vlo/trunk/vlo_webapp/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • vlo/trunk/vlo_webapp/src/main/java/eu/clarin/cmdi/vlo/pages/ResourceLinkPanel.java

    r1827 r2057  
    11package eu.clarin.cmdi.vlo.pages;
    22
     3import java.io.IOException;
     4import java.net.HttpURLConnection;
     5import java.net.MalformedURLException;
     6import java.net.URL;
     7import java.net.URLConnection;
    38import java.util.HashMap;
     9import java.util.List;
    410import java.util.Map;
    511
     
    814import net.handle.hdllib.HandleValue;
    915
     16import org.apache.commons.httpclient.HttpMethod;
    1017import org.apache.wicket.behavior.SimpleAttributeModifier;
    1118import org.apache.wicket.markup.html.basic.Label;
     
    2128import eu.clarin.cmdi.vlo.FacetConstants;
    2229
     30import javax.net.ssl.HttpsURLConnection;
     31
    2332public class ResourceLinkPanel extends Panel {
    2433
     
    2635
    2736    private static final long serialVersionUID = 1L;
    28    
     37
    2938    private final static String URN_NBN_RESOLVER_URL = "http://www.nbn-resolving.org/redirect/";
    3039
     
    6170
    6271    /**
    63      * Modifies resourceLink if necessary (adds support for different URN resolvers) 
     72     * Modifies resourceLink if necessary (adds support for different URN resolvers)
    6473     * @param resourceLink
    6574     * @return Modified resourceLink, if no modifications are necessary original parameter resourceLink is returned
     
    8089    private String getNameFromLink(String resourceLink) {
    8190        String result = resourceLink;
    82      // HandleResolver does not work at the moment on the clarin server see http://trac.clarin.eu/ticket/136, Disabled it for the release.       
     91        // We ALWAYS backoff to the resourceLink as default thingy.
     92
     93
     94
     95     // HandleResolver does not work at the moment on the clarin server see http://trac.clarin.eu/ticket/136, Disabled it for the release.
    8396//      if (resourceLink != null) {
    8497//          if (resourceLink.startsWith(FacetConstants.HANDLE_PREFIX)) {
     
    88101//                  handleResolver.setTcpTimeout(5000);//5 secs, default is one minute
    89102//                  HandleValue values[] = handleResolver.resolveHandle(handle, new String[] { "URL" }, null);
    90 //                 
     103//
    91104//                  for (HandleValue handleValue : values) {
    92105//                      String url = handleValue.getDataAsString();
     
    106119//      }
    107120
     121        /** NOTE: We are trying a different approach from the "official" one.
     122         * Will use the REST interface of hdl.handle.net.
     123         */
     124        if (resourceLink != null) {
     125            if (resourceLink.startsWith(FacetConstants.HANDLE_PREFIX)) {
     126                String handle = resourceLink.substring(FacetConstants.HANDLE_PREFIX.length());
     127                resourceLink = Configuration.getInstance().getHandleServerUrl() + handle;
     128                // Now points to something like http://hdl.handle.net/1839/00-0000-0000-0004-3357-F
     129                HttpURLConnection con = null;
     130                URL u;
     131                try{
     132                    u = new URL(resourceLink);
     133                    URLConnection c = u.openConnection();
     134                    if(c instanceof HttpURLConnection){
     135                        con = (HttpURLConnection) c;
     136                    }
     137                    if(con != null){
     138                        if(con.getResponseCode() == HttpURLConnection.HTTP_MOVED_PERM ||
     139                                con.getResponseCode() == HttpURLConnection.HTTP_MOVED_TEMP ||
     140                                con.getResponseCode() == HttpURLConnection.HTTP_SEE_OTHER){
     141                            for (Map.Entry<String, List<String>> header : con.getHeaderFields().entrySet()) {
     142                                if(header.getKey().equals("Location")){
     143                                    result = header.getValue().get(0);
     144                                }
     145                            }
     146                        }
     147                    }
     148                } catch (MalformedURLException e) {
     149                    LOG.warn("Error trying to get the name of the handle", e);
     150                } catch (IOException e) {
     151                    LOG.warn("Error trying to get the name of the handle", e);
     152                }
     153            }
     154        }
    108155        return result;
    109156    }
  • vlo/trunk/vlo_webapp/src/test/java/eu/clarin/cmdi/vlo/importer/FacetMappingFactoryTest.java

    r1938 r2057  
    4343        mapping = facets.get(index++);
    4444        assertEquals(FacetConstants.FIELD_YEAR, mapping.getName());
    45         assertEquals(1, mapping.getPatterns().size());
     45        assertEquals(2, mapping.getPatterns().size());
    4646        assertEquals("/c:CMD/c:Components/c:Session/c:Date/text()", mapping.getPatterns().get(0));
    4747        mapping = facets.get(index++);
Note: See TracChangeset for help on using the changeset viewer.