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);
}
}
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);
}
}
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();
}
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);
}
}
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);
}
}
Aggregations