001/* 002 * Copyright 2012 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.web.repository.content.jcr; 017 018import java.util.Date; 019import java.util.List; 020import java.util.Locale; 021import java.util.Map; 022 023import javax.jcr.Node; 024 025import org.ametys.cms.content.references.OutgoingReferences; 026import org.ametys.cms.repository.ModifiableWorkflowAwareContent; 027import org.ametys.cms.repository.WorkflowAwareContentHelper; 028import org.ametys.cms.repository.comment.Comment; 029import org.ametys.cms.repository.comment.CommentableContent; 030import org.ametys.core.user.UserIdentity; 031import org.ametys.plugins.repository.AmetysRepositoryException; 032import org.ametys.plugins.repository.RepositoryIntegrityViolationException; 033import org.ametys.plugins.repository.jcr.DublinCoreHelper; 034import org.ametys.plugins.repository.lock.LockableAmetysObject; 035import org.ametys.web.repository.content.ModifiableWebContent; 036 037/** 038 * Modifiable version of {@link DefaultWebContent}. 039 * @param <F> the actual type of factory. 040 */ 041public class ModifiableDefaultWebContent<F extends ModifiableDefaultWebContentFactory> extends DefaultWebContent<F> implements ModifiableWebContent, ModifiableWorkflowAwareContent, LockableAmetysObject, CommentableContent//, CopiableAmetysObject, JCRTraversableAmetysObject 042{ 043 /** 044 * Creates a {@link ModifiableDefaultWebContent}. 045 * @param node the node backing this {@link ModifiableDefaultWebContent}. 046 * @param parentPath the parent path in the Ametys hierarchy. 047 * @param factory the {@link DefaultWebContentFactory} which creates the AmetysObject. 048 */ 049 public ModifiableDefaultWebContent(Node node, String parentPath, F factory) 050 { 051 super(node, parentPath, factory); 052 } 053 054 // Workflow management. 055 056 @Override 057 public long getWorkflowId() throws AmetysRepositoryException 058 { 059 return WorkflowAwareContentHelper.getWorkflowId(this); 060 } 061 062 @Override 063 public void setWorkflowId(long workflowId) throws AmetysRepositoryException 064 { 065 WorkflowAwareContentHelper.setWorkflowId(this, workflowId); 066 } 067 068 @Override 069 public long getCurrentStepId() throws AmetysRepositoryException 070 { 071 return WorkflowAwareContentHelper.getCurrentStepId(this); 072 } 073 074 @Override 075 public void setCurrentStepId (long stepId) throws AmetysRepositoryException 076 { 077 WorkflowAwareContentHelper.setCurrentStepId(this, stepId); 078 } 079 080 @Override 081 public Date getProposalDate() throws AmetysRepositoryException 082 { 083 return WorkflowAwareContentHelper.getProposalDate(this); 084 } 085 086 @Override 087 public void setProposalDate(Date proposalDate) throws AmetysRepositoryException 088 { 089 WorkflowAwareContentHelper.setProposalDate(this, proposalDate); 090 } 091 092 @Override 093 public void remove() throws AmetysRepositoryException, RepositoryIntegrityViolationException 094 { 095 _getFactory().getSharedContentManager().switchSharedContentReferences(this); 096 super.remove(); 097 } 098 099 @Override 100 public void setSiteName(String siteName) 101 { 102 getMetadataHolder().setMetadata(METADATA_SITE, siteName); 103 } 104 105 /** 106 * Set the type of this content 107 * @param type the type to set 108 * @throws AmetysRepositoryException if something goes wrong when setting the type property of the content in JCR 109 */ 110 public void setType(String type) throws AmetysRepositoryException 111 { 112 _getFactory().getModifiableContentHelper().setType(this, type); 113 } 114 115 @Override 116 public void setTypes(String[] types) throws AmetysRepositoryException 117 { 118 _getFactory().getModifiableContentHelper().setTypes(this, types); 119 } 120 121 @Override 122 public void setMixinTypes(String[] mixins) throws AmetysRepositoryException 123 { 124 _getFactory().getModifiableContentHelper().setMixinTypes(this, mixins); 125 } 126 127 @Override 128 public void setLanguage(String language) throws AmetysRepositoryException 129 { 130 _getFactory().getModifiableContentHelper().setLanguage(this, language); 131 } 132 133 @Override 134 public void setTitle(String title, Locale locale) throws AmetysRepositoryException 135 { 136 _getFactory().getModifiableContentHelper().setTitle(this, title, locale); 137 } 138 139 @Override 140 @Deprecated 141 public void setTitle(String title) throws AmetysRepositoryException 142 { 143 _getFactory().getModifiableContentHelper().setTitle(this, title); 144 } 145 146 public void setCreator(UserIdentity user) throws AmetysRepositoryException 147 { 148 _getFactory().getModifiableContentHelper().setCreator(this, user); 149 } 150 151 public void setCreationDate(Date creationDate) throws AmetysRepositoryException 152 { 153 _getFactory().getModifiableContentHelper().setCreationDate(this, creationDate); 154 } 155 156 public void setLastContributor(UserIdentity user) 157 { 158 _getFactory().getModifiableContentHelper().setLastContributor(this, user); 159 } 160 161 public void setLastModified(Date lastModified) throws AmetysRepositoryException 162 { 163 _getFactory().getModifiableContentHelper().setLastModified(this, lastModified); 164 } 165 166 @Override 167 public void setLastValidationDate(Date validationDate) throws AmetysRepositoryException 168 { 169 _getFactory().getModifiableContentHelper().setLastValidationDate(this, validationDate); 170 } 171 172 @Override 173 public void setLastMajorValidationDate(Date validationDate) throws AmetysRepositoryException 174 { 175 _getFactory().getModifiableContentHelper().setLastMajorValidationDate(this, validationDate); 176 } 177 178 @Override 179 public void setOutgoingReferences(Map<String, OutgoingReferences> references) throws AmetysRepositoryException 180 { 181 _getFactory().getModifiableContentHelper().setOutgoingReferences(this, references); 182 } 183 184 // ------------------- Tags management -------------------- // 185 @Override 186 public void tag(String tag) throws AmetysRepositoryException 187 { 188 TaggableAmetysObjectHelper.tag(this, tag); 189 } 190 191 @Override 192 public void untag(String tag) throws AmetysRepositoryException 193 { 194 TaggableAmetysObjectHelper.untag(this, tag); 195 } 196 197 // Lock management. // 198 199 @Override 200 public void lock() throws AmetysRepositoryException 201 { 202 _getFactory().getLockComponent().lock(this); 203 } 204 205 @Override 206 public void unlock() throws AmetysRepositoryException 207 { 208 _getFactory().getLockComponent().unlock(this); 209 } 210 211 @Override 212 public boolean isLocked() throws AmetysRepositoryException 213 { 214 return _getFactory().getLockComponent().isLocked(this); 215 } 216 217 @Override 218 public UserIdentity getLockOwner() throws AmetysRepositoryException 219 { 220 return _getFactory().getLockComponent().getLockOwner(this); 221 } 222 223 // Dublin Core metadata. // 224 225 @Override 226 public void setDCTitle(String title) throws AmetysRepositoryException 227 { 228 DublinCoreHelper.setDCTitle(this, title); 229 } 230 231 @Override 232 public void setDCCreator(String creator) throws AmetysRepositoryException 233 { 234 DublinCoreHelper.setDCCreator(this, creator); 235 } 236 237 @Override 238 public void setDCSubject(String[] subject) throws AmetysRepositoryException 239 { 240 DublinCoreHelper.setDCSubject(this, subject); 241 } 242 243 @Override 244 public void setDCDescription(String description) throws AmetysRepositoryException 245 { 246 DublinCoreHelper.setDCDescription(this, description); 247 } 248 249 @Override 250 public void setDCPublisher(String publisher) throws AmetysRepositoryException 251 { 252 DublinCoreHelper.setDCPublisher(this, publisher); 253 } 254 255 @Override 256 public void setDCContributor(String contributor) throws AmetysRepositoryException 257 { 258 DublinCoreHelper.setDCContributor(this, contributor); 259 } 260 261 @Override 262 public void setDCDate(Date date) throws AmetysRepositoryException 263 { 264 DublinCoreHelper.setDCDate(this, date); 265 } 266 267 @Override 268 public void setDCType(String type) throws AmetysRepositoryException 269 { 270 DublinCoreHelper.setDCType(this, type); 271 } 272 273 @Override 274 public void setDCFormat(String format) throws AmetysRepositoryException 275 { 276 DublinCoreHelper.setDCFormat(this, format); 277 } 278 279 @Override 280 public void setDCIdentifier(String identifier) throws AmetysRepositoryException 281 { 282 DublinCoreHelper.setDCIdentifier(this, identifier); 283 } 284 285 @Override 286 public void setDCSource(String source) throws AmetysRepositoryException 287 { 288 DublinCoreHelper.setDCSource(this, source); 289 } 290 291 @Override 292 public void setDCLanguage(String language) throws AmetysRepositoryException 293 { 294 DublinCoreHelper.setDCLanguage(this, language); 295 } 296 297 @Override 298 public void setDCRelation(String relation) throws AmetysRepositoryException 299 { 300 DublinCoreHelper.setDCRelation(this, relation); 301 } 302 303 @Override 304 public void setDCCoverage(String coverage) throws AmetysRepositoryException 305 { 306 DublinCoreHelper.setDCCoverage(this, coverage); 307 } 308 309 @Override 310 public void setDCRights(String rights) throws AmetysRepositoryException 311 { 312 DublinCoreHelper.setDCRights(this, rights); 313 } 314 315 @Override 316 public Comment createComment() 317 { 318 return new Comment(this.getUnversionedMetadataHolder()); 319 } 320 321 @Override 322 public Comment getComment(String commentId) throws AmetysRepositoryException 323 { 324 return Comment.getComment(this.getUnversionedMetadataHolder(), commentId); 325 } 326 327 @Override 328 public List<Comment> getComments(boolean includeNotValidatedComments, boolean includeValidatedComments) throws AmetysRepositoryException 329 { 330 return Comment.getComments(this.getUnversionedMetadataHolder(), includeNotValidatedComments, includeValidatedComments); 331 } 332 333}