001/*
002 * #%L
003 * Netarchivesuite - deploy
004 * %%
005 * Copyright (C) 2005 - 2014 The Royal Danish Library, the Danish State and University 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    /** The path to the jmxUsername under heritrix from settings. */
223    static final String[] SETTINGS_HERITRIX_JMX_USERNAME_LEAF = HarvesterSettings.HERITRIX_JMX_USERNAME.replace(
224            COMPLETE_SETTINGS_BRANCH + ".", "").split("[.]");
225    /** The path to the jmxPassword under heritrix from settings. */
226    static final String[] SETTINGS_HERITRIX_JMX_PASSWORD_LEAF = HarvesterSettings.HERITRIX_JMX_PASSWORD.replace(
227            COMPLETE_SETTINGS_BRANCH + ".", "").split("[.]");
228    /** The path to the jmx accessFile leaf from settings. */
229    static final String[] SETTINGS_COMMON_JMX_ACCESSFILE = CommonSettings.JMX_ACCESS_FILE.replace(
230            COMPLETE_SETTINGS_BRANCH + ".", "").split("[.]");
231    /** The path to the jmx passwordFile leaf from settings. */
232    static final String[] SETTINGS_COMMON_JMX_PASSWORDFILE = CommonSettings.JMX_PASSWORD_FILE.replace(
233            COMPLETE_SETTINGS_BRANCH + ".", "").split("[.]");
234
235    // other constants
236    /** The amount of seconds to wait for the restart script. */
237    public static final int WAIT_TIME_DURING_RESTART = 10;
238    /** The number of milliseconds on a second. 1000. */
239    static final int TIME_SECOND_IN_MILLISECONDS = 1000;
240    /** The minimum number of arguments required. */
241    public static final int ARGUMENTS_REQUIRED = 4;
242    /** The exact number of arguments required for test. */
243    public static final int TEST_ARGUMENTS_REQUIRED = 4;
244    /** The maximum integer value in a character. */
245    public static final int TEST_OFFSET_INTEGER_MAXIMUM_VALUE = 9;
246    /** Directories to install under baseFileDir. */
247    public static final String[] BASEFILEDIR_SUBDIRECTORIES = {dk.netarkivet.archive.Constants.FILE_DIRECTORY_NAME,
248            dk.netarkivet.archive.Constants.TEMPORARY_DIRECTORY_NAME,
249            dk.netarkivet.archive.Constants.ATTIC_DIRECTORY_NAME};
250    /**
251     * The offset for the digit to replace during test in the monitor jmx port.
252     */
253    static final int TEST_OFFSET_MONITOR_JMX_PORT = 2;
254    /**
255     * The offset for the digit to replace during test in the monitor rmi port.
256     */
257    static final int TEST_OFFSET_MONITOR_RMI_PORT = 2;
258    /**
259     * The offset for the digit to replace during test in the heritrix jmx port.
260     */
261    static final int TEST_OFFSET_HERITRIX_JMX_PORT = 2;
262    /**
263     * The offset for the digit to replace during test in the heritrix gui port.
264     */
265    static final int TEST_OFFSET_HERITRIX_GUI_PORT = 2;
266    /**
267     * The offset for the digit to replace during test of the port in the archive database url.
268     */
269    static final int TEST_OFFSET_ARCHIVE_DB_URL_PORT = 2;
270    /**
271     * The offset for the digit to replace during test of the port in the harvest database url.
272     */
273    static final int TEST_OFFSET_HARVEST_DB_URL_PORT = 2;
274    /** The index of the offset part of the test argument. */
275    static final int TEST_ARGUMENT_OFFSET_INDEX = 0;
276    /** The index of the http part of the test argument. */
277    static final int TEST_ARGUMENT_HTTP_INDEX = 1;
278    /** The index of the environment name part of the test argument. */
279    static final int TEST_ARGUMENT_ENVIRONMENT_NAME_INDEX = 2;
280    /** The index of the mail part of the test argument. */
281    static final int TEST_ARGUMENT_MAIL_INDEX = 3;
282
283    // File and directory names
284    /** The name of the JMX remote password file. */
285    static final String JMX_PASSWORD_FILE_NAME = "jmxremote.password";
286    /** The name of the JMX remote access file. */
287    static final String JMX_ACCESS_FILE_NAME = "jmxremote.access";
288    /** The default path to the jmxremote.password file. */
289    static final String JMX_PASSWORD_FILE_PATH_DEFAULT = "conf/" + JMX_PASSWORD_FILE_NAME;
290    /** The default path to the jmxremote.access file. */
291    static final String JMX_ACCESS_FILE_PATH_DEFAULT = "conf/" + JMX_ACCESS_FILE_NAME;
292    /** The name of the security policy file. */
293    static final String SECURITY_POLICY_FILE_NAME = "security.policy";
294
295    /** The prefix for the SLF4J config file for the application. */
296    static final String SLF4J_CONFIG_APPLICATION_PREFIX = "logback_";
297    /** The suffix for the SLF4J config file for the application. */
298    static final String SLF4J_CONFIG_APPLICATION_SUFFIX = ".xml";
299
300    /**
301     * The directory for the harvest database in the unpacked NetarchiveSuite. The default directory for the database
302     * file.
303     */
304    static final String HARVEST_DATABASE_BASE_DIR = "harvestdefinitionbasedir";
305    /**
306     * The name of the harvest database in the directory above. The default name for the database file.
307     */
308    static final String HARVEST_DATABASE_BASE_FILE = "fullhddb.jar";
309
310    /**
311     * The path to the base harvestdatabase (the two above combined). This is the default location for the database.
312     */
313    static final String HARVEST_DATABASE_BASE_PATH = HARVEST_DATABASE_BASE_DIR + SLASH + HARVEST_DATABASE_BASE_FILE;
314    /**
315     * The name of the archive database in the database base dir above. This is the default name of the archive
316     * database.
317     */
318    static final String ARCHIVE_DATABASE_BASE_FILE = "archivedb.jar";
319
320    public static final String ARCHIVE_DATABASE_BASE_DIR = "archivedatabasedir";
321
322    /**
323     * The path to the base archive database (the one above combined with the base database dir). This is the default
324     * location for the archive database.
325     */
326    static final String ARCHIVE_DATABASE_BASE_PATH = ARCHIVE_DATABASE_BASE_DIR + SLASH + ARCHIVE_DATABASE_BASE_FILE;
327    /** The name of the new modified configuration file for tests. */
328    static final String TEST_CONFIG_FILE_REPLACE_ENDING = "_test.xml";
329    /** The script extension for Linux/Unix. */
330    static final String SCRIPT_EXTENSION_LINUX = ".sh";
331    /** The script extension for Windows. */
332    static final String SCRIPT_EXTENSION_WINDOWS = ".bat";
333    /** The name of the killall script. 'killall'. */
334    static final String SCRIPT_NAME_KILL_ALL = "killall";
335    /** The name of the install script. 'install'. */
336    static final String SCRIPT_NAME_INSTALL_ALL = "install";
337    /** The name of the startall script. 'startall'. */
338    static final String SCRIPT_NAME_START_ALL = "startall";
339    /** The name of the restart all application script. 'restart'. */
340    static final String SCRIPT_NAME_RESTART = "restart";
341    /** The name of the admin database start script. */
342    static final String SCRIPT_NAME_ADMIN_DB_START = "start_external_admin_database";
343    /** The name of the admin database kill script. */
344    static final String SCRIPT_NAME_ADMIN_DB_KILL = "kill_external_admin_database";
345    /** The name of the harvest database start script. */
346    static final String SCRIPT_NAME_HARVEST_DB_START = "start_external_harvest_database";
347    /** The name of the harvest database kill script. */
348    static final String SCRIPT_NAME_HARVEST_DB_KILL = "kill_external_harvest_database";
349    /** The name of the harvest database update script. */
350    static final String SCRIPT_NAME_HARVEST_DB_UPDATE = "update_external_harvest_database";;
351    /** The name of the wait script for windows. 'wait'. */
352    static final String SCRIPT_NAME_WAIT = "wait";
353    /** Prefix for the application kill script. 'kill_' . */
354    static final String SCRIPT_NAME_LOCAL_KILL = "kill_";
355    /** Prefix for the application start script. 'start_' . */
356    static final String SCRIPT_NAME_LOCAL_START = "start_";
357    /** Prefix for the application kill_ps script. 'kill_ps_' */
358    static final String SCRIPT_KILL_PS = "kill_ps_";
359    /** The prefix of the name for application specific settings files. */
360    static final String PREFIX_SETTINGS = "settings_";
361    /** The extension on XML files. */
362    static final String EXTENSION_XML_FILES = ".xml";
363    /** The extension on zip files. */
364    static final String EXTENSION_ZIP_FILES = ".zip";
365    /** The extension on policy files. */
366    static final String EXTENSION_POLICY_FILES = ".policy";
367    /** The extension on jar files. */
368    static final String EXTENSION_JAR_FILES = ".jar";
369    /** The extension on vb-script files. */
370    static final String EXTENSION_VBS_FILES = ".vbs";
371    /** The extension on log files. */
372    static final String EXTENSION_LOG_FILES = ".log";
373    /** The windows config directory path from install directory. */
374    static final String CONF_DIR_WINDOWS = "\\conf\\";
375    /** The Linux config directory path from install directory. */
376    static final String CONF_DIR_LINUX = "/conf/";
377    /** The Linux lib directory relative to the install directory. */
378    static final String LIB_DIR_LINUX = "/lib";
379    /** The windows lib directory relative to the install directory. */
380    static final String LIB_DIR_WINDOWS = "\\lib";
381
382    /** Settings prefix. settings_. */
383    static final String SETTINGS_PREFIX = "settings_";
384    /** Log property prefix. log_. */
385    static final String LOG_PREFIX = "log_";
386    /** Logback config prefix. logback_. */
387    static final String LOGBACK_PREFIX = "logback_";
388    /** Windows directory creation script prefix. */
389    static final String WINDOWS_DIR_CREATE_PREFIX = "dir_";
390
391    // evaluate specific constants
392    /** Complete list of settings files to combine to complete settings file. */
393    static final String[] BUILD_SETTING_FILES = {
394            "dk/netarkivet/archive/settings.xml",
395            "dk/netarkivet/common/settings.xml",
396            "dk/netarkivet/common/distribute/arcrepository/LocalArcRepositoryClientSettings.xml",
397            "dk/netarkivet/harvester/settings.xml", "dk/netarkivet/monitor/settings.xml",
398            "dk/netarkivet/wayback/settings.xml",
399            "dk/netarkivet/archive/arcrepository/distribute/JMSArcRepositoryClientSettings.xml",
400            "dk/netarkivet/harvester/indexserver/distribute/IndexRequestClientSettings.xml",
401            "dk/netarkivet/common/utils/EMailNotificationsSettings.xml",
402            "dk/netarkivet/common/utils/FilebasedFreeSpaceProviderSettings.xml",
403            "dk/netarkivet/common/distribute/FTPRemoteFileSettings.xml",
404            "dk/netarkivet/common/distribute/HTTPRemoteFileSettings.xml",
405            "dk/netarkivet/common/distribute/HTTPSRemoteFileSettings.xml",
406            "dk/netarkivet/common/distribute/JMSConnectionSunMQSettings.xml"};
407    /** The path to the complete settings file. */
408    public static final String BUILD_COMPLETE_SETTINGS_FILE_PATH = "dk/netarkivet/deploy/complete_settings.xml";
409    /** The name of the temporary run-file for windows. */
410    public static final String FILE_TEMPORARY_RUN_WINDOWS_NAME = "running_";
411
412    // argument parameters as constants.
413    /** For initiating a argument. */
414    public static final String ARG_INIT_ARG = "-";
415    /** For giving the configuration file as argument. */
416    public static final String ARG_CONFIG_FILE = "C";
417    /** For giving the NetarchiveSuite package file as argument. */
418    public static final String ARG_NETARCHIVE_SUITE_FILE = "Z";
419    /** For giving the security file as argument. */
420    public static final String ARG_SECURITY_FILE = "S";
421    /** For giving the SLF4J xml file as argument. */
422    public static final String ARG_SLF4J_CONFIG_FILE = "L";
423    /** For giving the optional output directory as argument. */
424    public static final String ARG_OUTPUT_DIRECTORY = "O";
425    /** For giving the optional database file as argument. */
426    public static final String ARG_DATABASE_FILE = "D";
427    /** For giving the optional test data. */
428    public static final String ARG_TEST = "T";
429    /** For giving the optional reset directory argument. */
430    public static final String ARG_RESET = "R";
431    /** For giving the optional evaluation argument. */
432    public static final String ARG_EVALUATE = "E";
433    /** For giving the optional archive database argument. */
434    public static final String ARG_ARC_DB = "A";
435    /** For installing external libraries through deploy. */
436    public static final String ARG_JAR_FOLDER = "J";
437    /** Optional definition of a default Heritrix3 bundler zip file. */
438    public static final String ARG_DEFAULT_BUNDLER_ZIP = "B";
439    /** Optional definition of a default Heritrix3 bundler zip file. */
440    public static final String ARG_DEFAULT_HERITRIX3_CERTIFICATE = "H";
441    /** Encoding to use for source files. */
442    public static final String ARG_SOURCE_ENCODING = "sourceEncoding";
443
444    // Argument values
445    /** The long yes argument. */
446    public static final String YES_LONG = "yes";
447    /** The short yes argument. */
448    public static final String YES_SHORT = "y";
449    /** The long no argument. */
450    public static final String NO_LONG = "no";
451    /** The short no argument. */
452    public static final String NO_SHORT = "n";
453
454    // Other string constants
455    /** Regular expression for finding the '.' character. */
456    public static final String REGEX_DOT_CHARACTER = "[.]";
457    /** Regular expression for finding the ',' character. */
458    public static final String REGEX_COMMA_CHARACTER = "[,]";
459    /** Regular expression for finding the '/' character. */
460    public static final String REGEX_SLASH_CHARACTER = "[/]";
461    /** Regular expression for finding the '/' character. */
462    public static final String REGEX_BACKSLASH_CHARACTER = "[\\\\]";
463    /** Argument. */
464    public static final String INIT_ARGUMENTS_LIST = "Arguments:";
465
466    /** The regular expression for validating the environment name. */
467    public static final String VALID_REGEX_ENVIRONMENT_NAME = "[a-zA-Z0-9]*";
468    /** The folder for the external jar-files to be copied into. */
469    public static final String EXTERNAL_JAR_DIRECTORY = "external";
470
471    // messages
472    /** The error message for error in parsing the arguments. */
473    public static final String MSG_ERROR_PARSE_ARGUMENTS = "WARNING: wrong arguments given.\n";
474    /** The error message when too many arguments are given. */
475    public static final String MSG_ERROR_TOO_MANY_ARGUMENTS = "Too many arguments given.\n";
476    /** The error message when not enough arguments are given. */
477    public static final String MSG_ERROR_NOT_ENOUGH_ARGUMENTS = "Not enough arguments given.\n";
478    /** The error message when no deploy-config file is given. */
479    public static final String MSG_ERROR_NO_CONFIG_FILE_ARG = "No config file argument: -C (Must end with '.xml').\n";
480    /** The error message when no NetarchiveSuite file is given. */
481    public static final String MSG_ERROR_NO_NETARCHIVESUITE_FILE_ARG = "No NetarchiveSuite file argument: -Z (Must end with '.zip').\n";
482    /** The error message when no security file is given. */
483    public static final String MSG_ERROR_NO_SECURITY_FILE_ARG = "No security file argument: -S (Must end with '.policy').\n";
484    /** The error message when no slf4j log property file is given. */
485    public static final String MSG_ERROR_NO_SLF4J_CONFIG_FILE_ARG = "No SLF4J configuration file argument: -B (Must end with '.xml').\n";
486    /** The error message when config file does not exist. */
487    public static final String MSG_ERROR_NO_CONFIG_FILE_FOUND = "Reference to non-existing config file (-C argument).";
488    /** The error message when NetarchiveSuite file does not exist. */
489    public static final String MSG_ERROR_NO_NETARCHIVESUITE_FILE_FOUND = "Reference to non-existing NetarchiveSuite file (-Z argument).";
490    /** The error message when security file does not exist. */
491    public static final String MSG_ERROR_NO_SECURITY_FILE_FOUND = "Reference to non-existing security file (-S argument).";
492   /** The error message when SLF4J config file does not exist. */
493    public static final String MSG_ERROR_NO_SLF4J_CONFIG_FILE_FOUND = "Reference to non-existing SLF4J config file (-B argument).";
494    /** The error message when database file does not exist. */
495    public static final String MSG_ERROR_NO_DATABASE_FILE_FOUND = "Reference to non-existing database file (-D argument).";
496    /** The error message when archive database file does not exist. */
497    public static final String MSG_ERROR_NO_BPDB_FILE_FOUND = "Reference to non-existing archive database file "
498            + "(-D argument).";
499    /**
500     * The error message when the folder with the external jar-library-files does not exist.
501     */
502    public static final String MSG_ERROR_NO_JAR_FOLDER = "Reference to non-existing external jar-folder.";
503    public static final String MSG_ERROR_NO_BUNDLER_ZIP_FILE = "Reference to non-existing bundler zip file.";
504    public static final String MSG_ERROR_NO_HERITRIX3_CERTIFICATE_FILE = "Reference to non-existing heritrix3 "
505            + "certificate file.";
506    /** The error message for wrong deploy-config file extension. */
507    public static final String MSG_ERROR_CONFIG_EXTENSION = "Config file must be '.xml'!.\n";
508    /** The error message for wrong NetarchiveSuite file extension. */
509    public static final String MSG_ERROR_NETARCHIVESUITE_EXTENSION = "NetarchiveSuite file must be '.zip'.\n";
510    /** The error message for wrong security file extension. */
511    public static final String MSG_ERROR_SECURITY_EXTENSION = "Security policy file must be '.policy'.\n";
512   /** The error message for wrong SLF4J config file extension. */
513    public static final String MSG_ERROR_SLF4J_CONFIG_EXTENSION = "SLF4J config file must be '.xml'.\n";
514    /** The error message for wrong database extension. */
515    public static final String MSG_ERROR_DATABASE_EXTENSION = "Database file must have extension '.jar' or '.zip'";
516    /** The error message for wrong archive database extension. */
517    public static final String MSG_ERROR_BPDB_EXTENSION = "Archive database file must have extension '.jar' or '.zip'";
518    /** The error message when test wrong number of test arguments. */
519    public static final String MSG_ERROR_TEST_ARGUMENTS = "There have to be " + TEST_ARGUMENTS_REQUIRED
520            + " test arguments.";
521    /** The error message when offset value are too different from httpport. */
522    public static final String MSG_ERROR_TEST_OFFSET = "Difference between Offset and http not between 0 and 10, as required.";
523    /** The error message when reset directory has wrong argument. */
524    public static final String MSG_ERROR_RESET_ARGUMENT = "Wrong argument for resetting the directory.";
525    /** The error message when a physical location has no name attribute. */
526    public static final String MSG_ERROR_PHYSICAL_LOCATION_NO_NAME = "A Physical Location has no name!";
527    /** The error message when IOException during cannocial path of zip file. */
528    public static final String MSG_ERROR_ZIP_CANNONICAL_PATH = "The cannonical path of the NetarchiveSuite zip file is invalid.";
529    /**
530     * The error message when the environment name for the test instance is invalid.
531     */
532    public static final String MSG_ERROR_INVALID_TEST_ENVIRONMENT_NAME = "The environment name for the test instance was not valid to the "
533            + "regular expressions: '" + VALID_REGEX_ENVIRONMENT_NAME + "'. " + "But was given: ";
534    /** The error message when the environment name is invalid. */
535    public static final String MSG_ERROR_INVALID_ENVIRONMENT_NAME = "The environment name must be valid to the regular expression: '"
536            + VALID_REGEX_ENVIRONMENT_NAME + "'. But the given was: ";
537    /** The error message when the wait script file cannot be written. */
538    public static final String MSG_ERROR_WAIT_FILE = "Problems creating local wait script.";
539    /** The error message when the restart script cannot be written. */
540    public static final String MSG_ERROR_RESTART_FILE = "Problems creating local restart script.";
541    /** The error message when the db-start script cannot be written. */
542    public static final String MSG_ERROR_DB_START_FILE = "Problems creating the local external_database_start script.";
543    /** The error message when the db-kill script cannot be written. */
544    public static final String MSG_ERROR_DB_KILL_FILE = "Problems creating the local external_database_kill script.";
545    /**
546     * The warning when more than one jmxremote.access or jmxremote.password file path is defined.
547     */
548    public static final String MSG_WARN_TOO_MANY_JMXREMOTE_FILE_PATHS = "Too many instances of jmxremote.password or jmxremote.access files defined.";
549    /**
550     * The warning when the NetarchiveSuite file will be overridden, since another file with same name exists.
551     */
552    public static final String MSG_WARN_ZIPFILE_ALREADY_EXISTS = "Warning: A NetarchiveSuite file already exists. It will be overridden. ";
553
554    /**
555     * Private constructor to avoid instantiation.
556     */
557    private Constants() {
558    }
559
560    /**
561     * Create the beginning of a scope in XML (e.g. html = \< html \>).
562     *
563     * @param scope The name of the XML-scope to have the start created.
564     * @return The beginning of the XML-scope.
565     * @throws ArgumentNotValid If the scope is null or empty.
566     */
567    public static String changeToXMLBeginScope(String scope) throws ArgumentNotValid {
568        ArgumentNotValid.checkNotNullOrEmpty(scope, "String scope");
569        return LESS_THAN + scope + GREATER_THAN;
570    }
571
572    /**
573     * Create the ending of a scope in XML (e.g. html = \< \html \>).
574     *
575     * @param scope The name of the XML-scope to have the end created.
576     * @return The ending of the XML-scope.
577     * @throws ArgumentNotValid If the scope is null or empty.
578     */
579    public static String changeToXMLEndScope(String scope) throws ArgumentNotValid {
580        ArgumentNotValid.checkNotNullOrEmpty(scope, "String scope");
581        return LESS_THAN + SLASH + scope + GREATER_THAN;
582    }
583
584    /**
585     * Checks whether a string is valid for environment name. The string is checked against a regular expression.
586     *
587     * @param name The environment name to validate.
588     * @return Whether the environment name is valid.
589     * @throws ArgumentNotValid If the name is null or empty.
590     */
591    public static boolean validEnvironmentName(String name) throws ArgumentNotValid {
592        ArgumentNotValid.checkNotNullOrEmpty(name, "String name");
593        return Pattern.matches(VALID_REGEX_ENVIRONMENT_NAME, name);
594    }
595
596}