3 * Copyright (C) 2007 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.
11 package eu
.etaxonomy
.cdm
.io
.common
.mapping
;
14 import java
.net
.URISyntaxException
;
15 import java
.sql
.ResultSet
;
16 import java
.sql
.SQLException
;
18 import org
.apache
.log4j
.Logger
;
20 import eu
.etaxonomy
.cdm
.io
.common
.DbImportStateBase
;
21 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
22 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
23 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentation
;
26 * This class adds a Media to a DescriptionElementBase
31 public class DbImportMediaMapper
extends DbImportMultiAttributeMapperBase
<DescriptionElementBase
, DbImportStateBase
<?
,?
>> {
32 @SuppressWarnings("unused")
33 private static final Logger logger
= Logger
.getLogger(DbImportMediaMapper
.class);
35 //********************************** FACTORY ***************************************
37 public static DbImportMediaMapper
NewInstance(String dbUriAttribute
){
38 return new DbImportMediaMapper(dbUriAttribute
, null);
42 public static DbImportMediaMapper
NewInstance(String dbFirstUriAttribute
, String dbSecondUriAttribute
){
43 return new DbImportMediaMapper(dbFirstUriAttribute
, dbSecondUriAttribute
);
47 //********************************** VARIABLES ***************************************
48 private String dbFirstUriAttribute
;
49 private String dbSecondUriAttribute
;
52 //********************************** METHODS ***************************************
55 public DbImportMediaMapper(String dbFirstUriAttribute
, String dbSecondUriAttribute
) {
57 this.dbFirstUriAttribute
= dbFirstUriAttribute
;
58 this.dbSecondUriAttribute
= dbSecondUriAttribute
;
63 * @see eu.etaxonomy.cdm.io.common.mapping.IDbImportMapper#invoke(java.sql.ResultSet, eu.etaxonomy.cdm.model.common.CdmBase)
65 public DescriptionElementBase
invoke(ResultSet rs
, DescriptionElementBase element
) throws SQLException
{
66 String uri1String
= getStringDbValue(rs
, dbFirstUriAttribute
);
67 String uri2String
= getStringDbValue(rs
, dbSecondUriAttribute
);
69 String mimeType
= null;
74 uri1
= new URI(uri1String
);
75 } catch (URISyntaxException e
) {
76 String warning
= "URISyntaxException when trying to convert first uri string: " + uri1String
;
77 logger
.error(warning
);
81 uri2
= new URI(uri2String
);
82 } catch (URISyntaxException e
) {
83 String warning
= "URISyntaxException when trying to convert first uri string: " + uri1String
;
84 logger
.error(warning
);
86 Media media
= Media
.NewInstance(uri1
, size
, mimeType
, suffix
);
88 MediaRepresentation secondRepresentation
= MediaRepresentation
.NewInstance(mimeType
, suffix
, uri2
, size
, null);
89 media
.addRepresentation(secondRepresentation
);
91 media
= Media
.NewInstance(uri2
, size
, mimeType
, suffix
);
93 element
.addMedia(media
);