use of org.talend.core.model.properties.ReferenceFileItem in project tmdm-studio-se by Talend.
the class AbstractRepositoryNodeResourceProvider method linkReferenceFile.
public void linkReferenceFile(Item item, IFile file, boolean updateRefName) {
try {
file.refreshLocal(0, null);
ReferenceFileItem fileItem = findReferenceFileItem(item, file);
if (fileItem != null) {
fileItem.getContent().setInnerContentFromFile(file);
} else {
ReferenceFileItem procFileItem = PropertiesFactory.eINSTANCE.createReferenceFileItem();
ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
byteArray.setInnerContentFromFile(file);
procFileItem.setContent(byteArray);
String fileExt = file.getFileExtension();
procFileItem.setExtension(fileExt);
// set name
if (updateRefName) {
String fileName = file.getName();
int index = fileName.lastIndexOf(fileExt);
if (index > 0) {
String name = fileName.substring(0, index - 1);
procFileItem.setName(name);
}
}
// item.getReferenceResources().clear();
item.getReferenceResources().add(procFileItem);
}
} catch (IOException e) {
log.error(e.getMessage(), e);
} catch (CoreException e) {
log.error(e.getMessage(), e);
}
}
use of org.talend.core.model.properties.ReferenceFileItem in project tmdm-studio-se by Talend.
the class AbstractRepositoryNodeResourceProvider method findReferenceFileItem.
private ReferenceFileItem findReferenceFileItem(Item item, IFile file) {
EList referenceResources = item.getReferenceResources();
if (referenceResources != null) {
for (Object refObj : referenceResources) {
ReferenceFileItem fileItem = (ReferenceFileItem) refObj;
String name = null;
if (fileItem.getName() != null) {
// $NON-NLS-1$
name = fileItem.getName() + "." + fileItem.getExtension();
} else {
URI uri = fileItem.getContent().eResource().getURI();
name = uri.lastSegment();
}
if (name != null && name.equals(file.getName())) {
return fileItem;
}
}
}
return null;
}
Aggregations