diff options
author | Rüdiger Timm <rt@openoffice.org> | 2008-12-10 14:25:11 +0000 |
---|---|---|
committer | Rüdiger Timm <rt@openoffice.org> | 2008-12-10 14:25:11 +0000 |
commit | 846e75eef7ac735f492cef899cc67bd83365f915 (patch) | |
tree | 9167b91cdbd7a775b1d81b6fecb551d34a2decd8 | |
parent | 92d94fc98efe24059ab8de0ed81ca31af5f8df98 (diff) |
CWS-TOOLING: integrate CWS ab65
2008-12-04 12:15:24 +0100 ab r264832 : #i83626# Removed warning
2008-12-04 12:04:09 +0100 ab r264830 : #i83626# Changed search result score handling
2008-11-28 13:37:09 +0100 ab r264548 : #i83626# Added missing juh.jar
2008-11-26 14:37:07 +0100 ab r264388 : #i83626# Added HelpComponent.java
2008-11-21 13:07:19 +0100 ab r264129 : #i83626# Fixed File URL versus system path confusion that made search operations fail on Unix
2008-11-19 12:22:10 +0100 ab r263978 : #i83627# Removed warning
2008-11-19 12:06:41 +0100 ab r263975 : #i83627# Removed warnings
2008-11-19 11:28:46 +0100 ab r263971 : #i83627# Support images in extension help
2008-11-11 11:48:21 +0100 ab r263551 : #i83626# Full text search in extension help
-rw-r--r-- | desktop/source/deployment/registry/help/dp_help.cxx | 34 | ||||
-rwxr-xr-x | xmlhelp/source/com/sun/star/help/HelpComponent.java | 138 | ||||
-rw-r--r-- | xmlhelp/source/com/sun/star/help/HelpIndexer.java | 356 | ||||
-rw-r--r-- | xmlhelp/source/com/sun/star/help/HelpLinker.cxx | 30 | ||||
-rw-r--r-- | xmlhelp/source/com/sun/star/help/HelpSearch.java | 655 | ||||
-rw-r--r-- | xmlhelp/source/com/sun/star/help/MANIFEST.MF | 2 | ||||
-rw-r--r-- | xmlhelp/source/com/sun/star/help/makefile.mk | 3 | ||||
-rw-r--r-- | xmlhelp/source/cxxhelp/provider/databases.cxx | 161 | ||||
-rw-r--r-- | xmlhelp/source/cxxhelp/provider/databases.hxx | 21 | ||||
-rw-r--r-- | xmlhelp/source/cxxhelp/provider/resultsetforquery.cxx | 312 | ||||
-rw-r--r-- | xmlhelp/source/cxxhelp/provider/urlparameter.cxx | 81 |
11 files changed, 1285 insertions, 508 deletions
diff --git a/desktop/source/deployment/registry/help/dp_help.cxx b/desktop/source/deployment/registry/help/dp_help.cxx index d5effdfa8680..bfd7bff3cb54 100644 --- a/desktop/source/deployment/registry/help/dp_help.cxx +++ b/desktop/source/deployment/registry/help/dp_help.cxx @@ -35,6 +35,7 @@ #include "dp_backend.h" #include "dp_ucb.h" #include "rtl/uri.hxx" +#include "osl/file.hxx" #include "ucbhelper/content.hxx" #include "comphelper/servicedecl.hxx" #include "svtools/inettype.hxx" @@ -44,6 +45,7 @@ #include <com/sun/star/util/XMacroExpander.hpp> #include <com/sun/star/uri/XUriReferenceFactory.hpp> #include <com/sun/star/uri/XVndSunStarExpandUrl.hpp> +#include <com/sun/star/script/XInvocation.hpp> using namespace ::dp_misc; using namespace ::com::sun::star; @@ -258,6 +260,15 @@ void BackendImpl::implProcessHelp makeAny( uno::Exception( aErrStr, oWeakThis ) ) ); } + Reference<XComponentContext> const & xContext = getComponentContext(); + Reference< script::XInvocation > xInvocation; + if( xContext.is() ) + { + xInvocation = Reference< script::XInvocation >( + xContext->getServiceManager()->createInstanceWithContext( rtl::OUString::createFromAscii( + "com.sun.star.help.HelpIndexer" ), xContext ) , UNO_QUERY ); + } + // Scan languages Sequence< rtl::OUString > aLanguageFolderSeq = xSFA->getFolderContents( aExpandedHelpURL, true ); sal_Int32 nLangCount = aLanguageFolderSeq.getLength(); @@ -335,6 +346,29 @@ void BackendImpl::implProcessHelp bool bSuccess = compileExtensionHelp( aHelpStr, aLangURL, nXhpFileCount, pXhpFiles, aErrorInfo ); + if( bSuccess && xInvocation.is() ) + { + Sequence<uno::Any> aParamsSeq( 6 ); + + aParamsSeq[0] = uno::makeAny( rtl::OUString::createFromAscii( "-lang" ) ); + rtl::OUString aLang; // TODO + aLang = rtl::OUString::createFromAscii( "de" ); // TODO + aParamsSeq[1] = uno::makeAny( aLang ); + + aParamsSeq[2] = uno::makeAny( rtl::OUString::createFromAscii( "-mod" ) ); + aParamsSeq[3] = uno::makeAny( rtl::OUString::createFromAscii( "help" ) ); + + aParamsSeq[4] = uno::makeAny( rtl::OUString::createFromAscii( "-zipdir" ) ); + rtl::OUString aSystemPath; + osl::FileBase::getSystemPathFromFileURL( aLangURL, aSystemPath ); + aParamsSeq[5] = uno::makeAny( aSystemPath ); + + Sequence< sal_Int16 > aOutParamIndex; + Sequence< uno::Any > aOutParam; + uno::Any aRet = xInvocation->invoke( rtl::OUString::createFromAscii( "createIndex" ), + aParamsSeq, aOutParamIndex, aOutParam ); + } + if( !bSuccess ) { USHORT nErrStrId = 0; diff --git a/xmlhelp/source/com/sun/star/help/HelpComponent.java b/xmlhelp/source/com/sun/star/help/HelpComponent.java new file mode 100755 index 000000000000..35c856ec5788 --- /dev/null +++ b/xmlhelp/source/com/sun/star/help/HelpComponent.java @@ -0,0 +1,138 @@ +/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: HelpSearch.java,v $
+ * $Revision: 1.2 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * 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.XSingleComponentFactory;
+import com.sun.star.registry.XRegistryKey;
+
+/*
+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;
+import com.sun.star.uno.AnyConverter;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+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;
+import org.apache.lucene.search.Searcher;
+import org.apache.lucene.search.TermQuery;
+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 HelpComponent
+{
+ /**
+ * Gives a factory for creating the service.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return returns a <code>XSingleComponentFactory</code> for creating
+ * the component
+ * @param sImplName the name of the implementation for which a
+ * service is desired
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static XSingleComponentFactory __getComponentFactory(String sImplName)
+ {
+ XSingleComponentFactory xFactory = null;
+
+ if ( sImplName.equals( HelpSearch._HelpSearch.class.getName() ) )
+ xFactory = Factory.createComponentFactory(HelpSearch._HelpSearch.class,
+ HelpSearch._HelpSearch.getServiceNames());
+ else if ( sImplName.equals( HelpIndexer.class.getName() ) )
+ xFactory = Factory.createComponentFactory(HelpIndexer.class,
+ HelpIndexer.getServiceNames());
+ return xFactory;
+ }
+
+ /**
+ * Writes the service information into the given registry key.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return returns true if the operation succeeded
+ * @param regKey the registryKey
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static boolean __writeRegistryServiceInfo(XRegistryKey regKey)
+ {
+ boolean bSuccessHelpSearch = Factory.writeRegistryServiceInfo
+ (HelpSearch._HelpSearch.class.getName(),
+ HelpSearch._HelpSearch.getServiceNames(), regKey);
+ boolean bSuccessHelpIndexer = Factory.writeRegistryServiceInfo
+ (HelpIndexer.class.getName(),
+ HelpIndexer.getServiceNames(), regKey);
+
+ return bSuccessHelpSearch && bSuccessHelpIndexer;
+ }
+ /** 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.
+ */
+ }
+}
diff --git a/xmlhelp/source/com/sun/star/help/HelpIndexer.java b/xmlhelp/source/com/sun/star/help/HelpIndexer.java index ce05b6f114e3..265bf6c7d383 100644 --- a/xmlhelp/source/com/sun/star/help/HelpIndexer.java +++ b/xmlhelp/source/com/sun/star/help/HelpIndexer.java @@ -27,8 +27,18 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + package com.sun.star.help; +import com.sun.star.lib.uno.helper.WeakBase;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.script.XInvocation;
+import com.sun.star.beans.XIntrospectionAccess;
+import com.sun.star.uno.Type;
+import com.sun.star.uno.Any;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.uno.XComponentContext;
+ import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.Arrays; @@ -47,15 +57,34 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.util.Date; -public class HelpIndexer { - - public HelpIndexer() { +import javax.swing.*;
+ +public class HelpIndexer extends WeakBase
+ implements XServiceInfo, XInvocation
+{
+ static private final String __serviceName =
+ "com.sun.star.help.HelpIndexer";
+ static private final String aCreateIndexMethodName = "createIndex";
+
+ public HelpIndexer() + { } + public HelpIndexer(XComponentContext xCompContext)
+ {
+ }
+
/** * @param args the command line arguments */ - public static void main(String[] args) { + public static void main( String[] args ) + { + boolean bExtensionMode = false; + mainImpl( args, bExtensionMode );
+ }
+
+ private static void mainImpl( String[] args, boolean bExtensionMode )
+ {
String aDirToZipStr = ""; String aLanguageStr = ""; String aModule = ""; @@ -68,27 +97,39 @@ public class HelpIndexer { boolean bOutput = false; int nArgCount = args.length; - for (int i = 0; i < nArgCount; i++) { - if ("-lang".equals(args[i])) { - if (i + 1 < nArgCount) { + for( int i = 0 ; i < nArgCount ; i++ ) + { + if( "-lang".equals(args[i]) ) + { + if( i + 1 < nArgCount ) + { aLanguageStr = args[i + 1]; bLang = true; } i++; - } else if ("-mod".equals(args[i])) { - if (i + 1 < nArgCount) { + } + else if( "-mod".equals(args[i]) ) + { + if( i + 1 < nArgCount ) + { aModule = args[i + 1]; bMod = true; } i++; - } else if ("-zipdir".equals(args[i])) { - if (i + 1 < nArgCount) { + } + else if( "-zipdir".equals(args[i]) ) + { + if( i + 1 < nArgCount ) + { aDirToZipStr = args[i + 1]; bZipDir = true; } i++; - } else if ("-o".equals(args[i])) { - if (i + 1 < nArgCount) { + } + else if( "-o".equals(args[i]) ) + { + if( i + 1 < nArgCount ) + { aTargetZipFileStr = args[i + 1]; bOutput = true; } @@ -96,129 +137,152 @@ public class HelpIndexer { } } - if (!bLang || !bMod || !bZipDir || !bOutput) { + if( !bLang || !bMod || !bZipDir || (!bOutput && !bExtensionMode) ) + { + if( bExtensionMode ) + return; + System.out.println("Usage: HelpIndexer -lang ISOLangCode -mod HelpModule -zipdir TempZipDir -o OutputZipFile"); - System.exit(-1); + System.exit( -1 ); } - File docDir = new File(aDirToZipStr); + File docDir = new File( aDirToZipStr ); String aIndexDirName = aModule + ".idxl"; - File aIndexDir = new File(aDirToZipStr + File.separator + aIndexDirName); - File aCaptionFilesDir = new File(aDirToZipStr + File.separator + "caption"); - File aContentFilesDir = new File(aDirToZipStr + File.separator + "content"); - - try { + File aIndexDir = new File( aDirToZipStr + File.separator + aIndexDirName ); + File aCaptionFilesDir = new File( aDirToZipStr + File.separator + "caption" ); + File aContentFilesDir = new File( aDirToZipStr + File.separator + "content" ); +
+ try + { Date start = new Date(); Analyzer analyzer = aLanguageStr.equals("ja") ? (Analyzer)new CJKAnalyzer() : (Analyzer)new StandardAnalyzer(); - IndexWriter writer = new IndexWriter(aIndexDir, analyzer, true); - System.out.println("Lucene: Indexing to directory '" + aIndexDir + "'..."); - int nRet = indexDocs(writer, aModule, aCaptionFilesDir, aContentFilesDir); - if (nRet != -1) { + IndexWriter writer = new IndexWriter( aIndexDir, analyzer, true ); + System.out.println( "Lucene: Indexing to directory '" + aIndexDir + "'..." ); + int nRet = indexDocs( writer, aModule, aCaptionFilesDir, aContentFilesDir ); + if( nRet != -1 ) + { System.out.println(); - System.out.println("Optimizing ..."); + System.out.println( "Optimizing ..." ); writer.optimize(); } writer.close(); - if (nRet == -1) { - deleteRecursively(aIndexDir); +
+ if( bExtensionMode )
+ {
+ deleteRecursively( aCaptionFilesDir ); + deleteRecursively( aContentFilesDir ); + }
+ else + { + if( nRet == -1 ) + deleteRecursively( aIndexDir ); + + System.out.println( "Zipping ..." ); + File aDirToZipFile = new File( aDirToZipStr ); + createZipFile( aDirToZipFile, aTargetZipFileStr ); + deleteRecursively( aDirToZipFile ); } - System.out.println("Zipping ..."); - File aDirToZipFile = new File(aDirToZipStr); - createZipFile(aDirToZipFile, aTargetZipFileStr); - deleteRecursively( aDirToZipFile ); - Date end = new Date(); System.out.println(end.getTime() - start.getTime() + " total milliseconds"); - } catch (IOException e) { + } + catch (IOException e) + { + if( bExtensionMode ) + return; + System.out.println(" caught a " + e.getClass() + - "\n with message: " + e.getMessage()); - System.exit(-1); + "\n with message: " + e.getMessage()); + System.exit( -1 ); } } private static int indexDocs(IndexWriter writer, String aModule, - File aCaptionFilesDir, File aContentFilesDir) throws IOException { - if (!aCaptionFilesDir.canRead() || !aCaptionFilesDir.isDirectory()) { - System.out.println("Not found: " + aCaptionFilesDir); + File aCaptionFilesDir, File aContentFilesDir) throws IOException + { + if( !aCaptionFilesDir.canRead() || !aCaptionFilesDir.isDirectory() ) + { + System.out.println( "Not found: " + aCaptionFilesDir ); return -1; } - if (!aContentFilesDir.canRead() || !aContentFilesDir.isDirectory()) { - System.out.println("Not found: " + aContentFilesDir); + if( !aContentFilesDir.canRead() || !aContentFilesDir.isDirectory() ) + { + System.out.println( "Not found: " + aContentFilesDir ); return -1; } String[] aCaptionFiles = aCaptionFilesDir.list(); - List aCaptionFilesList = Arrays.asList(aCaptionFiles); - HashSet aCaptionFilesHashSet = new HashSet(aCaptionFilesList); + List aCaptionFilesList = Arrays.asList( aCaptionFiles ); + HashSet aCaptionFilesHashSet = new HashSet( aCaptionFilesList ); String[] aContentFiles = aContentFilesDir.list(); - List aContentFilesList = Arrays.asList(aContentFiles); - HashSet aContentFilesHashSet = new HashSet(aContentFilesList); + List aContentFilesList = Arrays.asList( aContentFiles ); + HashSet aContentFilesHashSet = new HashSet( aContentFilesList ); // Loop over caption files and find corresponding content file - System.out.println("Indexing, adding files"); + System.out.println( "Indexing, adding files" ); int nCaptionFilesLen = aCaptionFiles.length; - for (int i = 0; i < nCaptionFilesLen; i++) { + for( int i = 0 ; i < nCaptionFilesLen ; i++ ) + { String aCaptionFileStr = aCaptionFiles[i]; - File aCaptionFile = new File(aCaptionFilesDir, aCaptionFileStr); + File aCaptionFile = new File( aCaptionFilesDir, aCaptionFileStr ); File aContentFile = null; - if (aContentFilesHashSet.contains(aCaptionFileStr)) { - aContentFile = new File(aContentFilesDir, aCaptionFileStr); - } + if( aContentFilesHashSet.contains( aCaptionFileStr ) ) + aContentFile = new File( aContentFilesDir, aCaptionFileStr ); - System.out.print("."); - writer.addDocument(HelpFileDocument.Document(aModule, aCaptionFile, aContentFile)); + System.out.print( "." ); + writer.addDocument( HelpFileDocument.Document( aModule, aCaptionFile, aContentFile ) ); } // Loop over content files to find remaining files not mapped to caption files int nContentFilesLen = aContentFiles.length; - for (int i = 0; i < nContentFilesLen; i++) { + for( int i = 0 ; i < nContentFilesLen ; i++ ) + { String aContentFileStr = aContentFiles[i]; - if (!aCaptionFilesHashSet.contains(aContentFileStr)) { + if( !aCaptionFilesHashSet.contains( aContentFileStr ) ) + { // Not already handled in caption files loop File aCaptionFile = null; - File aContentFile = new File(aContentFilesDir, aContentFileStr); - System.out.print("."); - writer.addDocument(HelpFileDocument.Document(aModule, aCaptionFile, aContentFile)); + File aContentFile = new File( aContentFilesDir, aContentFileStr ); + System.out.print( "." ); + writer.addDocument( HelpFileDocument.Document( aModule, aCaptionFile, aContentFile ) ); } } return 0; } - public static void createZipFile(File aDirToZip, String aTargetZipFileStr) - throws FileNotFoundException, IOException { - FileOutputStream fos = new FileOutputStream(aTargetZipFileStr); - ZipOutputStream zos = new ZipOutputStream(fos); + public static void createZipFile( File aDirToZip, String aTargetZipFileStr ) + throws FileNotFoundException, IOException + { + FileOutputStream fos = new FileOutputStream( aTargetZipFileStr ); + ZipOutputStream zos = new ZipOutputStream( fos ); File[] aChildrenFiles = aDirToZip.listFiles(); int nFileCount = aChildrenFiles.length; - for (int i = 0; i < nFileCount; i++) { - addToZipRecursively(zos, aChildrenFiles[i], null); - } + for( int i = 0 ; i < nFileCount ; i++ ) + addToZipRecursively( zos, aChildrenFiles[i], null ); zos.close(); } - public static void addToZipRecursively(ZipOutputStream zos, File aFile, String aBasePath) - throws FileNotFoundException, IOException { - if (aFile.isDirectory()) { + public static void addToZipRecursively( ZipOutputStream zos, File aFile, String aBasePath ) + throws FileNotFoundException, IOException + { + if( aFile.isDirectory() ) + { String aDirName = aFile.getName(); - if (aDirName.equalsIgnoreCase("caption") || aDirName.equalsIgnoreCase("content")) { + if( aDirName.equalsIgnoreCase( "caption" ) || aDirName.equalsIgnoreCase( "content" ) ) return; - } File[] aChildrenFiles = aFile.listFiles(); String aNewBasePath = ""; - if (aBasePath != null) { + if( aBasePath != null ) aNewBasePath += aBasePath + File.separator; - } aNewBasePath += aDirName; int nFileCount = aChildrenFiles.length; - for (int i = 0; i < nFileCount; i++) { - addToZipRecursively(zos, aChildrenFiles[i], aNewBasePath); - } + for( int i = 0 ; i < nFileCount ; i++ ) + addToZipRecursively( zos, aChildrenFiles[i], aNewBasePath ); return; } @@ -226,49 +290,149 @@ public class HelpIndexer { // No directory // read contents of file we are going to put in the zip int fileLength = (int) aFile.length(); - FileInputStream fis = new FileInputStream(aFile); + FileInputStream fis = new FileInputStream( aFile ); byte[] wholeFile = new byte[fileLength]; - int bytesRead = fis.read(wholeFile, 0, fileLength); + int bytesRead = fis.read( wholeFile, 0, fileLength ); fis.close(); String aFileName = aFile.getName(); String aEntryName = ""; - if (aBasePath != null) { + if( aBasePath != null ) aEntryName += aBasePath + "/"; - } aEntryName += aFileName; - ZipEntry aZipEntry = new ZipEntry(aEntryName); - aZipEntry.setTime(aFile.lastModified()); - aZipEntry.setSize(fileLength); + ZipEntry aZipEntry = new ZipEntry( aEntryName ); + aZipEntry.setTime( aFile.lastModified() ); + aZipEntry.setSize( fileLength ); - int nMethod = (aFileName.toLowerCase().endsWith(".jar")) + int nMethod = ( aFileName.toLowerCase().endsWith( ".jar" ) ) ? ZipEntry.STORED : ZipEntry.DEFLATED; - aZipEntry.setMethod(nMethod); + aZipEntry.setMethod( nMethod ); CRC32 tempCRC = new CRC32(); - tempCRC.update(wholeFile, 0, wholeFile.length); - aZipEntry.setCrc(tempCRC.getValue()); + tempCRC.update( wholeFile, 0, wholeFile.length ); + aZipEntry.setCrc( tempCRC.getValue() ); // write the contents into the zip element - zos.putNextEntry(aZipEntry); - zos.write(wholeFile, 0, fileLength); + zos.putNextEntry( aZipEntry ); + zos.write( wholeFile, 0, fileLength ); zos.closeEntry(); } - static public boolean deleteRecursively(File aFile) { - if (aFile.isDirectory()) { + static public boolean deleteRecursively( File aFile ) + { + if( aFile.isDirectory() ) + { File[] aChildrenFiles = aFile.listFiles(); int nFileCount = aChildrenFiles.length; - for (int i = 0; i < nFileCount; i++) { + for( int i = 0 ; i < nFileCount ; i++ ) + { File aChildrenFile = aChildrenFiles[i]; - boolean bSuccess = deleteRecursively(aChildrenFile); - if (!bSuccess) { + boolean bSuccess = deleteRecursively( aChildrenFile ); + if( !bSuccess ) return false; - } } } return aFile.delete(); } -} - +
+ //===================================================
+ // XInvocation
+ 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
+ {
+ if( !aFunctionName.equals( aCreateIndexMethodName ) )
+ throw new com.sun.star.lang.IllegalArgumentException();
+
+ aOutParamIndex[0] = new short[0];
+ aOutParam[0] = new Object[0];
+
+ int nParamCount = aParams.length;
+ String aStrs[] = new String[nParamCount];
+ for( int i = 0 ; i < nParamCount ; i++ )
+ {
+ try
+ {
+ aStrs[i] = AnyConverter.toString( aParams[i] );
+ }
+ catch( IllegalArgumentException e )
+ {
+ aStrs[i] = "";
+ }
+ }
+
+ boolean bExtensionMode = true; + mainImpl( aStrs, bExtensionMode );
+
+ return null;
+ }
+
+ 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
+ {
+ throw new com.sun.star.beans.UnknownPropertyException();
+ }
+
+ public boolean hasMethod( String aMethodName )
+ {
+ boolean bRet = (aMethodName.equals( aCreateIndexMethodName ) );
+ return bRet;
+ }
+ public boolean hasProperty( String aName ) {
+ return false;
+ }
+
+
+ /** This method returns an array of all supported service names.
+ * @return Array of supported service names.
+ */
+ public String[] getSupportedServiceNames()
+ {
+ return getServiceNames();
+ }
+
+ /** This method is a simple helper function to used in the
+ * static component initialisation functions as well as in
+ * getSupportedServiceNames.
+ */
+ public static String[] getServiceNames()
+ {
+ String[] sSupportedServiceNames = { __serviceName };
+ return sSupportedServiceNames;
+ }
+
+ /** This method returns true, if the given service will be
+ * supported by the component.
+ * @param sServiceName Service name.
+ * @return True, if the given service name will be supported.
+ */
+ 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 HelpIndexer.class.getName();
+ }
+}
+
diff --git a/xmlhelp/source/com/sun/star/help/HelpLinker.cxx b/xmlhelp/source/com/sun/star/help/HelpLinker.cxx index dcae7f4ae520..a696f32977b8 100644 --- a/xmlhelp/source/com/sun/star/help/HelpLinker.cxx +++ b/xmlhelp/source/com/sun/star/help/HelpLinker.cxx @@ -43,6 +43,7 @@ #include <sal/types.h> #include <osl/time.h> +#include <rtl/bootstrap.hxx> #ifdef SYSTEM_EXPAT #include <expat.h> @@ -344,7 +345,7 @@ void HelpLinker::initIndexerPreProcessor() */ void HelpLinker::link() throw( HelpProcessingException ) { - bool bIndexForExtension = false; // TODO + bool bIndexForExtension = true;
if( bExtensionMode ) { @@ -660,6 +661,8 @@ void HelpLinker::link() throw( HelpProcessingException ) void HelpLinker::main(std::vector<std::string> &args, std::string* pExtensionPath) throw( HelpProcessingException ) { + rtl::OUString aOfficeHelpPath; + bExtensionMode = false; if( pExtensionPath && pExtensionPath->length() > 0 ) { @@ -667,6 +670,9 @@ void HelpLinker::main(std::vector<std::string> &args, std::string* pExtensionPat bExtensionMode = true; extensionPath = *pExtensionPath; sourceRoot = fs::path(extensionPath); + + aOfficeHelpPath = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("$OOO_BASE_DIR/help") ); + rtl::Bootstrap::expandMacros( aOfficeHelpPath ); } if (args.size() > 0 && args[0][0] == '@') { @@ -839,12 +845,34 @@ void HelpLinker::main(std::vector<std::string> &args, std::string* pExtensionPat aStrStream << "no index caption stylesheet given" << std::endl; throw HelpProcessingException( HELPPROCESSING_GENERAL_ERROR, aStrStream.str() ); } + else if ( bExtensionMode )
+ {
+ rtl::OUString aIdxCaptionPathFileURL( aOfficeHelpPath );
+ aIdxCaptionPathFileURL += rtl::OUString::createFromAscii( "/idxcaption.xsl" );
+
+ rtl::OString aOStr_IdxCaptionPathFileURL( rtl::OUStringToOString + ( aIdxCaptionPathFileURL, fs::getThreadTextEncoding() ) ); + std::string aStdStr_IdxCaptionPathFileURL( aOStr_IdxCaptionPathFileURL.getStr() ); +
+ idxCaptionStylesheet = fs::path( aStdStr_IdxCaptionPathFileURL );
+ }
if (!bExtensionMode && idxContentStylesheet.empty()) { std::stringstream aStrStream; aStrStream << "no index content stylesheet given" << std::endl; throw HelpProcessingException( HELPPROCESSING_GENERAL_ERROR, aStrStream.str() ); } + else if ( bExtensionMode )
+ {
+ rtl::OUString aIdxContentPathFileURL( aOfficeHelpPath );
+ aIdxContentPathFileURL += rtl::OUString::createFromAscii( "/idxcontent.xsl" );
+
+ rtl::OString aOStr_IdxContentPathFileURL( rtl::OUStringToOString + ( aIdxContentPathFileURL, fs::getThreadTextEncoding() ) ); + std::string aStdStr_IdxContentPathFileURL( aOStr_IdxContentPathFileURL.getStr() ); +
+ idxContentStylesheet = fs::path( aStdStr_IdxContentPathFileURL );
+ }
if (!bExtensionMode && embeddStylesheet.empty()) { std::stringstream aStrStream; diff --git a/xmlhelp/source/com/sun/star/help/HelpSearch.java b/xmlhelp/source/com/sun/star/help/HelpSearch.java index c25bca066e02..e52dd2db7d83 100644 --- a/xmlhelp/source/com/sun/star/help/HelpSearch.java +++ b/xmlhelp/source/com/sun/star/help/HelpSearch.java @@ -1,304 +1,351 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: HelpSearch.java,v $ - * $Revision: 1.3 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * 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.XComponentContext; -import com.sun.star.registry.XRegistryKey; -import com.sun.star.lang.XServiceInfo; -import com.sun.star.uno.Type; -import com.sun.star.uno.Any; -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.IndexReader; -import org.apache.lucene.index.Term; -import org.apache.lucene.search.Hits; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.Searcher; -import org.apache.lucene.search.TermQuery; -import org.apache.lucene.search.WildcardQuery; - -import com.sun.star.script.XInvocation; -import com.sun.star.beans.XIntrospectionAccess; - -/** 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 { - - /** 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 { - - /** The service name, that must be used to get an instance of this service. - */ - static private final String __serviceName = - "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 - */ - private XMultiComponentFactory m_xMCF; - - /** The constructor of the inner class has a XMultiServiceFactory parameter. - * @param xmultiservicefactoryInitialization A special service factory - * could be introduced while initializing. - */ - public _HelpSearch(XComponentContext xCompContext) { - try { - m_cmpCtx = xCompContext; - m_xMCF = m_cmpCtx.getServiceManager(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** This method returns an array of all supported service names. - * @return Array of supported service names. - */ - public String[] getSupportedServiceNames() { - return getServiceNames(); - } - - /** This method is a simple helper function to used in the - * static component initialisation functions as well as in - * getSupportedServiceNames. - */ - public static String[] getServiceNames() { - String[] sSupportedServiceNames = {__serviceName}; - return sSupportedServiceNames; - } - - /** This method returns true, if the given service will be - * supported by the component. - * @param sServiceName Service name. - * @return True, if the given service name will be supported. - */ - 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(); - } - - //=================================================== - // XInvocation - 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 { - aOutParamIndex[0] = new short[0]; - aOutParam[0] = new Object[0]; - - String[] aRet = null; - if (!aFunctionName.equals(aSearchMethodName)) { - throw new com.sun.star.lang.IllegalArgumentException(); - } - - try { - aRet = doQuery(aParams); - } catch (Exception e) { - aRet = null; - } - - 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 { - throw new 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)); - return bRet; - } - - public boolean hasProperty(String aName) { - return false; - } - - // Command line interface for testing - 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) { - aStrs[i] = ""; - } - } - - // TODO: Error handling - for (int i = 0; i < nParamCount; i++) { - if ("-lang".equals(aStrs[i])) { - aLanguageStr = aStrs[i + 1]; - i++; - } else if ("-index".equals(aStrs[i])) { - aIndexStr = aStrs[i + 1]; - i++; - } else if ("-query".equals(aStrs[i])) { - aQueryStr = aStrs[i + 1]; - i++; - } else if ("-caption".equals(aStrs[i])) { - bCaptionOnly = true; - } - } - String[] aDocs = queryImpl(aLanguageStr, aIndexStr, aQueryStr, bCaptionOnly); - - return aDocs; - } - - 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) { - aField = "caption"; - } else { - aField = "content"; - } - - Query aQuery; - 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); - 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 : ""; - } - - reader.close(); - - return aDocs; - } - } - - /** - * Gives a factory for creating the service. - * This method is called by the <code>JavaLoader</code> - * <p> - * @return returns a <code>XSingleComponentFactory</code> for creating - * the component - * @param sImplName the name of the implementation for which a - * service is desired - * @see com.sun.star.comp.loader.JavaLoader - */ - public static XSingleComponentFactory __getComponentFactory(String sImplName) { - XSingleComponentFactory xFactory = null; - - if (sImplName.equals(_HelpSearch.class.getName())) { - xFactory = Factory.createComponentFactory(_HelpSearch.class, - _HelpSearch.getServiceNames()); - } - - return xFactory; - } - - /** - * Writes the service information into the given registry key. - * This method is called by the <code>JavaLoader</code> - * <p> - * @return returns true if the operation succeeded - * @param regKey the registryKey - * @see com.sun.star.comp.loader.JavaLoader - */ - public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) { - return Factory.writeRegistryServiceInfo(_HelpSearch.class.getName(), - _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) - 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. - */ - } -} +/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: HelpSearch.java,v $
+ * $Revision: 1.3 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * 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;
+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.search.Hits;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.Searcher;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.search.WildcardQuery;
+
+import com.sun.star.script.XInvocation;
+import com.sun.star.beans.XIntrospectionAccess;
+
+/** 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
+{
+ /** 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
+ {
+ /** The service name, that must be used to get an instance of this service.
+ */
+ static private final String __serviceName =
+ "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
+ */
+ private XMultiComponentFactory m_xMCF;
+
+ /** The constructor of the inner class has a XMultiServiceFactory parameter.
+ * @param xmultiservicefactoryInitialization A special service factory
+ * could be introduced while initializing.
+ */
+ public _HelpSearch(XComponentContext xCompContext)
+ {
+ try {
+ m_cmpCtx = xCompContext;
+ m_xMCF = m_cmpCtx.getServiceManager();
+ }
+ catch( Exception e ) {
+ e.printStackTrace();
+ }
+ }
+
+ /** This method returns an array of all supported service names.
+ * @return Array of supported service names.
+ */
+ public String[] getSupportedServiceNames()
+ {
+ return getServiceNames();
+ }
+
+ /** This method is a simple helper function to used in the
+ * static component initialisation functions as well as in
+ * getSupportedServiceNames.
+ */
+ public static String[] getServiceNames()
+ {
+ String[] sSupportedServiceNames = { __serviceName };
+ return sSupportedServiceNames;
+ }
+
+ /** This method returns true, if the given service will be
+ * supported by the component.
+ * @param sServiceName Service name.
+ * @return True, if the given service name will be supported.
+ */
+ 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();
+ }
+
+ //===================================================
+ // XInvocation
+ 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
+ {
+ String[] aRet = null;
+ if( !aFunctionName.equals( aSearchMethodName ) )
+ throw new com.sun.star.lang.IllegalArgumentException();
+
+ Object[] aScoreOutArray = new Object[1];
+ aScoreOutArray[0] = null;
+ try
+ {
+ aRet = doQuery( aParams, aScoreOutArray );
+ }
+ catch( Exception e )
+ {
+ aRet = null;
+ }
+
+ Object aScoreArray = aScoreOutArray[0];
+ if( aScoreArray == null )
+ {
+ aOutParamIndex[0] = new short[0];
+ aOutParam[0] = new Object[0];
+ }
+ else
+ {
+ short nInParamCount = (short)aParams.length;
+ aOutParamIndex[0] = new short[1];
+ aOutParamIndex[0][0] = nInParamCount;
+ aOutParam[0] = new Object[1];
+ aOutParam[0][0] = aScoreArray;
+ }
+
+ 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 {
+ throw new 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 ) );
+ return bRet;
+ }
+ public boolean hasProperty( String aName ) {
+ return false;
+ }
+
+ // Command line interface for testing
+ private static String[] doQuery( Object[] args, Object[] aScoreOutArray ) 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 )
+ {
+ aStrs[i] = "";
+ }
+ }
+
+ // TODO: Error handling
+ for( int i = 0 ; i < nParamCount ; i++ )
+ {
+ if ("-lang".equals(aStrs[i]) )
+ {
+ aLanguageStr = aStrs[i + 1];
+ i++;
+ }
+ else if( "-index".equals(aStrs[i]) )
+ {
+ aIndexStr = aStrs[i+1];
+ i++;
+ }
+ else if( "-query".equals(aStrs[i]) )
+ {
+ aQueryStr = aStrs[i+1];
+ i++;
+ }
+ else if( "-caption".equals(aStrs[i]) )
+ {
+ bCaptionOnly = true;
+ }
+ }
+ String[] aDocs = queryImpl( aLanguageStr, aIndexStr, aQueryStr, bCaptionOnly, aScoreOutArray );
+
+ return aDocs;
+ }
+
+ private static String[] queryImpl( String aLanguageStr, String aIndexStr, String aQueryStr,
+ boolean bCaptionOnly, Object[] aScoreOutArray ) 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 )
+ aField = "caption";
+ else
+ aField = "content";
+
+ Query aQuery;
+ 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 );
+ int nHitCount = aHits.length();
+
+ String aDocs[] = new String[nHitCount];
+ float aScores[] = null;
+ aScores = new float[nHitCount];
+ for( int iHit = 0 ; iHit < nHitCount ; iHit++ )
+ {
+ Document aDoc = aHits.doc( iHit );
+ String aPath = aDoc.get( "path" );
+ aDocs[iHit] = ( aPath != null ) ? aPath : "";
+ aScores[iHit] = aHits.score( iHit );
+ }
+ aScoreOutArray[0] = aScores;
+
+ reader.close();
+
+ return aDocs;
+ }
+ }
+
+ /**
+ * Gives a factory for creating the service.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return returns a <code>XSingleComponentFactory</code> for creating
+ * the component
+ * @param sImplName the name of the implementation for which a
+ * service is desired
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static XSingleComponentFactory __getComponentFactory(String sImplName)
+ {
+ XSingleComponentFactory xFactory = null;
+
+ if ( sImplName.equals( _HelpSearch.class.getName() ) )
+ xFactory = Factory.createComponentFactory(_HelpSearch.class,
+ _HelpSearch.getServiceNames());
+
+ return xFactory;
+ }
+
+ /**
+ * Writes the service information into the given registry key.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return returns true if the operation succeeded
+ * @param regKey the registryKey
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
+ return Factory.writeRegistryServiceInfo(_HelpSearch.class.getName(),
+ _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 )
+ 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.
+ */
+ }
+}
diff --git a/xmlhelp/source/com/sun/star/help/MANIFEST.MF b/xmlhelp/source/com/sun/star/help/MANIFEST.MF index 9a6238eabb6e..bf0e4ab46cb2 100644 --- a/xmlhelp/source/com/sun/star/help/MANIFEST.MF +++ b/xmlhelp/source/com/sun/star/help/MANIFEST.MF @@ -1,2 +1,2 @@ -RegistrationClassName: com.sun.star.help.HelpSearch +RegistrationClassName: com.sun.star.help.HelpComponent Class-Path: lucene-core-2.3.jar lucene-analyzers-2.3.jar diff --git a/xmlhelp/source/com/sun/star/help/makefile.mk b/xmlhelp/source/com/sun/star/help/makefile.mk index 6b5cf984489d..373e8f6c67dc 100644 --- a/xmlhelp/source/com/sun/star/help/makefile.mk +++ b/xmlhelp/source/com/sun/star/help/makefile.mk @@ -8,7 +8,7 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.39 $ +# $Revision: 1.38 $ # # This file is part of OpenOffice.org. # @@ -98,6 +98,7 @@ DEFLIB1NAME =$(TARGET) JAVACLASSFILES = \ $(CLASSDIR)$/$(PACKAGE)$/HelpSearch.class \ $(CLASSDIR)$/$(PACKAGE)$/HelpIndexer.class \ + $(CLASSDIR)$/$(PACKAGE)$/HelpComponent.class \ $(CLASSDIR)$/$(PACKAGE)$/HelpFileDocument.class JARFILES = ridl.jar jurt.jar unoil.jar juh.jar diff --git a/xmlhelp/source/cxxhelp/provider/databases.cxx b/xmlhelp/source/cxxhelp/provider/databases.cxx index ed0cf3e73649..578c428d6a35 100644 --- a/xmlhelp/source/cxxhelp/provider/databases.cxx +++ b/xmlhelp/source/cxxhelp/provider/databases.cxx @@ -81,16 +81,26 @@ static rtl::OUString aHelpMediaType( rtl::OUString::createFromAscii( "applicatio rtl::OUString Databases::expandURL( const rtl::OUString& aURL ) { + osl::MutexGuard aGuard( m_aMutex ); + rtl::OUString aRetURL = expandURL( aURL, m_xContext ); + return aRetURL; +} + +rtl::OUString Databases::expandURL( const rtl::OUString& aURL, Reference< uno::XComponentContext > xContext ) +{ static Reference< util::XMacroExpander > xMacroExpander; static Reference< uri::XUriReferenceFactory > xFac; - osl::MutexGuard aGuard( m_aMutex ); + if( !xContext.is() ) + return rtl::OUString(); if( !xMacroExpander.is() || !xFac.is() ) { + Reference< XMultiComponentFactory > xSMgr( xContext->getServiceManager(), UNO_QUERY ); + xFac = Reference< uri::XUriReferenceFactory >( - m_xSMgr->createInstanceWithContext( rtl::OUString::createFromAscii( - "com.sun.star.uri.UriReferenceFactory"), m_xContext ) , UNO_QUERY ); + xSMgr->createInstanceWithContext( rtl::OUString::createFromAscii( + "com.sun.star.uri.UriReferenceFactory"), xContext ) , UNO_QUERY ); if( !xFac.is() ) { throw RuntimeException( @@ -99,7 +109,7 @@ rtl::OUString Databases::expandURL( const rtl::OUString& aURL ) } xMacroExpander = Reference< util::XMacroExpander >( - m_xContext->getValueByName( + xContext->getValueByName( ::rtl::OUString::createFromAscii( "/singletons/com.sun.star.util.theMacroExpander" ) ), UNO_QUERY_THROW ); } @@ -1481,6 +1491,34 @@ Reference< deployment::XPackage > ExtensionIteratorBase::implGetNextSharedHelpPa return xHelpPackage; } +rtl::OUString ExtensionIteratorBase::implGetFileFromPackage( const rtl::OUString& rFileExtension, + com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage ) +{ + rtl::OUString aFile; + rtl::OUString aLanguage = m_aCorrectedLanguage; + for( sal_Int32 iPass = 0 ; iPass < 2 ; ++iPass ) + { + rtl::OUStringBuffer aStrBuf; + aStrBuf.append( xPackage->getURL() ); + aStrBuf.append( aSlash ); + aStrBuf.append( aLanguage ); + aStrBuf.append( aSlash ); + aStrBuf.append( aHelpFilesBaseName ); + aStrBuf.append( rFileExtension ); + + aFile = m_rDatabases.expandURL( aStrBuf.makeStringAndClear() ); + if( iPass == 0 ) + { + if( m_xSFA->exists( aFile ) ) + break; + if( m_aCorrectedLanguage.equals( aEnglishFallbackLang ) ) + break; + aLanguage = aEnglishFallbackLang; + } + } + return aFile; +} + //=================================================================== // class DataBaseIterator @@ -1611,28 +1649,9 @@ rtl::OUString KeyDataBaseFileIterator::nextDbFile( bool& o_rbExtension ) rtl::OUString KeyDataBaseFileIterator::implGetDbFileFromPackage ( Reference< deployment::XPackage > xPackage ) { - rtl::OUString aExpandedURL; - rtl::OUString aLanguage = m_aCorrectedLanguage; - for( sal_Int32 iPass = 0 ; iPass < 2 ; ++iPass ) - { - rtl::OUStringBuffer aStrBuf; - aStrBuf.append( xPackage->getURL() ); - aStrBuf.append( aSlash ); - aStrBuf.append( aLanguage ); - aStrBuf.append( aSlash ); - aStrBuf.append( aHelpFilesBaseName ); - aStrBuf.appendAscii( ".key" ); + rtl::OUString aExpandedURL = + implGetFileFromPackage( rtl::OUString::createFromAscii( ".key" ), xPackage ); - aExpandedURL = m_rDatabases.expandURL( aStrBuf.makeStringAndClear() ); - if( iPass == 0 ) - { - if( m_xSFA->exists( aExpandedURL ) ) - break; - if( m_aCorrectedLanguage.equals( aEnglishFallbackLang ) ) - break; - aLanguage = aEnglishFallbackLang; - } - } rtl::OUString aRetFile; osl::FileBase::getSystemPathFromFileURL( aExpandedURL, aRetFile ); @@ -1694,30 +1713,8 @@ Reference< XHierarchicalNameAccess > JarFileIterator::implGetJarFromPackage { Reference< XHierarchicalNameAccess > xNA; - rtl::OUString aExtensionPath = xPackage->getURL(); - - rtl::OUString zipFile; - rtl::OUString aLanguage = m_aCorrectedLanguage; - for( sal_Int32 iPass = 0 ; iPass < 2 ; ++iPass ) - { - rtl::OUStringBuffer aStrBuf; - aStrBuf.append( aExtensionPath ); - aStrBuf.append( aSlash ); - aStrBuf.append( aLanguage ); - aStrBuf.append( aSlash ); - aStrBuf.append( aHelpFilesBaseName ); - aStrBuf.append( rtl::OUString::createFromAscii( ".jar" ) ); - - zipFile = m_rDatabases.expandURL( aStrBuf.makeStringAndClear() ); - if( iPass == 0 ) - { - if( m_xSFA->exists( zipFile ) ) - break; - if( m_aCorrectedLanguage.equals( aEnglishFallbackLang ) ) - break; - aLanguage = aEnglishFallbackLang; - } - } + rtl::OUString zipFile = + implGetFileFromPackage( rtl::OUString::createFromAscii( ".jar" ), xPackage ); try { @@ -1751,3 +1748,69 @@ Reference< XHierarchicalNameAccess > JarFileIterator::implGetJarFromPackage return xNA; } + +//=================================================================== +// class IndexFolderIterator + +rtl::OUString IndexFolderIterator::nextIndexFolder( bool& o_rbExtension ) +{ + rtl::OUString aIndexFolder; + + while( !aIndexFolder.getLength() && m_eState != END_REACHED ) + { + switch( m_eState ) + { + case INITIAL_MODULE: + aIndexFolder = + m_rDatabases.getInstallPathAsURL() + + m_aCorrectedLanguage + aSlash + m_aInitialModule + + rtl::OUString::createFromAscii( ".idxl" ); + + o_rbExtension = false; + + m_eState = USER_EXTENSIONS; // Later: SHARED_MODULE + break; + + // Later: + //case SHARED_MODULE + //... + + case USER_EXTENSIONS: + { + Reference< deployment::XPackage > xParentPackageBundle; + Reference< deployment::XPackage > xHelpPackage = implGetNextUserHelpPackage( xParentPackageBundle ); + if( !xHelpPackage.is() ) + break; + + aIndexFolder = implGetIndexFolderFromPackage( xHelpPackage ); + o_rbExtension = true; + break; + } + + case SHARED_EXTENSIONS: + { + Reference< deployment::XPackage > xParentPackageBundle; + Reference< deployment::XPackage > xHelpPackage = implGetNextSharedHelpPackage( xParentPackageBundle ); + if( !xHelpPackage.is() ) + break; + + aIndexFolder = implGetIndexFolderFromPackage( xHelpPackage ); + o_rbExtension = true; + break; + } + case END_REACHED: + VOS_ENSURE( false, "IndexFolderIterator::nextIndexFolder(): Invalid case END_REACHED" ); + break; + } + } + + return aIndexFolder; +} + +rtl::OUString IndexFolderIterator::implGetIndexFolderFromPackage( Reference< deployment::XPackage > xPackage ) +{ + rtl::OUString aIndexFolder = + implGetFileFromPackage( rtl::OUString::createFromAscii( ".idxl" ), xPackage ); + return aIndexFolder; +} + diff --git a/xmlhelp/source/cxxhelp/provider/databases.hxx b/xmlhelp/source/cxxhelp/provider/databases.hxx index 82f993384606..f098f8109b34 100644 --- a/xmlhelp/source/cxxhelp/provider/databases.hxx +++ b/xmlhelp/source/cxxhelp/provider/databases.hxx @@ -306,6 +306,9 @@ namespace chelp { rtl::OUString expandURL( const rtl::OUString& aURL ); + static rtl::OUString expandURL( const rtl::OUString& aURL, + com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext ); + private: osl::Mutex m_aMutex; @@ -448,6 +451,8 @@ namespace chelp { ( com::sun::star::uno::Reference< com::sun::star::deployment::XPackage >& o_xParentPackageBundle ); com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > implGetNextSharedHelpPackage ( com::sun::star::uno::Reference< com::sun::star::deployment::XPackage >& o_xParentPackageBundle ); + rtl::OUString implGetFileFromPackage( const rtl::OUString& rFileExtension, + com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage ); com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > m_xContext; com::sun::star::uno::Reference< com::sun::star::ucb::XSimpleFileAccess > m_xSFA; @@ -537,6 +542,22 @@ namespace chelp { }; // end class JarFileIterator //=================================================================== + class IndexFolderIterator : public ExtensionIteratorBase + { + public: + IndexFolderIterator( Databases& rDatabases, const rtl::OUString& aInitialModule, const rtl::OUString& aLanguage ) + : ExtensionIteratorBase( rDatabases, aInitialModule, aLanguage ) + {} + + rtl::OUString nextIndexFolder( bool& o_rbExtension ); + + private: + rtl::OUString implGetIndexFolderFromPackage( + com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage ); + + }; // end class KeyDataBaseFileIterator + + //=================================================================== } // end namespace chelp diff --git a/xmlhelp/source/cxxhelp/provider/resultsetforquery.cxx b/xmlhelp/source/cxxhelp/provider/resultsetforquery.cxx index 8cfb95a5c8b6..0d1d4c4c2424 100644 --- a/xmlhelp/source/cxxhelp/provider/resultsetforquery.cxx +++ b/xmlhelp/source/cxxhelp/provider/resultsetforquery.cxx @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: resultsetforquery.cxx,v $ - * $Revision: 1.18 $ + * $Revision: 1.17 $ * * This file is part of OpenOffice.org. * @@ -50,6 +50,9 @@ #include "resultsetforquery.hxx" #include "databases.hxx" +// For testing +// #define LOGGING + using namespace std; using namespace chelp; using namespace xmlsearch::excep; @@ -60,6 +63,22 @@ using namespace com::sun::star::i18n; using namespace com::sun::star::uno; using namespace com::sun::star::lang; +struct HitItem +{ + rtl::OUString m_aURL; + float m_fScore; + + HitItem( void ) {} + HitItem( const rtl::OUString& aURL, float fScore ) + : m_aURL( aURL ) + , m_fScore( fScore ) + {} + bool operator < ( const HitItem& rHitItem ) const + { + return rHitItem.m_fScore < m_fScore; + } +}; + ResultSetForQuery::ResultSetForQuery( const uno::Reference< lang::XMultiServiceFactory >& xMSF, const uno::Reference< XContentProvider >& xProvider, sal_Int32 nOpenMode, @@ -86,7 +105,6 @@ ResultSetForQuery::ResultSetForQuery( const uno::Reference< lang::XMultiServiceF xMSF->createInstance( rtl::OUString::createFromAscii( "com.sun.star.help.HelpSearch" ) ), UNO_QUERY ); - unsigned int i; vector< vector< rtl::OUString > > queryList; { sal_Int32 idx; @@ -117,96 +135,288 @@ ResultSetForQuery::ResultSetForQuery( const uno::Reference< lang::XMultiServiceF } } - set< rtl::OUString > aSet,aCurrent,aResultSet; + vector< rtl::OUString > aCompleteResultVector; if( xInvocation.is() ) { rtl::OUString scope = m_aURLParameter.get_scope(); bool bCaptionsOnly = ( scope.compareToAscii( "Heading" ) == 0 ); sal_Int32 hitCount = m_aURLParameter.get_hitCount(); - try - { - rtl::OUString idxDir; - idxDir = - m_pDatabases->getInstallPathAsURL() + - m_pDatabases->lang( m_aURLParameter.get_language() ) + - rtl::OUString::createFromAscii( "/" ) + - m_aURLParameter.get_module() + - rtl::OUString::createFromAscii( ".idxl/" ); - - if(queryList.size() > 1) - hitCount = 2000; - - for( i = 0; i < queryList.size(); ++i ) - { - if( xInvocation.is() ) - { - int nParamCount = bCaptionsOnly ? 7 : 6; - Sequence<uno::Any> aParamsSeq( nParamCount ); - - aParamsSeq[0] = uno::makeAny( rtl::OUString::createFromAscii( "-lang" ) ); - aParamsSeq[1] = uno::makeAny( m_aURLParameter.get_language() ); +#ifdef LOGGING + FILE* pFile = fopen( "d:\\resultset_out.txt", "w" ); +#endif - aParamsSeq[2] = uno::makeAny( rtl::OUString::createFromAscii( "-index" ) ); - rtl::OUString aSystemPath; - osl::FileBase::getSystemPathFromFileURL( idxDir, aSystemPath ); - aParamsSeq[3] = uno::makeAny( aSystemPath ); + IndexFolderIterator aIndexFolderIt( *pDatabases, m_aURLParameter.get_module(), m_aURLParameter.get_language() ); + rtl::OUString idxDir; + bool bExtension = false; + int iDir = 0; + vector< vector<HitItem>* > aIndexFolderResultVectorVector; + while( (idxDir = aIndexFolderIt.nextIndexFolder( bExtension )).getLength() > 0 ) + { + vector<HitItem> aIndexFolderResultVector; - aParamsSeq[4] = uno::makeAny( rtl::OUString::createFromAscii( "-query" ) ); + try + { + vector< vector<HitItem>* > aQueryListResultVectorVector; + set< rtl::OUString > aSet,aCurrent,aResultSet;
+
+ int nQueryListSize = queryList.size(); + if( nQueryListSize > 1 ) + hitCount = 2000; - const std::vector< rtl::OUString >& aListItem = queryList[i]; - ::rtl::OUString aNewQueryStr = aListItem[0]; - aParamsSeq[5] = uno::makeAny( aNewQueryStr ); + for( int i = 0; i < nQueryListSize; ++i ) + { + vector<HitItem>* pQueryResultVector; + if( nQueryListSize > 1 ) + { + pQueryResultVector = new vector<HitItem>(); + aQueryListResultVectorVector.push_back( pQueryResultVector ); + } + else + { + pQueryResultVector = &aIndexFolderResultVector; + } + pQueryResultVector->reserve( hitCount ); - if( bCaptionsOnly ) - aParamsSeq[6] = uno::makeAny( rtl::OUString::createFromAscii( "-caption" ) ); + int nParamCount = bCaptionsOnly ? 7 : 6;
+ Sequence<uno::Any> aParamsSeq( nParamCount );
+
+ aParamsSeq[0] = uno::makeAny( rtl::OUString::createFromAscii( "-lang" ) );
+ aParamsSeq[1] = uno::makeAny( m_aURLParameter.get_language() );
+
+ aParamsSeq[2] = uno::makeAny( rtl::OUString::createFromAscii( "-index" ) );
+ rtl::OUString aSystemPath;
+ osl::FileBase::getSystemPathFromFileURL( idxDir, aSystemPath );
+ aParamsSeq[3] = uno::makeAny( aSystemPath );
+
+ aParamsSeq[4] = uno::makeAny( rtl::OUString::createFromAscii( "-query" ) );
+
+ const std::vector< rtl::OUString >& aListItem = queryList[i];
+ ::rtl::OUString aNewQueryStr = aListItem[0];
+ aParamsSeq[5] = uno::makeAny( aNewQueryStr );
+
+ if( bCaptionsOnly )
+ aParamsSeq[6] = uno::makeAny( rtl::OUString::createFromAscii( "-caption" ) );
Sequence< sal_Int16 > aOutParamIndex; Sequence< uno::Any > aOutParam; + uno::Any aRet = xInvocation->invoke( rtl::OUString::createFromAscii( "search" ), aParamsSeq, aOutParamIndex, aOutParam ); + Sequence< float > aScoreSeq; + int nScoreCount = 0; + int nOutParamCount = aOutParam.getLength(); + if( nOutParamCount == 1 ) + { + const uno::Any* pScoreAnySeq = aOutParam.getConstArray(); + if( pScoreAnySeq[0] >>= aScoreSeq ) + nScoreCount = aScoreSeq.getLength(); + } + Sequence<rtl::OUString> aRetSeq; if( aRet >>= aRetSeq ) { - aSet.clear(); + if( nQueryListSize > 1 ) + aSet.clear(); const rtl::OUString* pRetSeq = aRetSeq.getConstArray(); int nCount = aRetSeq.getLength(); if( nCount > hitCount ) nCount = hitCount; for( int j = 0 ; j < nCount ; ++j ) - aSet.insert( pRetSeq[j] ); + { + float fScore = 0.0; + if( j < nScoreCount ) + fScore = aScoreSeq[j]; + + rtl::OUString aURL = pRetSeq[j]; + pQueryResultVector->push_back( HitItem( aURL, fScore ) ); + if( nQueryListSize > 1 ) + aSet.insert( aURL ); + +#ifdef LOGGING + if( pFile ) + { + rtl::OString tmp(rtl::OUStringToOString( aURL, RTL_TEXTENCODING_UTF8)); + fprintf( pFile, "Dir %d, Query %d, Item: score=%f, URL=%s\n", iDir, i, fScore, tmp.getStr() ); + } +#endif + } } + + // intersect
+ if( nQueryListSize > 1 ) + { + if( i == 0 )
+ {
+ aResultSet = aSet;
+ }
+ else
+ {
+ aCurrent = aResultSet;
+ aResultSet.clear();
+ set_intersection( aSet.begin(),aSet.end(),
+ aCurrent.begin(),aCurrent.end(),
+ inserter(aResultSet,aResultSet.begin()));
+ }
+ }
} - // intersect - if( i == 0 ) - aResultSet = aSet; - else + // Combine results in aIndexFolderResultVector + if( nQueryListSize > 1 ) { - aCurrent = aResultSet; - aResultSet.clear(); - set_intersection( aSet.begin(),aSet.end(), - aCurrent.begin(),aCurrent.end(), - inserter(aResultSet,aResultSet.begin())); + for( int n = 0 ; n < nQueryListSize ; ++n ) + { + vector<HitItem>* pQueryResultVector = aQueryListResultVectorVector[n]; + vector<HitItem>& rQueryResultVector = *pQueryResultVector; + + int nItemCount = rQueryResultVector.size(); + for( int i = 0 ; i < nItemCount ; ++i ) + { + const HitItem& rItem = rQueryResultVector[ i ]; + set< rtl::OUString >::iterator it; + if( (it = aResultSet.find( rItem.m_aURL )) != aResultSet.end() ) + { + HitItem aItemCopy( rItem ); + aItemCopy.m_fScore /= nQueryListSize; // To get average score + if( n == 0 ) + { + // Use first pass to create entry + aIndexFolderResultVector.push_back( aItemCopy ); + +#ifdef LOGGING + if( pFile ) + { + rtl::OString tmp(rtl::OUStringToOString( aItemCopy.m_aURL, RTL_TEXTENCODING_UTF8)); + fprintf( pFile, "Combine: Query %d (first pass), Item %d: score=%f (%f), URL=%s\n", n, i, aItemCopy.m_fScore, rItem.m_fScore, tmp.getStr() ); + } +#endif + } + else + { + // Find entry in vector + int nCount = aIndexFolderResultVector.size(); + for( int j = 0 ; j < nCount ; ++j ) + { + HitItem& rFindItem = aIndexFolderResultVector[ j ]; + if( rFindItem.m_aURL.equals( aItemCopy.m_aURL ) ) + { +#ifdef LOGGING + if( pFile ) + { + rtl::OString tmp(rtl::OUStringToOString( aItemCopy.m_aURL, RTL_TEXTENCODING_UTF8)); + fprintf( pFile, "Combine: Query %d, Item %d: score=%f + %f = %f, URL=%s\n", n, i, + rFindItem.m_fScore, aItemCopy.m_fScore, rFindItem.m_fScore + aItemCopy.m_fScore, tmp.getStr() ); + } +#endif + + rFindItem.m_fScore += aItemCopy.m_fScore; + break; + } + } + } + } + } + + delete pQueryResultVector; + } + + sort( aIndexFolderResultVector.begin(), aIndexFolderResultVector.end() ); + } + + vector<HitItem>* pIndexFolderHitItemVector = new vector<HitItem>( aIndexFolderResultVector ); + aIndexFolderResultVectorVector.push_back( pIndexFolderHitItemVector ); + aIndexFolderResultVector.clear(); + } + catch( const Exception& ) + { + } + + ++iDir; + + } // Iterator + + + int nVectorCount = aIndexFolderResultVectorVector.size(); + vector<HitItem>::size_type* pCurrentVectorIndex = new vector<HitItem>::size_type[nVectorCount]; + for( int j = 0 ; j < nVectorCount ; ++j ) + pCurrentVectorIndex[j] = 0; + +#ifdef LOGGING + if( pFile ) + { + for( int k = 0 ; k < nVectorCount ; ++k ) + { + vector<HitItem>& rIndexFolderVector = *aIndexFolderResultVectorVector[k]; + int nItemCount = rIndexFolderVector.size(); + + fprintf( pFile, "Vector %d, %d elements\n", k, nItemCount ); + + for( int i = 0 ; i < nItemCount ; ++i ) + { + const HitItem& rItem = rIndexFolderVector[ i ]; + rtl::OString tmp(rtl::OUStringToOString(rItem.m_aURL, RTL_TEXTENCODING_UTF8)); + fprintf( pFile, " Item_vector%d, %d/%d: score=%f, URL=%s\n", k, i, nItemCount, rItem.m_fScore, tmp.getStr() ); + } + } + } +#endif + + sal_Int32 nTotalHitCount = m_aURLParameter.get_hitCount(); + sal_Int32 nHitCount = 0; + while( nHitCount < nTotalHitCount ) + { + int iVectorWithBestScore = -1; + float fBestScore = 0.0; + for( int k = 0 ; k < nVectorCount ; ++k ) + { + vector<HitItem>& rIndexFolderVector = *aIndexFolderResultVectorVector[k]; + if( pCurrentVectorIndex[k] < rIndexFolderVector.size() ) + { + const HitItem& rItem = rIndexFolderVector[ pCurrentVectorIndex[k] ]; + + if( fBestScore < rItem.m_fScore ) + { + fBestScore = rItem.m_fScore; + iVectorWithBestScore = k; + } } } + + if( iVectorWithBestScore == -1 ) // No item left at all + break; + + vector<HitItem>& rIndexFolderVector = *aIndexFolderResultVectorVector[iVectorWithBestScore]; + const HitItem& rItem = rIndexFolderVector[ pCurrentVectorIndex[iVectorWithBestScore] ]; + + pCurrentVectorIndex[iVectorWithBestScore]++; + + aCompleteResultVector.push_back( rItem.m_aURL ); + ++nHitCount; } - catch( const Exception& ) + + delete[] pCurrentVectorIndex; + for( int n = 0 ; n < nVectorCount ; ++n ) { + vector<HitItem>* pIndexFolderVector = aIndexFolderResultVectorVector[n]; + delete pIndexFolderVector; } + +#ifdef LOGGING + fclose( pFile ); +#endif } sal_Int32 replIdx = rtl::OUString::createFromAscii( "#HLP#" ).getLength(); rtl::OUString replWith = rtl::OUString::createFromAscii( "vnd.sun.star.help://" ); - set< rtl::OUString >::const_iterator set_it = aResultSet.begin(); - while( set_it != aResultSet.end() ) + int nResultCount = aCompleteResultVector.size(); + for( int r = 0 ; r < nResultCount ; ++r ) { - rtl::OUString aResultStr = replWith + set_it->copy(replIdx); + rtl::OUString aURL = aCompleteResultVector[r]; + rtl::OUString aResultStr = replWith + aURL.copy(replIdx); m_aPath.push_back( aResultStr ); - ++set_it; } m_aItems.resize( m_aPath.size() ); diff --git a/xmlhelp/source/cxxhelp/provider/urlparameter.cxx b/xmlhelp/source/cxxhelp/provider/urlparameter.cxx index 76a7d1902891..59ffaa2aa6c9 100644 --- a/xmlhelp/source/cxxhelp/provider/urlparameter.cxx +++ b/xmlhelp/source/cxxhelp/provider/urlparameter.cxx @@ -46,6 +46,7 @@ #include <osl/file.hxx> #include <cppuhelper/weak.hxx> #include <cppuhelper/queryinterface.hxx> +#include <comphelper/processfactory.hxx> #include <rtl/uri.hxx> #include <rtl/ustrbuf.hxx> #include <libxslt/xslt.h> @@ -63,6 +64,7 @@ #include <com/sun/star/ucb/XContentProvider.hpp> #include <com/sun/star/ucb/XContentIdentifierFactory.hpp> #include <com/sun/star/container/XHierarchicalNameAccess.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> #include "urlparameter.hxx" #include "databases.hxx" @@ -92,6 +94,7 @@ using namespace com::sun::star::io; using namespace com::sun::star::uno; using namespace com::sun::star::lang; using namespace com::sun::star::ucb; +using namespace com::sun::star::beans; using namespace com::sun::star::container; using namespace berkeleydbproxy; using namespace chelp; @@ -876,6 +879,18 @@ fileClose(void * context) { } // extern "C" +/* +// For debugging only +extern "C" void StructuredXMLErrorFunction(void *userData, xmlErrorPtr error) +{ + (void)userData; + (void)error; + + // Reset error handler + xmlSetStructuredErrorFunc( NULL, NULL ); +} +*/ + InputStreamTransformer::InputStreamTransformer( URLParameter* urlParam, Databases* pDatabases, bool isRoot ) @@ -905,20 +920,24 @@ InputStreamTransformer::InputStreamTransformer( URLParameter* urlParam, // Uses the implementation detail, that rtl::OString::getStr returns a zero terminated character-array - const char* parameter[44]; - rtl::OString parString[43]; + const char* parameter[47]; + rtl::OString parString[46]; int last = 0; parString[last++] = "Program"; - parString[last++] = rtl::OString('\'') + urlParam->getByName( "Program" ) + rtl::OString('\''); + rtl::OString aPureProgramm( urlParam->getByName( "Program" ) ); + parString[last++] = rtl::OString('\'') + aPureProgramm + rtl::OString('\''); parString[last++] = "Database"; parString[last++] = rtl::OString('\'') + urlParam->getByName( "DatabasePar" ) + rtl::OString('\''); parString[last++] = "Id"; parString[last++] = rtl::OString('\'') + urlParam->getByName( "Id" ) + rtl::OString('\''); parString[last++] = "Path"; - parString[last++] = rtl::OString('\'') + urlParam->getByName( "Path" ) + rtl::OString('\''); + rtl::OString aPath( urlParam->getByName( "Path" ) ); + parString[last++] = rtl::OString('\'') + aPath + rtl::OString('\''); + + rtl::OString aPureLanguage = urlParam->getByName( "Language" ); parString[last++] = "Language"; - parString[last++] = rtl::OString('\'') + urlParam->getByName( "Language" ) + rtl::OString('\''); + parString[last++] = rtl::OString('\'') + aPureLanguage + rtl::OString('\''); parString[last++] = "System"; parString[last++] = rtl::OString('\'') + urlParam->getByName( "System" ) + rtl::OString('\''); parString[last++] = "productname"; @@ -973,6 +992,57 @@ InputStreamTransformer::InputStreamTransformer( URLParameter* urlParam, RTL_TEXTENCODING_UTF8 ) + rtl::OString('\''); } + rtl::OString aPureExtensionId; + rtl::OString aExpandedExtensionPath; + if( !aPureProgramm.getLength() ) + { + // Extension jar file? Search for ? + rtl::OUString aJar = urlParam->get_jar(); + sal_Int32 nQuestionMark1 = aJar.indexOf( sal_Unicode('?') ); + sal_Int32 nQuestionMark2 = aJar.lastIndexOf( sal_Unicode('?') ); + if( nQuestionMark1 != -1 && nQuestionMark2 != -1 && nQuestionMark1 != nQuestionMark2 ) + { + // ExtensionPath + ::rtl::OUString aExtensionPath = aJar.copy( nQuestionMark1 + 1, nQuestionMark2 - nQuestionMark1 - 1 ); + + Reference< XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory(); + Reference< XPropertySet > xProps( xFactory, UNO_QUERY ); + OSL_ASSERT( xProps.is() ); + Reference< XComponentContext > xContext; + if (xProps.is()) + { + xProps->getPropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xContext; + } + if( !xContext.is() ) + { + throw RuntimeException( + ::rtl::OUString::createFromAscii( "InputStreamTransformer::InputStreamTransformer(), no XComponentContext" ), + Reference< XInterface >() ); + } + + rtl::OUString aOUExpandedExtensionPath = Databases::expandURL( aExtensionPath, xContext ); + aExpandedExtensionPath = rtl::OUStringToOString( aOUExpandedExtensionPath, osl_getThreadTextEncoding() ); + + // Add extension language part + rtl::OString aExtensionLanguage = aPureLanguage; + if( aExtensionLanguage.getLength() > 2 ) + aExtensionLanguage = aExtensionLanguage.copy( 0, 2 ); + aExpandedExtensionPath += rtl::OString('/'); + aExpandedExtensionPath += aExtensionLanguage; + parString[last++] = "ExtensionPath"; + parString[last++] = rtl::OString('\'') + aExpandedExtensionPath + rtl::OString('\''); + + // ExtensionId + sal_Int32 iSlash = aPath.indexOf( '/' ); + if( iSlash != -1 ) + aPureExtensionId = aPath.copy( 0, iSlash ); + + parString[last++] = "ExtensionId"; + parString[last++] = rtl::OString('\'') + aPureExtensionId + rtl::OString('\''); + } + } + for( int i = 0; i < last; ++i ) parameter[i] = parString[i].getStr(); parameter[last] = 0; @@ -990,6 +1060,7 @@ InputStreamTransformer::InputStreamTransformer( URLParameter* urlParam, xmlRegisterInputCallbacks(pkgMatch, pkgOpen, pkgRead, uriClose); xmlRegisterInputCallbacks(helpMatch, helpOpen, helpRead, uriClose); xmlRegisterInputCallbacks(fileMatch, fileOpen, fileRead, fileClose); + //xmlSetStructuredErrorFunc( NULL, (xmlStructuredErrorFunc)StructuredXMLErrorFunction ); xsltStylesheetPtr cur = xsltParseStylesheetFile((const xmlChar *)xslURLascii.getStr()); |