@@ -49,15 +49,34 @@ public class Page {
49
49
50
50
private byte [] bytes ;
51
51
52
- private List <Request > targetRequests = new ArrayList <Request >();
52
+ private List <Request > targetRequests = new ArrayList <>();
53
53
54
54
private String charset ;
55
55
56
56
public Page () {
57
57
}
58
58
59
- public static Page fail (){
59
+ /**
60
+ * Returns a {@link Page} with {@link #downloadSuccess} is {@code false}.
61
+ *
62
+ * @return the page.
63
+ * @deprecated Use {@link #fail(Request)} instead.
64
+ */
65
+ @ Deprecated
66
+ public static Page fail () {
67
+ return fail (null );
68
+ }
69
+
70
+ /**
71
+ * Returns a {@link Page} with {@link #downloadSuccess} is {@code false},
72
+ * and {@link #request} is specified.
73
+ *
74
+ * @return the page.
75
+ * @since 0.10.0
76
+ */
77
+ public static Page fail (Request request ){
60
78
Page page = new Page ();
79
+ page .setRequest (request );
61
80
page .setDownloadSuccess (false );
62
81
return page ;
63
82
}
@@ -123,13 +142,7 @@ public List<Request> getTargetRequests() {
123
142
* @param requests requests
124
143
*/
125
144
public void addTargetRequests (Iterable <String > requests ) {
126
- for (String s : requests ) {
127
- if (StringUtils .isBlank (s ) || s .equals ("#" ) || s .startsWith ("javascript:" )) {
128
- continue ;
129
- }
130
- s = UrlUtils .canonicalizeUrl (s , url .toString ());
131
- targetRequests .add (new Request (s ));
132
- }
145
+ addTargetRequests (requests , 0 ); // Default priority is 0
133
146
}
134
147
135
148
/**
@@ -139,13 +152,32 @@ public void addTargetRequests(Iterable<String> requests) {
139
152
* @param priority priority
140
153
*/
141
154
public void addTargetRequests (Iterable <String > requests , long priority ) {
142
- for (String s : requests ) {
143
- if (StringUtils .isBlank (s ) || s .equals ("#" ) || s .startsWith ("javascript:" )) {
144
- continue ;
145
- }
146
- s = UrlUtils .canonicalizeUrl (s , url .toString ());
147
- targetRequests .add (new Request (s ).setPriority (priority ));
155
+ if (requests == null ) {
156
+ return ;
157
+ }
158
+
159
+ for (String req : requests ) {
160
+ addRequestIfValid (req , priority );
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Helper method to add a request if it's valid.
166
+ *
167
+ * @param url URL to add
168
+ * @param priority Priority for the URL
169
+ */
170
+ private void addRequestIfValid (String url , long priority ) {
171
+ if (StringUtils .isBlank (url ) || url .equals ("#" ) || url .startsWith ("javascript:" )) {
172
+ return ;
173
+ }
174
+
175
+ String canonicalizedUrl = UrlUtils .canonicalizeUrl (url , this .url .toString ());
176
+ Request req = new Request (canonicalizedUrl );
177
+ if (priority > 0 ) {
178
+ req .setPriority (priority );
148
179
}
180
+ targetRequests .add (req );
149
181
}
150
182
151
183
/**
0 commit comments