/**
- *
+ *
*/
package eu.etaxonomy.taxeditor.parser;
public class ParseHandler{
private TaxonNameBase taxonNameBase;
-
+
private class MatchMatrix {
List<TaxonNameBase> duplicateNames = new ArrayList<TaxonNameBase>();
-
+
List<INomenclaturalReference> duplicateReferences = new ArrayList<INomenclaturalReference>();
List<INomenclaturalReference> duplicateInReferences = new ArrayList<INomenclaturalReference>();
private NonViralName name;
private boolean doResolveInReferences;
-
+
/**
- * Creates a new instance
- *
+ * Creates a new instance
+ *
* @param textWidget
* @param name
*/
this.name = (NonViralName) HibernateProxyHelper.deproxy(name);
}
}
-
+
/**
* Factory method to create a new instance of the this class
*
*/
public static ParseHandler NewInstance(TaxonNameBase name){
return new ParseHandler(name);
-
+
}
-
+
/**
* Parses a given string and returns a <code>TaxonNameBase</code> instance with the
* results of the parsing.
// if (name.hasProblem()) {
// name.setFullTitleCache(unparsedNameString);
// }
-
+
return name;
}
-
+
public static TaxonNameBase parseName(String unparsedNameString, Rank rank){
TaxonNameBase name = nonViralNameParser.parseFullName(unparsedNameString,
PreferencesUtil.getPreferredNomenclaturalCode(), rank);
-
+
return name;
}
-
+
/**
* Creates an empty <code>TaxonNameBase</code> instance with the nomenclatural code
* currently set in preferences.
public static TaxonNameBase createEmptyName(){
return nonViralNameParser.getNonViralNameInstance("", PreferencesUtil.getPreferredNomenclaturalCode());
}
-
+
/**
* Parses the string that was entered into the text widget and returns a
* NonViralName object that resulted from the parsing process.
* @return The parsed NonViralName object
*/
public NonViralName parse(String unparsedNameString){
-
+
// String unparsedNameString = "";
// try {
// Method getText;
// // we should never get here
// StoreUtil.error(this.getClass(), "Error trying to invoke getText method", e);
// }
-
-
+
+
nonViralNameParser.parseReferencedName(name, unparsedNameString,
name.getRank(), true);
// if (name.hasProblem()) {
// name.setFullTitleCache(unparsedNameString);
// }
-
+
return name;
}
-
+
/**
* Parses the string that was entered into the text widget and returns a
* NonViralName object that resulted from the parsing process.
* @return The parsed NonViralName object
*/
public NonViralName parseAndResolveDuplicates(String unparsedNameString){
-
+
NonViralName parsedName = parse(unparsedNameString);
-
+
MatchMatrix matchMatrix = findMatches(parsedName);
-
+
resolveDuplicates(parsedName, matchMatrix);
-
+
return parsedName;
}
-
-
-
-
- /**
+
+
+
+
+ /**
* @param name The name to resolve duplicates for.
*/
private void resolveDuplicates(NonViralName name, MatchMatrix matchMatrix) {
resolveDuplicateNames(name, matchMatrix);
-
+
resolveAllDuplicateAuthors(name, matchMatrix);
-
+
resolveDuplicateReferences(name, matchMatrix);
-
- if(matchMatrix.duplicateInReferences != null)
- resolveDuplicateInReferences(name, matchMatrix);
+
+ if(matchMatrix.duplicateInReferences != null) {
+ resolveDuplicateInReferences(name, matchMatrix);
+ }
}
- /**
+ /**
* @param name The name to resolve duplicates for.
*/
private void resolveDuplicateNames(NonViralName name, MatchMatrix matchMatrix) {
-
+
if (matchMatrix.duplicateNames.size() == 1){
name = (NonViralName) matchMatrix.duplicateNames.iterator().next();
}else if(matchMatrix.duplicateNames.size() > 1){
}
}
- /**
+ /**
* @param name The name to resolve duplicates for.
*/
private void resolveDuplicateReferences(NonViralName name, MatchMatrix matchMatrix) {
if(matchMatrix.duplicateReferences.size() == 1){
// exactly one match. We assume that the user wants this reference
- INomenclaturalReference duplicate = matchMatrix.duplicateReferences.iterator().next();
+ INomenclaturalReference duplicate = matchMatrix.duplicateReferences.iterator().next();
name.setNomenclaturalReference(duplicate);
}else if(matchMatrix.duplicateReferences.size() > 1){
// FIXME TODO resolve multiple duplications. Use first match for a start
INomenclaturalReference duplicate = matchMatrix.duplicateReferences.iterator().next();
name.setNomenclaturalReference(duplicate);
- }
+ }
}
- /**
+ /**
* @param name The name to resolve duplicates for.
*/
private void resolveDuplicateInReferences(NonViralName name, MatchMatrix matchMatrix) {
Reference reference = (Reference) HibernateProxyHelper.deproxy(name.getNomenclaturalReference());
-
+
if(matchMatrix.duplicateInReferences.size() > 0){
Reference inReference = (Reference) matchMatrix.duplicateInReferences.iterator().next();
reference.setInReference(inReference);
MessagingUtils.warn(this.getClass(), reference.getTitleCache());
}
}
-
- /**
+
+ /**
* @param name The name to resolve duplicates for.
*/
private void resolveAllDuplicateAuthors(NonViralName name, MatchMatrix matchMatrix) {
-
+
if(matchMatrix.duplicateCombinationAuthorTeams.size() > 0){
name.setCombinationAuthorTeam(matchMatrix.duplicateCombinationAuthorTeams.iterator().next());
Reference reference = (Reference) name.getNomenclaturalReference();
if(reference != null){
- reference.setAuthorTeam(matchMatrix.duplicateCombinationAuthorTeams.iterator().next());
+ reference.setAuthorship(matchMatrix.duplicateCombinationAuthorTeams.iterator().next());
}
// FIXME TODO resolve multiple duplications. We use first match for a start.
}
-
+
if(matchMatrix.duplicateExCombinationAuthorTeams.size() > 0){
name.setExCombinationAuthorTeam(matchMatrix.duplicateExCombinationAuthorTeams.iterator().next());
// FIXME TODO resolve multiple duplications. We use first match for a start.
}
-
+
if(matchMatrix.duplicateBasionymAuthorTeams.size() > 0){
name.setBasionymAuthorTeam(matchMatrix.duplicateBasionymAuthorTeams.iterator().next());
// FIXME TODO resolve multiple duplications. We use first match for a start.
}
-
+
if(matchMatrix.duplicateExBasionymAuthorTeams.size() > 0){
name.setExBasionymAuthorTeam(matchMatrix.duplicateExBasionymAuthorTeams.iterator().next());
// FIXME TODO resolve multiple duplications. We use first match for a start.
}
}
-
- /**
+
+ /**
* Splits a NonViralName into its parts and calls methods to find matches for these
* parts in the database.
- *
+ *
* @param name The NonViralName to find matches for.
*/
private MatchMatrix findMatches(NonViralName name){
-
+
MatchMatrix matchMatrix = new MatchMatrix();
-
+
matchMatrix.duplicateNames = findMatchingLatinNames(name);
-
- matchMatrix.duplicateCombinationAuthorTeams = findMatchingAuthors((TeamOrPersonBase) name.getCombinationAuthorTeam());
- matchMatrix.duplicateExCombinationAuthorTeams = findMatchingAuthors((TeamOrPersonBase) name.getExCombinationAuthorTeam());
- matchMatrix.duplicateBasionymAuthorTeams = findMatchingAuthors((TeamOrPersonBase) name.getBasionymAuthorTeam());
- matchMatrix.duplicateExBasionymAuthorTeams = findMatchingAuthors((TeamOrPersonBase) name.getExBasionymAuthorTeam());
-
+
+ matchMatrix.duplicateCombinationAuthorTeams = findMatchingAuthors(name.getCombinationAuthorTeam());
+ matchMatrix.duplicateExCombinationAuthorTeams = findMatchingAuthors(name.getExCombinationAuthorTeam());
+ matchMatrix.duplicateBasionymAuthorTeams = findMatchingAuthors(name.getBasionymAuthorTeam());
+ matchMatrix.duplicateExBasionymAuthorTeams = findMatchingAuthors(name.getExBasionymAuthorTeam());
+
INomenclaturalReference nomenclaturalReference = name.getNomenclaturalReference();
-
- // check if the reference has an inreference and also check if the inReference already exists
+
+ // check if the reference has an inreference and also check if the inReference already exists
if(nomenclaturalReference != null){
Reference inReference = ((Reference)nomenclaturalReference).getInReference();
if(inReference != null){
matchMatrix.duplicateInReferences = findMatchingNomenclaturalReference(inReference);
}
}
-
+
matchMatrix.duplicateReferences = findMatchingNomenclaturalReference(nomenclaturalReference);
-
+
return matchMatrix;
}
-
+
/**
* @param nomenclaturalReference The NomenclaturalReference to find matches for.
* @return A <code>List</code> of possibly matching NomenclaturalReference's.
*/
private List<INomenclaturalReference> findMatchingNomenclaturalReference(INomenclaturalReference nomenclaturalReference) {
- if(nomenclaturalReference == null) return new ArrayList<INomenclaturalReference>();
+ if(nomenclaturalReference == null) {
+ return new ArrayList<INomenclaturalReference>();
+ }
try{
return CdmStore.getService(ICommonService.class).findMatching(nomenclaturalReference, MatchStrategyConfigurator.ReferenceMatchStrategy());
}catch (MatchException e) {
if(authorTeam == null){
return new ArrayList<TeamOrPersonBase>();
}
-
+
try{
return CdmStore.getService(ICommonService.class).findMatching(authorTeam, MatchStrategyConfigurator.TeamOrPersonMatchStrategy());
}catch (MatchException e) {
try {
return CdmStore.getService(ICommonService.class).findMatching(taxonNameBase, MatchStrategyConfigurator.NonViralNameMatchStrategy());
-
+
} catch (MatchException e) {
MessagingUtils.error(this.getClass(), "Error finding matching names", e);
}
// $Id$
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
* @version 1.0
*/
public class OpenUrlSelectorWizard extends Wizard {
-
- private MobotOpenUrlServiceWrapper openUrlServiceWrapper;
- private MobotOpenUrlQuery query;
-
+ private final MobotOpenUrlServiceWrapper openUrlServiceWrapper;
+
+ private final MobotOpenUrlQuery query;
+
private OpenUrlReference openUrlReference;
-
- private CdmFormFactory formFactory;
+
+ private final CdmFormFactory formFactory;
private URI openUrlReferenceImageUri;
-
- private Reference reference;
-
- private String referenceDetail;
-
-
-
+
+ private final Reference reference;
+
+ private final String referenceDetail;
+
+
+
/**
- * @param openUrlSelectorElement
+ * @param openUrlSelectorElement
* @param reference
*/
public OpenUrlSelectorWizard(Reference reference, String referenceDetail) {
if(reference == null){
throw new IllegalArgumentException("Reference may not be empty");
}
-
+
this.reference = reference;
this.referenceDetail = referenceDetail;
-
+
setWindowTitle("Mobot Open Url");
setNeedsProgressMonitor(true);
-
+
formFactory = new CdmFormFactory(Display.getDefault());
-
+
openUrlServiceWrapper = new MobotOpenUrlServiceWrapper();
openUrlServiceWrapper.setBaseUrl(PreferencesUtil.getPreferenceStore().getString(IPreferenceKeys.OPENURL_ACCESS_POINT));
-
+
query = new MobotOpenUrlQuery();
-
+
query.refType = ReferenceType.getReferenceType(reference);
- if(reference.getAuthorTeam() != null){
- query.authorName = reference.getAuthorTeam().getTitleCache();
+ if(reference.getAuthorship() != null){
+ query.authorName = reference.getAuthorship().getTitleCache();
}
query.abbreviation = reference.getTitle();
if(reference.getInReference() != null){
query.publicationPlace = reference.getPlacePublished();
query.publisherName = reference.getPublisher();
query.volume = reference.getVolume();
-
+
query.startPage = referenceDetail;
}
-
+
/* (non-Javadoc)
* @see org.eclipse.jface.wizard.Wizard#addPages()
*/
@Override
public void addPages() {
-
+
addPage(new OpenUrlResultPage());
addPage(new OpenUrlReferencePage());
-
+
super.addPages();
}