Search in sources :

Example 36 with XMLBuilder

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

the class DataSourceProviderRegistry method saveConnectionTypes.

@Override
public void saveConnectionTypes() {
    File ctConfig = DBWorkbench.getPlatform().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.addAttribute(RegistryConstants.ATTR_CONFIRM_DATA_CHANGE, connectionType.isConfirmDataChange());
            List<DBPDataSourcePermission> modifyPermission = connectionType.getModifyPermission();
            if (modifyPermission != null) {
                xml.addAttribute("modifyPermission", modifyPermission.stream().map(DBPDataSourcePermission::name).collect(Collectors.joining(",")));
            }
            xml.endElement();
        }
        xml.endElement();
        xml.flush();
        os.close();
    } catch (Exception ex) {
        log.warn("Error saving drivers", ex);
    }
}
Also used : DBPDataSourcePermission(org.jkiss.dbeaver.model.DBPDataSourcePermission) XMLBuilder(org.jkiss.utils.xml.XMLBuilder) XMLException(org.jkiss.utils.xml.XMLException)

Example 37 with XMLBuilder

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

the class DataSourceProviderRegistry method saveConnectionTypes.

@Override
public void saveConnectionTypes() {
    File ctConfig = DBWorkbench.getPlatform().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.addAttribute(RegistryConstants.ATTR_CONFIRM_DATA_CHANGE, connectionType.isConfirmDataChange());
            List<DBPDataSourcePermission> modifyPermission = connectionType.getModifyPermission();
            if (modifyPermission != null) {
                xml.addAttribute("modifyPermission", modifyPermission.stream().map(DBPDataSourcePermission::name).collect(Collectors.joining(",")));
            }
            xml.endElement();
        }
        xml.endElement();
        xml.flush();
        os.close();
    } catch (Exception ex) {
        log.warn("Error saving drivers", ex);
    }
}
Also used : DBPDataSourcePermission(org.jkiss.dbeaver.model.DBPDataSourcePermission) XMLBuilder(org.jkiss.utils.xml.XMLBuilder) XMLException(org.jkiss.utils.xml.XMLException)

Example 38 with XMLBuilder

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

the class DBVModelSerializerLegacy 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.getProperties())) {
        for (Map.Entry<String, Object> prop : entity.getProperties().entrySet()) {
            xml.startElement(TAG_PROPERTY);
            xml.addAttribute(ATTR_NAME, prop.getKey());
            xml.addAttribute(ATTR_VALUE, CommonUtils.toString(prop.getValue()));
            xml.endElement();
        }
    }
    // Attributes
    for (DBVEntityAttribute attr : CommonUtils.safeCollection(entity.getEntityAttributes())) {
        if (!attr.hasValuableData()) {
            continue;
        }
        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, Object> transformOptions = transformSettings.getTransformOptions();
                    if (transformOptions != null) {
                        for (Map.Entry<String, Object> 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, CommonUtils.toString(prop.getValue()));
                                }
                            }
                        }
                    }
                }
            }
            if (!CommonUtils.isEmpty(attr.getProperties())) {
                for (Map.Entry<String, Object> prop : attr.getProperties().entrySet()) {
                    xml.startElement(TAG_PROPERTY);
                    xml.addAttribute(ATTR_NAME, prop.getKey());
                    xml.addAttribute(ATTR_VALUE, CommonUtils.toString(prop.getValue()));
                    xml.endElement();
                }
            }
        }
    }
    // Constraints
    for (DBVEntityConstraint c : CommonUtils.safeCollection(entity.getConstraints())) {
        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();
        }
    }
    // Foreign keys
    for (DBVEntityForeignKey fk : CommonUtils.safeCollection(entity.getForeignKeys())) {
        xml.startElement(TAG_ASSOCIATION);
        DBSEntity refEntity = fk.getAssociatedEntity();
        xml.addAttribute(ATTR_ENTITY, DBUtils.getObjectFullId(refEntity));
        DBSEntityConstraint refConstraint = fk.getReferencedConstraint();
        if (refConstraint != null) {
            xml.addAttribute(ATTR_CONSTRAINT, refConstraint.getName());
        }
        for (DBVEntityForeignKeyColumn cc : CommonUtils.safeCollection(fk.getAttributes())) {
            xml.startElement(TAG_ATTRIBUTE);
            xml.addAttribute(ATTR_NAME, cc.getAttributeName());
            xml.endElement();
        }
        xml.endElement();
    }
    // Colors
    if (!CommonUtils.isEmpty(entity.getColorOverrides())) {
        xml.startElement(TAG_COLORS);
        for (DBVColorOverride color : entity.getColorOverrides()) {
            xml.startElement(TAG_COLOR);
            xml.addAttribute(ATTR_NAME, color.getAttributeName());
            xml.addAttribute(ATTR_OPERATOR, color.getOperator().name());
            if (color.isRange()) {
                xml.addAttribute(ATTR_RANGE, true);
            }
            if (color.isSingleColumn()) {
                xml.addAttribute(ATTR_SINGLE_COLUMN, true);
            }
            if (color.getColorForeground() != null) {
                xml.addAttribute(ATTR_FOREGROUND, color.getColorForeground());
            }
            if (color.getColorForeground2() != null) {
                xml.addAttribute(ATTR_FOREGROUND2, color.getColorForeground2());
            }
            if (color.getColorBackground() != null) {
                xml.addAttribute(ATTR_BACKGROUND, color.getColorBackground());
            }
            if (color.getColorBackground2() != null) {
                xml.addAttribute(ATTR_BACKGROUND2, color.getColorBackground2());
            }
            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 : DBSEntityConstraint(org.jkiss.dbeaver.model.struct.DBSEntityConstraint) XMLBuilder(org.jkiss.utils.xml.XMLBuilder) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) Map(java.util.Map)

Example 39 with XMLBuilder

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

the class DataFormatterRegistry method saveProfiles.

private void saveProfiles() {
    if (customProfiles == null) {
        return;
    }
    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("profiles");
        for (DBDDataFormatterProfile profile : customProfiles) {
            xml.startElement("profile");
            xml.addAttribute("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("property");
                    xml.addAttribute("name", entry.getKey());
                    xml.addAttribute("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 40 with XMLBuilder

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

the class DashboardRegistry method saveConfigFile.

private void saveConfigFile() {
    try (OutputStream out = new FileOutputStream(getDashboardsConfigFile())) {
        XMLBuilder xml = new XMLBuilder(out, GeneralUtils.UTF8_ENCODING);
        xml.setButify(true);
        xml.startElement("dashboards");
        for (DashboardDescriptor dashboard : dashboardList.values()) {
            if (dashboard.isCustom()) {
                xml.startElement("dashboard");
                dashboard.serialize(xml);
                xml.endElement();
            }
        }
        xml.endElement();
        xml.flush();
    } catch (Exception e) {
        log.error("Error saving dashboard configuration", e);
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) XMLBuilder(org.jkiss.utils.xml.XMLBuilder) XMLException(org.jkiss.utils.xml.XMLException)

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