use of org.talend.core.model.properties.ReferenceFileItem in project tesb-studio-se by Talend.
the class NewRouteResourceWizard method performFinish.
/**
* @see org.eclipse.jface.wizard.Wizard#performFinish()
*/
@Override
public boolean performFinish() {
property.setId(repositoryFactory.getNextId());
property.setLabel(property.getDisplayName());
URL url = mainPage.getUrl();
Path p = new Path(property.getLabel());
String itemName = p.removeFileExtension().lastSegment();
// String refName = item.getProperty().getLabel() + LOW_DASH + VersionUtils.DEFAULT_VERSION;
String fileExtension = null;
if (url != null) {
p = new Path(url.getPath());
if (p.getFileExtension() != null) {
fileExtension = p.getFileExtension();
}
} else {
fileExtension = p.getFileExtension();
}
// https://jira.talendforge.org/browse/TESB-6853
if (fileExtension == null || fileExtension.isEmpty()) {
fileExtension = "txt";
}
// In case the source file extension is "item"
if (fileExtension.equals(FileConstants.ITEM_EXTENSION)) {
fileExtension += LOW_DASH;
}
// In case the source file extension is "properties"
if (fileExtension.equals(FileConstants.PROPERTIES_EXTENSION)) {
fileExtension += LOW_DASH;
}
ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
if (url == null) {
byteArray.setInnerContent(new byte[0]);
} else {
try {
InputStream inputStream = url.openStream();
byteArray.setInnerContent(IOUtils.toByteArray(inputStream));
inputStream.close();
} catch (Exception e) {
MessageBoxExceptionHandler.process(e);
ExceptionHandler.process(e);
return false;
}
}
ReferenceFileItem refItem = PropertiesFactory.eINSTANCE.createReferenceFileItem();
refItem.setContent(byteArray);
refItem.setExtension(fileExtension);
// refItem.setName(refName);
item.setName(itemName);
item.setBindingExtension(fileExtension);
byteArray = PropertiesFactory.eINSTANCE.createByteArray();
byteArray.setInnerContent(new byte[0]);
item.setContent(byteArray);
item.getReferenceResources().add(refItem);
RepositoryWorkUnit<Object> workUnit = new RepositoryWorkUnit<Object>(this.getWindowTitle(), this) {
@Override
protected void run() throws LoginException, PersistenceException {
repositoryFactory.create(item, mainPage.getDestinationPath());
RelationshipItemBuilder.getInstance().addOrUpdateItem(item);
}
};
workUnit.setAvoidUnloadResources(true);
repositoryFactory.executeRepositoryWorkUnit(workUnit);
// return item != null;
return true;
}
use of org.talend.core.model.properties.ReferenceFileItem in project tesb-studio-se by Talend.
the class RouteResourcesHelper method getRouteResourcesLocation.
public static String getRouteResourcesLocation(IRepositoryViewObject repositoryObject) {
if (repositoryObject == null) {
return null;
}
Item item = repositoryObject.getProperty().getItem();
if (item.getReferenceResources().isEmpty()) {
return null;
}
ReferenceFileItem refFileItem = (ReferenceFileItem) item.getReferenceResources().get(0);
URI uri = refFileItem.getContent().eResource().getURI();
try {
return FileLocator.toFileURL(new URL(uri.toString())).getFile();
} catch (IOException e) {
ExceptionHandler.process(e);
}
return null;
}
use of org.talend.core.model.properties.ReferenceFileItem in project tesb-studio-se by Talend.
the class RouteResourceEditor method saveContentsToItem.
/**
* Save the file content to EMF item.
*
* @param rrInput
*/
public static void saveContentsToItem(RouteResourceInput rrInput) {
try {
RouteResourceItem item = (RouteResourceItem) rrInput.getItem();
ReferenceFileItem refFile = (ReferenceFileItem) item.getReferenceResources().get(0);
InputStream inputstream = rrInput.getFile().getContents();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputstream));
String line = bufferedReader.readLine();
StringBuffer sb = new StringBuffer();
String lineSeparator = System.getProperty("line.separator");
while (line != null) {
sb.append(line).append(lineSeparator);
line = bufferedReader.readLine();
}
bufferedReader.close();
inputstream.close();
ByteArray content = refFile.getContent();
content.setInnerContent(sb.toString().getBytes());
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
Aggregations