001/* 002 * Copyright 2012 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.repository.content.jcr; 017 018import javax.jcr.Node; 019 020import org.apache.avalon.framework.service.ServiceException; 021 022import org.ametys.cms.repository.ModifiableContentHelper; 023import org.ametys.plugins.repository.AmetysObjectFactory; 024import org.ametys.plugins.repository.AmetysRepositoryException; 025import org.ametys.plugins.repository.jcr.LockComponent; 026import org.ametys.web.repository.content.ModifiableWebContent; 027import org.ametys.web.repository.content.shared.SharedContentManager; 028 029/** 030 * {@link AmetysObjectFactory} handling {@link ModifiableWebContent}. 031 */ 032public class ModifiableDefaultWebContentFactory extends DefaultWebContentFactory 033{ 034 private LockComponent _lockComponent; 035 private SharedContentManager _sharedContentManager; 036 private ModifiableContentHelper _modifiableContentHelper; 037 038 @Override 039 public ModifiableDefaultWebContent getAmetysObject(Node node, String parentPath) throws AmetysRepositoryException 040 { 041 return new ModifiableDefaultWebContent<>(node, parentPath, this); 042 } 043 044 LockComponent getLockComponent() 045 { 046 if (_lockComponent == null) 047 { 048 try 049 { 050 _lockComponent = (LockComponent) _manager.lookup(LockComponent.ROLE); 051 } 052 catch (ServiceException e) 053 { 054 throw new IllegalStateException("Unable to get LockComponent", e); 055 } 056 } 057 return _lockComponent; 058 } 059 060 SharedContentManager getSharedContentManager() 061 { 062 if (_sharedContentManager == null) 063 { 064 try 065 { 066 _sharedContentManager = (SharedContentManager) _manager.lookup(SharedContentManager.ROLE); 067 } 068 catch (ServiceException e) 069 { 070 throw new IllegalStateException("Unable to get SharedContentManager", e); 071 } 072 } 073 074 return _sharedContentManager; 075 } 076 077 ModifiableContentHelper getModifiableContentHelper() 078 { 079 if (_modifiableContentHelper == null) 080 { 081 try 082 { 083 _modifiableContentHelper = (ModifiableContentHelper) _manager.lookup(ModifiableContentHelper.ROLE); 084 } 085 catch (ServiceException e) 086 { 087 throw new IllegalStateException("Unable to get ModifiableContentHelper", e); 088 } 089 } 090 091 return _modifiableContentHelper; 092 } 093}