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: BasicLink.java 554094 2007-07-07 00:04:25Z adelmelle $ */
019:
020: package org.apache.fop.fo.flow;
021:
022: import org.xml.sax.Locator;
023:
024: import org.apache.fop.apps.FOPException;
025: import org.apache.fop.fo.FONode;
026: import org.apache.fop.fo.PropertyList;
027: import org.apache.fop.fo.ValidationException;
028:
029: /**
030: * The fo:basic-link formatting object.
031: *
032: * This class contains the logic to determine the link represented by this FO,
033: * and whether that link is external (uses a URI) or internal (an id
034: * reference).
035: */
036: public class BasicLink extends Inline {
037: // The value of properties relevant for fo:basic-link.
038: // private ToBeImplementedProperty destinationPlacementOffset;
039: private String externalDestination;
040: // private ToBeImplementedProperty indicateDestination;
041: private String internalDestination;
042: // private ToBeImplementedProperty showDestination;
043: // private ToBeImplementedProperty targetProcessingContext;
044: // private ToBeImplementedProperty targetPresentationContext;
045: // private ToBeImplementedProperty targetStylesheet;
046: // Unused but valid items, commented out for performance:
047: // private int dominantBaseline;
048: // End of property values
049:
050: // used only for FO validation
051: private boolean blockOrInlineItemFound = false;
052:
053: /**
054: * @param parent FONode that is the parent of this object
055: */
056: public BasicLink(FONode parent) {
057: super (parent);
058: }
059:
060: /**
061: * @see org.apache.fop.fo.FObj#bind(PropertyList)
062: */
063: public void bind(PropertyList pList) throws FOPException {
064: super .bind(pList);
065: // destinationPlacementOffset = pList.get(PR_DESTINATION_PLACEMENT_OFFSET);
066: externalDestination = pList.get(PR_EXTERNAL_DESTINATION)
067: .getString();
068: // indicateDestination = pList.get(PR_INDICATE_DESTINATION);
069: internalDestination = pList.get(PR_INTERNAL_DESTINATION)
070: .getString();
071: // showDestination = pList.get(PR_SHOW_DESTINATION);
072: // targetProcessingContext = pList.get(PR_TARGET_PROCESSING_CONTEXT);
073: // targetPresentationContext = pList.get(PR_TARGET_PRESENTATION_CONTEXT);
074: // targetStylesheet = pList.get(PR_TARGET_STYLESHEET);
075:
076: // per spec, internal takes precedence if both specified
077: if (internalDestination.length() > 0) {
078: externalDestination = null;
079: } else if (externalDestination.length() == 0) {
080: // slightly stronger than spec "should be specified"
081: attributeError("Missing attribute: Either external-destination or "
082: + "internal-destination must be specified.");
083: }
084: }
085:
086: /**
087: * @see org.apache.fop.fo.FONode#startOfNode
088: */
089: protected void startOfNode() throws FOPException {
090: super .startOfNode();
091: getFOEventHandler().startLink(this );
092: }
093:
094: /**
095: * @see org.apache.fop.fo.FONode#endOfNode
096: */
097: protected void endOfNode() throws FOPException {
098: super .endOfNode();
099: getFOEventHandler().endLink();
100: }
101:
102: /**
103: * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
104: * XSL Content Model: marker* (#PCDATA|%inline;|%block;)*
105: */
106: protected void validateChildNode(Locator loc, String nsURI,
107: String localName) throws ValidationException {
108: if (FO_URI.equals(nsURI) && localName.equals("marker")) {
109: if (blockOrInlineItemFound) {
110: nodesOutOfOrderError(loc, "fo:marker",
111: "(#PCDATA|%inline;|%block;)");
112: }
113: } else if (!isBlockOrInlineItem(nsURI, localName)) {
114: invalidChildError(loc, nsURI, localName);
115: } else {
116: blockOrInlineItemFound = true;
117: }
118: }
119:
120: /**
121: * @return the "internal-destination" property.
122: */
123: public String getInternalDestination() {
124: return internalDestination;
125: }
126:
127: /**
128: * @return the "external-destination" property.
129: */
130: public String getExternalDestination() {
131: return externalDestination;
132: }
133:
134: /**
135: * @return whether or not this basic link has an internal destination or not
136: */
137: public boolean hasInternalDestination() {
138: return internalDestination != null
139: && internalDestination.length() > 0;
140: }
141:
142: /**
143: * @return whether or not this basic link has an external destination or not
144: */
145: public boolean hasExternalDestination() {
146: return externalDestination != null
147: && externalDestination.length() > 0;
148: }
149:
150: /** @see org.apache.fop.fo.FObj#getLocalName() */
151: public String getLocalName() {
152: return "basic-link";
153: }
154:
155: /** @see org.apache.fop.fo.FObj#getNameId() */
156: public int getNameId() {
157: return FO_BASIC_LINK;
158: }
159: }
|