use of org.jkiss.dbeaver.model.data.DBDContent in project dbeaver by dbeaver.
the class DataExporterXML method exportRow.
@Override
public void exportRow(DBCSession session, Object[] row) throws DBException, IOException {
out.write(" <DATA_RECORD>\n");
for (int i = 0; i < row.length; i++) {
DBDAttributeBinding column = columns.get(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 dbeaver.
the class DataExporterHTML method exportRow.
@Override
public void exportRow(DBCSession session, DBCResultSet resultSet, Object[] row) throws DBException, IOException {
PrintWriter out = getWriter();
out.write("<tr" + (rowCount++ % 2 == 0 ? " class=\"odd\"" : "") + ">");
for (int i = 0; i < row.length; i++) {
DBDAttributeBinding column = columns[i];
if (DBUtils.isNullValue(row[i])) {
writeTextCell(null, false);
} 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());
out.write("<td>");
if (cs != null) {
if (ContentUtils.isTextContent(content)) {
writeCellValue(cs.getContentReader());
} else {
getSite().writeBinaryData(cs);
}
}
out.write("</td>");
} finally {
content.release();
}
} else {
String stringValue = super.getValueDisplayString(column, row[i]);
boolean isImage = row[i] instanceof File && stringValue != null && stringValue.endsWith(".jpg");
if (isImage) {
writeImageCell((File) row[i]);
} else {
writeTextCell(stringValue, false);
}
}
}
out.write("</tr>\n");
}
use of org.jkiss.dbeaver.model.data.DBDContent in project dbeaver by dbeaver.
the class DataExporterMarkdownTable method exportRow.
@Override
public void exportRow(DBCSession session, DBCResultSet resultSet, Object[] row) throws DBException, IOException {
writeDelimiter();
for (int i = 0; i < row.length && i < columns.length; i++) {
DBDAttributeBinding column = columns[i];
if (DBUtils.isNullValue(row[i])) {
if (!CommonUtils.isEmpty(nullString)) {
getWriter().write(nullString);
}
} 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) {
writeCellValue(DBConstants.NULL_VALUE_LABEL);
} else if (ContentUtils.isTextContent(content)) {
writeCellValue(cs.getContentReader());
} else {
getSite().writeBinaryData(cs);
}
} finally {
content.release();
}
} else {
writeCellValue(super.getValueDisplayString(column, row[i]));
}
writeDelimiter();
}
writeRowLimit();
}
use of org.jkiss.dbeaver.model.data.DBDContent in project dbeaver by dbeaver.
the class DataExporterSourceCode method exportRow.
@Override
public void exportRow(DBCSession session, DBCResultSet resultSet, Object[] row) throws DBException, IOException {
PrintWriter out = getWriter();
if (rowNum > 0) {
out.write("," + rowDelimiter);
}
rowNum++;
if (language == ProgramLanguages.PHP_VERSION_LESS_5_and_4) {
out.write("\tarray(" + rowDelimiter);
} else {
out.write("\t[" + rowDelimiter);
}
for (int i = 0; i < columns.length; i++) {
DBDAttributeBinding column = columns[i];
String columnName = column.getLabel();
if (CommonUtils.isEmpty(columnName)) {
columnName = column.getName();
}
out.write("\t\t" + quoteChar + JSONUtils.escapeJsonString(columnName) + quoteChar + " => ");
Object cellValue = row[column.getOrdinalPosition()];
if (DBUtils.isNullValue(cellValue)) {
writeTextCell(null);
} else if (cellValue instanceof DBDContent) {
// Content
// Inline textual content and handle binaries in some special way
DBDContent content = (DBDContent) cellValue;
try {
DBDContentStorage cs = content.getContents(session.getProgressMonitor());
if (cs != null) {
if (ContentUtils.isTextContent(content)) {
try (Reader in = cs.getContentReader()) {
out.write(quoteChar);
writeCellValue(in);
out.write(quoteChar);
}
} else {
getSite().writeBinaryData(cs);
}
}
} finally {
content.release();
}
} else {
if (cellValue instanceof Number || cellValue instanceof Boolean) {
out.write(cellValue.toString());
} else if (cellValue instanceof Date && formatDateISO) {
writeTextCell(JSONUtils.formatDate((Date) cellValue));
} else {
writeTextCell(super.getValueDisplayString(column, cellValue));
}
}
if (i < columns.length - 1) {
out.write(",");
}
out.write(rowDelimiter);
}
if (language == ProgramLanguages.PHP_VERSION_LESS_5_and_4) {
out.write("\t)");
} else {
out.write("\t]");
}
}
use of org.jkiss.dbeaver.model.data.DBDContent in project dbeaver by serge-rider.
the class DataExporterMarkdownTable method exportRow.
@Override
public void exportRow(DBCSession session, DBCResultSet resultSet, Object[] row) throws DBException, IOException {
writeDelimiter();
for (int i = 0; i < row.length && i < columns.length; i++) {
DBDAttributeBinding column = columns[i];
if (DBUtils.isNullValue(row[i])) {
if (!CommonUtils.isEmpty(nullString)) {
getWriter().write(nullString);
}
} 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) {
writeCellValue(DBConstants.NULL_VALUE_LABEL);
} else if (ContentUtils.isTextContent(content)) {
writeCellValue(cs.getContentReader());
} else {
getSite().writeBinaryData(cs);
}
} finally {
content.release();
}
} else {
writeCellValue(super.getValueDisplayString(column, row[i]));
}
writeDelimiter();
}
writeRowLimit();
}
Aggregations