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