This is a TeamSite 6.7.2/LiveSite 3.1 compliant mechanism that can be used to read all DCR files into a single XML files for further processing:

package com.littleforest.examples;

import com.interwoven.livesite.dom4j.Dom4jUtils;
import com.interwoven.livesite.external.ParameterHash;
import com.interwoven.livesite.runtime.RequestContext;
import com.interwoven.livesite.file.FileDALIfc;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.*;
import org.dom4j.*;
import java.util.Properties; /* Added for proxy use */
import com.interwoven.livesite.external.*;
import java.io.IOException;

public class xmlFileListContents {

public Document fetchTree(RequestContext context)
{
//look in ALL directories
Document doc = Dom4jUtils.newDocument();
Element fileElem = doc.addElement("Records");

FileDALIfc fileDAL = context.getFileDal();

String areaRelativeBasePath = context.getParameterString("BaseDirectory");

String absoluteBasePath = fileDAL.getRoot() + fileDAL.getSeparator() + areaRelativeBasePath;

//recurse directories
String[] directories = fileDAL.getChildDirectories(absoluteBasePath);
int dirCount = directories.length;

for(int k=0;k<dirCount;k++)
{
String absoluteDirPath = absoluteBasePath + fileDAL.getSeparator() + directories[k];

//recurse files in directories
String[] files = fileDAL.getChildFiles(absoluteDirPath);
int count = files.length;

for(int j=0;j<count;j++)
{
String absoluteFilePath = absoluteDirPath + fileDAL.getSeparator() + files[j];
Document fileDCR = Dom4jUtils.newDocument(fileDAL.read(absoluteFilePath))  ;

//add path as an attribute
fileDCR.getRootElement().addAttribute("path",absoluteFilePath);
// add the dcr to the result doc;
fileElem.add(fileDCR.getRootElement().createCopy())  ;
//optionally, may prefer path as an element
//fileElem.addElement("../path").addText(absoluteFilePath);
}

}

//ensure we have those in the Base too
String[] baseFiles = fileDAL.getChildFiles(absoluteBasePath);
int fCount = baseFiles.length;

for(int i=0;i<fCount;i++)
{
String absoluteFilePath = absoluteBasePath + fileDAL.getSeparator() + baseFiles[i];
Document fileDCR = Dom4jUtils.newDocument(fileDAL.read(absoluteFilePath))  ;

//add path as an attribute
fileDCR.getRootElement().addAttribute("path",absoluteFilePath);
// add the dcr to the result doc;
fileElem.add(fileDCR.getRootElement().createCopy())  ;
//optionally, may prefer path as an element
//fileElem.addElement("../path").addText(absoluteFilePath);
}

return doc;
}

}

Accessibility

LFi Accessibility tool gives you instant reports on how your pages perform against all major standards including WCAG 1.0, 2.0, etc.

Learn more

Multi-National Dashboards

Our dashboards allow you to spot trends in seconds. Customised by your business needs, you choose how our platform works for you.

Learn more

Content Audit

As LFi automates the audit of your website, it hugely speeds up the process of gathering the information you need.

Learn more
By |2017-10-05T16:08:19+00:00March 2nd, 2009|Articles, Java|0 Comments

About the Author: