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;
028
029/**
030 * This class represents a type of content.
031 */
032public interface ContentType extends ContentTypeDescriptor, MetadataDefinitionHolder
033{
034    /** Tag for private content type */
035    public static final String TAG_PRIVATE = "private";
036    
037    /** Tag for simple content type */
038    public static final String TAG_SIMPLE = "simple";
039    
040    /** Tag for simple content type */
041    public static final String TAG_MIXIN = "mixin";
042    
043    /**
044     * Called by the extension point when the content type hierarchy has been computed.
045     * Can be used to do more initialization, checks, ...
046     * @throws Exception if an error occurs of if an additional check fails.
047     */
048    void postInitialize() throws Exception;
049    
050    /**
051     * Retrieves the potential global validators.
052     * @return the global validators or an empty List if none.
053     */
054    List<ContentValidator> getGlobalValidators();
055    
056    /**
057     * Retrieves the RichText updater
058     * @return the RichText updater or <code>null</code> if none.
059     */
060    RichTextUpdater getRichTextUpdater();
061    
062    /**
063     * Get the indexing model
064     * @return the indexing model
065     */
066    IndexingModel getIndexingModel();
067    
068    /** 
069     * Retrieves the definition of a given metadata by its path. 
070     * @param metadataPath the metadata path, separated by '/'
071     * @return the metadata definition or <code>null</code> if not found 
072     */ 
073    MetadataDefinition getMetadataDefinitionByPath(String metadataPath);
074    
075    /**
076     * Determines if the definition of a given metadata exists.
077     * @param metadataName the metadata name.
078     * @return <code>true</code> if the metadata definition exists
079     */
080    boolean hasMetadataDefinition(String metadataName);
081    
082    /**
083     * Determine whether a metadata can be read at this time.
084     * @param metadataDef the metadata definition
085     * @param content The content where metadata is to be read on. Can be null, on content creation. 
086     * @return <code>true</code> if the current user is allowed to read the metadata of this content.
087     * @throws AmetysRepositoryException if an error occurs while accessing the content.
088     */
089    public boolean canRead(Content content, MetadataDefinition metadataDef) throws AmetysRepositoryException;
090
091    /**
092     * Determine whether a metadata can be written at this time.
093     * @param metadataDef the metadata definition
094     * @param content The content where metadata is to be written on. Can be null, on content creation. 
095     * @return <code>true</code> if the current user is allowed to write the metadata of this content.
096     * @throws AmetysRepositoryException if an error occurs while accessing the content.
097     */
098    public boolean canWrite(Content content, MetadataDefinition metadataDef) throws AmetysRepositoryException;
099    
100    /**
101     * Get the registered tags for this content types
102     * @return the tags
103     */
104    public Set<String> getTags ();
105    
106    /**
107     * Determines if the content type has the given tag
108     * @param tagName The tag name
109     * @return true if the content type is tagged with the given tag name
110     */
111    public boolean hasTag (String tagName);
112    
113    /**
114     * Get whether the content type is private, i.e. should not be created by
115     * the regular content interface.
116     * @return true if the content is private, false if it is public.
117     */
118    public boolean isPrivate();
119    
120    /**
121     * Get whether the content type is simple, i.e. should contains only simple metadata type to be edited in a grid.
122     * @return true if the content is simple, false otherwise
123     */
124    public boolean isSimple();
125    
126    /**
127     * Get whether the content type is abstract, i.e. should not be created by the regular content interface.
128     * @return true if the content is abstract, false otherwise.
129     */
130    public boolean isAbstract();
131    
132    /**
133     * Get whether the content type is a mixin, i.e. should used to add metadata to a existing content.
134     * @return true if the content is mixin, false otherwise.
135     */
136    public boolean isMixin();
137    
138    /**
139     * Get the right needed to create a content of this type.
140     * @return the right needed to create a content of this type. If null is returned, no right is needed.
141     */
142    public String getRight();
143    
144    /**
145     * SAX the additional content data linked to its {@link ContentType}
146     * These additional data will be available in content view
147     * @param contentHandler The handler to SAX into
148     * @param content The content
149     * @throws AmetysRepositoryException if an error occurs while accessing the content.
150     * @throws SAXException if an error occurs while SAXing
151     */
152    public void saxContentTypeAdditionalData (ContentHandler contentHandler, Content content) throws AmetysRepositoryException, SAXException;
153    
154    /**
155     * Get the additional data relative to its {@link ContentType}.
156     * These additional data are delivered to client side.
157     * @param content The content
158     * @return the additional properties in a Map
159     */
160    public Map<String, Object> getAdditionalData (Content content);
161}