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 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);
}
}
use of org.jkiss.utils.xml.XMLBuilder in project dbeaver by serge-rider.
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 serge-rider.
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);
}
}
use of org.jkiss.utils.xml.XMLBuilder in project dbeaver by serge-rider.
the class DataSourceSerializerLegacy method saveDataSources.
@Override
public void saveDataSources(DBRProgressMonitor monitor, DBPDataSourceConfigurationStorage configurationStorage, List<DataSourceDescriptor> localDataSources, File configFile) throws IOException {
// 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);
try (XMLBuilder.Element el1 = xml.startElement("data-sources")) {
if (configurationStorage.isDefault()) {
// Folders (only for default storage)
for (DataSourceFolder folder : registry.getAllFolders()) {
saveFolder(xml, folder);
}
}
// Datasources
for (DataSourceDescriptor dataSource : localDataSources) {
// Skip temporary
if (!dataSource.isDetached()) {
saveDataSource(xml, dataSource);
}
}
// Filters
if (configurationStorage.isDefault()) {
try (XMLBuilder.Element ignored = xml.startElement(RegistryConstants.TAG_FILTERS)) {
for (DBSObjectFilter cf : registry.getSavedFilters()) {
if (!cf.isEmpty()) {
saveObjectFiler(xml, null, null, cf);
}
}
}
}
}
xml.flush();
} catch (IOException ex) {
log.error("IO error while saving datasources xml", ex);
}
IOUtils.writeFileFromBuffer(configFile, tempStream.toByteArray());
}
use of org.jkiss.utils.xml.XMLBuilder in project dbeaver by serge-rider.
the class DataSourceProviderRegistry method saveDrivers.
public void saveDrivers() {
File driversConfig = DBWorkbench.getPlatform().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) {
if (provider.isTemporary()) {
continue;
}
xml.startElement(RegistryConstants.TAG_PROVIDER);
xml.addAttribute(RegistryConstants.ATTR_ID, provider.getId());
for (DBPDriver driver : provider.getDrivers()) {
if (driver instanceof DriverDescriptor && ((DriverDescriptor) driver).isModified()) {
((DriverDescriptor) driver).serialize(xml, false);
}
}
xml.endElement();
}
xml.endElement();
xml.flush();
os.close();
} catch (Exception ex) {
log.warn("Error saving drivers", ex);
}
}
Aggregations