Implementing template maps

Developers perform this task.

Exporting content from Brightspot to InDesign requires mapping Brightspot fields to InDesign tags. Work with your designer to understand the following:

  • Which InDesign documents will be importing content
  • Which Brightspot content types will be imported
  • Which objects in InDesign documents will be receiving content from which Brightspot fields
  • Tag names for those objects

With this understanding, you can model the InDesignDocument and InDesignTag content types that perform the export from Brightspot.

Brightspot provides sample classes NewspaperInDesignDocument.java and SmartBriefInDesignDocument.java that illustrate mapping between Brightspot fields and InDesign tags. You can find these classes in the directory brightspot/express/poc/src/main/java/brightspot/indesign/. These classes, and any class that maps between Brightspot and InDesign, require understanding the Brightspot classes InDesignDocument and InDesignTag.

InDesignDocument

Classes that extend InDesignDocument export content from Brightspot to an InDesign document. These classes must implement the getTags() method. Editors open InDesignDocument subclasses in Brightspot to synchronize content as described in Using InDesign with Brightspot.

The following snippet is an example of extending InDesignDocument to export fields from Brightspot articles to a tagged InDesign document.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import com.psddev.indesign.InDesignDocument;

public class WeeklyNewsletterCover extends InDesignDocument {

    private Article featuredArticle;
    private Article secondaryArticle;
    private Image mainImage;

    /* getters and setters */

    public List<InDesignTag> getTags() {
        List<InDesignTag> tags = new ArrayList<>();
        if (featuredArticle != null) {
            tags.add(new FieldDocumentTag("featuredHeadline", featuredArticle, "headline"));
            tags.add(new ImageDocumentTag("featuredImage", featuredArticle.getImage()));
        }
        if (secondaryArticle != null) {
            tags.add(new FieldDocumentTag("secondHeadline", secondaryArticle, "headline"));
        }
        if (mainImage != null) {
            tags.add(new ImageDocumentTag("mainImage", mainImage));
        }
        return tags;
    }
}

In the previous snippet—

  • Lines 5–7 declare the Article and Image content types exported to InDesign.
  • Lines 11–24 implement the getTags method. For each Article and Image instance, this method maps Brightspot fields to a corresponding InDesign tag. For example, in line 14, data from the Brightspot headline field is mapped to the InDesign featuredHeadline tag.
  • Lines 14, 15, 18, and 21 illustrate the instantiation of InDesign tags within Brightspot. InDesign tag data is represented by a tag class (such as FieldDocumentTag and ImageDocumentTag) that extends InDesignTag.

InDesignTag

Subclasses of InDesignTag map Brightspot field values to the corresponding tag in an InDesign file. The map is a JSON file that InDesign can read. The tag field’s value corresponds to the name of a tagged object on the InDesign file, typically a text frame or a rectangle.

In the following snippet, featuredHeadline corresponds to the name of a tagged container in InDesign, and headline corresponds to the internal name of a Brightspot field.

tags.add(new FieldDocumentTag("featuredHeadline", featuredArticle, "headline"));

Warning

Multiple InDesign objects with the same tag may cause the import from Brightspot to fail. Ensure the InDesign file’s objects have unique tags.

For additional information about how InDesign uses tags and the corresponding XML structure, see Tag content for XML.

Brightspot includes several InDesignTag subclasses, and you can create your own custom subclasses. Below is an example of extending InDesignTag to map an image with custom values.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import com.psddev.indesign.InDesignTag;

public class ImageInDesignTag extends InDesignTag {

    @Required
    private Image image;
    private String style;

    public ImageTag(String tag, Image image) {
        this.tag = tag;
        this.image = image;
    }

    @Override
    public String getType() {
        return "image";
    }

    @Override
    protected Map<String, String> getTagValues() {
        Map<String, String> values = new HashMap<>();
        if (image != null) {
            StorageItem file = image.getFile();
            if (file != null) {
                values.put("contents", file.getPublicUrl());
                values.put("imageSizes", image.getSizes());
                values.put("caption", image.getCaption());
                if (style != null) {
                    values.put("imageStyle", style);
                }
            }
        }
        return values;
    }
}

In the previous snippet, lines 19–34 implement the getTagValues method. Values of the Brightspot Image object are retrieved and set on InDesign values, such as imageSizes.

See also: