Changeset 2057
- Timestamp:
- 07/31/12 14:27:41 (12 years ago)
- 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 1 1 package eu.clarin.cmdi.vlo.pages; 2 2 3 import java.io.IOException; 4 import java.net.HttpURLConnection; 5 import java.net.MalformedURLException; 6 import java.net.URL; 7 import java.net.URLConnection; 3 8 import java.util.HashMap; 9 import java.util.List; 4 10 import java.util.Map; 5 11 … … 8 14 import net.handle.hdllib.HandleValue; 9 15 16 import org.apache.commons.httpclient.HttpMethod; 10 17 import org.apache.wicket.behavior.SimpleAttributeModifier; 11 18 import org.apache.wicket.markup.html.basic.Label; … … 21 28 import eu.clarin.cmdi.vlo.FacetConstants; 22 29 30 import javax.net.ssl.HttpsURLConnection; 31 23 32 public class ResourceLinkPanel extends Panel { 24 33 … … 26 35 27 36 private static final long serialVersionUID = 1L; 28 37 29 38 private final static String URN_NBN_RESOLVER_URL = "http://www.nbn-resolving.org/redirect/"; 30 39 … … 61 70 62 71 /** 63 * Modifies resourceLink if necessary (adds support for different URN resolvers) 72 * Modifies resourceLink if necessary (adds support for different URN resolvers) 64 73 * @param resourceLink 65 74 * @return Modified resourceLink, if no modifications are necessary original parameter resourceLink is returned … … 80 89 private String getNameFromLink(String resourceLink) { 81 90 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. 83 96 // if (resourceLink != null) { 84 97 // if (resourceLink.startsWith(FacetConstants.HANDLE_PREFIX)) { … … 88 101 // handleResolver.setTcpTimeout(5000);//5 secs, default is one minute 89 102 // HandleValue values[] = handleResolver.resolveHandle(handle, new String[] { "URL" }, null); 90 // 103 // 91 104 // for (HandleValue handleValue : values) { 92 105 // String url = handleValue.getDataAsString(); … … 106 119 // } 107 120 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 } 108 155 return result; 109 156 } -
vlo/trunk/vlo_webapp/src/test/java/eu/clarin/cmdi/vlo/importer/FacetMappingFactoryTest.java
r1938 r2057 43 43 mapping = facets.get(index++); 44 44 assertEquals(FacetConstants.FIELD_YEAR, mapping.getName()); 45 assertEquals( 1, mapping.getPatterns().size());45 assertEquals(2, mapping.getPatterns().size()); 46 46 assertEquals("/c:CMD/c:Components/c:Session/c:Date/text()", mapping.getPatterns().get(0)); 47 47 mapping = facets.get(index++);
Note: See TracChangeset
for help on using the changeset viewer.