java.lang.Object
com.aspose.words.BuildingBlockGallery
public class BuildingBlockGallery
- extends java.lang.Object
Utility class containing constants.
Specifies the predefined gallery into which a building block is classified.
Corresponds to the ST_DocPartGallery type in OOXML.
Example:
Shows ways of accessing building blocks in a glossary document.
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());
// 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) {
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;
}
- See Also:
- BuildingBlock.Gallery
ALL = 0 | |
public static final int ALL |
-
Specifies that this glossary document entry shall be associated with all possible gallery classification values.
AUTO_TEXT = 1 | |
public static final int AUTO_TEXT |
-
BIBLIOGRAPHY = 2 | |
public static final int BIBLIOGRAPHY |
-
COVER_PAGE = 3 | |
public static final int COVER_PAGE |
-
CUSTOM_AUTO_TEXT = 4 | |
public static final int CUSTOM_AUTO_TEXT |
-
CUSTOM_BIBLIOGRAPHY = 5 | |
public static final int CUSTOM_BIBLIOGRAPHY |
-
CUSTOM_COVER_PAGE = 6 | |
public static final int CUSTOM_COVER_PAGE |
-
CUSTOM_EQUATIONS = 7 | |
public static final int CUSTOM_EQUATIONS |
-
CUSTOM_FOOTERS = 8 | |
public static final int CUSTOM_FOOTERS |
-
CUSTOM_HEADERS = 9 | |
public static final int CUSTOM_HEADERS |
-
CUSTOM_1 = 10 | |
public static final int CUSTOM_1 |
-
CUSTOM_2 = 11 | |
public static final int CUSTOM_2 |
-
CUSTOM_3 = 12 | |
public static final int CUSTOM_3 |
-
CUSTOM_4 = 13 | |
public static final int CUSTOM_4 |
-
CUSTOM_5 = 14 | |
public static final int CUSTOM_5 |
-
CUSTOM_PAGE_NUMBER = 15 | |
public static final int CUSTOM_PAGE_NUMBER |
-
CUSTOM_PAGE_NUMBER_AT_BOTTOM = 16 | |
public static final int CUSTOM_PAGE_NUMBER_AT_BOTTOM |
-
CUSTOM_PAGE_NUMBER_AT_MARGIN = 17 | |
public static final int CUSTOM_PAGE_NUMBER_AT_MARGIN |
-
CUSTOM_PAGE_NUMBER_AT_TOP = 18 | |
public static final int CUSTOM_PAGE_NUMBER_AT_TOP |
-
CUSTOM_QUICK_PARTS = 19 | |
public static final int CUSTOM_QUICK_PARTS |
-
CUSTOM_TABLE_OF_CONTENTS = 20 | |
public static final int CUSTOM_TABLE_OF_CONTENTS |
-
CUSTOM_TABLES = 21 | |
public static final int CUSTOM_TABLES |
-
CUSTOM_TEXT_BOX = 22 | |
public static final int CUSTOM_TEXT_BOX |
-
CUSTOM_WATERMARKS = 23 | |
public static final int CUSTOM_WATERMARKS |
-
NO_GALLERY = 24 | |
public static final int NO_GALLERY |
-
QUICK_PARTS = 25 | |
public static final int QUICK_PARTS |
-
EQUATIONS = 26 | |
public static final int EQUATIONS |
-
FOOTERS = 27 | |
public static final int FOOTERS |
-
HEADERS = 28 | |
public static final int HEADERS |
-
PAGE_NUMBER = 29 | |
public static final int PAGE_NUMBER |
-
PAGE_NUMBER_AT_BOTTOM = 30 | |
public static final int PAGE_NUMBER_AT_BOTTOM |
-
PAGE_NUMBER_AT_MARGIN = 31 | |
public static final int PAGE_NUMBER_AT_MARGIN |
-
PAGE_NUMBER_AT_TOP = 32 | |
public static final int PAGE_NUMBER_AT_TOP |
-
STRUCTURED_DOCUMENT_TAG_PLACEHOLDER_TEXT = 33 | |
public static final int STRUCTURED_DOCUMENT_TAG_PLACEHOLDER_TEXT |
-
TABLE_OF_CONTENTS = 34 | |
public static final int TABLE_OF_CONTENTS |
-
TABLES = 35 | |
public static final int TABLES |
-
TEXT_BOX = 36 | |
public static final int TEXT_BOX |
-
WATERMARKS = 37 | |
public static final int WATERMARKS |
-
DEFAULT = 0 | |
public static final int DEFAULT |
-
Same as ALL.
See Also:
Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
Aspose.Words Support Forum - our preferred method of support.