mirror of https://github.com/apache/poi.git
put back the goto - it is terrible but I don't have time work out why it is needed
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1893597 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d457298316
commit
0ca10663c6
|
@ -26,13 +26,13 @@ public abstract class HeaderFooter implements org.apache.poi.ss.usermodel.Header
|
|||
protected HeaderFooter() {
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the internal text representation (combining center, left and right parts).
|
||||
* Possibly empty string if no header or footer is set. Never <code>null</code>.
|
||||
*/
|
||||
protected abstract String getRawText();
|
||||
|
||||
protected abstract String getRawText();
|
||||
|
||||
private String[] splitParts() {
|
||||
String text = getRawText();
|
||||
// default values
|
||||
|
@ -40,6 +40,8 @@ public abstract class HeaderFooter implements org.apache.poi.ss.usermodel.Header
|
|||
String _center = "";
|
||||
String _right = "";
|
||||
|
||||
// FIXME: replace outer goto. just eww.
|
||||
outer:
|
||||
while (text.length() > 1) {
|
||||
if (text.charAt(0) != '&') {
|
||||
// Mimics the behaviour of Excel, which would put it in the center.
|
||||
|
@ -48,43 +50,43 @@ public abstract class HeaderFooter implements org.apache.poi.ss.usermodel.Header
|
|||
}
|
||||
int pos = text.length();
|
||||
switch (text.charAt(1)) {
|
||||
case 'L':
|
||||
if (text.contains("&C")) {
|
||||
pos = Math.min(pos, text.indexOf("&C"));
|
||||
}
|
||||
if (text.contains("&R")) {
|
||||
pos = Math.min(pos, text.indexOf("&R"));
|
||||
}
|
||||
_left = text.substring(2, pos);
|
||||
text = text.substring(pos);
|
||||
return new String[] { _left, _center, _right, };
|
||||
case 'C':
|
||||
if (text.contains("&L")) {
|
||||
pos = Math.min(pos, text.indexOf("&L"));
|
||||
}
|
||||
if (text.contains("&R")) {
|
||||
pos = Math.min(pos, text.indexOf("&R"));
|
||||
}
|
||||
_center = text.substring(2, pos);
|
||||
text = text.substring(pos);
|
||||
return new String[] { _left, _center, _right, };
|
||||
case 'R':
|
||||
if (text.contains("&C")) {
|
||||
pos = Math.min(pos, text.indexOf("&C"));
|
||||
}
|
||||
if (text.contains("&L")) {
|
||||
pos = Math.min(pos, text.indexOf("&L"));
|
||||
}
|
||||
_right = text.substring(2, pos);
|
||||
text = text.substring(pos);
|
||||
return new String[] { _left, _center, _right, };
|
||||
default:
|
||||
// Mimics the behaviour of Excel, which would put it in the center.
|
||||
_center = text;
|
||||
break;
|
||||
case 'L':
|
||||
if (text.contains("&C")) {
|
||||
pos = Math.min(pos, text.indexOf("&C"));
|
||||
}
|
||||
if (text.contains("&R")) {
|
||||
pos = Math.min(pos, text.indexOf("&R"));
|
||||
}
|
||||
_left = text.substring(2, pos);
|
||||
text = text.substring(pos);
|
||||
break;
|
||||
case 'C':
|
||||
if (text.contains("&L")) {
|
||||
pos = Math.min(pos, text.indexOf("&L"));
|
||||
}
|
||||
if (text.contains("&R")) {
|
||||
pos = Math.min(pos, text.indexOf("&R"));
|
||||
}
|
||||
_center = text.substring(2, pos);
|
||||
text = text.substring(pos);
|
||||
break;
|
||||
case 'R':
|
||||
if (text.contains("&C")) {
|
||||
pos = Math.min(pos, text.indexOf("&C"));
|
||||
}
|
||||
if (text.contains("&L")) {
|
||||
pos = Math.min(pos, text.indexOf("&L"));
|
||||
}
|
||||
_right = text.substring(2, pos);
|
||||
text = text.substring(pos);
|
||||
break;
|
||||
default:
|
||||
// Mimics the behaviour of Excel, which would put it in the center.
|
||||
_center = text;
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return new String[] { _left, _center, _right, };
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -98,7 +100,7 @@ public abstract class HeaderFooter implements org.apache.poi.ss.usermodel.Header
|
|||
* @param newLeft The string to set as the left side.
|
||||
*/
|
||||
public final void setLeft(String newLeft) {
|
||||
updatePart(0, newLeft);
|
||||
updatePart(0, newLeft);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,7 +114,7 @@ public abstract class HeaderFooter implements org.apache.poi.ss.usermodel.Header
|
|||
* @param newCenter The string to set as the center.
|
||||
*/
|
||||
public final void setCenter(String newCenter) {
|
||||
updatePart(1, newCenter);
|
||||
updatePart(1, newCenter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -126,9 +128,9 @@ public abstract class HeaderFooter implements org.apache.poi.ss.usermodel.Header
|
|||
* @param newRight The string to set as the right side.
|
||||
*/
|
||||
public final void setRight(String newRight) {
|
||||
updatePart(2, newRight);
|
||||
updatePart(2, newRight);
|
||||
}
|
||||
|
||||
|
||||
private void updatePart(int partIndex, String newValue) {
|
||||
String[] parts = splitParts();
|
||||
parts[partIndex] = newValue == null ? "" : newValue;
|
||||
|
@ -142,7 +144,7 @@ public abstract class HeaderFooter implements org.apache.poi.ss.usermodel.Header
|
|||
String _left = parts[0];
|
||||
String _center = parts[1];
|
||||
String _right = parts[2];
|
||||
|
||||
|
||||
if (_center.length() < 1 && _left.length() < 1 && _right.length() < 1) {
|
||||
setHeaderFooterText("");
|
||||
return;
|
||||
|
@ -320,7 +322,7 @@ public abstract class HeaderFooter implements org.apache.poi.ss.usermodel.Header
|
|||
UNDERLINE_FIELD ("&U", true),
|
||||
DOUBLE_UNDERLINE_FIELD ("&E", true),
|
||||
;
|
||||
|
||||
|
||||
private final String _representation;
|
||||
private final boolean _occursInPairs;
|
||||
private MarkupTag(String sequence, boolean occursInPairs) {
|
||||
|
@ -342,4 +344,4 @@ public abstract class HeaderFooter implements org.apache.poi.ss.usermodel.Header
|
|||
return _occursInPairs;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue