1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.verify;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portlet.blogs.model.BlogsEntry;
20  import com.liferay.portlet.blogs.service.BlogsEntryLocalServiceUtil;
21  import com.liferay.portlet.blogs.util.TrackbackVerifierUtil;
22  import com.liferay.portlet.messageboards.model.MBDiscussion;
23  import com.liferay.portlet.messageboards.model.MBMessage;
24  import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
25  
26  import java.util.List;
27  
28  /**
29   * <a href="VerifyBlogsTrackbacks.java.html"><b><i>View Source</i></b></a>
30   *
31   * <p>
32   * This class looks at every blog comment to see if it is a trackback and
33   * verifies that the source URL is a valid URL. Do not run this unless you want
34   * to do this.
35   * </p>
36   *
37   * @author Alexander Chow
38   */
39  public class VerifyBlogsTrackbacks extends VerifyProcess {
40  
41      protected void doVerify() throws Exception {
42          List<MBDiscussion> discussions =
43              MBMessageLocalServiceUtil.getDiscussions(
44                  BlogsEntry.class.getName());
45  
46          for (MBDiscussion discussion : discussions) {
47              long entryId = discussion.getClassPK();
48              long threadId = discussion.getThreadId();
49  
50              try {
51                  BlogsEntry entry = BlogsEntryLocalServiceUtil.getBlogsEntry(
52                      entryId);
53  
54                  List<MBMessage> messages =
55                      MBMessageLocalServiceUtil.getThreadMessages(threadId);
56  
57                  for (MBMessage message : messages) {
58                      TrackbackVerifierUtil.verifyPost(entry, message);
59                  }
60              }
61              catch (Exception e) {
62                  _log.error(e, e);
63              }
64          }
65      }
66  
67      private static Log _log = LogFactoryUtil.getLog(
68          VerifyBlogsTrackbacks.class);
69  
70  }