View Javadoc
1   package org.kuali.common.devops.metadata.function;
2   
3   import static com.google.common.base.Optional.fromNullable;
4   import static org.apache.commons.lang.StringUtils.substringBetween;
5   import static org.kuali.common.util.base.Precondition.checkNotNull;
6   
7   import org.kuali.common.core.build.ValidatingBuilder;
8   import org.kuali.common.core.validate.annotation.IdiotProofImmutable;
9   
10  import com.google.common.base.Function;
11  import com.google.common.base.Optional;
12  
13  @IdiotProofImmutable
14  public final class TomcatVersionFunction implements Function<String, Optional<String>> {
15  
16  	private final String open;
17  	private final String close;
18  
19  	@Override
20  	public Optional<String> apply(String content) {
21  		checkNotNull(content, "content");
22  		return fromNullable(substringBetween(content, open, close));
23  	}
24  
25  	private TomcatVersionFunction(Builder builder) {
26  		this.open = builder.open;
27  		this.close = builder.close;
28  	}
29  
30  	public static TomcatVersionFunction create() {
31  		return builder().build();
32  	}
33  
34  	public static Builder builder() {
35  		return new Builder();
36  	}
37  
38  	public static class Builder extends ValidatingBuilder<TomcatVersionFunction> {
39  
40  		private String open = "<h3>Apache Tomcat/";
41  		private String close = "</h3>";
42  
43  		public Builder open(String open) {
44  			this.open = open;
45  			return this;
46  		}
47  
48  		public Builder close(String close) {
49  			this.close = close;
50  			return this;
51  		}
52  
53  		@Override
54  		public TomcatVersionFunction build() {
55  			return validate(new TomcatVersionFunction(this));
56  		}
57  
58  		public String getOpen() {
59  			return open;
60  		}
61  
62  		public void setOpen(String open) {
63  			this.open = open;
64  		}
65  
66  		public String getClose() {
67  			return close;
68  		}
69  
70  		public void setClose(String close) {
71  			this.close = close;
72  		}
73  
74  	}
75  
76  	public String getOpen() {
77  		return open;
78  	}
79  
80  	public String getClose() {
81  		return close;
82  	}
83  }