01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: BasicLinkLayoutManager.java 554094 2007-07-07 00:04:25Z adelmelle $ */
19:
20: package org.apache.fop.layoutmgr.inline;
21:
22: import org.apache.fop.datatypes.URISpecification;
23: import org.apache.fop.fo.flow.BasicLink;
24: import org.apache.fop.layoutmgr.LayoutManager;
25: import org.apache.fop.layoutmgr.PageSequenceLayoutManager;
26: import org.apache.fop.area.inline.InlineArea;
27: import org.apache.fop.area.Trait;
28: import org.apache.fop.area.LinkResolver;
29:
30: /**
31: * LayoutManager for the fo:basic-link formatting object
32: */
33: public class BasicLinkLayoutManager extends InlineLayoutManager {
34: private BasicLink fobj;
35:
36: /**
37: * Create an fo:basic-link layout manager.
38: *
39: * @param node the formatting object that creates the area
40: */
41: public BasicLinkLayoutManager(BasicLink node) {
42: super (node);
43: fobj = node;
44: }
45:
46: /** @see org.apache.fop.layoutmgr.inline.InlineLayoutManager#createArea(boolean) */
47: protected InlineArea createArea(boolean bInlineParent) {
48: InlineArea area = super .createArea(bInlineParent);
49: setupBasicLinkArea(parentLM, area);
50: return area;
51: }
52:
53: /*
54: * Detect internal or external link and add it as an area trait
55: *
56: * @param parentLM the parent LayoutManager
57: * @param area the basic-link's area
58: */
59: private void setupBasicLinkArea(LayoutManager parentLM,
60: InlineArea area) {
61: // internal destinations take precedence:
62: if (fobj.hasInternalDestination()) {
63: String idref = fobj.getInternalDestination();
64: PageSequenceLayoutManager pslm = getPSLM();
65: // the INTERNAL_LINK trait is added by the LinkResolver
66: // if and when the link is resolved:
67: LinkResolver res = new LinkResolver(idref, area);
68: res.resolveIDRef(idref, pslm.getFirstPVWithID(idref));
69: if (!res.isResolved()) {
70: pslm.addUnresolvedArea(idref, res);
71: }
72: } else if (fobj.hasExternalDestination()) {
73: String url = URISpecification.getURL(fobj
74: .getExternalDestination());
75: if (url.length() > 0) {
76: area.addTrait(Trait.EXTERNAL_LINK, url);
77: }
78: }
79: }
80: }
|