1 /*
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
922 href.startsWith("#")) {
923 String baseFile = base.getFile();
924 String newFile = u.getFile();
925 if (baseFile != null && newFile != null &&
926 !newFile.startsWith(baseFile)) {
927 u = new URL(base, baseFile + href);
928 }
929 }
930 } catch (MalformedURLException m) {
931 u = null;
932 }
933 HyperlinkEvent linkEvent;
934
935 if (!hdoc.isFrameDocument()) {
936 linkEvent = new HyperlinkEvent(
937 html, HyperlinkEvent.EventType.ACTIVATED, u, href,
938 element, mouseEvent);
939 } else {
940 String target = (anchor != null) ?
941 (String)anchor.getAttribute(HTML.Attribute.TARGET) : null;
942 if ((target == null) || (target.equals(""))) {
943 target = hdoc.getBaseTarget();
944 }
945 if ((target == null) || (target.equals(""))) {
946 target = "_self";
947 }
948 linkEvent = new HTMLFrameHyperlinkEvent(
949 html, HyperlinkEvent.EventType.ACTIVATED, u, href,
950 element, mouseEvent, target);
951 }
952 return linkEvent;
953 }
954
955 void fireEvents(JEditorPane editor, HTMLDocument doc, String href,
956 Element lastElem, MouseEvent mouseEvent) {
957 if (this.href != null) {
958 // fire an exited event on the old link
959 URL u;
960 try {
961 u = new URL(doc.getBase(), this.href);
962 } catch (MalformedURLException m) {
963 u = null;
964 }
965 HyperlinkEvent exit = new HyperlinkEvent(editor,
|
1 /*
2 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
922 href.startsWith("#")) {
923 String baseFile = base.getFile();
924 String newFile = u.getFile();
925 if (baseFile != null && newFile != null &&
926 !newFile.startsWith(baseFile)) {
927 u = new URL(base, baseFile + href);
928 }
929 }
930 } catch (MalformedURLException m) {
931 u = null;
932 }
933 HyperlinkEvent linkEvent;
934
935 if (!hdoc.isFrameDocument()) {
936 linkEvent = new HyperlinkEvent(
937 html, HyperlinkEvent.EventType.ACTIVATED, u, href,
938 element, mouseEvent);
939 } else {
940 String target = (anchor != null) ?
941 (String)anchor.getAttribute(HTML.Attribute.TARGET) : null;
942 if (target == null || target.isEmpty()) {
943 target = hdoc.getBaseTarget();
944 }
945 if (target == null || target.isEmpty()) {
946 target = "_self";
947 }
948 linkEvent = new HTMLFrameHyperlinkEvent(
949 html, HyperlinkEvent.EventType.ACTIVATED, u, href,
950 element, mouseEvent, target);
951 }
952 return linkEvent;
953 }
954
955 void fireEvents(JEditorPane editor, HTMLDocument doc, String href,
956 Element lastElem, MouseEvent mouseEvent) {
957 if (this.href != null) {
958 // fire an exited event on the old link
959 URL u;
960 try {
961 u = new URL(doc.getBase(), this.href);
962 } catch (MalformedURLException m) {
963 u = null;
964 }
965 HyperlinkEvent exit = new HyperlinkEvent(editor,
|