fixed ticket #3763
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / bulkeditor / input / entitycreator / ReferenceCreator.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.taxeditor.bulkeditor.input.entitycreator;
12
13 import java.util.HashMap;
14 import java.util.Map;
15
16 import eu.etaxonomy.cdm.model.reference.Reference;
17 import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
18 import eu.etaxonomy.cdm.model.reference.ReferenceType;
19 import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
20 import eu.etaxonomy.taxeditor.model.MessagingUtils;
21
22 /**
23 * <p>ReferenceCreator class.</p>
24 *
25 * @author p.ciardelli
26 * @created 07.07.2009
27 * @version 1.0
28 */
29 public class ReferenceCreator implements IEntityCreator<Reference> {
30
31 /* (non-Javadoc)
32 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityCreator#createEntity(java.lang.String)
33 */
34 /** {@inheritDoc} */
35 @Override
36 public Reference createEntity(String text) {
37 return createEntity(Reference.class, text);
38 }
39
40 /* (non-Javadoc)
41 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#createEntity(java.lang.Class, java.lang.String)
42 */
43 /** {@inheritDoc} */
44 @Override
45 public Reference createEntity(Object key, String text) {
46 Reference reference = null;
47
48 // TODO replace w more generic method when cdmlib matures accordingly
49 if (ReferenceType.Article.getMessage().equals(key)) {
50 reference = ReferenceFactory.newArticle();
51 }
52 if (ReferenceType.Book.getMessage().equals(key)) {
53 reference = ReferenceFactory.newBook();
54 }
55 if (ReferenceType.BookSection.getMessage().equals(key)) {
56 reference = ReferenceFactory.newBookSection();
57 }
58 if (ReferenceType.CdDvd.getMessage().equals(key)) {
59 reference = ReferenceFactory.newCdDvd();
60 }
61 if (ReferenceType.Database.getMessage().equals(key)) {
62 reference = ReferenceFactory.newDatabase();
63 }
64 if (ReferenceType.Generic.getMessage().equals(key)) {
65 reference = ReferenceFactory.newGeneric();
66 }
67 if (ReferenceType.InProceedings.getMessage().equals(key)) {
68 reference = ReferenceFactory.newInProceedings();
69 }
70 if (ReferenceType.Journal.getMessage().equals(key)) {
71 reference = ReferenceFactory.newJournal();
72 }
73 if (ReferenceType.Map.getMessage().equals(key)) {
74 reference = ReferenceFactory.newMap();
75 }
76 if (ReferenceType.Patent.getMessage().equals(key)) {
77 reference = ReferenceFactory.newPatent();
78 }
79 if (ReferenceType.PersonalCommunication.getMessage().equals(key)) {
80 reference = ReferenceFactory.newPersonalCommunication();
81 }
82 if (ReferenceType.PrintSeries.getMessage().equals(key)) {
83 reference = ReferenceFactory.newPrintSeries();
84 }
85 if (ReferenceType.Proceedings.getMessage().equals(key)) {
86 reference = ReferenceFactory.newProceedings();
87 }
88 if (ReferenceType.Report.getMessage().equals(key)) {
89 reference = ReferenceFactory.newReport();
90 }
91 if (ReferenceType.Thesis.getMessage().equals(key)) {
92 reference = ReferenceFactory.newThesis();
93 }
94 if (ReferenceType.WebPage.getMessage().equals(key)) {
95 reference = ReferenceFactory.newWebPage();
96 }
97 if (ReferenceType.Section.getMessage().equals(key)) {
98 reference = ReferenceFactory.newSection();
99 }
100 if (reference == null) {
101 MessagingUtils.warn(getClass(), "Reference type " + key + " not found. Creating reference with default type.");
102 reference = ReferenceFactory.newGeneric();
103 }
104 reference.setTitleCache(text, true);
105 return reference;
106 }
107
108 /* (non-Javadoc)
109 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#getClassLabelPairs()
110 */
111 /**
112 * <p>getKeyLabelPairs</p>
113 *
114 * @return a {@link java.util.Map} object.
115 */
116 @Override
117 public Map<Object, String> getKeyLabelPairs() {
118 Map<Object, String> result = new HashMap<Object, String>();
119 for (ReferenceType type : ReferenceType.values()) {
120 result.put(type.getMessage(), type.getMessage());
121 }
122 return result;
123 }
124
125 @Override
126 public boolean savesEntity() {
127 // TODO Auto-generated method stub
128 return false;
129 }
130 }