Building a parseRule for RuleBaseFileParser connector

  • 7011028
  • 14-Jul-2010
  • 19-Oct-2012

Resolution

The parseRule utilizes the following objects in its context:

  • application - the application definition
  • config - shortcut to the Map config on the application
  • schema - the schema being iterated
  • state - Map object for storing state between records
  • inputStream - InputStream to the file (may or may not be used)
  • reader - BufferedReader object that can be used to iterate over the contents of the file

Usually the reader object is used to parse out the file (i.e. reader.readLine())

Here is a simple example of a ParseRule that parses a CSV:

// Simple parseRule to use reader to read next line

import sailpoint.tools.*; import sailpoint.tools.xml.*; import sailpoint.object.Schema; import sailpoint.connector.Connector; import sailpoint.connector.DelimitedFileConnector; import java.util.ArrayList; import java.util.List; import java.util.Hashap;

//

//Main

// Map

map = null;
List cols = new ArrayList();
RFC4180LineParser parser = new RFC4180LineParser(',');

// Check state for saved iterator

RFC4180LineIterator iterator = (RFC4180LineIterator)state.get("4180Iterator");
if ( iterator == null ) { iterator = new RFC4180LineIterator(reader);
String header = iterator.readLine();

//

System.out.println("header." + header);
cols = parser.parseLine(header);

//

// Save it off for next time

//

state.put("4180Iterator", iterator);
state.put("cols", cols); }
else if ( cols.size() == 0 ) { cols = (List)state.get("cols"); }
parser.setNumberOfColumns(cols.size());

String nextLine = iterator.readLine()
if ( nextLine != null ) { List tokens = parser.parseLine(nextLine);
map = DelimitedFileConnector.defaultBuildMap(cols, tokens);

//

System.out.println("object:"+XMLObjectFactory.getInstance().toXml(map)); } return map;

Feedback service temporarily unavailable. For content questions or problems, please contact Support.