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 (https://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: https://www.alkacon.com
023 *
024 * For further information about OpenCms, please see the
025 * project website: https://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.workplace.threads;
033
034import org.opencms.file.CmsObject;
035import org.opencms.main.CmsLog;
036import org.opencms.relations.CmsExternalLinksValidator;
037import org.opencms.report.A_CmsReportThread;
038
039import org.apache.commons.logging.Log;
040
041/**
042 * Thread for extern link validation. <p>
043 *
044 * @since 6.0.0
045 */
046public class CmsExternalLinksValidatorThread extends A_CmsReportThread {
047
048    /** The log object for this class. */
049    private static final Log LOG = CmsLog.getLog(CmsExternalLinksValidatorThread.class);
050
051    /** the CmsObject to use. */
052    private CmsObject m_cms;
053
054    /** reference to the HtmlImport. */
055    private CmsExternalLinksValidator m_externLinkValidator;
056
057    /**
058     * Constructor, creates a new CmsExternLinkValidationThread.<p>
059     *
060     * @param cms the current CmsObject
061     */
062    public CmsExternalLinksValidatorThread(CmsObject cms) {
063
064        super(cms, Messages.get().getBundle().key(Messages.GUI_POINTER_VALIDATION_THREAD_NAME_0));
065        initHtmlReport(cms.getRequestContext().getLocale());
066        m_cms = cms;
067        m_cms.getRequestContext().setUpdateSessionEnabled(false);
068        m_externLinkValidator = new CmsExternalLinksValidator();
069        m_externLinkValidator.setReport(getReport());
070    }
071
072    /**
073     * @see org.opencms.report.A_CmsReportThread#getReportUpdate()
074     */
075    @Override
076    public String getReportUpdate() {
077
078        return getReport().getReportUpdate();
079    }
080
081    /**
082     * The run method which starts the import process.<p>
083     */
084    @Override
085    public void run() {
086
087        try {
088            // do the validation
089            m_externLinkValidator.validateLinks(m_cms);
090        } catch (Throwable e) {
091            getReport().println(e);
092            if (LOG.isErrorEnabled()) {
093                LOG.error(e.getLocalizedMessage());
094            }
095        }
096    }
097}