@@ -49,15 +49,34 @@ public class Page {
4949
5050 private byte [] bytes ;
5151
52- private List <Request > targetRequests = new ArrayList <Request >();
52+ private List <Request > targetRequests = new ArrayList <>();
5353
5454 private String charset ;
5555
5656 public Page () {
5757 }
5858
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 ){
6078 Page page = new Page ();
79+ page .setRequest (request );
6180 page .setDownloadSuccess (false );
6281 return page ;
6382 }
@@ -123,13 +142,7 @@ public List<Request> getTargetRequests() {
123142 * @param requests requests
124143 */
125144 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
133146 }
134147
135148 /**
@@ -139,13 +152,32 @@ public void addTargetRequests(Iterable<String> requests) {
139152 * @param priority priority
140153 */
141154 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 );
148179 }
180+ targetRequests .add (req );
149181 }
150182
151183 /**
0 commit comments