001package com.box.sdk;
002
003import java.text.ParseException;
004import java.util.Date;
005
006import com.eclipsesource.json.JsonObject;
007import com.eclipsesource.json.JsonValue;
008
009/**
010 * Represents a watermark.
011 * Watermarks are used to protect sensitive information in the Box account.
012 *
013 * @see <a href="https://docs.box.com/reference#watermarking">Watermarking</a>
014 */
015public class BoxWatermark extends BoxJSONObject {
016
017    /**
018     * Default imprint for watermarks.
019     */
020    public static final String WATERMARK_DEFAULT_IMPRINT = "default";
021
022    /**
023     * Json key for watermark.
024     * @see BoxWatermark#parseJSONMember(JsonObject.Member)
025     */
026    public static final String WATERMARK_JSON_KEY = "watermark";
027
028    /**
029     * Json key for created_at param.
030     * @see BoxWatermark#parseJSONMember(JsonObject.Member)
031     */
032    public static final String CREATED_AT_JSON_KEY = "created_at";
033
034    /**
035     * Json key for modified_at param.
036     * @see BoxWatermark#parseJSONMember(JsonObject.Member)
037     */
038    public static final String MODIFIED_AT_JSON_KEY = "modified_at";
039
040    /**
041     * Json key for watermark param.
042     */
043    public static final String WATERMARK_IMPRINT_JSON_KEY = "imprint";
044
045    /**
046     * @see #getCreatedAt()
047     */
048    private Date createdAt;
049
050    /**
051     * @see #getModifiedAt()
052     */
053    private Date modifiedAt;
054
055    /**
056     * Constructs an empty watermark object.
057     */
058    public BoxWatermark() {
059        super();
060    }
061
062    /**
063     * Constructs a watermark object by parsing information from a JSON string.
064     * @param  json the JSON string to parse.
065     */
066    public BoxWatermark(String json) {
067        super(json);
068    }
069
070    /**
071     * Constructs a watermark object using an already parsed JSON object.
072     * @param  jsonObject the parsed JSON object.
073     */
074    BoxWatermark(JsonObject jsonObject) {
075        super(jsonObject);
076    }
077
078    /**
079     * @return the time that the watermark was created.
080     */
081    public Date getCreatedAt() {
082        return this.createdAt;
083    }
084
085    /**
086     * @return the time that the watermark was last modified.
087     */
088    public Date getModifiedAt() {
089        return this.modifiedAt;
090    }
091
092    /**
093     * {@inheritDoc}
094     */
095    @Override
096    void parseJSONMember(JsonObject.Member member) {
097        super.parseJSONMember(member);
098        String memberName = member.getName();
099        JsonValue value = member.getValue();
100        if (memberName.equals(WATERMARK_JSON_KEY)) {
101            try {
102                this.createdAt = BoxDateFormat.parse(value.asObject().get(CREATED_AT_JSON_KEY).asString());
103                this.modifiedAt = BoxDateFormat.parse(value.asObject().get(MODIFIED_AT_JSON_KEY).asString());
104            } catch (ParseException e) {
105                assert false : "A ParseException indicates a bug in the SDK.";
106            }
107        }
108    }
109
110}