Changeset 4644
- Timestamp:
- 03/07/14 13:00:36 (10 years ago)
- Location:
- vlo/branches/vlo-3.0/vlo-web-app/src
- Files:
-
- 1 added
- 8 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/pojo/ResourceInfo.java
r4639 r4644 24 24 25 25 private final String href; 26 private final String fileName; 26 27 private final String mimeType; 27 28 private final ResourceType resourceType; 28 29 29 public ResourceInfo(String href, String mimeType, ResourceType resourceType) {30 public ResourceInfo(String href, String fileName, String mimeType, ResourceType resourceType) { 30 31 this.href = href; 32 this.fileName = fileName; 31 33 this.mimeType = mimeType; 32 34 this.resourceType = resourceType; … … 35 37 public String getHref() { 36 38 return href; 39 } 40 41 public String getFileName() { 42 return fileName; 37 43 } 38 44 -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/impl/ResourceStringConverterImpl.java
r4639 r4644 22 22 import eu.clarin.cmdi.vlo.pojo.ResourceType; 23 23 import eu.clarin.cmdi.vlo.service.ResourceStringConverter; 24 import java.net.URI; 25 import java.net.URISyntaxException; 24 26 import java.util.regex.Pattern; 27 import org.apache.commons.io.FilenameUtils; 25 28 26 29 /** … … 38 41 final String mimeType = tokens[0]; 39 42 final String href = tokens[1]; 43 44 final String fileName = getFileName(href); 40 45 // determine resource type based on mime type 41 46 final ResourceType resourceType = determineResourceType(mimeType); 42 return new ResourceInfo(href, mimeType, resourceType); 47 return new ResourceInfo(href, fileName, mimeType, resourceType); 48 } 49 50 private String getFileName(final String href) { 51 try { 52 //analyse URI 53 final URI uri = new URI(href); 54 final String scheme = uri.getScheme(); 55 final String path = uri.getPath(); 56 // in case of path information or handle, return original href 57 if (path == null || path.isEmpty() || (scheme != null && scheme.equals("hdl"))) { 58 return href; 59 } else { 60 return FilenameUtils.getName(path); 61 } 62 } catch (URISyntaxException ex) { 63 return href; 64 } 43 65 } 44 66 -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/components/ResourceLinkDetailsPanel.html
r4640 r4644 24 24 <body> 25 25 <wicket:panel> 26 <wicket:container wicket:id="resource"> 27 <a wicket:id="showResource"> 28 <wicket:container wicket:id="filename">resource.txt</wicket:container> 29 </a> 30 </wicket:container> 31 32 <!-- <div wicket:id="resourceDetails" class="recordresourcedetails"> 33 <h2 wicket:id="title">Bachelorscriptie+Rene+Witteveen+3375005.docx</h2> 34 <ul> 35 <li wicket:id="fileType">File type: text file</li> 36 <li wicket:id="resourceType">Mime type: application/msword</li> 37 <li>Location: 38 <a wicket:id="link" class="resourcedownloadlink"> 39 <wicket:container wicket:id="href"></wicket:container> 40 </a> 41 </li> 42 </ul> 43 </div>--> 26 <h2 wicket:id="fileName">Bachelorscriptie+Rene+Witteveen+3375005.docx</h2> 27 <ul> 28 <li>File type: <span wicket:id="resourceType">text file</span></li> 29 <li>Mime type: <span wicket:id="mimeType">application/msword</span></li> 30 <li>Location: 31 <a wicket:id="link" class="resourcedownloadlink"> 32 <wicket:container wicket:id="href"></wicket:container> 33 </a> 34 </li> 35 </ul> 44 36 </wicket:panel> 45 37 </body> -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/components/ResourceLinksPanel.html
r4640 r4644 25 25 <wicket:panel> 26 26 <wicket:container wicket:id="resource"> 27 <a wicket:id="showResource">27 <a class="resourceLink" wicket:id="showResource"> 28 28 <wicket:container wicket:id="filename">resource.txt</wicket:container> 29 29 </a> 30 30 </wicket:container> 31 31 32 <!-- <div wicket:id="resourceDetails" class="recordresourcedetails"> 33 <h2 wicket:id="title">Bachelorscriptie+Rene+Witteveen+3375005.docx</h2> 34 <ul> 35 <li wicket:id="fileType">File type: text file</li> 36 <li wicket:id="resourceType">Mime type: application/msword</li> 37 <li>Location: 38 <a wicket:id="link" class="resourcedownloadlink"> 39 <wicket:container wicket:id="href"></wicket:container> 40 </a> 41 </li> 42 </ul> 43 </div>--> 32 <div wicket:id="detailsContainer" id="recordresourcedetailsContainer"> 33 <div wicket:id="details" class="recordresourcedetails"></div> 34 </div> 44 35 </wicket:panel> 45 36 </body> -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/components/ResourceLinksPanel.java
r4640 r4644 21 21 import eu.clarin.cmdi.vlo.wicket.model.CollectionListModel; 22 22 import java.util.Collection; 23 import java.util.List; 23 24 import org.apache.wicket.AttributeModifier; 25 import org.apache.wicket.ajax.AjaxRequestTarget; 26 import org.apache.wicket.ajax.markup.html.AjaxFallbackLink; 27 import org.apache.wicket.behavior.AttributeAppender; 28 import org.apache.wicket.markup.html.WebMarkupContainer; 24 29 import org.apache.wicket.markup.html.basic.Label; 25 30 import org.apache.wicket.markup.html.link.Link; … … 34 39 35 40 /** 41 * Panel that shows all resources represented by a collection of resource 42 * strings as links that trigger a details panel for the selected resource 36 43 * 37 44 * @author twagoo … … 41 48 @SpringBean 42 49 private ResourceStringConverter resourceStringConverter; 50 private final WebMarkupContainer detailsContainer; 43 51 44 52 /** … … 49 57 public ResourceLinksPanel(String id, IModel<Collection<String>> model) { 50 58 super(id, model); 51 final ListView<String> resourcesView = new ListView<String>("resource", new CollectionListModel<String>(model)) { 59 // list view that shows all resources as links that show a resource details panel when clicked 60 add(new ResourcesListView("resource", new CollectionListModel<String>(model))); 52 61 53 @Override54 protected void populateItem(ListItem<String> item) {55 final ResourceInfoModel resourceInfoModel = new ResourceInfoModel(item.getModel());56 final Link link = new Link("showResource") {62 // container for resource details (to enable AJAX updates) 63 detailsContainer = new WebMarkupContainer("detailsContainer"); 64 detailsContainer.setOutputMarkupId(true); 65 add(detailsContainer); 57 66 58 @Override 59 public void onClick() { 60 throw new UnsupportedOperationException("Not supported yet."); 61 } 62 }; 63 item.add(link); 64 // set the file name as the link's text content 65 link.add(new Label("filename", new PropertyModel(resourceInfoModel, "href"))); 66 // set the class attribute on the link from the value associated 67 // with the resource type as defined in the properties file 68 link.add(new AttributeModifier("class", 69 new StringResourceModel("class.${resourceType}", ResourceLinksPanel.this, resourceInfoModel, ""))); 70 } 71 }; 72 resourcesView.setReuseItems(true); 73 add(resourcesView); 74 67 // insert a place holder until one of the resource links is clicked 68 final WebMarkupContainer detailsPlaceholder = new WebMarkupContainer("details"); 69 detailsPlaceholder.setVisible(false); 70 detailsContainer.add(detailsPlaceholder); 75 71 } 76 72 73 private class ResourcesListView extends ListView<String> { 74 75 public ResourcesListView(String id, IModel<? extends List<? extends String>> model) { 76 super(id, model); 77 setReuseItems(true); 78 } 79 80 @Override 81 protected void populateItem(ListItem<String> item) { 82 final ResourceInfoModel resourceInfoModel = new ResourceInfoModel(item.getModel()); 83 // add a link that will show the resource details panel when clicked 84 item.add(createLink(resourceInfoModel)); 85 } 86 87 private Link createLink(final ResourceInfoModel resourceInfoModel) { 88 final Link link = new AjaxFallbackLink("showResource") { 89 90 @Override 91 public void onClick(AjaxRequestTarget target) { 92 // replace any existing details panel or placeholder with 93 // a details panel for the current resource 94 detailsContainer.addOrReplace(new ResourceLinkDetailsPanel("details", resourceInfoModel)); 95 if (target != null) { 96 target.add(detailsContainer); 97 target.prependJavaScript("hideResourceDetails();"); 98 target.appendJavaScript("showResourceDetails();"); 99 } 100 } 101 }; 102 link.setAnchor(detailsContainer); 103 // set the file name as the link's text content 104 link.add(new Label("filename", new PropertyModel(resourceInfoModel, "fileName"))); 105 106 // set the class attribute on the link from the value associated 107 // with the resource type as defined in the properties file 108 final StringResourceModel linkClass = new StringResourceModel("class.${resourceType}", ResourceLinksPanel.this, resourceInfoModel, ""); 109 link.add(new AttributeAppender("class", linkClass).setSeparator(" ")); 110 111 return link; 112 } 113 } 114 115 /** 116 * Model for {@link ResourceInfo} that dynamically instantiates its objects 117 * from a resource string (as retrieved from the Solr index) using the 118 * {@link ResourceStringConverter} 119 */ 77 120 private class ResourceInfoModel extends LoadableDetachableModel<ResourceInfo> { 78 121 -
vlo/branches/vlo-3.0/vlo-web-app/src/main/webapp/js/vlo-record.js
r4466 r4644 16 16 */ 17 17 18 $(document).ready(function() { 18 $(document).ready(function() { 19 19 $("#recordtechnicaldetails, #recordcmdi").hide(); 20 20 $("#hiderecordtechnicaldetails, #hiderecordcmdi").hide(); 21 $("#recordcmditoggle a").click(function(event) {21 $("#recordcmditoggle a").click(function(event) { 22 22 event.preventDefault(); 23 23 $("#recordcmdi").toggle(); 24 24 $("#recordcmditoggle a").toggle(); 25 25 }); 26 $("#recordtechnicaldetailstoggle a").click(function(event) {26 $("#recordtechnicaldetailstoggle a").click(function(event) { 27 27 event.preventDefault(); 28 28 $("#recordtechnicaldetails").toggle(); 29 29 $("#recordtechnicaldetailstoggle a").toggle(); 30 30 }); 31 31 }); 32 33 function hideResourceDetails() { 34 $(".recordresourcedetails").slideUp('fast'); 35 } 36 37 function showResourceDetails() { 38 $(window).scrollTop($('#recordresourcedetailsContainer').position().top); 32 39 $(".recordresourcedetails").hide(); 33 $("#recordresources > a").click(function(event){ 34 event.preventDefault(); 35 $(".recordresourcedetails").slideToggle('fast'); 36 }); 37 }); 40 $(".recordresourcedetails").slideDown('fast'); 41 } -
vlo/branches/vlo-3.0/vlo-web-app/src/main/webapp/style/vlo-record.css
r4640 r4644 128 128 } 129 129 130 #recordresources a {130 #recordresources a.resourceLink { 131 131 display: inline-block; 132 132 float: left; … … 141 141 } 142 142 143 #recordresources a :hover {143 #recordresources a.resourceLink:hover { 144 144 background-color: #ccc; 145 145 } -
vlo/branches/vlo-3.0/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/service/impl/ResourceStringConverterImplTest.java
r4639 r4644 96 96 assertEquals(ResourceType.OTHER, result.getResourceType()); 97 97 } 98 99 @Test 100 public void testGetResourceInfoFilename() { 101 assertFileNameResult("file.txt", "http://myserver.com/file.txt"); 102 assertFileNameResult("file.txt", "file:/somehwere/on/my/fs/this/file.txt"); 103 assertFileNameResult("http://myserver.com", "http://myserver.com"); 104 assertFileNameResult("hdl:12345", "hdl:12345"); 105 } 106 107 private void assertFileNameResult(String expected, String href){ 108 String resourceString = "application/test" + FacetConstants.FIELD_RESOURCE_SPLIT_CHAR + href; 109 ResourceInfo result = instance.getResourceInfo(resourceString); 110 assertEquals(expected, result.getFileName()); 111 } 98 112 99 113 } -
vlo/branches/vlo-3.0/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/service/impl/ResourceTypeCountingServiceImplTest.java
r4639 r4644 52 52 "annotation resource string", 53 53 "other resource string" 54 // "video/mpeg" + FacetConstants.FIELD_RESOURCE_SPLIT_CHAR + "myvideo",55 // "audio/ogg" + FacetConstants.FIELD_RESOURCE_SPLIT_CHAR + "myaudio",56 // "audio/ogg" + FacetConstants.FIELD_RESOURCE_SPLIT_CHAR + "myaudio"54 // "video/mpeg" + FacetConstants.FIELD_RESOURCE_SPLIT_CHAR + "myvideo", 55 // "audio/ogg" + FacetConstants.FIELD_RESOURCE_SPLIT_CHAR + "myaudio", 56 // "audio/ogg" + FacetConstants.FIELD_RESOURCE_SPLIT_CHAR + "myaudio" 57 57 // "audio/ogg" + FacetConstants.FIELD_RESOURCE_SPLIT_CHAR + "myaudio", 58 58 // "audio/ogg" + FacetConstants.FIELD_RESOURCE_SPLIT_CHAR + "myaudio", … … 67 67 exactly(6).of(converter).getResourceInfo(with(any(String.class))); 68 68 will(onConsecutiveCalls( 69 returnValue(new ResourceInfo("href1", " video/mpeg", ResourceType.VIDEO)),70 returnValue(new ResourceInfo("href2", " video/mpeg", ResourceType.VIDEO)),71 returnValue(new ResourceInfo("href3", " audio/ogg", ResourceType.AUDIO)),72 returnValue(new ResourceInfo("href4", " audio/ogg", ResourceType.TEXT)),73 returnValue(new ResourceInfo("href5", " audio/ogg", ResourceType.ANNOTATION)),74 returnValue(new ResourceInfo("href6", " audio/ogg", ResourceType.OTHER))69 returnValue(new ResourceInfo("href1", "fileName1", "video/mpeg", ResourceType.VIDEO)), 70 returnValue(new ResourceInfo("href2", "fileName2", "video/mpeg", ResourceType.VIDEO)), 71 returnValue(new ResourceInfo("href3", "fileName3", "audio/ogg", ResourceType.AUDIO)), 72 returnValue(new ResourceInfo("href4", "fileName4", "audio/ogg", ResourceType.TEXT)), 73 returnValue(new ResourceInfo("href5", "fileName5", "audio/ogg", ResourceType.ANNOTATION)), 74 returnValue(new ResourceInfo("href6", "fileName6", "audio/ogg", ResourceType.OTHER)) 75 75 )); 76 76 } … … 82 82 assertThat(result, hasItem(new ResourceTypeCount(ResourceType.TEXT, 1))); 83 83 assertThat(result, hasItem(new ResourceTypeCount(ResourceType.ANNOTATION, 1))); 84 assertThat(result, hasItem(new ResourceTypeCount(ResourceType.OTHER, 1))); 84 assertThat(result, hasItem(new ResourceTypeCount(ResourceType.OTHER, 1))); 85 85 } 86 86
Note: See TracChangeset
for help on using the changeset viewer.