import java.sql.PreparedStatement;\r
import java.sql.SQLException;\r
import java.util.ArrayList;\r
+import java.util.Date;\r
import java.util.HashMap;\r
import java.util.List;\r
import java.util.Set;\r
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.IdMapper;\r
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.MethodMapper;\r
import eu.etaxonomy.cdm.io.common.Source;\r
+import eu.etaxonomy.cdm.model.agent.Team;\r
import eu.etaxonomy.cdm.model.common.Annotation;\r
import eu.etaxonomy.cdm.model.common.AnnotationType;\r
import eu.etaxonomy.cdm.model.common.CdmBase;\r
*/\r
@SuppressWarnings("unused")\r
private static String getWebShowName(TaxonNameBase taxonName) {\r
- String result = null;\r
- try {\r
- if (taxonName != null) {\r
- if (taxonName != null && taxonName.isInstanceOf(NonViralName.class)) {\r
- NonViralName nonViralName = CdmBase.deproxy(taxonName, NonViralName.class);\r
- String singleWhitespace = "\\s";\r
- String multipleWhitespaces = "\\s*";\r
- String whitespaceOrNothing = "\\s?";\r
- String singleBlank = " ";\r
- String anyNumberOfCharacters = ".*";\r
- String backSlashRegEx = "\\";\r
- // String periodRegEx = "\\.";\r
- // String asterixRegEx = "\\*";\r
- String questionMarkRegEx = "\\?";\r
- // String plusRegEx = "\\+";\r
- // String squareBracketRegEx = "\\[";\r
- // String curlyBracketRegEx = "\\{";\r
- // String pipeRegEx = "\\|";\r
- // String accentRegEx = "\\^";\r
- // String dollarSignRegEx = "\\$";\r
- String openingParenthesisRegEx = "\\(";\r
- String closingParenthesisRegEx = "\\)";\r
- String openParenthesis = "(";\r
- String closeParenthesis = ")";\r
- String italicBeginTag = "<i>";\r
- String italicEndTag = "</i>";\r
- String endAnchor = "$";\r
- \r
- String questionMarkReplacement = backSlashRegEx + questionMarkRegEx;\r
- // String backSlashReplacement = backSlashRegEx + backSlashRegEx;\r
- // String periodReplacement = backSlashRegEx + periodRegEx;\r
- // String asterixReplacement = backSlashRegEx + asterixRegEx;\r
- // String plusReplacement = backSlashRegEx + plusRegEx;\r
- // String squareBracketReplacement = backSlashRegEx + squareBracketRegEx;\r
- // String curlyBracketReplacement = backSlashRegEx + curlyBracketRegEx;\r
- // String pipeReplacement = backSlashRegEx + pipeRegEx;\r
- // String accentReplacement = backSlashRegEx + accentRegEx;\r
- // String dollarSignReplacement = backSlashRegEx + dollarSignRegEx;\r
- \r
- if (nonViralName != null) {\r
- if (nonViralName.getTitleCache() != null) {\r
- try {\r
- String fullName = nonViralName.getTitleCache();\r
- \r
- // This deals with question marks that are reserved in regular expressions\r
- fullName = fullName.replaceAll(questionMarkRegEx, questionMarkReplacement);\r
-\r
- String genusOrUninomial = nonViralName.getGenusOrUninomial();\r
- String infraGenericEpithet = nonViralName.getInfraGenericEpithet();\r
- if (infraGenericEpithet != null) {\r
- infraGenericEpithet = openParenthesis + infraGenericEpithet + closeParenthesis;\r
- }\r
- String specificEpithet = nonViralName.getSpecificEpithet();\r
- String infraSpecificEpithet = nonViralName.getInfraSpecificEpithet();\r
- \r
- StringBuffer replaceFullName = new StringBuffer(fullName);\r
- List<NamePosition> genusOrUninomialPosition = getPosition(genusOrUninomial, fullName);\r
- List<NamePosition> infraGenericEpithetPosition = getPosition(infraGenericEpithet, fullName);\r
- List<NamePosition> specificEpithetPosition = getPosition(specificEpithet, fullName);\r
- List<NamePosition> authorshipPosition = getPosition(specificEpithet, fullName);\r
- if (nameExists(genusOrUninomialPosition) || nameExists(infraGenericEpithetPosition) || nameExists(specificEpithetPosition)) {\r
- replaceFullName.insert(0, italicBeginTag);\r
- \r
- if (nameExists(specificEpithetPosition)) {\r
- boolean insertSpecificEpithetEndTag = true;\r
-\r
- if ((specificEpithet.equals(infraSpecificEpithet) && countPattern(infraSpecificEpithet, fullName) == 2) |\r
- (! specificEpithet.equals(infraSpecificEpithet) && countPattern(infraSpecificEpithet, fullName) == 1)) {\r
- // infraSpecificEpithet exists\r
-\r
- // Determine position of infraSpecificEpithet\r
- int infraSpecificEpithetLocation = replaceFullName.lastIndexOf(infraSpecificEpithet);\r
- int infraSpecificEpithetBeginLocation = infraSpecificEpithetLocation;\r
- int infraSpecificEpithetEndLocation = infraSpecificEpithetLocation + infraSpecificEpithet.length();\r
- \r
- // Check whether rank information exists between specificEpithet and infraSpecificEpithet\r
- String rankExistsRegEx = specificEpithet + singleWhitespace + anyNumberOfCharacters + singleWhitespace + infraSpecificEpithet;\r
- List<NamePosition> rankPosition = getPosition(rankExistsRegEx, fullName);\r
- if (rankPosition != null && nameExists(rankPosition)) {\r
- // Rank information exists\r
-\r
- // Insert italicBeginTag\r
- replaceFullName.insert(infraSpecificEpithetBeginLocation, italicBeginTag);\r
-\r
- // Check position of infraSpecificEpithet\r
- List<NamePosition> infraSpecificEpithetPosition = getPosition(infraSpecificEpithet, fullName);\r
- if (infraSpecificEpithetPosition != null) {\r
- if (infraSpecificEpithetPosition.contains(NamePosition.end)) {\r
- // Append italicEndTag\r
- replaceFullName.append(italicEndTag);\r
- } else {\r
- // Insert italicEndTag\r
- replaceFullName.insert(infraSpecificEpithetEndLocation + italicBeginTag.length(), italicEndTag);\r
- }\r
- }\r
- } else if (rankPosition != null && ! nameExists(rankPosition)) {\r
- // Rank information does not exist\r
- insertSpecificEpithetEndTag = false;\r
- \r
- // Insert italicEndTag\r
- replaceFullName.insert(infraSpecificEpithetEndLocation, italicEndTag);\r
- }\r
- }\r
-\r
- // Insert an italicEndTag for the specificEpithet\r
- if (insertSpecificEpithetEndTag) {\r
- int specificEpithetLocation = replaceFullName.indexOf(specificEpithet) + specificEpithet.length();\r
- if (specificEpithetPosition.contains(NamePosition.end)) {\r
- replaceFullName.append(italicEndTag);\r
- } else {\r
- replaceFullName.insert(specificEpithetLocation, italicEndTag);\r
- }\r
- }\r
- } else if (nameExists(infraGenericEpithetPosition)) {\r
- int infraGenericEpithetLocation = replaceFullName.indexOf(infraGenericEpithet) + \r
- openParenthesis.length() + infraGenericEpithet.length() + closeParenthesis.length();\r
- if (infraGenericEpithetPosition.contains(NamePosition.end)) {\r
- replaceFullName.append(italicEndTag);\r
- } else {\r
- replaceFullName.insert(infraGenericEpithetLocation, italicEndTag);\r
- }\r
- } else if (nameExists(genusOrUninomialPosition)) {\r
- replaceFullName.insert(genusOrUninomial.length() + italicBeginTag.length(), italicEndTag);\r
- }\r
- }\r
- \r
- result = replaceFullName.toString();\r
-\r
- } catch (Exception e) {\r
- // This needs a workaround since very likely there is a character in the fullName that is reserved in regular expressions\r
- logger.error("WebShowName could not be determined for NonViralName " + nonViralName.getUuid() + " (" + nonViralName.getTitleCache() + "): " + e.getMessage());\r
-// e.printStackTrace();\r
- result = nonViralName.getTitleCache();\r
- }\r
- } else {\r
- logger.error("WebShowName could not be determined: TitleCache is NULL for NonViralName " + nonViralName.getUuid() + " (" + nonViralName.getTitleCache() + ")");\r
- }\r
+ String result = "";\r
+ \r
+ List taggedName = taxonName.getTaggedName();\r
+// logger.error("----------------------------------------");\r
+ boolean stringPart = false;\r
+ boolean rankPart = false;\r
+ boolean teamPart = false;\r
+ boolean datePart = false;\r
+ boolean referencePart = false;\r
+ boolean openTag = false;\r
+ boolean start = true;\r
+ for (Object object : taggedName) {\r
+ if (object instanceof String) {\r
+ // Name part\r
+// logger.error("Name part found: " + object);\r
+ if (! openTag) {\r
+ if (start) {\r
+ result = "<i>";\r
+ start = false;\r
} else {\r
- logger.error("WebShowName could not be determined: NonViralName is NULL for TaxonName" + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")");\r
+ result += " <i>";\r
}\r
- \r
+ openTag = true;\r
+ } else {\r
+ result += " ";\r
}\r
+ result += object;\r
+ stringPart = true;\r
+ } else if (object instanceof Rank) {\r
+ // Rank\r
+ Rank rank = CdmBase.deproxy(object, Rank.class);\r
+// logger.error("Rank found: " + rank.getLabel());\r
+ if (openTag) {\r
+ result += "</i> ";\r
+ openTag = false;\r
+ } else {\r
+ result += " ";\r
+ }\r
+ result += rank.getLabel(); // TODO: change to getAbbreviation()\r
+ rankPart = true;\r
+ } else if (object instanceof Team) {\r
+// logger.error("Team: " + object);\r
+ if (openTag) {\r
+ result += "</i> ";\r
+ openTag = false;\r
+ } else {\r
+ result += " ";\r
+ }\r
+ result += object;\r
+ teamPart = true;\r
+ } else if (object instanceof Date) {\r
+// logger.error("Date found: " + object);\r
+ if (openTag) {\r
+ result += "</i> ";\r
+ openTag = false;\r
+ } else {\r
+ result += " ";\r
+ }\r
+ result += object;\r
+ datePart = true;\r
+ } else if (object instanceof ReferenceBase) {\r
+// logger.error("Reference found: " + object);\r
+ if (openTag) {\r
+ result += "</i> ";\r
+ openTag = false;\r
+ } else {\r
+ result += " ";\r
+ }\r
+ result += object;\r
+ referencePart = true;\r
} else {\r
- logger.warn("WebShowName could not be determined: TaxonName is NULL");\r
+ logger.error("Instance unknown: " + object.getClass());\r
}\r
- \r
-// logger.error("final result: " + result);\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
}\r
+ if (openTag) {\r
+ result += "</i>";\r
+ }\r
+// logger.error("WebShowName: " + result);\r
+\r
return result;\r
}\r
\r