Search in sources :

Example 1 with XmlNodeRetriever

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()]);
}
Also used : JsonTreeNode(org.talend.repository.ui.wizards.metadata.connection.files.json.JsonTreeNode) XmlNodeRetriever(org.talend.commons.runtime.xml.XmlNodeRetriever) ArrayList(java.util.ArrayList) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) AbstractTreePopulator(org.talend.repository.ui.wizards.metadata.connection.files.json.AbstractTreePopulator) JsonTreePopulator(org.talend.repository.ui.wizards.metadata.connection.files.json.JsonTreePopulator)

Aggregations

ArrayList (java.util.ArrayList)1 IContentProposal (org.eclipse.jface.fieldassist.IContentProposal)1 XmlNodeRetriever (org.talend.commons.runtime.xml.XmlNodeRetriever)1 AbstractTreePopulator (org.talend.repository.ui.wizards.metadata.connection.files.json.AbstractTreePopulator)1 JsonTreeNode (org.talend.repository.ui.wizards.metadata.connection.files.json.JsonTreeNode)1 JsonTreePopulator (org.talend.repository.ui.wizards.metadata.connection.files.json.JsonTreePopulator)1