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; 019import javax.jcr.RepositoryException; 020 021import org.apache.avalon.framework.service.ServiceException; 022 023import org.ametys.cms.repository.ModifiableContentHelper; 024import org.ametys.plugins.repository.AmetysObject; 025import org.ametys.plugins.repository.AmetysObjectFactory; 026import org.ametys.plugins.repository.AmetysRepositoryException; 027import org.ametys.plugins.repository.RepositoryConstants; 028 029/** 030 * {@link AmetysObjectFactory} which handles {@link DefaultSharedContent}s. 031 */ 032public class DefaultSharedContentFactory extends DefaultWebContentFactory 033{ 034 035 /** The shared content nodetype. */ 036 public static final String SHARED_CONTENT_NODETYPE = RepositoryConstants.NAMESPACE_PREFIX + ":defaultSharedContent"; 037 private ModifiableContentHelper _modifiableContentHelper; 038 039 @Override 040 public DefaultSharedContent getAmetysObject(Node node, String parentPath) throws AmetysRepositoryException 041 { 042 return new DefaultSharedContent<>(node, parentPath, this); 043 } 044 045 @Override 046 public <A extends AmetysObject> A resolveAmetysObject(Node node) throws AmetysRepositoryException, RepositoryException 047 { 048 return _resolver.<A>resolve(node, false); 049 } 050 051 ModifiableContentHelper getModifiableContentHelper() 052 { 053 if (_modifiableContentHelper == null) 054 { 055 try 056 { 057 _modifiableContentHelper = (ModifiableContentHelper) _manager.lookup(ModifiableContentHelper.ROLE); 058 } 059 catch (ServiceException e) 060 { 061 throw new IllegalStateException("Unable to get ModifiableContentHelper", e); 062 } 063 } 064 065 return _modifiableContentHelper; 066 } 067 068}