xref: /AOO41X/main/xmlhelp/source/com/sun/star/help/HelpIndexer.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 com.sun.star.help;
29 
30 import com.sun.star.lib.uno.helper.WeakBase;
31 import com.sun.star.lang.XServiceInfo;
32 import com.sun.star.script.XInvocation;
33 import com.sun.star.beans.XIntrospectionAccess;
34 import com.sun.star.uno.AnyConverter;
35 import com.sun.star.uno.XComponentContext;
36 
37 import java.io.File;
38 import java.io.FileNotFoundException;
39 import java.io.IOException;
40 import java.util.Date;
41 import java.util.zip.ZipOutputStream;
42 
43 /**
44    When this tool is used with long path names on Windows, that is paths which start
45    with \\?\, then the caller must make sure that the path is unique. This is achieved
46    by removing '.' and '..' from the path. Paths which are created by
47    osl_getSystemPathFromFileURL fulfill this requirement. This is necessary because
48    lucene is patched to not use File.getCanonicalPath. See long_path.patch in the lucene
49    module.
50  */
51 public class HelpIndexer extends WeakBase
52     implements XServiceInfo, XInvocation
53 {
54     static private final String __serviceName =
55         "com.sun.star.help.HelpIndexer";
56     static private final String aCreateIndexMethodName = "createIndex";
57 
58     static private com.sun.star.help.HelpIndexerTool helpindexer = new com.sun.star.help.HelpIndexerTool();
59 
60     public HelpIndexer()
61     {
62     }
63 
64     public HelpIndexer(XComponentContext xCompContext)
65     {
66     }
67 
68     public static void mainImpl( String[] args, boolean bExtensionMode )
69     {
70         helpindexer.mainImpl( args , bExtensionMode );
71     }
72 
73     public static void createZipFile( File aDirToZip, String aTargetZipFileStr )
74             throws FileNotFoundException, IOException
75     {
76         helpindexer.createZipFile( aDirToZip , aTargetZipFileStr );
77     }
78 
79     public static void addToZipRecursively( ZipOutputStream zos, File aFile, String aBasePath )
80             throws FileNotFoundException, IOException
81     {
82         helpindexer.addToZipRecursively( zos , aFile , aBasePath );
83     }
84 
85     static public boolean deleteRecursively( File aFile )
86     {
87         return helpindexer.deleteRecursively( aFile );
88     }
89 
90     //===================================================
91     // XInvocation
92     public XIntrospectionAccess getIntrospection()
93     {
94         return  null;
95     }
96 
97     public Object invoke( String aFunctionName, java.lang.Object[] aParams,
98         short[][] aOutParamIndex, java.lang.Object[][] aOutParam )
99             throws  com.sun.star.lang.IllegalArgumentException,
100                     com.sun.star.script.CannotConvertException,
101                     com.sun.star.reflection.InvocationTargetException
102     {
103         if(
104               !aFunctionName.equals( aCreateIndexMethodName  ) )
105             throw new com.sun.star.lang.IllegalArgumentException();
106 
107         aOutParamIndex[0] = new short[0];
108         aOutParam[0] = new Object[0];
109 
110         int nParamCount = aParams.length;
111         String aStrs[] = new String[nParamCount];
112         for( int i = 0 ; i < nParamCount ; i++ )
113         {
114             try
115             {
116                 aStrs[i] = AnyConverter.toString( aParams[i] );
117             }
118             catch( IllegalArgumentException e )
119             {
120                 aStrs[i] = "";
121             }
122         }
123 
124         boolean bExtensionMode = true;
125         mainImpl( aStrs, bExtensionMode );
126 
127         return null;
128     }
129 
130     public void setValue( String aPropertyName, java.lang.Object aValue )
131         throws  com.sun.star.beans.UnknownPropertyException,
132                 com.sun.star.script.CannotConvertException,
133                 com.sun.star.reflection.InvocationTargetException
134     {
135         throw new com.sun.star.beans.UnknownPropertyException();
136     }
137 
138     public Object getValue( String aPropertyName )
139         throws com.sun.star.beans.UnknownPropertyException
140     {
141         throw new com.sun.star.beans.UnknownPropertyException();
142     }
143 
144     public boolean hasMethod( String aMethodName )
145     {
146         boolean bRet = (aMethodName.equals( aCreateIndexMethodName ) );
147         return bRet;
148     }
149     public boolean hasProperty( String aName ) {
150         return false;
151     }
152 
153 
154 
155     /** This method returns an array of all supported service names.
156      * @return Array of supported service names.
157      */
158     public String[] getSupportedServiceNames()
159     {
160         return getServiceNames();
161     }
162 
163     /** This method is a simple helper function to used in the
164      * static component initialisation functions as well as in
165      * getSupportedServiceNames.
166      */
167     public static String[] getServiceNames()
168     {
169         String[] sSupportedServiceNames = { __serviceName };
170         return sSupportedServiceNames;
171     }
172 
173 
174     /** This method returns true, if the given service will be
175      * supported by the component.
176      * @param sServiceName Service name.
177      * @return True, if the given service name will be supported.
178      */
179     public boolean supportsService( String sServiceName )
180     {
181         return sServiceName.equals( __serviceName );
182     }
183 
184 
185     /** Return the class name of the component.
186      * @return Class name of the component.
187      */
188     public String getImplementationName()
189     {
190         return  HelpIndexer.class.getName();
191     }
192 
193 }
194 
195