Project

General

Profile

« Previous | Next » 

Revision 7defa3a9

Added by Andreas Müller over 16 years ago

View differences:

.gitattributes
206 206
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/TaxonRelationshipType.java -text
207 207
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/package.html -text
208 208
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/view/View.java -text
209
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/INameCacheStrategy.java -text
210 209
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/IStrategy.java -text
211
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/ITaxonNameParser.java -text
212
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/NameCacheStrategyBase.java -text
213
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/NonViralNameDefaultCacheStrategy.java -text
214 210
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/StrategyBase.java -text
215
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/TaxonNameParserBotanicalNameImpl.java -text
216
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/ZooNameDefaultCacheStrategy.java -text
217 211
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/BotanicNameDefaultCacheStrategy.java -text
218 212
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/IIdentifiableEntityCacheStrategy.java -text
219 213
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/INameCacheStrategy.java -text
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/INameCacheStrategy.java
1
/**
2
 * 
3
 */
4
package eu.etaxonomy.cdm.strategy;
5

  
6
import java.util.List;
7

  
8
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
9

  
10
/**
11
 * A name cache rendering strategy for all TaxonNameBase subclasses.
12
 * Different TaxonNameBase subclasses could have different strategies.
13
 * @author a.mueller
14
 *
15
 * @param <T> The concrete TaxonName class this strategy applies for
16
 */
17
public interface INameCacheStrategy<T extends TaxonNameBase> extends IStrategy {
18
	
19
	/**
20
	 * returns the composed name string without author or year
21
	 * @param object
22
	 * @return
23
	 */
24
	public String getNameCache(T object);
25
	
26

  
27
	/**
28
	 * returns the composed name string with author and/or year
29
	 * @param object
30
	 * @return
31
	 */
32
	public String getTitleCache(T object);
33

  
34
	/**
35
	 * returns an array of name tokens that together make up the full name
36
	 * a token can be a String (for name parts), Rank, AuthorTeam (for entire authorship string), 
37
	 * Date or ReferenceBase
38
	 * Example: ["Abies","alba",Rank.SUBSPECIES,"alpina",AuthorTeam("Greuther (L.)")]
39
	 * @param object
40
	 * @return
41
	 */
42
	public List<Object> getTaggedName(T object);
43
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/ITaxonNameParser.java
1
package eu.etaxonomy.cdm.strategy;
2

  
3
import eu.etaxonomy.cdm.model.name.BotanicalName;
4
import eu.etaxonomy.cdm.model.name.Rank;
5
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
6

  
7

  
8
/**
9
 * @author a.mueller
10
 *
11
 */
12
public interface ITaxonNameParser<T extends TaxonNameBase> extends IStrategy {
13
	
14

  
15
	/**
16
	 * Parses the taxonname String and returns a TaxonNameBase. 
17
	 * If the String is not parseable the "hasProblem" bit is set to true.
18
 	 * Returns null if fullName == null.
19
	 * @param fullName TaxonNameBase with Author, Year, Reference etc.,
20
	 * @return TaxonNameBase, with rank = Rank.GENUS for all Uninomials. 
21
	 */
22
	public T parseFullName(String fullName);
23

  
24
	/**
25
	 * Parses the taxonname String and returns a TaxonNameBase. 
26
	 * If the String is not parseable the "hasProblem" bit is set to true.
27
 	 * Returns null if fullName == null.
28
	 * @param fullName TaxonNameBase with Author, Year, Reference etc.,
29
	 * @param rank
30
	 * @return TaxonNameBase name, with name.rank = rank for all Uninomials and name.rank = Rank.GENUS for rank = null  
31
	 */
32
	public T parseFullName(String fullName, Rank rank);
33

  
34
	/**
35
 	 * Parses the taxonname String and fills the result into the existing TaxonNameBase nameToBeFilled. 
36
	 * Name related fields are set to default (null for Strings and other objects like Authors and References and false for booleans).
37
	 * NameRelations are not changed.
38
	 * If the String is not parseable the "hasProblem" bit is set to true.
39
 	 * No change is done to nameToBeFilled if fullName == null.
40
	 * @param fullName TaxonNameBase with Author, Year, Reference etc.,
41
	 * @param rank
42
	 * @param nameToBeFilled The TaxonNameBaseToBeFilled
43
	 */
44
	public void parseFullName(BotanicalName nameToBeFilled, String fullName, Rank rank, boolean makeEmpty);
45

  
46
	public BotanicalName parseFullReference(String fullReference, Rank rank);
47

  
48
	public void parseFullReference(BotanicalName nameToBeFilled, String fullReference, Rank rank, boolean makeEmpty);
49
	
50
	
51
	/**
52
	 * Parses the taxonname String and returns a TaxonNameBase. 
53
	 * If the String is not parseable the "hasProblem" bit is set to true.
54
 	 * Returns null if fullName == null.
55
	 * @param fullName TaxonNameBase without Author, Year, Reference etc.
56
	 * @param rank
57
	 * @return TaxonNameBase, with rank = Rank.GENUS for all Uninomials  
58
	 */
59
	public T parseSimpleName(String simpleName, Rank rank);
60

  
61
	/**
62
	 * Parses the taxonname String and returns a TaxonNameBase. 
63
	 * If the String is not parseable the "hasProblem" bit is set to true.
64
 	 * Returns null if fullName == null.
65
	 * @param fullName TaxonNameBase without Author, Year, Reference etc.
66
	 * @return TaxonNameBase name, with name.rank = rank for all Uninomials and name.rank = Rank.GENUS for rank = null  
67
	 */
68
	public T parseSimpleName(String simpleName);
69
	
70

  
71
	
72
	
73
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/NameCacheStrategyBase.java
1
/**
2
 * 
3
 */
4
package eu.etaxonomy.cdm.strategy;
5

  
6
import java.util.ArrayList;
7
import java.util.List;
8
import java.util.UUID;
9

  
10
import org.apache.log4j.Logger;
11

  
12

  
13
import eu.etaxonomy.cdm.model.agent.Agent;
14
import eu.etaxonomy.cdm.model.agent.INomenclaturalAgent;
15
import eu.etaxonomy.cdm.model.agent.Team;
16
import eu.etaxonomy.cdm.model.name.NonViralName;
17
import eu.etaxonomy.cdm.model.name.Rank;
18
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
19

  
20
/**
21
 * @author AM
22
 *
23
 */
24
public abstract class NameCacheStrategyBase<T extends NonViralName> extends StrategyBase implements INameCacheStrategy<T> {
25
	private static final Logger logger = Logger.getLogger(NameCacheStrategyBase.class);
26

  
27
	final static UUID uuid = UUID.fromString("817ae5b5-3ac2-414b-a134-a9ae86cba040");
28

  
29
	/**
30
	 * 
31
	 */
32
	public NameCacheStrategyBase() {
33
		super();
34
	}
35

  
36
	/* (non-Javadoc)
37
	 * @see eu.etaxonomy.cdm.strategy.INameCacheStrategy#getFullNameCache()
38
	 */
39
	// Test implementation
40
	public String getNameCache(T object) {
41
		String result;
42
		NonViralName name = (NonViralName)object;
43
		Rank rank = name.getRank();
44
		
45
		if (rank == null){
46
			return "";
47
		}else if (rank.isInfraSpecific()){
48
			result = getInfraSpeciesNameCache(name);
49
		}else if (rank.isSpecies()){
50
			result = getSpeciesNameCache(name);
51
		}else if (rank.isInfraGeneric()){
52
			result = getInfraGenusNameCache(name);
53
		}else if (rank.isGenus()){
54
			result = getGenusOrUninomialNameCache(name);
55
		}else if (rank.isSupraGeneric()){
56
			result = getGenusOrUninomialNameCache(name);
57
		}else{ 
58
			logger.warn("Name Strategy for Name (UUID: " + name.getUuid() +  ") not yet implemented");
59
			result = "XXX";
60
		}
61
		return result;
62
	}
63

  
64
	/* (non-Javadoc)
65
	 * @see eu.etaxonomy.cdm.strategy.INameCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.common.CdmBase)
66
	 */
67
	public String getTitleCache(T name){
68
		String result;
69
		//TODO use authorCache + TODO exAuthors
70
		INomenclaturalAgent agent= name.getCombinationAuthorTeam();
71
		if (isAutonym(name)){
72
			result = getSpeciesNameCache(name);
73
			if (agent != null){
74
				result += " " + agent.getNomenclaturalTitle();
75
			}
76
			result += " " + (nz(name.getInfraSpecificEpithet())).trim().replace("null", "");
77
		}else{
78
			result = getNameCache(name);
79
			if (agent != null){
80
				result += " " + agent.getNomenclaturalTitle();
81
			}
82
		}
83
		return result;
84
	}
85

  
86
	/* (non-Javadoc)
87
	 * @see eu.etaxonomy.cdm.strategy.INameCacheStrategy#getTaggedName(eu.etaxonomy.cdm.model.common.CdmBase)
88
	 */
89
	public List<Object> getTaggedName(T nvn) {
90
		List<Object> tags = new ArrayList<Object>();
91
		tags.add(nvn.getGenusOrUninomial());
92
		if (nvn.isSpecies() || nvn.isInfraSpecific()){
93
			tags.add(nvn.getSpecificEpithet());			
94
		}
95
		if (nvn.isInfraSpecific()){
96
			tags.add(nvn.getRank());			
97
			tags.add(nvn.getInfraSpecificEpithet());			
98
		}
99
		Team at = Team.NewInstance();
100
		at.setProtectedTitleCache(true);
101
		at.setTitleCache(nvn.getAuthorshipCache());
102
		tags.add(at);			
103
		tags.add(nvn.getNomenclaturalReference());			
104
		return tags;
105
	}
106

  
107

  
108
	/************** PRIVATES ****************/
109
		
110
		protected String getGenusOrUninomialNameCache(NonViralName name){
111
			String result;
112
			result = name.getGenusOrUninomial();
113
			return result;
114
		}
115
		
116
		protected String getInfraGenusNameCache(NonViralName name){
117
			//FIXME
118
			String result;
119
			result = name.getGenusOrUninomial();
120
			result += " (" + (nz(name.getInfraGenericEpithet()) + ")").trim().replace("null", "");
121
			return result;
122
		}
123

  
124
		
125
		protected String getSpeciesNameCache(NonViralName name){
126
			String result;
127
			result = name.getGenusOrUninomial();
128
			result += " " + nz(name.getSpecificEpithet()).trim().replace("null", "");
129
			return result;
130
		}
131
		
132
		
133
		protected String getInfraSpeciesNameCache(NonViralName name){
134
			String result;
135
			result = name.getGenusOrUninomial();
136
			result += " " + (nz(name.getSpecificEpithet()).trim()).replace("null", "");
137
			if (! isAutonym(name)){
138
				result += " " + (name.getRank().getAbbreviation()).trim().replace("null", "");
139
			}
140
			result += " " + (nz(name.getInfraSpecificEpithet())).trim().replace("null", "");
141
			return result;
142
		}
143
		
144
		
145
		/**
146
		 * @param name
147
		 * @return true, if name has Rank, Rank is below species and species epithet equals infraSpeciesEpithtet
148
		 */
149
		private boolean isAutonym(NonViralName name){
150
			if (name.getRank() != null && name.getRank().isInfraSpecific() && name.getSpecificEpithet() != null && name.getSpecificEpithet().equals(name.getInfraSpecificEpithet())){
151
				return true;
152
			}else{
153
				return false;
154
			}
155
		}
156
		
157
		/* Returns "" if nzString is null, identity function otherwise*/ 
158
		private String nz(String nzString){
159
			return (nzString == null)? "" : nzString;
160
		}
161

  
162
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/NonViralNameDefaultCacheStrategy.java
1
/**
2
 * 
3
 */
4
package eu.etaxonomy.cdm.strategy;
5

  
6
import java.util.UUID;
7

  
8
import org.apache.log4j.Logger;
9

  
10
import eu.etaxonomy.cdm.model.agent.Agent;
11
import eu.etaxonomy.cdm.model.agent.INomenclaturalAgent;
12
import eu.etaxonomy.cdm.model.common.CdmBase;
13
import eu.etaxonomy.cdm.model.name.NonViralName;
14

  
15

  
16
/**
17
 * @author a.mueller
18
 *
19
 */
20
public class NonViralNameDefaultCacheStrategy extends NameCacheStrategyBase<NonViralName> implements INameCacheStrategy<NonViralName> {
21
	private static final Logger logger = Logger.getLogger(NonViralNameDefaultCacheStrategy.class);
22
	
23
	final static UUID uuid = UUID.fromString("1cdda0d1-d5bc-480f-bf08-40a510a2f223");
24
	
25
	public  UUID getUuid(){
26
		return uuid;
27
	}
28

  
29
	
30
	public static NonViralNameDefaultCacheStrategy NewInstance(){
31
		return new NonViralNameDefaultCacheStrategy();
32
	}
33
	
34
	private NonViralNameDefaultCacheStrategy(){
35
		super();
36
	}
37

  
38
	
39
	/* (non-Javadoc)
40
	 * @see eu.etaxonomy.cdm.strategy.INameCacheStrategy#getNameCache()
41
	 */
42
	// Test implementation
43
	@Override
44
	public String getTitleCache(NonViralName object) {
45
		String result;
46
		NonViralName tn = (NonViralName)object;
47
		result = getNameCache(object);
48
		INomenclaturalAgent agent= tn.getCombinationAuthorTeam();
49
		if (agent != null){
50
			result += " " + agent.getNomenclaturalTitle();
51
		}
52
		return result;
53
	}
54

  
55
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/TaxonNameParserBotanicalNameImpl.java
1
/**
2
 * 
3
 */
4
package eu.etaxonomy.cdm.strategy;
5

  
6
import java.util.Calendar;
7
import java.util.regex.Matcher;
8
import java.util.regex.Pattern;
9

  
10
import org.apache.log4j.Logger;
11

  
12
import eu.etaxonomy.cdm.model.agent.Team;
13
import eu.etaxonomy.cdm.model.name.BotanicalName;
14
import eu.etaxonomy.cdm.model.name.CultivarPlantName;
15
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
16
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
17
import eu.etaxonomy.cdm.model.name.Rank;
18
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
19
import eu.etaxonomy.cdm.model.reference.Article;
20
import eu.etaxonomy.cdm.model.reference.Book;
21
import eu.etaxonomy.cdm.model.reference.BookSection;
22
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
23
import eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException;
24
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
25

  
26

  
27
/**
28
 * @author a.mueller
29
 *
30
 */
31
public class TaxonNameParserBotanicalNameImpl implements ITaxonNameParser<BotanicalName> {
32
	private static final Logger logger = Logger.getLogger(TaxonNameParserBotanicalNameImpl.class);
33
	
34
	// good intro: http://java.sun.com/docs/books/tutorial/essential/regex/index.html
35
	
36
	public static TaxonNameParserBotanicalNameImpl NEW_INSTANCE(){
37
		return new TaxonNameParserBotanicalNameImpl();
38
	}
39
	
40

  
41
	/* (non-Javadoc)
42
	 * @see eu.etaxonomy.cdm.strategy.ITaxonNameParser#parseSimpleName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)
43
	 */
44
	public BotanicalName parseSimpleName(String simpleName, Rank rank){
45
		//TODO
46
		logger.warn("parseSimpleName() not yet implemented. Uses parseFullName() instead");
47
		return parseFullName(simpleName, rank);
48
	}
49

  
50

  
51
	/* (non-Javadoc)
52
	 * @see eu.etaxonomy.cdm.strategy.ITaxonNameParser#parseSubGenericSimpleName(java.lang.String)
53
	 */
54
	public BotanicalName parseSimpleName(String simpleName){
55
		return parseSimpleName(simpleName, null);
56
	}
57

  
58
	/* (non-Javadoc)
59
	 * @see eu.etaxonomy.cdm.strategy.ITaxonNameParser#parseFullReference(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)
60
	 */
61
	public BotanicalName parseFullReference(String fullReference, Rank rank) {
62
		if (fullReference == null){
63
			return null;
64
		}else{
65
			BotanicalName result = new BotanicalName(null);
66
			parseFullReference(result, fullReference, rank, false);
67
			return result;
68
		}
69
	}
70
	
71
	/* (non-Javadoc)
72
	 * @see eu.etaxonomy.cdm.strategy.ITaxonNameParser#parseFullReference(eu.etaxonomy.cdm.model.name.BotanicalName, java.lang.String, eu.etaxonomy.cdm.model.name.Rank, boolean)
73
	 */
74
	public void parseFullReference(BotanicalName nameToBeFilled, String fullReference, Rank rank, boolean makeEmpty) {
75
		if (fullReference == null){
76
			//return null;
77
			return;
78
		}
79
		if (makeEmpty){
80
			makeEmpty(nameToBeFilled);
81
		}
82
		fullReference.replaceAll(oWs , " ");
83
		fullReference = fullReference.trim();
84
		
85
		//seperate name and reference part
86
		String nameAndRefSeperator = "(^" + anyFullName + ")("+ referenceSeperator + ")";
87
		Pattern nameAndRefSeperatorPattern = Pattern.compile(nameAndRefSeperator);
88
		Matcher nameAndRefSeperatorMatcher = nameAndRefSeperatorPattern.matcher(fullReference);
89
				
90
		if (nameAndRefSeperatorMatcher.find() ){
91
			String nameAndSeperator = nameAndRefSeperatorMatcher.group(0); 
92
		    String name = nameAndRefSeperatorMatcher.group(1); 
93
		    String reference = fullReference.substring(nameAndRefSeperatorMatcher.end());
94
		    
95
		    // inRef?
96
		    String seperator = nameAndSeperator.substring(name.length());
97
			boolean isInReference = false;
98
		    if (seperator.matches(inReferenceSeperator)){
99
		    	isInReference = true;
100
		    }
101
		   	
102
		    //status
103
		    reference = parseNomStatus(reference, nameToBeFilled);
104
		    
105
		    //parse subparts
106
		    parseFullName(nameToBeFilled, name, rank, makeEmpty);
107
		    parseReference(nameToBeFilled, reference, isInReference); 
108
		
109
		}else{
110
			//don't parse if name can't be seperated
111
			nameToBeFilled.setHasProblem(true);
112
			nameToBeFilled.setTitleCache(fullReference);
113
			logger.info("no applicable parsing rule could be found for \"" + fullReference + "\"");    
114
		}
115
	}
116
	
117
	//TODO make it an Array of status
118
	/**
119
	 * Extracts a {@link NomenclaturalStatus} from the reference String and adds it to the @link {@link TaxonNameBase}.
120
	 * The nomenclatural status part ist deleted from the reference String.
121
	 * @return  String the new (shortend) reference String 
122
	 */ 
123
	String parseNomStatus(String reference, BotanicalName nameToBeFilled) {
124
		String statusString;
125
		Pattern hasStatusPattern = Pattern.compile("(" + pNomStatusPhrase + ")"); 
126
		Matcher hasStatusMatcher = hasStatusPattern.matcher(reference);
127
		
128
		if (hasStatusMatcher.find()) {
129
			String statusPhrase = hasStatusMatcher.group(0);
130
			
131
			Pattern statusPattern = Pattern.compile(pNomStatus);
132
			Matcher statusMatcher = statusPattern.matcher(statusPhrase);
133
			statusMatcher.find();
134
			statusString = statusMatcher.group(0);
135
			try {
136
				NomenclaturalStatusType nomStatusType = NomenclaturalStatusType.getNomenclaturalStatusTypeByAbbreviation(statusString);
137
				NomenclaturalStatus nomStatus = NomenclaturalStatus.NewInstance(nomStatusType);
138
				nameToBeFilled.addStatus(nomStatus);
139
			    
140
			    reference = reference.replace(statusPhrase, "");
141
			} catch (UnknownCdmTypeException e) {
142
				//Do nothing
143
			}
144
		}
145
		return reference;
146
	}
147
	
148
	
149
	private void parseReference(BotanicalName nameToBeFilled, String reference, boolean isInReference){
150
			
151
		if (referencePattern.matcher(reference).matches() ){
152
			//End (just delete, may be ambigous for yearPhrase, but no real information gets lost
153
			Pattern endPattern = Pattern.compile( referenceEnd + end);
154
			Matcher endMatcher = endPattern.matcher(reference);
155
			if (endMatcher.find()){
156
				String endPart = endMatcher.group(0);
157
				reference = reference.substring(0, reference.length() - endPart.length());
158
			}
159
			
160
			//year
161
			String yearPart = null;
162
			String pYearPhrase = yearSeperator + yearPhrase + end;
163
			Pattern yearPhrasePattern = Pattern.compile(pYearPhrase);
164
			Matcher yearPhraseMatcher = yearPhrasePattern.matcher(reference);
165
			if (yearPhraseMatcher.find()){
166
				yearPart = yearPhraseMatcher.group(0);
167
				reference = reference.substring(0, reference.length() - yearPart.length());
168
				yearPart = yearPart.replaceFirst(start + yearSeperator, "").trim();
169
			}
170
			
171
			//detail
172
			String pDetailPhrase = detailSeperator + detail + end;
173
			Pattern detailPhrasePattern = Pattern.compile(pDetailPhrase);
174
			Matcher detailPhraseMatcher = detailPhrasePattern.matcher(reference);
175
			if (detailPhraseMatcher.find()){
176
				String detailPart = detailPhraseMatcher.group(0);
177
				reference = reference.substring(0, reference.length() - detailPart.length());
178
				detailPart = detailPart.replaceFirst(start + detailSeperator, "").trim();
179
				nameToBeFilled.setNomenclaturalMicroReference(detailPart);
180
			}
181
			//Title (and author)
182
			parseReferenceTitle(reference, yearPart);
183
	    }
184
	    
185
	}
186
		
187
	/**
188
	 * Parses the referenceTitlePart, including the author volume and edition.
189
	 * @param reference
190
	 * @param year
191
	 * @return
192
	 */
193
	private ReferenceBase parseReferenceTitle(String reference, String year){
194
		ReferenceBase result = null;
195
		Pattern bookPattern = Pattern.compile(bookReference);
196
		Pattern articlePattern = Pattern.compile(articleReference);
197
		Pattern bookSectionPattern = Pattern.compile(bookSectionReference);
198
		
199
		
200
		Matcher articleMatcher = articlePattern.matcher(reference);
201
		Matcher bookMatcher = bookPattern.matcher(reference);
202
		Matcher bookSectionMatcher = bookSectionPattern.matcher(reference);
203
		
204
		
205
		if (articleMatcher.matches()){
206
			//if (articlePatter)
207
			//(type, author, title, volume, editor, series;
208
			Article article = new Article();
209
			article.setTitleCache(reference);
210
			result = article;
211
		}else if(bookMatcher.matches()){
212
			Book book = new Book();
213
			book .setTitleCache(reference);
214
			result = book;
215
		}else if (bookSectionMatcher.matches()){
216
			BookSection bookSection = new BookSection();
217
			bookSection.setTitleCache(reference);
218
			result = bookSection;
219
		}else{
220
			logger.warn("unknown reference type not yet implemented");
221
			//ReferenceBase refBase = 
222
		}
223
		return result;
224
	}
225
	
226
	
227
	/* (non-Javadoc)
228
	 * @see eu.etaxonomy.cdm.strategy.ITaxonNameParser#parseSubGenericFullName(java.lang.String)
229
	 */
230
	public BotanicalName parseFullName(String fullName){
231
		return parseFullName(fullName, null);
232
	}
233
	
234
	
235
	/* (non-Javadoc)
236
	 * @see eu.etaxonomy.cdm.strategy.ITaxonNameParser#parseFullName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)
237
	 */
238
	public BotanicalName parseFullName(String fullName, Rank rank) {
239
		if (fullName == null){
240
			return null;
241
		}else{
242
			BotanicalName result = new BotanicalName(null);
243
			parseFullName(result, fullName, rank, false);
244
			return result;
245
		}
246
	}
247
		
248
	
249
	public void parseFullName(BotanicalName nameToBeFilled, String fullName, Rank rank, boolean makeEmpty) {
250
		//TODO prol. etc.
251
		
252
		String authorString = null;
253
		
254
		if (fullName == null){
255
			return;
256
		}
257
		if (makeEmpty){
258
			makeEmpty(nameToBeFilled);
259
		}
260
		fullName.replaceAll(oWs , " ");
261
		//TODO 
262
		// OLD: fullName = oWsRE.subst(fullName, " "); //substitute multiple whitespaces		   
263
		fullName = fullName.trim();
264
		
265
		String[] epi = pattern.split(fullName);
266
		try {
267
	    	//cultivars //TODO 2 implement cultivars
268
//		    if ( cultivarMarkerRE.match(fullName) ){ funktioniert noch nicht, da es z.B. auch Namen gibt, wie 't Hart
269
//		    	result = parseCultivar(fullName);
270
//		    }
271
		    //hybrids //TODO 2 implement hybrids
272
		    //else 
273
		    if (hybridPattern.matcher(fullName).matches() ){
274
		    	nameToBeFilled = parseHybrid(fullName);
275
		    }
276
		    else if (genusOrSupraGenusPattern.matcher(fullName).matches()){
277
		    	//supraGeneric
278
				if (rank.isSupraGeneric()){
279
					nameToBeFilled.setRank(rank);
280
					nameToBeFilled.setGenusOrUninomial(epi[0]);
281
				} 
282
				//genus
283
				else {
284
					nameToBeFilled.setRank(Rank.GENUS());
285
					nameToBeFilled.setGenusOrUninomial(epi[0]);
286
				}
287
				authorString = fullName.substring(epi[0].length());
288
			}
289
			//infra genus
290
			else if (infraGenusPattern.matcher(fullName).matches()){
291
				nameToBeFilled.setRank(Rank.getRankByAbbreviation(epi[1]));
292
				nameToBeFilled.setGenusOrUninomial(epi[0]);
293
				nameToBeFilled.setInfraGenericEpithet(epi[2]);
294
				authorString = fullName.substring(epi[0].length() + 1 + epi[1].length()+ 1 + epi[2].length());
295
			}
296
			//aggr. or group
297
			else if (aggrOrGroupPattern.matcher(fullName).matches()){
298
				nameToBeFilled.setRank(Rank.getRankByAbbreviation(epi[2]));
299
				nameToBeFilled.setGenusOrUninomial(epi[0]);
300
				nameToBeFilled.setSpecificEpithet(epi[1]);
301
			}
302
			//species
303
			else if (speciesPattern.matcher(fullName).matches()){
304
				nameToBeFilled.setRank(Rank.SPECIES());
305
				nameToBeFilled.setGenusOrUninomial(epi[0]);
306
				nameToBeFilled.setSpecificEpithet(epi[1]);
307
				authorString = fullName.substring(epi[0].length() + 1 + epi[1].length());
308
			}
309
			//autonym
310
			else if (autonymPattern.matcher(fullName).matches()){
311
				nameToBeFilled.setRank(Rank.getRankByAbbreviation(epi[epi.length - 2]));
312
				nameToBeFilled.setGenusOrUninomial(epi[0]);
313
				nameToBeFilled.setSpecificEpithet(epi[1]);
314
				nameToBeFilled.setInfraSpecificEpithet(epi[epi.length - 1]);
315
				int lenSpecies = 2 + epi[0].length()+epi[1].length();
316
				int lenInfraSpecies =  2 + epi[epi.length - 2].length() + epi[epi.length - 1].length();
317
				authorString = fullName.substring(lenSpecies, fullName.length() - lenInfraSpecies);
318
			}
319
			//infraSpecies
320
			else if (infraSpeciesPattern.matcher(fullName).matches()){
321
				String infraSpecRankEpi = epi[2];
322
				String infraSpecEpi = epi[3];
323
				if ("tax.".equals(infraSpecRankEpi)){
324
					infraSpecRankEpi += " " +  epi[3];
325
					infraSpecEpi = epi[4];
326
				}
327
				nameToBeFilled.setRank(Rank.getRankByAbbreviation(infraSpecRankEpi));
328
				nameToBeFilled.setGenusOrUninomial(epi[0]);
329
				nameToBeFilled.setSpecificEpithet(epi[1]);
330
				nameToBeFilled.setInfraSpecificEpithet(infraSpecEpi);
331
				authorString = fullName.substring(epi[0].length()+ 1 + epi[1].length() +1 + infraSpecRankEpi.length() + 1 + infraSpecEpi.length());
332
			}//old infraSpecies
333
			else if (oldInfraSpeciesPattern.matcher(fullName).matches()){
334
				boolean implemented = false;
335
				if (implemented){
336
					nameToBeFilled.setRank(Rank.getRankByNameOrAbbreviation(epi[2]));
337
					nameToBeFilled.setGenusOrUninomial(epi[0]);
338
					nameToBeFilled.setSpecificEpithet(epi[1]);
339
					//TODO result.setUnnamedNamePhrase(epi[2] + " " + epi[3]);
340
					authorString = fullName.substring(epi[0].length()+ 1 + epi[1].length() +1 + epi[2].length() + 1 + epi[3].length());
341
				}else{
342
					nameToBeFilled.setHasProblem(true);
343
					nameToBeFilled.setTitleCache(fullName);
344
					logger.info("Name string " + fullName + " could not be parsed because UnnnamedNamePhrase is not yet implemented!");
345
				}
346
			}
347
			//none
348
			else{ 
349
				nameToBeFilled.setHasProblem(true);
350
				nameToBeFilled.setTitleCache(fullName);
351
				logger.info("no applicable parsing rule could be found for \"" + fullName + "\"");
352
		    }
353
			//authors
354
		    if (nameToBeFilled != null && authorString != null && authorString.trim().length() > 0 ){ 
355
				Team[] authors = null;
356
				try {
357
					authors = fullTeams(authorString);
358
				} catch (StringNotParsableException e) {
359
					nameToBeFilled.setHasProblem(true);
360
					nameToBeFilled.setTitleCache(fullName);
361
					logger.info("no applicable parsing rule could be found for \"" + fullName + "\"");;
362
				}
363
				nameToBeFilled.setCombinationAuthorTeam(authors[0]);
364
				nameToBeFilled.setExCombinationAuthorTeam(authors[1]);
365
				nameToBeFilled.setBasionymAuthorTeam(authors[2]);
366
				nameToBeFilled.setExBasionymAuthorTeam(authors[3]);
367
			}	
368
			//return
369
			if (nameToBeFilled != null){
370
		    	//return(BotanicalName)result;
371
				return;
372
			}else{
373
				nameToBeFilled.setHasProblem(true);
374
				nameToBeFilled.setTitleCache(fullName);
375
				logger.info("Name string " + fullName + " could not be parsed!");
376
				//return result;
377
				return;
378
			}
379
		} catch (UnknownCdmTypeException e) {
380
			nameToBeFilled.setHasProblem(true);
381
			nameToBeFilled.setTitleCache(fullName);
382
			logger.info("unknown rank (" + (rank == null? "null":rank) + ") or abbreviation in string " +  fullName);
383
			//return result;
384
			return;
385
		}
386
	}
387
	
388
	private void makeEmpty(BotanicalName nameToBeFilled){
389
		nameToBeFilled.setAnamorphic(false);
390
		nameToBeFilled.setAppendedPhrase(null);
391
		nameToBeFilled.setAuthorshipCache(null);
392
		//TODO ??
393
		//nameToBeFilled.setBasionym(basionym);
394
		nameToBeFilled.setBasionymAuthorTeam(null);
395
		nameToBeFilled.setBinomHybrid(false);
396
		nameToBeFilled.setCombinationAuthorTeam(null);
397
		nameToBeFilled.setExBasionymAuthorTeam(null);
398
		
399
		
400
		nameToBeFilled.setExCombinationAuthorTeam(null);
401
		nameToBeFilled.setGenusOrUninomial(null);
402
		nameToBeFilled.setHasProblem(false);
403
		// TODO ?
404
		//nameToBeFilled.setHomotypicalGroup(newHomotypicalGroup);
405
		nameToBeFilled.setHybridFormula(false);
406
		nameToBeFilled.setInfraGenericEpithet(null);
407
		nameToBeFilled.setInfraSpecificEpithet(null);
408
		nameToBeFilled.setMonomHybrid(false);
409
		nameToBeFilled.setNameCache(null);
410
		nameToBeFilled.setNomenclaturalMicroReference(null);
411
		nameToBeFilled.setNomenclaturalReference(null);
412
		nameToBeFilled.setProtectedTitleCache(false);
413
		nameToBeFilled.setRank(null);
414
		nameToBeFilled.setSpecificEpithet(null);
415
		nameToBeFilled.setTitleCache(null, false);
416
		nameToBeFilled.setTrinomHybrid(false);
417
		nameToBeFilled.setUpdated(Calendar.getInstance());
418
		// TODO nameToBeFilled.setUpdatedBy(updatedBy);
419
			
420
	}
421
	
422
	
423
	/**
424
	 * Parses the fullAuthorString
425
	 * @param fullAuthorString
426
	 * @return array of Teams containing the Team[0], 
427
	 * ExTeam[1], BasionymTeam[2], ExBasionymTeam[3]
428
	 */
429
	public Team[] fullTeams (String fullAuthorString)
430
			throws StringNotParsableException{
431
		fullAuthorString = fullAuthorString.trim();
432
		if (! fullAuthorStringPattern.matcher(fullAuthorString).matches())
433
			throw new StringNotParsableException("fullAuthorString (" +fullAuthorString+") not parsable: ");
434
		return fullTeamsChecked(fullAuthorString);
435
	}
436
	
437
	
438
	/*
439
	 * like fullTeams but without trim and match check
440
	 */
441
	private Team[] fullTeamsChecked (String fullAuthorString){
442
		Team[] result = new Team[4]; 
443
		int authorTeamStart = 0;
444
		Matcher basionymMatcher = basionymPattern.matcher(fullAuthorString);
445
		if (basionymMatcher.find(0)){
446
			
447
			String basString = basionymMatcher.group();
448
			basString = basString.replaceFirst(basStart, "");
449
			basString = basString.replaceAll(basEnd, "").trim();
450
			authorTeamStart = basionymMatcher.end(1) + 1;
451
			
452
			Team[] basTeam = authorTeamAndEx(basString);
453
			result[2]= basTeam[0];
454
			result[3]= basTeam[1];
455
		}
456
		Team[] aTeam = authorTeamAndEx(fullAuthorString.substring(authorTeamStart));
457
		result[0]= aTeam[0];
458
		result[1]= aTeam[1];
459
		return result;
460
	}
461
	
462
	
463
	/**
464
	 * Parses the author and ex-author String
465
	 * @param authorTeamString String representing the author and the ex-author team
466
	 * @return array of Teams containing the Team[0] and the ExTeam[1]
467
	 */
468
	public Team[] authorTeamAndEx (String authorTeamString){
469
		Team[] result = new Team[2]; 
470
		//TODO noch allgemeiner am anfang durch Replace etc. 
471
		authorTeamString = authorTeamString.trim();
472
		authorTeamString = authorTeamString.replaceFirst(oWs + "ex" + oWs, " ex. " ); 
473
		int authorEnd = authorTeamString.length();
474
		
475
		Matcher exAuthorMatcher = exAuthorPattern.matcher(authorTeamString);
476
		if (exAuthorMatcher.find(0)){
477
			int exAuthorBegin = exAuthorMatcher.end(0);
478
			String exString = authorTeamString.substring(exAuthorBegin).trim();
479
			authorEnd = exAuthorMatcher.start(0);
480
			result [1] = authorTeam(exString);
481
		}
482
		result [0] = authorTeam(authorTeamString.substring(0, authorEnd));
483
		return result;
484
	}
485
	
486
	
487
	/**
488
	 * Parses an authorTeam String and returns the Team 
489
	 * !!! TODO (atomization not yet implemented)
490
	 * @param authorTeamString String representing the author team
491
	 * @return an Team 
492
	 */
493
	public Team authorTeam (String authorTeamString){
494
		if (authorTeamString == null) 
495
			return null;
496
		else if ((authorTeamString = authorTeamString.trim()).length() == 0)
497
			return null;
498
		else {
499
			Team result = Team.NewInstance();
500
			result.setTitleCache(authorTeamString);
501
			//TODO result = atomizedAuthor(authorTeamString); 
502
			return result;
503
		} 
504
		
505
	}
506
	
507

  
508
	//Parsing of the given full name that has been identified as hybrid already somewhere else.
509
	private BotanicalName parseHybrid(String fullName){
510
	    logger.warn("parseHybrid --> function not yet implemented");
511
	    BotanicalName result = new BotanicalName(null);
512
	    result.setTitleCache(fullName);
513
	    return result;
514
    }
515
	
516
//	// Parsing of the given full name that has been identified as a cultivar already somwhere else.
517
//	// The ... cv. ... syntax is not covered here as it is not according the rules for naming cultivars.
518
	public BotanicalName parseCultivar(String fullName)	throws StringNotParsableException{
519
		CultivarPlantName result = null;
520
		    String[] words = oWsPattern.split(fullName);
521
			
522
		    /* ---------------------------------------------------------------------------------
523
		     * cultivar
524
		     * ---------------------------------------------------------------------------------*/
525
			if (fullName.indexOf(" '") != 0){
526
				//TODO location of 'xx' is probably not arbitrary
527
				Matcher cultivarMatcher = cultivarPattern.matcher(fullName);
528
				if (cultivarMatcher.find()){
529
					String namePart = fullName.replaceFirst(cultivar, "");
530
					
531
					String cultivarPart = cultivarMatcher.group(0).replace("'","").trim();
532
					//OLD: String cultivarPart = cultivarRE.getParen(0).replace("'","").trim();
533
					
534
					result = (CultivarPlantName)parseFullName(namePart);
535
					result.setCultivarName(cultivarPart);
536
				}	
537
			}else if (fullName.indexOf(" cv.") != 0){
538
				// cv. is old form (not official) 
539
				throw new StringNotParsableException("Cultivars with only cv. not yet implemented in name parser!");
540
			}
541
				
542
		    /* ---------------------------------------------------------------------------------
543
		     * cultivar group
544
		     * ---------------------------------------------------------------------------------
545
		     */ 
546
			// TODO in work 
547
			//Ann. this is not the official way of noting cultivar groups
548
		    String group = oWs + "Group" + oWs + capitalEpiWord + end;
549
			Pattern groupRE = Pattern.compile(group);
550
			Matcher groupMatcher = groupRE.matcher(fullName);
551
			if (groupMatcher.find()){
552
		    	if (! words[words.length - 2].equals("group")){
553
		            throw new StringNotParsableException ("fct ParseHybrid --> term before cultivar group name in " + fullName + " should be 'group'");
554
		        }else{
555
		        	
556
		        	String namePart = fullName.substring(0, groupMatcher.start(0) - 0);
557
		        	//OLD: String namePart = fullName.substring(0, groupRE.getParenStart(0) - 0);
558
		        	
559
		        	String cultivarPart = words[words.length -1];
560
		        	result = (CultivarPlantName)parseFullName(namePart);
561
		        	if (result != null){
562
		        		result.setCultivarName(cultivarPart);
563
			        	
564
		        		//OLD: result.setCultivarGroupName(cultivarPart);
565
		        	}
566
		        }
567

  
568
		    }
569
//		    // ---------------------------------------------------------------------------------
570
//		    if ( result = "" ){
571
//		        return "I: fct ParseCultivar: --> could not parse cultivar " + fullName;
572
//		    }else{
573
//		        return result;
574
	//	    }
575
			return result; //TODO
576
	}
577

  
578
	
579
    
580
    //splitter
581
    static String epiSplitter = "(\\s+|\\(|\\))"; //( ' '+| '(' | ')' )
582
    static Pattern pattern = Pattern.compile(epiSplitter); 
583
    
584
    //some useful non-terminals
585
    static String start = "^";
586
    static String end = "$";
587
    static String anyEnd = ".*" + end;
588
    static String oWs = "\\s+"; //obligatory whitespaces
589
    static String fWs = "\\s*"; //facultative whitespcace
590
    
591
    static String capitalWord = "\\p{javaUpperCase}\\p{javaLowerCase}*";
592
    static String nonCapitalWord = "\\p{javaLowerCase}+";
593
    
594
    static String capitalDotWord = capitalWord + "\\.?"; //capitalWord with facultativ '.' at the end
595
    static String nonCapitalDotWord = nonCapitalWord + "\\.?"; //nonCapitalWord with facultativ '.' at the end
596
    static String dotWord = "(" + capitalWord + "|" + nonCapitalWord + ")\\.?"; //word (capital or non-capital) with facultativ '.' at the end
597
    //Words used in an epethiton for a TaxonName
598
    static String nonCapitalEpiWord = "[a-z?\\-]+";   //TODO solve checkin Problem with Unicode character "[a-z�\\-]+";
599
    static String capitalEpiWord = "[A-Z]"+ nonCapitalEpiWord;
600
     
601
    
602
   //years
603
    static String month = "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)";
604
    static String singleYear = "\\b" + "(?:17|18|19|20)" + "\\d{2}" + "\\b";                      // word boundary followed by either 17,18,19, or 20 (not captured) followed by 2 digits 	      
605
    static String yearPhrase = "(" + singleYear + "(-" + singleYear + ")?" + 
606
    						"(" + month + ")?)" ;                 // optional month
607
    
608
    //seperator
609
    static String yearSeperator = "." + oWs;
610
    static String detailSeperator = ":" + oWs;
611
    static String referenceSeperator1 = "," + oWs ;
612
    static String inReferenceSeperator = oWs + "in" + oWs;
613
    static String referenceSeperator = "(" + referenceSeperator1 +"|" + inReferenceSeperator + ")" ;
614
    static String referenceAuthorSeperator = ","+ oWs;
615
    static String volumeSeperator = "," + fWs ;
616
    static String referenceEnd = ".";
617
     
618
    
619
    //status
620
    static String status = "";
621
    
622
    //marker
623
    static String InfraGenusMarker = "(subgen.|subg.|sect.|subsect.|ser.|subser.|t.infgen.)";
624
    static String aggrOrGroupMarker = "(aggr.|agg.|group)";
625
    static String infraSpeciesMarker = "(subsp.|convar.|var.|subvar.|f.|subf.|f.spec.|tax." + fWs + "infrasp.)";
626
    static String oldInfraSpeciesMarker = "(prol.|proles|race|taxon|sublusus)";
627
    
628
    
629
    //AuthorString
630
    static String authorPart = "(" + "(D'|L'|'t\\s)?" + capitalDotWord + "('" + nonCapitalDotWord + ")?" + "|da|de(n|l|\\sla)?)" ;
631
    static String author = "(" + authorPart + "(" + fWs + "|-)" + ")+" + "(f.|fil.|secundus)?";
632
    static String teamSplitter = fWs + "(&)" + fWs;
633
    static String authorTeam = fWs + "(" + author + teamSplitter + ")*" + author + "(" + teamSplitter + "al.)?" + fWs;
634
    static String exString = "(ex.?)";
635
    static String authorAndExTeam = authorTeam + "(" + oWs + exString + oWs + authorTeam + ")?";
636
    static String basStart = "\\(";
637
    static String basEnd = "\\)";
638
    static String basionymAuthor = basStart + "(" + authorAndExTeam + ")" + basEnd;  // '(' and ')' is for evaluation with RE.paren(x)
639
    static String fullAuthorString = fWs + "(" + basionymAuthor +")?" + fWs + authorAndExTeam + fWs;
640
    static String facultFullAuthorString = "(" +  fullAuthorString + ")?" ; 
641

  
642
    
643
    //details
644
    //TODO still very simple
645
    static String pageNumber = "\\d{1,5}";
646
    static String detail = "(" + pageNumber + ")";
647
    
648
    //reference
649
    static String volume = "\\d{4}" + "\\(\\d{4}\\)?"; 	      
650
    
651
    static String referenceTitle = "(" + dotWord + fWs + ")" + "{2,}";
652
    static String bookReference = referenceTitle + volumeSeperator +  volume;
653
    static String bookSectionReference = authorTeam + referenceAuthorSeperator;
654
    static String articleReference = inReferenceSeperator + bookReference  ; 
655
    static String reference = "(" + articleReference + "|" + bookReference +")" + 
656
    				detailSeperator + detail + yearSeperator + yearPhrase +
657
    				referenceEnd; 
658

  
659
    static Pattern referencePattern = Pattern.compile(reference);
660
    
661
    static String pNomStatusNom = "nom\\." + fWs + "(superfl\\.|nud\\.|illeg\\.|inval\\.|cons\\.|alternativ\\.|subnud.|"+
662
    					"rej\\.|rej\\."+ fWs + "prop\\.|provis\\.)";
663
    static String pNomStatusOrthVar = "orth\\." + fWs + "var\\.";
664
    static String pNomStatus = "(" + pNomStatusNom + "|" + pNomStatusOrthVar +  ")";
665
    static String pNomStatusPhrase1 = "," + fWs + pNomStatus;
666
    static String pNomStatusPhrase2 = "\\[" + fWs + pNomStatus + "\\]";
667
    
668
    static String pNomStatusPhrase = "(?:" + pNomStatusPhrase1 + "|" + pNomStatusPhrase2 + ")";
669

  
670
// Soraya
671
//opus utique oppr.
672
//pro syn.
673
//provisional synonym
674
//fossil name
675

  
676
    
677
    
678
    //cultivars and hybrids
679
    static String cultivar = oWs + "'..+'"; //Achtung mit Hochkomma in AuthorNamen
680
    static String cultivarMarker = oWs + "(cv.|')";
681
    static String hybrid = oWs + "((x|X)" + oWs + "|notho)";//= ( x )|( X )|( notho)
682
    
683
    //  Name String
684
    static String genusOrSupraGenus = capitalEpiWord;
685
    static String infraGenus = capitalEpiWord + oWs + InfraGenusMarker + oWs + capitalEpiWord;
686
    static String aggrOrGroup = capitalEpiWord + oWs + nonCapitalEpiWord + oWs + aggrOrGroupMarker;
687
    static String species = capitalEpiWord + oWs +  nonCapitalEpiWord;
688
    static String infraSpecies = capitalEpiWord + oWs +  nonCapitalEpiWord + oWs + infraSpeciesMarker + oWs + nonCapitalEpiWord;
689
    static String oldInfraSpecies = capitalEpiWord + oWs +  nonCapitalEpiWord + oWs + oldInfraSpeciesMarker + oWs + nonCapitalEpiWord;
690
    static String autonym = capitalEpiWord + oWs + "(" + nonCapitalEpiWord +")" + oWs + fullAuthorString +  oWs + infraSpeciesMarker + oWs + "\\1";  //2-nd word and last word are the same 
691
    static String anyName = "(" + genusOrSupraGenus + "|" + infraGenus + "|" + aggrOrGroup + "|" + species + "|" + 
692
    					infraSpecies + "|" + infraSpecies + "|" + oldInfraSpecies + "|" + autonym   + ")+";
693
    static String anyFullName = anyName + oWs + fullAuthorString;
694
    
695
    //Pattern
696
    static Pattern oWsPattern = Pattern.compile(oWs);
697
    static Pattern teamSplitterPattern = Pattern.compile(teamSplitter);
698
    static Pattern cultivarPattern = Pattern.compile(cultivar);
699
    static Pattern cultivarMarkerPattern = Pattern.compile(cultivarMarker);
700
    static Pattern hybridPattern = Pattern.compile(hybrid); 
701
    
702
    static Pattern genusOrSupraGenusPattern = Pattern.compile(start + genusOrSupraGenus + facultFullAuthorString + end);
703
    static Pattern infraGenusPattern = Pattern.compile(start + infraGenus + facultFullAuthorString + end);
704
    static Pattern aggrOrGroupPattern = Pattern.compile(start + aggrOrGroup + fWs + end); //aggr. or group has no author string
705
    static Pattern speciesPattern = Pattern.compile(start + species + facultFullAuthorString + end);
706
    static Pattern infraSpeciesPattern = Pattern.compile(start + infraSpecies + facultFullAuthorString + end);
707
    static Pattern oldInfraSpeciesPattern = Pattern.compile(start + oldInfraSpecies + facultFullAuthorString + end);
708
    static Pattern autonymPattern = Pattern.compile(start + autonym + fWs + end);
709
	
710
    static Pattern basionymPattern = Pattern.compile(basionymAuthor);
711
    //static Pattern startsWithBasionymRE = Pattern.compile(basionymAuthor + anyEnd);
712
        static Pattern exAuthorPattern = Pattern.compile(oWs + exString);
713
    
714
    static Pattern fullAuthorStringPattern = Pattern.compile(fullAuthorString);
715

  
716

  
717
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/ZooNameDefaultCacheStrategy.java
1
package eu.etaxonomy.cdm.strategy;
2

  
3
import java.util.UUID;
4

  
5
import org.apache.log4j.Logger;
6

  
7
import eu.etaxonomy.cdm.model.agent.Agent;
8
import eu.etaxonomy.cdm.model.agent.INomenclaturalAgent;
9
import eu.etaxonomy.cdm.model.name.NonViralName;
10
import eu.etaxonomy.cdm.model.name.ZoologicalName;
11

  
12
public class ZooNameDefaultCacheStrategy extends NameCacheStrategyBase<ZoologicalName> implements	INameCacheStrategy<ZoologicalName> {
13
	private static final Logger logger = Logger.getLogger(ZooNameDefaultCacheStrategy.class);
14
	
15
	final static UUID uuid = UUID.fromString("950c4236-8156-4675-b866-785df33bc4d9");
16

  
17
	public UUID getUuid(){
18
		return uuid;
19
	}
20
	
21
	
22
	public static ZooNameDefaultCacheStrategy NewInstance(){
23
		return new ZooNameDefaultCacheStrategy();
24
	}
25
	
26
	private ZooNameDefaultCacheStrategy(){
27
		super();
28
	}
29

  
30
	
31
	/* (non-Javadoc)
32
	 * @see eu.etaxonomy.cdm.strategy.INameCacheStrategy#getNameCache()
33
	 */
34
	// PROTOTYPE dummy implementation
35
	@Override
36
	public String getTitleCache(ZoologicalName object) {
37
		String result;
38
		ZoologicalName tn = object;
39
		result = getNameCache(object);
40
		if (tn.getPublicationYear() != null) {
41
			result = (" " + tn.getPublicationYear()).trim();	
42
		}
43
		INomenclaturalAgent team= tn.getCombinationAuthorTeam();
44
		if (team != null){
45
			if (tn.getPublicationYear() != null) {
46
				result = ",";	
47
			} 
48
			result += " " + team.getNomenclaturalTitle();
49
		}
50
		return result;
51
	}
52

  
53
}

Also available in: Unified diff