001/* 002 * Copyright 2026 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.web.trash; 017 018import java.util.Optional; 019 020import javax.jcr.RepositoryException; 021 022import org.apache.cocoon.components.ContextHelper; 023import org.apache.commons.lang3.StringUtils; 024 025import org.ametys.cms.trash.TrashManager; 026import org.ametys.core.ui.Callable; 027import org.ametys.web.WebHelper; 028import org.ametys.web.trash.WebTrashElementDAO.WebTrashElementFilter; 029 030/** 031 * Override the trash manager to handle specific logic for web context 032 */ 033public class WebTrashManager extends TrashManager 034{ 035 @Override 036 // force the cms context. This method is not intended for context without site 037 @Callable(rights = "CMS_Rights_Trash", context = "/cms") 038 public void empty() throws RepositoryException 039 { 040 String siteName = WebHelper.getSiteName(ContextHelper.getRequest(_context)); 041 if (StringUtils.isNotEmpty(siteName)) 042 { 043 _trashElementDAO.empty(new WebTrashElementFilter(Optional.of(siteName), true, 0)); 044 } 045 } 046}