1 /*
2 * Copyright (c) 1997, 2014, 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
709 }
710
711 /**
712 * Fetches a stream for the given URL, which is about to
713 * be loaded by the <code>setPage</code> method. By
714 * default, this simply opens the URL and returns the
715 * stream. This can be reimplemented to do useful things
716 * like fetch the stream from a cache, monitor the progress
717 * of the stream, etc.
718 * <p>
719 * This method is expected to have the side effect of
720 * establishing the content type, and therefore setting the
721 * appropriate <code>EditorKit</code> to use for loading the stream.
722 * <p>
723 * If this the stream was an http connection, redirects
724 * will be followed and the resulting URL will be set as
725 * the <code>Document.StreamDescriptionProperty</code> so that relative
726 * URL's can be properly resolved.
727 *
728 * @param page the URL of the page
729 */
730 protected InputStream getStream(URL page) throws IOException {
731 final URLConnection conn = page.openConnection();
732 if (conn instanceof HttpURLConnection) {
733 HttpURLConnection hconn = (HttpURLConnection) conn;
734 hconn.setInstanceFollowRedirects(false);
735 Object postData = getPostData();
736 if (postData != null) {
737 handlePostData(hconn, postData);
738 }
739 int response = hconn.getResponseCode();
740 boolean redirect = (response >= 300 && response <= 399);
741
742 /*
743 * In the case of a redirect, we want to actually change the URL
744 * that was input to the new, redirected URL
745 */
746 if (redirect) {
747 String loc = conn.getHeaderField("Location");
748 if (loc.startsWith("http", 0)) {
1695 /**
1696 * This class provides support for <code>AccessibleHypertext</code>,
1697 * and is used in instances where the <code>EditorKit</code>
1698 * installed in this <code>JEditorPane</code> is an instance of
1699 * <code>HTMLEditorKit</code>.
1700 * <p>
1701 * <strong>Warning:</strong>
1702 * Serialized objects of this class will not be compatible with
1703 * future Swing releases. The current serialization support is
1704 * appropriate for short term storage or RMI between applications running
1705 * the same version of Swing. As of 1.4, support for long term storage
1706 * of all JavaBeans™
1707 * has been added to the <code>java.beans</code> package.
1708 * Please see {@link java.beans.XMLEncoder}.
1709 */
1710 @SuppressWarnings("serial") // Same-version serialization only
1711 protected class AccessibleJEditorPaneHTML extends AccessibleJEditorPane {
1712
1713 private AccessibleContext accessibleContext;
1714
1715 public AccessibleText getAccessibleText() {
1716 return new JEditorPaneAccessibleHypertextSupport();
1717 }
1718
1719 protected AccessibleJEditorPaneHTML () {
1720 HTMLEditorKit kit = (HTMLEditorKit)JEditorPane.this.getEditorKit();
1721 accessibleContext = kit.getAccessibleContext();
1722 }
1723
1724 /**
1725 * Returns the number of accessible children of the object.
1726 *
1727 * @return the number of accessible children of the object.
1728 */
1729 public int getAccessibleChildrenCount() {
1730 if (accessibleContext != null) {
1731 return accessibleContext.getAccessibleChildrenCount();
1732 } else {
1733 return 0;
1734 }
1735 }
1736
1737 /**
1738 * Returns the specified Accessible child of the object. The Accessible
1774 return null;
1775 }
1776 } else {
1777 return null;
1778 }
1779 }
1780 }
1781
1782 /**
1783 * What's returned by
1784 * <code>AccessibleJEditorPaneHTML.getAccessibleText</code>.
1785 *
1786 * Provides support for <code>AccessibleHypertext</code> in case
1787 * there is an HTML document being displayed in this
1788 * <code>JEditorPane</code>.
1789 *
1790 */
1791 protected class JEditorPaneAccessibleHypertextSupport
1792 extends AccessibleJEditorPane implements AccessibleHypertext {
1793
1794 public class HTMLLink extends AccessibleHyperlink {
1795 Element element;
1796
1797 public HTMLLink(Element e) {
1798 element = e;
1799 }
1800
1801 /**
1802 * Since the document a link is associated with may have
1803 * changed, this method returns whether this Link is valid
1804 * anymore (with respect to the document it references).
1805 *
1806 * @return a flag indicating whether this link is still valid with
1807 * respect to the AccessibleHypertext it belongs to
1808 */
1809 public boolean isValid() {
1810 return JEditorPaneAccessibleHypertextSupport.this.linksValid;
1811 }
1812
1813 /**
1814 * Returns the number of accessible actions available in this Link
1815 * If there are more than one, the first one is NOT considered the
1816 * "default" action of this LINK object (e.g. in an HTML imagemap).
|
1 /*
2 * Copyright (c) 1997, 2015, 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
709 }
710
711 /**
712 * Fetches a stream for the given URL, which is about to
713 * be loaded by the <code>setPage</code> method. By
714 * default, this simply opens the URL and returns the
715 * stream. This can be reimplemented to do useful things
716 * like fetch the stream from a cache, monitor the progress
717 * of the stream, etc.
718 * <p>
719 * This method is expected to have the side effect of
720 * establishing the content type, and therefore setting the
721 * appropriate <code>EditorKit</code> to use for loading the stream.
722 * <p>
723 * If this the stream was an http connection, redirects
724 * will be followed and the resulting URL will be set as
725 * the <code>Document.StreamDescriptionProperty</code> so that relative
726 * URL's can be properly resolved.
727 *
728 * @param page the URL of the page
729 * @return a stream for the URL which is about to be loaded
730 * @throws IOException if an I/O problem occurs
731 */
732 protected InputStream getStream(URL page) throws IOException {
733 final URLConnection conn = page.openConnection();
734 if (conn instanceof HttpURLConnection) {
735 HttpURLConnection hconn = (HttpURLConnection) conn;
736 hconn.setInstanceFollowRedirects(false);
737 Object postData = getPostData();
738 if (postData != null) {
739 handlePostData(hconn, postData);
740 }
741 int response = hconn.getResponseCode();
742 boolean redirect = (response >= 300 && response <= 399);
743
744 /*
745 * In the case of a redirect, we want to actually change the URL
746 * that was input to the new, redirected URL
747 */
748 if (redirect) {
749 String loc = conn.getHeaderField("Location");
750 if (loc.startsWith("http", 0)) {
1697 /**
1698 * This class provides support for <code>AccessibleHypertext</code>,
1699 * and is used in instances where the <code>EditorKit</code>
1700 * installed in this <code>JEditorPane</code> is an instance of
1701 * <code>HTMLEditorKit</code>.
1702 * <p>
1703 * <strong>Warning:</strong>
1704 * Serialized objects of this class will not be compatible with
1705 * future Swing releases. The current serialization support is
1706 * appropriate for short term storage or RMI between applications running
1707 * the same version of Swing. As of 1.4, support for long term storage
1708 * of all JavaBeans™
1709 * has been added to the <code>java.beans</code> package.
1710 * Please see {@link java.beans.XMLEncoder}.
1711 */
1712 @SuppressWarnings("serial") // Same-version serialization only
1713 protected class AccessibleJEditorPaneHTML extends AccessibleJEditorPane {
1714
1715 private AccessibleContext accessibleContext;
1716
1717 /**
1718 * Returns the accessible text.
1719 * @return the accessible text
1720 */
1721 public AccessibleText getAccessibleText() {
1722 return new JEditorPaneAccessibleHypertextSupport();
1723 }
1724
1725 /**
1726 * Constructs an {@code AccessibleJEditorPaneHTML}.
1727 */
1728 protected AccessibleJEditorPaneHTML () {
1729 HTMLEditorKit kit = (HTMLEditorKit)JEditorPane.this.getEditorKit();
1730 accessibleContext = kit.getAccessibleContext();
1731 }
1732
1733 /**
1734 * Returns the number of accessible children of the object.
1735 *
1736 * @return the number of accessible children of the object.
1737 */
1738 public int getAccessibleChildrenCount() {
1739 if (accessibleContext != null) {
1740 return accessibleContext.getAccessibleChildrenCount();
1741 } else {
1742 return 0;
1743 }
1744 }
1745
1746 /**
1747 * Returns the specified Accessible child of the object. The Accessible
1783 return null;
1784 }
1785 } else {
1786 return null;
1787 }
1788 }
1789 }
1790
1791 /**
1792 * What's returned by
1793 * <code>AccessibleJEditorPaneHTML.getAccessibleText</code>.
1794 *
1795 * Provides support for <code>AccessibleHypertext</code> in case
1796 * there is an HTML document being displayed in this
1797 * <code>JEditorPane</code>.
1798 *
1799 */
1800 protected class JEditorPaneAccessibleHypertextSupport
1801 extends AccessibleJEditorPane implements AccessibleHypertext {
1802
1803 /**
1804 * An HTML link.
1805 */
1806 public class HTMLLink extends AccessibleHyperlink {
1807 Element element;
1808
1809 /**
1810 * Constructs a {@code HTMLLink}.
1811 * @param e the element
1812 */
1813 public HTMLLink(Element e) {
1814 element = e;
1815 }
1816
1817 /**
1818 * Since the document a link is associated with may have
1819 * changed, this method returns whether this Link is valid
1820 * anymore (with respect to the document it references).
1821 *
1822 * @return a flag indicating whether this link is still valid with
1823 * respect to the AccessibleHypertext it belongs to
1824 */
1825 public boolean isValid() {
1826 return JEditorPaneAccessibleHypertextSupport.this.linksValid;
1827 }
1828
1829 /**
1830 * Returns the number of accessible actions available in this Link
1831 * If there are more than one, the first one is NOT considered the
1832 * "default" action of this LINK object (e.g. in an HTML imagemap).
|