From 6452bb76c4eb927c3b0ff9fe04555945adfc1bc9 Mon Sep 17 00:00:00 2001 From: jensp Date: Mon, 2 Jan 2012 18:31:38 +0000 Subject: [PATCH] =?UTF-8?q?-=20Erste=20Version=20eines=20Tool=20zum=20vers?= =?UTF-8?q?chieben=20eines=20Orderns=20samt=20Inhalt=20in=20eine=20andere?= =?UTF-8?q?=20Content-Section.=20Folgende=20=20=20Einschr=C3=A4nkungen:=20?= =?UTF-8?q?Alle=20Items=20im=20Ordner=20werden=20depubliziert.=20Nach=20de?= =?UTF-8?q?m=20Verschieben=20ist=20den=20Items=20kein=20Workflow=20zugeord?= =?UTF-8?q?net.=20-=20Kleinere=20Bug=20Fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.libreccm.org/ccm/trunk@1414 8810af33-2d31-482b-a856-94f89814c4df --- ...ublicPersonalProfileExtraXmlGenerator.java | 3 +- .../ExampleGenerator.java | 3 +- .../arsdigita/london/util/cmd/MoveFolder.java | 202 ++++++++++++++++++ 3 files changed, 206 insertions(+), 2 deletions(-) create mode 100644 ccm-ldn-util/src/com/arsdigita/london/util/cmd/MoveFolder.java diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileExtraXmlGenerator.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileExtraXmlGenerator.java index 7aead13e6..793cf128e 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileExtraXmlGenerator.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileExtraXmlGenerator.java @@ -90,7 +90,8 @@ public class PublicPersonalProfileExtraXmlGenerator implements ExtraXMLGenerator generator.generateContent(profileContent, profile.getOwner(), - state); + state, + profile.getLanguage()); } else { throw new UncheckedWrapperException(String.format( diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/ExampleGenerator.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/ExampleGenerator.java index f8a6aeacc..1f7d8d39c 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/ExampleGenerator.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/ExampleGenerator.java @@ -14,7 +14,8 @@ public class ExampleGenerator implements ContentGenerator { public void generateContent(final Element parent, final GenericPerson person, - final PageState state) { + final PageState state, + final String profileLanguage) { Element message = parent.newChildElement("message"); message.setText("Hello World!"); diff --git a/ccm-ldn-util/src/com/arsdigita/london/util/cmd/MoveFolder.java b/ccm-ldn-util/src/com/arsdigita/london/util/cmd/MoveFolder.java new file mode 100644 index 000000000..e9df1e019 --- /dev/null +++ b/ccm-ldn-util/src/com/arsdigita/london/util/cmd/MoveFolder.java @@ -0,0 +1,202 @@ +package com.arsdigita.london.util.cmd; + +import com.arsdigita.cms.ContentBundle; +import com.arsdigita.cms.ContentItem; +import com.arsdigita.cms.ContentSection; +import com.arsdigita.cms.ContentSectionCollection; +import com.arsdigita.cms.Folder; +import com.arsdigita.cms.ItemCollection; +import com.arsdigita.packaging.Program; +import java.util.Arrays; +import org.apache.commons.cli.CommandLine; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class MoveFolder extends Program { + + public MoveFolder() { + super("MoveFolder", + "1.0.0", + ""); + } + + public static void main(final String[] args) { + new MoveFolder().run(args); + } + + @Override + protected void doRun(final CommandLine cmdLine) { + + final String[] args = cmdLine.getArgs(); + + if (args.length != 2) { + System.err.println("Usage:"); + System.err.println("MoveFolder sourcecontentsection/source/folder " + + "targetcontentsection/target/"); + System.exit(-1); + } + + System.out.printf("Moving folder '%s' to '%s'...\n", + args[0], + args[1]); + + final String[] sourcePathTokens = args[0].split("/"); + final String[] targetPathTokens = args[1].split("/"); + + final ContentSection sourceContentSection = + getContentSection(sourcePathTokens[0]); + final ContentSection targetContentSection = + getContentSection(targetPathTokens[0]); + + if (sourceContentSection == null) { + System.err.printf("Failed to find source content section '%s'.", + sourcePathTokens[0]); + } + + if (targetContentSection == null) { + System.err.printf("Failed to find target content section '%s'.", + targetPathTokens[0]); + } + + final Folder sourceFolder = getFolder(Arrays.copyOfRange( + sourcePathTokens, + 1, + sourcePathTokens.length), + sourceContentSection); + final Folder targetFolder = getFolder(Arrays.copyOfRange( + targetPathTokens, + 1, + targetPathTokens.length), + targetContentSection); + + System.out.println("Depublishing all items in folder..."); + depublish(sourceFolder); + + System.out.println("Setting content section for folder to remove..."); + sourceFolder.setContentSection(targetContentSection); + sourceFolder.save(); + targetContentSection.save(); + System.out.println("Setting parent to target folder..."); + sourceFolder.setParent(targetFolder); + sourceFolder.save(); + targetFolder.save(); + + System.out.println("Setting content sections on items..."); + setContentSection(sourceFolder, targetContentSection); + + System.out.println("Done."); + + } + + private ContentSection getContentSection(final String name) { + final ContentSectionCollection sections = + ContentSection.getAllSections(); + + sections.addFilter(String.format("title = '%s'", name)); + + if (sections.isEmpty()) { + return null; + } else { + sections.next(); + final ContentSection result = sections.getContentSection(); + sections.close(); + return result; + } + } + + private Folder getFolder(final String[] path, + final ContentSection fromSection) { + final Folder root = fromSection.getRootFolder(); + Folder folder = root; + for (int i = 0; i < path.length; i++) { + folder = getSubFolder(root, path[i]); + + if (folder == null) { + break; + } + } + + return folder; + } + + private Folder getSubFolder(final Folder parent, + final String name) { + final Folder.ItemCollection items = parent.getItems(); + items.addFolderFilter(true); + items.addFilter(String.format("name = '%s'", name)); + + if (items.isEmpty()) { + return null; + } else { + items.next(); + final Folder folder = (Folder) items.getContentItem(); + items.close(); + return folder; + } + } + + private void depublish(final Folder folder) { + final Folder.ItemCollection items = folder.getItems(); + + ContentItem item; + while (items.next()) { + item = items.getContentItem(); + System.out.printf("Depublishing item '%s' (%s)...\n", + item.getName(), + item.getOID().toString()); + + if (item instanceof Folder) { + depublish((Folder) item); + } else if(item instanceof ContentBundle) { + depublish((ContentBundle) item); + } else { + item.unpublish(); + } + } + } + + private void depublish(final ContentBundle bundle) { + final ItemCollection items = bundle.getInstances(); + + while(items.next()) { + items.getContentItem().unpublish(); + } + } + + private void setContentSection(final Folder folder, + final ContentSection contentSection) { + final Folder.ItemCollection items = folder.getItems(); + + folder.setContentSection(contentSection); + folder.save(); + + ContentItem item; + while (items.next()) { + item = items.getContentItem(); + System.out.printf("Setting content section on item '%s' (%s)...\n", + item.getName(), + item.getOID().toString()); + + if (item instanceof Folder) { + setContentSection((Folder) item, contentSection); + } else if (item instanceof ContentBundle) { + setContentSection((ContentBundle) item, contentSection); + } else { + item.setContentSection(contentSection); + item.save(); + } + } + } + + private void setContentSection(final ContentBundle bundle, + final ContentSection contentSection) { + final ItemCollection items = bundle.getInstances(); + + while(items.next()) { + items.getContentItem().setContentSection(contentSection); + } + } +}