use of org.talend.core.model.metadata.builder.connection.SchemaTarget in project tdi-studio-se by Talend.
the class ImportTreeFromRepository method isMappedChild.
private boolean isMappedChild(String tempXpath) {
if (targetAbsolutePath == null) {
targetAbsolutePath = new HashMap<String, String>();
targetDatePattern = new HashMap<String, String>();
targetAbsolutePath.put(absoluteXPathQuery, null);
Pattern regex = Pattern.compile(RELATIVE_PATH_PATTERN, Pattern.CANON_EQ | Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
for (int n = 0; n < schemaTargets.size(); n++) {
Object obj = schemaTargets.get(n);
String relativeXPathQuery = "";
if (obj instanceof SchemaTarget) {
relativeXPathQuery = ((SchemaTarget) obj).getRelativeXPathQuery();
} else if (obj instanceof ConceptTarget) {
relativeXPathQuery = ((ConceptTarget) obj).getRelativeLoopExpression();
}
StringBuffer tempAbsolute = new StringBuffer();
tempAbsolute.append(absoluteXPathQuery);
tempAbsolute.append(XmlMapUtil.XPATH_SEPARATOR);
tempAbsolute.append(relativeXPathQuery);
if (relativeXPathQuery.startsWith(RELATIVE_PATH)) {
Matcher regexMatcher = regex.matcher(relativeXPathQuery);
int relativeLength = 0;
while (regexMatcher.find()) {
relativeLength++;
}
if (relativeLength > 0) {
String subRelativeQuery = relativeXPathQuery.substring(relativeLength * RELATIVE_PATH.length(), relativeXPathQuery.length());
String[] absoluteSplit = absoluteXPathQuery.split(XmlMapUtil.XPATH_SEPARATOR);
if (absoluteSplit.length > relativeLength) {
tempAbsolute = new StringBuffer();
for (int i = 0; i < absoluteSplit.length - relativeLength; i++) {
tempAbsolute.append(absoluteSplit[i]);
tempAbsolute.append(XmlMapUtil.XPATH_SEPARATOR);
}
tempAbsolute.append(subRelativeQuery);
}
}
}
if (metadataTable != null && n < metadataTable.getColumns().size()) {
MetadataColumn column = metadataTable.getColumns().get(n);
targetAbsolutePath.put(tempAbsolute.toString(), column.getTalendType());
targetDatePattern.put(tempAbsolute.toString(), column.getPattern());
} else {
targetAbsolutePath.put(tempAbsolute.toString(), null);
targetDatePattern.put(tempAbsolute.toString(), null);
}
}
}
for (String absTarget : targetAbsolutePath.keySet()) {
if (absTarget.startsWith(tempXpath)) {
return true;
}
}
return false;
}
use of org.talend.core.model.metadata.builder.connection.SchemaTarget 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);
}
}
Aggregations