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