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