-
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
138 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.poiji.parser; | ||
|
||
public class BooleanParser implements Parser<Boolean> { | ||
@Override | ||
public Boolean parse(String value) { | ||
if ("true".equalsIgnoreCase(value.trim())) { | ||
return true; | ||
} | ||
|
||
if ("false".equalsIgnoreCase(value.trim())) { | ||
return false; | ||
} | ||
|
||
/* LibreOffice compatibility: | ||
* | ||
* LibreOffice booleans are stored as formula =TRUE() or =FALSE() which is parsed by POI to 1 or 0. | ||
*/ | ||
if ("1".equals(value.trim())) { | ||
return true; | ||
} | ||
|
||
if ("0".equals(value.trim())) { | ||
return false; | ||
} | ||
|
||
throw new BooleanParseException(value); | ||
} | ||
|
||
public static class BooleanParseException extends RuntimeException { | ||
public BooleanParseException(String value) { | ||
super("Can't parse value to Boolean: " + value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters