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