If you need to generate DCRs from the command line, before, with the perl templates, we could use iwgen, iwregen, iwpt_compile to do our work for us. Now, we can’t because these tools do not support the XSL presentations we want to give them.

So, to paliate to this lack, we can create a class that’s going to do it from the command line.

 The engine behind all this is Xalan, so we can call it via the command line like this:

java org.apache.xalan.xslt.Process -IN absoluteDCRPath  -XSL absoluteXSLPath -OUT outputfilePath

However, this does not create the extended attributes we require. For this, you will need to connect ot teamsite, acquire the file and set the attributes that are required. This class below opens the DCR, transforms it using the XSL and sets the extended attributes as required.

 * To change this template, choose Tools | Templates
 * and open the template in the editor.
package picquet.teamsite.utils;

import com.interwoven.cssdk.common.CSClient;
import com.interwoven.cssdk.common.CSException;
import com.interwoven.cssdk.factory.CSFactory;
import com.interwoven.cssdk.factory.CSLocalFactory;
import com.interwoven.cssdk.filesys.CSVPath;
import com.interwoven.cssdk.filesys.CSExtendedAttribute;
import com.interwoven.cssdk.filesys.CSSimpleFile;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.Locale;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamResult;
import org.xml.sax.InputSource;

 * @author piquetl
public class XSLTransformer {

    public static void main(String[] args) {

        if (args.length<3){
            System.err.println("Usage: java picquet.teamsite.utils.XSLTransformer dcr xsl outputfile");
            System.err.println("file names should be absolute.");

        // grab the arguments, with more meaningful names
        String inputFileName = args[0];
        String xslStylesheetName = args[1];
        String outputFileName = args[2];

        // acquire a transformation engine based on the specified xsl
        Transformer transformer = null;
        try {
            TransformerFactory transformerFactory = TransformerFactory.newInstance();
            transformer = transformerFactory.newTransformer(new SAXSource(new InputSource(xslStylesheetName)));
        } catch (Exception e) {
            System.out.println("could not create a document builder");

        InputSource inputSource = new InputSource(inputFileName);
        try {
            FileOutputStream outputStream = new FileOutputStream(outputFileName);
            transformer.transform(new SAXSource(inputSource), new StreamResult(outputStream));
        } catch (TransformerException ex) {
            Logger.getLogger(XSLTransformer.class.getName()).log(Level.SEVERE, "Error transforming the source file with the xsl stylesheet into the output file.", ex);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(XSLTransformer.class.getName()).log(Level.SEVERE, "Output file not found.", ex);

        // connect to teamsite, so that we can apply the extended attributes on the file.
        Properties localProperties = new Properties();
        localProperties.setProperty("cssdk.cfg.path", "/apps/interwoven/teamsite/cssdk/cssdk.cfg");
        CSFactory factory = CSLocalFactory.getFactory(localProperties);
        CSClient client;
        try {
            // guessing the extended attributes
            CSExtendedAttribute[] extendedAttributes = new CSExtendedAttribute[3];
            String dcrType = inputFileName.replaceAll(".*templatedata/(.*)?/data/.*", "$1");
            String primaryDCR = inputFileName.replaceAll(".*templatedata/.*/data/(.*)", "$1");
            String primaryPT = inputFileName.replaceAll(".*templatedata/.*/presentation/(.*)", "$1");

            // applying the extended attributes
            client = factory.getClientForCurrentUser(new Locale("en", "uk"), "XSLTransformer", "localhost");
            CSSimpleFile outputFile = (CSSimpleFile) client.getFile(new CSVPath(outputFileName));
            extendedAttributes[0] = new CSExtendedAttribute("TeamSite/Templating/PrimaryDocumentType", dcrType);
            extendedAttributes[1] = new CSExtendedAttribute("TeamSite/Templating/PrimaryDCR", primaryDCR);
            extendedAttributes[2] = new CSExtendedAttribute("TeamSite/Templating/PrimaryPT", primaryPT);
        } catch (CSException ex) {
            Logger.getLogger(XSLTransformer.class.getName()).log(Level.SEVERE, "Unable to apply extended attributes to the output file", ex);

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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