Search in sources :

Example 21 with XMLBuilder

use of org.jkiss.utils.xml.XMLBuilder in project dbeaver by dbeaver.

the class DashboardViewConfiguration method saveSettings.

public void saveSettings() {
    File configFile = getConfigFile();
    if (items.isEmpty()) {
        if (configFile.exists() && !configFile.delete()) {
            log.debug("Can't delete view configuration " + configFile.getAbsolutePath());
        }
        return;
    }
    try (OutputStream out = new FileOutputStream(configFile)) {
        XMLBuilder xml = new XMLBuilder(out, GeneralUtils.UTF8_ENCODING);
        xml.setButify(true);
        xml.startElement("dashboards");
        xml.startElement("view");
        xml.addAttribute("openConnectionOnActivate", openConnectionOnActivate);
        xml.addAttribute("useSeparateConnection", useSeparateConnection);
        xml.endElement();
        for (DashboardItemViewConfiguration itemConfig : items) {
            xml.startElement("dashboard");
            itemConfig.serialize(xml);
            xml.endElement();
        }
        xml.endElement();
        xml.flush();
    } catch (Exception e) {
        log.error("Error saving dashboard view configuration", e);
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) XMLBuilder(org.jkiss.utils.xml.XMLBuilder)

Example 22 with XMLBuilder

use of org.jkiss.utils.xml.XMLBuilder in project dbeaver by dbeaver.

the class DriverDescriptorSerializerLegacy method serialize.

public void serialize(XMLBuilder xml, boolean export) throws IOException {
    Map<String, String> pathSubstitutions = getPathSubstitutions();
    try (XMLBuilder.Element e0 = xml.startElement(RegistryConstants.TAG_DRIVER)) {
        if (export) {
            xml.addAttribute(RegistryConstants.ATTR_PROVIDER, driver.getProviderDescriptor().getId());
        }
        xml.addAttribute(RegistryConstants.ATTR_ID, driver.getId());
        if (driver.isDisabled()) {
            xml.addAttribute(RegistryConstants.ATTR_DISABLED, true);
        }
        if (!CommonUtils.isEmpty(driver.getCategory())) {
            xml.addAttribute(RegistryConstants.ATTR_CATEGORY, driver.getCategory());
        }
        xml.addAttribute(RegistryConstants.ATTR_CATEGORIES, String.join(",", driver.getCategories()));
        xml.addAttribute(RegistryConstants.ATTR_NAME, driver.getName());
        xml.addAttribute(RegistryConstants.ATTR_CLASS, driver.getDriverClassName());
        if (!CommonUtils.isEmpty(driver.getSampleURL())) {
            xml.addAttribute(RegistryConstants.ATTR_URL, driver.getSampleURL());
        }
        if (!CommonUtils.isEmpty(driver.getDefaultPort())) {
            xml.addAttribute(RegistryConstants.ATTR_PORT, driver.getDefaultPort());
        }
        if (!CommonUtils.isEmpty(driver.getDefaultDatabase())) {
            xml.addAttribute(RegistryConstants.ATTR_DEFAULT_DATABASE, driver.getDefaultDatabase());
        }
        if (!CommonUtils.isEmpty(driver.getDefaultServer())) {
            xml.addAttribute(RegistryConstants.ATTR_DEFAULT_SERVER, driver.getDefaultServer());
        }
        if (!CommonUtils.isEmpty(driver.getDefaultUser())) {
            xml.addAttribute(RegistryConstants.ATTR_DEFAULT_USER, driver.getDefaultUser());
        }
        xml.addAttribute(RegistryConstants.ATTR_DESCRIPTION, CommonUtils.notEmpty(driver.getDescription()));
        if (driver.isCustomDriverLoader()) {
            xml.addAttribute(RegistryConstants.ATTR_CUSTOM_DRIVER_LOADER, driver.isCustomDriverLoader());
        }
        xml.addAttribute(RegistryConstants.ATTR_CUSTOM, driver.isCustom());
        if (driver.isEmbedded()) {
            xml.addAttribute(RegistryConstants.ATTR_EMBEDDED, driver.isEmbedded());
        }
        if (driver.isAnonymousAccess()) {
            xml.addAttribute(RegistryConstants.ATTR_ANONYMOUS, driver.isAnonymousAccess());
        }
        if (driver.isAllowsEmptyPassword()) {
            xml.addAttribute("allowsEmptyPassword", driver.isAllowsEmptyPassword());
        }
        if (!driver.isInstantiable()) {
            xml.addAttribute(RegistryConstants.ATTR_INSTANTIABLE, driver.isInstantiable());
        }
        // Libraries
        for (DBPDriverLibrary lib : driver.getDriverLibraries()) {
            if (export && !lib.isDisabled()) {
                continue;
            }
            try (XMLBuilder.Element e1 = xml.startElement(RegistryConstants.TAG_LIBRARY)) {
                xml.addAttribute(RegistryConstants.ATTR_TYPE, lib.getType().name());
                xml.addAttribute(RegistryConstants.ATTR_PATH, substitutePathVariables(pathSubstitutions, lib.getPath()));
                xml.addAttribute(RegistryConstants.ATTR_CUSTOM, lib.isCustom());
                if (lib.isDisabled()) {
                    xml.addAttribute(RegistryConstants.ATTR_DISABLED, true);
                }
                if (!CommonUtils.isEmpty(lib.getPreferredVersion())) {
                    xml.addAttribute(RegistryConstants.ATTR_VERSION, lib.getPreferredVersion());
                }
                // xml.addAttribute(RegistryConstants.ATTR_CUSTOM, lib.isCustom());
                List<DriverDescriptor.DriverFileInfo> files = driver.getResolvedFiles().get(lib);
                if (files != null) {
                    for (DriverDescriptor.DriverFileInfo file : files) {
                        try (XMLBuilder.Element e2 = xml.startElement(RegistryConstants.TAG_FILE)) {
                            if (file.getFile() == null) {
                                log.warn("File missing in " + file.getId());
                                continue;
                            }
                            xml.addAttribute(RegistryConstants.ATTR_ID, file.getId());
                            if (!CommonUtils.isEmpty(file.getVersion())) {
                                xml.addAttribute(RegistryConstants.ATTR_VERSION, file.getVersion());
                            }
                            xml.addAttribute(RegistryConstants.ATTR_PATH, substitutePathVariables(pathSubstitutions, file.getFile().getAbsolutePath()));
                        }
                    }
                }
            }
        }
        // Client homes
        for (DBPNativeClientLocation location : driver.getNativeClientHomes()) {
            try (XMLBuilder.Element e1 = xml.startElement(RegistryConstants.TAG_CLIENT_HOME)) {
                xml.addAttribute(RegistryConstants.ATTR_ID, location.getName());
                if (location.getPath() != null) {
                    xml.addAttribute(RegistryConstants.ATTR_PATH, location.getPath().getAbsolutePath());
                }
            }
        }
        // Parameters
        for (Map.Entry<String, Object> paramEntry : driver.getCustomParameters().entrySet()) {
            if (!CommonUtils.equalObjects(paramEntry.getValue(), driver.getDefaultParameters().get(paramEntry.getKey()))) {
                try (XMLBuilder.Element e1 = xml.startElement(RegistryConstants.TAG_PARAMETER)) {
                    xml.addAttribute(RegistryConstants.ATTR_NAME, paramEntry.getKey());
                    xml.addAttribute(RegistryConstants.ATTR_VALUE, CommonUtils.toString(paramEntry.getValue()));
                }
            }
        }
        // Properties
        for (Map.Entry<String, Object> propEntry : driver.getCustomConnectionProperties().entrySet()) {
            if (!CommonUtils.equalObjects(propEntry.getValue(), driver.getDefaultConnectionProperties().get(propEntry.getKey()))) {
                try (XMLBuilder.Element e1 = xml.startElement(RegistryConstants.TAG_PROPERTY)) {
                    xml.addAttribute(RegistryConstants.ATTR_NAME, propEntry.getKey());
                    xml.addAttribute(RegistryConstants.ATTR_VALUE, CommonUtils.toString(propEntry.getValue()));
                }
            }
        }
    }
}
Also used : DBPNativeClientLocation(org.jkiss.dbeaver.model.connection.DBPNativeClientLocation) XMLBuilder(org.jkiss.utils.xml.XMLBuilder) DBPDriverLibrary(org.jkiss.dbeaver.model.connection.DBPDriverLibrary) Map(java.util.Map)

Example 23 with XMLBuilder

use of org.jkiss.utils.xml.XMLBuilder in project dbeaver by dbeaver.

the class MavenRegistry method saveConfiguration.

public void saveConfiguration() {
    sortRepositories();
    try (OutputStream is = new FileOutputStream(getConfigurationFile())) {
        XMLBuilder xml = new XMLBuilder(is, GeneralUtils.UTF8_ENCODING);
        xml.setButify(true);
        try (final XMLBuilder.Element e1 = xml.startElement("maven")) {
            for (MavenRepository repository : repositories) {
                try (final XMLBuilder.Element e2 = xml.startElement("repository")) {
                    xml.addAttribute("id", repository.getId());
                    xml.addAttribute("order", repository.getOrder());
                    xml.addAttribute("enabled", repository.isEnabled());
                    if (repository.getType() != MavenRepository.RepositoryType.GLOBAL) {
                        xml.addAttribute("url", repository.getUrl());
                        xml.addAttribute("name", repository.getName());
                        if (!CommonUtils.isEmpty(repository.getDescription())) {
                            xml.addAttribute("description", repository.getDescription());
                        }
                        for (String scope : repository.getScopes()) {
                            try (final XMLBuilder.Element e3 = xml.startElement("scope")) {
                                xml.addAttribute("group", scope);
                            }
                        }
                        final DBPAuthInfo authInfo = repository.getAuthInfo();
                        if (!CommonUtils.isEmpty(authInfo.getUserName())) {
                            xml.addAttribute("auth-user", authInfo.getUserName());
                            if (!CommonUtils.isEmpty(authInfo.getUserPassword())) {
                                xml.addAttribute("auth-password", ENCRYPTOR.encrypt(authInfo.getUserPassword()));
                            }
                        }
                    }
                }
            }
        }
        xml.flush();
    } catch (Exception e) {
        log.error("Error saving Maven registry", e);
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) DBPAuthInfo(org.jkiss.dbeaver.model.connection.DBPAuthInfo) XMLBuilder(org.jkiss.utils.xml.XMLBuilder) IOException(java.io.IOException)

Example 24 with XMLBuilder

use of org.jkiss.utils.xml.XMLBuilder in project dbeaver by dbeaver.

the class SQLQueryParameterRegistry method save.

public void save() {
    File storeFile = DBWorkbench.getPlatform().getConfigurationFile(CONFIG_FILE_NAME);
    try (OutputStream os = new FileOutputStream(storeFile)) {
        XMLBuilder xml = new XMLBuilder(os, GeneralUtils.UTF8_ENCODING);
        xml.setButify(true);
        xml.startElement("bindings");
        for (ParameterInfo param : parameterMap.values()) {
            xml.startElement(TAG_PARAMETER);
            xml.addAttribute("name", param.name);
            xml.addAttribute("value", param.value);
            xml.endElement();
        }
        xml.endElement();
        xml.flush();
    } catch (IOException ex) {
        log.warn("IO error", ex);
    }
}
Also used : XMLBuilder(org.jkiss.utils.xml.XMLBuilder)

Example 25 with XMLBuilder

use of org.jkiss.utils.xml.XMLBuilder in project dbeaver by serge-rider.

the class DBVModel method serializeEntity.

private static void serializeEntity(XMLBuilder xml, DBVEntity entity) throws IOException {
    xml.startElement(TAG_ENTITY);
    xml.addAttribute(ATTR_NAME, entity.getName());
    if (!CommonUtils.isEmpty(entity.getDescriptionColumnNames())) {
        xml.addAttribute(ATTR_DESCRIPTION, entity.getDescriptionColumnNames());
    }
    if (!CommonUtils.isEmpty(entity.properties)) {
        for (Map.Entry<String, String> prop : entity.properties.entrySet()) {
            xml.startElement(TAG_PROPERTY);
            xml.addAttribute(ATTR_NAME, prop.getKey());
            xml.addAttribute(ATTR_VALUE, prop.getValue());
            xml.endElement();
        }
    }
    // Attributes
    for (DBVEntityAttribute attr : CommonUtils.safeCollection(entity.entityAttributes)) {
        try (final XMLBuilder.Element e3 = xml.startElement(TAG_ATTRIBUTE)) {
            xml.addAttribute(ATTR_NAME, attr.getName());
            final DBVTransformSettings transformSettings = attr.getTransformSettings();
            if (transformSettings != null && transformSettings.hasValuableData()) {
                try (final XMLBuilder.Element e4 = xml.startElement(TAG_TRANSFORM)) {
                    if (!CommonUtils.isEmpty(transformSettings.getCustomTransformer())) {
                        xml.addAttribute(ATTR_CUSTOM, transformSettings.getCustomTransformer());
                    }
                    for (String id : CommonUtils.safeCollection(transformSettings.getIncludedTransformers())) {
                        try (final XMLBuilder.Element e5 = xml.startElement(TAG_INCLUDE)) {
                            xml.addAttribute(ATTR_ID, id);
                        }
                    }
                    for (String id : CommonUtils.safeCollection(transformSettings.getExcludedTransformers())) {
                        try (final XMLBuilder.Element e5 = xml.startElement(TAG_EXCLUDE)) {
                            xml.addAttribute(ATTR_ID, id);
                        }
                    }
                    final Map<String, String> transformOptions = transformSettings.getTransformOptions();
                    if (transformOptions != null) {
                        for (Map.Entry<String, String> prop : transformOptions.entrySet()) {
                            try (final XMLBuilder.Element e5 = xml.startElement(TAG_PROPERTY)) {
                                if (prop.getValue() != null) {
                                    xml.addAttribute(ATTR_NAME, prop.getKey());
                                    xml.addAttribute(ATTR_VALUE, prop.getValue());
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // Constraints
    for (DBVEntityConstraint c : CommonUtils.safeCollection(entity.entityConstraints)) {
        if (c.hasAttributes()) {
            xml.startElement(TAG_CONSTRAINT);
            xml.addAttribute(ATTR_NAME, c.getName());
            xml.addAttribute(ATTR_TYPE, c.getConstraintType().getName());
            for (DBVEntityConstraintColumn cc : CommonUtils.safeCollection(c.getAttributeReferences(null))) {
                xml.startElement(TAG_ATTRIBUTE);
                xml.addAttribute(ATTR_NAME, cc.getAttributeName());
                xml.endElement();
            }
            xml.endElement();
        }
    }
    // Colors
    if (!CommonUtils.isEmpty(entity.colorOverrides)) {
        xml.startElement(TAG_COLORS);
        for (DBVColorOverride color : entity.colorOverrides) {
            xml.startElement(TAG_COLOR);
            xml.addAttribute(ATTR_NAME, color.getAttributeName());
            xml.addAttribute(ATTR_OPERATOR, color.getOperator().name());
            if (color.getColorForeground() != null) {
                xml.addAttribute(ATTR_FOREGROUND, color.getColorForeground());
            }
            if (color.getColorBackground() != null) {
                xml.addAttribute(ATTR_BACKGROUND, color.getColorBackground());
            }
            if (!ArrayUtils.isEmpty(color.getAttributeValues())) {
                for (Object value : color.getAttributeValues()) {
                    if (value == null) {
                        continue;
                    }
                    xml.startElement(TAG_VALUE);
                    xml.addText(GeneralUtils.serializeObject(value));
                    xml.endElement();
                }
            }
            xml.endElement();
        }
        xml.endElement();
    }
    xml.endElement();
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) Map(java.util.Map) XMLBuilder(org.jkiss.utils.xml.XMLBuilder)

Aggregations

XMLBuilder (org.jkiss.utils.xml.XMLBuilder)40 FileOutputStream (java.io.FileOutputStream)10 HashMap (java.util.HashMap)8 Map (java.util.Map)8 Bendpoint (org.eclipse.draw2d.Bendpoint)8 Rectangle (org.eclipse.draw2d.geometry.Rectangle)8 DBException (org.jkiss.dbeaver.DBException)7 OutputStream (java.io.OutputStream)6 XMLException (org.jkiss.utils.xml.XMLException)6 AbsoluteBendpoint (org.eclipse.draw2d.AbsoluteBendpoint)4 RelativeBendpoint (org.eclipse.draw2d.RelativeBendpoint)4 DBPDriverLibrary (org.jkiss.dbeaver.model.connection.DBPDriverLibrary)4 AssociationPart (org.jkiss.dbeaver.ext.erd.part.AssociationPart)3 EntityPart (org.jkiss.dbeaver.ext.erd.part.EntityPart)3 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2