Project

General

Profile

Download (9.67 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2

    
3
/**
4
 * Copyright (C) 2009 EDIT
5
 * European Distributed Institute of Taxonomy
6
 * http://www.e-taxonomy.eu
7
 *
8
 * The contents of this file are subject to the Mozilla Public License Version 1.1
9
 * See LICENSE.TXT at the top of this package for the full license terms.
10
 */
11
package eu.etaxonomy.dataportal.pages;
12

    
13
import java.net.MalformedURLException;
14
import java.util.ArrayList;
15
import java.util.List;
16
import java.util.UUID;
17

    
18
import org.apache.log4j.Logger;
19
import org.openqa.selenium.By;
20
import org.openqa.selenium.WebDriver;
21
import org.openqa.selenium.WebElement;
22
import org.openqa.selenium.support.CacheLookup;
23
import org.openqa.selenium.support.FindBy;
24

    
25
import eu.etaxonomy.dataportal.DataPortalContext;
26
import eu.etaxonomy.dataportal.ElementUtils;
27
import eu.etaxonomy.dataportal.elements.BaseElement;
28
import eu.etaxonomy.dataportal.elements.LinkElement;
29
import eu.etaxonomy.dataportal.elements.TypeDesignationElement;
30

    
31
/**
32
 * TODO: subpages like /cdm_dataportal/taxon/{uuid}/images are not jet suported, implement means to handle page parts
33
 *
34
 * @author andreas
35
 * @date Jul 1, 2011
36
 *
37
 */
38
public class TaxonSynonymyPage extends PortalPage {
39

    
40
    public static final Logger logger = Logger.getLogger(TaxonSynonymyPage.class);
41

    
42
    private UUID taxonUuid;
43

    
44
    protected static String drupalPagePathBase = "cdm_dataportal/taxon";
45

    
46
    /* (non-Javadoc)
47
     * @see eu.etaxonomy.dataportal.pages.PortalPage#getDrupalPageBase()
48
     */
49
    @Override
50
    protected String getDrupalPageBase() {
51
        return drupalPagePathBase;
52
    }
53

    
54
    @FindBy(id = "synonymy")
55
    @CacheLookup
56
    private WebElement synonymy;
57

    
58

    
59

    
60
    /**
61
     * @param driver
62
     * @param context
63
     * @param taxonUuid
64
     * @throws MalformedURLException
65
     */
66
    public TaxonSynonymyPage(WebDriver driver, DataPortalContext context, UUID taxonUuid) throws MalformedURLException {
67

    
68
        super(driver, context, taxonUuid.toString() + "/synonymy");
69

    
70
        this.taxonUuid = taxonUuid;
71
    }
72

    
73

    
74
    /**
75
     * @param driver
76
     * @param context
77
     * @throws Exception
78
     */
79
    public TaxonSynonymyPage(WebDriver driver, DataPortalContext context) throws Exception {
80
        super(driver, context);
81
    }
82

    
83

    
84

    
85
    /**
86
     * @return
87
     */
88
    public String getAcceptedNameText() {
89
        return getAcceptedName().getText();
90
    }
91

    
92
    /**
93
     * @return
94
     */
95
    public WebElement getAcceptedName() {
96
        WebElement acceptedName = synonymy.findElement(
97
                By.xpath("./div[contains(@class,'accepted-name')]")
98
        );
99
        return acceptedName;
100
    }
101

    
102
    /**
103
     * TypeDesignation of the accepted name are found in the HomotypicalGroup block element
104
     * thus this method will delegate to {@link #getHomotypicalGroupTypeDesignations()}
105
     * @return
106
     * @deprecated use {@link #getHomotypicalGroupTypeDesignations()} instead
107
     */
108
    @Deprecated
109
    public List<TypeDesignationElement> getAcceptedNameTypeDesignations() {
110
        return getHomotypicalGroupTypeDesignations();
111
    }
112

    
113
    /**
114
     * @return the getHomotypicalGroupFootNoteKeys()
115
     */
116
    public List<LinkElement> getAcceptedNameFootNoteKeys() {
117
        List<WebElement> fnkListElements = synonymy.findElements(
118
                By.xpath("./div[contains(@class,'accepted-name')]/following-sibling::span[contains(@class, 'footnote-key')]/a")
119
        );
120
        return ElementUtils.linkElementsFromFootNoteKeyListElements(fnkListElements);
121
    }
122

    
123
    /**
124
     * Footnotes of the accepted name are found in the HomotypicalGroup block element
125
     * thus this method will delegate to {@link #getHomotypicalGroupFootNotes()}
126
     *
127
     * @return
128
     * @deprecated
129
     */
130
    @Deprecated
131
    public List<BaseElement> getAcceptedNameFootNotes() {
132
//        List<WebElement> fnListElements = synonymy.findElements(
133
//                By.xpath("./div[contains(@class,'accepted-name')]/following-sibling::ul[contains(@class, 'footnotes')]/li[contains(@class, 'footnotes')]/span[contains(@class, 'footnote')]")
134
//        );
135
//        return ElementUtils.baseElementsFromFootNoteListElements(fnListElements);
136
        return getHomotypicalGroupFootNotes();
137
    }
138

    
139
    /**
140
     * @param synonymIndex
141
     *            the 1-based position of the synonym in the list of homotypical
142
     *            synonyms
143
     * @return the full text line of the synonym including the prepending symbol
144
     *         and all information rendered after the name. All whitespace is
145
     *         normalized to the SPACE character.
146
     */
147
    public String getHomotypicalGroupSynonymName(Integer synonymIndex) {
148
        WebElement synonym = getHomotypicalGroupSynonym(synonymIndex);
149
        return synonym.getText().replaceAll("\\s", " ");
150
    }
151

    
152

    
153
    /**
154
     * @param synonymIndex the 1-based index of the synonym in the group
155
     * @return
156
     */
157
    public WebElement getHomotypicalGroupSynonym(Integer synonymIndex) {
158
        WebElement synonym = synonymy.findElement(
159
                By.xpath("./div[contains(@class,'homotypic-synonymy-group')]/ul[contains(@class,'homotypicSynonyms')]/li[" + synonymIndex + "]")
160
        );
161
        return synonym;
162
    }
163

    
164
    /**
165
     * @return
166
     */
167
    public List<TypeDesignationElement> getHomotypicalGroupTypeDesignations() {
168
        List<WebElement> typeDesignationElements = synonymy.findElements(By
169
                .xpath("./div[contains(@class,'homotypic-synonymy-group')]/ul[contains(@class,'homotypicSynonyms')]/ul[contains(@class,'typeDesignations')]/li"));
170
        List<TypeDesignationElement> typeDesignations = new ArrayList<TypeDesignationElement>();
171
        for (WebElement el : typeDesignationElements) {
172
            typeDesignations.add(new TypeDesignationElement(el));
173
        }
174
        return typeDesignations;
175
    }
176

    
177
    public List<LinkElement> getHomotypicalGroupFootNoteKeys() {
178
        List<WebElement> fnkListElements = synonymy.findElements(
179
                By.xpath("./div[contains(@class,'homotypic-synonymy-group')]/ul[contains(@class,'homotypicSynonyms')]/*/span[contains(@class, 'footnote-key')]/a")
180
        );
181
        return ElementUtils.linkElementsFromFootNoteKeyListElements(fnkListElements);
182
    }
183

    
184
    public List<BaseElement> getHomotypicalGroupFootNotes() {
185
        List<WebElement> fnListElements = synonymy.findElements(
186
                By.xpath("./div[contains(@class,'homotypic-synonymy-group')]/ul[contains(@class,'footnotes')]/li[contains(@class, 'footnotes')]/span[contains(@class, 'footnote')]")
187
        );
188
        return ElementUtils.baseElementsFromFootNoteListElements(fnListElements);
189

    
190
    }
191

    
192

    
193

    
194
    /**
195
     * @param heterotypicalGroupIndex
196
     *            the 1-based index of the heterotypical group
197
     * @param synonymIndex
198
     *            the 1-based position of the synonym in the list specified
199
     *            group of heterotypical synonyms
200
     * @return the full text line of the synonym including the prepending symbol
201
     *         and all information rendered after the name. All whitespace is
202
     *         normalized to the SPACE character.
203
     */
204
    public String getHeterotypicalGroupSynonymName(Integer heterotypicalGroupIndex, Integer synonymIndex) {
205
        WebElement synonym = getHeterotypicalGroupSynonym(heterotypicalGroupIndex, synonymIndex);
206
        return synonym.getText().replaceAll("\\s", " ");
207
    }
208

    
209

    
210
    /**
211
     * @param heterotypicalGroupIndex
212
     *            the 1-based index of the heterotypical group
213
     * @param synonymIndex
214
     *            the 1-based position of the synonym in the list specified
215
     *            group of heterotypical synonyms
216
     * @return
217
     */
218
    public WebElement getHeterotypicalGroupSynonym(Integer heterotypicalGroupIndex, Integer synonymIndex) {
219
        WebElement synonym = synonymy.findElement(By.xpath("./div[contains(@class,'heterotypic-synonymy-group')][" + heterotypicalGroupIndex + "]/ul[contains(@class,'heterotypicSynonymyGroup')]/li[" + synonymIndex + "]"));
220
        return synonym;
221
    }
222

    
223
    /**
224
     * @param heterotypicalGroupIndex
225
     *            the 1-based index of the heterotypical group
226
     * @return
227
     */
228
    public List<TypeDesignationElement> getHeterotypicalGroupTypeDesignations(Integer heterotypicalGroupIndex) {
229
        List<WebElement> typeDesignationElements = synonymy.findElements(By
230
                .xpath("./div[contains(@class,'heterotypic-synonymy-group')][" + heterotypicalGroupIndex
231
                        + "]/ul[contains(@class,'heterotypicSynonymyGroup')]/ul[contains(@class,'typeDesignations')]/li"));
232
        List<TypeDesignationElement> typeDesignations = new ArrayList<TypeDesignationElement>();
233
        for (WebElement el : typeDesignationElements) {
234
            typeDesignations.add(new TypeDesignationElement(el));
235
        }
236
        return typeDesignations;
237
    }
238

    
239
    /**
240
     * @param heterotypicalGroupIndex
241
     * 				the 1-based index of the heterotypical group
242
     * @return
243
     */
244
    public List<LinkElement> getHeterotypicalGroupFootNoteKeys(Integer heterotypicalGroupIndex) {
245
        List<WebElement> fnkListElements = synonymy.findElements(
246
                By.xpath("./div[contains(@class,'heterotypic-synonymy-group')][" + heterotypicalGroupIndex + "]/ul/*/*/span[contains(@class, 'footnote-key')]/a")
247
         );
248
        return ElementUtils.linkElementsFromFootNoteKeyListElements(fnkListElements);
249
    }
250

    
251
    /**
252
     * @param heterotypicalGroupIndex
253
     * 				the 1-based index of the heterotypical group
254
     * @return
255
     */
256
    public List<BaseElement> getHeterotypicalGroupFootNotes(Integer heterotypicalGroupIndex) {
257
        List<WebElement> fnListElements = synonymy.findElements(
258
                By.xpath("./div[contains(@class,'heterotypic-synonymy-group')][" + heterotypicalGroupIndex + "]/ul/li[contains(@class, 'footnotes')]/span[contains(@class, 'footnote')]")
259
        );
260
        return ElementUtils.baseElementsFromFootNoteListElements(fnListElements);
261
    }
262

    
263
}
(6-6/6)