Search in sources :

Example 16 with ReferenceFileItem

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);
    }
}
Also used : ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) CoreException(org.eclipse.core.runtime.CoreException) ByteArray(org.talend.core.model.properties.ByteArray) IOException(java.io.IOException)

Example 17 with ReferenceFileItem

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;
}
Also used : ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) EList(org.eclipse.emf.common.util.EList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) URI(org.eclipse.emf.common.util.URI)

Aggregations

ReferenceFileItem (org.talend.core.model.properties.ReferenceFileItem)17 ByteArray (org.talend.core.model.properties.ByteArray)10 InputStream (java.io.InputStream)5 WSDataModelItem (org.talend.mdm.repository.model.mdmproperties.WSDataModelItem)5 File (java.io.File)4 IOException (java.io.IOException)4 IPath (org.eclipse.core.runtime.IPath)4 URI (org.eclipse.emf.common.util.URI)4 Item (org.talend.core.model.properties.Item)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FileInputStream (java.io.FileInputStream)3 URL (java.net.URL)3 IFile (org.eclipse.core.resources.IFile)3 Path (org.eclipse.core.runtime.Path)3 EList (org.eclipse.emf.common.util.EList)3 Test (org.junit.Test)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2