diff options
author | RĂ¼diger Timm <rt@openoffice.org> | 2008-08-01 11:13:47 +0000 |
---|---|---|
committer | RĂ¼diger Timm <rt@openoffice.org> | 2008-08-01 11:13:47 +0000 |
commit | e8ec64e402f9873ae95c67ae335650e9265bc843 (patch) | |
tree | c59100e76616998ed8135695dba4ea070d79eab8 /xmlhelp | |
parent | dd43a14a40fbba04c07a1d619b7ee21fb8307897 (diff) |
INTEGRATION: CWS helpsearch (1.2.8); FILE MERGED
2008/07/28 08:42:33 jsc 1.2.8.2: #i91750# use explicit cast to the Anaylzer interface
2008/07/23 07:31:09 jsc 1.2.8.1: #i91750# integrate lang parameter, use CJK analyzer for ja
Diffstat (limited to 'xmlhelp')
-rw-r--r-- | xmlhelp/source/com/sun/star/help/HelpSearch.java | 213 |
1 files changed, 92 insertions, 121 deletions
diff --git a/xmlhelp/source/com/sun/star/help/HelpSearch.java b/xmlhelp/source/com/sun/star/help/HelpSearch.java index 9bba0859f692..c25bca066e02 100644 --- a/xmlhelp/source/com/sun/star/help/HelpSearch.java +++ b/xmlhelp/source/com/sun/star/help/HelpSearch.java @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: HelpSearch.java,v $ - * $Revision: 1.2 $ + * $Revision: 1.3 $ * * This file is part of OpenOffice.org. * @@ -27,18 +27,14 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ - package com.sun.star.help; import com.sun.star.lib.uno.helper.Factory; import com.sun.star.lang.XMultiComponentFactory; import com.sun.star.lang.XSingleComponentFactory; import com.sun.star.lib.uno.helper.WeakBase; -import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; import com.sun.star.registry.XRegistryKey; -import com.sun.star.lang.XInitialization; -import com.sun.star.lang.XTypeProvider; import com.sun.star.lang.XServiceInfo; import com.sun.star.uno.Type; import com.sun.star.uno.Any; @@ -46,11 +42,10 @@ import com.sun.star.uno.AnyConverter; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.standard.StandardAnalyzer; +import org.apache.lucene.analysis.cjk.CJKAnalyzer; import org.apache.lucene.document.Document; -import org.apache.lucene.index.FilterIndexReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; -import org.apache.lucene.queryParser.QueryParser; import org.apache.lucene.search.Hits; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; @@ -61,35 +56,29 @@ import org.apache.lucene.search.WildcardQuery; import com.sun.star.script.XInvocation; import com.sun.star.beans.XIntrospectionAccess; -import java.io.FileOutputStream; -import java.io.PrintStream; -import java.io.File; - /** This class capsulates the class, that implements the minimal component, a * factory for creating the service (<CODE>__getComponentFactory</CODE>) and a * method, that writes the information into the given registry key * (<CODE>__writeRegistryServiceInfo</CODE>). */ -public class HelpSearch -{ +public class HelpSearch { + /** This class implements the component. At least the interfaces XServiceInfo, * XTypeProvider, and XInitialization should be provided by the service. */ public static class _HelpSearch extends WeakBase - implements XServiceInfo, XInvocation - { + implements XServiceInfo, XInvocation { + /** The service name, that must be used to get an instance of this service. */ static private final String __serviceName = - "com.sun.star.help.HelpSearch"; + "com.sun.star.help.HelpSearch"; static private final String aSearchMethodName = "search"; - /** The initial component contextr, that gives access to * the service manager, supported singletons, ... * It's often later used */ private XComponentContext m_cmpCtx; - /** The service manager, that gives access to all registered services. * It's often later used */ @@ -99,13 +88,11 @@ public class HelpSearch * @param xmultiservicefactoryInitialization A special service factory * could be introduced while initializing. */ - public _HelpSearch(XComponentContext xCompContext) - { + public _HelpSearch(XComponentContext xCompContext) { try { m_cmpCtx = xCompContext; m_xMCF = m_cmpCtx.getServiceManager(); - } - catch( Exception e ) { + } catch (Exception e) { e.printStackTrace(); } } @@ -113,8 +100,7 @@ public class HelpSearch /** This method returns an array of all supported service names. * @return Array of supported service names. */ - public String[] getSupportedServiceNames() - { + public String[] getSupportedServiceNames() { return getServiceNames(); } @@ -122,9 +108,8 @@ public class HelpSearch * static component initialisation functions as well as in * getSupportedServiceNames. */ - public static String[] getServiceNames() - { - String[] sSupportedServiceNames = { __serviceName }; + public static String[] getServiceNames() { + String[] sSupportedServiceNames = {__serviceName}; return sSupportedServiceNames; } @@ -133,147 +118,132 @@ public class HelpSearch * @param sServiceName Service name. * @return True, if the given service name will be supported. */ - public boolean supportsService( String sServiceName ) - { - return sServiceName.equals( __serviceName ); + public boolean supportsService(String sServiceName) { + return sServiceName.equals(__serviceName); } /** Return the class name of the component. * @return Class name of the component. */ - public String getImplementationName() - { - return _HelpSearch.class.getName(); + public String getImplementationName() { + return _HelpSearch.class.getName(); } //=================================================== // XInvocation - public XIntrospectionAccess getIntrospection() - { - return null; + public XIntrospectionAccess getIntrospection() { + return null; } - public Object invoke( String aFunctionName, java.lang.Object[] aParams, - short[][] aOutParamIndex, java.lang.Object[][] aOutParam ) - throws com.sun.star.lang.IllegalArgumentException, - com.sun.star.script.CannotConvertException, - com.sun.star.reflection.InvocationTargetException - { + public Object invoke(String aFunctionName, java.lang.Object[] aParams, + short[][] aOutParamIndex, java.lang.Object[][] aOutParam) + throws com.sun.star.lang.IllegalArgumentException, + com.sun.star.script.CannotConvertException, + com.sun.star.reflection.InvocationTargetException { aOutParamIndex[0] = new short[0]; aOutParam[0] = new Object[0]; String[] aRet = null; - if( !aFunctionName.equals( aSearchMethodName ) ) + if (!aFunctionName.equals(aSearchMethodName)) { throw new com.sun.star.lang.IllegalArgumentException(); - - try - { - aRet = doQuery( aParams ); } - catch( Exception e ) - { + + try { + aRet = doQuery(aParams); + } catch (Exception e) { aRet = null; } - Any aRetAny = new Any( new Type( String[].class ), aRet ); + Any aRetAny = new Any(new Type(String[].class), aRet); return aRetAny; } - public void setValue( String aPropertyName, java.lang.Object aValue ) - throws com.sun.star.beans.UnknownPropertyException, - com.sun.star.script.CannotConvertException, - com.sun.star.reflection.InvocationTargetException { + public void setValue(String aPropertyName, java.lang.Object aValue) + throws com.sun.star.beans.UnknownPropertyException, + com.sun.star.script.CannotConvertException, + com.sun.star.reflection.InvocationTargetException { throw new com.sun.star.beans.UnknownPropertyException(); } - public Object getValue( String aPropertyName ) - throws com.sun.star.beans.UnknownPropertyException { + public Object getValue(String aPropertyName) + throws com.sun.star.beans.UnknownPropertyException { throw new com.sun.star.beans.UnknownPropertyException(); } - public boolean hasMethod( String aMethodName ) { - boolean bRet = (aMethodName.equals( aSearchMethodName ) ); + public boolean hasMethod(String aMethodName) { + boolean bRet = (aMethodName.equals(aSearchMethodName)); return bRet; } - public boolean hasProperty( String aName ) { + + public boolean hasProperty(String aName) { return false; } // Command line interface for testing - private static String[] doQuery( Object[] args ) throws Exception - { + private static String[] doQuery(Object[] args) throws Exception { + String aLanguageStr = ""; String aIndexStr = ""; String aQueryStr = ""; boolean bCaptionOnly = false; int nParamCount = args.length; String aStrs[] = new String[nParamCount]; - for( int i = 0 ; i < nParamCount ; i++ ) - { - try - { - aStrs[i] = AnyConverter.toString( args[i] ); - } - catch( IllegalArgumentException e ) - { + for (int i = 0; i < nParamCount; i++) { + try { + aStrs[i] = AnyConverter.toString(args[i]); + } catch (IllegalArgumentException e) { aStrs[i] = ""; } } // TODO: Error handling - for( int i = 0 ; i < nParamCount ; i++ ) - { - if( "-index".equals(aStrs[i]) ) - { - aIndexStr = aStrs[i+1]; + for (int i = 0; i < nParamCount; i++) { + if ("-lang".equals(aStrs[i])) { + aLanguageStr = aStrs[i + 1]; i++; - } - else if( "-query".equals(aStrs[i]) ) - { - aQueryStr = aStrs[i+1]; + } else if ("-index".equals(aStrs[i])) { + aIndexStr = aStrs[i + 1]; i++; - } - else if( "-caption".equals(aStrs[i]) ) - { + } else if ("-query".equals(aStrs[i])) { + aQueryStr = aStrs[i + 1]; + i++; + } else if ("-caption".equals(aStrs[i])) { bCaptionOnly = true; } } - String[] aDocs = queryImpl( aIndexStr, aQueryStr, bCaptionOnly ); + String[] aDocs = queryImpl(aLanguageStr, aIndexStr, aQueryStr, bCaptionOnly); return aDocs; } - private static String[] queryImpl( String aIndexStr, String aQueryStr, boolean bCaptionOnly ) throws Exception - { - if( aIndexStr == "" ) - aIndexStr = "D:\\staroffice8_dev300_m5_ab49\\OpenOffice.org\\Basis 3.0\\help\\en\\index.sbasic"; - - IndexReader reader = IndexReader.open( aIndexStr ); - Searcher searcher = new IndexSearcher( reader ); - Analyzer analyzer = new StandardAnalyzer(); + private static String[] queryImpl(String aLanguageStr, String aIndexStr, String aQueryStr, boolean bCaptionOnly) throws Exception { + IndexReader reader = IndexReader.open(aIndexStr); + Searcher searcher = new IndexSearcher(reader); + Analyzer analyzer = aLanguageStr.equals("ja") ? (Analyzer)new CJKAnalyzer() : (Analyzer)new StandardAnalyzer(); String aField; - if( bCaptionOnly ) + if (bCaptionOnly) { aField = "caption"; - else + } else { aField = "content"; + } Query aQuery; - if( aQueryStr.endsWith( "*" ) ) - aQuery = new WildcardQuery( new Term( aField, aQueryStr ) ); - else - aQuery = new TermQuery( new Term( aField, aQueryStr ) ); + if (aQueryStr.endsWith("*")) { + aQuery = new WildcardQuery(new Term(aField, aQueryStr)); + } else { + aQuery = new TermQuery(new Term(aField, aQueryStr)); + } // Perform search - Hits aHits = searcher.search( aQuery ); + Hits aHits = searcher.search(aQuery); int nHitCount = aHits.length(); String aDocs[] = new String[nHitCount]; - for( int iHit = 0 ; iHit < nHitCount ; iHit++ ) - { - Document aDoc = aHits.doc( iHit ); - String aPath = aDoc.get( "path" ); - aDocs[iHit] = ( aPath != null ) ? aPath : ""; + for (int iHit = 0; iHit < nHitCount; iHit++) { + Document aDoc = aHits.doc(iHit); + String aPath = aDoc.get("path"); + aDocs[iHit] = (aPath != null) ? aPath : ""; } reader.close(); @@ -292,13 +262,13 @@ public class HelpSearch * service is desired * @see com.sun.star.comp.loader.JavaLoader */ - public static XSingleComponentFactory __getComponentFactory(String sImplName) - { + public static XSingleComponentFactory __getComponentFactory(String sImplName) { XSingleComponentFactory xFactory = null; - if ( sImplName.equals( _HelpSearch.class.getName() ) ) + if (sImplName.equals(_HelpSearch.class.getName())) { xFactory = Factory.createComponentFactory(_HelpSearch.class, - _HelpSearch.getServiceNames()); + _HelpSearch.getServiceNames()); + } return xFactory; } @@ -313,21 +283,22 @@ public class HelpSearch */ public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) { return Factory.writeRegistryServiceInfo(_HelpSearch.class.getName(), - _HelpSearch.getServiceNames(), - regKey); + _HelpSearch.getServiceNames(), + regKey); } - /** This method is a member of the interface for initializing an object - * directly after its creation. - * @param object This array of arbitrary objects will be passed to the - * component after its creation. - * @throws Exception Every exception will not be handled, but will be - * passed to the caller. - */ - public void initialize( Object[] object ) + + /** This method is a member of the interface for initializing an object + * directly after its creation. + * @param object This array of arbitrary objects will be passed to the + * component after its creation. + * @throws Exception Every exception will not be handled, but will be + * passed to the caller. + */ + public void initialize(Object[] object) throws com.sun.star.uno.Exception { - /* The component describes what arguments its expected and in which - * order!At this point you can read the objects and can intialize - * your component using these objects. - */ - } + /* The component describes what arguments its expected and in which + * order!At this point you can read the objects and can intialize + * your component using these objects. + */ + } } |