Revision 370503cf
Added by Niels Hoffmann almost 13 years ago
.gitattributes | ||
---|---|---|
18 | 18 |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/TreeNode.java -text |
19 | 19 |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/UriUtils.java -text |
20 | 20 |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/XmlHelp.java -text |
21 |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/mediaMetaData/AudioMetaData.java -text |
|
22 |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/mediaMetaData/ImageMetaData.java -text |
|
23 |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/mediaMetaData/JpegImageMetaData.java -text |
|
24 |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/mediaMetaData/MediaMetaData.java -text |
|
25 |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/mediaMetaData/MetaDataFactory.java -text |
|
26 |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/mediaMetaData/MimeType.java -text |
|
27 |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/mediaMetaData/TiffImageMetaData.java -text |
|
21 |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/media/AudioInfo.java -text |
|
22 |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/media/ImageInfo.java -text |
|
23 |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/media/MediaInfo.java -text |
|
24 |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/media/MimeType.java -text |
|
28 | 25 |
cdmlib-commons/src/main/resources/MUST-EXIST.txt -text |
29 | 26 |
cdmlib-commons/src/main/resources/log4j.properties -text |
30 | 27 |
cdmlib-commons/src/test/java/eu/etaxonomy/cdm/common/CdmUtilsTest.java -text |
31 |
cdmlib-commons/src/test/java/eu/etaxonomy/cdm/common/MediaMetaDataTest.java -text |
|
32 | 28 |
cdmlib-commons/src/test/java/eu/etaxonomy/cdm/common/UriUtilsTest.java -text |
33 | 29 |
cdmlib-commons/src/test/java/eu/etaxonomy/cdm/common/UuidGenerator.java -text |
34 | 30 |
cdmlib-commons/src/test/java/eu/etaxonomy/cdm/common/XmlHelpTest.java -text |
31 |
cdmlib-commons/src/test/java/eu/etaxonomy/cdm/common/media/ImageInfoTest.java -text |
|
35 | 32 |
cdmlib-commons/src/test/java/eu/etaxonomy/cdm/test/suite/CdmTestSuite.java -text |
36 | 33 |
cdmlib-commons/src/test/java/eu/etaxonomy/cdm/test/unit/CdmUnitTestBase.java -text |
37 | 34 |
cdmlib-commons/src/test/resources/images/OregonScientificDS6639-DSC_0307-small.jpg -text |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/UriUtils.java | ||
---|---|---|
24 | 24 |
import java.util.List; |
25 | 25 |
import java.util.Map; |
26 | 26 |
|
27 |
import org.apache.http.Header; |
|
27 | 28 |
import org.apache.http.HttpException; |
28 | 29 |
import org.apache.http.HttpResponse; |
29 | 30 |
import org.apache.http.HttpStatus; |
... | ... | |
85 | 86 |
File file = new File(uri); |
86 | 87 |
return new FileInputStream(file); |
87 | 88 |
}else{ |
88 |
throw new RuntimeException("Protokoll not yet handled: " + uri.getScheme()); |
|
89 |
throw new RuntimeException("Protocol not handled yet: " + uri.getScheme()); |
|
90 |
} |
|
91 |
} |
|
92 |
|
|
93 |
/** |
|
94 |
* Retrieves the size of the resource defined by the given uri in bytes |
|
95 |
* |
|
96 |
* @param uri the resource |
|
97 |
* @param requestHeaders additional headers. May be <code>null</code> |
|
98 |
* @return the size of the resource in bytes |
|
99 |
* |
|
100 |
* @throws ClientProtocolException |
|
101 |
* @throws IOException |
|
102 |
* @throws HttpException |
|
103 |
*/ |
|
104 |
public static long getResourceLength(URI uri, Map<String, String> requestHeaders) throws ClientProtocolException, IOException, HttpException{ |
|
105 |
if(requestHeaders == null){ |
|
106 |
requestHeaders = new HashMap<String, String>(); |
|
107 |
} |
|
108 |
|
|
109 |
if (uri.getScheme().equals("http") || uri.getScheme().equals("https")){ |
|
110 |
HttpResponse response = UriUtils.getResponse(uri, requestHeaders); |
|
111 |
if(UriUtils.isOk(response)){ |
|
112 |
Header[] contentLengths = response.getHeaders("Content-Length"); |
|
113 |
|
|
114 |
if(contentLengths == null || contentLengths.length == 0){ |
|
115 |
throw new HttpException("Could not retrieve Content-Length"); |
|
116 |
} |
|
117 |
|
|
118 |
if(contentLengths.length > 1){ |
|
119 |
throw new HttpException("Multiple Conten-Length headers sent"); |
|
120 |
} |
|
121 |
|
|
122 |
Header contentLength = contentLengths[0]; |
|
123 |
String value = contentLength.getValue(); |
|
124 |
|
|
125 |
return Long.valueOf(value); |
|
126 |
|
|
127 |
} else { |
|
128 |
throw new HttpException("HTTP Reponse code is not = 200 (OK): " + UriUtils.getStatus(response)); |
|
129 |
} |
|
130 |
}else if (uri.getScheme().equals("file")){ |
|
131 |
File file = new File(uri); |
|
132 |
return file.length(); |
|
133 |
}else{ |
|
134 |
throw new RuntimeException("Protocol not handled yet: " + uri.getScheme()); |
|
89 | 135 |
} |
90 | 136 |
} |
91 | 137 |
|
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/media/AudioInfo.java | ||
---|---|---|
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.common.media; |
|
11 |
|
|
12 |
|
|
13 |
/** |
|
14 |
* @author k.luther |
|
15 |
* @date 27.11.2009 |
|
16 |
* |
|
17 |
*/ |
|
18 |
public class AudioInfo extends MediaInfo { |
|
19 |
|
|
20 |
} |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/media/ImageInfo.java | ||
---|---|---|
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.common.media; |
|
11 |
|
|
12 |
import java.io.IOException; |
|
13 |
import java.io.InputStream; |
|
14 |
import java.net.URI; |
|
15 |
import java.util.HashMap; |
|
16 |
import java.util.Map; |
|
17 |
|
|
18 |
import org.apache.http.HttpException; |
|
19 |
import org.apache.log4j.Logger; |
|
20 |
import org.apache.sanselan.ImageReadException; |
|
21 |
import org.apache.sanselan.Sanselan; |
|
22 |
import org.apache.sanselan.common.IImageMetadata; |
|
23 |
import org.apache.sanselan.common.ImageMetadata.Item; |
|
24 |
|
|
25 |
import eu.etaxonomy.cdm.common.UriUtils; |
|
26 |
|
|
27 |
|
|
28 |
/** |
|
29 |
* @author k.luther |
|
30 |
* @date 27.11.2009 |
|
31 |
* |
|
32 |
*/ |
|
33 |
public class ImageInfo extends MediaInfo { |
|
34 |
private static Logger logger = Logger.getLogger(ImageInfo.class); |
|
35 |
|
|
36 |
private int width; |
|
37 |
private int height; |
|
38 |
private int bitPerPixel; |
|
39 |
private URI imageUri; |
|
40 |
|
|
41 |
private Map<String, String> metaData; |
|
42 |
|
|
43 |
public static ImageInfo NewInstance(URI imageUri, Integer timeOut) throws IOException, HttpException { |
|
44 |
ImageInfo instance = new ImageInfo(imageUri); |
|
45 |
instance.readImageInfo(timeOut); |
|
46 |
return instance; |
|
47 |
} |
|
48 |
|
|
49 |
public static ImageInfo NewInstanceWithMetaData(URI imageUri, Integer timeOut) throws IOException, HttpException { |
|
50 |
ImageInfo instance = NewInstance(imageUri, timeOut); |
|
51 |
instance.readMetaData(timeOut); |
|
52 |
return instance; |
|
53 |
} |
|
54 |
|
|
55 |
private ImageInfo(URI imageUri){ |
|
56 |
this.imageUri = imageUri; |
|
57 |
} |
|
58 |
|
|
59 |
public URI getUri() { |
|
60 |
return imageUri; |
|
61 |
} |
|
62 |
|
|
63 |
public int getWidth() { |
|
64 |
return width; |
|
65 |
} |
|
66 |
|
|
67 |
public int getHeight() { |
|
68 |
return height; |
|
69 |
} |
|
70 |
|
|
71 |
public int getBitPerPixel() { |
|
72 |
return bitPerPixel; |
|
73 |
} |
|
74 |
|
|
75 |
public Map<String, String> getMetaData(){ |
|
76 |
return metaData; |
|
77 |
} |
|
78 |
|
|
79 |
@Override |
|
80 |
public String toString(){ |
|
81 |
return getFormatName() + " [" + getMimeType()+ "] w:" + width + " h:" + height + " depth:" + bitPerPixel; |
|
82 |
} |
|
83 |
|
|
84 |
private void readImageInfo(Integer timeOut) throws IOException, HttpException{ |
|
85 |
|
|
86 |
InputStream inputStream; |
|
87 |
try { |
|
88 |
|
|
89 |
long length = UriUtils.getResourceLength(imageUri, null); |
|
90 |
|
|
91 |
inputStream = UriUtils.getInputStream(imageUri); |
|
92 |
org.apache.sanselan.ImageInfo imageInfo = Sanselan.getImageInfo(inputStream, null); |
|
93 |
|
|
94 |
setLength(length); |
|
95 |
setFormatName(imageInfo.getFormatName()); |
|
96 |
setMimeType(imageInfo.getMimeType()); |
|
97 |
width = imageInfo.getWidth(); |
|
98 |
height = imageInfo.getHeight(); |
|
99 |
bitPerPixel = imageInfo.getBitsPerPixel(); |
|
100 |
|
|
101 |
} catch (ImageReadException e) { |
|
102 |
logger.error("Could not read: " + imageUri + ". " + e.getMessage()); |
|
103 |
throw new IOException(e); |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
|
|
108 |
public Map<String, String> readMetaData(Integer timeOut) throws IOException, HttpException { |
|
109 |
|
|
110 |
try { |
|
111 |
InputStream inputStream = UriUtils.getInputStream(imageUri); |
|
112 |
|
|
113 |
IImageMetadata mediaData; |
|
114 |
mediaData = Sanselan.getMetadata(inputStream, null); |
|
115 |
|
|
116 |
if (mediaData != null){ |
|
117 |
metaData = new HashMap<String, String>(); |
|
118 |
for (Object object : mediaData.getItems()){ |
|
119 |
Item item = (Item) object; |
|
120 |
if (item.getKeyword().contains("/")){ |
|
121 |
String key = item.getKeyword(); |
|
122 |
//key.replace("/", ""); |
|
123 |
int index = key.indexOf("/"); |
|
124 |
key = key.substring(0, index); |
|
125 |
metaData.put(key, item.getText()); |
|
126 |
}else{ |
|
127 |
metaData.put(item.getKeyword(), item.getText()); |
|
128 |
} |
|
129 |
} |
|
130 |
} |
|
131 |
} catch (ImageReadException e) { |
|
132 |
logger.error("Could not read: " + imageUri + ". " + e.getMessage()); |
|
133 |
throw new IOException(e); |
|
134 |
} |
|
135 |
return metaData; |
|
136 |
} |
|
137 |
|
|
138 |
} |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/media/MediaInfo.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 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 |
|
|
11 |
package eu.etaxonomy.cdm.common.media; |
|
12 |
|
|
13 |
import org.apache.log4j.Logger; |
|
14 |
|
|
15 |
/** |
|
16 |
* |
|
17 |
* @author n.hoffmann |
|
18 |
* @created 13.11.2008 |
|
19 |
* @version 1.0 |
|
20 |
*/ |
|
21 |
public abstract class MediaInfo { |
|
22 |
private static Logger logger = Logger.getLogger(MediaInfo.class); |
|
23 |
private String formatName; |
|
24 |
private String mimeType; |
|
25 |
private long length; |
|
26 |
|
|
27 |
|
|
28 |
public void setMimeType(String mimeType) { |
|
29 |
this.mimeType = mimeType; |
|
30 |
} |
|
31 |
|
|
32 |
public String getMimeType() { |
|
33 |
return mimeType; |
|
34 |
} |
|
35 |
|
|
36 |
public void setFormatName(String formatName) { |
|
37 |
this.formatName = formatName; |
|
38 |
} |
|
39 |
|
|
40 |
public String getFormatName() { |
|
41 |
return formatName; |
|
42 |
} |
|
43 |
|
|
44 |
public void setLength(long length) { |
|
45 |
this.length = length; |
|
46 |
} |
|
47 |
|
|
48 |
public long getLength() { |
|
49 |
return length; |
|
50 |
} |
|
51 |
|
|
52 |
} |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/media/MimeType.java | ||
---|---|---|
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.common.media; |
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
/** |
|
15 |
* @author a.kohlbecker |
|
16 |
* @date 27.11.2009 |
|
17 |
* |
|
18 |
*/ |
|
19 |
public enum MimeType { |
|
20 |
TIFF ("image/tiff"), |
|
21 |
JPEG ("image/jpeg"), |
|
22 |
IMAGE ("image"), |
|
23 |
UNKNOWN ("unknown"), |
|
24 |
PNG ("image/png"); |
|
25 |
|
|
26 |
private final String mimeType; |
|
27 |
|
|
28 |
MimeType(String mimeType){ |
|
29 |
this.mimeType = mimeType; |
|
30 |
} |
|
31 |
public String getMimeType(){ |
|
32 |
return mimeType; |
|
33 |
} |
|
34 |
} |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/mediaMetaData/AudioMetaData.java | ||
---|---|---|
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.common.mediaMetaData; |
|
11 |
|
|
12 |
import java.net.URI; |
|
13 |
|
|
14 |
/** |
|
15 |
* @author k.luther |
|
16 |
* @date 27.11.2009 |
|
17 |
* |
|
18 |
*/ |
|
19 |
public class AudioMetaData extends MediaMetaData { |
|
20 |
|
|
21 |
@Override |
|
22 |
public void readMetaData(URI imageUri, Integer timeOut) { |
|
23 |
// TODO Auto-generated method stub |
|
24 |
|
|
25 |
} |
|
26 |
|
|
27 |
} |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/mediaMetaData/ImageMetaData.java | ||
---|---|---|
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.common.mediaMetaData; |
|
11 |
|
|
12 |
import java.io.File; |
|
13 |
import java.io.IOException; |
|
14 |
import java.io.InputStream; |
|
15 |
import java.net.URI; |
|
16 |
import java.util.HashMap; |
|
17 |
|
|
18 |
import org.apache.http.HttpException; |
|
19 |
import org.apache.log4j.Logger; |
|
20 |
import org.apache.sanselan.ImageInfo; |
|
21 |
import org.apache.sanselan.ImageReadException; |
|
22 |
import org.apache.sanselan.Sanselan; |
|
23 |
import org.apache.sanselan.common.IImageMetadata; |
|
24 |
import org.apache.sanselan.common.ImageMetadata.Item; |
|
25 |
|
|
26 |
import eu.etaxonomy.cdm.common.UriUtils; |
|
27 |
|
|
28 |
|
|
29 |
/** |
|
30 |
* @author k.luther |
|
31 |
* @date 27.11.2009 |
|
32 |
* |
|
33 |
*/ |
|
34 |
public class ImageMetaData extends MediaMetaData { |
|
35 |
private static Logger logger = Logger.getLogger(ImageMetaData.class); |
|
36 |
|
|
37 |
protected ImageMetaData(){ |
|
38 |
this.metaData = new HashMap<String, String>(); |
|
39 |
} |
|
40 |
|
|
41 |
protected int width, height, bitPerPixel; |
|
42 |
|
|
43 |
public int getWidth() { |
|
44 |
return width; |
|
45 |
} |
|
46 |
|
|
47 |
public void setWidth(int width) { |
|
48 |
this.width = width; |
|
49 |
} |
|
50 |
|
|
51 |
public int getHeight() { |
|
52 |
return height; |
|
53 |
} |
|
54 |
|
|
55 |
public void setHeight(int height) { |
|
56 |
this.height = height; |
|
57 |
} |
|
58 |
|
|
59 |
public int getBitPerPixel() { |
|
60 |
return bitPerPixel; |
|
61 |
} |
|
62 |
|
|
63 |
public void setBitPerPixel(int bitPerPixel) { |
|
64 |
this.bitPerPixel = bitPerPixel; |
|
65 |
} |
|
66 |
|
|
67 |
public String getFormatName() { |
|
68 |
return formatName; |
|
69 |
} |
|
70 |
|
|
71 |
public void setFormatName(String formatName) { |
|
72 |
this.formatName = formatName; |
|
73 |
} |
|
74 |
|
|
75 |
public String getMimeType() { |
|
76 |
return mimeType; |
|
77 |
} |
|
78 |
|
|
79 |
public void setMimeType(String mimeType) { |
|
80 |
this.mimeType = mimeType; |
|
81 |
} |
|
82 |
|
|
83 |
@Override |
|
84 |
public String toString(){ |
|
85 |
return formatName + " [" + mimeType+ "] w:" + width + " h:" + height + " depth:" + bitPerPixel; |
|
86 |
} |
|
87 |
|
|
88 |
|
|
89 |
private void readImageInfo(ImageInfo imageInfo) { |
|
90 |
this.formatName = imageInfo.getFormatName(); |
|
91 |
this.mimeType = imageInfo.getMimeType(); |
|
92 |
this.width = imageInfo.getWidth(); |
|
93 |
this.height = imageInfo.getHeight(); |
|
94 |
this.bitPerPixel = imageInfo.getBitsPerPixel(); |
|
95 |
|
|
96 |
} |
|
97 |
|
|
98 |
|
|
99 |
public void readImageInfo(URI imageUri, Integer timeOut) throws IOException, HttpException{ |
|
100 |
|
|
101 |
File image = null; |
|
102 |
InputStream inputStream; |
|
103 |
try { |
|
104 |
|
|
105 |
inputStream = UriUtils.getInputStream(imageUri); |
|
106 |
|
|
107 |
ImageInfo imageInfo = Sanselan.getImageInfo(inputStream, null); |
|
108 |
|
|
109 |
|
|
110 |
readImageInfo(imageInfo); |
|
111 |
|
|
112 |
} catch (IOException e) { |
|
113 |
logger.warn("Could not read: "+ imageUri.toString() + "; reason: "+e.getMessage()); |
|
114 |
throw e; |
|
115 |
} catch (HttpException e) { |
|
116 |
logger.warn("Could not open url: "+ imageUri.toString() + "; reason: "+e.getMessage()); |
|
117 |
throw e; |
|
118 |
} catch (ImageReadException e) { |
|
119 |
logger.error("Could not open url: " + imageUri + ". " + e.getMessage()); |
|
120 |
throw new IOException(e); |
|
121 |
} |
|
122 |
|
|
123 |
} |
|
124 |
|
|
125 |
|
|
126 |
public void readMetaData(URI mediaUri, Integer timeOut) throws IOException, HttpException { |
|
127 |
readImageInfo(mediaUri, timeOut); |
|
128 |
try { |
|
129 |
InputStream inputStream = UriUtils.getInputStream(mediaUri); |
|
130 |
|
|
131 |
IImageMetadata mediaData = Sanselan.getMetadata(inputStream, null); |
|
132 |
|
|
133 |
if (mediaData != null){ |
|
134 |
for (Object object : mediaData.getItems()){ |
|
135 |
Item item = (Item) object; |
|
136 |
if (item.getKeyword().contains("/")){ |
|
137 |
String key = item.getKeyword(); |
|
138 |
//key.replace("/", ""); |
|
139 |
int index = key.indexOf("/"); |
|
140 |
key = key.substring(0, index); |
|
141 |
metaData.put(key, item.getText()); |
|
142 |
|
|
143 |
}else{ |
|
144 |
metaData.put(item.getKeyword(), item.getText()); |
|
145 |
|
|
146 |
} |
|
147 |
|
|
148 |
} |
|
149 |
} |
|
150 |
} catch (ImageReadException e) { |
|
151 |
logger.warn(e.getLocalizedMessage()); |
|
152 |
throw new IOException(e); |
|
153 |
} catch (IOException e) { |
|
154 |
logger.warn("The image server is not available!"); |
|
155 |
throw e; |
|
156 |
} |
|
157 |
|
|
158 |
} |
|
159 |
|
|
160 |
public static ImageMetaData newInstance() { |
|
161 |
|
|
162 |
return new ImageMetaData(); |
|
163 |
} |
|
164 |
|
|
165 |
} |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/mediaMetaData/JpegImageMetaData.java | ||
---|---|---|
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.common.mediaMetaData; |
|
11 |
|
|
12 |
import java.io.File; |
|
13 |
import java.io.FileOutputStream; |
|
14 |
import java.io.IOException; |
|
15 |
import java.io.InputStream; |
|
16 |
import java.io.OutputStream; |
|
17 |
import java.net.URI; |
|
18 |
import java.net.URL; |
|
19 |
import java.net.URLConnection; |
|
20 |
import java.util.HashMap; |
|
21 |
|
|
22 |
import org.apache.log4j.Logger; |
|
23 |
import org.apache.sanselan.ImageReadException; |
|
24 |
import org.apache.sanselan.Sanselan; |
|
25 |
import org.apache.sanselan.common.IImageMetadata; |
|
26 |
import org.apache.sanselan.common.ImageMetadata.Item; |
|
27 |
import org.apache.sanselan.formats.jpeg.JpegImageMetadata; |
|
28 |
|
|
29 |
/** |
|
30 |
* @author k.luther |
|
31 |
* @date 27.11.2009 |
|
32 |
* |
|
33 |
*/ |
|
34 |
public class JpegImageMetaData extends ImageMetaData { |
|
35 |
private static Logger logger = Logger.getLogger(JpegImageMetaData.class); |
|
36 |
|
|
37 |
|
|
38 |
public static JpegImageMetaData newInstance(){ |
|
39 |
return new JpegImageMetaData(); |
|
40 |
} |
|
41 |
|
|
42 |
/*public void readImageMetaData (URI imageURI, Integer){ |
|
43 |
|
|
44 |
IImageMetadata mediaData = null; |
|
45 |
File imageFile = null; |
|
46 |
readImageInfo(imageURI); |
|
47 |
try { |
|
48 |
InputStream inputStream; |
|
49 |
URL imageUrl = imageURI.toURL(); |
|
50 |
|
|
51 |
URLConnection connection = imageUrl.openConnection(); |
|
52 |
inputStream = connection.getInputStream(); |
|
53 |
mediaData = Sanselan.getMetadata(inputStream, null); |
|
54 |
|
|
55 |
|
|
56 |
} catch (ImageReadException e) { |
|
57 |
logger.error(e); |
|
58 |
} catch (IOException e) { |
|
59 |
logger.error(e); |
|
60 |
} |
|
61 |
|
|
62 |
if(mediaData instanceof JpegImageMetadata){ |
|
63 |
JpegImageMetadata jpegMetadata = (JpegImageMetadata) mediaData; |
|
64 |
|
|
65 |
|
|
66 |
int counter = 0; |
|
67 |
for (Object object : jpegMetadata.getItems()){ |
|
68 |
Item item = (Item) object; |
|
69 |
|
|
70 |
//logger.debug("File: " + imageFile.getName() + ". "+ item.getKeyword() +" string is: " + item.getText()); |
|
71 |
if (item.getKeyword().contains("/")){ |
|
72 |
String key = item.getKeyword(); |
|
73 |
//key.replace("/", ""); |
|
74 |
int index = key.indexOf("/"); |
|
75 |
key = key.substring(0, index); |
|
76 |
metaData.put(key, item.getText()); |
|
77 |
|
|
78 |
}else{ |
|
79 |
metaData.put(item.getKeyword(), item.getText()); |
|
80 |
|
|
81 |
} |
|
82 |
} |
|
83 |
}else{ |
|
84 |
logger.error("The mimetype is not jpeg"); |
|
85 |
} |
|
86 |
|
|
87 |
|
|
88 |
}*/ |
|
89 |
|
|
90 |
} |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/mediaMetaData/MediaMetaData.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 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 |
|
|
11 |
package eu.etaxonomy.cdm.common.mediaMetaData; |
|
12 |
|
|
13 |
import java.io.IOException; |
|
14 |
import java.net.URI; |
|
15 |
import java.util.HashMap; |
|
16 |
import java.util.Map; |
|
17 |
|
|
18 |
import org.apache.http.HttpException; |
|
19 |
import org.apache.log4j.Logger; |
|
20 |
import org.apache.sanselan.ImageReadException; |
|
21 |
|
|
22 |
/** |
|
23 |
* |
|
24 |
* @author n.hoffmann |
|
25 |
* @created 13.11.2008 |
|
26 |
* @version 1.0 |
|
27 |
*/ |
|
28 |
public abstract class MediaMetaData { |
|
29 |
private static Logger logger = Logger.getLogger(MediaMetaData.class); |
|
30 |
protected String formatName, mimeType; |
|
31 |
HashMap<String, String> metaData; |
|
32 |
|
|
33 |
|
|
34 |
public abstract void readMetaData(URI mediaUri, Integer timeOut) throws IOException, HttpException; |
|
35 |
|
|
36 |
public Map<String, String> getMetaData() { |
|
37 |
|
|
38 |
return metaData; |
|
39 |
} |
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
} |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/mediaMetaData/MetaDataFactory.java | ||
---|---|---|
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.common.mediaMetaData; |
|
11 |
|
|
12 |
import java.io.IOException; |
|
13 |
import java.net.URI; |
|
14 |
|
|
15 |
import org.apache.http.HttpException; |
|
16 |
import org.apache.sanselan.ImageReadException; |
|
17 |
|
|
18 |
|
|
19 |
/** |
|
20 |
* @author k.luther |
|
21 |
* @date 27.11.2009 |
|
22 |
* |
|
23 |
*/ |
|
24 |
public final class MetaDataFactory { |
|
25 |
|
|
26 |
private static MetaDataFactory instance; |
|
27 |
|
|
28 |
private MetaDataFactory(){ |
|
29 |
|
|
30 |
} |
|
31 |
public synchronized static MetaDataFactory getInstance() { |
|
32 |
if (instance == null) { |
|
33 |
instance = new MetaDataFactory(); |
|
34 |
} |
|
35 |
return instance; |
|
36 |
} |
|
37 |
public MediaMetaData readMediaData(URI uri, MimeType mimetype, Integer timeOut) throws IOException, HttpException{ |
|
38 |
//MediaMetaData metaData = MediaMetaData.newInstance(); |
|
39 |
//MimeType mimeType = metaData.readMediaInfo(uri); |
|
40 |
switch (mimetype){ |
|
41 |
case JPEG: |
|
42 |
JpegImageMetaData jpegMediaMetaData = JpegImageMetaData.newInstance(); |
|
43 |
jpegMediaMetaData.readMetaData(uri, timeOut); |
|
44 |
((ImageMetaData)jpegMediaMetaData).readImageInfo(uri, timeOut); |
|
45 |
return jpegMediaMetaData; |
|
46 |
case TIFF: |
|
47 |
TiffImageMetaData tiffMetaData = TiffImageMetaData.newInstance(); |
|
48 |
tiffMetaData.readMetaData(uri, timeOut); |
|
49 |
((ImageMetaData)tiffMetaData).readImageInfo(uri, timeOut); |
|
50 |
return tiffMetaData; |
|
51 |
case IMAGE: |
|
52 |
ImageMetaData imageMetaData = ImageMetaData.newInstance(); |
|
53 |
imageMetaData.readImageInfo(uri, timeOut); |
|
54 |
if (imageMetaData.mimeType.equals(MimeType.JPEG.getMimeType())){ |
|
55 |
JpegImageMetaData jpegMediaMetaData2 = JpegImageMetaData.newInstance(); |
|
56 |
jpegMediaMetaData2.readMetaData(uri, timeOut); |
|
57 |
return jpegMediaMetaData2; |
|
58 |
}else if (imageMetaData.mimeType.equals(MimeType.TIFF.getMimeType())){ |
|
59 |
TiffImageMetaData tiffMetaData2 = TiffImageMetaData.newInstance(); |
|
60 |
tiffMetaData2.readMetaData(uri, timeOut); |
|
61 |
((ImageMetaData)tiffMetaData2).readImageInfo(uri, timeOut); |
|
62 |
return tiffMetaData2; |
|
63 |
} else { |
|
64 |
return imageMetaData; |
|
65 |
} |
|
66 |
default: |
|
67 |
break; |
|
68 |
} |
|
69 |
return null; |
|
70 |
|
|
71 |
|
|
72 |
} |
|
73 |
} |
|
74 |
|
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/mediaMetaData/MimeType.java | ||
---|---|---|
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.common.mediaMetaData; |
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
/** |
|
15 |
* @author a.kohlbecker |
|
16 |
* @date 27.11.2009 |
|
17 |
* |
|
18 |
*/ |
|
19 |
public enum MimeType { |
|
20 |
TIFF ("image/tiff"), |
|
21 |
JPEG ("image/jpeg"), |
|
22 |
IMAGE ("image"), |
|
23 |
UNKNOWN ("unknown"); |
|
24 |
|
|
25 |
private final String mimeType; |
|
26 |
|
|
27 |
MimeType(String mimeType){ |
|
28 |
this.mimeType = mimeType; |
|
29 |
} |
|
30 |
public String getMimeType(){ |
|
31 |
return mimeType; |
|
32 |
} |
|
33 |
|
|
34 |
} |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/mediaMetaData/TiffImageMetaData.java | ||
---|---|---|
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.common.mediaMetaData; |
|
11 |
|
|
12 |
import java.io.File; |
|
13 |
import java.io.IOException; |
|
14 |
import java.io.InputStream; |
|
15 |
import java.net.URI; |
|
16 |
import java.net.URL; |
|
17 |
import java.net.URLConnection; |
|
18 |
|
|
19 |
import org.apache.log4j.Logger; |
|
20 |
import org.apache.sanselan.ImageReadException; |
|
21 |
import org.apache.sanselan.Sanselan; |
|
22 |
import org.apache.sanselan.common.IImageMetadata; |
|
23 |
import org.apache.sanselan.common.ImageMetadata.Item; |
|
24 |
|
|
25 |
import org.apache.sanselan.formats.tiff.TiffImageMetadata; |
|
26 |
|
|
27 |
/** |
|
28 |
* @author k.luther |
|
29 |
* @date 27.11.2009 |
|
30 |
* |
|
31 |
*/ |
|
32 |
public class TiffImageMetaData extends ImageMetaData { |
|
33 |
private static Logger logger = Logger.getLogger(TiffImageMetaData.class); |
|
34 |
|
|
35 |
/*public void readImageMetaData(URI imageURI){ |
|
36 |
IImageMetadata mediaData = null; |
|
37 |
File imageFile = null; |
|
38 |
readImageInfo(imageURI); |
|
39 |
try { |
|
40 |
InputStream inputStream; |
|
41 |
URL imageUrl = imageURI.toURL(); |
|
42 |
|
|
43 |
URLConnection connection = imageUrl.openConnection(); |
|
44 |
inputStream = connection.getInputStream(); |
|
45 |
mediaData = Sanselan.getMetadata(inputStream, null); |
|
46 |
|
|
47 |
|
|
48 |
} catch (ImageReadException e) { |
|
49 |
logger.error(e); |
|
50 |
} catch (IOException e) { |
|
51 |
logger.error(e); |
|
52 |
} |
|
53 |
if(mediaData instanceof TiffImageMetadata){ |
|
54 |
TiffImageMetadata jpegMetadata = (TiffImageMetadata) mediaData; |
|
55 |
for (Object object : jpegMetadata.getItems()){ |
|
56 |
Item item = (Item) object; |
|
57 |
|
|
58 |
//logger.debug("File: " + imageFile.getName() + ". "+ item.getKeyword() +"string is: " + item.getText()); |
|
59 |
metaData.put(item.getKeyword(), item.getText()); |
|
60 |
|
|
61 |
} |
|
62 |
}else{ |
|
63 |
logger.error("The mimetype is not tiff"); |
|
64 |
} |
|
65 |
|
|
66 |
|
|
67 |
}*/ |
|
68 |
|
|
69 |
public static TiffImageMetaData newInstance() { |
|
70 |
|
|
71 |
return new TiffImageMetaData(); |
|
72 |
} |
|
73 |
|
|
74 |
|
|
75 |
} |
cdmlib-commons/src/test/java/eu/etaxonomy/cdm/common/MediaMetaDataTest.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 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 |
|
|
11 |
package eu.etaxonomy.cdm.common; |
|
12 |
|
|
13 |
|
|
14 |
import java.io.File; |
|
15 |
import java.io.IOException; |
|
16 |
import java.net.MalformedURLException; |
|
17 |
import java.net.URI; |
|
18 |
import java.net.URL; |
|
19 |
|
|
20 |
import org.apache.http.HttpException; |
|
21 |
import org.apache.log4j.Logger; |
|
22 |
import org.junit.After; |
|
23 |
import org.junit.AfterClass; |
|
24 |
import org.junit.Assert; |
|
25 |
import org.junit.Before; |
|
26 |
import org.junit.BeforeClass; |
|
27 |
import org.junit.Test; |
|
28 |
|
|
29 |
import eu.etaxonomy.cdm.common.mediaMetaData.ImageMetaData; |
|
30 |
import eu.etaxonomy.cdm.common.mediaMetaData.MetaDataFactory; |
|
31 |
import eu.etaxonomy.cdm.common.mediaMetaData.MimeType; |
|
32 |
|
|
33 |
/** |
|
34 |
* @author n.hoffmann |
|
35 |
* @created 13.11.2008 |
|
36 |
* @version 1.0 |
|
37 |
*/ |
|
38 |
public class MediaMetaDataTest { |
|
39 |
private static final Logger logger = Logger.getLogger(MediaMetaDataTest.class); |
|
40 |
|
|
41 |
/** |
|
42 |
* @throws java.lang.Exception |
|
43 |
*/ |
|
44 |
@BeforeClass |
|
45 |
public static void setUpBeforeClass() throws Exception { |
|
46 |
if (logger.isDebugEnabled()){logger.debug("setUpBeforeClass");} |
|
47 |
} |
|
48 |
|
|
49 |
/** |
|
50 |
* @throws java.lang.Exception |
|
51 |
*/ |
|
52 |
@AfterClass |
|
53 |
public static void tearDownAfterClass() throws Exception { |
|
54 |
} |
|
55 |
|
|
56 |
/** |
|
57 |
* @throws java.lang.Exception |
|
58 |
*/ |
|
59 |
@Before |
|
60 |
public void setUp() throws Exception { |
|
61 |
} |
|
62 |
|
|
63 |
/** |
|
64 |
* @throws java.lang.Exception |
|
65 |
*/ |
|
66 |
@After |
|
67 |
public void tearDown() throws Exception { |
|
68 |
} |
|
69 |
|
|
70 |
/********************* TESTS |
|
71 |
* @throws IOException |
|
72 |
* @throws HttpException ********************/ |
|
73 |
|
|
74 |
@Test |
|
75 |
public void readImageInfoFromFile() throws IOException, HttpException { |
|
76 |
File imageFile = new File("./src/test/resources/images/OregonScientificDS6639-DSC_0307-small.jpg"); |
|
77 |
MetaDataFactory metaFactory = MetaDataFactory.getInstance(); |
|
78 |
ImageMetaData imageMetaData = (ImageMetaData) metaFactory.readMediaData(imageFile.toURI(), MimeType.JPEG, 0); |
|
79 |
//imageMetaData.readFrom(imageFile); |
|
80 |
|
|
81 |
assertImageInfo(imageMetaData); |
|
82 |
imageFile = new File("./src/test/resources/images/OregonScientificDS6639-DSC_0307-small.tif"); |
|
83 |
|
|
84 |
imageMetaData = (ImageMetaData) metaFactory.readMediaData(imageFile.toURI(), MimeType.IMAGE, 0); |
|
85 |
assertTiffInfo(imageMetaData); |
|
86 |
} |
|
87 |
|
|
88 |
@Test |
|
89 |
public void readImageInfoFromUrl() throws IOException, HttpException { |
|
90 |
try { |
|
91 |
|
|
92 |
//TODO make ready for windows |
|
93 |
//URL imageUrl = new URL("file://" + new File("").getAbsolutePath()+ "/src/test/resources/images/OregonScientificDS6639-DSC_0307-small.jpg"); |
|
94 |
URL imageUrl = new URL("http://wp5.e-taxonomy.eu/media/palmae/photos/palm_tc_100447_6.jpg"); |
|
95 |
MetaDataFactory metaFactory = MetaDataFactory.getInstance(); |
|
96 |
ImageMetaData imageMetaData; |
|
97 |
|
|
98 |
try { |
|
99 |
imageMetaData = (ImageMetaData) metaFactory.readMediaData(CdmUtils.string2Uri(imageUrl.toString()), MimeType.JPEG, 30000); |
|
100 |
//imageMetaData.readImageMetaData(imageUrl); |
|
101 |
|
|
102 |
Assert.assertNotNull(imageMetaData); |
|
103 |
} catch (Exception e) { |
|
104 |
if (UriUtils.isInternetAvailable(URI.create(imageUrl.toString()))){ |
|
105 |
Assert.fail("Exception when reading media meta data though internet is available"); |
|
106 |
}else{ |
|
107 |
logger.warn("Internet not available. Can't test reading image meta data"); |
|
108 |
} |
|
109 |
} |
|
110 |
|
|
111 |
|
|
112 |
} catch (MalformedURLException e) { |
|
113 |
e.printStackTrace(); |
|
114 |
} |
|
115 |
} |
|
116 |
|
|
117 |
private void assertImageInfo (ImageMetaData imageMetaData){ |
|
118 |
Assert.assertEquals(24, imageMetaData.getBitPerPixel()); |
|
119 |
Assert.assertEquals("JPEG (Joint Photographic Experts Group) Format", imageMetaData.getFormatName()); |
|
120 |
Assert.assertEquals(300, imageMetaData.getWidth()); |
|
121 |
Assert.assertEquals(225, imageMetaData.getHeight()); |
|
122 |
Assert.assertEquals("image/jpeg", imageMetaData.getMimeType()); |
|
123 |
|
|
124 |
} |
|
125 |
|
|
126 |
private void assertTiffInfo (ImageMetaData imageMetaData){ |
|
127 |
|
|
128 |
Assert.assertEquals(24, imageMetaData.getBitPerPixel()); |
|
129 |
Assert.assertEquals("TIFF Tag-based Image File Format", imageMetaData.getFormatName()); |
|
130 |
Assert.assertEquals(300, imageMetaData.getWidth()); |
|
131 |
Assert.assertEquals(225, imageMetaData.getHeight()); |
|
132 |
Assert.assertEquals("image/tiff", imageMetaData.getMimeType()); |
|
133 |
} |
|
134 |
} |
cdmlib-commons/src/test/java/eu/etaxonomy/cdm/common/UriUtilsTest.java | ||
---|---|---|
1 | 1 |
package eu.etaxonomy.cdm.common; |
2 | 2 |
|
3 |
import static org.junit.Assert.*; |
|
4 |
|
|
3 |
import java.io.IOException; |
|
5 | 4 |
import java.net.MalformedURLException; |
6 | 5 |
import java.net.URI; |
7 | 6 |
import java.net.URISyntaxException; |
... | ... | |
11 | 10 |
|
12 | 11 |
import junit.framework.Assert; |
13 | 12 |
|
13 |
import org.apache.http.HttpException; |
|
14 | 14 |
import org.apache.http.NameValuePair; |
15 |
import org.apache.http.client.ClientProtocolException; |
|
15 | 16 |
import org.apache.http.message.BasicNameValuePair; |
16 | 17 |
import org.apache.log4j.Logger; |
17 | 18 |
import org.junit.Before; |
... | ... | |
54 | 55 |
} |
55 | 56 |
} |
56 | 57 |
|
58 |
@Test |
|
59 |
public void testGetResourceLength() throws ClientProtocolException, IOException, HttpException{ |
|
60 |
URI uri = URI.create("http://dev.e-taxonomy.eu/trac_htdocs/logo_edit.png"); |
|
61 |
Assert.assertEquals(9143, UriUtils.getResourceLength(uri, null)); |
|
62 |
} |
|
63 |
|
|
57 | 64 |
@Test |
58 | 65 |
public void testIsInternetAvailable() { |
59 | 66 |
URI firstUri = URI.create("http://www.gmx.de/"); |
cdmlib-commons/src/test/java/eu/etaxonomy/cdm/common/media/ImageInfoTest.java | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
*/ |
|
4 |
package eu.etaxonomy.cdm.common.media; |
|
5 |
|
|
6 |
import static org.junit.Assert.fail; |
|
7 |
|
|
8 |
import java.io.IOException; |
|
9 |
import java.net.URI; |
|
10 |
import java.net.URL; |
|
11 |
import java.util.Map; |
|
12 |
|
|
13 |
import org.apache.http.HttpException; |
|
14 |
import org.junit.Assert; |
|
15 |
import org.junit.Before; |
|
16 |
import org.junit.Test; |
|
17 |
|
|
18 |
import eu.etaxonomy.cdm.common.UriUtils; |
|
19 |
import eu.etaxonomy.cdm.common.media.ImageInfo; |
|
20 |
import eu.etaxonomy.cdm.common.media.MimeType; |
|
21 |
|
|
22 |
/** |
|
23 |
* @author n.hoffmann |
|
24 |
* |
|
25 |
*/ |
|
26 |
public class ImageInfoTest { |
|
27 |
|
|
28 |
private URI jpegUri; |
|
29 |
private URI tiffUri; |
|
30 |
private ImageInfo jpegInstance; |
|
31 |
private ImageInfo tifInstance; |
|
32 |
|
|
33 |
private URI remotePngUri; |
|
34 |
private ImageInfo pngInstance; |
|
35 |
|
|
36 |
/** |
|
37 |
* @throws java.lang.Exception |
|
38 |
*/ |
|
39 |
@Before |
|
40 |
public void setUp() throws Exception { |
|
41 |
URL jpegUrl = ImageInfoTest.class.getResource("/images/OregonScientificDS6639-DSC_0307-small.jpg"); |
|
42 |
jpegUri = jpegUrl.toURI(); |
|
43 |
|
|
44 |
URL tiffUrl = ImageInfoTest.class.getResource("/images/OregonScientificDS6639-DSC_0307-small.tif"); |
|
45 |
tiffUri = tiffUrl.toURI(); |
|
46 |
|
|
47 |
remotePngUri = URI.create("http://dev.e-taxonomy.eu/trac_htdocs/logo_edit.png"); |
|
48 |
} |
|
49 |
|
|
50 |
@Test |
|
51 |
public void testNewInstanceJpeg(){ |
|
52 |
try { |
|
53 |
ImageInfo.NewInstance(jpegUri, 0); |
|
54 |
} catch (Exception e) { |
|
55 |
fail("NewInstance method should not throw exceptions for existing uncorrupted images."); |
|
56 |
} |
|
57 |
} |
|
58 |
|
|
59 |
@Test |
|
60 |
public void testNewInstanceTiff() { |
|
61 |
try { |
|
62 |
ImageInfo.NewInstance(tiffUri, 0); |
|
63 |
} catch (Exception e) { |
|
64 |
fail("NewInstance method should not throw exceptions for existing uncorrupted images."); |
|
65 |
} |
|
66 |
} |
|
67 |
|
|
68 |
@Test |
|
69 |
public void testNewInstanceRemotePng() { |
|
70 |
try { |
|
71 |
ImageInfo.NewInstance(remotePngUri, 3000); |
|
72 |
} catch (Exception e) { |
|
73 |
fail("NewInstance method should not throw exceptions for existing uncorrupted images."); |
|
74 |
} |
|
75 |
} |
|
76 |
|
|
77 |
@Test(expected=IOException.class) |
|
78 |
public void testNewInstanceFileDoesNotExist() throws HttpException, IOException { |
|
79 |
URI nonExistentUri = URI.create("file:///nonExistentImage.jpg"); |
|
80 |
|
|
81 |
ImageInfo.NewInstance(nonExistentUri, 0); |
|
82 |
} |
|
83 |
|
|
84 |
private ImageInfo getJpegInstance(){ |
|
85 |
if(jpegInstance == null){ |
|
86 |
try { |
|
87 |
jpegInstance = ImageInfo.NewInstance(jpegUri, 0); |
|
88 |
} catch (Exception e) { |
|
89 |
fail("This case should have been covered by other tests."); |
|
90 |
return null; |
|
91 |
} |
|
92 |
} |
|
93 |
return jpegInstance; |
|
94 |
} |
|
95 |
|
|
96 |
private ImageInfo getTifInstance(){ |
|
97 |
if(tifInstance == null){ |
|
98 |
try { |
|
99 |
tifInstance = ImageInfo.NewInstance(tiffUri, 0); |
|
100 |
} catch (Exception e) { |
|
101 |
fail("This case should have been covered by other tests."); |
|
102 |
return null; |
|
103 |
} |
|
104 |
} |
|
105 |
return tifInstance; |
|
106 |
} |
|
107 |
|
|
108 |
private ImageInfo getRemotePngInstance(){ |
|
109 |
if(pngInstance == null){ |
|
110 |
try { |
|
111 |
pngInstance = ImageInfo.NewInstance(remotePngUri, 3000); |
|
112 |
} catch (Exception e) { |
|
113 |
fail("This case should have been covered by other tests."); |
|
114 |
return null; |
|
115 |
} |
|
116 |
} |
|
117 |
return pngInstance; |
|
118 |
} |
|
119 |
|
|
120 |
/** |
|
121 |
* Test method for {@link eu.etaxonomy.cdm.common.media.ImageInfo#getWidth()}. |
|
122 |
*/ |
|
123 |
@Test |
|
124 |
public void testGetWidth() { |
|
125 |
Assert.assertEquals(300, getJpegInstance().getWidth()); |
|
126 |
Assert.assertEquals(300, getTifInstance().getWidth()); |
|
127 |
|
|
128 |
if(UriUtils.isInternetAvailable(remotePngUri)){ |
|
129 |
Assert.assertEquals(93, getRemotePngInstance().getWidth()); |
|
130 |
} |
|
131 |
} |
|
132 |
|
|
133 |
/** |
|
134 |
* Test method for {@link eu.etaxonomy.cdm.common.media.ImageInfo#getHeight()}. |
|
135 |
*/ |
|
136 |
@Test |
|
137 |
public void testGetHeight() { |
|
138 |
Assert.assertEquals(225, getJpegInstance().getHeight()); |
|
139 |
Assert.assertEquals(225, getTifInstance().getHeight()); |
|
140 |
|
|
141 |
if(UriUtils.isInternetAvailable(remotePngUri)){ |
|
142 |
Assert.assertEquals(93, getRemotePngInstance().getHeight()); |
|
143 |
} |
|
144 |
} |
|
145 |
|
|
146 |
/** |
|
147 |
* Test method for {@link eu.etaxonomy.cdm.common.media.ImageInfo#getBitPerPixel()}. |
|
148 |
*/ |
|
149 |
@Test |
|
150 |
public void testGetBitPerPixel() { |
|
151 |
Assert.assertEquals(24, getJpegInstance().getBitPerPixel()); |
|
152 |
Assert.assertEquals(24, getTifInstance().getBitPerPixel()); |
|
153 |
|
|
154 |
if(UriUtils.isInternetAvailable(remotePngUri)){ |
|
155 |
Assert.assertEquals(32, getRemotePngInstance().getBitPerPixel()); |
|
156 |
} |
|
157 |
} |
|
158 |
|
|
159 |
/** |
|
160 |
* Test method for {@link eu.etaxonomy.cdm.common.media.ImageInfo#getFormatName()}. |
|
161 |
*/ |
|
162 |
@Test |
|
163 |
public void testGetFormatName() { |
|
164 |
Assert.assertEquals("JPEG (Joint Photographic Experts Group) Format", getJpegInstance().getFormatName()); |
|
165 |
Assert.assertEquals("TIFF Tag-based Image File Format", getTifInstance().getFormatName()); |
|
166 |
|
|
167 |
if(UriUtils.isInternetAvailable(remotePngUri)){ |
|
168 |
Assert.assertEquals("PNG Portable Network Graphics", getRemotePngInstance().getFormatName()); |
|
169 |
} |
|
170 |
} |
|
171 |
|
|
172 |
/** |
|
173 |
* Test method for {@link eu.etaxonomy.cdm.common.media.ImageInfo#getMimeType()}. |
|
174 |
*/ |
|
175 |
@Test |
|
176 |
public void testGetMimeType() { |
|
177 |
Assert.assertEquals(MimeType.JPEG.getMimeType(), getJpegInstance().getMimeType()); |
|
178 |
Assert.assertEquals(MimeType.TIFF.getMimeType(), getTifInstance().getMimeType()); |
|
179 |
|
|
180 |
if(UriUtils.isInternetAvailable(remotePngUri)){ |
|
181 |
Assert.assertEquals(MimeType.PNG.getMimeType(), getRemotePngInstance().getMimeType()); |
|
182 |
} |
|
183 |
} |
|
184 |
|
|
185 |
@Test |
|
186 |
public void testGetLength(){ |
|
187 |
Assert.assertEquals(63500, getJpegInstance().getLength()); |
|
188 |
Assert.assertEquals(202926, getTifInstance().getLength()); |
|
189 |
|
|
190 |
if(UriUtils.isInternetAvailable(remotePngUri)){ |
|
191 |
Assert.assertEquals(9143, getRemotePngInstance().getLength()); |
|
192 |
} |
|
193 |
} |
|
194 |
|
|
195 |
@Test |
|
196 |
public void testReadMetaDataJpeg() throws IOException, HttpException{ |
|
197 |
ImageInfo instance = getJpegInstance(); |
|
198 |
|
|
199 |
instance.readMetaData(0); |
|
200 |
|
|
201 |
Map<String, String> metaData = instance.getMetaData(); |
|
202 |
|
|
203 |
Assert.assertEquals(48, metaData.size()); |
|
204 |
} |
|
205 |
|
|
206 |
|
|
207 |
@Test |
|
208 |
public void testReadMetaDataTif() throws IOException, HttpException{ |
|
209 |
ImageInfo instance = getTifInstance(); |
|
210 |
|
|
211 |
instance.readMetaData(0); |
|
212 |
|
|
213 |
Map<String, String> metaData = instance.getMetaData(); |
|
214 |
|
|
215 |
Assert.assertEquals(15, metaData.size()); |
|
216 |
} |
|
217 |
|
|
218 |
@Test |
|
219 |
public void testReadMetaDataRemotePng() throws IOException, HttpException{ |
|
220 |
ImageInfo instance = getRemotePngInstance(); |
|
221 |
|
|
222 |
instance.readMetaData(3000); |
|
223 |
|
|
224 |
Map<String, String> metaData = instance.getMetaData(); |
|
225 |
|
|
226 |
Assert.assertEquals(1, metaData.size()); |
|
227 |
} |
|
228 |
} |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelFactsImport.java | ||
---|---|---|
10 | 10 |
package eu.etaxonomy.cdm.io.berlinModel.in; |
11 | 11 |
|
12 | 12 |
import java.io.IOException; |
13 |
import java.net.MalformedURLException; |
|
14 | 13 |
import java.net.URI; |
15 | 14 |
import java.net.URISyntaxException; |
16 |
import java.net.URL; |
|
17 | 15 |
import java.sql.ResultSet; |
18 | 16 |
import java.sql.SQLException; |
19 | 17 |
import java.util.Collection; |
... | ... | |
27 | 25 |
import org.springframework.stereotype.Component; |
28 | 26 |
|
29 | 27 |
import eu.etaxonomy.cdm.common.CdmUtils; |
30 |
import eu.etaxonomy.cdm.common.mediaMetaData.ImageMetaData;
|
|
28 |
import eu.etaxonomy.cdm.common.media.ImageInfo;
|
|
31 | 29 |
import eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer; |
32 | 30 |
import eu.etaxonomy.cdm.io.berlinModel.in.validation.BerlinModelFactsImportValidator; |
33 | 31 |
import eu.etaxonomy.cdm.io.common.IOValidator; |
... | ... | |
441 | 439 |
TaxonDescription taxonDescription = null; |
442 | 440 |
Reference sourceRef = state.getConfig().getSourceReference(); |
443 | 441 |
Integer size = null; |
444 |
ImageMetaData imageMetaData = ImageMetaData.newInstance();
|
|
442 |
ImageInfo imageMetaData = null;
|
|
445 | 443 |
URI uri; |
446 | 444 |
try { |
447 | 445 |
uri = new URI(fact.trim()); |
... | ... | |
450 | 448 |
return null; |
451 | 449 |
} |
452 | 450 |
try { |
453 |
imageMetaData.readMetaData(uri, 0);
|
|
451 |
imageMetaData = ImageInfo.NewInstance(uri, 0);
|
|
454 | 452 |
} catch (IOException e) { |
455 | 453 |
logger.error("IOError reading image metadata." , e); |
456 | 454 |
} catch (HttpException e) { |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelNameFactsImport.java | ||
---|---|---|
10 | 10 |
package eu.etaxonomy.cdm.io.berlinModel.in; |
11 | 11 |
|
12 | 12 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_FACT_ALSO_PUBLISHED_IN; |
13 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_FACT_PROTOLOGUE; |
|
14 | 13 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_FACT_BIBLIOGRAPHY; |
15 |
|
|
14 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_FACT_PROTOLOGUE; |
|
16 | 15 |
|
17 | 16 |
import java.io.File; |
18 | 17 |
import java.io.IOException; |
... | ... | |
33 | 32 |
import org.springframework.stereotype.Component; |
34 | 33 |
|
35 | 34 |
import eu.etaxonomy.cdm.common.CdmUtils; |
36 |
import eu.etaxonomy.cdm.common.mediaMetaData.ImageMetaData;
|
|
35 |
import eu.etaxonomy.cdm.common.media.ImageInfo;
|
|
37 | 36 |
import eu.etaxonomy.cdm.io.berlinModel.in.validation.BerlinModelNameFactsImportValidator; |
38 | 37 |
import eu.etaxonomy.cdm.io.common.IOValidator; |
39 | 38 |
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner; |
... | ... | |
375 | 374 |
|
376 | 375 |
|
377 | 376 |
private ImageFile makeImage(String imageUri, Integer size, File file){ |
378 |
ImageMetaData imageMetaData = ImageMetaData.newInstance();
|
|
377 |
ImageInfo imageMetaData = null;
|
|
379 | 378 |
URI uri; |
380 | 379 |
try { |
381 | 380 |
uri = new URI(imageUri); |
382 | 381 |
try { |
383 |
imageMetaData.readMetaData(uri, 0);
|
|
382 |
imageMetaData = ImageInfo.NewInstance(uri, 0);
|
|
384 | 383 |
} catch (IOException e) { |
385 | 384 |
logger.error("IOError reading image metadata." , e); |
386 | 385 |
} catch (HttpException e) { |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/CdmImportBase.java | ||
---|---|---|
23 | 23 |
|
24 | 24 |
import eu.etaxonomy.cdm.api.service.pager.Pager; |
25 | 25 |
import eu.etaxonomy.cdm.common.CdmUtils; |
26 |
import eu.etaxonomy.cdm.common.mediaMetaData.ImageMetaData;
|
|
26 |
import eu.etaxonomy.cdm.common.media.ImageInfo;
|
|
27 | 27 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
28 | 28 |
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer; |
29 | 29 |
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException; |
... | ... | |
646 | 646 |
if( multimediaObject == null){ |
647 | 647 |
return null; |
648 | 648 |
} else { |
649 |
ImageMetaData imd = ImageMetaData.newInstance();
|
|
649 |
ImageInfo imd = null;
|
|
650 | 650 |
URI uri; |
651 | 651 |
try { |
652 | 652 |
uri = new URI(multimediaObject); |
653 | 653 |
try { |
654 | 654 |
if (readDataFromUrl){ |
655 |
imd.readMetaData(uri, 0);
|
|
655 |
imd = ImageInfo.NewInstance(uri, 0);
|
|
656 | 656 |
} |
657 | 657 |
} catch (Exception e) { |
658 | 658 |
String message = "An error occurred when trying to read image meta data: " + e.getMessage(); |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/sdd/in/SDDDataSetImport.java | ||
---|---|---|
32 | 32 |
|
33 | 33 |
import eu.etaxonomy.cdm.api.service.IDescriptionService; |
34 | 34 |
import eu.etaxonomy.cdm.common.IProgressMonitor; |
35 |
import eu.etaxonomy.cdm.common.mediaMetaData.ImageMetaData;
|
|
35 |
import eu.etaxonomy.cdm.common.media.ImageInfo;
|
|
36 | 36 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
37 |
import eu.etaxonomy.cdm.io.common.CdmApplicationAwareDefaultImport; |
|
38 | 37 |
import eu.etaxonomy.cdm.io.common.CdmImportBase; |
39 | 38 |
import eu.etaxonomy.cdm.io.common.ICdmIO; |
40 | 39 |
import eu.etaxonomy.cdm.io.common.ICdmImport; |
... | ... | |
1595 | 1594 |
Element elSource = elMO.getChild("Source",sddNamespace); |
1596 | 1595 |
String href = elSource.getAttributeValue("href"); |
1597 | 1596 |
|
1598 |
ImageMetaData imageMetaData = ImageMetaData.newInstance();
|
|
1597 |
ImageInfo imageMetaData = null;
|
|
1599 | 1598 |
ImageFile image = null; |
1600 | 1599 |
if (href.substring(0,7).equals("http://")) { |
1601 | 1600 |
try{ |
1602 | 1601 |
URL url = new URL(href); |
1603 | 1602 |
|
1604 |
imageMetaData.readMetaData(url.toURI(), 0);
|
|
1603 |
imageMetaData = ImageInfo.NewInstance(url.toURI(), 0);
|
|
1605 | 1604 |
image = ImageFile.NewInstance(url.toURI(), null, imageMetaData); |
1606 | 1605 |
} catch (MalformedURLException e) { |
1607 | 1606 |
logger.error("Malformed URL", e); |
... | ... | |
1612 | 1611 |
File parent = f.getParentFile(); |
1613 | 1612 |
String fi = parent.toString() + File.separator + href; |
1614 | 1613 |
File file = new File(fi); |
1615 |
imageMetaData.readMetaData(new URI(fi), 0); //file
|
|
1614 |
imageMetaData = ImageInfo.NewInstance(new URI(fi), 0); //file
|
|
1616 | 1615 |
image = ImageFile.NewInstance(file.toURI(), null, imageMetaData); |
1617 | 1616 |
} |
1618 | 1617 |
MediaRepresentation representation = MediaRepresentation.NewInstance(imageMetaData.getMimeType(), null); |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/sdd/in/SDDImport.java | ||
---|---|---|
32 | 32 |
|
33 | 33 |
import eu.etaxonomy.cdm.api.service.IDescriptionService; |
34 | 34 |
import eu.etaxonomy.cdm.common.IProgressMonitor; |
35 |
import eu.etaxonomy.cdm.common.mediaMetaData.ImageMetaData;
|
|
35 |
import eu.etaxonomy.cdm.common.media.ImageInfo;
|
|
36 | 36 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
37 | 37 |
import eu.etaxonomy.cdm.io.common.CdmImportBase; |
38 | 38 |
import eu.etaxonomy.cdm.io.common.ICdmImport; |
... | ... | |
1563 | 1563 |
Element elSource = elMO.getChild("Source",sddNamespace); |
1564 | 1564 |
String href = elSource.getAttributeValue("href"); |
1565 | 1565 |
|
Also available in: Unified diff
Refactored MediaMetaData and family. Renamed it to MediaInfo. API is now less confusing and more consistent.