in poi-scratchpad/src/main/java/org/apache/poi/hwpf/converter/AbstractWordConverter.java [699:804]
protected abstract void processEndnoteAutonumbered(
HWPFDocument wordDocument, int noteIndex, Element block,
Range endnoteTextRange);
protected void processField(HWPFDocument wordDocument, Range parentRange,
int currentTableLevel, Field field, Element currentBlock) {
switch (field.getType()) {
case FIELD_PAGE_REFERENCE: {
final Range firstSubrange = field.firstSubrange(parentRange);
if (firstSubrange != null) {
String formula = firstSubrange.text();
Matcher matcher = PATTERN_PAGEREF.matcher(formula);
if (matcher.find()) {
String pageref = matcher.group(1);
processPageref(wordDocument, currentBlock,
field.secondSubrange(parentRange),
currentTableLevel, pageref);
return;
}
}
break;
}
case FIELD_EMBEDDED_OBJECT: {
if (!field.hasSeparator()) {
LOG.atWarn().log("{} contains {} with 'Embedded Object' but without separator mark", parentRange, field);
return;
}
CharacterRun separator = field
.getMarkSeparatorCharacterRun(parentRange);
if (separator.isOle2()) {
// the only supported so far
boolean processed = processOle2(wordDocument, separator,
currentBlock);
// if we didn't output OLE - output field value
if (!processed) {
processCharacters(wordDocument, currentTableLevel,
field.secondSubrange(parentRange), currentBlock);
}
return;
}
break;
}
case FIELD_DROP_DOWN: {
Range fieldContent = field.firstSubrange(parentRange);
if (fieldContent == null) {
throw new IllegalStateException("Cannot read field content from field " + field + " and range " + parentRange);
}
CharacterRun cr = fieldContent.getCharacterRun(fieldContent
.numCharacterRuns() - 1);
String[] values = cr.getDropDownListValues();
Integer defIndex = cr.getDropDownListDefaultItemIndex();
if (values != null && values.length > 0) {
processDropDownList(currentBlock, cr, values,
defIndex == null ? -1 : defIndex);
return;
}
break;
}
case FIELD_HYPERLINK: {
final Range firstSubrange = field.firstSubrange(parentRange);
if (firstSubrange != null) {
String formula = firstSubrange.text();
Matcher matcher = PATTERN_HYPERLINK_EXTERNAL.matcher(formula);
if (matcher.matches()) {
String hyperlink = matcher.group(1);
processHyperlink(wordDocument, currentBlock,
field.secondSubrange(parentRange),
currentTableLevel, hyperlink);
return;
}
matcher.usePattern(PATTERN_HYPERLINK_LOCAL);
if (matcher.matches()) {
String hyperlink = matcher.group(1);
Range textRange = null;
String text = matcher.group(2);
if (AbstractWordUtils.isNotEmpty(text)) {
textRange = new Range(firstSubrange.getStartOffset()
+ matcher.start(2),
firstSubrange.getStartOffset()
+ matcher.end(2), firstSubrange) {
@Override
public String toString() {
return "Local hyperlink text";
}
};
}
processPageref(wordDocument, currentBlock, textRange,
currentTableLevel, hyperlink);
return;
}
}
break;
}
}
LOG.atWarn().log("{} contains {} with unsupported type or format", parentRange, field);
processCharacters(wordDocument, currentTableLevel,
field.secondSubrange(parentRange), currentBlock);
}