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