001package org.kuali.common.devops.metadata.function; 002 003import static com.google.common.base.Optional.fromNullable; 004import static org.apache.commons.lang.StringUtils.substringBetween; 005import static org.kuali.common.util.base.Precondition.checkNotNull; 006 007import org.kuali.common.core.build.ValidatingBuilder; 008import org.kuali.common.core.validate.annotation.IdiotProofImmutable; 009 010import com.google.common.base.Function; 011import com.google.common.base.Optional; 012 013@IdiotProofImmutable 014public final class TomcatVersionFunction implements Function<String, Optional<String>> { 015 016 private final String open; 017 private final String close; 018 019 @Override 020 public Optional<String> apply(String content) { 021 checkNotNull(content, "content"); 022 return fromNullable(substringBetween(content, open, close)); 023 } 024 025 private TomcatVersionFunction(Builder builder) { 026 this.open = builder.open; 027 this.close = builder.close; 028 } 029 030 public static TomcatVersionFunction create() { 031 return builder().build(); 032 } 033 034 public static Builder builder() { 035 return new Builder(); 036 } 037 038 public static class Builder extends ValidatingBuilder<TomcatVersionFunction> { 039 040 private String open = "<h3>Apache Tomcat/"; 041 private String close = "</h3>"; 042 043 public Builder open(String open) { 044 this.open = open; 045 return this; 046 } 047 048 public Builder close(String close) { 049 this.close = close; 050 return this; 051 } 052 053 @Override 054 public TomcatVersionFunction build() { 055 return validate(new TomcatVersionFunction(this)); 056 } 057 058 public String getOpen() { 059 return open; 060 } 061 062 public void setOpen(String open) { 063 this.open = open; 064 } 065 066 public String getClose() { 067 return close; 068 } 069 070 public void setClose(String close) { 071 this.close = close; 072 } 073 074 } 075 076 public String getOpen() { 077 return open; 078 } 079 080 public String getClose() { 081 return close; 082 } 083}