25
Thu, Apr
1 New Articles

Integrate Open-Source Applications with Your System i

Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Open-source applications are programs whose source is freely available to be redistributed and enhanced as the user sees fit. The origins of the open-source software movement can be traced back to a man named Richard Stallman, who was at one time a programmer at the MIT AI lab. In the early '80s, Stallman fathered the GNU's Not Unix (GNU) project, whose goal was to create an entire operating system and a set of development tools that would be freely distributable. At the same time, he authored his vision for what is known today as open-source software in a work entitled the "GNU Manifesto."

Although GNU isn't UNIX, it's intended to be a UNIX-compatible operating system. Building on the GNU project in the early '90s, a programmer named Linus Torvald developed the kernel for a new operating system based on the GNU software license. That operating system (Linux) is now the third most popular operating system in the world. Today, the open-source movement thrives in every aspect of the software world. In fact, probably most software applications you can imagine have an open-source cousin. In this article, we'll examine how to make the most of open-source applications on your System i.

The concept of open-source software is nothing new on the System i. In fact, the System i HTTP Web Server is based on the popular open-source Apache Web server. And let's not forget that the Linux operating system has been available for the System i for years. Having said that, System i–specific open-source projects have, unfortunately, been few and far between. The good news, however, is that many open-source applications can be utilized on the System i, even though they're not System i–specific. One example of this is Apache Tomcat. This extension to the Apache Web server adds Java servlet and JavaServer Pages (JSP) capabilities. A Redbook is available with instructions for installing Tomcat on your System i.

Open-Source Tools for Building Office Documents

Another example of an open-source technology that you can use on the iSeries is the Jakarta POI project. This project is responsible for developing a set of open-source Java APIs for reading and writing Microsoft Office documents. This set of APIs is broken down into a set of subcomponents, as shown in the table below.

Jakarta POI Java APIs
Component
Description
POIFS
APIs for reading and writing OLE 2 Compound Document Formats in Java
HSSF
APIs for reading and writing Microsoft Excel 97(-XP) spreadsheets in Java
HWPF
APIs for reading and writing Microsoft Word 97(-XP) documents using Java
HPFS
APIs that allow access to Microsoft Office document file properties (title, author, etc.)


The POIFS API allows you to access documents using the OLE 2 Compound Document Format, the common "archived file" format used by Microsoft Office documents. Generally, the other APIs described here use the POIFS APIs under the covers. These APIs give us access to the file system itself through the org.apache.poi.poifs.filesystem.POIFSFileSystem class, the file system directory structure through the org.apache.poi.poifs.filesystem.DirectoryEntry instance, and individual documents through the org.apache.poi.poifs.filesystem.DocumentInputStream instance.

Microsoft Excel spreadsheet documents can be manipulated using the HSSF APIs, which are discussed in detail in the MC Press TechTip "Excel on the Fly" by Giuseppe Costagliola.

The HWPF project is intended to give a Java programmer access to Microsoft Word documents. This project is in a very early development phase and in fact has been stalled for quite some time. Word documents themselves are accessed through the org.apache.poi.hwpf.HWPFDocument class. Currently, this API supports basic document reading and editing capabilities, including the ability to read and update/append text within a Word document. Text can be extracted from a Word document using the org.apache.poi.hwpf.extractor.WordExtractor class. The getRange() method can be used to retrieve a specific portion of a document. A retrieve range can be used with the insertBefore() and insertAfter() methods to add text before or after that range.

The HPFS API gives us access to additional details related to a Microsoft Office document. These properties include the same type of details that can be found within the document properties dialog within Word or Excel, for example title and/or author. This API is accessed via the org.apache.poi.hpsf.SummaryInformation class. Individual properties can be accessed using the SummaryInformation class methods getTitle(), getAuthor(), etc.

Each of these APIs can be incorporated into Java applications running on your System i to create Microsoft Office–compatible documents while utilizing data in your System i database. Additional information on the Jakarta POI project can be found on the project Web site.

Open-Source Report Creation

Most System i programmers are used to using RPG to create report programs. Today, many of us use translation tools to convert the spooled file output generated by these RPG programs into PDF format so that the reports can be easily displayed with Adobe Acrobat Reader.

An example of a utility that does this is the SCS2iText utility illustrated in the TechTip "Spooled Files and PDF, Part Three" by Giuseppe Costagliola. The sample utility is based on the open-source iText Java class library. This class library gives you the ability to dynamically generate PDF documents from within a Java application. With that idea in mind, why not eliminate the middle man and generate your report programs in pure Java and at the same time send the output directly to a PDF file? This is all possible using iText. The iText class library is simple enough to use even for a novice Java programmer. Let's take a look at exactly how to use the iText class library within a Java reporting program. By combining JDBC database connectivity with iText capability to output a PDF, you can easily generate a PDF report on the fly. The Java source shown below illustrates this.

  // PDFFieldList.java

  import java.io.*;

  import com.lowagie.text.*;
  import com.lowagie.text.pdf.*;
  import java.sql.*;

  class PDFFieldList
  {
    public static void main (String [] args) throws Exception
    {
     // Input Parameters
     String fileName = args[0]; // File Name
     String libName = args[1];  // Library Name
     String outPDF = args[2];   // Output PDF Path/filename

     Document doc = new Document (PageSize.LETTER.rotate ());
     PdfWriter.getInstance (doc, new FileOutputStream (outPDF));
     doc.open ();

     // Create a 5-column table.

    PdfPTable table = new PdfPTable (5);

    // Create database connection
    try {
                Class.forName("com.ibm.db2.jdbc.app.DB2Driver");

                Connection conn = 

DriverManager.getConnection("jdbc:db2:*local");


     // Create and add a title across both columns.
     String heading = "Field Listing for File " + fileName + " in

library " + libName + ".";
     PdfPCell cell = new PdfPCell (new Paragraph (heading));
     cell.setColspan (5);
     cell.setHorizontalAlignment (Element.ALIGN_CENTER);
     table.addCell (cell);

     // Add header cells for these columns.

     table.addCell ("Field");
     table.addCell ("Description");
     table.addCell ("Type");
     table.addCell ("Length");
     table.addCell ("Dec");

      // Add each row.
     try {
          String sqlStr = "SELECT SYS_CNAME, LABEL, COLTYPE, LENGTH,

SCALE " +
                " FROM QSYS2.SYSCOLUMNS WHERE SYS_TNAME ='" + fileName

 + "' AND SYS_DNAME ='" + libName + "' ";

          PreparedStatement s = conn.prepareStatement(sqlStr);

          ResultSet rs = s.executeQuery();

        while (rs.next()) {
                       table.addCell (rs.getString(1));
                       table.addCell (rs.getString(2));
                       table.addCell (rs.getString(3));
                       table.addCell (rs.getString(4));
                       table.addCell (rs.getString(5));
                       }
          }
         catch (SQLException e) {
                     System.out.println("SQLException exception: ");
                     System.out.println("Message:....." + 

e.getMessage());
                     System.out.println("SQLState:...." + 

e.getSQLState());
                     System.out.println("Vendor Code:." + 

e.getErrorCode());
          }

      // Add the table to the document.

      doc.add (table);
      doc.close ();
            } catch (Exception e) {
                System.out.println("Database exception: " + 

e.getMessage());
            }
      }
    }

This sample program lists field information for a defined System i file. The first argument on the call identifies the file name, while the second identifies the library containing the defined file, and the third supplies the location and filename for the output PDF file.

This example imports the com.lowagie.text.* class along with the com.lowagie.text.pdf.* class. You create a new instance of the Document object named doc. This object represents a PDF document with a letter-size page in landscape orientation. The data for the report is read using a standard JDBC connection using a prepared SQL statement based on the SYSCOLUMNS file. The data from this file is output to a PDF table, where each cell in the table contains a data element from the SYSCOLUMNS file. Once all of the table records have been output, the table is added to the PDF document and the document is closed.

Prior to compiling this example, you'll need to download the iText jar from the project Web Site. Once you've downloaded the jar file, create a new folder in the root of the IFS named "iText" and place the iText jar in that folder. Also move the source for the PDFFieldList.java example into that folder as well. Next, enter a Qshell session using the QSH command. From the QSH command line, enter the following command to ensure that your classpath is set correctly prior to compiling the new class:

export -s CLASSPATH=/QIBM/ProdData/OS400/Java400/ext/db2_classes.jar:/iText/iText-2.0.0.jar: 

Note that the version of the iText jar file should match the version downloaded.

Now you're ready to compile your Java program using these commands:

cd /iText/

javac PDFFieldList.java

Notice that you first relocate to the iText folder prior to compiling. Once you've successfully compiled this program, you can call the newly created class using the following command:

java PDFFieldList 'SYSTABLES' 'QSYS2' '/iText/SYSTABLES.PDF' 

This statement executes the PDFFieldList class to generate a report containing a list of fields for the SYSTABLES file. The list is output to a PDF named SYSTABLES.PDF in the iText folder. The resulting PDF file shows a single table that contains all of the report data. Figure 2 illustrates this output PDF.

http://www.mcpressonline.com/articles/images/2002/OpenSourceSystemiV3--02280700.png
Figure 2: This is the output from the PDF report. (Click image to enlarge.)

The true beauty of using iText is that you can completely customize your report output, including fonts, text placement, and even images. This simple example illustrates the basic technique you need to use to create PDF reports using iText and Java.

Considering the Open-Source Alternative

In this article, I've covered just a few examples of how to integrate open-source software with your System i. I hope I've helped to convince you to consider checking out the open-source options for your next programming task. You may find that you've opened yourself to a whole new world of possibilities.

Mike Faust is Applications Support Manager for Invivo Corp in Orlando, Florida. Mike is also the author of the books The iSeries and AS/400 Programmer's Guide to Cool Things and Active Server Pages Primer and SQL Built-in Functions and Stored Procedures. You can contact Mike at This email address is being protected from spambots. You need JavaScript enabled to view it..

Mike Faust

Mike Faust is a senior consultant/analyst for Retail Technologies Corporation in Orlando, Florida. Mike is also the author of the books Active Server Pages Primer, The iSeries and AS/400 Programmer's Guide to Cool Things, JavaScript for the Business Developer, and SQL Built-in Functions and Stored Procedures. You can contact Mike at This email address is being protected from spambots. You need JavaScript enabled to view it..


MC Press books written by Mike Faust available now on the MC Press Bookstore.

Active Server Pages Primer Active Server Pages Primer
Learn how to make the most of ASP while creating a fully functional ASP "shopping cart" application.
List Price $79.00

Now On Sale

JavaScript for the Business Developer JavaScript for the Business Developer
Learn how JavaScript can help you create dynamic business applications with Web browser interfaces.
List Price $44.95

Now On Sale

SQL Built-in Functions and Stored Procedures SQL Built-in Functions and Stored Procedures
Unleash the full power of SQL with these highly useful tools.
List Price $49.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$0.00 Raised:
$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: