Search in sources :

Example 1 with XmlXPathLoopDescriptorImpl

use of org.talend.core.model.metadata.builder.connection.impl.XmlXPathLoopDescriptorImpl in project tdi-studio-se by Talend.

the class ImportTreeFromRepository method prepareEmfTreeFromXml.

private void prepareEmfTreeFromXml(XmlFileConnection connection) throws Exception {
    if (!connection.isInputModel()) {
        prepareEmfTreeFromConnection(connection);
    // String file = connection.getXmlFilePath();
    // List<FOXTreeNode> list = new ArrayList<FOXTreeNode>();
    // // fix for TDI-20671 , root element is loop in output
    // String rootXpath = null;
    // if (!connection.getRoot().isEmpty()) {
    // rootXpath = connection.getRoot().get(0).getXMLPath();
    // } else if (!connection.getLoop().isEmpty()) {
    // rootXpath = connection.getLoop().get(0).getXMLPath();
    // }
    // File xmlFile = new File(file);
    // if (xmlFile.exists() && !file.endsWith(".zip")) {
    // list = TreeUtil.getFoxTreeNodesForXmlMap(xmlFile.getAbsolutePath(), rootXpath, true);
    // } else if (connection.getFileContent() != null && connection.getFileContent().length > 0) {
    // String xsdFile = initFileContent(connection);
    // if (xsdFile != null && new File(xsdFile).exists()) {
    // String targetNameSpace = connection.getTargetNameSpace();
    // list = TreeUtil.getFoxTreeNodesForXmlMap(xsdFile, rootXpath, targetNameSpace, true);
    // } else {
    // // for manually created output
    // prepareEmfTreeFromConnection(connection);
    // return;
    //
    // }
    // } else {
    // // for manually created output
    // prepareEmfTreeFromConnection(connection);
    // return;
    // }
    // schemaNode.getChildren().clear();
    // root = connection.getRoot();
    // loop = connection.getLoop();
    // group = connection.getGroup();
    // groupElements = new ArrayList<TreeNode>();
    // prepareModelFromOutput(list, schemaNode);
    // if (loopNode != null) {
    // fillGroup(loopNode, groupElements);
    // } else {
    // if (!schemaNode.getChildren().isEmpty()) {
    // schemaNode.getChildren().get(0).setLoop(true);
    // }
    // }
    } else {
        List<SchemaTarget> schemaTargets = null;
        if (!connection.getSchema().isEmpty() && connection.getSchema().get(0) instanceof XmlXPathLoopDescriptorImpl) {
            absoluteXPathQuery = ((XmlXPathLoopDescriptorImpl) connection.getSchema().get(0)).getAbsoluteXPathQuery();
            schemaTargets = ((XmlXPathLoopDescriptorImpl) connection.getSchema().get(0)).getSchemaTargets();
            metadataTable = ConnectionHelper.getTables(connection).toArray(new MetadataTable[0])[0];
        }
        // fix for TDI-8707 : only import mapped elements from connection to xml map
        if (schemaTargets == null || schemaTargets.isEmpty()) {
            return;
        }
        this.schemaTargets = schemaTargets;
        String file = connection.getXmlFilePath();
        List<FOXTreeNode> list = new ArrayList<FOXTreeNode>();
        File xmlFile = new File(file);
        if (xmlFile.exists()) {
            list = TreeUtil.getFoxTreeNodesForXmlMap(xmlFile.getAbsolutePath(), absoluteXPathQuery, true);
        } else if (connection.getFileContent() != null && connection.getFileContent().length > 0) {
            String xsdFile = initFileContent(connection);
            if (xsdFile != null && new File(xsdFile).exists()) {
                list = TreeUtil.getFoxTreeNodesForXmlMap(xsdFile, absoluteXPathQuery, true);
            }
        } else {
            throw new FileNotFoundException();
        }
        schemaNode.getChildren().clear();
        prepareEmfTree(list, schemaNode);
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) XmlXPathLoopDescriptorImpl(org.talend.core.model.metadata.builder.connection.impl.XmlXPathLoopDescriptorImpl) SchemaTarget(org.talend.core.model.metadata.builder.connection.SchemaTarget) File(java.io.File)

Aggregations

File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 SchemaTarget (org.talend.core.model.metadata.builder.connection.SchemaTarget)1 XmlXPathLoopDescriptorImpl (org.talend.core.model.metadata.builder.connection.impl.XmlXPathLoopDescriptorImpl)1 FOXTreeNode (org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode)1