2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.store
.parser
;
12 import org
.apache
.log4j
.Logger
;
14 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
15 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
16 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
17 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
18 import eu
.etaxonomy
.cdm
.strategy
.parser
.INonViralNameParser
;
19 import eu
.etaxonomy
.cdm
.strategy
.parser
.NonViralNameParserImpl
;
20 import eu
.etaxonomy
.taxeditor
.store
.preference
.PreferencesUtil
;
27 public class CdmParserUtil
{
28 private static final Logger logger
= Logger
29 .getLogger(CdmParserUtil
.class);
31 private static INonViralNameParser nonViralNameParser
;
33 private static INonViralNameParser
getNonViralNameParser() {
34 if (nonViralNameParser
== null) {
35 nonViralNameParser
= NonViralNameParserImpl
.NewInstance();
37 return nonViralNameParser
;
40 public static void clearNonViralNameParser() {
41 nonViralNameParser
= null;
45 * Takes a raw string, returns a brand spanking new name object.
47 * If no nomenclatural code is specified, the code specified in user preferences
48 * is used, i.e. if the preferred code is ICBN, a <code>BotanicalName</code> is returned;
49 * if it's ICZN, a <code>ZoologicalName</code> is returned.
52 * @param fullReference
57 public static TaxonNameBase
parseFullReference(String fullReference
,
58 NomenclaturalCode nomCode
, Rank rank
) {
60 if (nomCode
== null) {
61 nomCode
= PreferencesUtil
.getPreferredNomenclaturalCode();
64 TaxonNameBase name
= getNonViralNameParser().parseReferencedName(fullReference
,
67 if (name
.hasProblem()) {
68 name
.setFullTitleCache(fullReference
);
75 * Takes an existing name object and a string, returns the same name
76 * object with the fields parsed from the string.
78 * @param nameToBeFilled
79 * @param fullReference
83 public static void parseFullReference(NonViralName nameToBeFilled
, String fullReference
) {
86 boolean makeEmpty
= true;
88 // If the name already has a rank, make sure it is passed to the parser
89 if (nameToBeFilled
.getRank() != null) {
90 rank
= nameToBeFilled
.getRank();
93 getNonViralNameParser().parseReferencedName(nameToBeFilled
, fullReference
, rank
, makeEmpty
);
95 if (nameToBeFilled
.hasProblem()) {
96 nameToBeFilled
.setFullTitleCache(fullReference
);
101 * @param nameToBeFilled
102 * @param fullNameString
106 public static void parseFullName(NonViralName nameToBeFilled
,
107 String fullNameString
, Rank rank
, boolean makeEmpty
) {
108 getNonViralNameParser().parseFullName(nameToBeFilled
, fullNameString
,