You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BasicLinkLayoutManager.java 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. /* $Id$ */
  18. package org.apache.fop.layoutmgr.inline;
  19. import org.apache.fop.area.LinkResolver;
  20. import org.apache.fop.area.Trait;
  21. import org.apache.fop.area.inline.BasicLinkArea;
  22. import org.apache.fop.area.inline.InlineArea;
  23. import org.apache.fop.area.inline.InlineParent;
  24. import org.apache.fop.datatypes.URISpecification;
  25. import org.apache.fop.fo.Constants;
  26. import org.apache.fop.fo.flow.BasicLink;
  27. import org.apache.fop.layoutmgr.PageSequenceLayoutManager;
  28. import org.apache.fop.layoutmgr.TraitSetter;
  29. /**
  30. * LayoutManager for the fo:basic-link formatting object
  31. */
  32. public class BasicLinkLayoutManager extends InlineLayoutManager {
  33. /**
  34. * Create an fo:basic-link layout manager.
  35. *
  36. * @param node the formatting object that creates the area
  37. */
  38. public BasicLinkLayoutManager(BasicLink node) {
  39. super(node);
  40. }
  41. /** {@inheritDoc} */
  42. protected InlineArea createArea(boolean bInlineParent) {
  43. InlineArea area = super.createArea(bInlineParent);
  44. setupBasicLinkArea(area);
  45. return area;
  46. }
  47. /*
  48. * Detect internal or external link and add it as an area trait
  49. *
  50. * @param area the basic-link's area
  51. */
  52. private void setupBasicLinkArea(InlineArea area) {
  53. BasicLink fobj = (BasicLink) this.fobj;
  54. // internal destinations take precedence:
  55. TraitSetter.addStructureTreeElement(area, fobj.getStructureTreeElement());
  56. if (fobj.hasInternalDestination()) {
  57. String idref = fobj.getInternalDestination();
  58. PageSequenceLayoutManager pslm = getPSLM();
  59. // the INTERNAL_LINK trait is added by the LinkResolver
  60. // if and when the link is resolved:
  61. LinkResolver res = new LinkResolver(idref, area);
  62. res.resolveIDRef(idref, pslm.getFirstPVWithID(idref));
  63. if (!res.isResolved()) {
  64. pslm.addUnresolvedArea(idref, res);
  65. }
  66. } else if (fobj.hasExternalDestination()) {
  67. String url = URISpecification.getURL(fobj.getExternalDestination());
  68. boolean newWindow = (fobj.getShowDestination() == Constants.EN_NEW);
  69. if (url.length() > 0) {
  70. area.addTrait(Trait.EXTERNAL_LINK,
  71. new Trait.ExternalLink(url, newWindow));
  72. }
  73. }
  74. }
  75. @Override
  76. protected InlineParent createInlineParent() {
  77. return new BasicLinkArea();
  78. }
  79. }