001/* 002 * Copyright 2017 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.plugins.odfweb.catalog; 017 018import java.util.Collections; 019import java.util.HashMap; 020import java.util.Map; 021 022import org.apache.avalon.framework.service.ServiceException; 023import org.apache.avalon.framework.service.ServiceManager; 024 025import org.ametys.core.ui.Callable; 026import org.ametys.odf.catalog.Catalog; 027import org.ametys.plugins.odfweb.repository.OdfPageHandler; 028import org.ametys.runtime.i18n.I18nizableText; 029import org.ametys.web.repository.page.Page; 030 031/** 032 * DAO for ODF catalog. 033 * Override {@link Catalog} to handle web specificities. 034 */ 035public class CatalogDAO extends org.ametys.odf.catalog.CatalogDAO 036{ 037 private OdfPageHandler _odfPageHandler; 038 039 @Override 040 public void service(ServiceManager smanager) throws ServiceException 041 { 042 super.service(smanager); 043 _odfPageHandler = (OdfPageHandler) smanager.lookup(OdfPageHandler.ROLE); 044 } 045 046 @Callable 047 @Override 048 public Map<String, Object> removeCatalog(String id) 049 { 050 Catalog catalog = _resolver.resolveById(id); 051 Page page = _odfPageHandler.getOdfRootPage(null, null, catalog.getName()); 052 053 if (page != null) 054 { 055 Map<String, Object> result = new HashMap<>(); 056 result.put("error", new I18nizableText("plugin.odf-web", "PLUGINS_ODFWEB_CATALOG_DELETE_ERROR_ODFROOT", Collections.singletonList(page.getTitle()))); 057 return result; 058 } 059 060 return super.removeCatalog(id); 061 062 } 063}