use of org.jkiss.utils.xml.XMLBuilder in project dbeaver by serge-rider.
the class DataSourceRegistry method saveDataSources.
private void saveDataSources() {
updateProjectNature();
final IProgressMonitor progressMonitor = new NullProgressMonitor();
saveInProgress = true;
try {
for (DataSourceOrigin origin : origins.values()) {
List<DataSourceDescriptor> localDataSources = getDataSources(origin);
IFile configFile = origin.getSourceFile();
try {
if (localDataSources.isEmpty()) {
configFile.delete(true, false, progressMonitor);
} else {
// Save in temp memory to be safe (any error during direct write will corrupt configuration)
ByteArrayOutputStream tempStream = new ByteArrayOutputStream(10000);
try {
XMLBuilder xml = new XMLBuilder(tempStream, GeneralUtils.UTF8_ENCODING);
xml.setButify(true);
xml.startElement("data-sources");
if (origin.isDefault()) {
// Folders (only for default origin)
for (DataSourceFolder folder : dataSourceFolders) {
saveFolder(xml, folder);
}
}
// Datasources
for (DataSourceDescriptor dataSource : localDataSources) {
saveDataSource(xml, dataSource);
}
xml.endElement();
xml.flush();
} catch (IOException ex) {
log.warn("IO error while saving datasources", ex);
}
InputStream ifs = new ByteArrayInputStream(tempStream.toByteArray());
if (!configFile.exists()) {
configFile.create(ifs, true, progressMonitor);
configFile.setHidden(true);
} else {
configFile.setContents(ifs, true, false, progressMonitor);
}
}
try {
getSecurePreferences().flush();
} catch (IOException e) {
log.error("Error saving secured preferences", e);
}
} catch (CoreException ex) {
log.error("Error saving datasources configuration", ex);
}
}
} finally {
saveInProgress = false;
}
}
use of org.jkiss.utils.xml.XMLBuilder in project dbeaver by serge-rider.
the class DataFormatterRegistry method saveProfiles.
private void saveProfiles() {
if (customProfiles == null) {
return;
}
File storeFile = DBeaverActivator.getConfigurationFile(CONFIG_FILE_NAME);
try (OutputStream os = new FileOutputStream(storeFile)) {
XMLBuilder xml = new XMLBuilder(os, GeneralUtils.UTF8_ENCODING);
xml.setButify(true);
xml.startElement(RegistryConstants.TAG_PROFILES);
for (DBDDataFormatterProfile profile : customProfiles) {
xml.startElement(RegistryConstants.TAG_PROFILE);
xml.addAttribute(RegistryConstants.ATTR_NAME, profile.getProfileName());
SimplePreferenceStore store = (SimplePreferenceStore) profile.getPreferenceStore();
Map<String, String> props = store.getProperties();
if (props != null) {
for (Map.Entry<String, String> entry : props.entrySet()) {
xml.startElement(RegistryConstants.TAG_PROPERTY);
xml.addAttribute(RegistryConstants.ATTR_NAME, entry.getKey());
xml.addAttribute(RegistryConstants.ATTR_VALUE, entry.getValue());
xml.endElement();
}
}
xml.endElement();
}
xml.endElement();
xml.flush();
} catch (IOException ex) {
log.warn("IO error", ex);
}
}
use of org.jkiss.utils.xml.XMLBuilder in project dbeaver by serge-rider.
the class BookmarkStorage method serialize.
public ByteArrayInputStream serialize() throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream(5000);
XMLBuilder xml = new XMLBuilder(buffer, GeneralUtils.getDefaultFileEncoding());
xml.startElement(TAG_BOOKMARK);
xml.addAttribute(ATTR_TITLE, title);
if (description != null) {
xml.addAttribute(ATTR_DESCRIPTION, description);
}
xml.addAttribute(ATTR_DATA_SOURCE, dataSourceId);
for (String path : dataSourcePath) {
xml.startElement(TAG_PATH);
xml.addText(path);
xml.endElement();
}
{
xml.startElement(TAG_IMAGE);
Image realImage = DBeaverIcons.getImage(this.image);
ImageLoader loader = new ImageLoader();
loader.data = new ImageData[] { realImage.getImageData() };
ByteArrayOutputStream imageBuffer = new ByteArrayOutputStream(5000);
loader.save(imageBuffer, SWT.IMAGE_PNG);
xml.addText(Base64.encode(imageBuffer.toByteArray()));
xml.endElement();
}
xml.endElement();
xml.flush();
return new ByteArrayInputStream(buffer.toByteArray());
}
use of org.jkiss.utils.xml.XMLBuilder in project dbeaver by serge-rider.
the class DataSourceProviderRegistry method saveConnectionTypes.
public void saveConnectionTypes() {
File ctConfig = DBeaverActivator.getConfigurationFile(RegistryConstants.CONNECTION_TYPES_FILE_NAME);
try {
OutputStream os = new FileOutputStream(ctConfig);
XMLBuilder xml = new XMLBuilder(os, GeneralUtils.UTF8_ENCODING);
xml.setButify(true);
xml.startElement(RegistryConstants.TAG_TYPES);
for (DBPConnectionType connectionType : connectionTypes.values()) {
xml.startElement(RegistryConstants.TAG_TYPE);
xml.addAttribute(RegistryConstants.ATTR_ID, connectionType.getId());
xml.addAttribute(RegistryConstants.ATTR_NAME, CommonUtils.toString(connectionType.getName()));
xml.addAttribute(RegistryConstants.ATTR_COLOR, connectionType.getColor());
xml.addAttribute(RegistryConstants.ATTR_DESCRIPTION, CommonUtils.toString(connectionType.getDescription()));
xml.addAttribute(RegistryConstants.ATTR_AUTOCOMMIT, connectionType.isAutocommit());
xml.addAttribute(RegistryConstants.ATTR_CONFIRM_EXECUTE, connectionType.isConfirmExecute());
xml.endElement();
}
xml.endElement();
xml.flush();
os.close();
} catch (Exception ex) {
log.warn("Error saving drivers", ex);
}
}
use of org.jkiss.utils.xml.XMLBuilder in project dbeaver by serge-rider.
the class DataSourceProviderRegistry method saveDrivers.
public void saveDrivers() {
File driversConfig = DBeaverActivator.getConfigurationFile(RegistryConstants.DRIVERS_FILE_NAME);
try {
OutputStream os = new FileOutputStream(driversConfig);
XMLBuilder xml = new XMLBuilder(os, GeneralUtils.UTF8_ENCODING);
xml.setButify(true);
xml.startElement(RegistryConstants.TAG_DRIVERS);
for (DataSourceProviderDescriptor provider : this.dataSourceProviders) {
xml.startElement(RegistryConstants.TAG_PROVIDER);
xml.addAttribute(RegistryConstants.ATTR_ID, provider.getId());
for (DriverDescriptor driver : provider.getDrivers()) {
if (driver.isModified()) {
driver.serialize(xml, false);
}
}
xml.endElement();
}
xml.endElement();
xml.flush();
os.close();
} catch (Exception ex) {
log.warn("Error saving drivers", ex);
}
}
Aggregations