001/* 002 * File : 003 * Date : 004 * Version: 005 * 006 * This library is part of OpenCms - 007 * the Open Source Content Management System 008 * 009 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 010 * 011 * This library is free software; you can redistribute it and/or 012 * modify it under the terms of the GNU Lesser General Public 013 * License as published by the Free Software Foundation; either 014 * version 2.1 of the License, or (at your option) any later version. 015 * 016 * This library is distributed in the hope that it will be useful, 017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 019 * Lesser General Public License for more details. 020 * 021 * For further information about Alkacon Software GmbH & Co. KG, please see the 022 * company website: http://www.alkacon.com 023 * 024 * For further information about OpenCms, please see the 025 * project website: http://www.opencms.org 026 * 027 * You should have received a copy of the GNU Lesser General Public 028 * License along with this library; if not, write to the Free Software 029 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 030 */ 031 032package org.opencms.ui.apps.linkvalidation; 033 034import org.opencms.file.CmsObject; 035import org.opencms.main.CmsLog; 036import org.opencms.relations.CmsExternalLinksValidator; 037import org.opencms.report.A_CmsReportThread; 038import org.opencms.workplace.threads.Messages; 039 040import org.apache.commons.logging.Log; 041 042/** 043 * Thread for extern link validation. <p> 044 * 045 * @since 6.0.0 046 */ 047public class CmsExternalLinksValidatorThread extends A_CmsReportThread { 048 049 /** The log object for this class. */ 050 private static final Log LOG = CmsLog.getLog(CmsExternalLinksValidatorThread.class); 051 052 /** the CmsObject to use. */ 053 private CmsObject m_cms; 054 055 /** reference to the HtmlImport. */ 056 private CmsExternalLinksValidator m_externLinkValidator; 057 058 /**Runnable called when thread finished.*/ 059 private Runnable m_fin; 060 061 /** 062 * Constructor, creates a new CmsExternLinkValidationThread.<p> 063 * 064 * @param cms the current CmsObject 065 * @param finRun runnable called after thread is finished 066 */ 067 public CmsExternalLinksValidatorThread(CmsObject cms, Runnable finRun) { 068 069 super(cms, Messages.get().getBundle().key(Messages.GUI_POINTER_VALIDATION_THREAD_NAME_0)); 070 initHtmlReport(cms.getRequestContext().getLocale()); 071 m_cms = cms; 072 m_fin = finRun; 073 m_cms.getRequestContext().setUpdateSessionEnabled(false); 074 m_externLinkValidator = new CmsExternalLinksValidator(); 075 m_externLinkValidator.setReport(getReport()); 076 } 077 078 /** 079 * @see org.opencms.report.A_CmsReportThread#getReportUpdate() 080 */ 081 @Override 082 public String getReportUpdate() { 083 084 return getReport().getReportUpdate(); 085 } 086 087 /** 088 * The run method which starts the import process.<p> 089 */ 090 @Override 091 public void run() { 092 093 try { 094 // do the validation 095 m_externLinkValidator.validateLinks(m_cms); 096 } catch (Throwable e) { 097 getReport().println(e); 098 if (LOG.isErrorEnabled()) { 099 LOG.error(e.getLocalizedMessage()); 100 } 101 } 102 if (m_fin != null) { 103 m_fin.run(); 104 } 105 } 106}