Search in sources :

Example 1 with ATreeNode

use of org.talend.datatools.xml.utils.ATreeNode in project tdi-studio-se by Talend.

the class ImportTreeFromXMLAction method treeNodeAdapt.

private List<FOXTreeNode> treeNodeAdapt(String file) {
    List<FOXTreeNode> list = new ArrayList<FOXTreeNode>();
    try {
        ATreeNode treeNode = SchemaPopulationUtil.getSchemaTree(file, true, 0);
        String schemaName = getSelectedSchema();
        String rootName = "";
        if (treeNode.getValue() instanceof String) {
            rootName += "/" + treeNode.getValue();
        }
        FOXTreeNode root = cloneATreeNode(treeNode, schemaName, rootName);
        Element rootElement = (Element) root;
        if (rootElement.getElementChildren() != null && rootElement.getElementChildren().size() > 0) {
            for (FOXTreeNode foxTreeNode : rootElement.getElementChildren()) {
                foxTreeNode.setParent(null);
                list.add(foxTreeNode);
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return list;
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) ATreeNode(org.talend.datatools.xml.utils.ATreeNode) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element) ArrayList(java.util.ArrayList)

Example 2 with ATreeNode

use of org.talend.datatools.xml.utils.ATreeNode in project tdi-studio-se by Talend.

the class ImportTreeFromXMLAction method cloneATreeNode.

private FOXTreeNode cloneATreeNode(ATreeNode treeNode, String schemaName, String currentPath) throws Exception {
    FOXTreeNode node = null;
    if (treeNode.getType() == ATreeNode.ATTRIBUTE_TYPE) {
        node = new Attribute();
    } else {
        node = new Element();
    }
    // zli fixed for bug 7414
    if (treeNode.getType() == ATreeNode.NAMESPACE_TYPE) {
        node = new NameSpaceNode();
        //$NON-NLS-1$
        node.setLabel("");
        node.setDefaultValue((String) treeNode.getValue());
    } else {
        node.setLabel((String) treeNode.getValue());
    }
    Object[] children = treeNode.getChildren();
    if (children != null) {
        for (Object element : children) {
            if (element instanceof ATreeNode) {
                ATreeNode child = (ATreeNode) element;
                String newPath = currentPath + "/";
                if (child.getValue() instanceof String) {
                    String elementName = (String) child.getValue();
                    if (currentPath.contains("/" + elementName + "/")) {
                        ExceptionHandler.process(new Exception("XSD ERROR: loop found. Item: " + elementName + " is already in the currentPath (" + currentPath + ")."));
                        continue;
                    }
                    newPath += elementName;
                } else {
                    newPath += "unknownElement";
                }
                FOXTreeNode foxChild = cloneATreeNode(child, schemaName, newPath);
                foxChild.setRow(schemaName);
                node.addChild(foxChild);
            }
        }
    }
    return node;
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) NameSpaceNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.NameSpaceNode) Attribute(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute) ATreeNode(org.talend.datatools.xml.utils.ATreeNode) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element)

Example 3 with ATreeNode

use of org.talend.datatools.xml.utils.ATreeNode in project tdi-studio-se by Talend.

the class ImportTreeFromXMLAction method run.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
@Override
public void run() {
    List<FOXTreeNode> newInput = new ArrayList<FOXTreeNode>();
    String filePath = getFilePath();
    if (filePath == null) {
        return;
    }
    boolean changed = true;
    try {
        if (XmlUtil.isXSDFile(filePath)) {
            XSDSchema xsdSchema = TreeUtil.getXSDSchema(filePath);
            List<ATreeNode> list = new XSDPopulationUtil2().getAllRootNodes(xsdSchema);
            if (list.size() > 1) {
                RootNodeSelectDialog dialog = new RootNodeSelectDialog(xmlViewer.getControl().getShell(), list);
                if (dialog.open() == IDialogConstants.OK_ID) {
                    ATreeNode selectedNode = dialog.getSelectedNode();
                    newInput = TreeUtil.getFoxTreeNodesByRootNode(xsdSchema, selectedNode);
                    changed = true;
                } else {
                    changed = false;
                }
            } else {
                newInput = TreeUtil.getFoxTreeNodesByRootNode(xsdSchema, list.get(0));
                changed = true;
            }
        } else {
            newInput = treeNodeAdapt(filePath);
            changed = true;
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    if (newInput.size() == 0) {
        return;
    }
    if (changed) {
        // updateNode
        for (FOXTreeNode node : newInput) {
            foxui.updateNode(node, getSelectedSchema());
        }
        List<FOXTreeNode> treeData = foxui.getFoxManager().getTreeData(getSelectedSchema());
        treeData.clear();
        treeData.addAll(newInput);
        xmlViewer.setInput(foxui.getFoxManager().getTreeData());
        // TreeUtil.guessAndSetLoopNode((FOXTreeNode) xmlViewer.getTree().getItem(0).getData());
        xmlViewer.refresh();
        xmlViewer.expandToLevel(3);
        foxui.updateStatus();
        foxui.redrawLinkers();
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) ATreeNode(org.talend.datatools.xml.utils.ATreeNode) RootNodeSelectDialog(org.talend.metadata.managment.ui.dialog.RootNodeSelectDialog) ArrayList(java.util.ArrayList) XSDPopulationUtil2(org.talend.datatools.xml.utils.XSDPopulationUtil2) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 4 with ATreeNode

use of org.talend.datatools.xml.utils.ATreeNode in project tdi-studio-se by Talend.

the class AbstractJSONFileStepForm method getDefaultRootNode.

protected ATreeNode getDefaultRootNode(List<ATreeNode> rootNodes) {
    if (rootNodes != null && rootNodes.size() > 0) {
        EList<JSONFileNode> root = getConnection().getRoot();
        JSONFileNode selectedNode = null;
        if (root != null && root.size() > 0) {
            selectedNode = root.get(0);
        } else {
            EList<JSONFileNode> loop = getConnection().getLoop();
            if (loop != null && loop.size() > 0) {
                selectedNode = loop.get(0);
            }
        }
        if (selectedNode != null) {
            String JSONPath = selectedNode.getJSONPath();
            if (JSONPath != null && JSONPath.length() > 0) {
                JSONPath = JSONPath.substring(JSONPath.lastIndexOf("/") + 1);
                for (int i = 0; i < rootNodes.size(); i++) {
                    ATreeNode node = rootNodes.get(i);
                    if (JSONPath.equals(node.getValue())) {
                        return node;
                    }
                }
            }
        }
    }
    return null;
}
Also used : JSONFileNode(org.talend.repository.model.json.JSONFileNode) ATreeNode(org.talend.datatools.xml.utils.ATreeNode)

Example 5 with ATreeNode

use of org.talend.datatools.xml.utils.ATreeNode in project tdi-studio-se by Talend.

the class ATreeNodeUtil method findTreeNode.

private static ATreeNode findTreeNode(String nodeName, ATreeNode rootTreeNode) {
    Object[] childNodes = rootTreeNode.getChildren();
    ATreeNode aTreeNode = null;
    for (Object node : childNodes) {
        if (nodeName.equals(((ATreeNode) node).getValue())) {
            return (ATreeNode) node;
        } else {
            continue;
        }
    }
    return aTreeNode;
}
Also used : ATreeNode(org.talend.datatools.xml.utils.ATreeNode)

Aggregations

ATreeNode (org.talend.datatools.xml.utils.ATreeNode)9 ArrayList (java.util.ArrayList)4 FOXTreeNode (org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode)3 Element (org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element)2 BufferedReader (java.io.BufferedReader)1 EOFException (java.io.EOFException)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 MalformedURLException (java.net.MalformedURLException)1 Charset (java.nio.charset.Charset)1 List (java.util.List)1 MalformedPatternException (org.apache.oro.text.regex.MalformedPatternException)1 MatchResult (org.apache.oro.text.regex.MatchResult)1 Pattern (org.apache.oro.text.regex.Pattern)1 Perl5Compiler (org.apache.oro.text.regex.Perl5Compiler)1 Perl5Matcher (org.apache.oro.text.regex.Perl5Matcher)1