use of org.jkiss.dbeaver.model.data.DBDContent in project dbeaver by serge-rider.
the class DataExporterXML method exportRow.
@Override
public void exportRow(DBCSession session, DBCResultSet resultSet, Object[] row) throws DBException, IOException {
PrintWriter out = getWriter();
out.write(" <DATA_RECORD>\n");
for (int i = 0; i < row.length; i++) {
DBDAttributeBinding column = columns[i];
String columnName = escapeXmlElementName(column.getName());
out.write(" <" + columnName + ">");
if (DBUtils.isNullValue(row[i])) {
writeTextCell(null);
} else if (row[i] instanceof DBDContent) {
// Content
// Inline textual content and handle binaries in some special way
DBDContent content = (DBDContent) row[i];
try {
DBDContentStorage cs = content.getContents(session.getProgressMonitor());
if (cs != null) {
if (ContentUtils.isTextContent(content)) {
try (Reader reader = cs.getContentReader()) {
writeCellValue(reader);
}
} else {
getSite().writeBinaryData(cs);
}
}
} finally {
content.release();
}
} else {
writeTextCell(super.getValueDisplayString(column, row[i]));
}
out.write("</" + columnName + ">\n");
}
out.write(" </DATA_RECORD>\n");
}
use of org.jkiss.dbeaver.model.data.DBDContent in project dbeaver by serge-rider.
the class DataExporterXLSX method exportRow.
@Override
public void exportRow(DBCSession session, DBCResultSet resultSet, Object[] row) throws DBException, IOException {
Worksheet wsh = getWsh(resultSet, row);
Row rowX = wsh.getSh().createRow(wsh.getCurrentRow());
int startCol = 0;
if (rowNumber) {
Cell cell = rowX.createCell(startCol, CellType.NUMERIC);
cell.setCellStyle(style);
cell.setCellValue(String.valueOf(wsh.getCurrentRow()));
startCol++;
}
for (int i = 0; i < row.length; i++) {
DBDAttributeBinding column = columns[i];
Cell cell = rowX.createCell(i + startCol, getCellType(column));
cell.setCellStyle(style);
if (DBUtils.isNullValue(row[i])) {
if (!CommonUtils.isEmpty(nullString)) {
cell.setCellValue(nullString);
} else {
cell.setCellValue("");
}
} else if (row[i] instanceof DBDContent) {
DBDContent content = (DBDContent) row[i];
try {
DBDContentStorage cs = content.getContents(session.getProgressMonitor());
if (cs == null) {
cell.setCellValue(DBConstants.NULL_VALUE_LABEL);
} else if (ContentUtils.isTextContent(content)) {
writeCellValue(cell, cs.getContentReader());
} else {
cell.setCellValue(BINARY_FIXED);
}
} finally {
content.release();
}
} else if (row[i] instanceof Boolean) {
if (booleRedefined) {
cell.setCellValue((Boolean) row[i] ? boolTrue : boolFalse);
} else {
cell.setCellValue((Boolean) row[i]);
}
} else if (row[i] instanceof Number) {
cell.setCellValue(((Number) row[i]).doubleValue());
} else if (row[i] instanceof Date) {
cell.setCellValue((Date) row[i]);
cell.setCellStyle(styleDate);
} else {
String stringValue = super.getValueDisplayString(column, row[i]);
cell.setCellValue(stringValue);
}
}
wsh.incRow();
rowCount++;
}
use of org.jkiss.dbeaver.model.data.DBDContent in project dbeaver by serge-rider.
the class ContentEditorInput method prepareContent.
private void prepareContent(DBRProgressMonitor monitor) throws DBException {
Object value = getValue();
DBDContent content;
if (value instanceof DBDContent) {
content = (DBDContent) value;
} else {
// No need to do init
stringStorage = new StringEditorInput(getName(), CommonUtils.toString(value), isReadOnly(), fileCharset).getStorage();
return;
}
DBDContentStorage storage = content.getContents(monitor);
if (contentDetached) {
release();
contentDetached = false;
}
if (storage instanceof DBDContentStorageLocal) {
// User content's storage directly
contentFile = ((DBDContentStorageLocal) storage).getDataFile();
contentDetached = true;
} else {
// Copy content to local file
try {
// Create file
if (contentFile == null) {
String valueId;
if (valueController instanceof IAttributeController) {
valueId = ((IAttributeController) valueController).getColumnId();
} else {
valueId = valueController.getValueName();
}
contentFile = ContentUtils.createTempContentFile(monitor, DBWorkbench.getPlatform(), valueId);
}
// Write value to file
copyContentToFile(content, monitor);
} catch (IOException e) {
// Delete temp file
if (contentFile != null && contentFile.exists()) {
if (!contentFile.delete()) {
log.warn("Can't delete temporary content file '" + contentFile.getAbsolutePath() + "'");
}
}
throw new DBException("Can't delete content file", e);
}
}
// Mark file as readonly
if (valueController.isReadOnly()) {
markReadOnly(true);
}
}
use of org.jkiss.dbeaver.model.data.DBDContent in project dbeaver by serge-rider.
the class ContentInlineEditor method extractEditorValue.
@Override
public Object extractEditorValue() {
String newValue = control.getText();
final DBDContent content = (DBDContent) valueController.getValue();
assert content != null;
try {
if (isText) {
content.updateContents(new VoidProgressMonitor(), new StringContentStorage(newValue));
} else {
content.updateContents(new VoidProgressMonitor(), new BytesContentStorage(newValue.getBytes(GeneralUtils.getDefaultFileEncoding()), GeneralUtils.getDefaultFileEncoding()));
}
} catch (Exception e) {
log.error(e);
}
return content;
}
use of org.jkiss.dbeaver.model.data.DBDContent in project dbeaver by dbeaver.
the class ContentEditorInput method loadFromExternalFile.
void loadFromExternalFile(File extFile, IProgressMonitor monitor) throws CoreException {
try {
release();
contentFile = extFile;
contentDetached = true;
Object value = getValue();
if (value instanceof DBDContent) {
((DBDContent) value).updateContents(new DefaultProgressMonitor(monitor), new ExternalContentStorage(DBWorkbench.getPlatform(), extFile));
} else {
updateStringValueFromFile(extFile);
}
refreshContentParts(extFile);
} catch (Throwable e) {
throw new CoreException(GeneralUtils.makeExceptionStatus(e));
}
}
Aggregations