001/* 002 * Copyright 2010 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.cms.contenttype; 017 018import java.util.List; 019import java.util.Map; 020import java.util.Optional; 021import java.util.Set; 022 023import org.xml.sax.ContentHandler; 024import org.xml.sax.SAXException; 025 026import org.ametys.cms.contenttype.ContentTypesHelper.ViewConfigurations; 027import org.ametys.cms.data.type.ModelItemTypeConstants; 028import org.ametys.cms.model.restrictions.RestrictedModelItem; 029import org.ametys.cms.repository.Content; 030import org.ametys.plugins.repository.AmetysRepositoryException; 031import org.ametys.runtime.model.Model; 032import org.ametys.runtime.model.View; 033 034/** 035 * This class represents a type of content. 036 */ 037public interface ContentType extends ContentTypeDescriptor, Model 038{ 039 /** Tag for private content type */ 040 public static final String TAG_PRIVATE = "private"; 041 042 /** Tag for reference table */ 043 public static final String TAG_REFERENCE_TABLE = "reference-table"; 044 045 /** Tag for renderable reference table */ 046 public static final String TAG_RENDERABLE_FERENCE_TABLE = "renderable-reference-table"; 047 048 /** Tag for simple content type */ 049 public static final String TAG_MIXIN = "mixin"; 050 051 /** Tag name for a view declaration */ 052 public static final String VIEW_TAG_NAME = "view"; 053 /** Tag name for a view declaration using the legacy syntax */ 054 public static final String VIEW_TAG_NAME_WITH_LEGACY_SYNTAX = "metadata-set"; 055 /** Tag name for a group declaration in a view using legacy syntax */ 056 public static final String GROUP_TAG_NAME_WITH_LEGACY_SYNTAX = "fieldset"; 057 /** Tag name for an attribute reference declaration in a view using the legacy syntax */ 058 public static final String ATTRIBUTE_REF_TAG_NAME_WITH_LEGACY_SYNTAX = "metadata-ref"; 059 060 061 /** 062 * Called by the extension point when the model items of all content types have been initialized. 063 * Can be used to do more initialization, checks, ... needing model items (attributes / properties) of distant contents 064 * @throws Exception if an error occurs of if an additional check fails. 065 */ 066 void initializeAfterModelItemsInitialization() throws Exception; 067 068 /** 069 * Called by the extension point when the views of all content types have been initialized. 070 * Can be used to do more initialization, checks, ... needing views of distant contents 071 * @throws Exception if an error occurs of if an additional check fails. 072 */ 073 void initializeAfterViewsInitialization() throws Exception; 074 075 /** 076 * Retrieves the potential global validators. 077 * @return the global validators or an empty List if none. 078 */ 079 List<ContentValidator> getGlobalValidators(); 080 081 /** 082 * Retrieves the RichText updater 083 * @return the RichText updater or <code>null</code> if none. 084 */ 085 RichTextUpdater getRichTextUpdater(); 086 087 /** 088 * Retrieves the properties references 089 * Properties can reference items on distant content type. 090 * Those references are like: Impacted ContentType -> local IndexingField name -> path to impacted content. 091 * @return this content type's properties references 092 */ 093 Map<String, Map<String, List<String>>> getPropertiesReferences(); 094 095 /** 096 * Retrieves the names of all the content type's view 097 * @return the views' names 098 */ 099 default Set<String> getViewNames() 100 { 101 return getViewNames(true); 102 } 103 104 /** 105 * Retrieves the names of all the content type's view 106 * @param includeInternals if the result should include internal views. 107 * @return the views' names 108 */ 109 Set<String> getViewNames(boolean includeInternals); 110 111 /** 112 * Retrieves the view with the given name 113 * @param viewName the name of the view to retrieve 114 * @return the view 115 */ 116 View getView(String viewName); 117 118 /** 119 * Retrieves all the views' configurations declared by this content type 120 * @return the views' configurations 121 */ 122 Map<String, ViewConfigurations> getViewConfigurations(); 123 124 /** 125 * Retrieves the optional view's configuration declared by this content type 126 * @param viewName the name of the view to retrieve 127 * @return the view's configuration 128 */ 129 Optional<ViewConfigurations> getViewConfigurations(String viewName); 130 131 /** 132 * Determine whether an attribute can be read at this time. 133 * Method called by {@link AttributeDefinition#canRead(Content)} to do some other checks, depending on the content type 134 * @param definition the attribute definition 135 * @param content The content where attribute is to be read on. Can be null, on content creation. 136 * @return <code>true</code> if the current user is allowed to read the attribute of this content. 137 * @throws AmetysRepositoryException if an error occurs while accessing the content. 138 */ 139 public default boolean canRead(Content content, RestrictedModelItem<Content> definition) throws AmetysRepositoryException 140 { 141 return true; 142 } 143 144 /** 145 * Determine whether an attribute can be written at this time. 146 * Method called by {@link AttributeDefinition#canWrite(Content)} to do some other checks, depending on the content type 147 * @param definition the attribute definition 148 * @param content The content where attribute is to be written on. Can be null, on content creation. 149 * @return <code>true</code> if the current user is allowed to write the attribute of this content. 150 * @throws AmetysRepositoryException if an error occurs while accessing the content. 151 */ 152 public default boolean canWrite(Content content, RestrictedModelItem<Content> definition) throws AmetysRepositoryException 153 { 154 return true; 155 } 156 157 /** 158 * Get the registered tags for this content type 159 * @return the tags 160 */ 161 public Set<String> getTags (); 162 163 /** 164 * Get the registered and inheritable tags for this content type 165 * @return the inheritable tags 166 */ 167 public Set<String> getInheritableTags (); 168 169 /** 170 * Determines if the content type has the given tag 171 * @param tagName The tag name 172 * @return true if the content type is tagged with the given tag name 173 */ 174 public boolean hasTag (String tagName); 175 176 /** 177 * Get whether the content type is private, i.e. should not be created by 178 * the regular content interface. 179 * @return true if the content is private, false if it is public. 180 */ 181 public boolean isPrivate(); 182 183 /** 184 * Get whether the content type is simple, i.e. should contains only simple metadata type to be edited in a grid. 185 * @return true if the content is simple, false otherwise 186 */ 187 public boolean isSimple(); 188 189 /** 190 * Get whether the content type is a reference table 191 * @return true if the content type is a reference table 192 */ 193 public boolean isReferenceTable(); 194 195 /** 196 * Get whether the content type is multilingual 197 * @return true if the content is multilingual, false otherwise 198 */ 199 public boolean isMultilingual(); 200 201 /** 202 * Get whether the content type is abstract, i.e. should not be created by the regular content interface. 203 * @return true if the content is abstract, false otherwise. 204 */ 205 public boolean isAbstract(); 206 207 /** 208 * Get whether the content type is a mixin, i.e. should used to add metadata to a existing content. 209 * @return true if the content is mixin, false otherwise. 210 */ 211 public boolean isMixin(); 212 213 /** 214 * Get the workflow names configured in the content type definition or in its supertypes. 215 * @return A {@link Set} of workflow names 216 */ 217 public Set<String> getConfiguredDefaultWorkflowNames(); 218 219 /** 220 * Get the default workflow name. 221 * @return The default workflow name 222 */ 223 public Optional<String> getDefaultWorkflowName(); 224 225 /** 226 * Get the right needed to create a content of this type. 227 * @return the right needed to create a content of this type. If null is returned, no right is needed. 228 */ 229 public String getRight(); 230 231 /** 232 * SAX the additional content data linked to its {@link ContentType} 233 * These additional data will be available in content view 234 * @param contentHandler The handler to SAX into 235 * @param content The content 236 * @throws AmetysRepositoryException if an error occurs while accessing the content. 237 * @throws SAXException if an error occurs while SAXing 238 */ 239 public void saxContentTypeAdditionalData (ContentHandler contentHandler, Content content) throws AmetysRepositoryException, SAXException; 240 241 /** 242 * Get the additional data relative to its {@link ContentType}. 243 * These additional data are delivered to client side. 244 * @param content The content 245 * @return the additional properties in a Map 246 */ 247 public Map<String, Object> getAdditionalData (Content content); 248 249// /** 250// * Gets the "parent" content type of this content type. Must be a private and simple content type. 251// * @return the "parent" content type of this content type 252// */ 253// public ContentType getParentContentType(); 254 255 /** 256 * Gets the attribute holding the "parent" of the contents of this content type. Must be of type {@link ModelItemTypeConstants#CONTENT_ELEMENT_TYPE_ID} and must reference a private and simple content type. 257 * @return the attribute holding the "parent" of the contents of this content type 258 */ 259 public Optional<ContentAttributeDefinition> getParentAttributeDefinition(); 260 261 /** 262 * Get the overridden model items list 263 * @return the overridden model items list 264 */ 265 public List<String> getOverriddenModelItems(); 266 267 /** 268 * Get the overridden views list 269 * @return the overridden views list 270 */ 271 public List<String> getOverriddenViews(); 272 273}