001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.relations;
029
030import org.opencms.i18n.CmsMessages;
031
032import java.util.Date;
033import java.util.Iterator;
034import java.util.Locale;
035import java.util.Map;
036import java.util.Map.Entry;
037
038/**
039 * Stores the result of a pointer link validation. <p>
040 *
041 * @since 6.0.0
042 */
043public class CmsExternalLinksValidationResult {
044
045    /**  The broken links that were found.<p> */
046    private Map<String, String> m_brokenLinks;
047
048    /**  The date of the validation.<p> */
049    private Date m_validationDate;
050
051    /**
052     * Constructs a new pointer link validation result.<p>
053     *
054     * @param brokenLinks a list of the broken links
055     */
056    public CmsExternalLinksValidationResult(Map<String, String> brokenLinks) {
057
058        m_brokenLinks = brokenLinks;
059        m_validationDate = new Date();
060    }
061
062    /**
063     * Returns a Html representation of this pointer link validation result.<p>
064     *
065     * @param locale the Locale to display the result in
066     *
067     * @return a Html representation of this external link validation result
068     */
069    public String toHtml(Locale locale) {
070
071        CmsMessages mg = Messages.get().getBundle(locale);
072        if (m_brokenLinks.size() > 0) {
073            StringBuffer result = new StringBuffer(1024);
074            Iterator<Entry<String, String>> brokenLinks = m_brokenLinks.entrySet().iterator();
075            result.append(mg.key(Messages.GUI_LINK_VALIDATION_RESULTS_INTRO_1, new Object[] {m_validationDate})).append(
076                "<ul>");
077            while (brokenLinks.hasNext()) {
078                Entry<String, String> link = brokenLinks.next();
079                String linkPath = link.getKey();
080                String linkUrl = link.getValue();
081                String msg = mg.key(Messages.GUI_LINK_POINTING_TO_2, new Object[] {linkPath, linkUrl});
082                result.append("<li>").append(msg).append("</li>");
083            }
084            return result.append("</ul>").toString();
085        } else {
086            return mg.key(Messages.GUI_LINK_VALIDATION_RESULTS_ALL_VALID_1, new Object[] {m_validationDate});
087        }
088    }
089}