1*8622218dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*8622218dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*8622218dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*8622218dSAndrew Rist * distributed with this work for additional information 6*8622218dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*8622218dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*8622218dSAndrew Rist * "License"); you may not use this file except in compliance 9*8622218dSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*8622218dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*8622218dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*8622218dSAndrew Rist * software distributed under the License is distributed on an 15*8622218dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*8622218dSAndrew Rist * KIND, either express or implied. See the License for the 17*8622218dSAndrew Rist * specific language governing permissions and limitations 18*8622218dSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*8622218dSAndrew Rist *************************************************************/ 21*8622218dSAndrew Rist 22*8622218dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package org.openoffice.java.accessibility; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import org.openoffice.java.accessibility.logging.*; 27cdf0e10cSrcweir 28cdf0e10cSrcweir import com.sun.star.accessibility.*; 29cdf0e10cSrcweir import com.sun.star.uno.*; 30cdf0e10cSrcweir 31cdf0e10cSrcweir /** The AccessibleHypertextImpl mapps all calls to the java AccessibleHypertext 32cdf0e10cSrcweir * interface to the corresponding methods of the UNO XAccessibleHypertext 33cdf0e10cSrcweir * interface. 34cdf0e10cSrcweir */ 35cdf0e10cSrcweir public class AccessibleHypertextImpl extends AccessibleTextImpl 36cdf0e10cSrcweir implements javax.accessibility.AccessibleHypertext { 37cdf0e10cSrcweir 38cdf0e10cSrcweir protected class Hyperlink extends javax.accessibility.AccessibleHyperlink { 39cdf0e10cSrcweir protected XAccessibleHyperlink unoObject; 40cdf0e10cSrcweir Hyperlink(XAccessibleHyperlink xHyperlink)41cdf0e10cSrcweir public Hyperlink(XAccessibleHyperlink xHyperlink) { 42cdf0e10cSrcweir unoObject = xHyperlink; 43cdf0e10cSrcweir } 44cdf0e10cSrcweir getStartIndex()45cdf0e10cSrcweir public int getStartIndex() { 46cdf0e10cSrcweir try { 47cdf0e10cSrcweir System.err.println("StartIndex: " + unoObject.getStartIndex()); 48cdf0e10cSrcweir return unoObject.getStartIndex(); 49cdf0e10cSrcweir } catch (com.sun.star.uno.RuntimeException e) { 50cdf0e10cSrcweir return -1; 51cdf0e10cSrcweir } 52cdf0e10cSrcweir } 53cdf0e10cSrcweir getAccessibleActionObject(int param)54cdf0e10cSrcweir public Object getAccessibleActionObject(int param) { 55cdf0e10cSrcweir System.err.println("getActionObject"); 56cdf0e10cSrcweir try { 57cdf0e10cSrcweir Object any = unoObject.getAccessibleActionObject(param); 58cdf0e10cSrcweir if (AnyConverter.isString(any)) { 59cdf0e10cSrcweir String url = AnyConverter.toString(any); 60cdf0e10cSrcweir if (null != url) { 61cdf0e10cSrcweir return new java.net.URL(url); 62cdf0e10cSrcweir } 63cdf0e10cSrcweir } 64cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 65cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 66cdf0e10cSrcweir } catch (java.net.MalformedURLException exception) { 67cdf0e10cSrcweir } catch (com.sun.star.uno.RuntimeException e) { 68cdf0e10cSrcweir } 69cdf0e10cSrcweir 70cdf0e10cSrcweir return null; 71cdf0e10cSrcweir } 72cdf0e10cSrcweir getEndIndex()73cdf0e10cSrcweir public int getEndIndex() { 74cdf0e10cSrcweir try { 75cdf0e10cSrcweir System.err.println("StartIndex: " + unoObject.getEndIndex()); 76cdf0e10cSrcweir return unoObject.getEndIndex(); 77cdf0e10cSrcweir } catch (com.sun.star.uno.RuntimeException e) { 78cdf0e10cSrcweir return -1; 79cdf0e10cSrcweir } 80cdf0e10cSrcweir } 81cdf0e10cSrcweir getAccessibleActionAnchor(int param)82cdf0e10cSrcweir public Object getAccessibleActionAnchor(int param) { 83cdf0e10cSrcweir System.err.println("getActionAnchor"); 84cdf0e10cSrcweir try { 85cdf0e10cSrcweir Object any = unoObject.getAccessibleActionObject(param); 86cdf0e10cSrcweir if (AnyConverter.isString(any)) { 87cdf0e10cSrcweir System.err.println("Anchor: " + AnyConverter.toString(any)); 88cdf0e10cSrcweir return AnyConverter.toString(any); 89cdf0e10cSrcweir } 90cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 91cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 92cdf0e10cSrcweir } catch (com.sun.star.uno.RuntimeException e) { 93cdf0e10cSrcweir } 94cdf0e10cSrcweir return null; 95cdf0e10cSrcweir } 96cdf0e10cSrcweir isValid()97cdf0e10cSrcweir public boolean isValid() { 98cdf0e10cSrcweir return unoObject.isValid(); 99cdf0e10cSrcweir } 100cdf0e10cSrcweir doAccessibleAction(int param)101cdf0e10cSrcweir public boolean doAccessibleAction(int param) { 102cdf0e10cSrcweir try { 103cdf0e10cSrcweir return unoObject.doAccessibleAction(param); 104cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 105cdf0e10cSrcweir return false; 106cdf0e10cSrcweir } catch (com.sun.star.uno.RuntimeException e) { 107cdf0e10cSrcweir return false; 108cdf0e10cSrcweir } 109cdf0e10cSrcweir } 110cdf0e10cSrcweir getAccessibleActionDescription(int param)111cdf0e10cSrcweir public String getAccessibleActionDescription(int param) { 112cdf0e10cSrcweir try { 113cdf0e10cSrcweir return unoObject.getAccessibleActionDescription(param); 114cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 115cdf0e10cSrcweir return null; 116cdf0e10cSrcweir } 117cdf0e10cSrcweir } 118cdf0e10cSrcweir getAccessibleActionCount()119cdf0e10cSrcweir public int getAccessibleActionCount() { 120cdf0e10cSrcweir try { 121cdf0e10cSrcweir return unoObject.getAccessibleActionCount(); 122cdf0e10cSrcweir } catch (com.sun.star.uno.RuntimeException e) { 123cdf0e10cSrcweir return 0; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir } 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir /** Creates new AccessibleHypertextImpl */ AccessibleHypertextImpl(XAccessibleHypertext xAccessibleHypertext)129cdf0e10cSrcweir public AccessibleHypertextImpl(XAccessibleHypertext xAccessibleHypertext) { 130cdf0e10cSrcweir if (Build.PRODUCT) { 131cdf0e10cSrcweir unoObject = xAccessibleHypertext; 132cdf0e10cSrcweir } else { 133cdf0e10cSrcweir String property = System.getProperty("AccessBridgeLogging"); 134cdf0e10cSrcweir if ((property != null) && (property.indexOf("text") != -1)) { 135cdf0e10cSrcweir unoObject = new XAccessibleHypertextLog(xAccessibleHypertext); 136cdf0e10cSrcweir } else { 137cdf0e10cSrcweir unoObject = xAccessibleHypertext; 138cdf0e10cSrcweir } 139cdf0e10cSrcweir } 140cdf0e10cSrcweir } 141cdf0e10cSrcweir get(com.sun.star.uno.XInterface unoObject)142cdf0e10cSrcweir public static javax.accessibility.AccessibleText get(com.sun.star.uno.XInterface unoObject) { 143cdf0e10cSrcweir try { 144cdf0e10cSrcweir XAccessibleHypertext unoAccessibleHypertext = (XAccessibleHypertext) 145cdf0e10cSrcweir UnoRuntime.queryInterface(XAccessibleHypertext.class, unoObject); 146cdf0e10cSrcweir if (unoAccessibleHypertext != null) { 147cdf0e10cSrcweir return new AccessibleHypertextImpl(unoAccessibleHypertext); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir 150cdf0e10cSrcweir XAccessibleText unoAccessibleText = (XAccessibleText) 151cdf0e10cSrcweir UnoRuntime.queryInterface(XAccessibleText.class, unoObject); 152cdf0e10cSrcweir if (unoAccessibleText != null) { 153cdf0e10cSrcweir return new AccessibleTextImpl(unoAccessibleText); 154cdf0e10cSrcweir } 155cdf0e10cSrcweir } catch (com.sun.star.uno.RuntimeException e) { 156cdf0e10cSrcweir } 157cdf0e10cSrcweir return null; 158cdf0e10cSrcweir } 159cdf0e10cSrcweir getLink(int param)160cdf0e10cSrcweir public javax.accessibility.AccessibleHyperlink getLink(int param) { 161cdf0e10cSrcweir try { 162cdf0e10cSrcweir return new Hyperlink(((XAccessibleHypertext) unoObject).getHyperLink(param)); 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir catch(com.sun.star.lang.IndexOutOfBoundsException exception) { 166cdf0e10cSrcweir throw new IndexOutOfBoundsException(exception.getMessage()); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir } 169cdf0e10cSrcweir getLinkCount()170cdf0e10cSrcweir public int getLinkCount() { 171cdf0e10cSrcweir try { 172cdf0e10cSrcweir return ((XAccessibleHypertext) unoObject).getHyperLinkCount(); 173cdf0e10cSrcweir } catch (com.sun.star.uno.RuntimeException e) { 174cdf0e10cSrcweir return 0; 175cdf0e10cSrcweir } 176cdf0e10cSrcweir } 177cdf0e10cSrcweir getLinkIndex(int param)178cdf0e10cSrcweir public int getLinkIndex(int param) { 179cdf0e10cSrcweir try { 180cdf0e10cSrcweir return ((XAccessibleHypertext) unoObject).getHyperLinkIndex(param); 181cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 182cdf0e10cSrcweir return -1; 183cdf0e10cSrcweir } catch (com.sun.star.uno.RuntimeException e) { 184cdf0e10cSrcweir return -1; 185cdf0e10cSrcweir } 186cdf0e10cSrcweir } 187cdf0e10cSrcweir } 188