Search in sources :

Example 6 with XMLBuilder

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;
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) XMLBuilder(org.jkiss.utils.xml.XMLBuilder) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException)

Example 7 with XMLBuilder

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);
    }
}
Also used : SimplePreferenceStore(org.jkiss.dbeaver.model.impl.preferences.SimplePreferenceStore) DBDDataFormatterProfile(org.jkiss.dbeaver.model.data.DBDDataFormatterProfile) HashMap(java.util.HashMap) Map(java.util.Map) XMLBuilder(org.jkiss.utils.xml.XMLBuilder)

Example 8 with XMLBuilder

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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ImageData(org.eclipse.swt.graphics.ImageData) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Image(org.eclipse.swt.graphics.Image) DBPImage(org.jkiss.dbeaver.model.DBPImage) ImageLoader(org.eclipse.swt.graphics.ImageLoader) XMLBuilder(org.jkiss.utils.xml.XMLBuilder)

Example 9 with XMLBuilder

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);
    }
}
Also used : DBPConnectionType(org.jkiss.dbeaver.model.connection.DBPConnectionType) XMLBuilder(org.jkiss.utils.xml.XMLBuilder) XMLException(org.jkiss.utils.xml.XMLException)

Example 10 with XMLBuilder

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);
    }
}
Also used : DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) XMLBuilder(org.jkiss.utils.xml.XMLBuilder) XMLException(org.jkiss.utils.xml.XMLException)

Aggregations

XMLBuilder (org.jkiss.utils.xml.XMLBuilder)12 HashMap (java.util.HashMap)3 FileOutputStream (java.io.FileOutputStream)2 Map (java.util.Map)2 Bendpoint (org.eclipse.draw2d.Bendpoint)2 Rectangle (org.eclipse.draw2d.geometry.Rectangle)2 AssociationPart (org.jkiss.dbeaver.ext.erd.part.AssociationPart)2 EntityPart (org.jkiss.dbeaver.ext.erd.part.EntityPart)2 DriverDescriptor (org.jkiss.dbeaver.registry.driver.DriverDescriptor)2 XMLException (org.jkiss.utils.xml.XMLException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 HashSet (java.util.HashSet)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1