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