use of org.talend.commons.runtime.xml.XmlNodeRetriever in project tdi-studio-se by Talend.
the class JSONXPathProposalProvider method getProposals4JsonPath.
private IContentProposal[] getProposals4JsonPath(String contents, int position) {
AbstractTreePopulator treePopulator = linker.getTreePopulator();
if (!(treePopulator instanceof JsonTreePopulator)) {
return null;
}
XmlNodeRetriever nodeRetriever = linker.getNodeRetriever();
if (!(nodeRetriever instanceof JsonNodeRetriever)) {
return null;
}
JsonNodeRetriever jsonNodeRetriever = (JsonNodeRetriever) nodeRetriever;
String beforeCursorExp = null;
boolean isAbsoluteExpression = contents.trim().startsWith(linker.getRootSeperator());
beforeCursorExp = contents.substring(0, position);
int lastIndexFieldSeperator = beforeCursorExp.lastIndexOf(linker.getFieldSeperator());
String currentExpr = null;
if (0 <= lastIndexFieldSeperator) {
currentExpr = beforeCursorExp.substring(0, lastIndexFieldSeperator);
} else {
currentExpr = beforeCursorExp;
}
currentExpr = currentExpr.trim();
String currentWord = extractLastWord(beforeCursorExp);
if (!isAbsoluteExpression && lastIndexFieldSeperator < 0) {
currentWord = currentExpr;
currentExpr = "";
}
if (currentWord != null) {
currentWord = currentWord.trim();
}
List<JsonTreeNode> proposalNodes = jsonNodeRetriever.retrieveProposalJsonTreeNode((JsonTreePopulator) treePopulator, currentExpr, currentWord, isRelativeTable, isAbsoluteExpression);
List<IContentProposal> proposals = new ArrayList<IContentProposal>();
if (proposalNodes != null && !proposalNodes.isEmpty()) {
Iterator<JsonTreeNode> iter = proposalNodes.iterator();
while (iter.hasNext()) {
JsonTreeNode jsonTreeNode = iter.next();
JsonPathContentProposal proposal = new JsonPathContentProposal(jsonTreeNode.getLabel());
proposals.add(proposal);
}
}
return proposals.toArray(new IContentProposal[proposals.size()]);
}
Aggregations