Home > Domino Tips > Developer > Java > @Word in Java
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

JAVA

@Word in Java


Paul Cathro
05.10.2004
Rating: -3.00- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


This is a simple class that emulates the @Word function in Lotus Notes. It uses the StringTokenizer class to parse a string, and uses the NextToken method of StringTokenizer to load a vector with all the tokens of that string.

The vector is then used by the tokenFound method to return the token requested as a parameter to the tokenFound method. If the value passed falls outside the number of tokens, a NULL is returned. The same three constructors found in the StringTokenizer class are included in this class.

 
import java.util.*;
import java.io.*;

/**

* This is a simple class that emulates 
the @Word function in Lotus
Notes. It uses the StringTokenizer class 
to parse a string and uses the
NextToken method of StringTokenizer to 
load a vector with all the tokens of
that string. The vector is then used by the 
tokenFound method to return the
token requested as a parameter to the 
tokenFound method. If the value passed 
falls outside the number of tokens a NULL 
is returned. The same three 
constructors found in the StringTokenizer 
class are included in this class.

The following is one example of the 
use of JavaWord. The code:

  String tmp = "This~is~a~test~of~parsing~text";
  JavaWord jw = new JavaWord(tmp, "~");
  String jwStr = jw.tokenFound("4");
 
 * Prints the following output:
   test
 
@author Paul V. Cathro
@version 1.1
 
*/

public class JavaWord {
 private static final PrintStream o = System.out;
 private static int j, tok;
 private static String tokenFound, holdToken,
 prevToken = "";
 private static StringTokenizer pt1;
 private static Vector token = new Vector();
 private static boolean firstNoDel = false;

 /**

* Receives the string to parse. Then it loads 
a vector with all the tokens in 
the string. This constructor uses " tnr" 
(blank, tab, newline, and return) as 
delimiters and the delimiters are not 
returned as tokens.
 
 * @param sStr - String to parse
 */
 public JavaWord(String sStr) {
  token.removeAllElements();
  token.trimToSize();
  pt1 = new StringTokenizer(sStr);
  tok = pt1.countTokens();
   while (pt1.hasMoreTokens()) {
   token.addElement(pt1.nextToken());
  }
 }

 /**

* Receives the string to parse and the 
delimiter to parse on.  Then it loads a 
vector with all the tokens in the string.
 
 * @param sStr - String to parse
 * @param sTok - delimeter to parse on
 */
 public JavaWord(String sStr, String sTok) {
  token.removeAllElements();
  token.trimToSize(); 
  pt1 = new StringTokenizer(sStr, sTok);
  tok = pt1.countTokens();
  while (pt1.hasMoreTokens()) {
   token.addElement(pt1.nextToken());
  }
 }

 /**

* Receives the string to parse, 
the delimiter to parse on, and Boolean set 
to "true" if there is the possibility having 
blank tokens or the string 
starting with a blank token. Then it loads a
 vector with all the tokens in the 
string. If the Boolean is set to "true" then
 the delimiters are included as 
tokens.
 
 * @param sStr - String to parse
 * @param sTok - delimeter to parse on
 * @param retTok - Boolean, if set to true 
will check for and handle 
blank tokens
 */
 public JavaWord(String sStr, String sTok, 
boolean retTok) {
  token.removeAllElements();
  token.trimToSize();
  if (retTok == true) {
   pt1 = new StringTokenizer(sStr, sTok, true);
   tok = pt1.countTokens();
   // if last token is a delimiter then subtract 1 from
the total token count
   if ((sStr.lastIndexOf("~") + 1) == sStr.length()) {
    tok--; 
   }  
   int z = 0;
   while (pt1.hasMoreTokens()) {
    holdToken = pt1.nextToken(); 

    if (!holdToken.equals(sTok)) {
     token.addElement(holdToken);
     firstNoDel = true;
    } else if (prevToken.equals(sTok) && 
holdToken.equals(sTok)) {
     token.addElement("");
    } else if (firstNoDel == false && z == 0 && 
holdToken.equals(sTok)) {
     token.addElement("");
     z++;
    } else if (firstNoDel == true && z == 0 && 
holdToken.equals(sTok)) {
     z++;   
    } else if (z > 0 && holdToken.equals(sTok)) {
     z++;
    }  
    prevToken = holdToken;
   }
   tok = tok - z;
  } else {
   pt1 = new StringTokenizer(sStr, sTok, false);
   tok = pt1.countTokens();
   while (pt1.hasMoreTokens()) {
    token.addElement(pt1.nextToken());
   }
  }
  firstNoDel = false;
  }

 /**

* Takes the number passed to this 
method (tokenFound) and returns the 
corresponding token based on the string 
passed to the constructor.  If a number
is passed to this method that is outside 
of the total token count then a blank 
is returned.
 
 * @param tokWant - number of the token
 to return
 *
 * @return token requested
 */
 public String tokenFound(String tokWant) {
  Integer tokInt = Integer.valueOf(tokWant);
  int tmpInt = tokInt.intValue() - 1;   // -1 
to adjust to the 
StringTokenizer array starting at zero 
  if (tmpInt <= tok && tmpInt >= 0 &
& !token.isEmpty() &&
tokInt.intValue() <= token.size()) {
   tokenFound = (String)token.elementAt(tmpInt);
  } else {
   tokenFound = "";
  }
  return tokenFound;
 }
}

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip exchange by member Paul Cathro. Please let others know how useful it is via the rating scale below.

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Java
Java code inserts data from Notes documents into a SQL table
Java code shortens strings in a SQL table
How to execute a stored procedure in Lotus Notes Domino using Java
How to return an HTML representation of a Lotus Notes rich-text field
Shrink Lotus Notes databases with many attachments
Converting Lotus Notes Domino Web pages to PDF files with a Java agent
A bevy of Notes/Domino development tips
Converting Web pages to images using Java
Creating Microsoft Word documents from Lotus Notes
FAQ: Java for Lotus Notes and Domino

Java for Lotus Notes Domino
Top 10 Lotus Notes/Domino coding and development tips of 2008
Java code inserts data from Notes documents into a SQL table
Java code shortens strings in a SQL table
How to execute a stored procedure in Lotus Notes Domino using Java
Top 10 Lotus Notes Domino programming and development tips of 2007
How to return an HTML representation of a Lotus Notes rich-text field
Shrink Lotus Notes databases with many attachments
Converting Lotus Notes Domino Web pages to PDF files with a Java agent
Developing Eclipse plug-ins for Lotus Notes and Domino -- 7 tips in 7 minutes
A bevy of Notes/Domino development tips

Lotus Notes Domino Formula Language
View hidden fields on Lotus Notes/Domino forms
Case-insensitive @Unique version combines fields on Lotus Notes forms
Do I use Formula or LotusScript to include a doclink to a Notes view?
Top 10 Lotus Notes/Domino coding and development tips of 2008
Provide rich-text formatting via the Profile document and Formula
Top 10 Formula language tips
Using Formula language code to sort Lotus Notes messages by subject
How to create dynamic JavaScript in Notes Domino without formulas
Stop response documents from showing in a Lotus Notes form
Formula language button manages Deny Access list searches

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts