001/*
002 * #%L
003 * Netarchivesuite - deploy
004 * %%
005 * Copyright (C) 2005 - 2018 The Royal Danish Library, 
006 *             the National Library of France and the Austrian National Library.
007 * %%
008 * This program is free software: you can redistribute it and/or modify
009 * it under the terms of the GNU Lesser General Public License as
010 * published by the Free Software Foundation, either version 2.1 of the
011 * License, or (at your option) any later version.
012 * 
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016 * GNU General Lesser Public License for more details.
017 * 
018 * You should have received a copy of the GNU General Lesser Public
019 * License along with this program.  If not, see
020 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
021 * #L%
022 */
023package dk.netarkivet.deploy;
024
025import java.util.regex.Pattern;
026
027import dk.netarkivet.archive.ArchiveSettings;
028import dk.netarkivet.common.CommonSettings;
029import dk.netarkivet.common.exceptions.ArgumentNotValid;
030import dk.netarkivet.common.utils.EMailNotifications;
031import dk.netarkivet.harvester.HarvesterSettings;
032import dk.netarkivet.monitor.MonitorSettings;
033
034/**
035 * Class containing the constant variables.
036 * <p>
037 * SETTINGS_ = path to branches from the settings branch. COMPLETE_ = path from beyond the settings branch.
038 */
039public final class Constants {
040
041    // Single character specific
042    /** The empty string, "". */
043    static final String EMPTY = "";
044    /** The newline character as a string. */
045    static final String NEWLINE = "\n";
046    /** Quote mark. */
047    static final String QUOTE_MARK = "\"";
048    /** Apostrophe. */
049    static final String APOSTROPHE = "'";
050    /** The space character as a string. */
051    static final String SPACE = " ";
052    /** The at '@' character as a string. */
053    static final String AT = "@";
054    /** The underscore '_' character as a string. */
055    static final String UNDERSCORE = "_";
056    /** Less than (prefix for XML). */
057    static final String LESS_THAN = "<";
058    /** Greater than (suffix for XML). */
059    static final String GREATER_THAN = ">";
060    /** Slash, Linux/Unix directory path separator. */
061    static final String SLASH = "/";
062    /** Dot: '.'. */
063    static final String DOT = ".";
064    /** Dash: '-'. */
065    static final String DASH = "-";
066    /** BackSlash: '\\'. */
067    static final String BACKSLASH = "\\";
068    /** Colon: ':'. */
069    static final String COLON = ":";
070    /** Semicolon: ';'. */
071    static final String SEMICOLON = ";";
072    /** ( - To start a standard bracket. */
073    static final String BRACKET_BEGIN = "(";
074    /** ) - To end a standard bracket. */
075    static final String BRACKET_END = ")";
076    /** [ - To start a square bracket. */
077    static final String SQUARE_BRACKET_BEGIN = "[";
078    /** ] - To end a square bracket. */
079    static final String SQUARE_BRACKET_END = "]";
080    /** $ - Dollar sign. */
081    static final String DOLLAR_SIGN = "$";
082    /** | - Separator. */
083    static final String SEPARATOR = "|";
084    /** - Star. */
085    static final String STAR = "*";
086
087    // deploy specific parameters.
088    /** The path to the class path branches. */
089    static final String DEPLOY_CLASS_PATH = "deployClassPath";
090    /** The path to the java option branches. */
091    static final String DEPLOY_JAVA_OPTIONS = "deployJavaOpt";
092    /** The path to the optional installation directory. */
093    static final String DEPLOY_INSTALL_DIR = "deployInstallDir";
094    /** The path to the machine user name. */
095    static final String DEPLOY_MACHINE_USER_NAME = "deployMachineUserName";
096    /** The path to the directory for the database. */
097    static final String DEPLOY_HARVEST_DATABASE_DIR = "deployHarvestDatabaseDir";
098    /** The path to the directory for the archive database. */
099    static final String DEPLOY_ARCHIVE_DATABASE_DIR = "deployArchiveDatabaseDir";
100    /** The path to physical locations in from the global scope. */
101    static final String DEPLOY_PHYSICAL_LOCATION = "thisPhysicalLocation";
102    /** The path to machines from a physical location. */
103    static final String DEPLOY_MACHINE = "deployMachine";
104    /** The path to applications from a machine. */
105    static final String DEPLOY_APPLICATION_NAME = "applicationName";
106
107    // Attributes
108    /** The path to name in a application instance. */
109    static final String APPLICATION_NAME_ATTRIBUTE = "name";
110    /** The path to name in a physical location instance. */
111    static final String PHYSICAL_LOCATION_NAME_ATTRIBUTE = "name";
112    /** The path to name in a machine instance. */
113    static final String MACHINE_NAME_ATTRIBUTE = "name";
114    /** The path to the operating system variable. */
115    static final String MACHINE_OPERATING_SYSTEM_ATTRIBUTE = "os";
116    /** The path to the machine encoding. */
117    static final String MACHINE_ENCODING_ATTRIBUTE = "encoding";
118    /** Default machine encoding, if not defined. Currently UTF-8. */
119    static final String MACHINE_ENCODING_DEFAULT = "UTF-8";
120
121    // Attribute values
122    /** The operating system attribute for windows. */
123    static final String OPERATING_SYSTEM_WINDOWS_ATTRIBUTE = "windows";
124    /** The operating system attribute for linux/unix. */
125    static final String OPERATING_SYSTEM_LINUX_ATTRIBUTE = "linux";
126
127    // TAGS
128    /** The attachment for the file dir in the security policy file. */
129    static final String SECURITY_FILE_DIR_TAG = "filedir";
130    /** The name of the jmx principal name tag in the security file. */
131    static final String SECURITY_JMX_PRINCIPAL_NAME_TAG = "ROLE";
132    /** The name of the common temp dir tag in the security policy file. */
133    static final String SECURITY_COMMON_TEMP_DIR_TAG = "TEMPDIR";
134    /** The name of the application id in the log.prop file. */
135    static final String LOG_PROPERTY_APPLICATION_ID_TAG = "APPID";
136
137    // Setting specific
138    /** Path to the Settings branch. */
139    static final String COMPLETE_SETTINGS_BRANCH = CommonSettings.SETTINGS;
140    /** The total path to the environment name from an entity branch. */
141    static final String[] COMPLETE_ENVIRONMENT_NAME_LEAF = CommonSettings.ENVIRONMENT_NAME.split("[.]");
142    /** The path to the environment name from the settings branch. */
143    static final String[] SETTINGS_ENVIRONMENT_NAME_LEAF = CommonSettings.ENVIRONMENT_NAME.replace(
144            CommonSettings.SETTINGS + ".", "").split("[.]");
145    /** The path to the database directory from the settings branch. */
146    static final String[] DATABASE_URL_SETTING_LEAF_PATH = CommonSettings.DB_BASE_URL.replace(
147            CommonSettings.SETTINGS + ".", "").split("[.]");
148    /** The complete path to the port leaf from beyond settings. */
149    static final String[] COMPLETE_HTTP_PORT_LEAF = CommonSettings.HTTP_PORT_NUMBER.split("[.]");
150    /** The complete path to the receiver leaf from beyond settings. */
151    static final String[] SETTINGS_NOTIFICATION_RECEIVER_PATH = EMailNotifications.MAIL_RECEIVER_SETTING.split("[.]");
152    /** The path to the jmxPort leaf from beyond settings. */
153    static final String[] COMPLETE_JMX_PORT_PATH = CommonSettings.JMX_PORT.split("[.]");
154    /** The path to the rmiPort leaf from beyond settings. */
155    static final String[] COMPLETE_JMX_RMIPORT_PATH = CommonSettings.JMX_RMI_PORT.split("[.]");
156    /** The path to the heritrix guiPort from beyond settings. */
157    static final String[] COMPLETE_HARVEST_HERITRIX_GUI_PORT_PATH = HarvesterSettings.HERITRIX_GUI_PORT.split("[.]");
158    /** The path to the heritrix jmxPort from beyond settings. */
159    static final String[] COMPLETE_HARVEST_HERITRIX_JMX_PORT = HarvesterSettings.HERITRIX_JMX_PORT.split("[.]");
160    /** The path to the archive database port leaf from beyond settings. */
161    static final String[] COMPLETE_ARCHIVE_DATABASE_PORT = ArchiveSettings.PORT_ARCREPOSITORY_ADMIN_DATABASE
162            .split("[.]");
163    /** The path to the archive database port leaf from settings. */
164    static final String[] SETTINGS_ARCHIVE_DATABASE_PORT = ArchiveSettings.PORT_ARCREPOSITORY_ADMIN_DATABASE.replace(
165            CommonSettings.SETTINGS + ".", "").split("[.]");
166    /** The path to the harvest database port leaf from beyond settings. */
167    static final String[] COMPLETE_HARVEST_DATABASE_PORT = CommonSettings.DB_PORT.split("[.]");
168    /** The path to the harvest database port leaf from settings. */
169    static final String[] SETTINGS_HARVEST_DATABASE_PORT = CommonSettings.DB_PORT.replace(
170            CommonSettings.SETTINGS + ".", "").split("[.]");
171    /** The path to the heritrix jmxPort from the settings branch. */
172    static final String[] SETTINGS_HARVEST_HERITRIX_JMX_PORT = HarvesterSettings.HERITRIX_JMX_PORT.replace(
173            CommonSettings.SETTINGS + ".", "").split("[.]");
174    /** The path to the tempDir leaf from settings. */
175    static final String[] SETTINGS_TEMPDIR_LEAF = CommonSettings.DIR_COMMONTEMPDIR.replace(
176            CommonSettings.SETTINGS + ".", "").split("[.]");
177    /** The path to the fileDir branch from settings. */
178    static final String[] SETTINGS_BITARCHIVE_BASEFILEDIR_LEAF = ArchiveSettings.BITARCHIVE_SERVER_FILEDIR.replace(
179            CommonSettings.SETTINGS + ".", "").split("[.]");
180    /** The path to the serverDir leaf from settings. */
181    static final String[] SETTINGS_HARVEST_SERVERDIR_LEAF = HarvesterSettings.HARVEST_CONTROLLER_SERVERDIR.replace(
182            CommonSettings.SETTINGS + ".", "").split("[.]");
183
184    /** The path to the bundle leaf from settings. */
185    static final String[] SETTINGS_HARVEST_HERITRIX3_BUNDLE_LEAF = HarvesterSettings.HERITRIX3_BUNDLE.replace(
186            CommonSettings.SETTINGS + ".", "").split("[.]");
187    /** The path to the certificate leaf from settings. */
188    static final String[] SETTINGS_HARVEST_HERITRIX3_CERTIFICATE_LEAF = HarvesterSettings.HERITRIX3_CERTIFICATE.replace(
189            CommonSettings.SETTINGS + ".", "").split("[.]");
190
191    /**
192     * The path to the bitpreservation base dir leaf from settings. Uses the constant from ArciveSettings, with the
193     * 'settings' removed.
194     */
195    static final String[] SETTINGS_ARCHIVE_BP_BASEDIR_LEAF = ArchiveSettings.DIR_ARCREPOSITORY_BITPRESERVATION.replace(
196            CommonSettings.SETTINGS + ".", "").split("[.]");
197    /**
198     * The path to the arcrepository base dir leaf from settings. Uses the constant from ArciveSettings, with the
199     * 'settings' removed.
200     */
201    static final String[] SETTINGS_ARCHIVE_ARC_BASEDIR_LEAF = ArchiveSettings.DIRS_ARCREPOSITORY_ADMIN.replace(
202            CommonSettings.SETTINGS + ".", "").split("[.]");
203    /** The path to the viewer proxy base dir leaf from settings. */
204    static final String[] SETTINGS_VIEWERPROXY_BASEDIR_LEAF = HarvesterSettings.VIEWERPROXY_DIR.replace(
205            CommonSettings.SETTINGS + ".", "").split("[.]");
206    /** The path from monitor to the jmxUsername leaf. */
207    static final String[] SETTINGS_MONITOR_JMX_NAME_LEAF = MonitorSettings.JMX_USERNAME_SETTING.replace(
208            CommonSettings.SETTINGS + ".", "").split("[.]");
209    /** The path from monitor to the jmxPassword leaf. */
210    static final String[] SETTINGS_MONITOR_JMX_PASSWORD_LEAF = MonitorSettings.JMX_PASSWORD_SETTING.replace(
211            CommonSettings.SETTINGS + ".", "").split("[.]");
212    /** The path to the application instance id leaf from settings. */
213    static final String[] SETTINGS_APPLICATION_INSTANCE_ID_LEAF = CommonSettings.APPLICATION_INSTANCE_ID.replace(
214            CommonSettings.SETTINGS + ".", "").split("[.]");
215    /** The path to thisPhysicalLocation from settings. */
216    static final String[] COMPLETE_THIS_PHYSICAL_LOCATION_LEAF = CommonSettings.THIS_PHYSICAL_LOCATION.split("[.]");
217    /** The path to applicationName from beyond settings. */
218    static final String[] COMPLETE_APPLICATION_NAME_LEAF = CommonSettings.APPLICATION_NAME.split("[.]");
219    /** Path to the branch with the Heritrix settings. */
220    static final String[] SETTINGS_HERITRIX_BRANCH = HarvesterSettings.HERITRIX.replace(
221            COMPLETE_SETTINGS_BRANCH + ".", "").split("[.]");
222    
223    /** Path to the branch with the Heritrix3 settings. */
224    static final String[] SETTINGS_HERITRIX3_BRANCH = HarvesterSettings.HERITRIX3.replace(
225            COMPLETE_SETTINGS_BRANCH + ".", "").split("[.]");
226    
227    /** The path to the jmxUsername under heritrix from settings. */
228    static final String[] SETTINGS_HERITRIX_JMX_USERNAME_LEAF = HarvesterSettings.HERITRIX_JMX_USERNAME.replace(
229            COMPLETE_SETTINGS_BRANCH + ".", "").split("[.]");
230    /** The path to the jmxPassword under heritrix from settings. */
231    static final String[] SETTINGS_HERITRIX_JMX_PASSWORD_LEAF = HarvesterSettings.HERITRIX_JMX_PASSWORD.replace(
232            COMPLETE_SETTINGS_BRANCH + ".", "").split("[.]");
233    /** The path to the jmx accessFile leaf from settings. */
234    static final String[] SETTINGS_COMMON_JMX_ACCESSFILE = CommonSettings.JMX_ACCESS_FILE.replace(
235            COMPLETE_SETTINGS_BRANCH + ".", "").split("[.]");
236    /** The path to the jmx passwordFile leaf from settings. */
237    static final String[] SETTINGS_COMMON_JMX_PASSWORDFILE = CommonSettings.JMX_PASSWORD_FILE.replace(
238            COMPLETE_SETTINGS_BRANCH + ".", "").split("[.]");
239
240    // other constants
241    /** The amount of seconds to wait for the restart script. */
242    public static final int WAIT_TIME_DURING_RESTART = 10;
243    /** The number of milliseconds on a second. 1000. */
244    static final int TIME_SECOND_IN_MILLISECONDS = 1000;
245    /** The minimum number of arguments required. */
246    public static final int ARGUMENTS_REQUIRED = 4;
247    /** The exact number of arguments required for test. */
248    public static final int TEST_ARGUMENTS_REQUIRED = 4;
249    /** The maximum integer value in a character. */
250    public static final int TEST_OFFSET_INTEGER_MAXIMUM_VALUE = 9;
251    /** Directories to install under baseFileDir. */
252    public static final String[] BASEFILEDIR_SUBDIRECTORIES = {
253            dk.netarkivet.archive.Constants.FILE_DIRECTORY_NAME,// This works only for the default setup
254            dk.netarkivet.archive.Constants.TEMPORARY_DIRECTORY_NAME,
255            dk.netarkivet.archive.Constants.ATTIC_DIRECTORY_NAME};
256    /**
257     * The offset for the digit to replace during test in the monitor jmx port.
258     */
259    static final int TEST_OFFSET_MONITOR_JMX_PORT = 2;
260    /**
261     * The offset for the digit to replace during test in the monitor rmi port.
262     */
263    static final int TEST_OFFSET_MONITOR_RMI_PORT = 2;
264    /**
265     * The offset for the digit to replace during test in the heritrix jmx port.
266     */
267    static final int TEST_OFFSET_HERITRIX_JMX_PORT = 2;
268    /**
269     * The offset for the digit to replace during test in the heritrix gui port.
270     */
271    static final int TEST_OFFSET_HERITRIX_GUI_PORT = 2;
272    /**
273     * The offset for the digit to replace during test of the port in the archive database url.
274     */
275    static final int TEST_OFFSET_ARCHIVE_DB_URL_PORT = 2;
276    /**
277     * The offset for the digit to replace during test of the port in the harvest database url.
278     */
279    static final int TEST_OFFSET_HARVEST_DB_URL_PORT = 2;
280    /** The index of the offset part of the test argument. */
281    static final int TEST_ARGUMENT_OFFSET_INDEX = 0;
282    /** The index of the http part of the test argument. */
283    static final int TEST_ARGUMENT_HTTP_INDEX = 1;
284    /** The index of the environment name part of the test argument. */
285    static final int TEST_ARGUMENT_ENVIRONMENT_NAME_INDEX = 2;
286    /** The index of the mail part of the test argument. */
287    static final int TEST_ARGUMENT_MAIL_INDEX = 3;
288
289    // File and directory names
290    /** The name of the JMX remote password file. */
291    static final String JMX_PASSWORD_FILE_NAME = "jmxremote.password";
292    /** The name of the JMX remote access file. */
293    static final String JMX_ACCESS_FILE_NAME = "jmxremote.access";
294    /** The default path to the jmxremote.password file. */
295    static final String JMX_PASSWORD_FILE_PATH_DEFAULT = "conf/" + JMX_PASSWORD_FILE_NAME;
296    /** The default path to the jmxremote.access file. */
297    static final String JMX_ACCESS_FILE_PATH_DEFAULT = "conf/" + JMX_ACCESS_FILE_NAME;
298    /** The name of the security policy file. */
299    static final String SECURITY_POLICY_FILE_NAME = "security.policy";
300
301    /** The prefix for the SLF4J config file for the application. */
302    static final String SLF4J_CONFIG_APPLICATION_PREFIX = "logback_";
303    /** The suffix for the SLF4J config file for the application. */
304    static final String SLF4J_CONFIG_APPLICATION_SUFFIX = ".xml";
305
306    /**
307     * The directory for the harvest database in the unpacked NetarchiveSuite. The default directory for the database
308     * file.
309     */
310    static final String HARVEST_DATABASE_BASE_DIR = "harvestdefinitionbasedir";
311    /**
312     * The name of the harvest database in the directory above. The default name for the database file.
313     */
314    static final String HARVEST_DATABASE_BASE_FILE = "fullhddb.jar";
315
316    /**
317     * The path to the base harvestdatabase (the two above combined). This is the default location for the database.
318     */
319    static final String HARVEST_DATABASE_BASE_PATH = HARVEST_DATABASE_BASE_DIR + SLASH + HARVEST_DATABASE_BASE_FILE;
320    /**
321     * The name of the archive database in the database base dir above. This is the default name of the archive
322     * database.
323     */
324    static final String ARCHIVE_DATABASE_BASE_FILE = "archivedb.jar";
325
326    /**
327     * The directory which will contain the bitmag (bitrepository.org) client configuration if the -I setting was
328     * specified on the command line. All files are copied from the directory specified.
329     */
330    static final String BITMAG_CLIENT_CONFIG_DIR = "bitmag_client_config";
331
332    /**
333     * The name of the certkey file to be used for authorisation by the bitmagasin client. There must be a single .pem file
334     * in the source directory which will be copied to this file.
335     */
336    static final String BITMAG_CERTKEY_FILE = "client.pem";
337
338    public static final String ARCHIVE_DATABASE_BASE_DIR = "archivedatabasedir";
339    
340
341    /** The default logo filename */
342    public static final String DEFAULT_LOGO_FILENAME = "transparent_logo.png";
343    /** The default menulogo filename */
344    public static final String DEFAULT_MENULOGO_FILENAME = "transparent_menu_logo.png";
345
346    /** The webpages directory */
347    public static final String WEBPAGESDIR = "webpages";
348    
349    /** The war filenames in the webpages directory */
350    public static final String WARFILENAMES[] = {
351                "BitPreservation.war",
352                "HarvestDefinition.war",
353                "QA.war",
354                "HarvestChannel.war",
355                "History.war",
356                "Status.war"
357    };
358
359    /**
360     * The path to the base archive database (the one above combined with the base database dir). This is the default
361     * location for the archive database.
362     */
363    static final String ARCHIVE_DATABASE_BASE_PATH = ARCHIVE_DATABASE_BASE_DIR + SLASH + ARCHIVE_DATABASE_BASE_FILE;
364    /** The name of the new modified configuration file for tests. */
365    static final String TEST_CONFIG_FILE_REPLACE_ENDING = "_test.xml";
366    /** The script extension for Linux/Unix. */
367    static final String SCRIPT_EXTENSION_LINUX = ".sh";
368    /** The script extension for Windows. */
369    static final String SCRIPT_EXTENSION_WINDOWS = ".bat";
370    /** The name of the killall script. 'killall'. */
371    static final String SCRIPT_NAME_KILL_ALL = "killall";
372    /** The name of the install script. 'install'. */
373    static final String SCRIPT_NAME_INSTALL_ALL = "install";
374    /** The name of the startall script. 'startall'. */
375    static final String SCRIPT_NAME_START_ALL = "startall";
376    /** The name of the restart all application script. 'restart'. */
377    static final String SCRIPT_NAME_RESTART = "restart";
378    /** The name of the admin database start script. */
379    static final String SCRIPT_NAME_ADMIN_DB_START = "start_external_admin_database";
380    /** The name of the admin database kill script. */
381    static final String SCRIPT_NAME_ADMIN_DB_KILL = "kill_external_admin_database";
382    /** The name of the harvest database start script. */
383    static final String SCRIPT_NAME_HARVEST_DB_START = "start_external_harvest_database";
384    /** The name of the harvest database kill script. */
385    static final String SCRIPT_NAME_HARVEST_DB_KILL = "kill_external_harvest_database";
386    /** The name of the harvest database update script. */
387    static final String SCRIPT_NAME_HARVEST_DB_UPDATE = "update_external_harvest_database";;
388    /** The name of the wait script for windows. 'wait'. */
389    static final String SCRIPT_NAME_WAIT = "wait";
390    /** Prefix for the application kill script. 'kill_' . */
391    static final String SCRIPT_NAME_LOCAL_KILL = "kill_";
392    /** Prefix for the application start script. 'start_' . */
393    static final String SCRIPT_NAME_LOCAL_START = "start_";
394    /** Prefix for the application kill_ps script. 'kill_ps_' */
395    static final String SCRIPT_KILL_PS = "kill_ps_";
396    /** The prefix of the name for application specific settings files. */
397    static final String PREFIX_SETTINGS = "settings_";
398    /** The extension on XML files. */
399    static final String EXTENSION_XML_FILES = ".xml";
400    /** The extension on zip files. */
401    static final String EXTENSION_ZIP_FILES = ".zip";
402    /** The extension on policy files. */
403    static final String EXTENSION_POLICY_FILES = ".policy";
404    /** The extension on jar files. */
405    static final String EXTENSION_JAR_FILES = ".jar";
406    /** The extension on vb-script files. */
407    static final String EXTENSION_VBS_FILES = ".vbs";
408    /** The extension on log files. */
409    static final String EXTENSION_LOG_FILES = ".log";
410    /** The windows config directory path from install directory. */
411    static final String CONF_DIR_WINDOWS = "\\conf\\";
412    /** The Linux config directory path from install directory. */
413    static final String CONF_DIR_LINUX = "/conf/";
414    /** The Linux lib directory relative to the install directory. */
415    static final String LIB_DIR_LINUX = "/lib";
416    /** The windows lib directory relative to the install directory. */
417    static final String LIB_DIR_WINDOWS = "\\lib";
418
419    /** Settings prefix. settings_. */
420    static final String SETTINGS_PREFIX = "settings_";
421    /** Log property prefix. log_. */
422    static final String LOG_PREFIX = "log_";
423    /** Logback config prefix. logback_. */
424    static final String LOGBACK_PREFIX = "logback_";
425    /** Windows directory creation script prefix. */
426    static final String WINDOWS_DIR_CREATE_PREFIX = "dir_";
427
428    // evaluate specific constants
429    /** Complete list of settings files to combine to complete settings file. */
430    static final String[] BUILD_SETTING_FILES = {
431            "dk/netarkivet/archive/settings.xml",
432            "dk/netarkivet/common/settings.xml",
433            "dk/netarkivet/common/distribute/arcrepository/LocalArcRepositoryClientSettings.xml",
434            "dk/netarkivet/harvester/settings.xml", "dk/netarkivet/monitor/settings.xml",
435            "dk/netarkivet/wayback/settings.xml",
436            "dk/netarkivet/archive/arcrepository/distribute/JMSArcRepositoryClientSettings.xml",
437            "dk/netarkivet/harvester/indexserver/distribute/IndexRequestClientSettings.xml",
438            "dk/netarkivet/common/utils/EMailNotificationsSettings.xml",
439            "dk/netarkivet/common/utils/FilebasedFreeSpaceProviderSettings.xml",
440            "dk/netarkivet/common/distribute/FTPRemoteFileSettings.xml",
441            "dk/netarkivet/common/distribute/HTTPRemoteFileSettings.xml",
442            "dk/netarkivet/common/distribute/HTTPSRemoteFileSettings.xml",
443            "dk/netarkivet/common/distribute/JMSConnectionSunMQSettings.xml"};
444    /** The path to the complete settings file. */
445    public static final String BUILD_COMPLETE_SETTINGS_FILE_PATH = "dk/netarkivet/deploy/complete_settings.xml";
446    /** The name of the temporary run-file for windows. */
447    public static final String FILE_TEMPORARY_RUN_WINDOWS_NAME = "running_";
448
449    // argument parameters as constants.
450    /** For initiating a argument. */
451    public static final String ARG_INIT_ARG = "-";
452    /** For giving the configuration file as argument. */
453    public static final String ARG_CONFIG_FILE = "C";
454    /** For giving the NetarchiveSuite package file as argument. */
455    public static final String ARG_NETARCHIVE_SUITE_FILE = "Z";
456    /** For giving the security file as argument. */
457    public static final String ARG_SECURITY_FILE = "S";
458    /** For giving the SLF4J xml file as argument. */
459    public static final String ARG_SLF4J_CONFIG_FILE = "L";
460    /** For giving the optional output directory as argument. */
461    public static final String ARG_OUTPUT_DIRECTORY = "O";
462    /** For giving the optional database file as argument. */
463    public static final String ARG_DATABASE_FILE = "D";
464    /** For giving the optional test data. */
465    public static final String ARG_TEST = "T";
466    /** For giving the optional reset directory argument. */
467    public static final String ARG_RESET = "R";
468    /** For giving the optional evaluation argument. */
469    public static final String ARG_EVALUATE = "E";
470    /** For giving the optional archive database argument. */
471    public static final String ARG_ARC_DB = "A";
472    /** For installing external libraries through deploy. */
473    public static final String ARG_JAR_FOLDER = "J";
474    /** Optional definition of a default Heritrix3 bundler zip file. */
475    public static final String ARG_DEFAULT_BUNDLER_ZIP = "B";
476    /** Optional definition of a bitmagasin source directory. */
477    public static final String ARG_BITMAG_SOURCE_DIR = "I";
478    /** Optional definition of a default Heritrix3 bundler zip file. */
479    public static final String ARG_DEFAULT_HERITRIX3_CERTIFICATE = "H";
480    /** Encoding to use for source files. */
481    public static final String ARG_SOURCE_ENCODING = "sourceEncoding";
482    /** Optional definition of a Logo png file. */
483    public static final String ARG_LOGO = "l";
484    /** Optional definition of a Menulogo png file. */
485    public static final String ARG_MENULOGO = "m";
486
487    // Argument values
488    /** The long yes argument. */
489    public static final String YES_LONG = "yes";
490    /** The short yes argument. */
491    public static final String YES_SHORT = "y";
492    /** The long no argument. */
493    public static final String NO_LONG = "no";
494    /** The short no argument. */
495    public static final String NO_SHORT = "n";
496
497    // Other string constants
498    /** Regular expression for finding the '.' character. */
499    public static final String REGEX_DOT_CHARACTER = "[.]";
500    /** Regular expression for finding the ',' character. */
501    public static final String REGEX_COMMA_CHARACTER = "[,]";
502    /** Regular expression for finding the '/' character. */
503    public static final String REGEX_SLASH_CHARACTER = "[/]";
504    /** Regular expression for finding the '/' character. */
505    public static final String REGEX_BACKSLASH_CHARACTER = "[\\\\]";
506    /** Argument. */
507    public static final String INIT_ARGUMENTS_LIST = "Arguments:";
508
509    /** The regular expression for validating the environment name. */
510    public static final String VALID_REGEX_ENVIRONMENT_NAME = "[a-zA-Z0-9]*";
511    /** The folder for the external jar-files to be copied into. */
512    public static final String EXTERNAL_JAR_DIRECTORY = "external";
513
514    // messages
515    /** The error message for error in parsing the arguments. */
516    public static final String MSG_ERROR_PARSE_ARGUMENTS = "WARNING: wrong arguments given.\n";
517    /** The error message when too many arguments are given. */
518    public static final String MSG_ERROR_TOO_MANY_ARGUMENTS = "Too many arguments given.\n";
519    /** The error message when not enough arguments are given. */
520    public static final String MSG_ERROR_NOT_ENOUGH_ARGUMENTS = "Not enough arguments given.\n";
521    /** The error message when no deploy-config file is given. */
522    public static final String MSG_ERROR_NO_CONFIG_FILE_ARG = "No config file argument: -C (Must end with '.xml').\n";
523    /** The error message when no NetarchiveSuite file is given. */
524    public static final String MSG_ERROR_NO_NETARCHIVESUITE_FILE_ARG = "No NetarchiveSuite file argument: -Z (Must end with '.zip').\n";
525    /** The error message when no security file is given. */
526    public static final String MSG_ERROR_NO_SECURITY_FILE_ARG = "No security file argument: -S (Must end with '.policy').\n";
527    /** The error message when no slf4j log property file is given. */
528    public static final String MSG_ERROR_NO_SLF4J_CONFIG_FILE_ARG = "No SLF4J configuration file argument: -L (Must end with '.xml').\n";
529    /** The error message when config file does not exist. */
530    public static final String MSG_ERROR_NO_CONFIG_FILE_FOUND = "Reference to non-existing config file (-C argument).";
531    /** The error message when NetarchiveSuite file does not exist. */
532    public static final String MSG_ERROR_NO_NETARCHIVESUITE_FILE_FOUND = "Reference to non-existing NetarchiveSuite file (-Z argument).";
533    /** The error message when security file does not exist. */
534    public static final String MSG_ERROR_NO_SECURITY_FILE_FOUND = "Reference to non-existing security file (-S argument).";
535   /** The error message when SLF4J config file does not exist. */
536    public static final String MSG_ERROR_NO_SLF4J_CONFIG_FILE_FOUND = "Reference to non-existing SLF4J config file (-L argument).";
537    /** The error message when database file does not exist. */
538    public static final String MSG_ERROR_NO_DATABASE_FILE_FOUND = "Reference to non-existing database file (-D argument).";
539    /** The error message when archive database file does not exist. */
540    public static final String MSG_ERROR_NO_BPDB_FILE_FOUND = "Reference to non-existing archive database file "
541            + "(-D argument).";
542    /**
543     * The error message when the folder with the external jar-library-files does not exist.
544     */
545    public static final String MSG_ERROR_NO_JAR_FOLDER = "Reference to non-existing external jar-folder.";
546    public static final String MSG_ERROR_NO_BUNDLER_ZIP_FILE = "Reference to non-existing bundler zip file.";
547    public static final String MSG_ERROR_NO_HERITRIX3_CERTIFICATE_FILE = "Reference to non-existing heritrix3 "
548            + "certificate file.";
549    /** The error message for missing bitmagasin source directory. */
550    public static final String MSG_ERROR_NO_BITMAG_FOLDER = "Reference to non-existing bitmagasin source directory.";
551    /** The error message for wrong deploy-config file extension. */
552    public static final String MSG_ERROR_CONFIG_EXTENSION = "Config file must be '.xml'!.\n";
553    /** The error message for wrong NetarchiveSuite file extension. */
554    public static final String MSG_ERROR_NETARCHIVESUITE_EXTENSION = "NetarchiveSuite file must be '.zip'.\n";
555    /** The error message for wrong security file extension. */
556    public static final String MSG_ERROR_SECURITY_EXTENSION = "Security policy file must be '.policy'.\n";
557   /** The error message for wrong SLF4J config file extension. */
558    public static final String MSG_ERROR_SLF4J_CONFIG_EXTENSION = "SLF4J config file must be '.xml'.\n";
559    /** The error message for wrong database extension. */
560    public static final String MSG_ERROR_DATABASE_EXTENSION = "Database file must have extension '.jar' or '.zip'";
561    /** The error message for wrong archive database extension. */
562    public static final String MSG_ERROR_BPDB_EXTENSION = "Archive database file must have extension '.jar' or '.zip'";
563    /** The error message when test wrong number of test arguments. */
564    public static final String MSG_ERROR_TEST_ARGUMENTS = "There have to be " + TEST_ARGUMENTS_REQUIRED
565            + " test arguments.";
566    /** The error message when offset value are too different from httpport. */
567    public static final String MSG_ERROR_TEST_OFFSET = "Difference between Offset and http not between 0 and 10, as required.";
568    /** The error message when reset directory has wrong argument. */
569    public static final String MSG_ERROR_RESET_ARGUMENT = "Wrong argument for resetting the directory.";
570    /** The error message when a physical location has no name attribute. */
571    public static final String MSG_ERROR_PHYSICAL_LOCATION_NO_NAME = "A Physical Location has no name!";
572    /** The error message when IOException during cannocial path of zip file. */
573    public static final String MSG_ERROR_ZIP_CANNONICAL_PATH = "The cannonical path of the NetarchiveSuite zip file is invalid.";
574    /**
575     * The error message when the environment name for the test instance is invalid.
576     */
577    public static final String MSG_ERROR_INVALID_TEST_ENVIRONMENT_NAME = "The environment name for the test instance was not valid to the "
578            + "regular expressions: '" + VALID_REGEX_ENVIRONMENT_NAME + "'. " + "But was given: ";
579    /** The error message when the environment name is invalid. */
580    public static final String MSG_ERROR_INVALID_ENVIRONMENT_NAME = "The environment name must be valid to the regular expression: '"
581            + VALID_REGEX_ENVIRONMENT_NAME + "'. But the given was: ";
582    /** The error message when the wait script file cannot be written. */
583    public static final String MSG_ERROR_WAIT_FILE = "Problems creating local wait script.";
584    /** The error message when the restart script cannot be written. */
585    public static final String MSG_ERROR_RESTART_FILE = "Problems creating local restart script.";
586    /** The error message when the db-start script cannot be written. */
587    public static final String MSG_ERROR_DB_START_FILE = "Problems creating the local external_database_start script.";
588    /** The error message when the db-kill script cannot be written. */
589    public static final String MSG_ERROR_DB_KILL_FILE = "Problems creating the local external_database_kill script.";
590    /**
591     * The warning when more than one jmxremote.access or jmxremote.password file path is defined.
592     */
593    public static final String MSG_WARN_TOO_MANY_JMXREMOTE_FILE_PATHS = "Too many instances of jmxremote.password or jmxremote.access files defined.";
594    /**
595     * The warning when the NetarchiveSuite file will be overridden, since another file with same name exists.
596     */
597    public static final String MSG_WARN_ZIPFILE_ALREADY_EXISTS = "Warning: A NetarchiveSuite file already exists. It will be overridden. ";
598    public static final String REPOSITORY_SETTINGS_XML = "RepositorySettings.xml";
599    public static final String PEM = ".pem";
600    public static final String HARVEST_CONTROLLER_APPLICATION = "HarvestControllerApplication";
601
602    /**
603     * Private constructor to avoid instantiation.
604     */
605    private Constants() {
606    }
607
608    /**
609     * Create the beginning of a scope in XML (e.g. html = \< html \>).
610     *
611     * @param scope The name of the XML-scope to have the start created.
612     * @return The beginning of the XML-scope.
613     * @throws ArgumentNotValid If the scope is null or empty.
614     */
615    public static String changeToXMLBeginScope(String scope) throws ArgumentNotValid {
616        ArgumentNotValid.checkNotNullOrEmpty(scope, "String scope");
617        return LESS_THAN + scope + GREATER_THAN;
618    }
619
620    /**
621     * Create the ending of a scope in XML (e.g. html = \< \html \>).
622     *
623     * @param scope The name of the XML-scope to have the end created.
624     * @return The ending of the XML-scope.
625     * @throws ArgumentNotValid If the scope is null or empty.
626     */
627    public static String changeToXMLEndScope(String scope) throws ArgumentNotValid {
628        ArgumentNotValid.checkNotNullOrEmpty(scope, "String scope");
629        return LESS_THAN + SLASH + scope + GREATER_THAN;
630    }
631
632    /**
633     * Checks whether a string is valid for environment name. The string is checked against a regular expression.
634     *
635     * @param name The environment name to validate.
636     * @return Whether the environment name is valid.
637     * @throws ArgumentNotValid If the name is null or empty.
638     */
639    public static boolean validEnvironmentName(String name) throws ArgumentNotValid {
640        ArgumentNotValid.checkNotNullOrEmpty(name, "String name");
641        return Pattern.matches(VALID_REGEX_ENVIRONMENT_NAME, name);
642    }
643
644}