From: <fg...@us...> - 2009-05-02 12:25:24
|
Revision: 1174 http://openutils.svn.sourceforge.net/openutils/?rev=1174&view=rev Author: fgiust Date: 2009-05-02 12:25:07 +0000 (Sat, 02 May 2009) Log Message: ----------- new tasks Modified Paths: -------------- trunk/openutils-mgnltasks/src/site/changes/changes.xml Added Paths: ----------- trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CreateMissingPropertyTask.java trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/DirectoryBootstrapTask.java Added: trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CreateMissingPropertyTask.java =================================================================== --- trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CreateMissingPropertyTask.java (rev 0) +++ trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CreateMissingPropertyTask.java 2009-05-02 12:25:07 UTC (rev 1174) @@ -0,0 +1,80 @@ +/** + * Copyright Openmind http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package it.openutils.mgnltasks; + +import info.magnolia.cms.core.Content; +import info.magnolia.cms.core.HierarchyManager; +import info.magnolia.cms.core.NodeData; +import info.magnolia.cms.util.ContentUtil; +import info.magnolia.cms.util.NodeDataUtil; +import info.magnolia.module.InstallContext; +import info.magnolia.module.delta.AbstractRepositoryTask; +import info.magnolia.module.delta.TaskExecutionException; + +import javax.jcr.RepositoryException; + + +/** + * Set a nodedata if not existing. Also creates the full path if missing. + * @author fgiust + * @version $Id$ + */ +public class CreateMissingPropertyTask extends AbstractRepositoryTask +{ + + private final String workspaceName; + + private final String nodePath; + + private final String propertyName; + + private final String propertyValue; + + public CreateMissingPropertyTask( + String name, + String description, + String workspaceName, + String nodePath, + String propertyName, + String propertyValue) + { + super(name, description); + this.workspaceName = workspaceName; + this.nodePath = nodePath; + this.propertyName = propertyName; + this.propertyValue = propertyValue; + } + + /** + * {@inheritDoc} + */ + @Override + protected void doExecute(InstallContext ctx) throws RepositoryException, TaskExecutionException + { + final HierarchyManager hm = ctx.getHierarchyManager(workspaceName); + + final Content node = ContentUtil.createPath(hm, nodePath, false); + if (!node.hasNodeData(propertyName)) + { + NodeData property = NodeDataUtil.getOrCreate(node, propertyName); + property.setValue(propertyValue); + } + + } + +} Property changes on: trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CreateMissingPropertyTask.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/DirectoryBootstrapTask.java =================================================================== --- trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/DirectoryBootstrapTask.java (rev 0) +++ trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/DirectoryBootstrapTask.java 2009-05-02 12:25:07 UTC (rev 1174) @@ -0,0 +1,51 @@ +/** + * Copyright Openmind http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package it.openutils.mgnltasks; + +import info.magnolia.module.InstallContext; +import info.magnolia.module.delta.BootstrapResourcesTask; + +import org.apache.commons.lang.StringUtils; + + +/** + * Bootstrap al the files in a given directory. + * @author fgiust + * @version $Id$ + */ +public class DirectoryBootstrapTask extends BootstrapResourcesTask +{ + + private final String directory; + + public DirectoryBootstrapTask(String directory) + { + super("Bootstrap", "Bootstraps all the file in the mgnl-bootstrap/" + directory + " directory"); + this.directory = directory; + } + + /** + * Accepts any resource directly under "/mgnl-bootstrap/directory" but not recursive into sub-directories. + */ + @Override + protected boolean acceptResource(InstallContext ctx, String resourceName) + { + final String resourceFilename = StringUtils.substringAfter(resourceName, "/mgnl-bootstrap/" + directory + "/"); + return !StringUtils.contains(resourceFilename, "/") && resourceFilename.endsWith(".xml"); + } +} Property changes on: trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/DirectoryBootstrapTask.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/openutils-mgnltasks/src/site/changes/changes.xml =================================================================== --- trunk/openutils-mgnltasks/src/site/changes/changes.xml 2009-04-29 20:42:27 UTC (rev 1173) +++ trunk/openutils-mgnltasks/src/site/changes/changes.xml 2009-05-02 12:25:07 UTC (rev 1174) @@ -8,6 +8,9 @@ <author email="fgiust(at)users.sourceforge.net">Fabrizio Giustina</author> </properties> <body> + <release version="4.0.1" date="2009-05-02" description=""> + <action type="add" dev="fgiust">new tasks: CreateMissingPropertyTask, DirectoryBootstrapTask</action> + </release> <release version="4.0" date="2009-03-12" description=""> <action type="update" dev="fgiust">Updated to magnolia 4.0. This release will not work correctly with previous versions. Please note that previous 3.x releases don't fully work with magnolia 4.0 either.</action> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |