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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. }
  42. /**
  43. * Returns the target URI.
  44. * @return the target URI
  45. */
  46. public String getURI() {
  47. return this.uri;
  48. }
  49. /**
  50. * Indicates whether the link shall be opened in a new window.
  51. * @return true if a new window shall be opened
  52. */
  53. public boolean isNewWindow() {
  54. return this.newWindow;
  55. }
  56. /** {@inheritDoc} */
  57. public boolean isSame(AbstractAction other) {
  58. if (other == null) {
  59. throw new NullPointerException("other must not be null");
  60. }
  61. if (!(other instanceof URIAction)) {
  62. return false;
  63. }
  64. URIAction otherAction = (URIAction)other;
  65. if (!getURI().equals(otherAction.getURI())) {
  66. return false;
  67. }
  68. if (isNewWindow() != otherAction.isNewWindow()) {
  69. return false;
  70. }
  71. return true;
  72. }
  73. /** {@inheritDoc} */
  74. public String getIdPrefix() {
  75. return "fop-" + GOTO_URI.getLocalName();
  76. }
  77. /** {@inheritDoc} */
  78. public void toSAX(ContentHandler handler) throws SAXException {
  79. AttributesImpl atts = new AttributesImpl();
  80. if (hasId()) {
  81. atts.addAttribute(null, "id", "id", XMLUtil.CDATA, getId());
  82. }
  83. atts.addAttribute(null, "uri", "uri", XMLUtil.CDATA, getURI());
  84. if (isNewWindow()) {
  85. atts.addAttribute(null, "show-destination", "show-destination", XMLUtil.CDATA, "new");
  86. }
  87. handler.startElement(GOTO_URI.getNamespaceURI(),
  88. GOTO_URI.getLocalName(), GOTO_URI.getQName(), atts);
  89. handler.endElement(GOTO_URI.getNamespaceURI(),
  90. GOTO_URI.getLocalName(), GOTO_URI.getQName());
  91. }
  92. }