1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
31 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *************************************************************************/
36 import com
.sun
.star
.beans
.PropertyValue
;
37 import com
.sun
.star
.frame
.FrameSearchFlag
;
38 import com
.sun
.star
.frame
.XDesktop
;
39 import com
.sun
.star
.frame
.XDispatch
;
40 import com
.sun
.star
.frame
.XDispatchProvider
;
41 import com
.sun
.star
.frame
.XFrame
;
42 import com
.sun
.star
.lang
.XMultiComponentFactory
;
43 import com
.sun
.star
.lang
.XServiceInfo
;
44 import com
.sun
.star
.uno
.AnyConverter
;
45 import com
.sun
.star
.uno
.Type
;
46 import com
.sun
.star
.uno
.TypeClass
;
47 import com
.sun
.star
.uno
.UnoRuntime
;
48 import com
.sun
.star
.uno
.XComponentContext
;
49 import com
.sun
.star
.util
.URL
;
50 import com
.sun
.star
.util
.XURLTransformer
;
56 private XMultiComponentFactory m_xMultiComponentFactory
;
57 private XComponentContext m_xComponentContext
;
58 private Object
[] m_oParamObjects
= null;
59 private int m_nNodeType
= XUnoNode
.nOTHERS
;
60 private Type aType
= null;
61 private String sLabel
= "";
65 /** Creates a new instance of UnoNode */
66 public UnoNode(Object _oUnoObject
) {
67 m_xComponentContext
= Introspector
.getIntrospector().getXComponentContext();
68 m_xMultiComponentFactory
= m_xComponentContext
.getServiceManager();
69 m_oUnoObject
= _oUnoObject
;
72 public UnoNode(Object _oUnoObject
, Type _aType
) {
75 m_nNodeType
= XUnoNode
.nINTERFACE
;
78 public Object
getUnoObject(){
83 private XComponentContext
getXComponentContext(){
84 return m_xComponentContext
;
88 private XMultiComponentFactory
getXMultiComponentFactory(){
89 return m_xMultiComponentFactory
;
93 public String
getAnchor(){
97 public int getNodeType(){
101 public void setNodeType(int _nNodeType
){
102 m_nNodeType
= _nNodeType
;
105 public String
getClassName(){
106 String sClassName
= "";
107 if (m_nNodeType
== XUnoNode
.nINTERFACE
){
108 sClassName
= aType
.getTypeName();
110 else if(m_nNodeType
== XUnoNode
.nSERVICE
){
117 public Type
getUnoType(){
121 protected void setLabel(String _sLabel
){
125 public void openIdlDescription(String _sIDLUrl
, String _sClassName
){
127 String sIDLUrl
= _sIDLUrl
;
128 String sAnchor
= ""; // TODO find out how the Anchor may be set at the html file; //_sAnchor;
129 boolean bExists
= Introspector
.getIntrospector().getXSimpleFileAccess().exists(sIDLUrl
);
130 if (sIDLUrl
.equals("") || (!bExists
)){
131 sIDLUrl
= "https://api.libreoffice.org/" + Inspector
.sIDLDOCUMENTSUBFOLDER
;
133 if (!sIDLUrl
.endsWith("/")){
136 if (_sClassName
.equals("")){
141 sIDLUrl
+= _sClassName
.replace(".", "_1_1");
144 if (sAnchor
!= null){
145 if (!sAnchor
.equals("")){
146 sIDLUrl
+= "#" + sAnchor
;
149 URL openHyperlink
= getDispatchURL(".uno:OpenHyperlink");
150 PropertyValue pv
= new PropertyValue();
153 getXDispatcher(openHyperlink
).dispatch(openHyperlink
, new PropertyValue
[] {pv
});
154 } catch(Exception exception
) {
155 exception
.printStackTrace(System
.err
);
159 private com
.sun
.star
.util
.URL
getDispatchURL(String _sURL
){
161 Object oTransformer
= getXMultiComponentFactory().createInstanceWithContext("com.sun.star.util.URLTransformer", getXComponentContext());
162 XURLTransformer xTransformer
= UnoRuntime
.queryInterface(XURLTransformer
.class, oTransformer
);
163 com
.sun
.star
.util
.URL
[] oURL
= new com
.sun
.star
.util
.URL
[1];
164 oURL
[0] = new com
.sun
.star
.util
.URL();
165 oURL
[0].Complete
= _sURL
;
166 xTransformer
.parseStrict(oURL
);
168 } catch (Exception e
) {
169 e
.printStackTrace(System
.err
);
175 private XFrame
getCurrentFrame(){
177 Object oDesktop
= getXMultiComponentFactory().createInstanceWithContext("com.sun.star.frame.Desktop", getXComponentContext());
178 XDesktop xDesktop
= UnoRuntime
.queryInterface(XDesktop
.class, oDesktop
);
179 return xDesktop
.getCurrentFrame();
180 } catch (Exception e
) {
181 e
.printStackTrace(System
.err
);
186 private XDispatch
getXDispatcher(com
.sun
.star
.util
.URL oURL
) {
188 com
.sun
.star
.util
.URL
[] oURLArray
= new com
.sun
.star
.util
.URL
[1];
190 XDispatchProvider xDispatchProvider
= UnoRuntime
.queryInterface(XDispatchProvider
.class, getCurrentFrame());
191 XDispatch xDispatch
= xDispatchProvider
.queryDispatch(oURLArray
[0], "_top", FrameSearchFlag
.ALL
); // "_self"
193 } catch (Exception e
) {
194 e
.printStackTrace(System
.err
);
199 public boolean isFilterApplicable(String _sFilter
, String _sName
){
200 boolean bFilterDoesApply
= true;
201 if (_sFilter
.length() > 0){
202 if (_sName
.indexOf(_sFilter
) == -1){
203 bFilterDoesApply
= false;
206 return bFilterDoesApply
;
210 public static String
getDisplayValueOfPrimitiveType(Object _objectElement
){
213 if (AnyConverter
.isString(_objectElement
)){
214 sValue
= AnyConverter
.toString(_objectElement
);
216 else if (AnyConverter
.isBoolean(_objectElement
)){
217 sValue
+= AnyConverter
.toBoolean(_objectElement
);
219 else if (AnyConverter
.isByte(_objectElement
)){
220 sValue
+= AnyConverter
.toByte(_objectElement
);
222 else if (AnyConverter
.isChar(_objectElement
)){
223 sValue
+= AnyConverter
.toChar(_objectElement
);
225 else if (AnyConverter
.isDouble(_objectElement
)){
226 sValue
+= AnyConverter
.toDouble(_objectElement
);
228 else if (AnyConverter
.isFloat(_objectElement
)){
229 sValue
+= AnyConverter
.toFloat(_objectElement
);
231 else if (AnyConverter
.isInt(_objectElement
)){
232 sValue
+= AnyConverter
.toInt(_objectElement
);
234 else if (AnyConverter
.isLong(_objectElement
)){
235 sValue
+= AnyConverter
.toLong(_objectElement
);
237 else if (AnyConverter
.isShort(_objectElement
)){
238 sValue
+= AnyConverter
.toShort(_objectElement
);
241 catch( Exception e
) {
242 System
.err
.println( e
);
247 protected static String
[] getDisplayValuesofPrimitiveArray(Object _oUnoObject
){
248 String
[] sDisplayValues
= null;
250 Type aType
= AnyConverter
.getType(_oUnoObject
);
251 TypeClass aTypeClass
= aType
.getTypeClass();
252 int nTypeValue
= aTypeClass
.getValue();
253 if (nTypeValue
== TypeClass
.SEQUENCE_value
){
254 nTypeValue
= (sequenceComponentType(aType
)).getTypeClass().getValue();
257 case TypeClass
.BOOLEAN_value
:
258 boolean[] bBooleans
= (boolean[]) AnyConverter
.toArray(_oUnoObject
);
259 sDisplayValues
= new String
[bBooleans
.length
];
260 for (int i
= 0; i
< bBooleans
.length
; i
++){
261 sDisplayValues
[i
] = Boolean
.toString(bBooleans
[i
]);
264 case TypeClass
.BYTE_value
:
265 byte[] bBytes
= (byte[]) AnyConverter
.toArray(_oUnoObject
);
266 sDisplayValues
= new String
[bBytes
.length
];
267 for (int i
= 0; i
< bBytes
.length
; i
++){
268 sDisplayValues
[i
] = "" + bBytes
[i
];
271 case TypeClass
.DOUBLE_value
:
272 double[] fdoubles
= (double[]) AnyConverter
.toArray(_oUnoObject
);
273 sDisplayValues
= new String
[fdoubles
.length
];
274 for (int i
= 0; i
< fdoubles
.length
; i
++){
275 sDisplayValues
[i
] = String
.valueOf(fdoubles
[i
]);
278 case TypeClass
.FLOAT_value
:
279 float[] ffloats
= (float[]) AnyConverter
.toArray(_oUnoObject
);
280 sDisplayValues
= new String
[ffloats
.length
];
281 for (int i
= 0; i
< ffloats
.length
; i
++){
282 sDisplayValues
[i
] = String
.valueOf(ffloats
[i
]);
285 case TypeClass
.LONG_value
:
286 int[] nints
= (int[]) AnyConverter
.toArray(_oUnoObject
);
287 sDisplayValues
= new String
[nints
.length
];
288 for (int i
= 0; i
< nints
.length
; i
++){
289 sDisplayValues
[i
] = String
.valueOf(nints
[i
]);
292 case TypeClass
.HYPER_value
:
293 long[] nlongs
= (long[]) AnyConverter
.toArray(_oUnoObject
);
294 sDisplayValues
= new String
[nlongs
.length
];
295 for (int i
= 0; i
< nlongs
.length
; i
++){
296 sDisplayValues
[i
] = String
.valueOf(nlongs
[i
]);
299 case TypeClass
.SHORT_value
:
300 short[] nShorts
= (short[]) AnyConverter
.toArray(_oUnoObject
);
301 sDisplayValues
= new String
[nShorts
.length
];
302 for (int i
= 0; i
< nShorts
.length
; i
++){
303 sDisplayValues
[i
] = "" + nShorts
[i
];
306 case TypeClass
.CHAR_value
:
309 System
.out
.println("Value could not be retrieved: " + aType
.getTypeClass().getClass().getName());
311 return sDisplayValues
;
313 catch( Exception e
) {
314 System
.err
.println( e
);
319 private static Type
sequenceComponentType(Type sequenceType
) {
320 String n
= sequenceType
.getTypeName();
321 final String PREFIX
= "[]";
322 return new Type(n
.substring(PREFIX
.length()));
329 public static String
getNodeDescription(Object _oUnoObject
){
330 XServiceInfo xServiceInfo
= UnoRuntime
.queryInterface( XServiceInfo
.class, _oUnoObject
);
331 if ( xServiceInfo
!= null ) {
332 return xServiceInfo
.getImplementationName();
334 if (Introspector
.isObjectPrimitive(_oUnoObject
)){ //super.isO{sObjectClassName.equals("String"))issClassName.equals("String"))
335 return _oUnoObject
.toString();
338 return _oUnoObject
.getClass().getName();
342 public void setParameterObjects(Object
[] _oParamObjects
){
343 m_oParamObjects
= _oParamObjects
;
346 public Object
[] getParameterObjects(){
347 return m_oParamObjects
;
351 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */