From: <fg...@us...> - 2008-07-24 08:30:40
|
Revision: 892 http://openutils.svn.sourceforge.net/openutils/?rev=892&view=rev Author: fgiust Date: 2008-07-24 08:30:43 +0000 (Thu, 24 Jul 2008) Log Message: ----------- new tasks for checking/replacing templates Modified Paths: -------------- trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/DisableSubscribersTask.java trunk/openutils-mgnltasks/src/site/changes/changes.xml Added Paths: ----------- trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/BaseCheckMissingTask.java trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CheckMissingParagraphsTask.java trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CheckMissingTemplatesTask.java trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/ReplaceTemplateTask.java Added: trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/BaseCheckMissingTask.java =================================================================== --- trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/BaseCheckMissingTask.java (rev 0) +++ trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/BaseCheckMissingTask.java 2008-07-24 08:30:43 UTC (rev 892) @@ -0,0 +1,157 @@ +/** + * 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.beans.config.ContentRepository; +import info.magnolia.cms.core.Content; +import info.magnolia.cms.core.HierarchyManager; +import info.magnolia.cms.core.search.Query; +import info.magnolia.cms.core.search.QueryManager; +import info.magnolia.module.InstallContext; +import info.magnolia.module.delta.AbstractRepositoryTask; +import info.magnolia.module.delta.TaskExecutionException; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import javax.jcr.RepositoryException; +import javax.jcr.query.InvalidQueryException; + +import org.apache.commons.lang.StringUtils; + + +/** + * An abstract task that check for invalid templates/paragraphs. Should not be used directly, see + * {@link CheckMissingTemplatesTask} and {@link CheckMissingParagraphsTask} instead. + * @author fgiust + * @version $Id: $ + */ +public abstract class BaseCheckMissingTask extends AbstractRepositoryTask +{ + + private final String templateOrParagraph; + + private final String nodetype; + + /** + * @param templateOrParagraph "template" or "paragraph" + * @param nodetype node type foc checked nodes + */ + public BaseCheckMissingTask(String templateOrParagraph, String nodetype) + { + super("Check " + templateOrParagraph + "s task", "Checking pages configured with missing " + + templateOrParagraph + + "s"); + this.templateOrParagraph = templateOrParagraph; + this.nodetype = nodetype; + + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + @Override + protected void doExecute(InstallContext installContext) throws RepositoryException, TaskExecutionException + { + + QueryManager configQueryManager = installContext + .getHierarchyManager(ContentRepository.CONFIG) + .getQueryManager(); + + Collection<Content> templates = configQueryManager.createQuery( + "//modules/*/" + templateOrParagraph + "s/*", + Query.XPATH).execute().getContent("mgnl:contentNode"); + + List<String> templ = new ArrayList<String>(); + Iterator<Content> availableTemplates = templates.iterator(); + while (availableTemplates.hasNext()) + { + Content template = availableTemplates.next(); + templ.add(template.getName()); + } + + checkInvalidPages(installContext, templ); + + } + + /** + * @param installContext + * @param templates + * @throws RepositoryException + * @throws InvalidQueryException + */ + @SuppressWarnings("unchecked") + private void checkInvalidPages(InstallContext installContext, List<String> templates) throws RepositoryException, + InvalidQueryException + { + HierarchyManager hm = installContext.getHierarchyManager(ContentRepository.WEBSITE); + + QueryManager qm = hm.getQueryManager(); + + StringBuilder query = new StringBuilder("//*[jcr:primaryType='" + + this.nodetype + + "' and MetaData/mgnl:template and not("); + + Iterator<String> nameIterator = templates.iterator(); + while (nameIterator.hasNext()) + { + String template = nameIterator.next(); + + query.append("MetaData/mgnl:template='"); + query.append(template); + query.append("'"); + if (nameIterator.hasNext()) + { + query.append(" or "); + } + } + + query.append(")]"); + + String queryAAsString = query.toString(); + + log.debug("Running query: {}", queryAAsString); + + Collection<Content> nodes = qm.createQuery(queryAAsString, Query.XPATH).execute().getContent(this.nodetype); + + int count = 0; + StringBuilder sb = new StringBuilder(); + + for (Content page : nodes) + { + String template = page.getMetaData().getTemplate(); + + if (StringUtils.isNotEmpty(template)) + { + count++; + sb.append(page.getHandle()); + sb.append(" "); + sb.append(template); + sb.append("\n"); + } + } + + if (count > 0) + { + log.error("Found {} pages with invalid templates:\n{}", count, sb.toString()); + } + } +} Property changes on: trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/BaseCheckMissingTask.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/CheckMissingParagraphsTask.java =================================================================== --- trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CheckMissingParagraphsTask.java (rev 0) +++ trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CheckMissingParagraphsTask.java 2008-07-24 08:30:43 UTC (rev 892) @@ -0,0 +1,35 @@ +/** + * 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; + +/** + * A task that checks for pages that contains invalid (missing) paragraphs and logs the result as an error on startup. + * Please note that this task collect the paragraph list extracting any direct subnode of the "paragraphs" nodes in each + * installed module, and not using ParagraphManager (not yet initialized at startup). + * @author fgiust + * @version $Id: $ + */ +public class CheckMissingParagraphsTask extends BaseCheckMissingTask +{ + + public CheckMissingParagraphsTask() + { + super("paragraph", "mgnl:contentNode"); + } + +} Property changes on: trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CheckMissingParagraphsTask.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/CheckMissingTemplatesTask.java =================================================================== --- trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CheckMissingTemplatesTask.java (rev 0) +++ trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CheckMissingTemplatesTask.java 2008-07-24 08:30:43 UTC (rev 892) @@ -0,0 +1,35 @@ +/** + * 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; + +/** + * A task that checks for pages that contains invalid (missing) templates and logs the result as an error on startup. + * Please note that this task collect the template list extracting any direct subnode of the "templates" nodes in each + * installed module, and not using TemplateManager (not yet initialized at startup). + * @author fgiust + * @version $Id: $ + */ +public class CheckMissingTemplatesTask extends BaseCheckMissingTask +{ + + public CheckMissingTemplatesTask() + { + super("template", "mgnl:content"); + } + +} Property changes on: trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CheckMissingTemplatesTask.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/DisableSubscribersTask.java =================================================================== --- trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/DisableSubscribersTask.java 2008-07-21 13:27:33 UTC (rev 891) +++ trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/DisableSubscribersTask.java 2008-07-24 08:30:43 UTC (rev 892) @@ -17,6 +17,7 @@ */ package it.openutils.mgnltasks; +import info.magnolia.cms.beans.config.ContentRepository; import info.magnolia.cms.core.Content; import info.magnolia.cms.core.HierarchyManager; import info.magnolia.cms.core.NodeData; @@ -53,7 +54,7 @@ protected void doExecute(InstallContext installContext) throws RepositoryException, TaskExecutionException { - HierarchyManager hm = installContext.getHierarchyManager("config"); + HierarchyManager hm = installContext.getHierarchyManager(ContentRepository.CONFIG); if (hm.isExist(subscribersPath)) { Added: trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/ReplaceTemplateTask.java =================================================================== --- trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/ReplaceTemplateTask.java (rev 0) +++ trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/ReplaceTemplateTask.java 2008-07-24 08:30:43 UTC (rev 892) @@ -0,0 +1,91 @@ +/** + * 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.beans.config.ContentRepository; +import info.magnolia.cms.core.Content; +import info.magnolia.cms.core.HierarchyManager; +import info.magnolia.cms.core.search.Query; +import info.magnolia.cms.core.search.QueryManager; +import info.magnolia.module.InstallContext; +import info.magnolia.module.delta.AbstractRepositoryTask; +import info.magnolia.module.delta.TaskExecutionException; + +import java.util.Collection; + +import javax.jcr.RepositoryException; + + +/** + * A task that replace any occurrence of a given template with another at startup (handy for renamed templates). + * @author fgiust + * @version $Id: $ + */ +public class ReplaceTemplateTask extends AbstractRepositoryTask +{ + + private final String actualTemplate; + + private final String newTemplate; + + /** + * @param actualTemplate template to be replaced + * @param newTemplate new template + */ + public ReplaceTemplateTask(String actualTemplate, String newTemplate) + { + super("Replacing template " + actualTemplate + " with " + newTemplate, "Replacing template " + + actualTemplate + + " with " + + newTemplate); + this.actualTemplate = actualTemplate; + this.newTemplate = newTemplate; + + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + @Override + protected void doExecute(InstallContext installContext) throws RepositoryException, TaskExecutionException + { + + HierarchyManager hm = installContext.getHierarchyManager(ContentRepository.WEBSITE); + + QueryManager qm = hm.getQueryManager(); + + StringBuilder query = new StringBuilder("//*[MetaData/mgnl:template ='"); + query.append(actualTemplate); + query.append("']"); + + String queryAAsString = query.toString(); + + log.debug("Running query: {}", queryAAsString); + + Collection<Content> nodes = qm.createQuery(queryAAsString, Query.XPATH).execute().getContent(); + + for (Content page : nodes) + { + log.warn("Replacing template " + page.getMetaData().getTemplate() + " with {} in {}", newTemplate, page + .getHandle()); + page.getMetaData().setTemplate(newTemplate); + } + } + +} Property changes on: trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/ReplaceTemplateTask.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 2008-07-21 13:27:33 UTC (rev 891) +++ trunk/openutils-mgnltasks/src/site/changes/changes.xml 2008-07-24 08:30:43 UTC (rev 892) @@ -8,6 +8,10 @@ <author email="fgiust(at)users.sourceforge.net">Fabrizio Giustina</author> </properties> <body> + <release version="3.5.4" date="2008-07-24" description=""> + <action type="add" dev="fgiust">new tasks: CheckMissingTemplatesTask, CheckMissingParagraphsTask, + ReplaceTemplateTask</action> + </release> <release version="3.5.3" date="2008-06-24" description=""> <action type="add" dev="fgiust">new CheckAndCreateRoleTask and CheckAndCreateGroupTask</action> <action type="update" dev="fgiust">AnonymousUserSetupTask now also takes care of changing This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2008-07-27 09:19:24
|
Revision: 897 http://openutils.svn.sourceforge.net/openutils/?rev=897&view=rev Author: fgiust Date: 2008-07-27 09:19:30 +0000 (Sun, 27 Jul 2008) Log Message: ----------- new tasks: AddPermissionTask and CreateDefaultRepositoryAclForAllUsersTask Modified Paths: -------------- trunk/openutils-mgnltasks/src/site/changes/changes.xml Added Paths: ----------- trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/AddPermissionTask.java trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CreateDefaultRepositoryAclForAllUsersTask.java Added: trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/AddPermissionTask.java =================================================================== --- trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/AddPermissionTask.java (rev 0) +++ trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/AddPermissionTask.java 2008-07-27 09:19:30 UTC (rev 897) @@ -0,0 +1,137 @@ +/** + * 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.beans.config.ContentRepository; +import info.magnolia.cms.core.Content; +import info.magnolia.cms.core.HierarchyManager; +import info.magnolia.cms.core.Path; +import info.magnolia.cms.security.AccessDeniedException; +import info.magnolia.cms.util.NodeDataUtil; +import info.magnolia.module.InstallContext; +import info.magnolia.module.delta.AbstractRepositoryTask; +import info.magnolia.module.delta.Task; +import info.magnolia.module.delta.TaskExecutionException; + +import java.util.Collection; + +import javax.jcr.RepositoryException; + + +/** + * Sets or add permissions on a repository:path for a given role. + * @author fgiust + * @version $Id: $ + */ +public class AddPermissionTask extends AbstractRepositoryTask implements Task +{ + + private final String role; + + private final String repo; + + private final String path; + + private final long permission; + + public AddPermissionTask(String role, String repo, String path, long permission) + { + super("Setup permissions on " + repo + ":" + path + " for " + role, "Setup permissions on " + + repo + + ":" + + path + + " for " + + role); + this.role = role; + this.repo = repo; + this.path = path; + this.permission = permission; + + } + + /** + * {@inheritDoc} + */ + @Override + protected void doExecute(InstallContext installContext) throws RepositoryException, TaskExecutionException + { + + HierarchyManager hm = installContext.getHierarchyManager(ContentRepository.USER_ROLES); + + Content roleNode = hm.getContent("/" + role); + + setupAcl(roleNode, repo, path, permission); + } + + /** + * @param role + * @param repository + * @param newpermissions + * @throws RepositoryException + * @throws AccessDeniedException + */ + @SuppressWarnings("unchecked") + private void setupAcl(Content role, String repository, String path, long newpermissions) + throws RepositoryException, AccessDeniedException + { + Content acls = role.getChildByName("acl_" + repository); + + if (acls == null) + { + acls = role.createContent("acl_" + repository, "mgnl:contentNode"); + } + + Collection<Content> children = acls.getChildren(); + + boolean found = false; + for (Content acl : children) + { + String aclPath = acl.getNodeData("path").getString(); + if (path.equals(aclPath)) + { + found = true; + + long permissions = acl.getNodeData("permissions").getLong(); + if (permissions != newpermissions) + { + setPermission(acl, path, newpermissions); + } + } + } + if (!found) + { + Content acl = acls.createContent(Path.getUniqueLabel(acls, "0"), "mgnl:contentNode"); + setPermission(acl, path, newpermissions); + + } + } + + /** + * @param acl + * @param newpermissions + * @throws RepositoryException + * @throws AccessDeniedException + */ + private void setPermission(Content acl, String path, long newpermissions) throws RepositoryException, + AccessDeniedException + { + log.info("Setting permissions for {} to {}", this.repo + ":" + path, this.role); + NodeDataUtil.getOrCreate(acl, "path").setValue(path); + NodeDataUtil.getOrCreate(acl, "permissions").setValue(newpermissions); + } +} Property changes on: trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/AddPermissionTask.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/CreateDefaultRepositoryAclForAllUsersTask.java =================================================================== --- trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CreateDefaultRepositoryAclForAllUsersTask.java (rev 0) +++ trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CreateDefaultRepositoryAclForAllUsersTask.java 2008-07-27 09:19:30 UTC (rev 897) @@ -0,0 +1,93 @@ +/** + * 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.beans.config.ContentRepository; +import info.magnolia.cms.core.Content; +import info.magnolia.cms.core.HierarchyManager; +import info.magnolia.cms.core.ItemType; +import info.magnolia.cms.util.ContentUtil; +import info.magnolia.module.InstallContext; +import info.magnolia.module.delta.AbstractRepositoryTask; +import info.magnolia.module.delta.TaskExecutionException; + +import java.util.Collection; + +import javax.jcr.RepositoryException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Adds a default repository permissions for all the configured users, only if there is no acl set for the given + * repository. + * @author fgiust + * @version $Id: $ + */ +public class CreateDefaultRepositoryAclForAllUsersTask extends AbstractRepositoryTask +{ + + private static Logger log = LoggerFactory.getLogger(CreateDefaultRepositoryAclForAllUsersTask.class); + + private String repository; + + private long permissions; + + public CreateDefaultRepositoryAclForAllUsersTask(String repository, long permissions) + { + super("Adding permissions on " + repository + " repository", "Adding permissions on " + + repository + + " repository"); + this.repository = repository; + this.permissions = permissions; + } + + @SuppressWarnings("unchecked") + @Override + protected void doExecute(InstallContext ctx) throws RepositoryException, TaskExecutionException + { + HierarchyManager hm = ctx.getHierarchyManager(ContentRepository.USER_ROLES); + final Content parentNode = hm.getContent("/"); + + final Collection<Content> childNodes = ContentUtil.collectAllChildren(parentNode, ItemType.ROLE); + + for (Content content : childNodes) + { + operateOnChildNode(content, ctx); + } + } + + protected void operateOnChildNode(Content node, InstallContext ctx) throws RepositoryException, + TaskExecutionException + { + + String aclpath = "acl_" + repository; + + if (!node.hasContent(aclpath)) + { + log.info("adding permissions on {} to role {}", repository, node.getName()); + + Content aclnode = node.createContent(aclpath, ItemType.CONTENTNODE); + Content permNode = aclnode.createContent("0", ItemType.CONTENTNODE); + permNode.createNodeData("path", "/*"); + permNode.createNodeData("permissions", new Long(permissions)); + } + } + +} Property changes on: trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/CreateDefaultRepositoryAclForAllUsersTask.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 2008-07-24 08:49:42 UTC (rev 896) +++ trunk/openutils-mgnltasks/src/site/changes/changes.xml 2008-07-27 09:19:30 UTC (rev 897) @@ -8,6 +8,9 @@ <author email="fgiust(at)users.sourceforge.net">Fabrizio Giustina</author> </properties> <body> + <release version="3.5.5" date="2008-07-27" description=""> + <action type="add" dev="fgiust">new tasks: AddPermissionTask, CreateDefaultRepositoryAclForAllUsersTask</action> + </release> <release version="3.5.4" date="2008-07-24" description=""> <action type="add" dev="fgiust">new tasks: CheckMissingTemplatesTask, CheckMissingParagraphsTask, ReplaceTemplateTask</action> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |