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, 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.ui.apps.linkvalidation;
029
030import org.opencms.file.CmsObject;
031import org.opencms.file.CmsResource;
032import org.opencms.ui.components.CmsResourceTable.I_ResourcePropertyProvider;
033import org.opencms.ui.components.CmsResourceTableProperty;
034import org.opencms.util.CmsStringUtil;
035
036import java.util.List;
037import java.util.Locale;
038import java.util.Map;
039
040import com.vaadin.v7.data.Item;
041import com.vaadin.v7.event.ItemClickEvent.ItemClickListener;
042
043/**
044 * Validator for links.<p>
045 */
046public abstract class A_CmsLinkValidator implements I_ResourcePropertyProvider {
047
048    /** Property.*/
049    protected CmsResourceTableProperty property;
050
051    /**
052     * Empty constructor.<p>
053     */
054    public A_CmsLinkValidator() {
055
056    }
057
058    /**
059     * @see org.opencms.ui.components.CmsResourceTable.I_ResourcePropertyProvider#addItemProperties(com.vaadin.v7.data.Item, org.opencms.file.CmsObject, org.opencms.file.CmsResource, java.util.Locale)
060     */
061    public void addItemProperties(Item resourceItem, CmsObject cms, CmsResource resource, Locale locale) {
062
063        String val = "";
064        if (!CmsStringUtil.isEmptyOrWhitespaceOnly(failMessage(resource))) {
065            val = failMessage(resource);
066        }
067        resourceItem.getItemProperty(property).setValue(val);
068
069    }
070
071    /**
072     * Returns resources which fail the validations.<p>
073     *
074     * @param resources to check
075     * @return List of failed resources
076     */
077    public abstract List<CmsResource> failedResources(List<String> resources);
078
079    /**
080     *  Get fail message for resource.
081     * @param resource to get message for
082     * @return Message
083     * */
084    public abstract String failMessage(CmsResource resource);
085
086    /** Get click listener
087     * @return ItemClickListener or null
088     * */
089    public abstract ItemClickListener getClickListener();
090
091    /** Get property Name.
092     * @return Name of property
093     * */
094    public abstract String getPropertyName();
095
096    /** Get all properties.
097     * @return Map of table properties
098     * */
099    public abstract Map<CmsResourceTableProperty, Integer> getTableProperties();
100
101    /**Get  table property.
102     * @return property
103     * */
104    public CmsResourceTableProperty getTableProperty() {
105
106        return property;
107    }
108
109}