On 10/29/07, Grégory Joseph <[email protected]> wrote: > > Fabrizio, doesn't this duplicate NewPropertyTask and/or > CheckOrCreatePropertyTask ?
NewPropertyTask only creates a new property and CheckOrCreatePropertyTask expect to modify a known previous value. None of them can be used to simply set a (maybe not existing) property to a defined value. So no, it doesn't actually duplicate any of them... fabrizio On Oct 29, 2007, at 21:02 , [EMAIL PROTECTED] wrote: > > > Revision12097AuthorfgiustDate2007-10-29 21:02:56 +0100 (Mon, 29 Oct > > 2007)Log Messagea simple task to set a property valuesAdded Paths > > magnolia/trunk/magnolia-core/src/main/java/info/magnolia/module/ > > delta/SetPropertyTask.java > > Diff > > Added: magnolia/trunk/magnolia-core/src/main/java/info/magnolia/ > > module/delta/SetPropertyTask.java (12096 => 12097)--- magnolia/ > > trunk/magnolia-core/src/main/java/info/magnolia/module/delta/ > > SetPropertyTask.java 2007-10-29 17:31:00 UTC (rev 12096) +++ > > magnolia/trunk/magnolia-core/src/main/java/info/magnolia/module/ > > delta/SetPropertyTask.java 2007-10-29 20:02:56 UTC (rev 12097)@@ > > -0,0 +1,75 @@+/** + * + * Magnolia and its source-code is licensed > > under the LGPL. + * You may copy, adapt, and redistribute this file > > for commercial or non-commercial use. + * When copying, adapting, > > or redistributing this document in keeping with the guidelines > > above, + * you are required to provide proper attribution to > > obinary. + * If you reproduce or distribute the document without > > making any substantive modifications to its content, + * please use > > the following attribution line: + * + * Copyright 1993-2006 obinary > > Ltd. (http://www.obinary.com) All rights reserved. + * + */ > > +package info.magnolia.module.delta; + +import > > info.magnolia.cms.core.Content; +import > > info.magnolia.cms.core.HierarchyManager; +import > > info.magnolia.cms.core.NodeData; +import > > info.magnolia.cms.util.NodeDataUtil; +import > > info.magnolia.module.InstallContext; + +import > > javax.jcr.RepositoryException; + +import > > org.apache.commons.lang.StringUtils; + + +/** + * Sets a new value > > for a property. + * @author fgiust + * @version $Revision: $ > > ($Author: $) + */ +public class SetPropertyTask extends > > AbstractRepositoryTask { + + private final String workspaceName; > > + + private final String nodePath; + + private final String > > propertyName; + + private final String newValue; + + /** > > + * @param workspaceName + * @param nodePath + * @param > > propertyName + * @param newValue + */ + public > > SetPropertyTask(String workspaceName, String nodePath, String > > propertyName, String newValue) { + super("Sets the value for > > " + nodePath + "/" + propertyName + " value", "Sets the value for " > > + + nodePath + + "/" + + > > propertyName + + " value"); + this.workspaceName > > = workspaceName; + this.nodePath = nodePath; + > > this.propertyName = propertyName; + this.newValue = > > newValue; + } + + /** + * [EMAIL PROTECTED] + */ + > > protected void doExecute(InstallContext installContext) throws > > RepositoryException, TaskExecutionException { + + > > HierarchyManager hm = installContext.getHierarchyManager > > (workspaceName); + + Content node = hm.getContent(nodePath); > > + + NodeData property = NodeDataUtil.getOrCreate(node, > > propertyName); + + String actualValue = property.getString > > (); + if (!StringUtils.equals(newValue, StringUtils.trim > > (actualValue))) { + property.setValue(newValue); > > + } + } +} > > > > > ---------------------------------------------------------------- > for list details see > http://documentation.magnolia.info/docs/en/editor/stayupdated.html > ---------------------------------------------------------------- >
