| 1 | |
package org.jbehave.core.io; |
| 2 | |
|
| 3 | |
import static org.apache.commons.lang.StringUtils.removeStart; |
| 4 | |
|
| 5 | |
import java.net.MalformedURLException; |
| 6 | |
import java.net.URL; |
| 7 | |
|
| 8 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
| 9 | |
import org.apache.commons.lang.builder.ToStringStyle; |
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
public class StoryLocation { |
| 24 | |
|
| 25 | |
private final URL codeLocation; |
| 26 | |
private final String storyPath; |
| 27 | |
private final boolean storyPathIsURL; |
| 28 | |
|
| 29 | 68 | public StoryLocation(URL codeLocation, String storyPath) { |
| 30 | 68 | this.codeLocation = codeLocation; |
| 31 | 68 | this.storyPath = storyPath; |
| 32 | 68 | this.storyPathIsURL = isURL(storyPath); |
| 33 | 68 | } |
| 34 | |
|
| 35 | |
public URL getCodeLocation() { |
| 36 | 74 | return codeLocation; |
| 37 | |
} |
| 38 | |
|
| 39 | |
public String getStoryPath() { |
| 40 | 3 | return storyPath; |
| 41 | |
} |
| 42 | |
|
| 43 | |
public String getURL() { |
| 44 | 3 | if (storyPathIsURL) { |
| 45 | 2 | return storyPath; |
| 46 | |
} else { |
| 47 | 1 | return codeLocation.toExternalForm() + storyPath; |
| 48 | |
} |
| 49 | |
} |
| 50 | |
|
| 51 | |
public String getPath() { |
| 52 | 67 | if (storyPathIsURL) { |
| 53 | 4 | return removeStart(storyPath, codeLocation.toExternalForm()); |
| 54 | |
} else { |
| 55 | 63 | return storyPath; |
| 56 | |
} |
| 57 | |
} |
| 58 | |
|
| 59 | |
private boolean isURL(String path) { |
| 60 | |
try { |
| 61 | 68 | new URL(path); |
| 62 | 4 | return true; |
| 63 | 64 | } catch (MalformedURLException e) { |
| 64 | 64 | return false; |
| 65 | |
} |
| 66 | |
} |
| 67 | |
|
| 68 | |
@Override |
| 69 | |
public String toString() { |
| 70 | 3 | return ToStringBuilder.reflectionToString(this, |
| 71 | |
ToStringStyle.SHORT_PREFIX_STYLE); |
| 72 | |
} |
| 73 | |
} |