Recursive sites folders Datasource

Posted: 20 July 2009 in CSSDK, Java, SitePublisher, Sites, Teamsite, Worfklow models, Workflows

This code recursively traverses the sites directory of the current workarea and returns each  folder.

This is usefull when creating new pages automatically through workflows.

package com.acme.intranet;

import com.interwoven.cssdk.common.CSClient;
import com.interwoven.cssdk.common.CSException;
import com.interwoven.cssdk.filesys.CSAreaRelativePath;
import com.interwoven.cssdk.filesys.CSDir;
import com.interwoven.cssdk.filesys.CSVPath;
import com.interwoven.cssdk.filesys.CSWorkarea;
import com.interwoven.datasource.SortedValuesMapDataSource;
import com.interwoven.datasource.core.DataSourceContext;
import com.interwoven.livesite.common.cssdk.datasource.AbstractDataSource;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

public class SiteFoldersDataSource extends AbstractDataSource implements SortedValuesMapDataSource {

    private Map<String, String> dataSourceValues = new HashMap<String, String>();
    private File startingDirectory = null;

    public final void traverse( final File f ) throws IOException {
  if (f.isDirectory()) {
   final File[] childs = f.listFiles();
   for( File child : childs ) {

    /* method executed whenever a directory is encountered. */
    public void onDirectory(final File directory) {
        String directoryRelativePath = new CSVPath(directory.getAbsolutePath()).getAreaRelativePath().toString();
        String directoryPath=directory.getAbsolutePath();
        if (!directory.equals(startingDirectory)) {
            // omit the sites directory
            dataSourceValues.put(directoryRelativePath, directoryRelativePath);

    /* method executed whenever a file is encountered. You should override this method */
    public void onFile( final File f ) {

    public Map<String, String> execute(DataSourceContext dsContext) {
        CSClient client = getClient(dsContext);
        try {
            CSWorkarea workarea = client.getWorkarea(new CSVPath(dsContext.getServerContext()).getArea(), true);
            String sitesDirectoryRelativePath="sites";
            CSDir sitesCSDirectory = (CSDir) workarea.getFile(new CSAreaRelativePath(sitesDirectoryRelativePath));
            startingDirectory = new File(sitesCSDirectory.getVPath().getPathNoServer().toString());

            try {
            } catch (IOException ex) {
                Logger.getLogger(SiteFoldersDataSource.class.getName()).log(Level.SEVERE, null, ex);
        } catch (CSException ex) {
            Logger.getLogger(SiteFoldersDataSource.class.getName()).log(Level.SEVERE, null, ex);
  1. Abdul khadar says:

    Hi Laurent,

    I need a help on teamsite..
    I read all your blogs, they were very helpful.
    I have a problem while submitting a content.
    When i select *publish content and try to submit it throws an error saying failed to instantiate workflow model and when i click details it shows list of exceptions from interwoven which says CSauthorizationexception: (operation not permitted)
    I am not able to identify or solve this issue. could you please let me know what can be the problem??
    Thanks in advance.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s