001/* 002 * Copyright 2021 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.odfsync.cdmfr.extractor; 017 018import org.apache.avalon.framework.component.Component; 019import org.apache.avalon.framework.service.ServiceException; 020import org.apache.avalon.framework.service.ServiceManager; 021import org.apache.avalon.framework.service.Serviceable; 022import org.w3c.dom.Element; 023 024import org.ametys.cms.contenttype.ContentType; 025import org.ametys.cms.contenttype.ContentTypeExtensionPoint; 026import org.ametys.cms.repository.Content; 027import org.ametys.odf.course.Course; 028import org.ametys.odf.courselist.CourseList; 029import org.ametys.odf.coursepart.CoursePart; 030import org.ametys.odf.enumeration.OdfReferenceTableHelper; 031import org.ametys.odf.program.TraversableProgramPart; 032import org.ametys.plugins.odfsync.cdmfr.ImportCDMFrContext; 033import org.ametys.plugins.odfsync.cdmfr.components.ImportCDMFrComponent; 034import org.ametys.plugins.odfsync.utils.ContentWorkflowDescription; 035import org.ametys.plugins.repository.AmetysObjectResolver; 036import org.ametys.plugins.repository.data.extractor.ModelAwareValuesExtractor; 037import org.ametys.plugins.repository.data.extractor.xml.XMLValuesExtractorAdditionalDataGetter; 038 039/** 040 * Factory for {@link ImportCDMFrValuesExtractor} 041 * Creates the right instance of {@link ImportCDMFrValuesExtractor} according to the imported content 042 * Provides components to the values extractor 043 */ 044public class ImportCDMFrValuesExtractorFactory implements Component, Serviceable 045{ 046 /** The component role. */ 047 public static final String ROLE = ImportCDMFrValuesExtractorFactory.class.getName(); 048 049 /** The ametys object resolver */ 050 protected AmetysObjectResolver _resolver; 051 052 /** The content type extension point */ 053 protected ContentTypeExtensionPoint _contentTypeExtensionPoint; 054 055 /** The ODF TableRef Helper */ 056 private OdfReferenceTableHelper _odfRefTableHelper; 057 058 public void service(ServiceManager manager) throws ServiceException 059 { 060 _resolver = (AmetysObjectResolver) manager.lookup(AmetysObjectResolver.ROLE); 061 _contentTypeExtensionPoint = (ContentTypeExtensionPoint) manager.lookup(ContentTypeExtensionPoint.ROLE); 062 _odfRefTableHelper = (OdfReferenceTableHelper) manager.lookup(OdfReferenceTableHelper.ROLE); 063 } 064 065 /** 066 * Retrieves the values extractor corresponding to the given content 067 * @param contentElement the DOM content element 068 * @param component The import CDM-fr component 069 * @param content The content to synchronize 070 * @param contentType The content type 071 * @param syncCode The synchronization code 072 * @param context the import context 073 * @return the values extractor corresponding to the given content 074 */ 075 public ModelAwareValuesExtractor getValuesExtractor(Element contentElement, ImportCDMFrComponent component, Content content, ContentType contentType, String syncCode, ImportCDMFrContext context) 076 { 077 XMLValuesExtractorAdditionalDataGetter additionalDataGetter = new ImportCDMFrAdditionalDataGetter(); 078 079 if (content instanceof TraversableProgramPart) 080 { 081 return new ImportTraversableProgramPartValuesExtractor(contentElement, this, component, syncCode, context, additionalDataGetter, contentType); 082 } 083 else if (content instanceof CourseList) 084 { 085 return new ImportCourseListValuesExtractor(contentElement, this, component, context, additionalDataGetter, contentType); 086 } 087 else if (content instanceof Course) 088 { 089 return new ImportCourseValuesExtractor(contentElement, this, component, syncCode, context, additionalDataGetter, contentType); 090 } 091 else if (content instanceof CoursePart) 092 { 093 return new ImportCoursePartValuesExtractor(contentElement, this, component, context, additionalDataGetter, contentType); 094 } 095 else 096 { 097 return new ImportCDMFrValuesExtractor(contentElement, this, component, context, additionalDataGetter, contentType); 098 } 099 } 100 101 /** 102 * Retrieves the values extractor for mentions 103 * @param contentElement the DOM content element 104 * @param component The import CDM-fr component 105 * @param context the import context 106 * @return the values extractor corresponding to the given content 107 */ 108 public ModelAwareValuesExtractor getMentionValuesExtractor(Element contentElement, ImportCDMFrComponent component, ImportCDMFrContext context) 109 { 110 ContentType contentType = _contentTypeExtensionPoint.getExtension(ContentWorkflowDescription.PROGRAM_WF_DESCRIPTION.getContentType()); 111 XMLValuesExtractorAdditionalDataGetter additionalDataGetter = new ImportCDMFrAdditionalDataGetter(); 112 return new ImportCDMFrValuesExtractor(contentElement, this, component, context, additionalDataGetter, contentType); 113 } 114 115 /** 116 * Retrieves the values extractor for mentions 117 * @param contentElement the DOM content element 118 * @param component The import CDM-fr component 119 * @param context the import context 120 * @return the values extractor corresponding to the given content 121 */ 122 public ModelAwareValuesExtractor getSharedSubProgramValuesExtractor(Element contentElement, ImportCDMFrComponent component, ImportCDMFrContext context) 123 { 124 ContentType contentType = _contentTypeExtensionPoint.getExtension(ContentWorkflowDescription.SUBPROGRAM_WF_DESCRIPTION.getContentType()); 125 XMLValuesExtractorAdditionalDataGetter additionalDataGetter = new ImportCDMFrAdditionalDataGetter(); 126 return new ImportCDMFrValuesExtractor(contentElement, this, component, context, additionalDataGetter, contentType); 127 } 128 129 /** 130 * Retrieves the ametys object resolver 131 * @return the ametys object resolver 132 */ 133 public AmetysObjectResolver getAmetysObjectResolver() 134 { 135 return _resolver; 136 } 137 138 /** 139 * Retrieves the content type extension point 140 * @return the content type extension point 141 */ 142 public ContentTypeExtensionPoint getContentTypeExtensionPoint() 143 { 144 return _contentTypeExtensionPoint; 145 } 146 147 /** 148 * Retrieves the {@link OdfReferenceTableHelper} 149 * @return the {@link OdfReferenceTableHelper} 150 */ 151 public OdfReferenceTableHelper getODFReferenceTableHelper() 152 { 153 return _odfRefTableHelper; 154 } 155}