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.Map; 021 022import javax.jcr.Node; 023 024import org.ametys.cms.content.references.OutgoingReferences; 025import org.ametys.cms.repository.ModifiableContentHelper; 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 ModifiableContentHelper.setType(this, type); 113 } 114 115 @Override 116 public void setTypes(String[] types) throws AmetysRepositoryException 117 { 118 ModifiableContentHelper.setTypes(this, types); 119 } 120 121 @Override 122 public void setMixinTypes(String[] mixins) throws AmetysRepositoryException 123 { 124 ModifiableContentHelper.setMixinTypes(this, mixins); 125 } 126 127 public void setLanguage(String language) throws AmetysRepositoryException 128 { 129 ModifiableContentHelper.setLanguage(this, language); 130 } 131 132 public void setTitle(String title) throws AmetysRepositoryException 133 { 134 ModifiableContentHelper.setTitle(this, title); 135 } 136 137 public void setCreator(UserIdentity user) throws AmetysRepositoryException 138 { 139 ModifiableContentHelper.setCreator(this, user); 140 } 141 142 public void setCreationDate(Date creationDate) throws AmetysRepositoryException 143 { 144 ModifiableContentHelper.setCreationDate(this, creationDate); 145 } 146 147 public void setLastContributor(UserIdentity user) 148 { 149 ModifiableContentHelper.setLastContributor(this, user); 150 } 151 152 public void setLastModified(Date lastModified) throws AmetysRepositoryException 153 { 154 ModifiableContentHelper.setLastModified(this, lastModified); 155 } 156 157 @Override 158 public void setLastValidationDate(Date validationDate) throws AmetysRepositoryException 159 { 160 ModifiableContentHelper.setLastValidationDate(this, validationDate); 161 } 162 163 @Override 164 public void setLastMajorValidationDate(Date validationDate) throws AmetysRepositoryException 165 { 166 ModifiableContentHelper.setLastMajorValidationDate(this, validationDate); 167 } 168 169 @Override 170 public void setOutgoingReferences(Map<String, OutgoingReferences> references) throws AmetysRepositoryException 171 { 172 ModifiableContentHelper.setOutgoingReferences(this, references); 173 } 174 175 // ------------------- Tags management -------------------- // 176 @Override 177 public void tag(String tag) throws AmetysRepositoryException 178 { 179 TaggableAmetysObjectHelper.tag(this, tag); 180 } 181 182 @Override 183 public void untag(String tag) throws AmetysRepositoryException 184 { 185 TaggableAmetysObjectHelper.untag(this, tag); 186 } 187 188 // Lock management. // 189 190 @Override 191 public void lock() throws AmetysRepositoryException 192 { 193 _getFactory().getLockComponent().lock(this); 194 } 195 196 @Override 197 public void unlock() throws AmetysRepositoryException 198 { 199 _getFactory().getLockComponent().unlock(this); 200 } 201 202 @Override 203 public boolean isLocked() throws AmetysRepositoryException 204 { 205 return _getFactory().getLockComponent().isLocked(this); 206 } 207 208 @Override 209 public UserIdentity getLockOwner() throws AmetysRepositoryException 210 { 211 return _getFactory().getLockComponent().getLockOwner(this); 212 } 213 214 // Dublin Core metadata. // 215 216 @Override 217 public void setDCTitle(String title) throws AmetysRepositoryException 218 { 219 DublinCoreHelper.setDCTitle(this, title); 220 } 221 222 @Override 223 public void setDCCreator(String creator) throws AmetysRepositoryException 224 { 225 DublinCoreHelper.setDCCreator(this, creator); 226 } 227 228 @Override 229 public void setDCSubject(String[] subject) throws AmetysRepositoryException 230 { 231 DublinCoreHelper.setDCSubject(this, subject); 232 } 233 234 @Override 235 public void setDCDescription(String description) throws AmetysRepositoryException 236 { 237 DublinCoreHelper.setDCDescription(this, description); 238 } 239 240 @Override 241 public void setDCPublisher(String publisher) throws AmetysRepositoryException 242 { 243 DublinCoreHelper.setDCPublisher(this, publisher); 244 } 245 246 @Override 247 public void setDCContributor(String contributor) throws AmetysRepositoryException 248 { 249 DublinCoreHelper.setDCContributor(this, contributor); 250 } 251 252 @Override 253 public void setDCDate(Date date) throws AmetysRepositoryException 254 { 255 DublinCoreHelper.setDCDate(this, date); 256 } 257 258 @Override 259 public void setDCType(String type) throws AmetysRepositoryException 260 { 261 DublinCoreHelper.setDCType(this, type); 262 } 263 264 @Override 265 public void setDCFormat(String format) throws AmetysRepositoryException 266 { 267 DublinCoreHelper.setDCFormat(this, format); 268 } 269 270 @Override 271 public void setDCIdentifier(String identifier) throws AmetysRepositoryException 272 { 273 DublinCoreHelper.setDCIdentifier(this, identifier); 274 } 275 276 @Override 277 public void setDCSource(String source) throws AmetysRepositoryException 278 { 279 DublinCoreHelper.setDCSource(this, source); 280 } 281 282 @Override 283 public void setDCLanguage(String language) throws AmetysRepositoryException 284 { 285 DublinCoreHelper.setDCLanguage(this, language); 286 } 287 288 @Override 289 public void setDCRelation(String relation) throws AmetysRepositoryException 290 { 291 DublinCoreHelper.setDCRelation(this, relation); 292 } 293 294 @Override 295 public void setDCCoverage(String coverage) throws AmetysRepositoryException 296 { 297 DublinCoreHelper.setDCCoverage(this, coverage); 298 } 299 300 @Override 301 public void setDCRights(String rights) throws AmetysRepositoryException 302 { 303 DublinCoreHelper.setDCRights(this, rights); 304 } 305 306 @Override 307 public Comment createComment() 308 { 309 return new Comment(this.getUnversionedMetadataHolder()); 310 } 311 312 @Override 313 public Comment getComment(String commentId) throws AmetysRepositoryException 314 { 315 return Comment.getComment(this.getUnversionedMetadataHolder(), commentId); 316 } 317 318 @Override 319 public List<Comment> getComments(boolean includeNotValidatedComments, boolean includeValidatedComments) throws AmetysRepositoryException 320 { 321 return Comment.getComments(this.getUnversionedMetadataHolder(), includeNotValidatedComments, includeValidatedComments); 322 } 323 324}