Difference between revisions of "Extensions.ZipHandling.ZipFile"

From emotive
Jump to navigation Jump to search
(Created page with "{{DISPLAYTITLE: '''OpenScreen'''}}Category:HMI == Classification == {{ClassificationActivity | OpenScreen | Creates and displays a custom screen at runtime | Action|...")
 
Line 1: Line 1:
{{DISPLAYTITLE:  '''OpenScreen'''}}[[Category:HMI]]
+
{{DISPLAYTITLE:  '''ZipFile'''}}[[Category:Zip]]
 
== Classification ==
 
== Classification ==
{{ClassificationActivity | OpenScreen | Creates and displays a custom screen at runtime | [[Action]]| [[Extensions.HMI|OTX HMI extension]] | [[Extensions.HMI#Actions|Custom screen related actions]] | [[Extensions.HMI.ScreenException|ScreenException]] | [[Core.Validation.CoreChk053|Core_Chk053]] <br/> [[Extensions.HMI.HMIChk002|HMI_Chk002]] <br/> [[Extensions.HMI.HMIChk003|HMI_Chk003]] <br/> [[Extensions.HMI.HMIChk004|HMI_Chk004]] <br/> [[Extensions.HMI.HMIChk005|HMI_Chk005]]}}
+
{{ClassificationActivity | ZipFile | Compresses the file or folder | [[Action]]| [[Extensions.ZipHandling|OTX ZipHandling extension]] | - | [[Extensions.Zip.FileAlreadyExistsException|FileAlreadyExistsException]] <br/>[[Extensions.Zip.FileNotFoundException|FileNotFoundException]] | [[Core.Validation.ZipFiles_Chk002|ZipFiles_Chk002]]}}
  
 
== OTL Syntax ==
 
== OTL Syntax ==
 
<syntaxhighlight lang="java" enclose="div" style="font-size: medium;">
 
<syntaxhighlight lang="java" enclose="div" style="font-size: medium;">
Hmi.OpenScreen(ScreenVariable screenHandle, OtxLink screen, {ScreenArguments[ ] arguments}, Boolean modal);
+
ZipHandling.ZipFile(StringTerm source, StringTerm target, ListTerm extensions, BooleanTerm append, BooleanTerm override);
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
== Description ==
 
== Description ==
The '''OpenScreen''' creates activity and displays a custom ''screen'' at runtime. The ''screen'' will be displayed immediately and can accept user input. If other ''screens'' are already open when the new ''screen'' is opened, the test application shall ensure that the new screen is not hidden by other screens.
+
Compresses the file or folder denoted by the given source path. If the path points to a single file, only that file will be stored in the target file. If the path points to a folder, the folder and all its contents (files and subfolders in arbitrary depth) will be stored in the target file. In the case of a folder, that folder will be the root element in the target file. <br/>
 +
It is possible to control which files to add by passing in a list of allowed file extensions. Only the files that match one of the given file extension strings will be added (including the folder structures they are contained in). <br/>
 +
Furthermore it is possible to specify whether an existing target file will be overridden or not. Depending on whether the source(s) will be appended to an existing ZIP file, a flag controls whether or not the corresponding flag is set to TRUE, then any existing ZIP file will be silently overridden. Otherwise, if the flag is set to FALSE and the denoted target file already exists, an exception is thrown.
  
 
== Properties ==
 
== Properties ==
 
{| {{TableHeader}}
 
{| {{TableHeader}}
 
{{TableRowPropertiesHeader}}
 
{{TableRowPropertiesHeader}}
{{TableRowPropertie1| Screen | [[OtxLink]] | - | - | [1] | This attribute contains a name which points to a '''ScreenSignature''' which contains a parameter description for the screen that shall be opened.}}
+
{{TableRowPropertie1| Source | [[Core.DataTypes.SimpleDataType.String|String]] | - | - | [1..1] | Contains the path to the to-be-zipped file or folder. The path shall be a URI, relative to the OTX_HOME directory. If the file or folder denoted by this path does not exist or is not accessible, an exception is thrown.}}
{{TableRowPropertie2| ArgumentsList | [[ScreenArguments]] | - | - | [0..1] | This simple container element represents a list of arguments for an open screen call.}}
+
{{TableRowPropertie2| Target | [[Core.DataTypes.SimpleDataType.String|String]] | - | - | [1..1] | Contains the path to the target ZIP file. The path shall be a URI, relative to the OTX_HOME directory. If the file denoted by this path already exists and the override flag is not set or set to FALSE, then an exception is thrown. Also if the file already exists and cannot be overridden, or if it cannot be created at the given location, an exception is thrown.}}
{{TableRowPropertie1| Modal | [[Core.DataTypes.SimpleDataType.Boolean|Boolean]] | [[Value]] | false | [0..1] | This option tells the runtime system to make this screen modal or non-modal.}}
+
{{TableRowPropertie1| Extensions | [[Core.DataTypes.ComplexDataType.List|List]] | - | - | [0..1] | The extensions element is a List of Strings. It contains a list of file extension strings. Only files, that have the given file extension (e.g. "txt": files ending with .txt) will be stored in the zip file. <br/>
{{TableRowPropertie2| ScreenHandle | [[Extensions.HMI.Screen|Screen]] | [[Variable]] | - | [0..1] | This optional element represents the variable which shall be the handle for the opened screen.}}
+
This element is optional and if omitted, no filtering is performed, accepting any file with any file extension. In case, that files without an extension should be zipped an empty string is used. <br/>
 +
It is possible to provide strings that contain wildcard characters. These are used as placeholders for arbitrary characters. The characters are: <br/>
 +
⎯ '*' (asterisk) for an arbitrary amount [0..*] of consecutive characters. <br/>
 +
⎯ '?' (question mark) for exactly one arbitrary character. <br/>
 +
'''EXAMPLE:''' <br/>
 +
With the extensions of ["t?t"] the following files will match (amongst others): <br/>
 +
⎯ File.txt <br/>
 +
⎯ File.tut <br/>
 +
⎯ File.t1t <br/>
 +
The following files will not match: <br/>
 +
⎯ File.tt <br/>
 +
⎯ File.text <br/>
 +
⎯ File.log <br/>
 +
'''EXAMPLE:''' <br/>
 +
With the extension of ["log*"] the following files will match (amongst others): <br/>
 +
⎯ File.log <br/>
 +
⎯ File.log1 <br/>
 +
⎯ File.log_02 <br/>
 +
⎯ File.log.01 <br/>
 +
The following file will not match: <br/>
 +
⎯ File.3log <br/>
 +
⎯ File.lg.log <br/>
 +
⎯ File.zip <br/>
 +
'''IMPORTANT — Case sensitivity is platform dependent and may vary depending on the underlying system. It might therefore be necessary to provide a list with upper case and lower case variants of the same extension (e.g. "txt" and "TXT").'''}}
 +
{{TableRowPropertie2| Append | [[Core.DataTypes.SimpleDataType.Boolean|Boolean]] | - | - | [0..1] | If this flag is set to TRUE, then the to be zipped sources shall be appended to an existing ZIP file, instead of replacing that ZIP file with a new one. <br/>
 +
If this flag is omitted, it defaults to FALSE. <br/>
 +
If the target ZIP file does not exist and the append flag is provided and resolves to TRUE, a [[Extensions.Zip.FileNotFoundException|FileNotFoundException]] is thrown.}}
 +
{{TableRowPropertie1| Override | [[Core.DataTypes.SimpleDataType.Boolean|Boolean]] | - | - | [0..1] | Determines whether an already existing target file shall be overridden or not.
 +
If the flag evaluates to TRUE, an existing target file will be silently overridden. <br/>
 +
If it evaluates to FALSE, an existing target file will cause an exception to be thrown. <br/>
 +
If the flag is omitted, it defaults to FALSE. <br/>
 +
If the append flag is present and evaluates to TRUE, then the override flag concerns overriding files in the target ZIP file. This means, that the above mentioned rules are applied to the contents of the target ZIP file, possibly throwing a [[Extensions.Zip.FileAlreadyExistsException|FileAlreadyExistsException]], if any of the source files is already stored in the denoted ZIP file. In case an exception occurs the existing zip file shall be unchanged.}}
 
|}
 
|}
  
Line 31: Line 64:
 
{
 
{
 
/// Local Declarations
 
/// Local Declarations
 
HMI.Screen ScreenHandle1;
 
Integer Integer1;
 
  
 
/// Flow
 
/// Flow
  
HMI.OpenScreen(ScreenHandle1, ScreenSignature1, {ScreenInOutParameter1 = Integer1}, false);
+
ZipHandling.ZipFile("file:///D:/FolderUnZipped", "file:///D:/FileZipped.zip", {"t?t"}, false, true);
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
== See also ==
 
== See also ==
[[Extensions.HMI.HighlightScreen|HighlightScreen]] <br/>
+
[[Extensions.ZipHandling.UnZipFile|UnZipFile]]
[[Extensions.HMI.CloseScreen|CloseScreen]]
 

Revision as of 08:27, 11 September 2019

Classification

Name ZipFile
Short Description Compresses the file or folder
Class Action
Extension OTX ZipHandling extension
Group -
Exceptions FileAlreadyExistsException
FileNotFoundException
Checker Rules ZipFiles_Chk002
Standard Compliant Yes

OTL Syntax

ZipHandling.ZipFile(StringTerm source, StringTerm target, ListTerm extensions, BooleanTerm append, BooleanTerm override);

Description

Compresses the file or folder denoted by the given source path. If the path points to a single file, only that file will be stored in the target file. If the path points to a folder, the folder and all its contents (files and subfolders in arbitrary depth) will be stored in the target file. In the case of a folder, that folder will be the root element in the target file.
It is possible to control which files to add by passing in a list of allowed file extensions. Only the files that match one of the given file extension strings will be added (including the folder structures they are contained in).
Furthermore it is possible to specify whether an existing target file will be overridden or not. Depending on whether the source(s) will be appended to an existing ZIP file, a flag controls whether or not the corresponding flag is set to TRUE, then any existing ZIP file will be silently overridden. Otherwise, if the flag is set to FALSE and the denoted target file already exists, an exception is thrown.

Properties

Name Data Type Class Default Cardinality Description
Source String - - [1..1] Contains the path to the to-be-zipped file or folder. The path shall be a URI, relative to the OTX_HOME directory. If the file or folder denoted by this path does not exist or is not accessible, an exception is thrown.
Target String - - [1..1] Contains the path to the target ZIP file. The path shall be a URI, relative to the OTX_HOME directory. If the file denoted by this path already exists and the override flag is not set or set to FALSE, then an exception is thrown. Also if the file already exists and cannot be overridden, or if it cannot be created at the given location, an exception is thrown.
Extensions List - - [0..1] The extensions element is a List of Strings. It contains a list of file extension strings. Only files, that have the given file extension (e.g. "txt": files ending with .txt) will be stored in the zip file.

This element is optional and if omitted, no filtering is performed, accepting any file with any file extension. In case, that files without an extension should be zipped an empty string is used.
It is possible to provide strings that contain wildcard characters. These are used as placeholders for arbitrary characters. The characters are:
⎯ '*' (asterisk) for an arbitrary amount [0..*] of consecutive characters.
⎯ '?' (question mark) for exactly one arbitrary character.
EXAMPLE:
With the extensions of ["t?t"] the following files will match (amongst others):
⎯ File.txt
⎯ File.tut
⎯ File.t1t
The following files will not match:
⎯ File.tt
⎯ File.text
⎯ File.log
EXAMPLE:
With the extension of ["log*"] the following files will match (amongst others):
⎯ File.log
⎯ File.log1
⎯ File.log_02
⎯ File.log.01
The following file will not match:
⎯ File.3log
⎯ File.lg.log
⎯ File.zip
IMPORTANT — Case sensitivity is platform dependent and may vary depending on the underlying system. It might therefore be necessary to provide a list with upper case and lower case variants of the same extension (e.g. "txt" and "TXT").

Append Boolean - - [0..1] If this flag is set to TRUE, then the to be zipped sources shall be appended to an existing ZIP file, instead of replacing that ZIP file with a new one.

If this flag is omitted, it defaults to FALSE.
If the target ZIP file does not exist and the append flag is provided and resolves to TRUE, a FileNotFoundException is thrown.

Override Boolean - - [0..1] Determines whether an already existing target file shall be overridden or not.

If the flag evaluates to TRUE, an existing target file will be silently overridden.
If it evaluates to FALSE, an existing target file will cause an exception to be thrown.
If the flag is omitted, it defaults to FALSE.
If the append flag is present and evaluates to TRUE, then the override flag concerns overriding files in the target ZIP file. This means, that the above mentioned rules are applied to the contents of the target ZIP file, possibly throwing a FileAlreadyExistsException, if any of the source files is already stored in the denoted ZIP file. In case an exception occurs the existing zip file shall be unchanged.

OTL Examples

/// Signatures

package HMI.ScreenSignature ScreenSignature1(ref Integer ScreenInOutParameter1);

/// Global Declarations

public procedure main()
{
	/// Local Declarations

	/// Flow

	ZipHandling.ZipFile("file:///D:/FolderUnZipped", "file:///D:/FileZipped.zip", {"t?t"}, false, true);
}

See also

UnZipFile