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