aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/apache/fop/fo/pagination/PageMasterReference.java
blob: 05300a065e3d71e830a91a9e9a284b77b5be5af3 (plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * $Id$
 * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
 * For details on use and redistribution please refer to the
 * LICENSE file included with these sources.
 */

package org.apache.fop.fo.pagination;

import org.apache.fop.fo.*;
import org.apache.fop.fo.properties.*;
import org.apache.fop.apps.FOPException;

/**
 * Base PageMasterReference class. Provides implementation for handling the
 * master-name attribute and containment within a PageSequenceMaster
 */
public abstract class PageMasterReference extends FObj
    implements SubSequenceSpecifier {

    private String _masterName;
    private PageSequenceMaster _pageSequenceMaster;

    public PageMasterReference(FObj parent, PropertyList propertyList)
            throws FOPException {
        super(parent, propertyList);
        this.name = getElementName();
        if (getProperty("master-name") != null) {
            setMasterName(getProperty("master-name").getString());
        }
        validateParent(parent);

    }

    protected void setMasterName(String masterName) {
        _masterName = masterName;
    }

    /**
     * Returns the "master-name" attribute of this page master reference
     */
    public String getMasterName() {
        return _masterName;
    }

    protected void setPageSequenceMaster(PageSequenceMaster pageSequenceMaster) {
        _pageSequenceMaster = pageSequenceMaster;
    }

    protected PageSequenceMaster getPageSequenceMaster() {
        return _pageSequenceMaster;
    }

    public abstract String getNextPageMaster(int currentPageNumber,
                                             boolean thisIsFirstPage,
                                             boolean isEmptyPage);

    /**
     * Gets the formating object name for this object. Subclasses must provide this.
     *
     * @return the element name of this reference. e.g. fo:repeatable-page-master-reference
     */
    protected abstract String getElementName();

    /**
     * Checks that the parent is the right element. The default implementation
     * checks for fo:page-sequence-master
     */
    protected void validateParent(FObj parent) throws FOPException {
        if (parent.getName().equals("fo:page-sequence-master")) {
            _pageSequenceMaster = (PageSequenceMaster)parent;

            if (getMasterName() == null) {
                log.warn("" + getElementName()
                                       + " does not have a master-name and so is being ignored");
            } else {
                _pageSequenceMaster.addSubsequenceSpecifier(this);
            }
        } else {
            throw new FOPException(getElementName() + " must be"
                                   + "child of fo:page-sequence-master, not "
                                   + parent.getName());
        }
    }

    public abstract void reset();




}