Open XML

For a new version of the Entity Translator check up the internet site of Open XML!

Diese Seite auf Deutsch

Entity Translator v1.0.2

Offline Documentation

What is the Entity Translator Package?

The Entity Translator Package for Delphi™ contains two components with whom certain elements of a string can be replaced by others. That allows for example to replace ordinary strings by HTML-conforming strings. The component TCharToEntityTranslator serves to replace single characters of a text by a series of characters. The other way round the component TEntityToCharTranslator serves to replace a special kind of character series, called entities, by other characters. Impotant: Entities start each with the same character (in HTML this is '&') and end each with the same character (in HTML this is ';').
 
 

System Requirements

The Entity Translator Package has been programed and tested using Delphi 3, though likewise it should work with all subsequent Delphi versions and may be also with Delphi 1 and 2. If you tested the package with another version than Delphi 3, please give us feedback whether you succeeded or not!
 
 

The Entity Translator Archive

All files needed for installing the Entity Translator can be found in a zip-archive which can be downloaded via the internet site of Open XML. This archive contains the following files:
Entity.dcr The bit maps for the Delphi component's palette
Entity.pas The Delphi source code
gitter4.gif An image used in the documentation
HtmlToLatin1.ini Example File for TEntityToCharTranslator to convert HTML into Latin-1
Latin1ToHtml.ini Example file for TCharToEntityTranslator to convert Latin-1 into HTML
liesmich.html The documentation in German
openxmllogo.gif An image used in the documentation
readme.html The documentation in English
spacer.gif An image used in the documentation
 
 

Installation

The installation procedure is as follows:
  1. Create a new directory and extract into it the zip-archive.
  2. Select the Option "Install Component" from the "Component" menu.
  3. Add the file ending with ".pas" to a new or to an already existing package.
  4. Click on OK, and next confirm that the components should be compiled and installed.
  5. Close the package window, and next confirm that the modifications should be saved.
  6. When the components have been successfully installed, a new page titled "XML" should appear in the component's palette. There you can find the new components.
 
 

TCharToEntityTranslator Component

Derived from TComponent
Unit: Entity

With a TCharToEntityTranslator Component single characters of a text can be replaced by a series of characters.


Properties

TCharToEntityTranslator.DictionaryFile

property DictionaryFile: TFileName

The property DictionaryFile is the name of the file which contains the translation table which specifies the mapping of each single character to its corresponding character series. This is a text file which lines have the following structure:
<SingleCharacter>=<CharacterSeries>

Hint: The zip-archive contains a file Latin1ToHTML.ini with which a text which was created with the help of a text editor and a Latin-1 font can be transformed in an HTML text. That changes for example every 'ß' in the Latin-1 text into '&szlig;' in the HTML text.


TCharToEntityTranslator.HasEntries (readonly)

property HasEntries: Boolean

Returns 'True' if the translation table has entries, otherwise 'False' is returned.


Methods

TCharToEntityTranslator.Create

constructor Create(AOwner: TComponent); override;

The method Create generates and installs a new instance of TCharToEntityTranslator. With create you can generate a CharToEntityTranslator at runtime. For CharToEntityTranslators which were placed at design time at a form, create will be called automatically.


TCharToEntityTranslator.Translate

function Translate(const source: string): string; virtual;

The function Translate replaces single characters of 'source' according to the translation table specified in the property 'DictionaryFile' and returns the result in a string. The property 'DictionaryFile' must have been set before to a valid translation table!


TCharToEntityTranslator.ReplaceWhiteSpace

function ReplaceWhiteSpace(const Source: string; const ReplaceChar: Char): string; virtual;

The function ReplaceWhiteSpace replaces each white space character (SPACE, TAB, LF, CR) in the string 'Source' by the character specified in 'ReplaceChar' and returns the result as a string.

Hint: Several succeeding white space characters will be replaced by the same number of 'ReplaceChar' characters.


TCharToEntityTranslator.ReplaceChar

function ReplaceChar(const Source: string; const FindChar, ReplaceChar: Char): string; virtual;

The function ReplaceChar replaces every 'FindChar' character in the string 'Source' by the character specified in 'ReplaceChar' and returns the result in a string.

Hint: This function is very helpful if one wants to hand over a text to a PageProducer. For if the text contains any white space the PageProducer would incorrectly process it. Using the ReplaceWhiteSpace function one can prevent the PageProducer from doing so by replacing each white space in the text by a character which is guarantied not to appear in the text. Example:

with CharToEntityTranslator1 do
  NewText:= ReplaceWhiteSpace(OldText,Char(1));


In the OnHTMLTag event of the PageProducers one can reconstruct the original text using the ReplaceChar function to replace the character used before by a SPACE:

with CharToEntityTranslator1 do
  OldText:= ReplaceChar(TagParams.Values['Value'],Char(1),' ');


Attention: TABs, LFs and CRs of the original text became all SPACEs now! However, for HTML this usually does not matter.

 
 

TEntityToCharTranslator Component

Derived from TCharToEntityTranslator
Unit: Entity

With a TEntityToCharTranslator component sequences of characters in a text, which are bound by certain boundary characters, can be replaced by others.


Property

TEntityToCharTranslator.DictionaryFile

property DictionaryFile: TFileName

The property DictionaryFile is the name of the file which contains the translation table which specifies the mapping of each character series to its corresponding replacement character series. This is a text file which lines have the following structure:
<CharacterSeries>=<ReplacementCharacterSeries>
where the character series has to start each with the same character and end each with the same character

Hint: The zip-archive contains a file HTMLToLatin1.ini with which a HTML text can be transformed in an text based on a Latin-1 font. That changes for example every '&szlig;' in the HTML text into 'ß' in the Latin-1 text.


TCharToEntityTranslator.HasEntries (readonly)

property HasEntries: Boolean

Returns 'True' if the translation table has entries, otherwise 'False' is returned.


TEntityToCharTranslator.LeftDelimiter

property LeftDelimiter: Char default '&';

This property contains the leading boundary character for the character sequences to be replaced. The default value is '&'.

TEntityToCharTranslator.RightDelimiter

property RightDelimiter: Char default ';';

This property contains the closing boundary character for the character sequences to be replaced. The default value is ';'.


Methods

TEntityToCharTranslator.Create

constructor Create(AOwner: TComponent); override;

The method Create generates and installs a new instance of TEntityToCharTranslator. With create you can generate a EntityToCharTranslator at runtime. For EntityToCharTranslator which were placed at design time at a form, create will be called automatically.


TEntityToCharTranslator.Translate

function Translate(const source: string): string; virtual;

The function Translate replaces certain characters sequences of 'source' according to the translation table specified in the property 'DictionaryFile' and returns the result in a string. Each character sequence to be replaced must start with those character specified in the LeftDelimiter property and must end with those character specified in the RightDelimiter property. The property 'DictionaryFile' must have been set before to a valid translation table!


TEntityToCharTranslator.ReplaceWhiteSpace

See: TCharToEntityTranslator.ReplaceWhiteSpace


TEntityToCharTranslator.ReplaceChar

See: TCharToEntityTranslator.ReplaceChar

 
 

Feedback about Open XML