/* * [ViaForSender.java] * * Summary: Centralised logic that depends on the how the Replicator is delivered. * * Copyright: (c) 2003-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 7.6 2007-07-16 */ package com.mindprod.replicatorsender; import com.mindprod.replicatorcommon.ViaCommon; import java.io.File; import java.io.Serializable; import static com.mindprod.replicatorsender.ConfigForSender.AUTHENTICATION; import static com.mindprod.replicatorsender.ConfigForSender.SENDER_ZIP_STAGING_DIR; import static com.mindprod.replicatorsender.ConfigForSender.SUGGESTED_LAN_ZIP_URL; import static com.mindprod.replicatorsender.ConfigForSender.WEBSITE_ZIP_URL; /** * Centralised logic that depends on the how the Replicator is delivered. *

* Not distributed to receiver, for sender only. * * @author Roedy Green, Canadian Mind Products * @version 7.6 2007-07-16 * @since 2003-10-20 */ enum ViaForSender implements Serializable { /** * gets files from website */ @SuppressWarnings( { "EnumeratedConstantNamingConvention" } ) VIA_WEBSITE( ViaCommon.VIA_WEBSITE, AUTHENTICATION, WEBSITE_ZIP_URL ), /** * gets files from LAN */ @SuppressWarnings( { "EnumeratedConstantNamingConvention" } ) VIA_LAN( ViaCommon.VIA_LAN, AUTHENTICATION, SUGGESTED_LAN_ZIP_URL ), /** * gets files from website to relay to others. */ @SuppressWarnings( { "EnumeratedConstantNamingConvention" } ) VIA_RELAY( ViaCommon.VIA_RELAY, AUTHENTICATION, WEBSITE_ZIP_URL ), /** * TEST, gets files from sender's staging directory loops back to same machine. */ @SuppressWarnings( { "EnumeratedConstantNamingConvention" } ) VIA_TEST( ViaCommon.VIA_TEST, "none", "file:/" + SENDER_ZIP_STAGING_DIR // this is the file separator, not the line separator. .replace( File.separatorChar, '/' ) ), /** * CD, gets files from CD. */ @SuppressWarnings( { "EnumeratedConstantNamingConvention" } ) VIA_CD( ViaCommon.VIA_CD, "none", "file:///X:/" ) { /** * Get codebase for JNLP file, special version for VIA_CD * @param driveLetter drive letter \\p{Upper} used only for VIA_CD * @return codebase for use in JNLP file */ public String getCodebase( char driveLetter ) { return "file:///" + driveLetter + ":/"; } }; /** * Layout version number. */ private static final long serialVersionUID = 310L; /** * password */ private final String authentication; /** * codebase for JNLP */ private final String codeBase; /** * corresponding ViaCommon code. */ private final ViaCommon viaCommon; /** * constructor * * @param viaCommon corresponding common enum * @param authentication must be "basic" or "none", what sort of authorisation required to access the zips. * @param codeBase url where the zips are. */ ViaForSender( ViaCommon viaCommon, String authentication, String codeBase ) { assert viaCommon != null : "viaCommon null"; this.viaCommon = viaCommon; assert authentication != null && ( authentication.equals( "basic" ) || authentication.equals( "none" ) ) : "authentication invalid"; this.authentication = authentication; assert codeBase != null : "codeBase null"; this.codeBase = codeBase; } /** * Do we keep zips for this via after downloading? * * @return true if we keep zips by default for this viaCode */ @SuppressWarnings( { "BooleanMethodNameMustStartWithQuestion" } ) public boolean defaultKeepZips() { return viaCommon.defaultKeepZips(); } /** * Do we unpack zips for this via after downloading? * * @return true if we unpack zips by default for this viaCode */ @SuppressWarnings( { "BooleanMethodNameMustStartWithQuestion", "SameReturnValue" } ) public boolean defaultUnpackZips() { return true; } /** * Get authentication param for JNLP file * * @return authentication e.g. basic or none for use in JNLP file */ public String getAuthentication() { return authentication; } /** * Get codebase for JNLP file * * @param driveLetter drive letter \\p{Upper} used only for VIA_CD * * @return codebase for use in JNLP file */ public String getCodebase( char driveLetter ) { return codeBase; } /** * convert via enum to long string description. * * @return long string form of enum */ public String getDescription() { return viaCommon.getDescription(); } /** * Get name of JNLP file * * @param driveLetter drive letter \\p{Upper} used only for VIA_CD * * @return codebase for use in JNLP file */ public String getJnlpName( char driveLetter ) { String result = "replicatorreceiver" + this.toString(); if ( this == VIA_CD ) { result += driveLetter; } result += ".jnlp"; return result; } /** * online vs offline processing. * * @return true if can processZipsPass1 zips without an Internet connection. */ public boolean isOfflineAllowed() { return viaCommon.isOfflineAllowed(); } /** * convert via enum to string. * * @return string form of enum. */ public String toString() { return viaCommon.toString(); } }