Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Link management and preparing the future

XM matures, with features enough to publish simple Web sites

Return to article.


Listing 6. DirectoryWalker redux

protected void walk(File source,File target,int depth)
   throws IOException, XMException
{
   if(source.isDirectory())
   {
      // File rulesFile = new File(source,Constants.rulesFilename);
      File[] files = source.listFiles(),
             dirs = new File[files.length],
             docs = new File[files.length];
      int idirs = 0,
          idocs = 0;
      for(int i = 0;i < files.length;i++)
      {
         if(files[i].isDirectory())
            dirs[idirs++] = files[i];
         else if(files[i].isFile())
            docs[idocs++] = files[i];
         else
            throw new NotImplementedException("Expecting file or directory");
      }
      if(!(target.exists() && target.isDirectory()))
         if(!target.mkdirs())
            messenger.fatal(new XMException(
               Resources.getString("cannotcreatedirectory"),
                                   new Object[] {target.getAbsolutePath()}));
      for(int i = 0;i < idocs;i++)
      {
         Mover mover = supervisor.getMover(docs[i]);
         File result = mover.move(docs[i],target,depth);
         messenger.progress(docs[i],result);
      }
      for(int i = 0;i < idirs;i++)
         walk(dirs[i],new File(target,dirs[i].getName()),depth + 1);
   }
   else
      messenger.fatal(new XMException(Resources.getString("notdirectory"),
                                      new Object[] {source.getAbsolutePath()}));
}

Return to article.