bug 60253: add helper functions to make the constructor formula1-overloading code simpler
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1764831 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ee6b1e741d
commit
999c6499ec
@ -82,6 +82,7 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint {
|
|||||||
*/
|
*/
|
||||||
public XSSFDataValidationConstraint(int validationType, int operator, String formula1, String formula2) {
|
public XSSFDataValidationConstraint(int validationType, int operator, String formula1, String formula2) {
|
||||||
super();
|
super();
|
||||||
|
//removes leading equals sign if present
|
||||||
setFormula1(formula1);
|
setFormula1(formula1);
|
||||||
setFormula2(formula2);
|
setFormula2(formula2);
|
||||||
this.validationType = validationType;
|
this.validationType = validationType;
|
||||||
@ -92,12 +93,10 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint {
|
|||||||
//FIXME: Need to confirm if this is not a formula.
|
//FIXME: Need to confirm if this is not a formula.
|
||||||
// empirical testing shows Excel saves explicit lists surrounded by double quotes,
|
// empirical testing shows Excel saves explicit lists surrounded by double quotes,
|
||||||
// range formula expressions can't start with quotes (I think - anyone have a creative counter example?)
|
// range formula expressions can't start with quotes (I think - anyone have a creative counter example?)
|
||||||
if( ValidationType.LIST==validationType
|
if ( ValidationType.LIST == validationType
|
||||||
&& formula1 != null
|
&& this.formula1 != null
|
||||||
&& formula1.startsWith(QUOTE)
|
&& isQuoted(this.formula1) ) {
|
||||||
&& formula1.endsWith(QUOTE) ) {
|
explicitListOfValues = LIST_SPLIT_REGEX.split(unquote(this.formula1));
|
||||||
final String formulaWithoutQuotes = formula1.substring(1, formula1.length()-1);
|
|
||||||
explicitListOfValues = LIST_SPLIT_REGEX.split(formulaWithoutQuotes);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,6 +167,19 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint {
|
|||||||
protected static String removeLeadingEquals(String formula1) {
|
protected static String removeLeadingEquals(String formula1) {
|
||||||
return isFormulaEmpty(formula1) ? formula1 : formula1.charAt(0)=='=' ? formula1.substring(1) : formula1;
|
return isFormulaEmpty(formula1) ? formula1 : formula1.charAt(0)=='=' ? formula1.substring(1) : formula1;
|
||||||
}
|
}
|
||||||
|
private static boolean isQuoted(String s) {
|
||||||
|
return s.startsWith(QUOTE) && s.endsWith(QUOTE);
|
||||||
|
}
|
||||||
|
private static String unquote(String s) {
|
||||||
|
// removes leading and trailing quotes from a quoted string
|
||||||
|
if (isQuoted(s)) {
|
||||||
|
return s.substring(1, s.length()-1);
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
protected static boolean isFormulaEmpty(String formula1) {
|
||||||
|
return formula1 == null || formula1.trim().length()==0;
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.apache.poi.ss.usermodel.DataValidationConstraint#setFormula2(java.lang.String)
|
* @see org.apache.poi.ss.usermodel.DataValidationConstraint#setFormula2(java.lang.String)
|
||||||
@ -207,9 +219,6 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static boolean isFormulaEmpty(String formula1) {
|
|
||||||
return formula1 == null || formula1.trim().length()==0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String prettyPrint() {
|
public String prettyPrint() {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
Loading…
Reference in New Issue
Block a user