@@ -49,7 +49,7 @@ 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
@@ -142,13 +142,7 @@ public List<Request> getTargetRequests() {
142
142
* @param requests requests
143
143
*/
144
144
public void addTargetRequests (Iterable <String > requests ) {
145
- for (String s : requests ) {
146
- if (StringUtils .isBlank (s ) || s .equals ("#" ) || s .startsWith ("javascript:" )) {
147
- continue ;
148
- }
149
- s = UrlUtils .canonicalizeUrl (s , url .toString ());
150
- targetRequests .add (new Request (s ));
151
- }
145
+ addTargetRequests (requests , 0 ); // Default priority is 0
152
146
}
153
147
154
148
/**
@@ -158,13 +152,32 @@ public void addTargetRequests(Iterable<String> requests) {
158
152
* @param priority priority
159
153
*/
160
154
public void addTargetRequests (Iterable <String > requests , long priority ) {
161
- for (String s : requests ) {
162
- if (StringUtils .isBlank (s ) || s .equals ("#" ) || s .startsWith ("javascript:" )) {
163
- continue ;
164
- }
165
- s = UrlUtils .canonicalizeUrl (s , url .toString ());
166
- 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 );
167
179
}
180
+ targetRequests .add (req );
168
181
}
169
182
170
183
/**
0 commit comments