@@ -202,12 +202,79 @@ public T toFile(File parent, String child) throws IOException {
202
202
return toFile (new File (parent , child ));
203
203
}
204
204
205
+ /**
206
+ * Ping search engine that sitemap has changed. For Google it will call this URL:
207
+ * https://www.google.com/ping?sitemap=URL_Encoded_sitemapUrl
208
+ *
209
+ * @param searchEngines Search engines to ping
210
+ * @param sitemapUrl sitemap url
211
+ */
212
+ public void ping (String sitemapUrl , SearchEngine ... searchEngines ) {
213
+ for (SearchEngine searchEngine : searchEngines ) {
214
+ ping (searchEngine .getPingUrl (), sitemapUrl , searchEngine .getPrettyName ());
215
+ }
216
+ }
217
+
218
+ /**
219
+ * Ping search engine that sitemap has changed. Sitemap must be on this location:
220
+ * baseUrl/sitemap.xml (for example http://www.javavids.com/sitemap.xml)
221
+ *
222
+ * @param doNotThrowExceptionOnFailure If this is true and it's not possible to ping search engine,
223
+ * this method won't throw any exception, but will return false.
224
+ * @param searchEngines Search engines to ping
225
+ * @return If operation succeeded
226
+ */
227
+ public boolean ping (boolean doNotThrowExceptionOnFailure , SearchEngine ... searchEngines ) {
228
+ try {
229
+ ping (searchEngines );
230
+ return true ;
231
+ } catch (Exception e ) {
232
+ if (doNotThrowExceptionOnFailure ) {
233
+ return false ;
234
+ }
235
+ throw e ;
236
+ }
237
+ }
238
+
239
+ /**
240
+ * Ping search engine that sitemap has changed. For Google it will call this URL:
241
+ * https://www.google.com/ping?sitemap=URL_Encoded_sitemapUrl
242
+ *
243
+ * @param sitemapUrl sitemap url
244
+ * @param doNotThrowExceptionOnFailure If this is true and it's not possible to ping search engine,
245
+ * this method won't throw any exception, but will return false.
246
+ * @param searchEngines Search engines to ping
247
+ * @return If operation succeeded
248
+ */
249
+ public boolean ping (String sitemapUrl , boolean doNotThrowExceptionOnFailure , SearchEngine ... searchEngines ) {
250
+ try {
251
+ ping (sitemapUrl , searchEngines );
252
+ return true ;
253
+ } catch (Exception e ) {
254
+ if (doNotThrowExceptionOnFailure ) {
255
+ return false ;
256
+ }
257
+ throw e ;
258
+ }
259
+ }
260
+
261
+ /**
262
+ * Ping search engine that sitemap has changed. Sitemap must be on this location:
263
+ * baseUrl/sitemap.xml (for example http://www.javavids.com/sitemap.xml)
264
+ * @param searchEngines Search engines to ping
265
+ */
266
+ public void ping (SearchEngine ... searchEngines ) {
267
+ ping (baseUrl + "sitemap.xml" , searchEngines );
268
+ }
269
+
205
270
/**
206
271
* Ping Google that sitemap has changed. Will call this URL:
207
272
* https://www.google.com/ping?sitemap=URL_Encoded_sitemapUrl
208
273
*
209
274
* @param sitemapUrl sitemap url
275
+ * @deprecated Use {@link #ping(String, SearchEngine...)}
210
276
*/
277
+ @ Deprecated
211
278
public void pingGoogle (String sitemapUrl ) {
212
279
ping ("https://www.google.com/ping?sitemap=" , sitemapUrl , "Google" );
213
280
}
@@ -220,7 +287,9 @@ public void pingGoogle(String sitemapUrl) {
220
287
* @param doNotThrowExceptionOnFailure If this is true and it's not possible to ping google,
221
288
* this method won't throw any exception, but will return false.
222
289
* @return If operation succeeded
290
+ * @deprecated Use {@link #ping(String, boolean, SearchEngine...)}
223
291
*/
292
+ @ Deprecated
224
293
public boolean pingGoogle (String sitemapUrl , boolean doNotThrowExceptionOnFailure ) {
225
294
try {
226
295
pingGoogle (sitemapUrl );
@@ -238,7 +307,9 @@ public boolean pingGoogle(String sitemapUrl, boolean doNotThrowExceptionOnFailur
238
307
* https://www.bing.com/ping?sitemap=URL_Encoded_sitemapUrl
239
308
*
240
309
* @param sitemapUrl sitemap url
310
+ * @deprecated Use {@link #ping(String, SearchEngine...)}
241
311
*/
312
+ @ Deprecated
242
313
public void pingBing (String sitemapUrl ) {
243
314
ping ("https://www.bing.com/ping?sitemap=" , sitemapUrl , "Bing" );
244
315
}
@@ -251,7 +322,9 @@ public void pingBing(String sitemapUrl) {
251
322
* @param doNotThrowExceptionOnFailure If this is true and it's not possible to ping google,
252
323
* this method won't throw any exception, but will return false.
253
324
* @return If operation succeeded
325
+ * @deprecated Use {@link #ping(String, boolean, SearchEngine...)}
254
326
*/
327
+ @ Deprecated
255
328
public boolean pingBing (String sitemapUrl , boolean doNotThrowExceptionOnFailure ) {
256
329
try {
257
330
pingBing (sitemapUrl );
@@ -264,23 +337,13 @@ public boolean pingBing(String sitemapUrl, boolean doNotThrowExceptionOnFailure)
264
337
}
265
338
}
266
339
267
- private void ping (String resourceUrl , String sitemapUrl , String serviceName ) {
268
- try {
269
- String pingUrl = resourceUrl + URLEncoder .encode (sitemapUrl , "UTF-8" );
270
- // ping Google / Bing
271
- int returnCode = httpClient .get (pingUrl );
272
- if (returnCode != 200 ) {
273
- throw new WebmasterToolsException (serviceName + " could not be informed about new sitemap!" );
274
- }
275
- } catch (Exception ex ) {
276
- throw new WebmasterToolsException (serviceName + " could not be informed about new sitemap!" );
277
- }
278
- }
279
-
280
340
/**
281
341
* Ping Google that sitemap has changed. Sitemap must be on this location:
282
342
* baseUrl/sitemap.xml (for example http://www.javavids.com/sitemap.xml)
343
+ *
344
+ * @deprecated Use {@link #ping(SearchEngine...)}
283
345
*/
346
+ @ Deprecated
284
347
public void pingGoogle () {
285
348
pingGoogle (baseUrl + "sitemap.xml" );
286
349
}
@@ -292,7 +355,9 @@ public void pingGoogle() {
292
355
* @param doNotThrowExceptionOnFailure If this is true and it's not possible to ping google,
293
356
* this method won't throw any exception, but will return false.
294
357
* @return If operation succeeded
358
+ * @deprecated Use {@link #ping(boolean, SearchEngine...)}
295
359
*/
360
+ @ Deprecated
296
361
public boolean pingGoogle (boolean doNotThrowExceptionOnFailure ) {
297
362
try {
298
363
pingGoogle ();
@@ -308,7 +373,10 @@ public boolean pingGoogle(boolean doNotThrowExceptionOnFailure) {
308
373
/**
309
374
* Ping Google that sitemap has changed. Sitemap must be on this location:
310
375
* baseUrl/sitemap.xml (for example http://www.javavids.com/sitemap.xml)
376
+ *
377
+ * @deprecated Use {@link #ping(SearchEngine...)}
311
378
*/
379
+ @ Deprecated
312
380
public void pingBing () {
313
381
pingBing (baseUrl + "sitemap.xml" );
314
382
}
@@ -320,7 +388,9 @@ public void pingBing() {
320
388
* @param doNotThrowExceptionOnFailure If this is true and it's not possible to ping google,
321
389
* this method won't throw any exception, but will return false.
322
390
* @return If operation succeeded
391
+ * @deprecated Use {@link #ping(boolean, SearchEngine...)}
323
392
*/
393
+ @ Deprecated
324
394
public boolean pingBing (boolean doNotThrowExceptionOnFailure ) {
325
395
try {
326
396
pingBing ();
@@ -333,6 +403,19 @@ public boolean pingBing(boolean doNotThrowExceptionOnFailure) {
333
403
}
334
404
}
335
405
406
+ private void ping (String resourceUrl , String sitemapUrl , String serviceName ) {
407
+ try {
408
+ String pingUrl = resourceUrl + URLEncoder .encode (sitemapUrl , "UTF-8" );
409
+ // ping Google / Bing
410
+ int returnCode = httpClient .get (pingUrl );
411
+ if (returnCode != 200 ) {
412
+ throw new WebmasterToolsException (serviceName + " could not be informed about new sitemap!" );
413
+ }
414
+ } catch (Exception ex ) {
415
+ throw new WebmasterToolsException (serviceName + " could not be informed about new sitemap!" );
416
+ }
417
+ }
418
+
336
419
@ Override
337
420
protected void beforeAddPageEvent (WebPage webPage ) {
338
421
if (defaultDir != null && webPage .getDir () == null ) {
0 commit comments