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