| 1 | package be.nikiroo.gofetch.data; |
| 2 | |
| 3 | import java.net.URL; |
| 4 | import java.util.List; |
| 5 | |
| 6 | import be.nikiroo.gofetch.support.BasicSupport; |
| 7 | import be.nikiroo.gofetch.support.Type; |
| 8 | |
| 9 | /** |
| 10 | * A news story. |
| 11 | * |
| 12 | * @author niki |
| 13 | */ |
| 14 | public class Story { |
| 15 | private Type type; |
| 16 | private String id; |
| 17 | private String title; |
| 18 | private String author; |
| 19 | private String date; |
| 20 | private String category; |
| 21 | private String details; |
| 22 | private String urlInternal; |
| 23 | private String urlExternal; |
| 24 | private String content; |
| 25 | |
| 26 | private String fullContent; |
| 27 | private List<Comment> comments; |
| 28 | |
| 29 | /** |
| 30 | * Create a news story. |
| 31 | * |
| 32 | * @param type |
| 33 | * the source {@link Type} |
| 34 | * @param id |
| 35 | * the news ID |
| 36 | * @param title |
| 37 | * the news title |
| 38 | * @param author |
| 39 | * the author name for the details |
| 40 | * @param date |
| 41 | * the post date for the details |
| 42 | * @param category |
| 43 | * the category for the details |
| 44 | * @param details |
| 45 | * some details to add to the title (author, date and category |
| 46 | * will be added in the getter if available) |
| 47 | * @param urlInternal |
| 48 | * the {@link URL} to get this news on the associated news site |
| 49 | * @param urlExternal |
| 50 | * an external {@link URL} that serve as the news' source, if any |
| 51 | * @param content |
| 52 | * the story content |
| 53 | */ |
| 54 | public Story(Type type, String id, String title, String author, |
| 55 | String date, String category, String details, String urlInternal, |
| 56 | String urlExternal, String content) { |
| 57 | this.type = type; |
| 58 | this.id = id; |
| 59 | this.title = title; |
| 60 | this.author = author; |
| 61 | this.date = date; |
| 62 | this.category = category; |
| 63 | this.details = details; |
| 64 | this.urlInternal = urlInternal; |
| 65 | this.urlExternal = urlExternal; |
| 66 | this.content = content; |
| 67 | |
| 68 | // Defaults fullContent to content |
| 69 | this.fullContent = content; |
| 70 | } |
| 71 | |
| 72 | public String getSelector() { |
| 73 | return BasicSupport.getSelector(type) + id; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * @return the id |
| 78 | */ |
| 79 | public String getId() { |
| 80 | return id; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * @return the title |
| 85 | */ |
| 86 | public String getTitle() { |
| 87 | return title; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * @return the details |
| 92 | */ |
| 93 | public String getDetails() { |
| 94 | String details = ""; |
| 95 | |
| 96 | if (category != null && !category.trim().isEmpty()) |
| 97 | details += "[" + category + "] "; |
| 98 | if (date != null && !date.trim().isEmpty()) |
| 99 | details += date + " "; |
| 100 | if (author != null && !author.trim().isEmpty()) |
| 101 | details += "(" + this.author + ") "; |
| 102 | if (this.details != null && !this.details.trim().isEmpty()) |
| 103 | details += "\n" + this.details; |
| 104 | |
| 105 | return details.trim(); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * @return the url |
| 110 | */ |
| 111 | public String getUrlInternal() { |
| 112 | return urlInternal; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * @return the urlExternal |
| 117 | */ |
| 118 | public String getUrlExternal() { |
| 119 | return urlExternal; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * @return the body |
| 124 | */ |
| 125 | public String getContent() { |
| 126 | return content; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * @return the fullContent |
| 131 | */ |
| 132 | public String getFullContent() { |
| 133 | return fullContent; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * @param fullContent |
| 138 | * the fullContent to set |
| 139 | */ |
| 140 | public void setFullContent(String fullContent) { |
| 141 | this.fullContent = fullContent; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * @return the comments |
| 146 | */ |
| 147 | public List<Comment> getComments() { |
| 148 | return comments; |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * @param comments |
| 153 | * the comments to set |
| 154 | */ |
| 155 | public void setComments(List<Comment> comments) { |
| 156 | this.comments = comments; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Find a comment or sub-comment by its id. |
| 161 | * |
| 162 | * @param id |
| 163 | * the id to look for F |
| 164 | * @return this if it has the given id, or a child of this if the child have |
| 165 | * the given id, or NULL if not |
| 166 | */ |
| 167 | public Comment getCommentById(String id) { |
| 168 | if (id != null && comments != null) { |
| 169 | for (Comment comment : comments) { |
| 170 | Comment found = comment.getById(id); |
| 171 | if (found != null) { |
| 172 | return found; |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | return null; |
| 178 | } |
| 179 | } |