I need to build a java service which extracts the value of a field at runtime. The path of the field in the canonical and the canonical document itself should be given as input.
Eg:
fromDoc consists of sub documents within it, in a hierarchy, ie.
fromDoc/Data/Parameters/outDate
fromDoc
[LIST]
Data
[LIST]
Parameters
[LIST]
outDate(string)
[/LIST]
[/LIST]
[/LIST]
For inStringValues I give the input as ‘fromDoc/Data/Parameters/outDate’
the output should return the value of the variable ‘fromDoc/Data/Parameters/outDate’ at run time.
I have a code which implements this with the key value pair logic.
@akki_84: Sounds to me like, as we say in german, “shooting sparrows with cannons”.
I recommend to send in a single string giving the path name, eg something like “doc/subDocLevel2/Level3/Level4/field” and a Document. get the iData for the Pipeline and split the string into components using Java’s String.split(“/”) to get an array of path components. use all but the last to iterate down to the final document and then get the value that it is pointing at.
IDataCursor now = pipeline.getCursor();
String[] components = IDataUtil.getString(now, "path").split("/");
for (int i=0; i < components.length-1) {[INDENT]IDataCursor next = IDataUtil.getIData(now, components[i]).getCursor();
now.destroy();
now = next;[/INDENT]
}
String field = now.GetString(components[components.lenght-1]);
now.destroy();
now = pipeline.getCursor();
IDataUtil.putString(now, "result", field);
now.destroy();
Errorhandling and checking for invalid input (like // in a string or strings starting with / may be added as an exercise.
With extra code. Then you either get an IData or an IData. If you want to deal with arrays too, my recommendation would require extension to understand and handle a syntax like doc/subDoc/subSubDoc[42]/field or whatever is convenient.
something along the lines of
[FONT=courier new]Pattern p = Pattern.compile(".*\\[[0-9]+\\]"); // place outside the loop, need to construct pattern to look for only once[/font]
[FONT=courier new]Matcher m = p.matcher(components[i]); // put into the loop
if (m.find()) {[/font][INDENT][FONT=courier new]// handle array case. error handling left as exercise :)
next = IDataUtils.getIDataArray(now, m.group(0))[Integer.parseInt(m.group(1))].getCursor();[/font][/INDENT]
[FONT=courier new]} else {
[/font][INDENT][FONT=courier new]// as before[/font][/INDENT]
[FONT=courier new]}
[/font]
shouldnt be too much work to get this one right for a java person.