001/* 002 * Copyright 2025 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.cms.trash.element; 017 018import java.util.Collection; 019import java.util.List; 020 021import javax.jcr.Node; 022 023import org.apache.avalon.framework.service.ServiceException; 024import org.apache.avalon.framework.service.ServiceManager; 025 026import org.ametys.cms.repository.DefaultIndexableTraversableAmetysObjectFactory; 027import org.ametys.cms.trash.model.TrashElementModel; 028import org.ametys.plugins.repository.AmetysObjectFactory; 029import org.ametys.plugins.repository.AmetysObjectResolver; 030import org.ametys.plugins.repository.AmetysRepositoryException; 031import org.ametys.plugins.repository.RepositoryConstants; 032import org.ametys.plugins.repository.jcr.SimpleModelAwareAmetysObject; 033import org.ametys.runtime.model.Model; 034 035/** 036 * {@link AmetysObjectFactory} handling {@link DefaultTrashElement}. 037 */ 038public class TrashElementFactory extends DefaultIndexableTraversableAmetysObjectFactory 039{ 040 /** {@link DefaultTrashElement} nodetype for resources collection */ 041 public static final String TRASH_ELEMENT_NODETYPE = RepositoryConstants.NAMESPACE_PREFIX + ":trashElement"; 042 043 /** The trash root node name */ 044 public static final String ROOT_NODE_NAME = RepositoryConstants.NAMESPACE_PREFIX_INTERNAL + ":trash"; 045 046 private Model _model; 047 048 @Override 049 public void service(ServiceManager manager) throws ServiceException 050 { 051 super.service(manager); 052 _model = (TrashElementModel) manager.lookup(TrashElementModel.ROLE); 053 } 054 055 @Override 056 public DefaultTrashElement getAmetysObject(Node node, String parentPath) throws AmetysRepositoryException 057 { 058 return new DefaultTrashElement(node, parentPath, this); 059 } 060 061 @Override 062 public Collection< ? extends Model> getModel(SimpleModelAwareAmetysObject ametysObject) 063 { 064 return List.of(_model); 065 } 066 067 AmetysObjectResolver _getAOResolver() 068 { 069 return _resolver; 070 } 071}