use of org.jkiss.dbeaver.model.data.DBDContent in project dbeaver by serge-rider.
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));
}
}
use of org.jkiss.dbeaver.model.data.DBDContent in project dbeaver by serge-rider.
the class AbstractTextPanelEditor method extractEditorValue.
@Override
public void extractEditorValue(@NotNull DBRProgressMonitor monitor, @NotNull StyledText control, @NotNull DBDContent value) throws DBException {
if (valueController.getValue() instanceof DBDContent) {
monitor.beginTask("Extract text", 1);
try {
monitor.subTask("Extracting text from editor");
editor.doSave(RuntimeUtils.getNestedMonitor(monitor));
final IEditorInput editorInput = editor.getEditorInput();
if (editorInput instanceof ContentEditorInput) {
final ContentEditorInput contentEditorInput = (ContentEditorInput) editorInput;
contentEditorInput.updateContentFromFile(monitor, value);
}
} catch (Exception e) {
throw new DBException("Error extracting text from editor", e);
} finally {
monitor.done();
}
} else {
value.updateContents(monitor, new StringContentStorage(control.getText()));
}
}
use of org.jkiss.dbeaver.model.data.DBDContent in project dbeaver by serge-rider.
the class ContentPanelEditor method extractEditorValue.
@Override
public Object extractEditorValue() throws DBException {
final Object content = valueController.getValue();
if (isStringValue()) {
StringContent stringContent = new StringContent(valueController.getExecutionContext(), null);
streamEditor.extractEditorValue(new VoidProgressMonitor(), control, stringContent);
return stringContent.getRawValue();
} else {
if (content == null) {
log.warn("NULL content value. Must be DBDContent.");
} else if (streamEditor == null) {
log.warn("NULL content editor.");
} else {
try {
streamEditor.extractEditorValue(new VoidProgressMonitor(), control, (DBDContent) content);
} catch (Throwable e) {
log.debug(e);
valueController.showMessage(e.getMessage(), DBPMessageType.ERROR);
}
}
return content;
}
}
use of org.jkiss.dbeaver.model.data.DBDContent in project dbeaver by serge-rider.
the class TextViewDialog method extractEditorValue.
@Override
public Object extractEditorValue() {
Object prevValue = getValueController().getValue();
Object rawValue;
if (prevValue instanceof DBDContent) {
if (ContentUtils.isTextContent((DBDContent) prevValue)) {
rawValue = isTextEditorActive() ? textEdit.getText() : getBinaryString();
} else {
rawValue = isTextEditorActive() ? GeneralUtils.convertToBytes(textEdit.getText()) : getBinaryContent();
}
} else {
if (isTextEditorActive()) {
rawValue = textEdit.getText();
} else {
rawValue = getBinaryString();
}
}
try (DBCSession session = getValueController().getExecutionContext().openSession(new VoidProgressMonitor(), DBCExecutionPurpose.UTIL, "Make text value from editor")) {
return getValueController().getValueHandler().getValueFromObject(session, getValueController().getValueType(), rawValue, false, false);
} catch (Exception e) {
DBWorkbench.getPlatformUI().showError("Extract editor value", "Can't extract editor value", e);
return null;
}
}
use of org.jkiss.dbeaver.model.data.DBDContent in project dbeaver by serge-rider.
the class DataExporterDbUnit method exportRow.
@Override
public void exportRow(DBCSession session, DBCResultSet resultSet, Object[] row) throws DBException, IOException {
PrintWriter out = getWriter();
out.write(" <" + tableName);
for (int i = 0; i < row.length; i++) {
if (DBUtils.isNullValue(row[i]) && !includeNullValues) {
continue;
}
DBDAttributeBinding column = columns[i];
String columnName = escapeXmlElementName(column.getName());
if (columnName != null && upperCaseColumnNames) {
columnName = columnName.toUpperCase();
}
out.write(" " + columnName + "=\"");
Object columnValue = row[i];
if (DBUtils.isNullValue(columnValue)) {
writeTextCell("" + getSite().getProperties().get(PROP_NULL_VALUE_STRING));
} else if (columnValue instanceof Float || columnValue instanceof Double || columnValue instanceof BigDecimal) {
int scale = column.getMetaAttribute().getScale() != null && column.getMetaAttribute().getScale() > 0 ? column.getMetaAttribute().getScale() : 1;
try {
out.write(String.format(Locale.ROOT, "%." + scale + "f", columnValue));
} catch (Exception e) {
out.write(columnValue.toString());
}
} else if (columnValue instanceof Boolean) {
out.write(columnValue.toString());
} else if (columnValue instanceof Number) {
out.write(columnValue.toString());
} else if (columnValue instanceof Timestamp) {
try {
int nanoseconds = ((Timestamp) columnValue).getNanos();
out.write(String.format(Locale.ROOT, "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%2$d", columnValue, nanoseconds));
} catch (Exception e) {
out.write(columnValue.toString());
}
} else if (columnValue instanceof Time) {
try {
out.write(String.format(Locale.ROOT, "%1$tH:%1$tM:%1$tS", columnValue));
} catch (Exception e) {
out.write(columnValue.toString());
}
} else if (columnValue instanceof Date) {
try {
out.write(String.format(Locale.ROOT, "%1$tY-%1$tm-%1$td", columnValue));
} catch (Exception e) {
out.write(columnValue.toString());
}
} else if (columnValue instanceof DBDContent) {
// Content
// Inline textual content and handle binaries in some special way
DBDContent content = (DBDContent) columnValue;
try {
DBDContentStorage cs = content.getContents(session.getProgressMonitor());
if (cs != null) {
if (ContentUtils.isTextContent(content)) {
try (Reader reader = cs.getContentReader()) {
writeCellValue(reader);
}
} else {
try (final InputStream stream = cs.getContentStream()) {
Base64.encode(stream, cs.getContentLength(), getSite().getWriter());
}
}
}
} finally {
content.release();
}
} else {
writeTextCell(super.getValueDisplayString(column, columnValue));
}
out.write("\"");
}
out.write("/>" + CommonUtils.getLineSeparator());
}
Aggregations