• Get the Flash Player to see the slideshow.
  • Categories

  • Authors

  • Great Quotes

    Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it! — Goethe

Get in touch...

To have a chat about
your CMS needs...

Call us 0207 193 2014
or
Email us on

Posts Tagged ‘dcr’

Read a Single XML File in Java

Monday, March 2nd, 2009

The following should complement the supplied article for reading XML files (DCRs) based on a directory.  This will read the contents of a singe file

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.external.*;
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 java.io.IOException;
import com.interwoven.livesite.file.FileDALIfc; /* Added to avoid use of CDATA write */
 
public class xmlDcrUtilities{
 
public Document readSingle(RequestContext context)
{
//look in any single directory only
Document doc = Dom4jUtils.newDocument();
Element fileElem = doc.addElement("Records");
 
FileDALIfc fileDAL = context.getFileDal();
 
String absoluteFilePath = context.getParameterString("DCRPath");
 
Document fileDCR = Dom4jUtils.newDocument(fileDAL.read(absoluteFilePath))  ;
fileElem.add(fileDCR.getRootElement().createCopy())  ;
 
return doc;
}
 
}