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.Set; 021 022import org.xml.sax.ContentHandler; 023import org.xml.sax.SAXException; 024 025import org.ametys.cms.contenttype.indexing.IndexingModel; 026import org.ametys.cms.repository.Content; 027import org.ametys.plugins.repository.AmetysRepositoryException; 028import org.ametys.runtime.model.Model; 029import org.ametys.runtime.model.ModelItem; 030import org.ametys.runtime.model.View; 031 032/** 033 * This class represents a type of content. 034 */ 035public interface ContentType extends ContentTypeDescriptor, Model, MetadataDefinitionHolder 036{ 037 /** Tag for private content type */ 038 public static final String TAG_PRIVATE = "private"; 039 040 /** Tag for reference table */ 041 public static final String TAG_REFERENCE_TABLE = "reference-table"; 042 043 /** Tag for renderable reference table */ 044 public static final String TAG_RENDERABLE_FERENCE_TABLE = "renderable-reference-table"; 045 046 /** Tag for simple content type */ 047 public static final String TAG_MIXIN = "mixin"; 048 049 /** 050 * Called by the extension point when the content type hierarchy has been computed. 051 * Can be used to do more initialization, checks, ... 052 * @throws Exception if an error occurs of if an additional check fails. 053 */ 054 void postInitialize() throws Exception; 055 056 /** 057 * Retrieves the potential global validators. 058 * @return the global validators or an empty List if none. 059 */ 060 List<ContentValidator> getGlobalValidators(); 061 062 /** 063 * Retrieves the RichText updater 064 * @return the RichText updater or <code>null</code> if none. 065 */ 066 RichTextUpdater getRichTextUpdater(); 067 068 /** 069 * Get the indexing model 070 * @return the indexing model 071 */ 072 IndexingModel getIndexingModel(); 073 074 /** 075 * Retrieves the names of all the content type's view 076 * @return the views' names 077 */ 078 Set<String> getViewNames(); 079 080 /** 081 * Retrieves the view with the given name 082 * @param viewName the name of the view to retrieve 083 * @return the view 084 */ 085 View getView(String viewName); 086 087 /** 088 * Retrieves the definition of a given metadata by its path. 089 * @param metadataPath the metadata path, separated by '/' 090 * @return the metadata definition or <code>null</code> if not found 091 * @deprecated Use {@link #getModelItem(String)} API instead 092 */ 093 @Deprecated 094 MetadataDefinition getMetadataDefinitionByPath(String metadataPath); 095 096 /** 097 * Determines if the definition of a given metadata exists. 098 * @param metadataName the metadata name. 099 * @return <code>true</code> if the metadata definition exists 100 * @deprecated Use {@link ModelItem} API instead 101 */ 102 @Deprecated 103 boolean hasMetadataDefinition(String metadataName); 104 105 /** 106 * Determine whether a metadata can be read at this time. 107 * @param metadataDef the metadata definition 108 * @param content The content where metadata is to be read on. Can be null, on content creation. 109 * @return <code>true</code> if the current user is allowed to read the metadata of this content. 110 * @throws AmetysRepositoryException if an error occurs while accessing the content. 111 * @deprecated Use {@link AttributeDefinition#canRead(Content)} instead 112 */ 113 @Deprecated 114 public boolean canRead(Content content, MetadataDefinition metadataDef) throws AmetysRepositoryException; 115 116 /** 117 * Determine whether a metadata can be written at this time. 118 * @param metadataDef the metadata definition 119 * @param content The content where metadata is to be written on. Can be null, on content creation. 120 * @return <code>true</code> if the current user is allowed to write the metadata of this content. 121 * @throws AmetysRepositoryException if an error occurs while accessing the content. 122 * @deprecated Use {@link AttributeDefinition#canWrite(Content)} instead 123 */ 124 @Deprecated 125 public boolean canWrite(Content content, MetadataDefinition metadataDef) throws AmetysRepositoryException; 126 127 /** 128 * Get the registered tags for this content types 129 * @return the tags 130 */ 131 public Set<String> getTags (); 132 133 /** 134 * Determines if the content type has the given tag 135 * @param tagName The tag name 136 * @return true if the content type is tagged with the given tag name 137 */ 138 public boolean hasTag (String tagName); 139 140 /** 141 * Get whether the content type is private, i.e. should not be created by 142 * the regular content interface. 143 * @return true if the content is private, false if it is public. 144 */ 145 public boolean isPrivate(); 146 147 /** 148 * Get whether the content type is simple, i.e. should contains only simple metadata type to be edited in a grid. 149 * @return true if the content is simple, false otherwise 150 */ 151 public boolean isSimple(); 152 153 /** 154 * Get whether the content type is a reference table 155 * @return true if the content type is a reference table 156 */ 157 public boolean isReferenceTable(); 158 159 /** 160 * Get whether the content type is multilingual 161 * @return true if the content is multilingual, false otherwise 162 */ 163 public boolean isMultilingual(); 164 165 /** 166 * Get whether the content type is abstract, i.e. should not be created by the regular content interface. 167 * @return true if the content is abstract, false otherwise. 168 */ 169 public boolean isAbstract(); 170 171 /** 172 * Get whether the content type is a mixin, i.e. should used to add metadata to a existing content. 173 * @return true if the content is mixin, false otherwise. 174 */ 175 public boolean isMixin(); 176 177 /** 178 * Get the right needed to create a content of this type. 179 * @return the right needed to create a content of this type. If null is returned, no right is needed. 180 */ 181 public String getRight(); 182 183 /** 184 * SAX the additional content data linked to its {@link ContentType} 185 * These additional data will be available in content view 186 * @param contentHandler The handler to SAX into 187 * @param content The content 188 * @throws AmetysRepositoryException if an error occurs while accessing the content. 189 * @throws SAXException if an error occurs while SAXing 190 */ 191 public void saxContentTypeAdditionalData (ContentHandler contentHandler, Content content) throws AmetysRepositoryException, SAXException; 192 193 /** 194 * Get the additional data relative to its {@link ContentType}. 195 * These additional data are delivered to client side. 196 * @param content The content 197 * @return the additional properties in a Map 198 */ 199 public Map<String, Object> getAdditionalData (Content content); 200 201// /** 202// * Gets the "parent" content type of this content type. Must be a private and simple content type. 203// * @return the "parent" content type of this content type 204// */ 205// public ContentType getParentContentType(); 206 207 /** 208 * Gets the metadata holding the "parent" of the contents of this content type. Must be of type {@link MetadataType#CONTENT} and must reference a private and simple content type. 209 * @return the metadata holding the "parent" of the contents of this content type 210 * @deprecated Use {@link ModelItem} API instead 211 */ 212 @Deprecated 213 public MetadataDefinition getParentMetadata(); 214}