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.content.ContentExtractor; 027import org.ametys.web.repository.content.ModifiableWebContent; 028import org.ametys.web.repository.content.shared.SharedContentManager; 029 030/** 031 * {@link AmetysObjectFactory} handling {@link ModifiableWebContent}. 032 */ 033public class ModifiableDefaultWebContentFactory extends DefaultWebContentFactory 034{ 035 private LockComponent _lockComponent; 036 private SharedContentManager _sharedContentManager; 037 private ModifiableContentHelper _modifiableContentHelper; 038 private ContentExtractor _contentExtractor; 039 040 @Override 041 public ModifiableDefaultWebContent getAmetysObject(Node node, String parentPath) throws AmetysRepositoryException 042 { 043 return new ModifiableDefaultWebContent<>(node, parentPath, this); 044 } 045 046 LockComponent getLockComponent() 047 { 048 if (_lockComponent == null) 049 { 050 try 051 { 052 _lockComponent = (LockComponent) _manager.lookup(LockComponent.ROLE); 053 } 054 catch (ServiceException e) 055 { 056 throw new IllegalStateException("Unable to get LockComponent", e); 057 } 058 } 059 return _lockComponent; 060 } 061 062 SharedContentManager getSharedContentManager() 063 { 064 if (_sharedContentManager == null) 065 { 066 try 067 { 068 _sharedContentManager = (SharedContentManager) _manager.lookup(SharedContentManager.ROLE); 069 } 070 catch (ServiceException e) 071 { 072 throw new IllegalStateException("Unable to get SharedContentManager", e); 073 } 074 } 075 076 return _sharedContentManager; 077 } 078 079 ModifiableContentHelper getModifiableContentHelper() 080 { 081 if (_modifiableContentHelper == null) 082 { 083 try 084 { 085 _modifiableContentHelper = (ModifiableContentHelper) _manager.lookup(ModifiableContentHelper.ROLE); 086 } 087 catch (ServiceException e) 088 { 089 throw new IllegalStateException("Unable to get ModifiableContentHelper", e); 090 } 091 } 092 093 return _modifiableContentHelper; 094 } 095 096 ContentExtractor getContentExtractor() 097 { 098 if (_contentExtractor == null) 099 { 100 try 101 { 102 _contentExtractor = (ContentExtractor) _manager.lookup(ContentExtractor.WEB_CONTENT_EXTACTOR_ROLE); 103 } 104 catch (ServiceException e) 105 { 106 throw new IllegalStateException("Unable to get ContentExtractor", e); 107 } 108 } 109 110 return _contentExtractor; 111 } 112}