1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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.portal.kernel.workflow.StatusConstants;
20  import com.liferay.portlet.blogs.model.BlogsEntry;
21  import com.liferay.portlet.blogs.service.BlogsEntryLocalServiceUtil;
22  import com.liferay.portlet.blogs.util.LinkbackConsumerUtil;
23  import com.liferay.portlet.messageboards.model.MBDiscussion;
24  import com.liferay.portlet.messageboards.model.MBMessage;
25  import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
26  
27  import java.util.List;
28  
29  /**
30   * <a href="VerifyBlogsTrackbacks.java.html"><b><i>View Source</i></b></a>
31   *
32   * <p>
33   * This class looks at every blog comment to see if it is a trackback and
34   * verifies that the source URL is a valid URL. Do not run this unless you want
35   * to do this.
36   * </p>
37   *
38   * @author Alexander Chow
39   */
40  public class VerifyBlogsTrackbacks extends VerifyProcess {
41  
42      protected void doVerify() throws Exception {
43          List<MBDiscussion> discussions =
44              MBMessageLocalServiceUtil.getDiscussions(
45                  BlogsEntry.class.getName());
46  
47          for (MBDiscussion discussion : discussions) {
48              long entryId = discussion.getClassPK();
49              long threadId = discussion.getThreadId();
50  
51              try {
52                  BlogsEntry entry = BlogsEntryLocalServiceUtil.getBlogsEntry(
53                      entryId);
54  
55                  List<MBMessage> messages =
56                      MBMessageLocalServiceUtil.getThreadMessages(
57                          threadId, StatusConstants.APPROVED);
58  
59                  for (MBMessage message : messages) {
60                      LinkbackConsumerUtil.verifyPost(entry, message);
61                  }
62              }
63              catch (Exception e) {
64                  _log.error(e, e);
65              }
66          }
67      }
68  
69      private static Log _log = LogFactoryUtil.getLog(
70          VerifyBlogsTrackbacks.class);
71  
72  }