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