public class BuildingBlockGallery
extends java.lang.Object
Remarks:
Corresponds to the ST_DocPartGallery type in OOXML.
Examples:
Shows ways of accessing building blocks in a glossary document.
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();
// Visit start/end of the Glossary document.
glossaryDoc.accept(visitor);
// Visit only start of the Glossary document.
glossaryDoc.acceptStart(visitor);
// Visit only end of the Glossary document.
glossaryDoc.acceptEnd(visitor);
System.out.println(visitor.getText());
// In Microsoft Word, we can access 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.
/// 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;
}
| Modifier and Type | Field and Description |
|---|---|
static int |
ALL
Specifies that this glossary document entry shall be associated with all possible gallery classification values.
|
static int |
AUTO_TEXT |
static int |
BIBLIOGRAPHY |
static int |
COVER_PAGE |
static int |
CUSTOM_1 |
static int |
CUSTOM_2 |
static int |
CUSTOM_3 |
static int |
CUSTOM_4 |
static int |
CUSTOM_5 |
static int |
CUSTOM_AUTO_TEXT |
static int |
CUSTOM_BIBLIOGRAPHY |
static int |
CUSTOM_COVER_PAGE |
static int |
CUSTOM_EQUATIONS |
static int |
CUSTOM_FOOTERS |
static int |
CUSTOM_HEADERS |
static int |
CUSTOM_PAGE_NUMBER |
static int |
CUSTOM_PAGE_NUMBER_AT_BOTTOM |
static int |
CUSTOM_PAGE_NUMBER_AT_MARGIN |
static int |
CUSTOM_PAGE_NUMBER_AT_TOP |
static int |
CUSTOM_QUICK_PARTS |
static int |
CUSTOM_TABLE_OF_CONTENTS |
static int |
CUSTOM_TABLES |
static int |
CUSTOM_TEXT_BOX |
static int |
CUSTOM_WATERMARKS |
static int |
DEFAULT
Same as
ALL. |
static int |
EQUATIONS |
static int |
FOOTERS |
static int |
HEADERS |
static int |
length |
static int |
NO_GALLERY |
static int |
PAGE_NUMBER |
static int |
PAGE_NUMBER_AT_BOTTOM |
static int |
PAGE_NUMBER_AT_MARGIN |
static int |
PAGE_NUMBER_AT_TOP |
static int |
QUICK_PARTS |
static int |
STRUCTURED_DOCUMENT_TAG_PLACEHOLDER_TEXT |
static int |
TABLE_OF_CONTENTS |
static int |
TABLES |
static int |
TEXT_BOX |
static int |
WATERMARKS |
| Modifier and Type | Method and Description |
|---|---|
static int |
fromName(java.lang.String buildingBlockGalleryName) |
static java.lang.String |
getName(int buildingBlockGallery) |
static int[] |
getValues() |
static java.lang.String |
toString(int buildingBlockGallery) |
public static int ALL
public static int AUTO_TEXT
public static int BIBLIOGRAPHY
public static int COVER_PAGE
public static int CUSTOM_AUTO_TEXT
public static int CUSTOM_BIBLIOGRAPHY
public static int CUSTOM_COVER_PAGE
public static int CUSTOM_EQUATIONS
public static int CUSTOM_FOOTERS
public static int CUSTOM_HEADERS
public static int CUSTOM_1
public static int CUSTOM_2
public static int CUSTOM_3
public static int CUSTOM_4
public static int CUSTOM_5
public static int CUSTOM_PAGE_NUMBER
public static int CUSTOM_PAGE_NUMBER_AT_BOTTOM
public static int CUSTOM_PAGE_NUMBER_AT_MARGIN
public static int CUSTOM_PAGE_NUMBER_AT_TOP
public static int CUSTOM_QUICK_PARTS
public static int CUSTOM_TABLE_OF_CONTENTS
public static int CUSTOM_TABLES
public static int CUSTOM_TEXT_BOX
public static int CUSTOM_WATERMARKS
public static int NO_GALLERY
public static int QUICK_PARTS
public static int EQUATIONS
public static int FOOTERS
public static int HEADERS
public static int PAGE_NUMBER
public static int PAGE_NUMBER_AT_BOTTOM
public static int PAGE_NUMBER_AT_MARGIN
public static int PAGE_NUMBER_AT_TOP
public static int STRUCTURED_DOCUMENT_TAG_PLACEHOLDER_TEXT
public static int TABLE_OF_CONTENTS
public static int TABLES
public static int TEXT_BOX
public static int WATERMARKS
public static int DEFAULT
ALL.public static int length