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.

URIAction.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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.render.intermediate.extensions;
  19. import org.xml.sax.ContentHandler;
  20. import org.xml.sax.SAXException;
  21. import org.xml.sax.helpers.AttributesImpl;
  22. import org.apache.fop.util.XMLUtil;
  23. /**
  24. * Action class which represents a "URI" action, i.e. an action that will call up an external
  25. * resource identified by a URI.
  26. */
  27. public class URIAction extends AbstractAction implements DocumentNavigationExtensionConstants {
  28. private String uri;
  29. private boolean newWindow;
  30. /**
  31. * Creates a new instance.
  32. * @param uri the target URI
  33. * @param newWindow true if the link should be opened in a new window
  34. */
  35. public URIAction(String uri, boolean newWindow) {
  36. if (uri == null) {
  37. throw new NullPointerException("uri must not be null");
  38. }
  39. this.uri = uri;
  40. this.newWindow = newWindow;
  41. setID(getIDPrefix() + (uri + newWindow).hashCode());
  42. }
  43. /**
  44. * Returns the target URI.
  45. * @return the target URI
  46. */
  47. public String getURI() {
  48. return this.uri;
  49. }
  50. /**
  51. * Indicates whether the link shall be opened in a new window.
  52. * @return true if a new window shall be opened
  53. */
  54. public boolean isNewWindow() {
  55. return this.newWindow;
  56. }
  57. /** {@inheritDoc} */
  58. public boolean isSame(AbstractAction other) {
  59. if (other == null) {
  60. throw new NullPointerException("other must not be null");
  61. }
  62. if (!(other instanceof URIAction)) {
  63. return false;
  64. }
  65. URIAction otherAction = (URIAction)other;
  66. if (!getURI().equals(otherAction.getURI())) {
  67. return false;
  68. }
  69. if (isNewWindow() != otherAction.isNewWindow()) {
  70. return false;
  71. }
  72. if (getStructureTreeElement() != null) {
  73. return getStructureTreeElement().equals(other.getStructureTreeElement());
  74. }
  75. return true;
  76. }
  77. /** {@inheritDoc} */
  78. public String getIDPrefix() {
  79. return "fop-" + GOTO_URI.getLocalName();
  80. }
  81. /** {@inheritDoc} */
  82. public void toSAX(ContentHandler handler) throws SAXException {
  83. AttributesImpl atts = new AttributesImpl();
  84. if (hasID()) {
  85. atts.addAttribute("", "id", "id", XMLUtil.CDATA, getID());
  86. }
  87. atts.addAttribute("", "uri", "uri", XMLUtil.CDATA, getURI());
  88. if (isNewWindow()) {
  89. atts.addAttribute("", "show-destination", "show-destination", XMLUtil.CDATA, "new");
  90. }
  91. handler.startElement(GOTO_URI.getNamespaceURI(),
  92. GOTO_URI.getLocalName(), GOTO_URI.getQName(), atts);
  93. handler.endElement(GOTO_URI.getNamespaceURI(),
  94. GOTO_URI.getLocalName(), GOTO_URI.getQName());
  95. }
  96. }