CargoTranslator Class

Properties   Methods   Events   Config Settings   Errors  

The CargoTranslator class is optimized for Cargo-IMP translation, providing a simple way to convert Cargo-IMP documents to and from XML or JSON.

Syntax

ipworksedi.Cargotranslator

Remarks

The CargoTranslator class provides a simple way to convert Cargo-IMP to XML or JSON and vice versa.

Getting Started

The class will convert a document from the format specified by InputFormat to the format specified by OutputFormat. In practice this allows for converting to XML or JSON from Cargo-IMP and vice versa.

Before translating from Cargo-IMP to XML or JSON it is recommended to load a schema using the LoadSchema method. This ensures additional information can be included in the XML or JSON document. If a schema is specified the XML or JSON will include types and descriptions as element attributes which are useful for interpreting the data.

After calling Translate the resulting output will contain the Cargo-IMP, XML or JSON data as defined by OutputFormat.

Input and Output Properties

The class will determine the source and destination of the input and output based on which properties are set.

The order in which the input properties are checked is as follows:

When a valid source is found the search stops. The order in which the output properties are checked is as follows:

Schemas are written in JSON format: { "name": "FSU", "desc": "FSU MESSAGE", "children": { "1": { "desc": "Standard Message Identification", "children": { "1.1": { "desc": "Standard Message Identifier", "value": "FSU" }, "1.2": { "value": "/" }, "1.3": { "desc": "Message Type Version Number", "format": "n[...3]" }, "1.4": { "value": "\r\n" } } }, "2": { ... For example schemas and questions, please contact support@nsoftware.com.

Property List


The following is the full list of the properties of the class with short descriptions. Click on the links for further details.

ErrorsA collection of errors that occurred when parsing the Cargo-IMP messages.
InputDataThe data to translate.
InputFileThe file to translate.
InputFormatThe format of the input data.
OutputDataThe translated data.
OutputFileThe file to which the translated data will be written.
OutputFormatThe format of the output data.
OverwriteWhether to overwrite the file.
SuffixWhat to append after each segment delimiter.

Method List


The following is the full list of the methods of the class with short descriptions. Click on the links for further details.

ConfigSets or retrieves a configuration setting.
LoadSchemaLoads a schema file describing a Message type.
ResetResets the class.
SetInputStreamSets the stream from which the class will read the data to parse.
SetOutputStreamThe stream to which the class will write the translated data.
TranslateTranslates the specified data.

Event List


The following is the full list of the events fired by the class with short descriptions. Click on the links for further details.

ErrorFired when information is available about errors during data delivery.
ResolveSchemaFires whenever a new Cargo-Imp message is encountered and no schema is found for it.

Config Settings


The following is a list of config settings for the class with short descriptions. Click on the links for further details.

BuildInfoInformation about the product's build.
GUIAvailableWhether or not a message loop is available for processing events.
LicenseInfoInformation about the current license.
MaskSensitiveWhether sensitive data is masked in log messages.
UseDaemonThreadsWhether threads created by the class are daemon threads.
UseFIPSCompliantAPITells the class whether or not to use FIPS certified APIs.
UseInternalSecurityAPIWhether or not to use the system security libraries or an internal implementation.

Errors Property (CargoTranslator Class)

A collection of errors that occurred when parsing the Cargo-IMP messages.

Syntax


public CargoErrorList getErrors();


Remarks

This property is populated with error information. After calling Translate, check this property to determine if any errors occurred while parsing the message. If there are any errors present, the output from translation will likely be incorrect.

This property is read-only and not available at design time.

Please refer to the CargoError type for a complete list of fields.

InputData Property (CargoTranslator Class)

The data to translate.

Syntax


public String getInputData();


public void setInputData(String inputData);

Default Value

""

Remarks

This property specifies the data to be translated. This may be set to Cargo-IMP data or XML/JSON data. To specify the type of data held by the property set InputFormat.

Input and Output Properties

The class will determine the source and destination of the input and output based on which properties are set.

The order in which the input properties are checked is as follows:

When a valid source is found the search stops. The order in which the output properties are checked is as follows:

InputFile Property (CargoTranslator Class)

The file to translate.

Syntax


public String getInputFile();


public void setInputFile(String inputFile);

Default Value

""

Remarks

This property specifies the file to be processed. Set this property to the full or relative path to the file which will be processed. To specify the type of data in the input file set InputFormat.

Input and Output Properties

The class will determine the source and destination of the input and output based on which properties are set.

The order in which the input properties are checked is as follows:

When a valid source is found the search stops. The order in which the output properties are checked is as follows:

This property is not available at design time.

InputFormat Property (CargoTranslator Class)

The format of the input data.

Syntax


public int getInputFormat();


public void setInputFormat(int inputFormat);


Enumerated values:
  public final static int eifXML = 0;
  public final static int eifJSON = 1;
  public final static int eifCargo = 2;

Default Value

2

Remarks

This property specifies the format of the input data. The value set here, along with OutputFormat, determines how the data is converted when Translate is called.

Possible values are:

  • 0 (ifXML)
  • 1 (ifJSON)
  • 2 (ifCargo)
Before calling Translate, both InputFormat and OutputFormat must be specified. Translation from XML or JSON to Cargo-IMP and vice versa are supported. If InputFormat is ofXML or ofJSON, OutputFormat must be ofCargo. Similarly, if InputFormat is ofCargo, OutputFormat must be ofXML or ofJSON.

This property is not available at design time.

OutputData Property (CargoTranslator Class)

The translated data.

Syntax


public String getOutputData();


public void setOutputData(String outputData);

Default Value

""

Remarks

This property will be populated with the translated data after calling Translate if OutputFile and SetOutputStream are not set.

Input and Output Properties

The class will determine the source and destination of the input and output based on which properties are set.

The order in which the input properties are checked is as follows:

When a valid source is found the search stops. The order in which the output properties are checked is as follows:

This property is not available at design time.

OutputFile Property (CargoTranslator Class)

The file to which the translated data will be written.

Syntax


public String getOutputFile();


public void setOutputFile(String outputFile);

Default Value

""

Remarks

This property specifies the file to which the translated data will be written. This may be set to an absolute or relative path. This should be set before calling Translate.

Input and Output Properties

The class will determine the source and destination of the input and output based on which properties are set.

The order in which the input properties are checked is as follows:

When a valid source is found the search stops. The order in which the output properties are checked is as follows:

This property is not available at design time.

OutputFormat Property (CargoTranslator Class)

The format of the output data.

Syntax


public int getOutputFormat();


public void setOutputFormat(int outputFormat);


Enumerated values:
  public final static int eofXML = 0;
  public final static int eofJSON = 1;
  public final static int eofCargo = 2;

Default Value

0

Remarks

This property specifies the format of the output data. The value set here, along with InputFormat, determines how the data is converted when Translate is called.

Possible values are:

  • 0 (ofXML)
  • 1 (ofJSON)
  • 2 (ofCargo)
Before calling Translate, both InputFormat and OutputFormat must be specified. Translation from XML or JSON to Cargo-IMP and vice versa are supported. If InputFormat is ofXML or ofJSON, OutputFormat must be ofCargo. Similarly, if InputFormat is ofCargo, OutputFormat must be ofXML or ofJSON.

This property is not available at design time.

Overwrite Property (CargoTranslator Class)

Whether to overwrite the file.

Syntax


public boolean isOverwrite();


public void setOverwrite(boolean overwrite);

Default Value

False

Remarks

This property specifies whether the file is overwritten when Translate is called. If set to False (default) the class throws an exception when attempting to write to a file which already exists. If set to True the class will overwrite the existing file.

Suffix Property (CargoTranslator Class)

What to append after each segment delimiter.

Syntax


public int getSuffix();


public void setSuffix(int suffix);


Enumerated values:
  public final static int suffixNone = 0;
  public final static int suffixCR = 1;
  public final static int suffixLF = 2;
  public final static int suffixCRLF = 3;

Default Value

3

Remarks

If Suffix is different from suffixNone, trailing (suffix) characters are appended after each segment delimiter. This is useful if you want to have a carriage return/line feed after each segment to make the document more readable.

This property is not available at design time.

Config Method (Cargotranslator Class)

Sets or retrieves a configuration setting.

Syntax

public String config(String configurationString);

Remarks

Config is a generic method available in every class. It is used to set and retrieve configuration settings for the class.

These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the class, access to these internal properties is provided through the Config method.

To set a configuration setting named PROPERTY, you must call Config("PROPERTY=VALUE"), where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).

To read (query) the value of a configuration setting, you must call Config("PROPERTY"). The value will be returned as a string.

LoadSchema Method (Cargotranslator Class)

Loads a schema file describing a Message type.

Syntax

public void loadSchema(String fileName);

Remarks

This method parses the File and loads it into an internal schema list.

If the schema file does not exist or cannot be parsed as an Cargo-IMP schema, the class throws an exception.

Schemas are written in JSON format: { "name": "FSU", "desc": "FSU MESSAGE", "children": { "1": { "desc": "Standard Message Identification", "children": { "1.1": { "desc": "Standard Message Identifier", "value": "FSU" }, "1.2": { "value": "/" }, "1.3": { "desc": "Message Type Version Number", "format": "n[...3]" }, "1.4": { "value": "\r\n" } } }, "2": { ... For example schemas and questions, please contact support@nsoftware.com.

Reset Method (Cargotranslator Class)

Resets the class.

Syntax

public void reset();

Remarks

When called, the class initializes itself to its default state.

SetInputStream Method (Cargotranslator Class)

Sets the stream from which the class will read the data to parse.

Syntax

public void setInputStream(java.io.InputStream inputStream);

Remarks

This method sets the stream from which the class will read the data to parse.

Input Properties

The class will determine the source of the input based on which properties are set.

The order in which the input properties are checked is as follows:

When a valid source is found the search stops.

SetOutputStream Method (Cargotranslator Class)

The stream to which the class will write the translated data.

Syntax

public void setOutputStream(java.io.OutputStream outputStream);

Remarks

This method sets the stream to which the class will write the translated data.

Output Properties

The class will determine the source of the output based on which properties are set.

The order in which the output properties are checked is as follows:

When a valid source is found the search stops.

Translate Method (Cargotranslator Class)

Translates the specified data.

Syntax

public void translate();

Remarks

This method translates the specified data.

The class will convert a document from the format specified by InputFormat to the format specified by OutputFormat. In practice this allows for converting to XML or JSON from Cargo-IMP and vice versa.

Before translating from Cargo-IMP to XML or JSON it is recommended to load a schema using the LoadSchema method. This ensures additional information can be included in the XML or JSON document. If a schema is specified the XML or JSON will include types and descriptions as element attributes which are useful for interpreting the data.

After calling Translate the resulting output will contain the Cargo-IMP, XML or JSON data as defined by OutputFormat.

Input and Output Properties

The class will determine the source and destination of the input and output based on which properties are set.

The order in which the input properties are checked is as follows:

When a valid source is found the search stops. The order in which the output properties are checked is as follows:

Schemas are written in JSON format: { "name": "FSU", "desc": "FSU MESSAGE", "children": { "1": { "desc": "Standard Message Identification", "children": { "1.1": { "desc": "Standard Message Identifier", "value": "FSU" }, "1.2": { "value": "/" }, "1.3": { "desc": "Message Type Version Number", "format": "n[...3]" }, "1.4": { "value": "\r\n" } } }, "2": { ... For example schemas and questions, please contact support@nsoftware.com.

Error Event (Cargotranslator Class)

Fired when information is available about errors during data delivery.

Syntax

public class DefaultCargotranslatorEventListener implements CargotranslatorEventListener {
  ...
  public void error(CargotranslatorErrorEvent e) {}
  ...
}

public class CargotranslatorErrorEvent {
  public int errorCode;
  public String description;
}

Remarks

The Error event is fired in case of exceptional conditions during message processing. Normally the class throws an exception.

The ErrorCode parameter contains an error code, and the Description parameter contains a textual description of the error. For a list of valid error codes and their descriptions, please refer to the Error Codes section.

ResolveSchema Event (Cargotranslator Class)

Fires whenever a new Cargo-Imp message is encountered and no schema is found for it.

Syntax

public class DefaultCargotranslatorEventListener implements CargotranslatorEventListener {
  ...
  public void resolveSchema(CargotranslatorResolveSchemaEvent e) {}
  ...
}

public class CargotranslatorResolveSchemaEvent {
  public String messageIdentifier;
  public String version;
}

Remarks

The ResolveSchema event will fire when a the class encounters a new Cargo-IMP message, but it finds no schema corresponding to it already loaded.

MessageIdentifier contains the message type, such as "FWB" or "FSU".

Version contains the version of the schema used by the message.

When processing this event, the caller can use LoadSchema() to load a new schema into the class that can be used to parse the transaction.

CargoError Type

This type contains the details of an error that occurred while parsing a Cargo-IMP message.

Remarks

The fields below provide information about the error.

Fields

Description
String (read-only)

Default Value: "0"

The description of current error.

Line
int (read-only)

Default Value: 0

The text line where the error occurred.

Offset
int (read-only)

Default Value: 0

The text offset where the error occurred.

Position
int (read-only)

Default Value: 0

The text position where the error occurred.

Config Settings (Cargotranslator Class)

The class accepts one or more of the following configuration settings. Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the class, access to these internal properties is provided through the Config method.

Base Config Settings

BuildInfo:   Information about the product's build.

When queried, this setting will return a string containing information about the product's build.

GUIAvailable:   Whether or not a message loop is available for processing events.

In a GUI-based application, long-running blocking operations may cause the application to stop responding to input until the operation returns. The class will attempt to discover whether or not the application has a message loop and, if one is discovered, it will process events in that message loop during any such blocking operation.

In some non-GUI applications, an invalid message loop may be discovered that will result in errant behavior. In these cases, setting GUIAvailable to false will ensure that the class does not attempt to process external events.

LicenseInfo:   Information about the current license.

When queried, this setting will return a string containing information about the license this instance of a class is using. It will return the following information:

  • Product: The product the license is for.
  • Product Key: The key the license was generated from.
  • License Source: Where the license was found (e.g., RuntimeLicense, License File).
  • License Type: The type of license installed (e.g., Royalty Free, Single Server).
  • Last Valid Build: The last valid build number for which the license will work.
MaskSensitive:   Whether sensitive data is masked in log messages.

In certain circumstances it may be beneficial to mask sensitive data, like passwords, in log messages. Set this to true to mask sensitive data. The default is true.

This setting only works on these classes: AS3Receiver, AS3Sender, Atom, Client(3DS), FTP, FTPServer, IMAP, OFTPClient, SSHClient, SCP, Server(3DS), Sexec, SFTP, SFTPServer, SSHServer, TCPClient, TCPServer.

UseDaemonThreads:   Whether threads created by the class are daemon threads.

If set to True (default), when the class creates a thread, the thread's Daemon property will be explicitly set to True. When set to False, the class will not set the Daemon property on the created thread. The default value is True.

UseFIPSCompliantAPI:   Tells the class whether or not to use FIPS certified APIs.

When set to true, the class will utilize the underlying operating system's certified APIs. Java editions, regardless of OS, utilize Bouncy Castle FIPS, while all the other Windows editions make use of Microsoft security libraries.

The Java edition requires installation of the FIPS certified Bouncy Castle library regardless of the target operating system. This can be downloaded from https://www.bouncycastle.org/fips-java/. Only the "Provider" library is needed. The jar file should then be installed in a JRE search path.

In the application where the component will be used the following classes must be imported:

import java.security.Security; import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider;

The Bouncy Castle provider must be added as a valid provider and must also be configured to operate in FIPS mode:

System.setProperty("org.bouncycastle.fips.approved_only","true"); Security.addProvider(new BouncyCastleFipsProvider());

When UseFIPSCompliantAPI is true, SSL enabled classes can optionally be configured to use the TLS Bouncy Castle library. When SSLProvider is set to sslpAutomatic (default) or sslpInternal an internal TLS implementation is used, but all cryptographic operations are offloaded to the BCFIPS provider in order to achieve FIPS compliant operation. If SSLProvider is set to sslpPlatform the Bouncy Castle JSSE will be used in place of the internal TLS implementation.

To enable the use of the Bouncy Castle JSSE take the following steps in addition to the steps above. Both the Bouncy Castle FIPS provider and the Bouncy Castle JSSE must be configured to use the Bouncy Castle TLS library in FIPS mode. Obtain the Bouncy Castle TLS library from https://www.bouncycastle.org/fips-java/. The jar file should then be installed in a JRE search path.

In the application where the component will be used the following classes must be imported:

import java.security.Security; import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider; //required to use BCJSSE when SSLProvider is set to sslpPlatform import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider;

The Bouncy Castle provider must be added as a valid provider and must also be configured to operate in FIPS mode:

System.setProperty("org.bouncycastle.fips.approved_only","true"); Security.addProvider(new BouncyCastleFipsProvider()); //required to use BCJSSE when SSLProvider is set to sslpPlatform Security.addProvider(new BouncyCastleJsseProvider("fips:BCFIPS")); //optional - configure logging level of BCJSSE Logger.getLogger("org.bouncycastle.jsse").setLevel(java.util.logging.Level.OFF); //configure the class to use BCJSSE component.setSSLProvider(1); //platform component.config("UseFIPSCompliantAPI=true"); Note: TLS 1.3 support requires the Bouncy Castle TLS library version 1.0.14 or later.

FIPS mode can be enabled by setting the UseFIPSCompliantAPI configuration setting to true. This is a static setting which applies to all instances of all classes of the toolkit within the process. It is recommended to enable or disable this setting once before the component has been used to establish a connection. Enabling FIPS while an instance of the component is active and connected may result in unexpected behavior.

For more details please see the FIPS 140-2 Compliance article.

Note: Enabling FIPS-compliance requires a special license; please contact sales@nsoftware.com for details.

UseInternalSecurityAPI:   Whether or not to use the system security libraries or an internal implementation.

When set to false, the class will use the system security libraries by default to perform cryptographic functions where applicable.

Setting this configuration setting to true tells the class to use the internal implementation instead of using the system security libraries.

This setting is set to false by default on all platforms.

Trappable Errors (Cargotranslator Class)

CargoTranslator Errors

304   Could not write to file.
1000   Invalid schema file.
1001   No schema found.
1002   Schema format error.
1003   Line or message was too long.
1004   Failed to parse the message version.
1005   Element is not in the schema file or is not a simple element.
1006   Could not find the element.