🔀 Merge branch 'website/epic-games' into next
[rhynodge.git] / src / main / java / net / pterodactylus / rhynodge / states / HtmlState.java
1 /*
2  * Rhynodge - HtmlState.java - Copyright Â© 2013 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.rhynodge.states;
19
20 import javax.annotation.Nonnull;
21 import javax.annotation.Nullable;
22
23 import net.pterodactylus.rhynodge.State;
24
25 import org.jsoup.nodes.Document;
26
27 /**
28  * {@link State} implementation that contains a parsed HTML {@link Document}.
29  *
30  * @author <a href="mailto:bombe@pterodactylus.net">David â€˜Bombe’ Roden</a>
31  */
32 public class HtmlState extends AbstractState {
33
34         /** The URI of the parsed document. */
35         private final String uri;
36
37         /** The parsed document. */
38         private final Document document;
39
40         /**
41          * Creates a new HTML state.
42          *
43          * @param uri
44          *            The URI of the parsed document
45          * @param document
46          *            The parsed documnet
47          */
48         public HtmlState(String uri, Document document) {
49                 this.uri = uri;
50                 this.document = document;
51         }
52
53         //
54         // ACCESSORS
55         //
56
57         @Override
58         public boolean isEmpty() {
59                 return false;
60         }
61
62         /**
63          * Returns the URI of the parsed document.
64          *
65          * @return The URI of the parsed document
66          */
67         public String uri() {
68                 return uri;
69         }
70
71         /**
72          * Returns the parsed document.
73          *
74          * @return The parsed document
75          */
76         public Document document() {
77                 return document;
78         }
79
80         @Nonnull
81         @Override
82         protected String plainText() {
83                 //noinspection ConstantConditions
84                 return htmlText();
85         }
86
87         @Nullable
88         @Override
89         protected String htmlText() {
90                 return document.toString();
91         }
92
93         //
94         // OBJECT METHODS
95         //
96
97         /**
98          * {@inheritDoc}
99          */
100         @Override
101         public String toString() {
102                 return String.format("%s[document=(%s chars)]", getClass().getSimpleName(), document().toString().length());
103         }
104
105 }