001/* 002 * #%L 003 * Netarchivesuite - common 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.common; 024 025import java.text.SimpleDateFormat; 026import java.util.regex.Pattern; 027 028import org.apache.lucene.util.Version; 029 030/** 031 * This class is used for global constants only. 032 * <p> 033 * If your constant is only to be used in a single package, put it in a Constants-class in that package, and make sure 034 * it is package private (no modifiers). 035 * <p> 036 * If your constant is used in a single class only, put it in that class, and make sure it is private. 037 * <p> 038 * Remember everything placed here MUST be constants. 039 * <p> 040 * This class is never instantiated, so thread security is not an issue. 041 */ 042public final class Constants { 043 /** The pattern for an IP-address key. */ 044 public static final String IP_REGEX_STRING = "[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}"; 045 /** A full string matcher for an IP-address. */ 046 public static final Pattern IP_KEY_REGEXP = Pattern.compile("^" + IP_REGEX_STRING + "$"); 047 /** A full string matcher for an IPv6-address. */ 048 public static final Pattern IPv6_KEY_REGEXP = Pattern.compile("^([0-9A-F]{1,2}\\:){5}[0-9A-F]{1,2}$"); 049 /** 050 * The suffix of a regular expression that matches the metadata files. Add job IDs to the front as necessary. 051 */ 052 public static final String METADATA_FILE_PATTERN_SUFFIX = "-metadata-[0-9]+.(w)?arc"; 053 /** The mimetype for a list of CDX entries. */ 054 public static final String CDX_MIME_TYPE = "application/x-cdx"; 055 056 /** Extension of XML file names. */ 057 public static final String XML_EXTENSION = ".xml"; 058 059 // Version string. */ 060 private static String version; 061 062 /** Current version of Heritrix used by netarkivet-code. */ 063 private static final String HERITRIX_VERSION = "1.14.4"; 064 065 /** 066 * Read this much data when copying data from a file channel. Note that due to a bug in java, this should never be 067 * set larger than Integer.MAX_VALUE, since a call to fileChannel.transferFrom/To fails with an error while calling 068 * mmap. 069 */ 070 public static final long IO_CHUNK_SIZE = 65536L; 071 /** The directory name of the heritrix directory with arcfiles. */ 072 public static final String ARCDIRECTORY_NAME = "arcs"; 073 /** The directory name of the heritrix directory with warcfiles. */ 074 public static final String WARCDIRECTORY_NAME = "warcs"; 075 /** 076 * How big a buffer we use for read()/write() operations on InputStream/ OutputStream. 077 */ 078 public static final int IO_BUFFER_SIZE = 4096; 079 080 /** The date format used for NetarchiveSuite dateformatting. */ 081 private static final String ISO_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss Z"; 082 083 /** Internationalisation resource bundle for common module. */ 084 public static final String TRANSLATIONS_BUNDLE = "dk.netarkivet.common.Translations"; 085 086 /** 087 * Private constructor that does absolutely nothing. Necessary in order to prevent initialization. 088 */ 089 private Constants() { 090 // Not to be initialised 091 } 092 093 /** 094 * Get a human-readable version string. 095 * 096 * @return A string telling current version and status of code. 097 */ 098 public static String getVersionString() { 099 if (version == null) { 100 StringBuilder sb = new StringBuilder(); 101 sb.append("Version: "); 102 sb.append(Constants.class.getPackage().getSpecificationVersion()); 103 String implementationVersion = Constants.class.getPackage().getImplementationVersion(); 104 if (implementationVersion != null && implementationVersion.length() == 40) { 105 sb.append(" (<a href=\"https://github.com/netarchivesuite/netarchivesuite/commit/"); 106 sb.append(implementationVersion); 107 sb.append("\">"); 108 sb.append(implementationVersion.substring(0, 10)); 109 sb.append("</a>)"); 110 } 111 version = sb.toString(); 112 } 113 return version; 114 } 115 116 /** 117 * Get the Heritrix version presently in use. 118 * 119 * @return the Heritrix version presently in use 120 */ 121 public static String getHeritrixVersionString() { 122 return HERITRIX_VERSION; 123 } 124 125 /** 126 * Get a formatter that can read and write a date in ISO format including hours/minutes/seconds and timezone. 127 * 128 * @return The formatter. 129 */ 130 public static SimpleDateFormat getIsoDateFormatter() { 131 return new SimpleDateFormat(ISO_DATE_FORMAT); 132 } 133 134 /** One minute in milliseconds. */ 135 public static final long ONE_MIN_IN_MILLIES = 60 * 1000; 136 137 /** One day in milliseconds. */ 138 public static final long ONE_DAY_IN_MILLIES = 24 * 60 * ONE_MIN_IN_MILLIES; 139 140 /** Pattern that matches our our CDX mimetype. */ 141 public static final String CDX_MIME_PATTERN = "application/x-cdx"; 142 143 /** Pattern that matches everything. */ 144 public static final String ALL_PATTERN = ".*"; 145 146 /** Lucene version used by this release of NetarchiveSuite. */ 147 public static final Version LUCENE_VERSION = Version.LUCENE_44; 148 149 /** The current website for the NetarchiveSuite project. */ 150 public static final String PROJECT_WEBSITE = "https://sbforge.org/display/NAS"; 151 152 public static String getHeritrix3VersionString() { 153 return "3.3.0-LBS-2014-03"; 154 } 155}