public class FieldSubject extends Field
To learn more, visit the Working with Fields documentation article.
Remarks:
Retrieves, and optionally sets, the document's subject, as recorded in the Subject property of the built-in document properties.
Examples:
Shows how to use the SUBJECT field.
Document doc = new Document();
// Set a value for the document's "Subject" built-in property.
doc.getBuiltInDocumentProperties().setSubject("My subject");
// Create a SUBJECT field to display the value of that built-in property.
DocumentBuilder builder = new DocumentBuilder(doc);
FieldSubject field = (FieldSubject) builder.insertField(FieldType.FIELD_SUBJECT, true);
field.update();
Assert.assertEquals(field.getFieldCode(), " SUBJECT ");
Assert.assertEquals(field.getResult(), "My subject");
// If we give the SUBJECT field's Text property value and update it, the field will
// overwrite the current value of the "Subject" built-in property with the value of its Text property,
// and then display the new value.
field.setText("My new subject");
field.update();
Assert.assertEquals(field.getFieldCode(), " SUBJECT \"My new subject\"");
Assert.assertEquals(field.getResult(), "My new subject");
Assert.assertEquals("My new subject", doc.getBuiltInDocumentProperties().getSubject());
doc.save(getArtifactsDir() + "Field.SUBJECT.docx");
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getText()
Gets the text of the subject.
|
void |
setText(java.lang.String value)
Sets the text of the subject.
|
getDisplayResult, getEnd, getFieldCode, getFieldCode, getFormat, getLocaleId, getResult, getSeparator, getStart, getType, isDirty, isDirty, isLocked, isLocked, needStoreOldResultNodes, remove, setLocaleId, setResult, unlink, update, updatepublic java.lang.String getText()
Examples:
Shows how to use the SUBJECT field.
Document doc = new Document();
// Set a value for the document's "Subject" built-in property.
doc.getBuiltInDocumentProperties().setSubject("My subject");
// Create a SUBJECT field to display the value of that built-in property.
DocumentBuilder builder = new DocumentBuilder(doc);
FieldSubject field = (FieldSubject) builder.insertField(FieldType.FIELD_SUBJECT, true);
field.update();
Assert.assertEquals(field.getFieldCode(), " SUBJECT ");
Assert.assertEquals(field.getResult(), "My subject");
// If we give the SUBJECT field's Text property value and update it, the field will
// overwrite the current value of the "Subject" built-in property with the value of its Text property,
// and then display the new value.
field.setText("My new subject");
field.update();
Assert.assertEquals(field.getFieldCode(), " SUBJECT \"My new subject\"");
Assert.assertEquals(field.getResult(), "My new subject");
Assert.assertEquals("My new subject", doc.getBuiltInDocumentProperties().getSubject());
doc.save(getArtifactsDir() + "Field.SUBJECT.docx");
public void setText(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to use the SUBJECT field.
Document doc = new Document();
// Set a value for the document's "Subject" built-in property.
doc.getBuiltInDocumentProperties().setSubject("My subject");
// Create a SUBJECT field to display the value of that built-in property.
DocumentBuilder builder = new DocumentBuilder(doc);
FieldSubject field = (FieldSubject) builder.insertField(FieldType.FIELD_SUBJECT, true);
field.update();
Assert.assertEquals(field.getFieldCode(), " SUBJECT ");
Assert.assertEquals(field.getResult(), "My subject");
// If we give the SUBJECT field's Text property value and update it, the field will
// overwrite the current value of the "Subject" built-in property with the value of its Text property,
// and then display the new value.
field.setText("My new subject");
field.update();
Assert.assertEquals(field.getFieldCode(), " SUBJECT \"My new subject\"");
Assert.assertEquals(field.getResult(), "My new subject");
Assert.assertEquals("My new subject", doc.getBuiltInDocumentProperties().getSubject());
doc.save(getArtifactsDir() + "Field.SUBJECT.docx");
value - The text of the subject.java.lang.Exception