public class BuildingBlockGallery
Corresponds to the ST_DocPartGallery type in OOXML. Example:
public void glossaryDocument() throws Exception {
Document doc = new Document();
GlossaryDocument glossaryDoc = new GlossaryDocument();
glossaryDoc.appendChild(createNewBuildingBlock(glossaryDoc, "Block 1"));
glossaryDoc.appendChild(createNewBuildingBlock(glossaryDoc, "Block 2"));
glossaryDoc.appendChild(createNewBuildingBlock(glossaryDoc, "Block 3"));
glossaryDoc.appendChild(createNewBuildingBlock(glossaryDoc, "Block 4"));
glossaryDoc.appendChild(createNewBuildingBlock(glossaryDoc, "Block 5"));
Assert.assertEquals(glossaryDoc.getBuildingBlocks().getCount(), 5);
doc.setGlossaryDocument(glossaryDoc);
// There are various ways of accessing building blocks.
// 1 - Get the first/last building blocks in the collection:
Assert.assertEquals("Block 1", glossaryDoc.getFirstBuildingBlock().getName());
Assert.assertEquals("Block 5", glossaryDoc.getLastBuildingBlock().getName());
// 2 - Get a building block by index:
Assert.assertEquals("Block 2", glossaryDoc.getBuildingBlocks().get(1).getName());
Assert.assertEquals("Block 3", glossaryDoc.getBuildingBlocks().toArray()[2].getName());
// 3 - Get the first building block that matches a gallery, name and category:
Assert.assertEquals("Block 4",
glossaryDoc.getBuildingBlock(BuildingBlockGallery.ALL, "(Empty Category)", "Block 4").getName());
// We will do that using a custom visitor,
// which will give every BuildingBlock in the GlossaryDocument a unique GUID
GlossaryDocVisitor visitor = new GlossaryDocVisitor();
glossaryDoc.accept(visitor);
System.out.println(visitor.getText());
// When we open this document using Microsoft Word,
// we can find the building blocks via Insert -> Quick Parts -> Building Blocks Organizer.
doc.save(getArtifactsDir() + "BuildingBlocks.GlossaryDocument.dotx");
}
public static BuildingBlock createNewBuildingBlock(final GlossaryDocument glossaryDoc, final String buildingBlockName) {
BuildingBlock buildingBlock = new BuildingBlock(glossaryDoc);
buildingBlock.setName(buildingBlockName);
return buildingBlock;
}
/// <summary>
/// Gives each building block in a visited glossary document a unique GUID, and stores the GUID-building block pairs in a dictionary.
/// </summary>
public static class GlossaryDocVisitor extends DocumentVisitor {
public GlossaryDocVisitor() {
mBlocksByGuid = new HashMap<>();
mBuilder = new StringBuilder();
}
public String getText() {
return mBuilder.toString();
}
public HashMap<UUID, BuildingBlock> getDictionary() {
return mBlocksByGuid;
}
public int visitGlossaryDocumentStart(final GlossaryDocument glossary) {
mBuilder.append("Glossary document found!\n");
return VisitorAction.CONTINUE;
}
public int visitGlossaryDocumentEnd(final GlossaryDocument glossary) {
mBuilder.append("Reached end of glossary!\n");
mBuilder.append("BuildingBlocks found: " + mBlocksByGuid.size() + "\r\n");
return VisitorAction.CONTINUE;
}
public int visitBuildingBlockStart(final BuildingBlock block) {
block.setGuid(UUID.randomUUID());
mBlocksByGuid.put(block.getGuid(), block);
return VisitorAction.CONTINUE;
}
public int visitBuildingBlockEnd(final BuildingBlock block) {
mBuilder.append("\tVisited block \"" + block.getName() + "\"" + "\r\n");
mBuilder.append("\t Type: " + block.getType() + "\r\n");
mBuilder.append("\t Gallery: " + block.getGallery() + "\r\n");
mBuilder.append("\t Behavior: " + block.getBehavior() + "\r\n");
mBuilder.append("\t Description: " + block.getDescription() + "\r\n");
return VisitorAction.CONTINUE;
}
private final HashMap<UUID, BuildingBlock> mBlocksByGuid;
private final StringBuilder mBuilder;
}
Field Summary | ||
---|---|---|
static final int | ALL | |
Specifies that this glossary document entry shall be associated with all possible gallery classification values.
|
||
static final int | AUTO_TEXT | |
static final int | BIBLIOGRAPHY | |
static final int | COVER_PAGE | |
static final int | CUSTOM_AUTO_TEXT | |
static final int | CUSTOM_BIBLIOGRAPHY | |
static final int | CUSTOM_COVER_PAGE | |
static final int | CUSTOM_EQUATIONS | |
static final int | CUSTOM_FOOTERS | |
static final int | CUSTOM_HEADERS | |
static final int | CUSTOM_1 | |
static final int | CUSTOM_2 | |
static final int | CUSTOM_3 | |
static final int | CUSTOM_4 | |
static final int | CUSTOM_5 | |
static final int | CUSTOM_PAGE_NUMBER | |
static final int | CUSTOM_PAGE_NUMBER_AT_BOTTOM | |
static final int | CUSTOM_PAGE_NUMBER_AT_MARGIN | |
static final int | CUSTOM_PAGE_NUMBER_AT_TOP | |
static final int | CUSTOM_QUICK_PARTS | |
static final int | CUSTOM_TABLE_OF_CONTENTS | |
static final int | CUSTOM_TABLES | |
static final int | CUSTOM_TEXT_BOX | |
static final int | CUSTOM_WATERMARKS | |
static final int | NO_GALLERY | |
static final int | QUICK_PARTS | |
static final int | EQUATIONS | |
static final int | FOOTERS | |
static final int | HEADERS | |
static final int | PAGE_NUMBER | |
static final int | PAGE_NUMBER_AT_BOTTOM | |
static final int | PAGE_NUMBER_AT_MARGIN | |
static final int | PAGE_NUMBER_AT_TOP | |
static final int | STRUCTURED_DOCUMENT_TAG_PLACEHOLDER_TEXT | |
static final int | TABLE_OF_CONTENTS | |
static final int | TABLES | |
static final int | TEXT_BOX | |
static final int | WATERMARKS | |
static final int | DEFAULT | |
Same as |
public static final int ALL
public static final int AUTO_TEXT
public static final int BIBLIOGRAPHY
public static final int COVER_PAGE
public static final int CUSTOM_AUTO_TEXT
public static final int CUSTOM_BIBLIOGRAPHY
public static final int CUSTOM_COVER_PAGE
public static final int CUSTOM_EQUATIONS
public static final int CUSTOM_FOOTERS
public static final int CUSTOM_HEADERS
public static final int CUSTOM_1
public static final int CUSTOM_2
public static final int CUSTOM_3
public static final int CUSTOM_4
public static final int CUSTOM_5
public static final int CUSTOM_PAGE_NUMBER
public static final int CUSTOM_PAGE_NUMBER_AT_BOTTOM
public static final int CUSTOM_PAGE_NUMBER_AT_MARGIN
public static final int CUSTOM_PAGE_NUMBER_AT_TOP
public static final int CUSTOM_QUICK_PARTS
public static final int CUSTOM_TABLE_OF_CONTENTS
public static final int CUSTOM_TABLES
public static final int CUSTOM_TEXT_BOX
public static final int CUSTOM_WATERMARKS
public static final int NO_GALLERY
public static final int QUICK_PARTS
public static final int EQUATIONS
public static final int FOOTERS
public static final int HEADERS
public static final int PAGE_NUMBER
public static final int PAGE_NUMBER_AT_BOTTOM
public static final int PAGE_NUMBER_AT_MARGIN
public static final int PAGE_NUMBER_AT_TOP
public static final int STRUCTURED_DOCUMENT_TAG_PLACEHOLDER_TEXT
public static final int TABLE_OF_CONTENTS
public static final int TABLES
public static final int TEXT_BOX
public static final int WATERMARKS
public static final int DEFAULT