xref: /AOO41X/main/accessibility/bridge/org/openoffice/java/accessibility/AccessibleHypertextImpl.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package org.openoffice.java.accessibility;
29 
30 import org.openoffice.java.accessibility.logging.*;
31 
32 import com.sun.star.accessibility.*;
33 import com.sun.star.uno.*;
34 
35 /** The AccessibleHypertextImpl mapps all calls to the java AccessibleHypertext
36  *  interface to the corresponding methods of the UNO XAccessibleHypertext
37  *  interface.
38  */
39 public class AccessibleHypertextImpl extends AccessibleTextImpl
40     implements javax.accessibility.AccessibleHypertext {
41 
42     protected class Hyperlink extends javax.accessibility.AccessibleHyperlink {
43         protected XAccessibleHyperlink unoObject;
44 
45         public Hyperlink(XAccessibleHyperlink xHyperlink) {
46             unoObject = xHyperlink;
47         }
48 
49         public int getStartIndex() {
50             try {
51                 System.err.println("StartIndex: " + unoObject.getStartIndex());
52                 return unoObject.getStartIndex();
53             } catch (com.sun.star.uno.RuntimeException e) {
54                 return -1;
55             }
56         }
57 
58         public Object getAccessibleActionObject(int param) {
59             System.err.println("getActionObject");
60             try {
61                 Object any = unoObject.getAccessibleActionObject(param);
62                 if (AnyConverter.isString(any)) {
63                     String url = AnyConverter.toString(any);
64                     if (null != url) {
65                         return new java.net.URL(url);
66                     }
67                 }
68             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
69             } catch (com.sun.star.lang.IllegalArgumentException e) {
70             } catch (java.net.MalformedURLException exception) {
71             } catch (com.sun.star.uno.RuntimeException e) {
72             }
73 
74             return null;
75         }
76 
77         public int getEndIndex() {
78             try {
79                 System.err.println("StartIndex: " + unoObject.getEndIndex());
80                 return unoObject.getEndIndex();
81             } catch (com.sun.star.uno.RuntimeException e) {
82                 return -1;
83             }
84         }
85 
86         public Object getAccessibleActionAnchor(int param) {
87             System.err.println("getActionAnchor");
88             try {
89                 Object any = unoObject.getAccessibleActionObject(param);
90                 if (AnyConverter.isString(any)) {
91                     System.err.println("Anchor: " + AnyConverter.toString(any));
92                     return AnyConverter.toString(any);
93                 }
94             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
95             } catch (com.sun.star.lang.IllegalArgumentException e) {
96             } catch (com.sun.star.uno.RuntimeException e) {
97             }
98             return null;
99         }
100 
101         public boolean isValid() {
102             return unoObject.isValid();
103         }
104 
105         public boolean doAccessibleAction(int param) {
106             try {
107                 return unoObject.doAccessibleAction(param);
108             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
109                 return false;
110             } catch (com.sun.star.uno.RuntimeException e) {
111                 return false;
112             }
113         }
114 
115         public String getAccessibleActionDescription(int param) {
116             try {
117                 return unoObject.getAccessibleActionDescription(param);
118             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
119                 return null;
120             }
121         }
122 
123         public int getAccessibleActionCount() {
124             try {
125                 return unoObject.getAccessibleActionCount();
126             } catch (com.sun.star.uno.RuntimeException e) {
127                 return 0;
128             }
129         }
130     }
131 
132     /** Creates new AccessibleHypertextImpl */
133     public AccessibleHypertextImpl(XAccessibleHypertext xAccessibleHypertext) {
134         if (Build.PRODUCT) {
135             unoObject = xAccessibleHypertext;
136         } else {
137             String property = System.getProperty("AccessBridgeLogging");
138             if ((property != null) && (property.indexOf("text") != -1)) {
139                 unoObject = new XAccessibleHypertextLog(xAccessibleHypertext);
140             } else {
141                 unoObject = xAccessibleHypertext;
142             }
143         }
144     }
145 
146     public static javax.accessibility.AccessibleText get(com.sun.star.uno.XInterface unoObject) {
147         try {
148             XAccessibleHypertext unoAccessibleHypertext = (XAccessibleHypertext)
149                 UnoRuntime.queryInterface(XAccessibleHypertext.class, unoObject);
150             if (unoAccessibleHypertext != null) {
151                 return new AccessibleHypertextImpl(unoAccessibleHypertext);
152             }
153 
154             XAccessibleText unoAccessibleText = (XAccessibleText)
155                 UnoRuntime.queryInterface(XAccessibleText.class, unoObject);
156             if (unoAccessibleText != null) {
157                 return new AccessibleTextImpl(unoAccessibleText);
158             }
159         } catch (com.sun.star.uno.RuntimeException e) {
160         }
161         return null;
162     }
163 
164     public javax.accessibility.AccessibleHyperlink getLink(int param) {
165         try {
166             return new Hyperlink(((XAccessibleHypertext) unoObject).getHyperLink(param));
167         }
168 
169         catch(com.sun.star.lang.IndexOutOfBoundsException exception) {
170             throw new IndexOutOfBoundsException(exception.getMessage());
171         }
172     }
173 
174     public int getLinkCount() {
175         try {
176             return ((XAccessibleHypertext) unoObject).getHyperLinkCount();
177         } catch (com.sun.star.uno.RuntimeException e) {
178             return 0;
179         }
180     }
181 
182     public int getLinkIndex(int param) {
183         try {
184             return ((XAccessibleHypertext) unoObject).getHyperLinkIndex(param);
185         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
186             return -1;
187         } catch (com.sun.star.uno.RuntimeException e) {
188             return -1;
189         }
190     }
191 }
192