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 com.sun.star.wizards.common; 25 26 import com.sun.star.lang.IllegalArgumentException; 27 import com.sun.star.lang.XMultiServiceFactory; 28 import com.sun.star.script.XInvocation; 29 import com.sun.star.beans.PropertyValue; 30 31 public class Resource 32 { 33 34 XInvocation xInvocation; 35 XMultiServiceFactory xMSF; 36 String Unit; 37 String Module; 38 39 /** Creates a new instance of Resource 40 * @param _xMSF 41 * @param _Unit 42 * @param _Module 43 */ Resource(XMultiServiceFactory _xMSF, String _Unit, String _Module)44 public Resource(XMultiServiceFactory _xMSF, String _Unit, String _Module) 45 { 46 this.xMSF = _xMSF; 47 this.Unit = _Unit; 48 this.Module = _Module; 49 this.xInvocation = initResources(); 50 } 51 getResText(int nID)52 public String getResText(int nID) 53 { 54 try 55 { 56 short[][] PointerArray = new short[1][]; 57 Object[][] DummyArray = new Object[1][]; 58 Object[] nIDArray = new Object[1]; 59 nIDArray[0] = new Integer(nID); 60 return (String) xInvocation.invoke("getString", nIDArray, PointerArray, DummyArray); 61 } 62 catch (Exception exception) 63 { 64 exception.printStackTrace(); 65 throw new java.lang.IllegalArgumentException("Resource with ID not" + String.valueOf(nID) + "not found"); 66 } 67 } 68 getStringList(int nID)69 public PropertyValue[] getStringList(int nID) 70 { 71 try 72 { 73 short[][] PointerArray = new short[1][]; 74 Object[][] DummyArray = new Object[1][]; 75 Object[] nIDArray = new Object[1]; 76 nIDArray[0] = new Integer(nID); 77 //Object bla = xInvocation.invoke("getStringList", nIDArray, PointerArray, DummyArray); 78 return (PropertyValue[]) xInvocation.invoke("getStringList", nIDArray, PointerArray, DummyArray); 79 } 80 catch (Exception exception) 81 { 82 exception.printStackTrace(); 83 throw new java.lang.IllegalArgumentException("Resource with ID not" + String.valueOf(nID) + "not found"); 84 } 85 } 86 getResArray(int nID, int iCount)87 public String[] getResArray(int nID, int iCount) 88 { 89 try 90 { 91 String[] ResArray = new String[iCount]; 92 for (int i = 0; i < iCount; i++) 93 { 94 ResArray[i] = getResText(nID + i); 95 } 96 return ResArray; 97 } 98 catch (Exception exception) 99 { 100 exception.printStackTrace(System.out); 101 throw new java.lang.IllegalArgumentException("Resource with ID not" + String.valueOf(nID) + "not found"); 102 } 103 } 104 initResources()105 public XInvocation initResources() 106 { 107 try 108 { 109 com.sun.star.uno.XInterface xResource = (com.sun.star.uno.XInterface) xMSF.createInstance("com.sun.star.resource.VclStringResourceLoader"); 110 if (xResource == null) 111 { 112 showCommonResourceError(xMSF); 113 throw new IllegalArgumentException(); 114 } 115 else 116 { 117 XInvocation xResInvoke = com.sun.star.uno.UnoRuntime.queryInterface(XInvocation.class, xResource); 118 xResInvoke.setValue("FileName", Module); 119 return xResInvoke; 120 } 121 } 122 catch (Exception exception) 123 { 124 exception.printStackTrace(System.out); 125 showCommonResourceError(xMSF); 126 return null; 127 } 128 } 129 showCommonResourceError(XMultiServiceFactory xMSF)130 public static void showCommonResourceError(XMultiServiceFactory xMSF) 131 { 132 String ProductName = Configuration.getProductName(xMSF); 133 String sError = "The files required could not be found.\nPlease start the %PRODUCTNAME Setup and choose 'Repair'."; 134 sError = JavaTools.replaceSubString(sError, ProductName, "%PRODUCTNAME"); 135 SystemDialog.showMessageBox(xMSF, "ErrorBox", com.sun.star.awt.VclWindowPeerAttribute.OK, sError); 136 } 137 } 138