TFORMer SDK - JAVA
8
|
This sample demonstrates functions to access or modify the information stored in a Repository.
import com.tecit.TFORMer.*; // Licensing, Error handling, Enumerations import com.tecit.TFORMer.Repository.*; // Provides access to Repository elements import com.tecit.TFORMer.Printing.*; // Contains functionality for a Print-Job import com.tecit.TFORMer.Enumerations.*; // Contains all enumerations class RepositorySamples { //------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------- static Repository ConnectToStandAloneForm () throws TFormerException { // Create a new Repository instance using a stand-alone FormLayout (extension *.tff) // Examples are usually installed in // - Windows Vista or later: C:/Program Data/TEC-IT/TFORMer/8/Examples // - Older Microsoft Windows versions: C:/Documents and Settings/All Users/Application Data/TEC-IT/TFORMer/8/Examples Repository repository = new Repository("C:/Documents and Settings/All Users/Application Data/TEC-IT/TFORMer/8/Examples/Command Line/ODBCReportPDF/ODBCReportPDF.tff", false, true); return repository; } //------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------- static Repository ConnectToRepository () throws TFormerException { // Create a new Repository instance using a Repository (extension *.tfr) // Examples are usually installed in // - Windows Vista: C:/Program Data/TEC-IT/TFORMer/8/Examples // - Older Microsoft Windows versions: C:/Documents and Settings/All Users/Application Data/TEC-IT/TFORMer/8/Examples Repository repository = new Repository("C:/Documents and Settings/All Users/Application Data/TEC-IT/TFORMer/8/Examples/Demo Repository/Demos.tfr", false, true); return repository; } //------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------- static void DataFieldUsageStandAloneForm () throws TFormerException { Repository repository = ConnectToStandAloneForm (); // Retrieve the global Project // A stand-alone FormLayout contains only the global Project, the global Project holds the FormLayout and all DataField definitions Project project = repository.getGlobalProject (); // Retrieve the one and only FormLayout within the stand-alone FormLayout FormLayout formlayout = project.getFirstFormLayout (); // Iterate all DataFields within the Project DataField datafield = project.getFirstDataField (); while (datafield != null) { System.out.println (datafield.toString()); // Retrieve the usage of the DataFields in the FormLayout switch (formlayout.getDataFieldUsage (datafield.getName ())) { case Calculated: System.out.println ("--> The value of this DataField is computed within the FormLayout"); break; case Invalid : System.out.println ("--> Invalid usage - contact TEC-IT"); break; case Normal : System.out.println ("--> The DataField is used within the FormLayout; its value can be set"); break; case NotUsed : System.out.println ("--> This DataField is not used in this FormLayout"); break; case Parameter : System.out.println ("--> This is a system DataField (like the page number) used within the FormLayout"); break; } datafield = datafield.getNext (); } } //------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------- static void FetchFormLayoutStandAloneForm () throws TFormerException { Repository repository = ConnectToStandAloneForm (); // Retrieve the global Project // A stand-alone FormLayout contains only the global Project, the global Project contains the FormLayout Project project = repository.getGlobalProject (); if (project != null) { System.out.println (project.toString()); // Retrieve the first (and only) FormLayout FormLayout formlayout = project.getFirstFormLayout (); if (formlayout != null) { System.out.println (formlayout.toString()); } } } //------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------- static void IterateProjects () throws TFormerException { Repository repository = ConnectToRepository (); // Retrieve the first Project Project project = repository.getFirstProject (); while (project != null) { System.out.println (project.toString()); // Get the next Project project = project.getNext (); } } //------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------- static void IterateFormLayoutsRepository () throws TFormerException { Repository repository = ConnectToRepository (); // Retrieve the first Project Project project = repository.getFirstProject (); while (project != null) { System.out.println (project.toString()); // Retrieve the first FormLayout in this Project FormLayout formlayout = project.getFirstFormLayout (); while (formlayout != null) { System.out.println (formlayout.toString()); // Get the next FormLayout in this Project formlayout = formlayout.getNext (); } // Get the next Project project = project.getNext (); } } //------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------- static void IterateDataFieldsStandAloneForm () throws TFormerException { Repository repository = ConnectToStandAloneForm (); // Retrieve the global Project // A stand-alone FormLayout contains only the global Project, the global Project holds all DataField definitions Project project = repository.getGlobalProject (); // Retrieve the first DataField DataField datafield = project.getFirstDataField (); while (datafield != null) { // Your code follows System.out.println (datafield.getName ()); // Get the next DataField datafield = datafield.getNext (); } } //------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------- static void DataSourceOdbcModify () throws TFormerException { Repository repository = ConnectToStandAloneForm (); // Retrieve the global Project // DataSources are defined in a Project or a global Project Project project = repository.getGlobalProject (); // Retrieve the DataSource by name // Since we know the type of the DataSource, we can cast it to DataSourceOdbc DataSourceOdbc dataSource = (DataSourceOdbc) (project.getDataSource ("ODBC")); // Modify some DataSource properties dataSource.setUser(""); dataSource.setPassword(""); } //------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------- static void DataSourceCsvModify () throws TFormerException { Repository repository = ConnectToStandAloneForm (); // Retrieve the global Project // DataSources are defined in a Project or a global Project Project project = repository.getGlobalProject (); // Retrieve the DataSource by name // Since we know the type of the DataSource, we can cast it to DataSourceCsv DataSourceCsv dataSource = (DataSourceCsv)project.getDataSource("CSV"); // Modify some DataSource properties dataSource.setQualifier("'"); dataSource.setSeparator(","); } //------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------- static void DataSourceXmlModify () throws TFormerException { Repository repository = ConnectToStandAloneForm (); // Retrieve the global Project // DataSources are defined in a Project or a global Project Project project = repository.getGlobalProject (); // Retrieve the DataSource by name // Since we know the type of the DataSource, we can cast it to DataSourceXml DataSourceXml dataSource = (DataSourceXml)project.getDataSource("XML"); // Modify some DataSource properties dataSource.setXsltFilename(""); // clear XSLT filename } //------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------- static void IterateDataSourcesProject (Project project) throws TFormerException { // Iterate all DataSources of the Project for (DataSource ds = project.getFirstDataSource(); ds != null; ds = ds.getNext()) { System.out.println (ds.toString()); // Print information for the DataSourceParameters of the DataSource for (DataSourceParameter dsParam = ds.getFirstParameter(); dsParam != null; dsParam = dsParam.getNext()) System.out.println (dsParam.toString()); // Print information for the ComputedFields of the DataSource for (ComputedField dsComp = ds.getFirstComputedField(); dsComp != null; dsComp = dsComp.getNext()) System.out.println (dsComp.toString()); // Print the mapping between source fields and DataFields for (DSFieldMapping dsFieldmap = ds.getFirstDSFieldMapping(); dsFieldmap != null; dsFieldmap = dsFieldmap.getNext()) System.out.println (dsFieldmap.toString()); } } //------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------- static void IterateDataSources () throws TFormerException { // Open the Repository Repository repository = ConnectToRepository (); // Iterate the DataSources of the global Project // If a Repository is used, the global Project and additional user-defined Projects may exist System.out.println ("Global project"); IterateDataSourcesProject (repository.getGlobalProject ()); // Iterate additional Projects // Additional Projects are only possible when using a Repository for (Project project = repository.getFirstProject (); project != null; project = project.getNext()) { System.out.println (project.toString()); // Iterate the DataSources of the Project IterateDataSourcesProject (project); } } //------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------- static void IterateDataSourcesStandAloneForm () throws TFormerException { Repository repository = ConnectToStandAloneForm (); // Iterate the DataSources of the global Project // If a stand-alone FormLayout is used, the global Project is the only Project System.out.println ("Global project"); IterateDataSourcesProject (repository.getGlobalProject ()); } //------------------------------------------------------------------------------------------- // M A I N //------------------------------------------------------------------------------------------- // Call the various sample functions //------------------------------------------------------------------------------------------- public static void main (String[] args) throws TFormerException { try { System.out.println ("Run DataFieldUsageStandAloneForm ..."); DataFieldUsageStandAloneForm (); System.out.println ("Run FetchFormLayoutStandAloneForm ..."); FetchFormLayoutStandAloneForm (); System.out.println ("Run IterateProjects ..."); IterateProjects (); System.out.println ("Run IterateFormLayoutsRepository ..."); IterateFormLayoutsRepository (); System.out.println ("Run IterateDataFieldsStandAloneForm ..."); IterateDataFieldsStandAloneForm(); System.out.println ("Run IterateDataSources ..."); IterateDataSources (); System.out.println ("Run IterateDataSourcesStandAloneForm ..."); IterateDataSourcesStandAloneForm(); } catch(TFormerException ex){ // ... manage the exception System.out.println("Exception : "); System.out.printf(" Description: %s\n", ex.getMessage( )); } } } // class RepossitorySamples
© 2006-2024 - all rights reserved by TEC-IT Datenverarbeitung GmbH |
![]() |
Generated on Thu Oct 3 2024 05:08:23 for TFORMer SDK - JAVA with doxygen 1.7.6.1 |