com.g11ntoolkit.tokenizer
Class TokXMLFile

java.lang.Object
  |
  +--com.g11ntoolkit.tokenizer.FileTokenizer
        |
        +--com.g11ntoolkit.tokenizer.TokXMLFile

public class TokXMLFile
extends FileTokenizer

Tokenize the specified buffer as an XML file.

Version:
2005/07/22
Author:
Bill Rich, Wilandra Consulting LLC
Copyright © 2001-2005, Wilandra Consulting LLC. All rights reserved.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

See License Agreement.


Field Summary
private static gnu.regexp.RE[] exprs
          The set of regular expressions we will use for processing.
private static java.lang.String localeString
          The locale for the input file.
private static java.util.logging.Logger log
          The log used for all messages from this class.
private static int nextStart
          The next starting position for the tag match.
private static java.lang.String[] patterns
          The set of regular expression patterns we will use for processing.
protected static java.lang.String theContextFileName
          The context input file name saved for later use.
protected static Token token
          The Token object to use to generate tokens for each extracted string.
protected static java.util.ResourceBundle xliffrb
          Constants, messages, and variables used by the tools and classes for XLIFF processing.
private static java.lang.String XMLPropFileName
          The file name for the properties file that will contain the regular expressions describing the extracts for XML files.
private static java.util.ResourceBundle xmlres
          Contains the XML literals used for XML file extracts.
private static java.lang.String xmlString
          A work area for parsing the input file buffer to find the tags and replace the strings with tokens.
protected static java.util.ResourceBundle xrb
          XML Properties Resource Bundle.
 
Fields inherited from class com.g11ntoolkit.tokenizer.FileTokenizer
context, encoding, inFileBuffer, jspVars, mrb, product, productVersion, revContext, targetLocale, tokContext, vrb
 
Constructor Summary
TokXMLFile()
          This constructor is used to establish an instance of the class with no input information.
TokXMLFile(java.lang.String anEncoding, java.util.Locale aLocale, Token aToken, java.lang.String propFile)
          This constructor is used to establish an instance of the class and save all the input information for use in processing the file.
 
Method Summary
private static java.lang.String getXMLPropFileName()
          Returns the file name for the properties file that will contain regular expressions describing the XML file extracts.
static boolean isToken(java.lang.String str, Token tok)
          Returns true if the string is a token.
private static void loadPatterns()
          Loads the regualr expression patterns from the PropertiesResourceBundle.
static void main(java.lang.String[] args)
          Allows this tool to be run from the command line.
private static void setXMLPropFileName(java.lang.String fn)
          Sets the file name for the properties file that will contain regular expressions describing the XML file extracts.
static StrFile tokenize(java.lang.String inFileName, java.lang.String contextFileName, java.util.Locale targetLocale, java.lang.String localeString)
          This is the method that tokenizes the buffer and writes the two output files.
 
Methods inherited from class com.g11ntoolkit.tokenizer.FileTokenizer
cleanConcats, getEncoding, getFileBuffer, getKey, getProductName, getProductVersion, getToken, keys, readFile, readFilePlain, setContext, setEncoding, setProductName, setProductVersion, setupTok, setupTok, tokens
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static java.util.logging.Logger log
The log used for all messages from this class.


xliffrb

protected static java.util.ResourceBundle xliffrb
Constants, messages, and variables used by the tools and classes for XLIFF processing.


xmlres

private static java.util.ResourceBundle xmlres
Contains the XML literals used for XML file extracts.


xrb

protected static java.util.ResourceBundle xrb
XML Properties Resource Bundle.

The set of regular expressions used to find the translatable strings in an XML file. Refer to the TokXMLFile Regular Expressions Guide for information on what this file contains and how to code it.


xmlString

private static java.lang.String xmlString
A work area for parsing the input file buffer to find the tags and replace the strings with tokens.


patterns

private static java.lang.String[] patterns
The set of regular expression patterns we will use for processing.

This will be set of strings that contain the regular expressions describing what to extract from the XML file.


exprs

private static gnu.regexp.RE[] exprs
The set of regular expressions we will use for processing.

This will be set of regular expressions describing what to extract from the XML file.


nextStart

private static int nextStart
The next starting position for the tag match.

It is important to keep this up to date with each match because we don't want to return the same tag twice.


token

protected static Token token
The Token object to use to generate tokens for each extracted string.


XMLPropFileName

private static java.lang.String XMLPropFileName
The file name for the properties file that will contain the regular expressions describing the extracts for XML files.


theContextFileName

protected static java.lang.String theContextFileName
The context input file name saved for later use.


localeString

private static java.lang.String localeString
The locale for the input file.

Constructor Detail

TokXMLFile

public TokXMLFile()
This constructor is used to establish an instance of the class with no input information. It is useful for setting up the class for the check function.


TokXMLFile

public TokXMLFile(java.lang.String anEncoding,
                  java.util.Locale aLocale,
                  Token aToken,
                  java.lang.String propFile)
           throws FileTokenizerError
This constructor is used to establish an instance of the class and save all the input information for use in processing the file.

Parameters:
anEncoding - a String specifying the encoding for the output files.
aLocale - a Locale object
aToken - a Token object
propFile - a String specifying the properties resource bundle file name that contains the list of elements and attributes to extract values for in the XML file
Throws:
FileTokenizerError - for any errors detected during processing
Method Detail

main

public static void main(java.lang.String[] args)
                 throws FileTokRunError
Allows this tool to be run from the command line.

Sets up the environment then uses the tokenize method to extract the strings.

Parameters:
args - a String array specifying the command line parameters. The order does not matter except that the arguments that are paired must be paired in order. The arguments are not case sensitive.
FileTokRunError

loadPatterns

private static void loadPatterns()
Loads the regualr expression patterns from the PropertiesResourceBundle.

This table describes what will be extracted from an XML file.


tokenize

public static StrFile tokenize(java.lang.String inFileName,
                               java.lang.String contextFileName,
                               java.util.Locale targetLocale,
                               java.lang.String localeString)
                        throws FileTokenizerError
This is the method that tokenizes the buffer and writes the two output files.

It uses the super class setupTok method to do the common work of reading the file into a string buffer.

Parameters:
inFileName - a String specifying the input file name
contextFileName - a String specifying the input file name to use as the token id and context
targetLocale - a Locale specifying the intended target locale
Returns:
a StrFile representing the extracted strings for the input file
Throws:
FileTokenizerError - if any errors occur during processing.

isToken

public static boolean isToken(java.lang.String str,
                              Token tok)
Returns true if the string is a token.

Looks for the string to begin and end with the token decoration.

Parameters:
str - a String specifying the string
tok - a Token specifying the token (used for finding the decoration)
Returns:
a boolean representing whether the string is a token or not

setXMLPropFileName

private static void setXMLPropFileName(java.lang.String fn)
Sets the file name for the properties file that will contain regular expressions describing the XML file extracts.

Parameters:
fn - a String specifying the name of the file
See Also:
getXMLPropFileName()

getXMLPropFileName

private static java.lang.String getXMLPropFileName()
Returns the file name for the properties file that will contain regular expressions describing the XML file extracts.

Returns:
a String representing the name of the file
See Also:
setXMLPropFileName(java.lang.String)