Novell is now a part of Micro Focus

HowTo: Create a simple Document Management Application Part 1

Novell Cool Solutions: Feature
By Stomfi

Digg This - Slashdot This

Posted: 14 Jul 2005

StomfiLearning to use Linux at Home and Work
Welcome to my ongoing series of HowTo articles designed to help Linux newbies get comfortable with Linux. Before trying any of these HowTos, take a few minutes to study the prerequisites so you can hit the ground running.

This two part HowTo shows you how to create a simple Document Management System using the Shell and Runtime Revolution.

I have used some new shell tools and some new RunRev functions in this project so that you can increase your knowledge.

Special Offer for Cool Solutions Readers: Free Copy of Runtime Revolution
The good folks at Runtime Revolution have extended a special offer to Cool Solutions readers to make it easier for you to implement the great ideas in Stomfi's articles. They are offering it for free to Novell customers who know the secret code. See this page for details.

The new shell tools are some of the bibliographic database tools, namely "indxbib" and "lkbib". These are part of the "refer" suite. Refer was designed to add troff/nroff/groff formatted references to a document. We shall be using them for our own purposes, using a subset of the possible database entries. You can look up the manual pages for "refer" to see all the possible entries. The reason we are using these tools is that they are suitable, and who wants to waste time reinventing them.

I've used a new RunRev function in this project for making and selecting items from a menu, and I've used one of the windows for two activities, both adding and editing, by changing the property of the display field, and adding a flag to tell which mode we are using. I've also set up a new construct that passes a flag to the program about which calling screen to return to. This is really simple RunRev scripting as I do all the information processing with the Linux shell tools, which were designed for that purpose.

This is a picture of my Midnight Commander window showing the refer database with an index in the left panel and the shell script names in the right panel:

There are two "sed" scripts in the "bin" folder as they encompass several substitution commands, and this is the preferred way to do it. To keep things simple and readable, I usually include the "awk" scripts inside the shell scripts, but it is a better technique to put them in separate files like these "sed" scripts.

I shall try to do this for multi-line awk scripts from now on. For those of you who have not been following my articles, you can read the earlier ones, as there is a slow progression of knowledge and skill level.

This is the RunRev startup window:

This is what you see when you click the help button:

I left you a bit of work to do filling out this help screen. Don't forget to set the property that locks the text if you are going to distribute the final executable.

This is what you see when you hold down the left mouse button over the START button:

Pretty garish colour properties I've selected. You can choose yours to suit. The Pop up menu is not anchored to one place, so may appear anywhere on your desktop. I'll leave you to find out how to anchor it as I enjoy the random factor.

This is the window you see when you move the held down mouse over to the FIND item and release the left button.

I have already entered the search term "newbie". Letter case is not important. I can just read the display or edit the entry by clicking one of the "Title:" lines. This is a simple application, and if two documents have the same title and you wanted to edit the second, it wouldn't work as currently written. You could add the "Author:" line to the look up to allow for identical titles.

To make life easy for yourself when adding a new document to your database, first do a title word search on your existing records, and add something to the new title to make it unique.

I have clicked on the 'SCOOL title line. This is the Add/Edit window:

Clicking any of the buttons to the left of the display window will request a modification for that line. You will see which lines have been modified, as they will have the button label in front of the new line. Thus:

Clicking EXIT will take you back to the calling script's card, in this case the search term card "FINDREF".

If you select ADD from the START menu, you will be taken to the same Add/Edit window, but the list behaviour of the display field is temporarily set to "true" so that you can select an old or new document details database by clicking in the display.

Clicking on "Stomfi" in this example, will put "Stomfi" into the Database File field. Clicking a blank line will ask you for the name of a new database, or if you clicked an empty line by mistake, an existing one.

The display field is cleared and its list behaviour set back to "false". The name you entered is put into the Database File field.

The QUIT button on the menu quits the application. It's a good idea to comment this out in the script when you are developing the application, as in browse mode it will completely quit the RunRev IDE and you will have to start it up again.

Here is a picture of the Application Browser window showing all the card names and the objects on the "ADDDOC" card:

You can see I have put in a "DEBUG" field. This field has its "visible" property clicked off. i.e. set to "false", as you just use the property inspector to view its contents. You use this when things are not behaving properly by putting the output of a shell script into this field. For example, say that you have a line in a script which says:

put the shell of DUSHELL into DUNSHELL

You can add the line:

put DUNSHELL into field "DEBUG"

or, if you are looking at multiple outputs:

put return & DUNSHELL after field "DEBUG"

The "DOCADD" object on this card is a group which is made up of the buttons. This was to make it easier to move them around, when I was designing the layout of the window. I had to make sure that they were not under the mouse when entering this window to do an Edit from the "FINDREF" window, as that would have caused one of them to be clicked as well. You can leave out the grouping if you like, or you can group them for setting the layout and ungroup them when satisfied. To edit the properties or script of group members, you have to right click the member name in the Application Browser window.

These are the scripts that allow this application to perform its activities:

Start window Help Button

on mouseUp

   global WITCH

   put "DocManage" into WITCH

   go card "HELP"

end mouseUp

WITCH is the global that sets which card the help window returns to when its EXIT button is clicked.

START button script

on menuPick myitem

   switch myitem

      case "FIND"

         global WITCH

         global FRETURN

         put "DocManage" into WITCH

         put "NO" into FRETURN

         go card "FINDREF"


      case "ADD"

         go card "ADDDOC"


      case "QUIT"

         #Put a # in front of the next line when developing. Delete it before creating a Stand Alone



   end switch

end menuPick

This is a new RunRev function that we haven't used before. You can use the Menu Builder in the Tools drop down menu or you can type your own like the one above.

FINDREF card script

on openCard

   global FRETURN

   if FRETURN <> "YES"


      put empty into field "SRESULTS"

   end if

   put "YES" into FRETURN

end openCard

The above script clears the contents of SRESULTS only if FRETURN is not set to "YES".

Search Term Button

on mouseDown

   ask "Enter a single word Search Term"

   put it into STERM

   put ($HOME & "/docmanage/bin/" && quote & STERM & quote) into LUKUP

   replace return with empty in LUKUP

   put the shell of LUKUP into field "SRESULTS"

end mouseDown

The search term must be a single word or number. The script calls the following Shell script with the search term as its argument.


# SearchTerm

#Set Database Folder


#Change folder to make command line less wordy


#Make a list of Databases

DBLIST=`ls | grep -v "\.i"`


#Create command line DB option list


for DBF in $DBLIST


   #First make sure that the indexes are up to date

   indxbib $DBF

   #Construct the options part of the line



#Create list of matching records

#Print the %T Title, %A Author, %D Date, %S Ezine and %K Section


#Create a list of records using lkbib to find the records, awk to print the lines we want,

#with a # on the last line of each record.

#and sed to replace the refer field markers with names. The tee file is for debugging

lkbib $DBOPTIONS "$1" |\

awk '{if($1 ~ "%A") print $0};\

{if($1 ~ "%D") print $0};\

{if($1 ~ "%K") print $0};\

{if($1 ~ "%S") print $0};\

{if($1 ~ "%T") print $0, "\n#"}'|\

sed -f $HOME/docmanage/bin/headings.sed | tee $HOME/docmanage/srecs.txt

#end of shell script

The database directory contains index files as well as data files. The grep command makes sure the index files are not listed. The for loop constructs an option line from the list of data files. The lkbib command looks in all the database files, using the indexes, to find the search term. The sed command uses the file named after the " -f" to get its command from. This is the headings.sed script. It doesn't have to be an executable.






Each line of the sed script substitutes the first pattern with the second. The " \t" represent a TAB.

FINDREF Exit button

on mouseUp

   global FRETURN

   put "NO" into FRETURN

   global WITCH

   put the name of this card into CNAME

   if CNAME contains WITCH


      put "DocManage" into WITCH

   end if

   go card WITCH

end mouseUp

This button contains the WITCH construct which allows the return to the calling window. The if statement makes sure that it goes to the start window if WITCH contains the same card name as this one.

Field SRESULTS script

on mouseDown

   global EDITME

   put the selectedText of me into EDITME

   if EDITME <> empty and EDITME contains "Title:"


      global WITCH

      put "FINDREF" into WITCH

      go card "ADDDOC"

   end if

end mouseDown

This script uses the clicked Title line to go to the ADDDOC window.

The final part of this HowTo will show the rest of the scripts and their explanations will be published in Part 2 of this series.

Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions.

© Copyright Micro Focus or one of its affiliates