use of org.talend.core.model.properties.ByteArray 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.ByteArray 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);
}
}
use of org.talend.core.model.properties.ByteArray in project tdi-studio-se by Talend.
the class SaveAsRoutineWizard method performFinish.
public boolean performFinish() {
boolean ok = false;
try {
isUpdate = isUpdate();
if (isUpdate) {
assginVlaues(oldProperty, property);
repositoryFactory.save(oldRoutineItem);
// assign value
routineItem = oldRoutineItem;
} else {
property.setId(repositoryFactory.getNextId());
// copy the byte[] content, the new routineItem get the old saved content, it is not the newest.
ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
byteArray.setInnerContent(oldRoutineItem.getContent().getInnerContent());
routineItem.setContent(byteArray);
// don't need to add depended routines.
repositoryFactory.create(routineItem, mainPage.getDestinationPath());
}
ok = true;
} catch (Exception e) {
MessageDialog.openError(getShell(), "Error", "Routine could not be saved" + " : " + e.getMessage());
ExceptionHandler.process(e);
}
return ok;
}
use of org.talend.core.model.properties.ByteArray in project tdi-studio-se by Talend.
the class HL7Manager method readMessageContent.
private void readMessageContent() {
filePath = hl7Component.getElementParameter(EParameterName.FILENAME.getName()).getValue().toString();
String filePathNoQuotes = TalendTextUtils.removeQuotes(filePath);
File file = Path.fromOSString(filePathNoQuotes).toFile();
startChar = hl7Component.getElementParameter("START_MSG").getValue().toString();
endChar = hl7Component.getElementParameter("END_MSG").getValue().toString();
//$NON-NLS-1$
IElementParameter messagePara = hl7Component.getElementParameter("MESSAGE");
List<Map<String, String>> msgListMap = (List<Map<String, String>>) messagePara.getValue();
if (msgListMap != null && msgListMap.size() > 0) {
for (Map<String, String> msgMap : msgListMap) {
if (msgMap.get("MSGITEM") != null && msgMap.get("MSGITEM") instanceof String) {
String msgItem = msgMap.get("MSGITEM");
initMsgContentList.add(msgItem);
}
}
} else if (file.exists()) {
hasFile = true;
ByteArray array = PropertiesFactory.eINSTANCE.createByteArray();
try {
array.setInnerContentFromFile(file);
TalendHL7Reader talendHL7Reader = new TalendHL7Reader(new java.io.FileInputStream(file), "ISO-8859-15");
String HL7InputTem = null;
String messageText = "";
while ((HL7InputTem = talendHL7Reader.getMessage()) != null) {
initMsgContentList.add(HL7InputTem);
}
if (initMsgContentList == null || initMsgContentList.size() == 0) {
String msgText = new String(array.getInnerContent());
initMsgContentList.add(msgText);
}
} catch (IOException e) {
ExceptionHandler.process(e);
}
}
}
Aggregations