001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.util;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.repository.LocalRepository;
019    import com.liferay.portal.kernel.repository.RepositoryProviderUtil;
020    import com.liferay.portal.kernel.repository.capabilities.RepositoryEventTriggerCapability;
021    import com.liferay.portal.kernel.repository.event.RepositoryEventTrigger;
022    import com.liferay.portal.kernel.repository.event.RepositoryEventType;
023    
024    /**
025     * @author Adolfo P??rez
026     */
027    public class RepositoryUtil {
028    
029            public static RepositoryEventTrigger getFolderRepositoryEventTrigger(
030                            long folderId)
031                    throws PortalException {
032    
033                    LocalRepository localRepository =
034                            RepositoryProviderUtil.getFolderLocalRepository(folderId);
035    
036                    return getRepositoryEventTrigger(localRepository);
037            }
038    
039            public static RepositoryEventTrigger getRepositoryEventTrigger(
040                            long repositoryId)
041                    throws PortalException {
042    
043                    LocalRepository localRepository =
044                            RepositoryProviderUtil.getLocalRepository(repositoryId);
045    
046                    return getRepositoryEventTrigger(localRepository);
047            }
048    
049            protected static RepositoryEventTrigger getRepositoryEventTrigger(
050                    LocalRepository localRepository) {
051    
052                    if (localRepository.isCapabilityProvided(
053                                    RepositoryEventTriggerCapability.class)) {
054    
055                            return localRepository.getCapability(
056                                    RepositoryEventTriggerCapability.class);
057                    }
058    
059                    return _dummyRepositoryEventTrigger;
060            }
061    
062            private static final RepositoryEventTrigger _dummyRepositoryEventTrigger =
063                    new RepositoryEventTrigger() {
064    
065                            @Override
066                            public <S extends RepositoryEventType, T> void trigger(
067                                    Class<S> repositoryEventTypeClass, Class<T> modelClass,
068                                    T model) {
069                            }
070    
071                    };
072    
073    }