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