3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.ext
.openurl
;
13 import java
.net
.URISyntaxException
;
15 import org
.apache
.log4j
.Logger
;
17 import eu
.etaxonomy
.cdm
.ext
.openurl
.MobotOpenUrlServiceWrapper
.ReferenceType
;
18 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
19 import eu
.etaxonomy
.cdm
.strategy
.cache
.reference
.IReferenceBaseCacheStrategy
;
22 * @author a.kohlbecker
26 public class OpenUrlReference
<S
extends IReferenceBaseCacheStrategy
> extends Reference
<S
> {
29 private static final String PAGETHUMB_BASE_URI
= "http://www.biodiversitylibrary.org/pagethumb/";
31 public static final Logger logger
= Logger
.getLogger(OpenUrlReference
.class);
33 private static final long serialVersionUID
= 1L;
39 private ReferenceType referenceType
= null;
42 * Links to the specific book or journal, that is to the front page
44 * @param itemUri the itemUri to set
46 public void setItemUri(URI itemUri
) {
47 this.itemUri
= itemUri
;
51 * Links to the according entry in the bibliography.
55 public URI
getItemUri() {
60 * @param titleUri the titleUri to set
62 public void setTitleUri(URI titleUri
) {
63 this.titleUri
= titleUri
;
68 * @return the titleUri
70 public URI
getTitleUri() {
76 * Splits the id from the base ulr of the id urls used in bhl. For example the url string http://www.biodiversitylibrary.org/item/16772 will be split into
78 * <li>http://www.biodiversitylibrary.org/item</li>
84 private String
[] splitPathAndId(URI uri
) {
85 String
[] tokens
= new String
[2];
87 String titleUriString
= uri
.toString();
88 tokens
[1] = titleUriString
.substring(titleUriString
.lastIndexOf('/') + 1);
89 tokens
[0] = titleUriString
.substring(0, titleUriString
.lastIndexOf('/'));
97 * @param referenceType the referenceType to set
99 public void setReferenceType(ReferenceType referenceType
) {
100 this.referenceType
= referenceType
;
104 * @return the referenceType
106 public ReferenceType
getReferenceType() {
107 return referenceType
;
111 * This method will construct an URI pointing to a service which creates an
112 * jpeg image. This may take a while. For more information please refer to
113 * http://biodivlib.wikispaces.com/Developer+Tools+and+API. If the width or
114 * height of the of the image given as parameter are null or 0 the BHL
115 * service will respond with the default thumbnail which seems to be cached.
116 * This is usually much faster than requesting for a custom imge
121 * width of the image, may be null or 0
123 * height of the image, may be null or 0
126 public URI
getJpegImage(Integer width
, Integer height
){
131 if(width
!= null && height
!= null && width
> 0 && height
> 0){
132 sizeStr
= "," + width
+ "," + height
;
134 String
[] tokens
= splitPathAndId(getUri());
135 if(tokens
.length
== 2){
136 imageURI
= new URI(PAGETHUMB_BASE_URI
+ tokens
[1] + sizeStr
);
138 } catch (URISyntaxException e
) {
139 // should never happen, but let's report it anyway