/** * Same as {@link #setBaseUrl(URL)} except that a * {@link MalformedURLException} may occur when creating the {@link URL} * instance from the given parameters. * * @param aScheme The {@link Scheme} (e.g. {@link Scheme#HTTP} or * {@link Scheme#HTTPS}) to be used for the base {@link URL}. * * @param aHost The host to which the base {@link URL} is to point to. * * @param aPort The port to be used when connecting to the host. * * @throws MalformedURLException in case the parameters cannot be * converted to a valid (accepted) {@link URL}. */ default void setBaseUrl( Scheme aScheme, String aHost, int aPort ) throws MalformedURLException { setBaseUrl( new URL( aScheme.getName(), aHost, aPort, "" ) ); }
/** * Builder method for * {@link BaseUrlMutator#setBaseUrl(Scheme, String, int)}. * * @param aScheme The {@link Scheme} (e.g. {@link Scheme#HTTP} or * {@link Scheme#HTTPS}) to be used for the base {@link URL}. * * @param aHost The host to which the base {@link URL} is to point to. * * @param aPort The port to be used when connecting to the host. * * @return The builder for applying multiple build operations. * * @throws MalformedURLException in case the parameters cannot be * converted to a valid (accepted) {@link URL}. */ default B withBaseUrl( Scheme aScheme, String aHost, int aPort ) throws MalformedURLException { return withBaseUrl( new URL( aScheme.getName(), aHost, aPort, "" ) ); }
/** * Determines the parent JAR file's URL for your running application (not * including the "!" which is required to address a file within that JAR). * * @return The parrent's JAR file URL or null if the application does not * seem to reside in a JAR. */ public static URL toParentJarUrl() { URL theUrl = FileUtility.class.getProtectionDomain().getCodeSource().getLocation(); if ( !theUrl.getProtocol().equals( Scheme.JAR.getName() ) ) return null; try { String theJarPath = URLDecoder.decode( theUrl.getFile(), Encoding.UTF_8.getCode() ); theJarPath = Scheme.JAR.toUrl( theJarPath ); return new URL( theJarPath ); } catch ( UnsupportedEncodingException | MalformedURLException e ) { return null; } }
/** * Same as {@link #setBaseUrl(URL)} except that a * {@link MalformedURLException} may occur when creating the {@link URL} * instance from the given parameters. * * @param aScheme The {@link Scheme} (e.g. {@link Scheme#HTTP} or * {@link Scheme#HTTPS}) to be used for the base {@link URL}. * * @param aHost The host to which the base {@link URL} is to point to. * * @param aPort The port to be used when connecting to the host. * * @param aPath The path on the host to which the base {@link URL} is to * point to. * * @throws MalformedURLException in case the parameters cannot be * converted to a valid (accepted) {@link URL}. */ default void setBaseUrl( Scheme aScheme, String aHost, int aPort, String aPath ) throws MalformedURLException { setBaseUrl( new URL( aScheme.getName(), aHost, aPort, aPath ) ); } }
/** * Builder method for * {@link BaseUrlMutator#setBaseUrl(Scheme, String, int, String)}. * * @param aScheme The {@link Scheme} (e.g. {@link Scheme#HTTP} or * {@link Scheme#HTTPS}) to be used for the base {@link URL}. * * @param aHost The host to which the base {@link URL} is to point to. * * @param aPort The port to be used when connecting to the host. * * @param aPath The path on the host to which the base {@link URL} is to * point to. * * @return The builder for applying multiple build operations. * * @throws MalformedURLException in case the parameters cannot be * converted to a valid (accepted) {@link URL}. */ default B withBaseUrl( Scheme aScheme, String aHost, int aPort, String aPath ) throws MalformedURLException { return withBaseUrl( new URL( aScheme.getName(), aHost, aPort, aPath ) ); } }
/** * Same as {@link #setBaseUrl(URL)} except that a * {@link MalformedURLException} may occur when creating the {@link URL} * instance from the given parameters. * * @param aProtocol The protocol (e.g. HTTP or HTTPS) to be used for the * base {@link URL}. * * @param aHost The host to which the base {@link URL} is to point to. * * @throws MalformedURLException in case the parameters cannot be * converted to a valid (accepted) {@link URL}. */ default void setBaseUrl( String aProtocol, String aHost ) throws MalformedURLException { int thePort = -1; if ( Scheme.HTTP.getName().equalsIgnoreCase( aProtocol ) ) thePort = Port.HTTP.getPort(); if ( Scheme.HTTPS.getName().equalsIgnoreCase( aProtocol ) ) thePort = Port.HTTPS.getPort(); setBaseUrl( new URL( aProtocol, aHost, thePort, "" ) ); }
/** * Same as {@link #withBaseUrl(URL)} except that a * {@link MalformedURLException} may occur when creating the {@link URL} * instance from the given parameters. * * @param aProtocol The protocol (e.g. HTTP or HTTPS) to be used for the * base {@link URL}. * * @param aHost The host to which the base {@link URL} is to point to. * * @return The builder for applying multiple build operations. * * @throws MalformedURLException in case the parameters cannot be * converted to a valid (accepted) {@link URL}. */ default B withBaseUrl( String aProtocol, String aHost ) throws MalformedURLException { int thePort = -1; if ( Scheme.HTTP.getName().equalsIgnoreCase( aProtocol ) ) thePort = Port.HTTP.getPort(); if ( Scheme.HTTPS.getName().equalsIgnoreCase( aProtocol ) ) thePort = Port.HTTPS.getPort(); return withBaseUrl( new URL( aProtocol, aHost, thePort, "" ) ); }
/** * Same as {@link #setBaseUrl(URL)} except that a * {@link MalformedURLException} may occur when creating the {@link URL} * instance from the given parameters. * * @param aProtocol The protocol (e.g. HTTP or HTTPS) to be used for the * base {@link URL}. * * @param aHost The host to which the base {@link URL} is to point to. * * @param aPath The path on the host to which the base {@link URL} is to * point to. * * @throws MalformedURLException in case the parameters cannot be * converted to a valid (accepted) {@link URL}. */ default void setBaseUrl( String aProtocol, String aHost, String aPath ) throws MalformedURLException { int thePort = -1; if ( Scheme.HTTP.getName().equalsIgnoreCase( aProtocol ) ) thePort = Port.HTTP.getPort(); if ( Scheme.HTTPS.getName().equalsIgnoreCase( aProtocol ) ) thePort = Port.HTTPS.getPort(); setBaseUrl( new URL( aProtocol, aHost, thePort, "" ) ); }
/** * Same as {@link #withBaseUrl(URL)} except that a * {@link MalformedURLException} may occur when creating the {@link URL} * instance from the given parameters. * * @param aProtocol The protocol (e.g. HTTP or HTTPS) to be used for the * base {@link URL}. * * @param aHost The host to which the base {@link URL} is to point to. * * @param aPath The path on the host to which the base {@link URL} is to * point to. * * @return The builder for applying multiple build operations. * * @throws MalformedURLException in case the parameters cannot be * converted to a valid (accepted) {@link URL}. */ default B withBaseUrl( String aProtocol, String aHost, String aPath ) throws MalformedURLException { int thePort = -1; if ( Scheme.HTTP.getName().equalsIgnoreCase( aProtocol ) ) thePort = Port.HTTP.getPort(); if ( Scheme.HTTPS.getName().equalsIgnoreCase( aProtocol ) ) thePort = Port.HTTPS.getPort(); return withBaseUrl( new URL( aProtocol, aHost, thePort, aPath ) ); }
if ( !aJarUrl.getProtocol().equals( Scheme.JAR.getName() ) ) return null; List<String> theList = new ArrayList<String>(); try {
/** * Same as {@link #setBaseUrl(URL)} except that a * {@link MalformedURLException} may occur when creating the {@link URL} * instance from the given parameters. * * @param aScheme The {@link Scheme} (e.g. {@link Scheme#HTTP} or * {@link Scheme#HTTPS}) to be used for the base {@link URL}. * * @param aHost The host to which the base {@link URL} is to point to. * * @throws MalformedURLException in case the parameters cannot be * converted to a valid (accepted) {@link URL}. */ default void setBaseUrl( Scheme aScheme, String aHost ) throws MalformedURLException { int thePort = -1; if ( Scheme.HTTP == aScheme ) thePort = Port.HTTP.getPort(); if ( Scheme.HTTPS == aScheme ) thePort = Port.HTTPS.getPort(); setBaseUrl( new URL( aScheme.getName(), aHost, thePort, "" ) ); }
/** * Same as {@link #withBaseUrl(URL)} except that a * {@link MalformedURLException} may occur when creating the {@link URL} * instance from the given parameters. * * @param aScheme The {@link Scheme} (e.g. {@link Scheme#HTTP} or * {@link Scheme#HTTPS}) to be used for the base {@link URL}. * * @param aHost The host to which the base {@link URL} is to point to. * * @return The builder for applying multiple build operations. * * @throws MalformedURLException in case the parameters cannot be * converted to a valid (accepted) {@link URL}. */ default B withBaseUrl( Scheme aScheme, String aHost ) throws MalformedURLException { int thePort = -1; if ( Scheme.HTTP == aScheme ) thePort = Port.HTTP.getPort(); if ( Scheme.HTTPS == aScheme ) thePort = Port.HTTPS.getPort(); return withBaseUrl( new URL( aScheme.getName(), aHost, thePort, "" ) ); }
/** * Same as {@link #setBaseUrl(URL)} except that a * {@link MalformedURLException} may occur when creating the {@link URL} * instance from the given parameters. * * @param aScheme The {@link Scheme} (e.g. {@link Scheme#HTTP} or * {@link Scheme#HTTPS}) to be used for the base {@link URL}. * * @param aHost The host to which the base {@link URL} is to point to. * * @param aPath The path on the host to which the base {@link URL} is to * point to. * * @throws MalformedURLException in case the parameters cannot be * converted to a valid (accepted) {@link URL}. */ default void setBaseUrl( Scheme aScheme, String aHost, String aPath ) throws MalformedURLException { int thePort = -1; if ( Scheme.HTTP == aScheme ) thePort = Port.HTTP.getPort(); if ( Scheme.HTTPS == aScheme ) thePort = Port.HTTPS.getPort(); setBaseUrl( new URL( aScheme.getName(), aHost, thePort, "" ) ); }
if ( aJarUrl.getProtocol().equals( Scheme.FILE.getName() ) ) return aJarUrl; if ( !aJarUrl.getProtocol().equals( Scheme.JAR.getName() ) ) return null; String theJarPath = new CsvBuilderImpl().withCsvEscapeMode( CsvEscapeMode.ESCAPED ).withFields( FileUtility.toJarHierarchy( aJarUrl ) ).withDelimiter( Delimiter.SYSTEM_FILE_PATH.getChar() ).toRecord(); File theJarDir = new File( aToDir, theJarPath );
/** * Same as {@link #withBaseUrl(URL)} except that a * {@link MalformedURLException} may occur when creating the {@link URL} * instance from the given parameters. * * @param aScheme The {@link Scheme} (e.g. {@link Scheme#HTTP} or * {@link Scheme#HTTPS}) to be used for the base {@link URL}. * * @param aHost The host to which the base {@link URL} is to point to. * * @param aPath The path on the host to which the base {@link URL} is to * point to. * * @return The builder for applying multiple build operations. * * @throws MalformedURLException in case the parameters cannot be * converted to a valid (accepted) {@link URL}. */ default B withBaseUrl( Scheme aScheme, String aHost, String aPath ) throws MalformedURLException { int thePort = -1; if ( Scheme.HTTP == aScheme ) thePort = Port.HTTP.getPort(); if ( Scheme.HTTPS == aScheme ) thePort = Port.HTTPS.getPort(); return withBaseUrl( new URL( aScheme.getName(), aHost, thePort, aPath ) ); }
/** * {@inheritDoc} */ @Override public void setBaseUrl( Url aBaseUrl ) { if ( aBaseUrl != null ) { if ( aBaseUrl.getScheme() != Scheme.HTTP && aBaseUrl.getScheme() != Scheme.HTTPS ) { throw new IllegalArgumentException( "Cannot use the protocol <" + aBaseUrl.getScheme() + "> to do HTTP requests (" + aBaseUrl.toHttpUrl() + "). You must provide a base URL for protocols <" + Scheme.HTTP.getName() + "> or <" + Scheme.HTTPS.getName() + ">." ); } if ( aBaseUrl.getQueryFields() != null && aBaseUrl.getQueryFields().size() != 0 ) { throw new IllegalArgumentException( "Cannot use a query <" + new VerboseTextBuilderImpl().withElements( aBaseUrl.getQueryFields() ) + "> as bayse path. You must provide a base URL without a query." ); } } _baseUrl = aBaseUrl; }