Project

General

Profile

Download (3.61 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2009 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
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.
9
*/
10
package eu.etaxonomy.cdm.ext.openurl;
11

    
12
import java.net.URI;
13
import java.net.URISyntaxException;
14

    
15
import org.apache.log4j.Logger;
16

    
17
import eu.etaxonomy.cdm.ext.openurl.MobotOpenUrlServiceWrapper.ReferenceType;
18
import eu.etaxonomy.cdm.model.reference.Reference;
19

    
20
/**
21
 * @author a.kohlbecker
22
 * @date 16.12.2010
23
 *
24
 */
25
public class OpenUrlReference extends Reference {
26

    
27

    
28
	private static final String PAGETHUMB_BASE_URI = "http://www.biodiversitylibrary.org/pagethumb/";
29

    
30
	public static final Logger logger = Logger.getLogger(OpenUrlReference.class);
31

    
32
	private static final long serialVersionUID = 1L;
33

    
34
	private URI itemUri;
35

    
36
	private URI titleUri;
37

    
38
	private ReferenceType referenceType = null;
39

    
40
	/**
41
	 * Links to the specific book or journal, that is to the front page
42
	 *
43
	 * @param itemUri the itemUri to set
44
	 */
45
	public void setItemUri(URI itemUri) {
46
		this.itemUri = itemUri;
47
	}
48

    
49
	/**
50
	 * Links to the according entry in the bibliography.
51
	 *
52
	 * @return the itemUri
53
	 */
54
	public URI getItemUri() {
55
		return itemUri;
56
	}
57

    
58
	/**
59
	 * @param titleUri the titleUri to set
60
	 */
61
	public void setTitleUri(URI titleUri) {
62
		this.titleUri = titleUri;
63
	}
64

    
65

    
66
	/**
67
	 * @return the titleUri
68
	 */
69
	public URI getTitleUri() {
70
		return titleUri;
71
	}
72

    
73

    
74
	/**
75
	 * 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
76
	 * <ol>
77
	 * <li>http://www.biodiversitylibrary.org/item</li>
78
	 * <li>16772</li>
79
	 * </ol>
80
	 * @param uri
81
	 * @return
82
	 */
83
	private String[] splitPathAndId(URI uri) {
84
		String[] tokens = new String[2];
85
		if(uri != null){
86
			String titleUriString = uri.toString();
87
			tokens[1]  = titleUriString.substring(titleUriString.lastIndexOf('/') + 1);
88
			tokens[0]  = titleUriString.substring(0, titleUriString.lastIndexOf('/'));
89
			return tokens;
90
		} else  {
91
			return null;
92
		}
93
	}
94

    
95
	/**
96
	 * @param referenceType the referenceType to set
97
	 */
98
	public void setReferenceType(ReferenceType referenceType) {
99
		this.referenceType = referenceType;
100
	}
101

    
102
	/**
103
	 * @return the referenceType
104
	 */
105
	public ReferenceType getReferenceType() {
106
		return referenceType;
107
	}
108

    
109
	/**
110
	 * This method will construct an URI pointing to a service which creates an
111
	 * jpeg image. This may take a while. For more information please refer to
112
	 * http://biodivlib.wikispaces.com/Developer+Tools+and+API. If the width or
113
	 * height of the of the image given as parameter are null or 0 the BHL
114
	 * service will respond with the default thumbnail which seems to be cached.
115
	 * This is usually much faster than requesting for a custom imge
116
	 * size.
117
	 * <p>
118
	 *
119
	 * @param width
120
	 *            width of the image, may be null or 0
121
	 * @param height
122
	 *            height of the image, may be null or 0
123
	 * @return
124
	 */
125
	public URI getJpegImage(Integer width, Integer height){
126

    
127
		URI imageURI = null;
128
		try {
129
			String sizeStr = "";
130
			if(width != null && height != null && width > 0 && height > 0){
131
				sizeStr = "," + width + "," + height;
132
			}
133
			String[] tokens = splitPathAndId(getUri());
134
			if(tokens.length == 2){
135
				imageURI = new URI(PAGETHUMB_BASE_URI + tokens[1] + sizeStr);
136
			}
137
		} catch (URISyntaxException e) {
138
			// should never happen, but let's report it anyway
139
			logger.error(e);
140
		}
141
		return imageURI;
142
	}
143
}
(4-4/4)