|
3 | 3 | import webGrude.OkHttpBrowser; |
4 | 4 |
|
5 | 5 | import java.lang.annotation.ElementType; |
6 | | -import java.lang.annotation.Repeatable; |
7 | 6 | import java.lang.annotation.Retention; |
8 | 7 | import java.lang.annotation.RetentionPolicy; |
9 | 8 | import java.lang.annotation.Target; |
10 | 9 |
|
11 | 10 | /** |
12 | | - * Annotates a field to be mapped using a css selector. |
| 11 | + * Annotates a field to be mapped using a CSS selector. |
13 | 12 | * <p> |
14 | | - * A field annotated with this will receive the value corresponding to it's css |
| 13 | + * A field annotated with this will receive the value corresponding to its CSS |
15 | 14 | * selector when mapped. |
16 | | - * The field can be any of the following types (or its primitive): |
| 15 | + * The field can be one of the following types (or its primitive counterpart): |
17 | 16 | * <ul> |
18 | | - * <li>String</li> |
19 | | - * <li>Float</li> |
20 | | - * <li>Integer</li> |
21 | | - * <li>Boolean</li> |
22 | | - * <li>webGrude.mapping.elements.Link</li> |
23 | | - * <li>org.jsoup.nodes.Element</li> |
| 17 | + * <li>String</li> |
| 18 | + * <li>Float</li> |
| 19 | + * <li>Integer</li> |
| 20 | + * <li>Boolean</li> |
| 21 | + * <li>{@code webGrude.mapping.elements.Link}</li> |
| 22 | + * <li>{@code org.jsoup.nodes.Element}</li> |
24 | 23 | * </ul> |
25 | | - * Or a List of any of these types.<br> |
26 | | - * You can also set the field as an attribute value instead of it's text using |
27 | | - * the attr annotation value. html and outerHtml are also valid values for attr. |
28 | | - * For example: |
| 24 | + * Or a {@code List} of any of these types. |
29 | 25 | * <p> |
30 | | - * A field mapping a link with id foo |
31 | | - * </p> |
32 | | - * <pre> |
33 | | - * {@code @Selector("#foo") String fooText;} |
34 | | - * </pre> |
35 | | - * <p> |
36 | | - * A field mapping a link with id foo but receiving the href value |
37 | | - * </p> |
38 | | - * <pre> |
39 | | - * {@code @Selector(value = "#foo", attr="href") String fooText;} |
40 | | - * </pre> |
41 | | - * <p> |
42 | | - * A field mapping a link with id foo but receiving the href value |
43 | | - * </p> |
44 | | - * <pre> |
45 | | - * {@code @Selector(value = "#foo", attr="href") String fooText;} |
46 | | - * </pre> |
47 | | - * <p> |
48 | | - * A field mapping a the inner html code of a link with id foo |
49 | | - * </p> |
50 | | - * <pre> |
51 | | - * {@code @Selector(value = "#foo", attr="html") String fooHtml;} |
52 | | - * </pre> |
53 | | - * <p> |
54 | | - * A field mapping a the outer html code of a link with id foo |
55 | | - * </p> |
56 | | - * <pre> |
57 | | - * {@code @Selector(value = "#foo", attr="outerHtml") String fooOuterHtml;} |
58 | | - * </pre> |
| 26 | + * You can also extract an attribute's value instead of the element's text using |
| 27 | + * the {@code attr} attribute. Special values for {@code attr} include: |
| 28 | + * {@code "html"} (inner HTML) and {@code "outerHtml"} (entire HTML of the element). |
59 | 29 | * |
60 | 30 | * @author beothorn |
61 | 31 | * @see webGrude.mapping.annotations.Page |
|
65 | 35 | @Retention(RetentionPolicy.RUNTIME) |
66 | 36 | @Target({ElementType.FIELD}) |
67 | 37 | public @interface Selector { |
| 38 | + |
| 39 | + /** |
| 40 | + * The CSS selector used to locate the element(s). |
| 41 | + * |
| 42 | + * @return the CSS selector string |
| 43 | + */ |
68 | 44 | String value(); |
| 45 | + |
| 46 | + /** |
| 47 | + * The attribute to extract from the selected element. |
| 48 | + * If empty, the text content is used. |
| 49 | + * Special values include "html" and "outerHtml". |
| 50 | + * |
| 51 | + * @return the attribute name or empty for text content |
| 52 | + */ |
69 | 53 | String attr() default ""; |
| 54 | + |
| 55 | + /** |
| 56 | + * A formatting pattern (e.g., for dates or numbers) to apply when mapping the value. |
| 57 | + * |
| 58 | + * @return the format string |
| 59 | + */ |
70 | 60 | String format() default ""; |
| 61 | + |
| 62 | + /** |
| 63 | + * The locale to use for formatting and parsing. |
| 64 | + * Should be in the form of a language tag, e.g., "en-US". |
| 65 | + * |
| 66 | + * @return the locale string |
| 67 | + */ |
71 | 68 | String locale() default ""; |
| 69 | + |
| 70 | + /** |
| 71 | + * The default value to assign to the field if the selector does not match anything. |
| 72 | + * |
| 73 | + * @return the default value |
| 74 | + */ |
72 | 75 | String defValue() default ""; |
73 | 76 | } |
0 commit comments