[LIB-4] Output of results to console
[hespiff.git] / src / main / java / org / hedgecode / xml / xspf / XSPFConsole.java
1 /*
2  * Copyright (c) 2015-2019. Developed by Hedgecode.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.hedgecode.xml.xspf;
18
19 import java.util.Calendar;
20
21 /**
22  * XSPF API utility class for working with console.
23  *
24  * @author Dmitry Samoshin aka gotty
25  */
26 public final class XSPFConsole {
27
28     private static final String[] ASCII_LOGO = {
29             "  _______     _                   _                ",
30             " |   |  _|_ _| |___ ___ ___ ___ _| |___            ",
31             " |     | -_| . | . | -_|  _| . | . | -_|           ",
32             " |     |___|___|_  |___|___|___|___|___|           ",
33             " |___|___|     |___|  _______           _ ___ ___  ",
34             "                     |   |  _|_ ___ ___|_|  _|  _| ",
35             "                     |     | -_|_ -| . | | |_| |_  ",
36             "                     |     |___|___|  _|_|  _|  _| ",
37             "                     |___|___|     |_|   |_| |_|   ",
38             "     __ __ _____ _____ _____    _____ _____ _      ",
39             "    |  |  |   __|  _  |   __|  |  _  |  _  |_|     ",
40             "    |-   -|__   |   __|   __|  |     |   __| |     ",
41             "    |__|__|_____|__|  |__|     |__|__|__|  |_|     "
42     };
43
44     private static final String COPYRIGHT = "Copyright (c) Hedgecode";
45
46     private XSPFConsole() {
47     }
48
49     public static void console(String message) {
50         System.out.println(
51                 message == null ? "" : message
52         );
53     }
54
55     public static void empty() {
56         console(null);
57     }
58
59     public static void init() {
60         asciiLogo();
61         empty();
62         copyright();
63         version();
64         empty();
65     }
66
67     private static void asciiLogo() {
68         for (String line : ASCII_LOGO) {
69             console(line);
70         }
71     }
72
73     private static void copyright() {
74         int currentYear = Calendar.getInstance().get(Calendar.YEAR);
75         int inceptionYear = XSPFProperties.getInteger(XSPFProperties.INCEPTION_YEAR, currentYear);
76         String copyright = currentYear > inceptionYear
77                 ? String.format("%s-%s %s", inceptionYear, currentYear, COPYRIGHT)
78                 : String.format("%s %s", currentYear, COPYRIGHT);
79         console(
80                 alignCenter(copyright)
81         );
82     }
83
84     private static void version() {
85         console(
86                 alignCenter(
87                         String.format(
88                                 "v. %s", XSPFProperties.getString(XSPFProperties.VERSION)
89                         )
90                 )
91         );
92     }
93
94     private static String alignCenter(String message) {
95         int indent = (ASCII_LOGO[0].length() + message.length()) / 2;
96         return String.format(
97                 "%" + indent + "s",
98                 message
99         );
100     }
101
102 }