*
Metamerge logo
Search

Advanced Search
*
*
*
* HOME DOCUMENTS & RESOURCES DOWNLOADS EARLY TECH ACCESS SUPPORT FAQ KNOWN ISSUES OLD VERSIONS

 

*

 


com.architech.function
Class userFunctions2

java.lang.Object
  |
  +--com.architech.function.userFunctions2

public class userFunctions2
extends Object

This class contains a number of convenience methods widely used by the scripting environment. The scripting name for this class is known as system. This class is registered by default in the scripting environment by it's presence in the Java Libraries configuration page.


Field Summary
 Exception lastError
          The Exception object set by the last call in this library.
 
Constructor Summary
userFunctions2()
           
 
Method Summary
 void abortAssemblyLine(String reason)
          Throws a rseAbortAL exception to tell the assembly line to terminate the assembly line.
 int charCode(char ch)
          Returns a character's numeric value using the Character.digit method.
 int charCode(String str, int index)
          Returns the numeric value for a character.
 boolean chdir(String directory)
          Change Java runtime working directory (Sets the "user.dir" property which not always works!!).
 boolean copyFile(String fromPath, String toPath, boolean overwrite)
          Copy file.
 String dtSeconds()
          Returns the number of milliseconds since Jan 1 1970 as a string.
 void dumpEntry(Entry e)
          Dumps an entry to the console log.
 boolean dumpJavaClass(String className)
          Dumps the public methods for a Java class.
 String entry2LDIF(Entry e)
          Converts an Entry object to an LDIF string.
 String formatDate(Date date, String format)
          this method formats a java.util.Date object using the provided template
 rscConnectorInterface getConnector(String name)
          Load a connector.
 String getcwd()
          Returns the current working directory.
 com.architech.protocols.FTPBean getFTP()
          Returns an instance of the FTP object.
 String getJavaProperty(String prop)
          Returns the value for a system property.
 String getOSName()
          Returns the name of the operating system./
 com.architech.parser.rspParserInterface getParser(String name)
          Load a parser.
 String getScriptText(String name)
          Returns the text from the Script Library.
 String getX400Attribute(String x400, String sep, String attribute)
          Returns an attribute value from an X.400 address.
 org.apache.xpath.XPathAPI getXPathAPI()
          Returns the Apache XPathAPI
 Entry httpGet(String url)
          Posts file to a web server.
 Entry httpPost(String url, Object file)
           
 Entry httpRequest(String method, String contentType, String url, Object file)
           
 void ignoreEntry()
          Throws a rseEntryIgnore exception to tell the assembly line to skip the current connector and continue with the next connector in the assembly line.
 boolean isValidInt(String str)
          Returns true if a string holds a valid Integer.
 rscConnectorInterface loadConnector(String connectorName)
          Load a connector.
 String mapString(String source, String fromSet, String toSet)
          Translates characters in a string.
 Attribute newAttribute(String name)
          Creates a new Attribute object.
 Entry newEntry()
          Creates a new Entry object.
 Object newObject(String className)
          Creates a new object.
 rscSearchCriteria newSearchCriteria()
          Creates a new rscSearchCriteira object.
 String normalizeX400(String value, String cursep, String newsep)
          Converts an X.400 address to a string using short form attribute names.
 BufferedWriter openFileForAppend(String path)
          Opens a file in append mode and returns the associated BufferedWriter object.
 BufferedReader openFileForInput(String path)
          Opens a file for input and returns the associated BufferedReader object.
 BufferedWriter openFileForOutput(String path)
          Opens a file in output mode and returns the associated BufferedWriter object.
 Date parseDate(String value, String format)
          Converts a String to a java.util.Date object.
 Entry parseObject(String parser, Object data)
          Use a parser to interpret data.
 String remove(String s, String source)
          Remove occurrences of a character from a string.
 String removeStringChars(String source, String fromSet)
          Removes occurrences of characters from a string.
 void restartEntry()
          Throws a rseRestartEntry exception to tell the assembly line to skip all connectors and start with first connector in the assembly line using the current work object.
 com.architech.function.NodeIterator selectNodeIterator(org.w3c.dom.Node contextNode, String str)
          Selects nodes using an XPath expression from an XML node.
 org.w3c.dom.NodeList selectNodeList(org.w3c.dom.Node contextNode, String str)
          Selects nodes using an XPath expression from an XML node.
 org.w3c.dom.Node selectSingleNode(org.w3c.dom.Node contextNode, String str)
          Selects a single node using an XPath expression from an XML node.
 String sendMail(String from, String recipient, String subject, String body, String attachment)
          Sends an email message.
 void setJavaProperty(String prop, String value)
          Sets the value of a property name.
 com.architech.function.executeCommand shellCommand(String command)
          Executes a shell command.
 void skipEntry()
          Throws a rseEntrySkipped exception to tell the assembly line to skip the current entry.
 void skipTo(String name)
          Throws a rseSkipTo exception to tell the task to skip to the action/connector named by name.
 InterruptedException sleep(int seconds)
          Causes the current thread (e.g.
 boolean snmpTrap(String host, int port, String oid, String value)
          Sends an SNMP trap.
 String[] splitString(String source, String separators)
          Splits a string into an array of strings.
 void throwException(String message)
          Throws a generic java.lang.Exception.
 String toHex(String str)
          Converts a string to a hexadecimal string where each character is converted to a two-byte hex value.
 Integer toInt(String str)
          Convert a string to an java.lang.Integer object.
 String translateString(String str, String fromCharset, String toCharset)
          Translate a string from one character set to another.
 String trim(String str)
          Trims leading/traing white-space from a string.
 void writeln(Writer w, String str)
          Writes a string plus a CRLF using a Writer object.
 String xslTransform(Object xsl, Object xml)
          Calls the XSLTransformer to transform an XML document using a given style sheet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lastError

public Exception lastError
The Exception object set by the last call in this library.
Constructor Detail

userFunctions2

public userFunctions2()
Method Detail

remove

public String remove(String s,
                     String source)
              throws Exception
Remove occurrences of a character from a string. For example, if you want to remove all blanks from the string "J O P" then you would use remove (" ", "J O P"). The returned value would then be "JOP".
 var a = "A string with blanks";
 var b = system.remove (" ", a);
 task.logmsg ("Result: " + b);      // "Astringwithblanks"
 
Parameters:
s - The character to be removed
source - The string from which characters are removed

trim

public String trim(String str)
Trims leading/traing white-space from a string.
Parameters:
str - The string to trim
Returns:
The trimmed string

toInt

public Integer toInt(String str)
              throws Exception
Convert a string to an java.lang.Integer object.
Parameters:
str - The string with a number
Returns:
The Integer object

isValidInt

public boolean isValidInt(String str)
Returns true if a string holds a valid Integer.
Parameters:
str - The string to test
Returns:
True if string can be converted to an Integer

openFileForAppend

public BufferedWriter openFileForAppend(String path)
                                 throws Exception
Opens a file in append mode and returns the associated BufferedWriter object.
Parameters:
path - The file path to open
Returns:
The BufferedWriter object

openFileForOutput

public BufferedWriter openFileForOutput(String path)
                                 throws Exception
Opens a file in output mode and returns the associated BufferedWriter object.
Parameters:
path - The file path to open (overwrites existing file)
Returns:
The BufferedWriter object

openFileForInput

public BufferedReader openFileForInput(String path)
                                throws Exception
Opens a file for input and returns the associated BufferedReader object.
Parameters:
path - The file path to open
Returns:
The BufferedReader object

writeln

public void writeln(Writer w,
                    String str)
             throws Exception
Writes a string plus a CRLF using a Writer object.
Parameters:
w - The writer object
str - The string to write

sendMail

public String sendMail(String from,
                       String recipient,
                       String subject,
                       String body,
                       String attachment)
                throws Exception
Sends an email message. Make sure the mail.smtp.host property is configured with the hostname of a valid SMTP server.
Parameters:
from - The From field
recipient - A comma separated list of recipient addresses
subject - The Subject field
body - The message text
attachment - If specified a file-path that will be attached to the message

copyFile

public boolean copyFile(String fromPath,
                        String toPath,
                        boolean overwrite)
                 throws Exception
Copy file. This method copies fromPath to toPath. The overwrite flag specifies whether the destination file should be overwritten.
Parameters:
fromPath - The source file
toPath - The destination file
overwrite - Specify true if destination should be overwritten.
Returns:
true if file was copied, false if toPath exists and overwrite=false.

newAttribute

public Attribute newAttribute(String name)
Creates a new Attribute object.
Parameters:
name - The attribute name
Returns:
The Attribute object

newSearchCriteria

public rscSearchCriteria newSearchCriteria()
Creates a new rscSearchCriteira object.
Returns:
The rscSearchCriteria object

newEntry

public Entry newEntry()
Creates a new Entry object.
Returns:
The Entry object

newObject

public Object newObject(String className)
Creates a new object. This method only works for Java objects that have empty constructors. It is a convenience method for scripting languages that cannot create Java objects directly.
Parameters:
className - The java class name
Returns:
The rscSearchCriteria object

skipEntry

public void skipEntry()
               throws com.architech.exceptions.rseEntrySkipped
Throws a rseEntrySkipped exception to tell the assembly line to skip the current entry.

ignoreEntry

public void ignoreEntry()
                 throws com.architech.exceptions.rseEntryIgnore
Throws a rseEntryIgnore exception to tell the assembly line to skip the current connector and continue with the next connector in the assembly line.

restartEntry

public void restartEntry()
                  throws com.architech.exceptions.rseRestartEntry
Throws a rseRestartEntry exception to tell the assembly line to skip all connectors and start with first connector in the assembly line using the current work object.

skipTo

public void skipTo(String name)
            throws com.architech.exceptions.rseSkipTo
Throws a rseSkipTo exception to tell the task to skip to the action/connector named by name.

abortAssemblyLine

public void abortAssemblyLine(String reason)
                       throws com.architech.exceptions.rseAbortAL
Throws a rseAbortAL exception to tell the assembly line to terminate the assembly line.
Parameters:
reason - Descriptive text why the AL is terminated

throwException

public void throwException(String message)
                    throws Exception
Throws a generic java.lang.Exception.
Parameters:
message - The exception's message text

loadConnector

public rscConnectorInterface loadConnector(String connectorName)
Load a connector. This method loads a connector from the current config file.
Parameters:
connectorName - The connector name as it appears in the configuration file
Returns:
The connector object

dtSeconds

public String dtSeconds()
Returns the number of milliseconds since Jan 1 1970 as a string.
Returns:
Number of milliseconds

sleep

public InterruptedException sleep(int seconds)
Causes the current thread (e.g. assembly line, event handler etc..) to sleep for a number of seconds. If the sleep is interrupted the InterruptedException value is returned. If not, null is returned.
Parameters:
seconds - Number of seconds to sleep
Returns:
null if successful, excpetion object otherwise

removeStringChars

public String removeStringChars(String source,
                                String fromSet)
Removes occurrences of characters from a string.
Parameters:
source - The source string
fromSet - A string specifying characters to be removed from source
Returns:
The resulting string

mapString

public String mapString(String source,
                        String fromSet,
                        String toSet)
Translates characters in a string. The fromSet and toSet contains the characters used to perform substitution. The first character in fromSet is replace with the first character in toSet etc.
Parameters:
source - The source string
fromSet - The characters to be replaced
toSet - The characters to replace characters in fromSet
Returns:
The substituted string

translateString

public String translateString(String str,
                              String fromCharset,
                              String toCharset)
Translate a string from one character set to another.
Parameters:
str - The source string
fromCharset - The source character set
toCharset - The target character set
Returns:
The translated string

toHex

public String toHex(String str)
Converts a string to a hexadecimal string where each character is converted to a two-byte hex value.
Parameters:
str - The source string
Returns:
The hexadecimal string

charCode

public int charCode(String str,
                    int index)
Returns the numeric value for a character.
Parameters:
str - The source string
index - The position of the character in str
Returns:
The numeric value

charCode

public int charCode(char ch)
Returns a character's numeric value using the Character.digit method.
Parameters:
ch - The character
Returns:
The numeric value

getX400Attribute

public String getX400Attribute(String x400,
                               String sep,
                               String attribute)
Returns an attribute value from an X.400 address.
Parameters:
x400 - The X.400 address
sep - The separator used in the address ( typically "/" or ";" )
attribute - The X.400 attribute
Returns:
The value or null if no attribute was found

normalizeX400

public String normalizeX400(String value,
                            String cursep,
                            String newsep)
Converts an X.400 address to a string using short form attribute names. Attributes are sorted in order of significance.
Parameters:
value - The X.400 address
cursep - The separator used in value
newsep - The separator to be used in the result
Returns:
The reformatted X.400 address

parseDate

public Date parseDate(String value,
                      String format)
Converts a String to a java.util.Date object.
Parameters:
value - The date in string form
format - The format of value (e.g. "YYYY.MM.DD", "MM/DD/YY" etc ...)
Returns:
The Date object or null if an error occurred
See Also:
lastError

formatDate

public String formatDate(Date date,
                         String format)
this method formats a java.util.Date object using the provided template
Parameters:
value - The date object
format - The format of value (e.g. "YYYY.MM.DD", "MM/DD/YY" etc ...)
Returns:
The string representation or null if an error occurred
See Also:
lastError

splitString

public String[] splitString(String source,
                            String separators)
Splits a string into an array of strings.
Parameters:
source - The source string
separators - The word-separating characters
Returns:
Array of strings

getConnector

public rscConnectorInterface getConnector(String name)
Load a connector. This method loads a connector from the current config file.
Parameters:
name - The connector name as it appears in the configuration file
Returns:
The connector object

getParser

public com.architech.parser.rspParserInterface getParser(String name)
Load a parser. This method loads a parser from the current config file.
Parameters:
name - The parser name as it appears in the configuration file
Returns:
The parser object

parseObject

public Entry parseObject(String parser,
                         Object data)
Use a parser to interpret data. This method will either use the data object as-is if it is a reader or inputstream class, or it will create a StringReader from the string representation of the data obect and pass it to the parser. The parser will be called to interpret the byte stream and return an Entry. If the parse fails a null is returned.
Parameters:
parser - The parser name
data - Any object of type Reader, InputStream or object that has a toString method
Returns:
The parsed entry
See Also:
lastError

shellCommand

public com.architech.function.executeCommand shellCommand(String command)
Executes a shell command.
Parameters:
command - The shell command to execute
Returns:
An executeCommand object
See Also:
executeCommand

getOSName

public String getOSName()
Returns the name of the operating system./
Returns:
The OS name

getJavaProperty

public String getJavaProperty(String prop)
Returns the value for a system property.
Parameters:
prop - The property name
Returns:
The property value or null if no such property exists

setJavaProperty

public void setJavaProperty(String prop,
                            String value)
Sets the value of a property name.
Parameters:
prop - The property name
value - The property value

entry2LDIF

public String entry2LDIF(Entry e)
Converts an Entry object to an LDIF string.
Parameters:
e - The entry
Returns:
The LDIF string

getFTP

public com.architech.protocols.FTPBean getFTP()
Returns an instance of the FTP object.
Returns:
The FTP object
See Also:
FTPBean

dumpEntry

public void dumpEntry(Entry e)
Dumps an entry to the console log.
Parameters:
e - The entry

getXPathAPI

public org.apache.xpath.XPathAPI getXPathAPI()
Returns the Apache XPathAPI
Returns:
XPathAPI object

selectSingleNode

public org.w3c.dom.Node selectSingleNode(org.w3c.dom.Node contextNode,
                                         String str)
Selects a single node using an XPath expression from an XML node.
Parameters:
contextNode - The XML document node
str - The XPath search string
Returns:
XML Document node

selectNodeList

public org.w3c.dom.NodeList selectNodeList(org.w3c.dom.Node contextNode,
                                           String str)
Selects nodes using an XPath expression from an XML node.
Parameters:
contextNode - The XML document node
str - The XPath search string
Returns:
A NodeList object

selectNodeIterator

public com.architech.function.NodeIterator selectNodeIterator(org.w3c.dom.Node contextNode,
                                                              String str)
Selects nodes using an XPath expression from an XML node.
Parameters:
contextNode - The XML document node
str - The XPath search string
Returns:
A NodeIterator object

xslTransform

public String xslTransform(Object xsl,
                           Object xml)
Calls the XSLTransformer to transform an XML document using a given style sheet.
Parameters:
xsl - The XSL Style sheet (String, java.io.File, java.io.Reader )
xml - The XML document (String, java.io.File, java.io.Reader )
Returns:
The translated document

dumpJavaClass

public boolean dumpJavaClass(String className)
Dumps the public methods for a Java class.
Parameters:
className - The java class name
Returns:
True if dump succeeded
See Also:
lastError

chdir

public boolean chdir(String directory)
Change Java runtime working directory (Sets the "user.dir" property which not always works!!).
Parameters:
directory - File system directory
Returns:
True if directory exists, false if directory is not valid

getcwd

public String getcwd()
Returns the current working directory.
Returns:
Working directory

getScriptText

public String getScriptText(String name)
Returns the text from the Script Library.
Parameters:
name - The script name as it appears in the configuration.
Returns:
The script text or null if not found

snmpTrap

public boolean snmpTrap(String host,
                        int port,
                        String oid,
                        String value)
Sends an SNMP trap.
Parameters:
host - The IP host
port - The TCP port
oid - The OID
value - The value
Returns:
True if Trap was sent
See Also:
lastError

httpGet

public Entry httpGet(String url)
Posts file to a web server.
Parameters:
url - The URL to the web server
file - The file name to be sent. You can provide this parameter as a String or as a java.io.File object. If this parameter is NULL the method will do as GET with no additional data, otherwise a POST is performed.
Returns:
The response from the server is encapsulated into an Entry object or NULL if an error occurred.
See Also:
lastError

httpPost

public Entry httpPost(String url,
                      Object file)

httpRequest

public Entry httpRequest(String method,
                         String contentType,
                         String url,
                         Object file)


Copyright © 1999-2001 Metamerge AS. All Rights Reserved.
*

 

  Metamerge Integrator version 4.6 ©Copyright Metamerge AS 2000-2002 Last edited 2002-05-07 contact us