// Path: src/main/java/ru/taximaxim/pgsqlblocks/utils/ColumnLayout.java
// public class ColumnLayout {
// 
//     private final int order;
//     private final Columns column;
//     private final Integer width;
// 
//     public ColumnLayout(int order, Columns column, Integer width) {
//         this.order = order;
//         this.column = column;
//         this.width = width;
//     }
// 
//     public int getOrder() {
//         return order;
//     }
// 
//     public Columns getColumn() {
//         return column;
//     }
// 
//     public Integer getWidth() {
//         return width;
//     }
// }
// 
// Path: src/main/java/ru/taximaxim/pgsqlblocks/utils/Columns.java
// public enum Columns {
// 
//     PID("pid"),
//     BACKEND_TYPE("backend_type"),
//     BLOCK_CREATE_DATE("block_start_date"),
//     BLOCK_END_DATE("block_end_date"),
//     BLOCKED_COUNT("num_of_blocked_processes"),
//     APPLICATION_NAME("application"),
//     DATABASE_NAME("db_name"),
//     USER_NAME("user_name"),
//     CLIENT("client"),
//     BACKEND_START("backend_start"),
//     QUERY_START("query_start"),
//     XACT_START("xact_start"),
//     DURATION("duration"),
//     STATE("state"),
//     STATE_CHANGE("state_change"),
//     BLOCKED("blocked_by"),
//     LOCK_TYPE("lock_type"),
//     RELATION("relation"),
//     SLOW_QUERY("slow_query"),
//     QUERY("query");
// 
//     private final String columnName;
// 
//     Columns(String columnName) {
//         this.columnName = columnName;
//     }
// 
//     public String getColumnName() {
//         return columnName;
//     }
// }
// 
// Path: src/main/java/ru/taximaxim/pgsqlblocks/utils/PathBuilder.java
// public final class PathBuilder {
// 
//     private static final Logger LOG = LogManager.getLogger(PathBuilder.class);
// 
//     private static PathBuilder instance;
// 
//     private Path path;
// 
//     private PathBuilder() {
//         try {
//             String os = System.getProperty("os.name").toLowerCase();
//             if (os.contains("win")) {
//                 path = Paths.get(System.getProperty("user.home"), "pgSqlBlocks");
//                 Files.createDirectories(path);
//                 Files.setAttribute(path, "dos:hidden", Boolean.TRUE, LinkOption.NOFOLLOW_LINKS);
//             } else {
//                 path = Paths.get(System.getProperty("user.home"), ".pgSqlBlocks");
//                 Files.createDirectories(path);
//             }
//         } catch (IOException e) {
//             LOG.error(String.format("Ошибка создания директории %s: %s", path, e.getMessage()));
//         }
//     }
// 
//     public static PathBuilder getInstance() {
//         if(instance == null) {
//             instance = new PathBuilder();
//         }
//         return instance;
//     }
// 
//     public Path getBlocksJournalsDir() {
//         Path blocksJournalsDir = path.resolve("blocksJournals");
//         if (!blocksJournalsDir.toFile().exists()) {
//             try {
//                 Files.createDirectory(blocksJournalsDir);
//             } catch (IOException e) {
//                 LOG.error(String.format("Ошибка создания директории %s: %s", blocksJournalsDir, e.getMessage()));
//             }
//         }
//         return blocksJournalsDir;
//     }
// 
//     public Path getServersPath() {
//         return path.resolve("servers.xml");
//     }
// 
//     public Path getColumnsPath() {
//         return path.resolve("columns");
//     }
// 
//     // TODO разные конфиги log4j.propertires для разных ОС
//     Path getPropertiesPath() {
//         Path propPath = path.resolve("pgsqlblocks.properties");
//         if (!propPath.toFile().exists()) {
//             try {
//                 Files.createFile(propPath);
//             } catch (IOException e) {
//                 LOG.error(String.format("Ошибка создания файла %s: %s", propPath, e.getMessage()));
//             }
//         }
//         return propPath;
//     }
// }


import java.nio.file.Path;
import java.util.List;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import ru.taximaxim.pgsqlblocks.utils.ColumnLayout;
import ru.taximaxim.pgsqlblocks.utils.Columns;
import ru.taximaxim.pgsqlblocks.utils.PathBuilder;
/*-
 * ========================LICENSE_START=================================
 * pgSqlBlocks
 * %
 * Copyright (C) 2017 - 2018 "Technology" LLC
 * %
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =========================LICENSE_END==================================
 */
package ru.taximaxim.pgsqlblocks.xmlstore;




public class ColumnLayoutsXmlStore extends XmlStore<ColumnLayout> {

    private static final String ROOT_TAG = "columns";

    private static final String COLUMN = "column";
    private static final String COLUMN_ORDER = "column_order";
    private static final String COLUMN_NAME = "column_name";
    private static final String COLUMN_SIZE = "column_size";

    private final String fileName;

    public ColumnLayoutsXmlStore(String fileName) {
        super(ROOT_TAG);
        this.fileName = fileName;
    }

    @Override
    protected Path getXmlFile() {
// Path: src/main/java/ru/taximaxim/pgsqlblocks/utils/ColumnLayout.java
// public class ColumnLayout {
// 
//     private final int order;
//     private final Columns column;
//     private final Integer width;
// 
//     public ColumnLayout(int order, Columns column, Integer width) {
//         this.order = order;
//         this.column = column;
//         this.width = width;
//     }
// 
//     public int getOrder() {
//         return order;
//     }
// 
//     public Columns getColumn() {
//         return column;
//     }
// 
//     public Integer getWidth() {
//         return width;
//     }
// }
// 
// Path: src/main/java/ru/taximaxim/pgsqlblocks/utils/Columns.java
// public enum Columns {
// 
//     PID("pid"),
//     BACKEND_TYPE("backend_type"),
//     BLOCK_CREATE_DATE("block_start_date"),
//     BLOCK_END_DATE("block_end_date"),
//     BLOCKED_COUNT("num_of_blocked_processes"),
//     APPLICATION_NAME("application"),
//     DATABASE_NAME("db_name"),
//     USER_NAME("user_name"),
//     CLIENT("client"),
//     BACKEND_START("backend_start"),
//     QUERY_START("query_start"),
//     XACT_START("xact_start"),
//     DURATION("duration"),
//     STATE("state"),
//     STATE_CHANGE("state_change"),
//     BLOCKED("blocked_by"),
//     LOCK_TYPE("lock_type"),
//     RELATION("relation"),
//     SLOW_QUERY("slow_query"),
//     QUERY("query");
// 
//     private final String columnName;
// 
//     Columns(String columnName) {
//         this.columnName = columnName;
//     }
// 
//     public String getColumnName() {
//         return columnName;
//     }
// }
// 
// Path: src/main/java/ru/taximaxim/pgsqlblocks/utils/PathBuilder.java
// public final class PathBuilder {
// 
//     private static final Logger LOG = LogManager.getLogger(PathBuilder.class);
// 
//     private static PathBuilder instance;
// 
//     private Path path;
// 
//     private PathBuilder() {
//         try {
//             String os = System.getProperty("os.name").toLowerCase();
//             if (os.contains("win")) {
//                 path = Paths.get(System.getProperty("user.home"), "pgSqlBlocks");
//                 Files.createDirectories(path);
//                 Files.setAttribute(path, "dos:hidden", Boolean.TRUE, LinkOption.NOFOLLOW_LINKS);
//             } else {
//                 path = Paths.get(System.getProperty("user.home"), ".pgSqlBlocks");
//                 Files.createDirectories(path);
//             }
//         } catch (IOException e) {
//             LOG.error(String.format("Ошибка создания директории %s: %s", path, e.getMessage()));
//         }
//     }
// 
//     public static PathBuilder getInstance() {
//         if(instance == null) {
//             instance = new PathBuilder();
//         }
//         return instance;
//     }
// 
//     public Path getBlocksJournalsDir() {
//         Path blocksJournalsDir = path.resolve("blocksJournals");
//         if (!blocksJournalsDir.toFile().exists()) {
//             try {
//                 Files.createDirectory(blocksJournalsDir);
//             } catch (IOException e) {
//                 LOG.error(String.format("Ошибка создания директории %s: %s", blocksJournalsDir, e.getMessage()));
//             }
//         }
//         return blocksJournalsDir;
//     }
// 
//     public Path getServersPath() {
//         return path.resolve("servers.xml");
//     }
// 
//     public Path getColumnsPath() {
//         return path.resolve("columns");
//     }
// 
//     // TODO разные конфиги log4j.propertires для разных ОС
//     Path getPropertiesPath() {
//         Path propPath = path.resolve("pgsqlblocks.properties");
//         if (!propPath.toFile().exists()) {
//             try {
//                 Files.createFile(propPath);
//             } catch (IOException e) {
//                 LOG.error(String.format("Ошибка создания файла %s: %s", propPath, e.getMessage()));
//             }
//         }
//         return propPath;
//     }
// }


// Path: src/main/java/ru/taximaxim/pgsqlblocks/xmlstore/ColumnLayoutsXmlStore.java
import java.nio.file.Path;
import java.util.List;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import ru.taximaxim.pgsqlblocks.utils.ColumnLayout;
import ru.taximaxim.pgsqlblocks.utils.Columns;
import ru.taximaxim.pgsqlblocks.utils.PathBuilder;

/*-
 * ========================LICENSE_START=================================
 * pgSqlBlocks
 * %
 * Copyright (C) 2017 - 2018 "Technology" LLC
 * %
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =========================LICENSE_END==================================
 */
package ru.taximaxim.pgsqlblocks.xmlstore;




public class ColumnLayoutsXmlStore extends XmlStore<ColumnLayout> {

    private static final String ROOT_TAG = "columns";

    private static final String COLUMN = "column";
    private static final String COLUMN_ORDER = "column_order";
    private static final String COLUMN_NAME = "column_name";
    private static final String COLUMN_SIZE = "column_size";

    private final String fileName;

    public ColumnLayoutsXmlStore(String fileName) {
        super(ROOT_TAG);
        this.fileName = fileName;
    }

    @Override
    protected Path getXmlFile() {
        return PathBuilder.getInstance().getColumnsPath().resolve(fileName);