com.aspose.words

Class BuildingBlockGallery

  • 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 how to use GlossaryDocument and BuildingBlockCollection.
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 is a different ways how to get created building blocks
    Assert.assertEquals(glossaryDoc.getFirstBuildingBlock().getName(), "Block 1");
    Assert.assertEquals(glossaryDoc.getBuildingBlocks().get(1).getName(), "Block 2");
    Assert.assertEquals(glossaryDoc.getBuildingBlocks().toArray()[2].getName(), "Block 3");
    Assert.assertEquals(glossaryDoc.getLastBuildingBlock().getName(), "Block 5");

    // Get a block by gallery, category and name
    BuildingBlock block4 =
            glossaryDoc.getBuildingBlock(BuildingBlockGallery.ALL, "(Empty Category)", "Block 4");

    // All GUIDs are the same by default
    Assert.assertEquals(block4.getGuid().toString(), "00000000-0000-0000-0000-000000000000");

    // To be able to uniquely identify blocks by GUID, each GUID must be unique
    // We will do that using a custom visitor
    GlossaryDocVisitor visitor = new GlossaryDocVisitor();
    glossaryDoc.accept(visitor);

    Assert.assertEquals(visitor.getDictionary().size(), 5);

    System.out.println(visitor.getText());

    // We can find our new blocks in Microsoft Word 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>
/// Simple implementation of giving each building block in a glossary document a unique GUID. Implemented as a Visitor.
/// </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 documnent 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 HashMap<UUID, BuildingBlock> mBlocksByGuid;
    private StringBuilder mBuilder;
}
See Also:
BuildingBlock.Gallery

Field Summary
static final intALL = 0
Specifies that this glossary document entry shall be associated with all possible gallery classification values.
static final intAUTO_TEXT = 1
static final intBIBLIOGRAPHY = 2
static final intCOVER_PAGE = 3
static final intCUSTOM_AUTO_TEXT = 4
static final intCUSTOM_BIBLIOGRAPHY = 5
static final intCUSTOM_COVER_PAGE = 6
static final intCUSTOM_EQUATIONS = 7
static final intCUSTOM_FOOTERS = 8
static final intCUSTOM_HEADERS = 9
static final intCUSTOM_1 = 10
static final intCUSTOM_2 = 11
static final intCUSTOM_3 = 12
static final intCUSTOM_4 = 13
static final intCUSTOM_5 = 14
static final intCUSTOM_PAGE_NUMBER = 15
static final intCUSTOM_PAGE_NUMBER_AT_BOTTOM = 16
static final intCUSTOM_PAGE_NUMBER_AT_MARGIN = 17
static final intCUSTOM_PAGE_NUMBER_AT_TOP = 18
static final intCUSTOM_QUICK_PARTS = 19
static final intCUSTOM_TABLE_OF_CONTENTS = 20
static final intCUSTOM_TABLES = 21
static final intCUSTOM_TEXT_BOX = 22
static final intCUSTOM_WATERMARKS = 23
static final intNO_GALLERY = 24
static final intQUICK_PARTS = 25
static final intEQUATIONS = 26
static final intFOOTERS = 27
static final intHEADERS = 28
static final intPAGE_NUMBER = 29
static final intPAGE_NUMBER_AT_BOTTOM = 30
static final intPAGE_NUMBER_AT_MARGIN = 31
static final intPAGE_NUMBER_AT_TOP = 32
static final intSTRUCTURED_DOCUMENT_TAG_PLACEHOLDER_TEXT = 33
static final intTABLE_OF_CONTENTS = 34
static final intTABLES = 35
static final intTEXT_BOX = 36
static final intWATERMARKS = 37
static final intDEFAULT = 0
Same as ALL.
 

    • Field Detail

      • 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.