1*57c10a96SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*57c10a96SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*57c10a96SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*57c10a96SAndrew Rist * distributed with this work for additional information 6*57c10a96SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*57c10a96SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*57c10a96SAndrew Rist * "License"); you may not use this file except in compliance 9*57c10a96SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*57c10a96SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*57c10a96SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*57c10a96SAndrew Rist * software distributed under the License is distributed on an 15*57c10a96SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*57c10a96SAndrew Rist * KIND, either express or implied. See the License for the 17*57c10a96SAndrew Rist * specific language governing permissions and limitations 18*57c10a96SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*57c10a96SAndrew Rist *************************************************************/ 21*57c10a96SAndrew Rist 22*57c10a96SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package com.sun.star.help; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import com.sun.star.lib.uno.helper.WeakBase; 27cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo; 28cdf0e10cSrcweir import com.sun.star.script.XInvocation; 29cdf0e10cSrcweir import com.sun.star.beans.XIntrospectionAccess; 30cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 31cdf0e10cSrcweir import com.sun.star.uno.XComponentContext; 32cdf0e10cSrcweir 33cdf0e10cSrcweir import java.io.File; 34cdf0e10cSrcweir import java.io.FileNotFoundException; 35cdf0e10cSrcweir import java.io.IOException; 36cdf0e10cSrcweir import java.util.Date; 37cdf0e10cSrcweir import java.util.zip.ZipOutputStream; 38cdf0e10cSrcweir 39cdf0e10cSrcweir /** 40cdf0e10cSrcweir When this tool is used with long path names on Windows, that is paths which start 41cdf0e10cSrcweir with \\?\, then the caller must make sure that the path is unique. This is achieved 42cdf0e10cSrcweir by removing '.' and '..' from the path. Paths which are created by 43cdf0e10cSrcweir osl_getSystemPathFromFileURL fulfill this requirement. This is necessary because 44cdf0e10cSrcweir lucene is patched to not use File.getCanonicalPath. See long_path.patch in the lucene 45cdf0e10cSrcweir module. 46cdf0e10cSrcweir */ 47cdf0e10cSrcweir public class HelpIndexer extends WeakBase 48cdf0e10cSrcweir implements XServiceInfo, XInvocation 49cdf0e10cSrcweir { 50cdf0e10cSrcweir static private final String __serviceName = 51cdf0e10cSrcweir "com.sun.star.help.HelpIndexer"; 52cdf0e10cSrcweir static private final String aCreateIndexMethodName = "createIndex"; 53cdf0e10cSrcweir 54cdf0e10cSrcweir static private com.sun.star.help.HelpIndexerTool helpindexer = new com.sun.star.help.HelpIndexerTool(); 55cdf0e10cSrcweir 56cdf0e10cSrcweir public HelpIndexer() 57cdf0e10cSrcweir { 58cdf0e10cSrcweir } 59cdf0e10cSrcweir 60cdf0e10cSrcweir public HelpIndexer(XComponentContext xCompContext) 61cdf0e10cSrcweir { 62cdf0e10cSrcweir } 63cdf0e10cSrcweir 64cdf0e10cSrcweir public static void mainImpl( String[] args, boolean bExtensionMode ) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir helpindexer.mainImpl( args , bExtensionMode ); 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir public static void createZipFile( File aDirToZip, String aTargetZipFileStr ) 70cdf0e10cSrcweir throws FileNotFoundException, IOException 71cdf0e10cSrcweir { 72cdf0e10cSrcweir helpindexer.createZipFile( aDirToZip , aTargetZipFileStr ); 73cdf0e10cSrcweir } 74cdf0e10cSrcweir 75cdf0e10cSrcweir public static void addToZipRecursively( ZipOutputStream zos, File aFile, String aBasePath ) 76cdf0e10cSrcweir throws FileNotFoundException, IOException 77cdf0e10cSrcweir { 78cdf0e10cSrcweir helpindexer.addToZipRecursively( zos , aFile , aBasePath ); 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir static public boolean deleteRecursively( File aFile ) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir return helpindexer.deleteRecursively( aFile ); 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir //=================================================== 87cdf0e10cSrcweir // XInvocation 88cdf0e10cSrcweir public XIntrospectionAccess getIntrospection() 89cdf0e10cSrcweir { 90cdf0e10cSrcweir return null; 91cdf0e10cSrcweir } 92cdf0e10cSrcweir 93cdf0e10cSrcweir public Object invoke( String aFunctionName, java.lang.Object[] aParams, 94cdf0e10cSrcweir short[][] aOutParamIndex, java.lang.Object[][] aOutParam ) 95cdf0e10cSrcweir throws com.sun.star.lang.IllegalArgumentException, 96cdf0e10cSrcweir com.sun.star.script.CannotConvertException, 97cdf0e10cSrcweir com.sun.star.reflection.InvocationTargetException 98cdf0e10cSrcweir { 99cdf0e10cSrcweir if( 100cdf0e10cSrcweir !aFunctionName.equals( aCreateIndexMethodName ) ) 101cdf0e10cSrcweir throw new com.sun.star.lang.IllegalArgumentException(); 102cdf0e10cSrcweir 103cdf0e10cSrcweir aOutParamIndex[0] = new short[0]; 104cdf0e10cSrcweir aOutParam[0] = new Object[0]; 105cdf0e10cSrcweir 106cdf0e10cSrcweir int nParamCount = aParams.length; 107cdf0e10cSrcweir String aStrs[] = new String[nParamCount]; 108cdf0e10cSrcweir for( int i = 0 ; i < nParamCount ; i++ ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir try 111cdf0e10cSrcweir { 112cdf0e10cSrcweir aStrs[i] = AnyConverter.toString( aParams[i] ); 113cdf0e10cSrcweir } 114cdf0e10cSrcweir catch( IllegalArgumentException e ) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir aStrs[i] = ""; 117cdf0e10cSrcweir } 118cdf0e10cSrcweir } 119cdf0e10cSrcweir 120cdf0e10cSrcweir boolean bExtensionMode = true; 121cdf0e10cSrcweir mainImpl( aStrs, bExtensionMode ); 122cdf0e10cSrcweir 123cdf0e10cSrcweir return null; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir public void setValue( String aPropertyName, java.lang.Object aValue ) 127cdf0e10cSrcweir throws com.sun.star.beans.UnknownPropertyException, 128cdf0e10cSrcweir com.sun.star.script.CannotConvertException, 129cdf0e10cSrcweir com.sun.star.reflection.InvocationTargetException 130cdf0e10cSrcweir { 131cdf0e10cSrcweir throw new com.sun.star.beans.UnknownPropertyException(); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir public Object getValue( String aPropertyName ) 135cdf0e10cSrcweir throws com.sun.star.beans.UnknownPropertyException 136cdf0e10cSrcweir { 137cdf0e10cSrcweir throw new com.sun.star.beans.UnknownPropertyException(); 138cdf0e10cSrcweir } 139cdf0e10cSrcweir 140cdf0e10cSrcweir public boolean hasMethod( String aMethodName ) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir boolean bRet = (aMethodName.equals( aCreateIndexMethodName ) ); 143cdf0e10cSrcweir return bRet; 144cdf0e10cSrcweir } 145cdf0e10cSrcweir public boolean hasProperty( String aName ) { 146cdf0e10cSrcweir return false; 147cdf0e10cSrcweir } 148cdf0e10cSrcweir 149cdf0e10cSrcweir 150cdf0e10cSrcweir 151cdf0e10cSrcweir /** This method returns an array of all supported service names. 152cdf0e10cSrcweir * @return Array of supported service names. 153cdf0e10cSrcweir */ 154cdf0e10cSrcweir public String[] getSupportedServiceNames() 155cdf0e10cSrcweir { 156cdf0e10cSrcweir return getServiceNames(); 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir /** This method is a simple helper function to used in the 160cdf0e10cSrcweir * static component initialisation functions as well as in 161cdf0e10cSrcweir * getSupportedServiceNames. 162cdf0e10cSrcweir */ 163cdf0e10cSrcweir public static String[] getServiceNames() 164cdf0e10cSrcweir { 165cdf0e10cSrcweir String[] sSupportedServiceNames = { __serviceName }; 166cdf0e10cSrcweir return sSupportedServiceNames; 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir 170cdf0e10cSrcweir /** This method returns true, if the given service will be 171cdf0e10cSrcweir * supported by the component. 172cdf0e10cSrcweir * @param sServiceName Service name. 173cdf0e10cSrcweir * @return True, if the given service name will be supported. 174cdf0e10cSrcweir */ 175cdf0e10cSrcweir public boolean supportsService( String sServiceName ) 176cdf0e10cSrcweir { 177cdf0e10cSrcweir return sServiceName.equals( __serviceName ); 178cdf0e10cSrcweir } 179cdf0e10cSrcweir 180cdf0e10cSrcweir 181cdf0e10cSrcweir /** Return the class name of the component. 182cdf0e10cSrcweir * @return Class name of the component. 183cdf0e10cSrcweir */ 184cdf0e10cSrcweir public String getImplementationName() 185cdf0e10cSrcweir { 186cdf0e10cSrcweir return HelpIndexer.class.getName(); 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir } 190cdf0e10cSrcweir 191