001/* 002 * Copyright 2011 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.skinfactory.parameters; 017 018import java.nio.file.Path; 019import java.util.Map; 020 021import org.xml.sax.ContentHandler; 022import org.xml.sax.SAXException; 023 024import org.ametys.runtime.i18n.I18nizableText; 025import org.ametys.web.skin.SkinModel; 026 027/** 028 * Class representing a parameter of a skin. 029 */ 030public abstract class AbstractSkinParameter 031{ 032 String _id; 033 I18nizableText _label; 034 I18nizableText _description; 035 036 /** Enumeration of supported types */ 037 public static enum SkinParameterType 038 { 039 /** Image */ 040 IMAGE, 041 /** CSS property */ 042 CSS, 043 /** Variant */ 044 VARIANT, 045 /** Text */ 046 TEXT, 047 /** I18n text */ 048 I18N 049 } 050 051 /** 052 * Constructor 053 * @param id the unique id 054 * @param label the label 055 * @param description the description 056 */ 057 public AbstractSkinParameter(String id, I18nizableText label, I18nizableText description) 058 { 059 this._id = id; 060 this._label = label; 061 this._description = description; 062 } 063 064 /** 065 * Get the unique id 066 * @return the unique id 067 */ 068 public String getId() 069 { 070 return _id; 071 } 072 073 /** 074 * Get the label 075 * @return the label 076 */ 077 public I18nizableText getLabel() 078 { 079 return _label != null ? _label : new I18nizableText(_id); 080 } 081 082 /** 083 * Set the label 084 * @param label the label to set 085 */ 086 public void setLabel (I18nizableText label) 087 { 088 _label = label; 089 } 090 091 /** 092 * Get the description 093 * @return the description 094 */ 095 public I18nizableText getDescription() 096 { 097 return _description != null ? _description : new I18nizableText(""); 098 } 099 100 /** 101 * Set the description 102 * @param description the description to set 103 */ 104 public void setDescription (I18nizableText description) 105 { 106 _description = description; 107 } 108 109 /** 110 * Get type 111 * @return The type 112 */ 113 public abstract SkinParameterType getType(); 114 115 /** 116 * Apply parameter to the skin 117 * @param tempDir the work directory 118 * @param modelDir the model directory 119 * @param value the value 120 * @param lang The language. Can be null. 121 */ 122 public abstract void apply(Path tempDir, Path modelDir, Object value, String lang); 123 124 /** 125 * SAX the parameter 126 * @param contentHandler The content handler to SAX into 127 * @param modelName The model name 128 * @throws SAXException if an error occurred while SAXing 129 */ 130 public abstract void toSAX (ContentHandler contentHandler, String modelName) throws SAXException; 131 132 /** 133 * Transform the parameter into a JSON object 134 * @param modelName The model name 135 * @return The JSON representation of the parameter 136 */ 137 public abstract Map<String, Object> toJson (String modelName); 138 139 /** 140 * Get the default value 141 * @param model The model 142 * @return The default value 143 */ 144 public abstract Object getDefaultValue (SkinModel model); 145 146 /** 147 * Get the default value 148 * @param model The model 149 * @param lang The language 150 * @return The default value 151 */ 152 public abstract Object getDefaultValue (SkinModel model, String lang); 153 154 /** 155 * Widget class 156 * 157 */ 158 public class Widget 159 { 160 String _group; 161 String[] _params; 162 String _name; 163 164 /** 165 * Constructor 166 * @param name the name of the widget 167 * @param group the group of the widget 168 * @param params the widget parameters 169 */ 170 public Widget(String name, String group, String[] params) 171 { 172 _name = name; 173 _group = group; 174 _params = params; 175 } 176 } 177}