KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > fo > pagination > bookmarks > Bookmark


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id $ */
19
20 package org.apache.fop.fo.pagination.bookmarks;
21
22 import java.util.ArrayList JavaDoc;
23 import org.xml.sax.Locator JavaDoc;
24 import org.apache.fop.apps.FOPException;
25 import org.apache.fop.fo.FObj;
26 import org.apache.fop.fo.FONode;
27 import org.apache.fop.fo.PropertyList;
28 import org.apache.fop.fo.ValidationException;
29 import org.apache.fop.fo.properties.CommonAccessibility;
30
31
32 /**
33  * The fo:bookmark formatting object, first introduced in the
34  * XSL 1.1 WD. Prototype version only, subject to change as
35  * XSL 1.1 WD evolves.
36  */

37 public class Bookmark extends FObj {
38     private BookmarkTitle bookmarkTitle;
39     private ArrayList JavaDoc childBookmarks = new ArrayList JavaDoc();
40
41     // The value of properties relevant for this FO
42
private CommonAccessibility commonAccessibility;
43     private String JavaDoc internalDestination;
44     private String JavaDoc externalDestination;
45     private boolean bShow = true; // from starting-state property
46

47     /**
48      * Create a new bookmark object.
49      *
50      * @param parent the parent fo node
51      */

52     public Bookmark(FONode parent) {
53         super(parent);
54     }
55
56     /**
57      * @see org.apache.fop.fo.FObj#bind(PropertyList)
58      */

59     public void bind(PropertyList pList) throws FOPException {
60         commonAccessibility = pList.getAccessibilityProps();
61         externalDestination = pList.get(PR_EXTERNAL_DESTINATION).getString();
62         internalDestination = pList.get(PR_INTERNAL_DESTINATION).getString();
63         bShow = (pList.get(PR_STARTING_STATE).getEnum() == EN_SHOW);
64
65         // per spec, internal takes precedence if both specified
66
if (internalDestination.length() > 0) {
67             externalDestination = null;
68         } else if (externalDestination.length() == 0) {
69             // slightly stronger than spec "should be specified"
70
attributeError("Missing attribute: Either external-destination or " +
71                 "internal-destination must be specified.");
72         } else {
73             attributeWarning("external-destination property not currently supported");
74         }
75     }
76
77     /**
78      * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
79         XSL/FOP: (bookmark-title, bookmark*)
80      */

81     protected void validateChildNode(Locator JavaDoc loc, String JavaDoc nsURI, String JavaDoc localName)
82         throws ValidationException {
83             if (FO_URI.equals(nsURI) && localName.equals("bookmark-title")) {
84                 if (bookmarkTitle != null) {
85                     tooManyNodesError(loc, "fo:bookmark-title");
86                 }
87             } else if (FO_URI.equals(nsURI) && localName.equals("bookmark")) {
88                 if (bookmarkTitle == null) {
89                     nodesOutOfOrderError(loc, "fo:bookmark-title", "fo:bookmark");
90                 }
91             } else {
92                 invalidChildError(loc, nsURI, localName);
93             }
94     }
95
96     /**
97      * @see org.apache.fop.fo.FONode#endOfNode
98      */

99     protected void endOfNode() throws FOPException {
100         if (bookmarkTitle == null) {
101            missingChildElementError("(bookmark-title, bookmark*)");
102         }
103     }
104
105     /**
106      * @see org.apache.fop.fo.FONode#addChildNode(FONode)
107      */

108     protected void addChildNode(FONode obj) {
109         if (obj instanceof BookmarkTitle) {
110             bookmarkTitle = (BookmarkTitle)obj;
111         } else if (obj instanceof Bookmark) {
112             childBookmarks.add(obj);
113         }
114     }
115
116     /**
117      * Get the bookmark title for this bookmark
118      *
119      * @return the bookmark title string or an empty string if not found
120      */

121     public String JavaDoc getBookmarkTitle() {
122         return bookmarkTitle == null ? "" : bookmarkTitle.getTitle();
123     }
124
125     public String JavaDoc getInternalDestination() {
126         return internalDestination;
127     }
128
129     public String JavaDoc getExternalDestination() {
130         return externalDestination;
131     }
132
133     /**
134      * Determines if this fo:bookmark's subitems should be initially displayed
135      * or hidden, based on the starting-state property set on this FO.
136      *
137      * @return true if this bookmark's starting-state is "show", false if "hide".
138      */

139     public boolean showChildItems() {
140         return bShow;
141     }
142
143     public ArrayList JavaDoc getChildBookmarks() {
144         return childBookmarks;
145     }
146
147     /** @see org.apache.fop.fo.FONode#getLocalName() */
148     public String JavaDoc getLocalName() {
149         return "bookmark";
150     }
151
152     /**
153      * @see org.apache.fop.fo.FObj#getNameId()
154      */

155     public int getNameId() {
156         return FO_BOOKMARK;
157     }
158 }
159
Popular Tags