1
|
/**
|
2
|
* Copyright (C) 2009 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.ext.openurl;
|
10
|
|
11
|
import java.net.URISyntaxException;
|
12
|
|
13
|
import org.apache.log4j.Logger;
|
14
|
|
15
|
import eu.etaxonomy.cdm.common.URI;
|
16
|
import eu.etaxonomy.cdm.ext.openurl.MobotOpenUrlServiceWrapper.ReferenceType;
|
17
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
18
|
|
19
|
/**
|
20
|
* @author a.kohlbecker
|
21
|
* @since 16.12.2010
|
22
|
*/
|
23
|
public class OpenUrlReference extends Reference {
|
24
|
|
25
|
private static final long serialVersionUID = 5523159432429746682L;
|
26
|
public static final Logger logger = Logger.getLogger(OpenUrlReference.class);
|
27
|
|
28
|
private static final String PAGETHUMB_BASE_URI = "http://www.biodiversitylibrary.org/pagethumb/";
|
29
|
|
30
|
private URI itemUri;
|
31
|
|
32
|
private URI titleUri;
|
33
|
|
34
|
private ReferenceType referenceType = null;
|
35
|
|
36
|
/**
|
37
|
* Links to the specific book or journal, that is to the front page
|
38
|
*
|
39
|
* @param itemUri the itemUri to set
|
40
|
*/
|
41
|
public void setItemUri(URI itemUri) {
|
42
|
this.itemUri = itemUri;
|
43
|
}
|
44
|
|
45
|
/**
|
46
|
* Links to the according entry in the bibliography.
|
47
|
*
|
48
|
* @return the itemUri
|
49
|
*/
|
50
|
public URI getItemUri() {
|
51
|
return itemUri;
|
52
|
}
|
53
|
|
54
|
/**
|
55
|
* @param titleUri the titleUri to set
|
56
|
*/
|
57
|
public void setTitleUri(URI titleUri) {
|
58
|
this.titleUri = titleUri;
|
59
|
}
|
60
|
|
61
|
|
62
|
/**
|
63
|
* @return the titleUri
|
64
|
*/
|
65
|
public URI getTitleUri() {
|
66
|
return titleUri;
|
67
|
}
|
68
|
|
69
|
|
70
|
/**
|
71
|
* 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
|
72
|
* <ol>
|
73
|
* <li>http://www.biodiversitylibrary.org/item</li>
|
74
|
* <li>16772</li>
|
75
|
* </ol>
|
76
|
* @param uri
|
77
|
* @return
|
78
|
*/
|
79
|
private String[] splitPathAndId(URI uri) {
|
80
|
String[] tokens = new String[2];
|
81
|
if(uri != null){
|
82
|
String titleUriString = uri.toString();
|
83
|
tokens[1] = titleUriString.substring(titleUriString.lastIndexOf('/') + 1);
|
84
|
tokens[0] = titleUriString.substring(0, titleUriString.lastIndexOf('/'));
|
85
|
return tokens;
|
86
|
} else {
|
87
|
return null;
|
88
|
}
|
89
|
}
|
90
|
|
91
|
/**
|
92
|
* @param referenceType the referenceType to set
|
93
|
*/
|
94
|
public void setReferenceType(ReferenceType referenceType) {
|
95
|
this.referenceType = referenceType;
|
96
|
}
|
97
|
|
98
|
/**
|
99
|
* @return the referenceType
|
100
|
*/
|
101
|
public ReferenceType getReferenceType() {
|
102
|
return referenceType;
|
103
|
}
|
104
|
|
105
|
/**
|
106
|
* This method will construct an URI pointing to a service which creates an
|
107
|
* jpeg image. This may take a while. For more information please refer to
|
108
|
* http://biodivlib.wikispaces.com/Developer+Tools+and+API. If the width or
|
109
|
* height of the of the image given as parameter are null or 0 the BHL
|
110
|
* service will respond with the default thumbnail which seems to be cached.
|
111
|
* This is usually much faster than requesting for a custom imge
|
112
|
* size.
|
113
|
* <p>
|
114
|
*
|
115
|
* @param width
|
116
|
* width of the image, may be null or 0
|
117
|
* @param height
|
118
|
* height of the image, may be null or 0
|
119
|
* @return
|
120
|
*/
|
121
|
public URI getJpegImage(Integer width, Integer height){
|
122
|
|
123
|
URI imageURI = null;
|
124
|
try {
|
125
|
String sizeStr = "";
|
126
|
if(width != null && height != null && width > 0 && height > 0){
|
127
|
sizeStr = "," + width + "," + height;
|
128
|
}
|
129
|
String[] tokens = splitPathAndId(getUri());
|
130
|
if(tokens.length == 2){
|
131
|
imageURI = new URI(PAGETHUMB_BASE_URI + tokens[1] + sizeStr);
|
132
|
}
|
133
|
} catch (URISyntaxException e) {
|
134
|
// should never happen, but let's report it anyway
|
135
|
logger.error(e);
|
136
|
}
|
137
|
return imageURI;
|
138
|
}
|
139
|
}
|