| 1 | |
package org.apache.maven.shared.io.location; |
| 2 | |
|
| 3 | |
import java.net.MalformedURLException; |
| 4 | |
import java.net.URL; |
| 5 | |
|
| 6 | |
import org.apache.maven.shared.io.logging.MessageHolder; |
| 7 | |
|
| 8 | |
public class URLLocatorStrategy |
| 9 | |
implements LocatorStrategy |
| 10 | |
{ |
| 11 | |
|
| 12 | 4 | private String tempFilePrefix = "location."; |
| 13 | |
|
| 14 | 4 | private String tempFileSuffix = ".url"; |
| 15 | |
|
| 16 | 4 | private boolean tempFileDeleteOnExit = true; |
| 17 | |
|
| 18 | 3 | public URLLocatorStrategy() |
| 19 | |
{ |
| 20 | 3 | } |
| 21 | |
|
| 22 | 1 | public URLLocatorStrategy( String tempFilePrefix, String tempFileSuffix, boolean tempFileDeleteOnExit ) |
| 23 | |
{ |
| 24 | 1 | this.tempFilePrefix = tempFilePrefix; |
| 25 | 1 | this.tempFileSuffix = tempFileSuffix; |
| 26 | 1 | this.tempFileDeleteOnExit = tempFileDeleteOnExit; |
| 27 | 1 | } |
| 28 | |
|
| 29 | |
public Location resolve( String locationSpecification, MessageHolder messageHolder ) |
| 30 | |
{ |
| 31 | 2 | Location location = null; |
| 32 | |
|
| 33 | |
try |
| 34 | |
{ |
| 35 | 2 | URL url = new URL( locationSpecification ); |
| 36 | |
|
| 37 | 2 | location = new URLLocation( url, locationSpecification, tempFilePrefix, tempFileSuffix, |
| 38 | 1 | tempFileDeleteOnExit ); |
| 39 | |
} |
| 40 | 1 | catch ( MalformedURLException e ) |
| 41 | |
{ |
| 42 | 1 | messageHolder.addMessage( "Building URL from location: " + locationSpecification, e ); |
| 43 | |
} |
| 44 | |
|
| 45 | 2 | return location; |
| 46 | |
} |
| 47 | |
|
| 48 | |
} |