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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.xslf.usermodel;
  16. import org.apache.poi.openxml4j.opc.PackageRelationship;
  17. import org.apache.poi.openxml4j.opc.TargetMode;
  18. import org.apache.poi.sl.usermodel.Hyperlink;
  19. import org.apache.poi.util.Internal;
  20. import org.openxmlformats.schemas.drawingml.x2006.main.CTHyperlink;
  21. import java.net.URI;
  22. public class XSLFHyperlink implements Hyperlink {
  23. final XSLFTextRun _r;
  24. final CTHyperlink _link;
  25. XSLFHyperlink(CTHyperlink link, XSLFTextRun r){
  26. _r = r;
  27. _link = link;
  28. }
  29. @Internal
  30. public CTHyperlink getXmlObject(){
  31. return _link;
  32. }
  33. @Override
  34. public void setAddress(String address){
  35. XSLFSheet sheet = _r.getParentParagraph().getParentShape().getSheet();
  36. PackageRelationship rel =
  37. sheet.getPackagePart().
  38. addExternalRelationship(address, XSLFRelation.HYPERLINK.getRelation());
  39. _link.setId(rel.getId());
  40. }
  41. @Override
  42. public String getAddress() {
  43. return getTargetURI().toASCIIString();
  44. }
  45. @Override
  46. public String getLabel() {
  47. return _link.getTooltip();
  48. }
  49. @Override
  50. public void setLabel(String label) {
  51. _link.setTooltip(label);
  52. }
  53. @Override
  54. public int getType() {
  55. // TODO: currently this just returns nonsense
  56. if ("ppaction://hlinksldjump".equals(_link.getAction())) {
  57. return LINK_DOCUMENT;
  58. }
  59. return LINK_URL;
  60. }
  61. public void setAddress(XSLFSlide slide){
  62. XSLFSheet sheet = _r.getParentParagraph().getParentShape().getSheet();
  63. PackageRelationship rel =
  64. sheet.getPackagePart().
  65. addRelationship(slide.getPackagePart().getPartName(),
  66. TargetMode.INTERNAL,
  67. XSLFRelation.SLIDE.getRelation());
  68. _link.setId(rel.getId());
  69. _link.setAction("ppaction://hlinksldjump");
  70. }
  71. @Internal
  72. public URI getTargetURI(){
  73. XSLFSheet sheet = _r.getParentParagraph().getParentShape().getSheet();
  74. String id = _link.getId();
  75. return sheet.getPackagePart().getRelationship(id).getTargetURI();
  76. }
  77. }