Search in sources :

Example 11 with XMLBuilder

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

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 DBAAuthInfo 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) DBAAuthInfo(org.jkiss.dbeaver.model.access.DBAAuthInfo) XMLBuilder(org.jkiss.utils.xml.XMLBuilder) IOException(java.io.IOException)

Example 12 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)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