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.forms.question.computing; 017 018import java.util.ArrayList; 019import java.util.List; 020 021import org.apache.avalon.framework.configuration.Configurable; 022import org.apache.avalon.framework.configuration.Configuration; 023import org.apache.avalon.framework.configuration.ConfigurationException; 024import org.apache.avalon.framework.service.ServiceException; 025import org.apache.avalon.framework.service.ServiceManager; 026import org.apache.avalon.framework.service.Serviceable; 027import org.xml.sax.ContentHandler; 028import org.xml.sax.SAXException; 029 030import org.ametys.plugins.forms.question.FormQuestionDataTypeExtensionPoint; 031import org.ametys.plugins.forms.question.sources.ChoiceSourceTypeExtensionPoint; 032import org.ametys.plugins.forms.repository.FormEntry; 033import org.ametys.plugins.forms.repository.FormQuestion; 034import org.ametys.runtime.i18n.I18nizableText; 035import org.ametys.runtime.plugin.component.AbstractLogEnabled; 036import org.ametys.runtime.plugin.component.PluginAware; 037 038/** 039 * Static class for creating {@link ComputingType} from xml configuration 040 */ 041public abstract class AbstractStaticComputingType extends AbstractLogEnabled implements ComputingType, Serviceable, Configurable, PluginAware 042{ 043 /** Forms */ 044 protected String _pluginName; 045 /** Id of computing type */ 046 protected String _id; 047 /** Label of computing type */ 048 protected I18nizableText _label; 049 /** Description of computing type */ 050 protected I18nizableText _description; 051 /** Xslt associated with computing type */ 052 protected String _xslt; 053 054 /** The computing type extension point */ 055 protected ComputingTypeExtensionPoint _computingTypeExtensionPoint; 056 /** The form question data type extension point */ 057 protected FormQuestionDataTypeExtensionPoint _formQuestionDataTypeExtensionPoint; 058 /** The choice source type extension point */ 059 protected ChoiceSourceTypeExtensionPoint _choiceSourceTypeExtensionPoint; 060 061 public void service(ServiceManager manager) throws ServiceException 062 { 063 _computingTypeExtensionPoint = (ComputingTypeExtensionPoint) manager.lookup(ComputingTypeExtensionPoint.ROLE); 064 _formQuestionDataTypeExtensionPoint = (FormQuestionDataTypeExtensionPoint) manager.lookup(FormQuestionDataTypeExtensionPoint.ROLE); 065 _choiceSourceTypeExtensionPoint = (ChoiceSourceTypeExtensionPoint) manager.lookup(ChoiceSourceTypeExtensionPoint.ROLE); 066 } 067 068 public void setPluginInfo(String pluginName, String featureName, String id) 069 { 070 _pluginName = pluginName; 071 } 072 073 public void configure(Configuration configuration) throws ConfigurationException 074 { 075 _id = configuration.getAttribute("id"); 076 077 Configuration childLabel = configuration.getChild("label"); 078 _label = I18nizableText.getI18nizableTextValue(childLabel, "plugin." + _pluginName, childLabel.getValue()); 079 080 Configuration childDesc = configuration.getChild("description"); 081 _description = I18nizableText.getI18nizableTextValue(childDesc, "plugin." + _pluginName, childDesc.getValue()); 082 083 _xslt = configuration.getChild("xslt").getValue(null); 084 } 085 086 public String getId() 087 { 088 return _id; 089 } 090 091 public I18nizableText getLabel() 092 { 093 return _label; 094 } 095 096 public I18nizableText getDescription() 097 { 098 return _description; 099 } 100 101 public String getXSLT() 102 { 103 return _xslt; 104 } 105 106 public boolean hasComputedValue() 107 { 108 return true; 109 } 110 111 public List<String> getFieldToDisableIfFormPublished() 112 { 113 return new ArrayList<>(); 114 } 115 116 public void saxAdditionalValue(ContentHandler contentHandler, FormQuestion question, FormEntry entry) throws SAXException 117 { 118 // Do nothing by default 119 } 120 121 public String getJSRenderer() 122 { 123 return null; 124 } 125}