Skip to content

FieldUpdater: Ignores fields with formatting/spelling/... within field #645

@matthiaso

Description

@matthiaso

The following field:

Image

is ignored by org.docx4j.model.fields.FieldUpdater.update(boolean)

An error is logged:

ERROR [main] org.docx4j.model.fields.FieldUpdater.extractInstr(FieldUpdater.java:309) - TODO DOCPROPERTY field contained complex instruction
INFO  [main] org.docx4j.model.fields.FieldUpdater.update(FieldUpdater.java:87) - 
Simple Fields in /word/document.xml
============= 
Found 0 simple fields 
 
 Complex Fields in /word/document.xml
============== 
Found 1 fields 
null
null -> NOT FOUND! 

Taking a look at the document itself it seems that the instructions could just be concatenated, e.g. change within org.docx4j.model.fields.FieldUpdater.extractInstr(List<Object>):

String[] instrAsString = instructions.stream()
    .map(XmlUtils::unwrap)
    .map(o1 -> {
      if (o1 instanceof Text) {
        return ((Text) o1).getValue();
      }
      else {
        if (log.isErrorEnabled()) {
          log.error("TODO: extract field name from " + o1.getClass().getName());
          log.error(XmlUtils.marshaltoString(instructions.get(0), true, true));
        }
        return null;
      }
    })
    .toArray(i -> new String[i]);

if (Arrays.stream(instrAsString).anyMatch(Objects::isNull)) {
  return null;
}

return Arrays.stream(instrAsString).collect(Collectors.joining());

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions