Programming API
TrapEd has now (since Version 2.0) opened it's internals to let
you do what you want and automate your processes.
The API is only available in a licensed version of TrapEd.
The API is of course written in Tcl. So if you
don't know Tcl, don't be afraid, it's really easy to learn, as you
will see from the examples given here.
To get access to the interactive API open a DOS-box (via
start-menu than do execute..., type in
cmd than change to the traped-directory of
the TrapEd-distribution in the opened DOS-box). Than start TrapEd
like this:
traped.exe -script interactive
Instead of the usual TrapEd-gui a console pops up in which you can
type in your commands which are executed immediatly when you hit the
return-key.
(With the command exit you can close the console and exit TrapEd).
The following sections is divided in the following sections:
Available Commands
The following sections describes all available commands.
This is the detailed description of all the commands.
If not mentioned otherwise the expected results (which are mentioned in the
examples) always refer to the example-attr-file which you should have
Downloaded with the trial-copy of TrapEd.
readAttrFile - read an attr-file
| Syntax
| readAttrFile [options] filename with filename being an existing attr-file and options could be -utf8 1 (which is the default when no options are provided) or -utf8 0, telling TrapEd to read the attr-file as Latin-1 (only Vignette version less than V6).
|
| Return
| a handle which can be used as a command for further access to the attr-file.
|
| Description
| This is usually the first command to use. You provide a filename and TrapEd reads the content of the Vignette attr-file into it's internal structure (this may take as long and will eat as much memory as if you use the TrapEd-gui.
readAttrFile returns a handle to the internal structure, this handle will be used as a new command in subsequent calls.
|
| Example
| set trapedHandle [readAttrFile "d:/example.attr"]
|
getRootId - get the ID of the root-element
| Syntax
| handle getRootId
|
| Return
| Vignette-ID of the root-element (e.g. "/pr/a", if you have an attr-file of the complete project-hierarchie.)
|
| Description
| To loop through your templates or whatever you usually need a start.
getRootId gives you the Vignette-ID of the toplevel-project.
|
| Example
| set trapedHandle [readAttrFile "d:/example.attr"]
set rootId [$trapedHandle getRootId]
|
getType - retrieve the type
| Syntax
| handle getType id with id being a regular Vignette-ID (e.g. "/pr/a")."]
|
| Return
| The type of this thing is returned: Project, Template, File or Record."]
|
| Description
| Determine the object-type of the given ID."]
|
| Example
| set trapedHandle [readAttrFile "d:/example.attr"]
set rootId [$trapedHandle getRootId]
# this should print "Project"
puts [$trapedHandle getType $rootId]
|
getIdList - get a list of all IDs below
| Syntax
| handle getIdList type [project-id]
project-id is optional and must be a valid Vignette-ID of a project, if not provided the root-id is used
type is one of {Template, File, Record, Project}.
|
| Return
| A list of Vignette-IDs of objects of type lying directly under the given project.
|
| Description
| With getIdList you get the possibility to browse through all items in the attr-file.
|
| Example
| set trapedHandle [readAttrFile "d:/example.attr"]
# no ID provided => rootId "/pr/44" is used
# this should print templateId: "/ci/8f"
puts [$trapedHandle getIdList Template]
|
getIdListRecursive - get an ID-list recursively
| Syntax
| handle getIdListRecursive type [project-id]
project-id is optional and if given a valid Vignette-project-ID (or root-id)
type is one of {Template, File, Record, Project}.
|
| Return
| A list of Vignette-IDs of all objects of type lying beneath the given project.
|
| Description
| Like getIdList but returns all ids even if in subprojects.
|
| Example
| set trapedHandle [readAttrFile "d:/example.attr"]
# no ID provided => rootId "/pr/44" is used
# this should print the following templateId-list: "/ci/8f /ci/1631 /ci/162e /ci/9a"
puts [$trapedHandle getIdListRecursive Template]
|
getAttributeValue - determine attribute-value
| Syntax
| handle getAttributeValue id attribute
|
| Return
| the value of attribute from id
|
| Description
| With this function you can access everything that is stored inside an attr-file and provided by TrapEd. For a description of the known attributes, see Supported attributes. The following table shows the supported attributes for the API. Attention: attribute is case-sensitive!
|
| Example
| set trapedHandle [readAttrFile "d:/example.attr"]
# no ID provided => rootId "/pr/44" is used
foreach id [$trapedHandle getIdListRecursive Template] {
puts "$id State: [$trapedHandle getAttributeValue $id State]"
puts "$id cache: [$trapedHandle getAttributeValue $id cache]"
}
This should print the following:
/ci/8f State: Working
/ci/8f cache: n
/ci/1631 State: Working
/ci/1631 cache: y
/ci/162e State: Working
/ci/162e cache: n
/ci/9a State: Ready To Launch
/ci/9a cache: y
|
| Project | Template | File | Record |
| - | AlwaysPrivate | AlwaysPrivate | AlwaysPrivate |
Authz (Tcl-list of authorized users to access the project) | - | - | - |
| CreatedBy | CreatedBy | CreatedBy | CreatedBy |
CreateTime in seconds since 1970 (see Statistics). | CreateTime | CreateTime | CreateTime |
| - | - | - | DatabaseName |
| - | - | - | DatabaseServer |
| LastModifier | LastModifier | LastModifier | LastModifier |
LastModTime (same format as CreateTime). | LastModTime | LastModTime | LastModTime |
| Name | Name | Name | Name |
| - | - | - | NameOfTable |
ParentProject (id of parent-project) If this attribute is modified a move is executed. | ParentProject | ParentProject | ParentProject |
| - | Paths | Paths | - |
Producers (Tcl-list of producers for that project) | - | - | - |
| - | - | - | PrimaryKeyName |
| - | RecordID | - | RecordID |
| - | State (e.g. Working) | State | State |
| - | Subtype (e.g. Other) | - | - |
| - | TemplateType (one of TSP, ASP, JSP) This attribute is read-only. | - | - |
| - | body (the template-code) | - | - |
| - | browserCaps (the variation-number) | - | - |
| - | cache (y == template is cached,
n == not cached) | - | - |
| - | deleted (y == template has been deleted,
n == not deleted) | - | - |
| - | ext (the extension, usually html) | - | - |
| - | tableName (if you had an association to a database-table) | - | - |
setAttributeValue - modify attribute-value
| Syntax
| handle setAttributeValue id attribute new_value
|
| Return
| nothing
|
| Description
| Modify the attribute-value. If you provide wrong values (e.g. x for cache) an error is thrown which should be catched with catch.
You can set the following attribute (but use this with care): TemplateType (JSP, TSP or ASP) CreateTime LastModTime ParentProject.
|
| Example
| # Set all template to "not-cached"
set trapedHandle [readAttrFile "d:/example.attr"]
# no ID provided => rootId "/pr/44" is used
foreach id [$trapedHandle getIdListRecursive Template] {
$trapedHandle setAttributeValue $id cache y
}
$trapedHandle writeToFile "d:/example.attr"
if you would run the example code for getAttributeValue again all caching should now be set to 'y'
|
getAttributes - get all attributes at once
| Syntax
| handle getAttributes id
|
| Return
| a key-value list of all attributes with their corresponding values
|
| Description
| Get all available attribute for the specified item {Template, File, Record or Project}.
Be aware the timestamps are returned in seconds since 1970 and not in the native Vignette-format.
|
| Example
| set tH [readAttrFile "d:/example.attr"]
$tH getAttributes [$trapedHandle getRootId]
This would return: e.g.
CreatedBy TrapEd CreateTime 1047401249 LastModifier TrapEd LastModTime 1055321442 \
Name Example ParentProject {} Authz {} Producers admin
This could be used in conjunction with setAttributes, e.g.:
eval $tH setAttributes $id2 [$th getAttributes $id1]
If you want to have convenient access to all attributes via a Tcl-array:
array set aAttr [$tH getAttributes $id]
puts "Name: $aAttr(Name)"
|
setAttributes - modify many attributes at once
| Syntax
| handle setAttributes id key1 value1 key2 value2 key3...
|
| Return
| nothing
|
| Description
| Update all given attributes.
|
| Example
| set tH [readAttrFile "d:/example.attr"]
$tH setAttributes /ci/8f Name "New Name" cache n
You can simply give key-value pairs to the command. For all given keys the values will be updated, all other keys won't be touched.
If you set the attribute ParentProject a move will be executed.
|
create - create a new item (template, project, file or record)
| Syntax
| handle create type parent-project-id name [id]
|
| Return
| new id
|
| Description
| Create a newe item by specifying the type of the item {Template, File, Record or Project} and provide the project-id where the item should be created.
Furthermore give it a unique name (no checks are done for this!).
If you don't provide an id a new unique one is automatically generated and returned.
If you provide an id this one is used for the new item. No checks for uniqueness or correctness of the id will be done. So use with care.
|
| Example
| set tH [readAttrFile "d:/example.attr"]
set newId [$tH create Template [$tH getRootId] "My new Template"]
puts "Created: $newId"
|
delete - delete a template, file, ...
| Syntax
| handle delete id
|
| Return
| nothing
|
| Description
| Delete the specified item {Template, File, Record or Project}. In case of a project everything below is deleted as well.
|
| Example
| set trapedHandle [readAttrFile "d:/example.attr"]
$trapedHandle delete /ci/8f
|
copy - copy an item (template, ...) to another project or attr-file
| Syntax
| handle copy from_id to_project_id [to_name] [<to_handle>]
|
| Return
| nothing
|
| Description
| Copy the specified item {Template, File, Record or Project}.
to_project_id is the project to which the item is copied.
If the item is a project only the project with from_id is copied.
All item below that project are ignored but you can simply do that yourself (have a look at the examples).
If you want to given the item a new name, e.g. if you copy a project to the same level you have to provide to_name.
Be careful though, that no checks are done for unique names and more important for unique ids!
|
| Example
| The following example copies a template from example2.attr to the root-project of
example.attr (the name of the template is not changed (parameter to_name == "").
set tH1 [readAttrFile "d:/example.attr"]
set tH2 [readAttrFile "d:/example2.attr"]
$tH2 copy /ci/8f [$tH1 getRootId] "" $tH1
To copy a complete tree:
# $pT is the target project-id ($tT is the target-handle)
# $pS is the source project-id which should be copied ($tS is the source-handle)
# this assumes that the first copied project has a parentproject-id which
# is also existing in $tT
foreach id [$tS getIdListRecursive Project] {
$tS copy $id [$tS getAttributeValue $id ParentProject] "" $tH
foreach {Template Record File} {
foreach cid [$tS getIdList $type $id] {
$tS copy $cid $id "" $tH
}
}
}
|
move - move an item (template, ...) to another project
| Syntax
| handle move from_id to_id
|
| Return
| nothing
|
| Description
| Move the specified item {Template, File, Record or Project}. If you move a project the complete subtree is moved as well.
You cannot move an item to another attr-file. But you can simply work around that by doing a copy (see the recursive-copy-example above)
and afterwards a delete on the source-project.
|
| Example
| set tH [readAttrFile "d:/example.attr"]
$tH move /pr/118 /pr/e86
|
writeToFile - dump the modification to a valid attr-file
| Syntax
| handle writeToFile filename
|
| Return
| nothing
|
| Description
| Write the modified structure to the file filename.
|
| Example
| see example for setAttributeValue.
|
Restrictions
There are some restrictions in the API of TrapEd (version 2.4):
- The
compress-option for opening an attr-file (see readAttrFile) is not available. Also the ignore files/records-options are not available, but you can easily implement those yourself.
- You have no access to the additional information stored in the attr-file (e.g. database-user, ...).
Besides those small restrictions you should be able to do anything you like.
Tips and tricks
If you are developing your own scripts you should first start by
typing the commands interactively into the API-console (inside the
examples-directory of your installation)
(..\traped.exe -script interactive).
Afterwards you can save your script with Save commands
from the File-menu of the interactive shell and execute
it the next time (may be as an at-job) as
..\traped.exe -script filename.tcl
When developing your scripts you should keep the following hints in mind:
- When you specify filepaths in tcl you must use a "/" (instead of "\\") (e.g.
readAttrFile D:/transfer/example/example.attr).
- If you run your scripts and nothing happens an error might have occured. You should always use the output redirection to see those messages in the file the output is redirected to. E.g.:
...traped.exe -script filename.tcl > output.txt
- Keep the files in the
example-directory of the TrapEd-distribution and start TrapEd in the example-directory (with ..\traped.exe).
You can than simply source your tcl-example-files without providing a path.