Transact

⌘K
  1. Home
  2. Transact
  3. Developer Documentation
  4. Scripting Resources
  5. JDOM Script Configuration

JDOM Script Configuration

Update the dcma-scripting-plugin.properties in {EPHESOFT_INSTALL_DIR}EphesoftApplicationWEB-INFclassesMETA-INFdcma-scripting-plugin

  • script.parser_type= jdom

If anything other than jdom is specified for script.parser_type then the IScript parser will be used and Scripts using IScript will be executed.

Sample Scripts for comparison ISCRIPT and JDOM

Let’s take the simple example for converting IScript scripts into JDOM scripts. Changes to be made to convert the present script to JDOM.

1) Change the import statement

  • import org.w3c.IScript.Document;
  • import org.w3c.IScript.Node;
  • import org.w3c.IScript.NodeList;
  • import com.ephesoft.dcma.script.IScripts;
to
  • import org.jdom.Document;
  • import org.jdom.Element;
  • import org.jdom.output.XMLOutputter;
  • import com.ephesoft.dcma.script.IJDomScript;

and replace the following import

import com.ephesoft.dcma.script.IScripts;

with the following

import com.ephesoft.dcma.script.IJDomScript;
2) Change the implements statement

IJDomScript is the interface for running the JDOM Scripts. Each scripts should implements IJDomScript for running the customize script using JDOM.
public class ScriptAutomaticValidation implements IScripts {
to
public class ScriptAutomaticValidation implements IJDomScript {

3) API difference in JDOM w.r.t ISCRIPT

Getting the list document object in JDOM is different from ISCRIPT:
In JDOM we need to iterate each node for getting the child element list because JDOM doesn’t access the child tag directly without accessing the parent tag of that child tag.

1. Getting Pages Nodes in JDOM vs. ISCRIPT

JDOM IScript
// Getting PAGES tag with accessing its parent in batch.xml// Getting first child of root nodeElement documents = document.getRootElement().getChild(DOCUMENTS);

// Getting first child of DOCUMENTS node

List documentList = documents.getChildren(DOCUMENT); for (int documentIndex = 0; documentIndex < documentList.size(); documentIndex++) { Element document = (Element) documentList.get(documentIndex); Element pages = (Element) document.getChild(PAGES); }

// Getting directly PAGES tag without accessing its parent in batch.xmlNodeList documentList = document.getElementsByTagName(PAGES);

2. Getting Text Content from element:

JDOM IScript
String elementValue = element.getText(); String elementValue = element.getTextContent();

3. Setting Text Context in element:

JDOM IScript
element.setText(“String Data”); element.setTextContent(“String Data”);

4. To get a child node for any particular node :

JDOM IScript
Element variableName = (Element) parentElement.getChild(“Name_of_child”); Element variableName = (Element) parentElement.getChild(“Name_of_child”);

5. To get the textual content of the named child element:

JDOM IScript
String textName = element.getChildText(“Name_of_child”); String name = parentElement.getElementsByTagName(” Name “).item(0).getTextContent();

6. To set the textual content of the element:

JDOM IScript
Element.setText(“Text_to_be_put_as_name”); Element.setTextContent(“Text_to_be_put_as_name”);

7. To create a new child node in the parent:

JDOM IScript
Element newElement = new
Element(“Name_of_element”); parentElement.addContent( newElement);
Element childElement = document.createElement(“Child”);parentElement.appendChild(childElement);Here document is the argument passed to the method.
Ex: “execute(Document document, String fieldName, String docIdentifier)”

How to implement zip functionality in the present scripts

Changes needed to be made to the scripts for making the old scripts work with the new ZIP functionality. For each script:

1. Add the following import statements to the script java class file:

  • import java.util.zip.ZipEntry;
  • import java.util.zip.ZipOutputStream;
  • import java.io.File;
  • import java.io.FileWriter;
  • import java.io.OutputStream;
  • import java.io.FileOutputStream;
  • import java.io.IOException;
  • import java.io.FileNotFoundException;
  • import java.util.List;
2. Add the following property after the import statements:

  • private static String ZIP_FILE_EXT = “.zip”;
3. Replace the entire writeToXML method in each of the scripts with the following updated version:
private void writeToXML(Document document) {
String batchLocalPath = null;
Element batchLocalPathElement = document.getRootElement().getChild(BATCH_LOCAL_PATH);
if (null != batchLocalPathElement) {
batchLocalPath = batchLocalPathElement.getText();}
if (null == batchLocalPath) {
System.err.println(“Unable to find the local folder path in batch xml file.”);
return;
}
String batchInstanceID = null;
Element batchInstanceIDElement = document.getRootElement().getChild(BATCH_INSTANCE_ID);
if (null != batchInstanceIDElement) {
batchInstanceID = batchInstanceIDElement.getText();}
if (null == batchInstanceID) {
System.err.println(“Unable to find the batch instance ID in batch xml file.”);
return;}
String batchXMLPath = batchLocalPath.trim() + File.separator + batchInstanceID + File.separator + batchInstanceID+ EXT_BATCH_XML_FILE;
String batchXMLZipPath = batchXMLPath + ZIP_FILE_EXT;
System.out.println(“batchXMLZipPath************” + batchXMLZipPath);
OutputStream outputStream = null;
File zipFile = new File(batchXMLZipPath);
FileWriter writer = null;
XMLOutputter out = new XMLOutputter();
try {
if (zipFile.exists()) {
System.out.println(“Found the batch xml zip file.”);
outputStream = getOutputStreamFromZip(batchXMLPath, batchInstanceID + EXT_BATCH_XML_FILE);
out.output(document, outputStream);
} else {
writer = new java.io.FileWriter(batchXMLPath);
out.output(document, writer);
writer.flush();
writer.close();}
} catch (Exception e) {
System.err.println(e.getMessage());
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
}}}}
4. Add the following method to the script java class file, as it is required by the new writeToXml() function:
public static OutputStream getOutputStreamFromZip(final String zipName,final String fileName) throws FileNotFoundException, IOException {
ZipOutputStream stream = null;
stream = new ZipOutputStream(new FileOutputStream(new File(zipName
+ ZIP_FILE_EXT)));
ZipEntry zipEntry = new ZipEntry(fileName);
stream.putNextEntry(zipEntry);
return stream;
}