001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id $ */
019:
020: package org.apache.fop.fo.pagination.bookmarks;
021:
022: import java.util.ArrayList;
023: import org.xml.sax.Locator;
024: import org.apache.fop.apps.FOPException;
025: import org.apache.fop.fo.FObj;
026: import org.apache.fop.fo.FONode;
027: import org.apache.fop.fo.PropertyList;
028: import org.apache.fop.fo.ValidationException;
029: import org.apache.fop.fo.properties.CommonAccessibility;
030:
031: /**
032: * The fo:bookmark formatting object, first introduced in the
033: * XSL 1.1 WD. Prototype version only, subject to change as
034: * XSL 1.1 WD evolves.
035: */
036: public class Bookmark extends FObj {
037: private BookmarkTitle bookmarkTitle;
038: private ArrayList childBookmarks = new ArrayList();
039:
040: // The value of properties relevant for this FO
041: private CommonAccessibility commonAccessibility;
042: private String internalDestination;
043: private String externalDestination;
044: private boolean bShow = true; // from starting-state property
045:
046: /**
047: * Create a new bookmark object.
048: *
049: * @param parent the parent fo node
050: */
051: public Bookmark(FONode parent) {
052: super (parent);
053: }
054:
055: /**
056: * @see org.apache.fop.fo.FObj#bind(PropertyList)
057: */
058: public void bind(PropertyList pList) throws FOPException {
059: commonAccessibility = pList.getAccessibilityProps();
060: externalDestination = pList.get(PR_EXTERNAL_DESTINATION)
061: .getString();
062: internalDestination = pList.get(PR_INTERNAL_DESTINATION)
063: .getString();
064: bShow = (pList.get(PR_STARTING_STATE).getEnum() == EN_SHOW);
065:
066: // per spec, internal takes precedence if both specified
067: if (internalDestination.length() > 0) {
068: externalDestination = null;
069: } else if (externalDestination.length() == 0) {
070: // slightly stronger than spec "should be specified"
071: attributeError("Missing attribute: Either external-destination or "
072: + "internal-destination must be specified.");
073: } else {
074: attributeWarning("external-destination property not currently supported");
075: }
076: }
077:
078: /**
079: * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
080: XSL/FOP: (bookmark-title, bookmark*)
081: */
082: protected void validateChildNode(Locator loc, String nsURI,
083: String localName) throws ValidationException {
084: if (FO_URI.equals(nsURI) && localName.equals("bookmark-title")) {
085: if (bookmarkTitle != null) {
086: tooManyNodesError(loc, "fo:bookmark-title");
087: }
088: } else if (FO_URI.equals(nsURI) && localName.equals("bookmark")) {
089: if (bookmarkTitle == null) {
090: nodesOutOfOrderError(loc, "fo:bookmark-title",
091: "fo:bookmark");
092: }
093: } else {
094: invalidChildError(loc, nsURI, localName);
095: }
096: }
097:
098: /**
099: * @see org.apache.fop.fo.FONode#endOfNode
100: */
101: protected void endOfNode() throws FOPException {
102: if (bookmarkTitle == null) {
103: missingChildElementError("(bookmark-title, bookmark*)");
104: }
105: }
106:
107: /**
108: * @see org.apache.fop.fo.FONode#addChildNode(FONode)
109: */
110: protected void addChildNode(FONode obj) {
111: if (obj instanceof BookmarkTitle) {
112: bookmarkTitle = (BookmarkTitle) obj;
113: } else if (obj instanceof Bookmark) {
114: childBookmarks.add(obj);
115: }
116: }
117:
118: /**
119: * Get the bookmark title for this bookmark
120: *
121: * @return the bookmark title string or an empty string if not found
122: */
123: public String getBookmarkTitle() {
124: return bookmarkTitle == null ? "" : bookmarkTitle.getTitle();
125: }
126:
127: public String getInternalDestination() {
128: return internalDestination;
129: }
130:
131: public String getExternalDestination() {
132: return externalDestination;
133: }
134:
135: /**
136: * Determines if this fo:bookmark's subitems should be initially displayed
137: * or hidden, based on the starting-state property set on this FO.
138: *
139: * @return true if this bookmark's starting-state is "show", false if "hide".
140: */
141: public boolean showChildItems() {
142: return bShow;
143: }
144:
145: public ArrayList getChildBookmarks() {
146: return childBookmarks;
147: }
148:
149: /** @see org.apache.fop.fo.FONode#getLocalName() */
150: public String getLocalName() {
151: return "bookmark";
152: }
153:
154: /**
155: * @see org.apache.fop.fo.FObj#getNameId()
156: */
157: public int getNameId() {
158: return FO_BOOKMARK;
159: }
160: }
|