javahelp2-2.0.05/javahelp_nbproject/ 0000755 0001750 0001750 00000000000 11220022253 016347 5 ustar varun varun javahelp2-2.0.05/javahelp_nbproject/manifest.mf 0000644 0001750 0001750 00000001167 10661201734 020521 0 ustar varun varun Manifest-Version: 1.0
Created-By: 1.5.0_08 (Sun Microsystems Inc.)
Specification-Version: 2.0
Specification-Vendor: Sun Microsystems, Inc
Implementation-Vendor-Id: com.sun
Extension-Name: javax.help
Implementation-Version: 2.0_03
Implementation-Vendor: Sun Microsystems, Inc
Name: javax/help/JHelpContentViewer.class
Java-Bean: True
Name: javax/help/JHelpTOCNavigator.class
Java-Bean: True
Name: javax/help/
Package-Sealed: true
Name: javax/help/JHelpIndexNavigator.class
Java-Bean: True
Name: javax/help/JHelpSearchNavigator.class
Java-Bean: True
Name: javax/help/JHelp.class
Java-Bean: True
javahelp2-2.0.05/javahelp_nbproject/nbproject/ 0000755 0001750 0001750 00000000000 11220022253 020335 5 ustar varun varun javahelp2-2.0.05/javahelp_nbproject/nbproject/build-impl.xml 0000644 0001750 0001750 00000065661 10661201734 023146 0 ustar varun varun
Must set src.impl.dirMust set src.new.dirMust set build.dirMust set dist.dirMust set build.classes.dirMust set dist.javadoc.dirMust set build.test.classes.dirMust set build.test.results.dirMust set build.classes.excludesMust set dist.jarMust select some files in the IDE or set javac.includesTo run this application from the command line without Ant, try:java -cp "${run.classpath.with.dist.jar}" ${main.class}To run this application from the command line without Ant, try:java -jar "${dist.jar.resolved}"Must select one file in the IDE or set run.classMust select one file in the IDE or set debug.classMust set fix.includesMust select some files in the IDE or set javac.includesSome tests failed; see details above.Must select some files in the IDE or set test.includesSome tests failed; see details above.Must select one file in the IDE or set test.classMust select one file in the IDE or set applet.urlMust select one file in the IDE or set applet.url
javahelp2-2.0.05/javahelp_nbproject/nbproject/genfiles.properties 0000644 0001750 0001750 00000000707 10661201734 024266 0 ustar varun varun build.xml.data.CRC32=bc1e27e0
build.xml.script.CRC32=079caa17
build.xml.stylesheet.CRC32=a12b3d02
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=74a01f5f
nbproject/build-impl.xml.script.CRC32=357bfc33
nbproject/build-impl.xml.stylesheet.CRC32=2093e0f1
javahelp2-2.0.05/javahelp_nbproject/nbproject/project.xml 0000644 0001750 0001750 00000001054 10661201734 022540 0 ustar varun varun
org.netbeans.modules.java.j2seprojectJavaHelp1.6.5
javahelp2-2.0.05/javahelp_nbproject/nbproject/project.properties 0000644 0001750 0001750 00000006427 10661201734 024145 0 ustar varun varun # Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun in the LICENSE file that accompanied this code.
#
# This code 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 General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form,**/*.html
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
debug.classpath=\
${run.classpath}
debug.test.classpath=\
${run.test.classpath}
# This directory is removed when the project is cleaned:
dist.dir=dist/lib
dist.jar=${dist.dir}/jh-client.jar
dist.javadoc.dir=${dist.dir}/javadoc
file.reference.jdic.jar=lib/jdic.jar
file.reference.jsp-api.jar=lib/jsp-api.jar
file.reference.servlet-api.jar=lib/servlet-api.jar
file.reference.space-javahelp=..
file.reference.src-impl=../jhMaster/JavaHelp/src/impl
file.reference.src-new=../jhMaster/JavaHelp/src/new
jar.compress=false
javac.classpath=\
${file.reference.servlet-api.jar}:\
${file.reference.jsp-api.jar}:\
${file.reference.jdic.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.source=1.4
javac.target=1.4
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}:\
${libs.junit.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
main.class=
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
# or test-sys-prop.name=value to set system properties for unit tests):
run.jvmargs=
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
src.impl.dir=${file.reference.src-impl}
src.new.dir=${file.reference.src-new}
javahelp2-2.0.05/javahelp_nbproject/build.xml.orig 0000644 0001750 0001750 00000025760 10661201734 021154 0 ustar varun varun
Builds, tests, and runs the project JavaHelp.
Downloading JDIC. If you get an error like 'Server redirected too many times' download it manually from
https://jdic.dev.java.net/servlets/ProjectDocumentView?documentID=5715&showInfo=true
Then copy the zip file to ${jdic-zip} and re-build
To build the entire javahelp distribution, run the "release" ant target.
javahelp2-2.0.05/javahelp_nbproject/build.xml 0000644 0001750 0001750 00000026232 10661202260 020203 0 ustar varun varun
Builds, tests, and runs the project JavaHelp.
Downloading JDIC. If you get an error like 'Server redirected too many times' download it manually from
https://jdic.dev.java.net/servlets/ProjectDocumentView?documentID=5715&showInfo=true
Then copy the zip file to ${jdic-zip} and re-build
To build the entire javahelp distribution, run the "release" ant target.
javahelp2-2.0.05/jhMaster/ 0000755 0001750 0001750 00000000000 11220022253 014264 5 ustar varun varun javahelp2-2.0.05/jhMaster/GNUmakefile 0000644 0001750 0001750 00000003075 10661202060 016347 0 ustar varun varun #
# @(#)GNUmakefile 1.14 06/10/30
#
# Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun in the LICENSE file that accompanied this code.
#
# This code 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 General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
all:
java -fullversion
cd JSearch ; $(MAKE) all
cd JavaHelp/build ; $(MAKE) all
cd JavaHelp/demos ; $(MAKE) all validate
release: all docs
docs: all
cd JavaHelp/build ; $(MAKE) docs
cd JavaHelp/doc/jhug; $(MAKE) all
cd JavaHelp/doc/public-spec/V2.0; $(MAKE) all
clean:
cd JSearch ; $(MAKE) clean
cd JavaHelp/build ; $(MAKE) clean
cd JavaHelp/demos ; $(MAKE) clean
javahelp2-2.0.05/jhMaster/JSearch/ 0000755 0001750 0001750 00000000000 11220022253 015603 5 ustar varun varun javahelp2-2.0.05/jhMaster/JSearch/misc/ 0000755 0001750 0001750 00000000000 11220022253 016536 5 ustar varun varun javahelp2-2.0.05/jhMaster/JSearch/misc/GNUmakefile 0000644 0001750 0001750 00000004170 10661201770 020625 0 ustar varun varun #
# @(#)GNUmakefile 1.12 06/10/30
#
# Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun in the LICENSE file that accompanied this code.
#
# This code 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 General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
.SUFFIXES:
.SUFFIXES: .java .class
JHHOMEWS=../../JavaHelp
VPATH = $(JHHOMEWS)/src/impl:$(JHHOMEWS)/src/new
SEARCH_SRC=ConfigFile.java \
IndexBuilder.java \
IndexerKit.java \
SearchEngine.java \
SearchEvent.java \
SearchItem.java \
SearchListener.java \
SearchQuery.java
SEARCH_CLASSES=$(SEARCH_SRC:%.java=classes/javax/help/search/%.class)
OTHER_SRC=javax/help/event/EventListenerList.java \
javax/help/HelpUtilities.java
OTHER_CLASSES=$(OTHER_SRC:%.java=classes/%.class)
IMPL_SRC:=com/sun/java/help/impl/HeaderParser.java
IMPL_CLASSES=$(IMPL_SRC:%.java=classes/%.class)
ALL_CLASSES=$(SEARCH_CLASSES) $(IMPL_CLASSES) $(OTHER_CLASSES)
jar: ../lib/jsearch-misc.jar
../lib/jsearch-misc.jar: classes $(ALL_CLASSES)
cd classes ; \
jar cf ../../lib/jsearch-misc.jar javax com
classes/%.class: %.java
javac -d classes -classpath ../../JavaHelp/src/impl:../../JavaHelp/src/new $<
classes:
mkdir classes
clean:
$(RM) -rf classes
javahelp2-2.0.05/jhMaster/JSearch/client/ 0000755 0001750 0001750 00000000000 11220022253 017061 5 ustar varun varun javahelp2-2.0.05/jhMaster/JSearch/client/com/ 0000755 0001750 0001750 00000000000 11220022253 017637 5 ustar varun varun javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/ 0000755 0001750 0001750 00000000000 11220022253 020444 5 ustar varun varun javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/ 0000755 0001750 0001750 00000000000 11220022253 021365 5 ustar varun varun javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/ 0000755 0001750 0001750 00000000000 11220022253 022315 5 ustar varun varun javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/ 0000755 0001750 0001750 00000000000 11220022253 023562 5 ustar varun varun javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/Block.java 0000644 0001750 0001750 00000005474 10661201772 025506 0 ustar varun varun /*
* @(#)Block.java 1.10 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @(#) Block.java 1.3 - last change made 03/20/98
*/
package com.sun.java.help.search;
import java.io.IOException;
/**
* This class represents a Block of information in DictBlock
*
* @author Jacek Ambroziak
* @author Roger D. Brinkley
* @version 1.3 03/20/98
*/
class Block
{
public static final int HEADERLEN = 8;
public static final int IDLEN = 4;
public int number;
public boolean isLeaf = true;
public int free = 0;
public byte[] data = null;
public Block(int blocksize) {
data = new byte[blocksize - HEADERLEN];
}
public void setBlockNumber(int n) {
number = n;
}
public void setFree(int free) {
free = free;
}
public int integerAt(int i) {
return ((((((data[i++]&0xFF)<<8)
|data[i++]&0xFF)<<8)
|data[i++]&0xFF)<<8)
|data[i]&0xFF;
}
public void setIntegerAt(int i, int value)
{
for (int j = i + 3; j >= i; j--, value >>>= 8)
data[j] = (byte)(value & 0xFF);
}
public static Block readIn(RAFFile in, Block block)
throws IOException
{
debug("readIn");
block.number = in.readInt();
int twoFields = in.readInt();
block.isLeaf = (twoFields & 0x80000000) != 0;
block.free = twoFields & 0x7FFFFFFF;
in.readFully(block.data);
return block;
}
public void writeOut(RAFFile out) throws IOException
{
out.writeInt(number);
out.writeInt(free | (isLeaf ? 0x80000000 : 0));
out.write(data);
}
/**
* Debug code
*/
private static boolean debug=false;
private static void debug(String msg) {
if (debug) {
System.err.println("Block: "+msg);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/BtreeDict.java 0000644 0001750 0001750 00000021264 10661201772 026314 0 ustar varun varun /*
* @(#)BtreeDict.java 1.14 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @(#) BtreeDict.java 1.5 - last change made 03/18/98
*/
package com.sun.java.help.search;
import java.io.*;
/**
* @version 1.5 03/18/98
* @author Jacek R. Ambroziak
* @author Roger D. Brinkley
*/
public class BtreeDict
{
protected static final int ENTHEADERLEN = 6;
protected static final int BLOCKSIZE = 2048;
protected static final int DATALEN = BLOCKSIZE - Block.HEADERLEN;
protected static final int MaxKeyLength = 255;
//!!! Careful with that number, Eugene
protected static final int lastPtrIndex = 508;
protected class DictBlock extends Block
{
public DictBlock() {
super(BLOCKSIZE);
}
public int free() {
return free + firstEntry();
}
public int numberOfEntries() {
return integerAt(0);
}
public int nthPointer(int n) {
return integerAt(4*(n + 1));
}
public int getChildIdx(int index) {
return nthPointer(lastPtrIndex - index);
}
public int entryKeyLength(int i) {
return data[i] & 0xFF;
}
public int entryCompression(int i) {
return data[i + 1] & 0xFF;
}
public int entryID(int i) {
return integerAt(i + 2);
}
public int entryLength(int entry) {
return ENTHEADERLEN + entryKeyLength(entry);
}
public int entryKey(int entry) {
return entry + ENTHEADERLEN;
}
public int firstEntry() {
return 4;
}
public int nextEntry(int entry) {
return entry + entryLength(entry);
}
public void restoreKeyInBuffer(int entry, byte[] buffer)
{
int howMany = entryKeyLength(entry);
int where = entryCompression(entry);
int from = entryKey(entry);
while (howMany-- > 0)
buffer[where++] = data[from++];
}
public String restoreKey(int entry, byte[] buffer)
{
int howMany = entryKeyLength(entry);
int where = entryCompression(entry);
int from = entryKey(entry);
while (howMany-- > 0)
buffer[where++] = data[from++];
String string = null;
try {
string = new String(buffer, 0, where, "UTF8");
} catch (java.io.UnsupportedEncodingException e) {
// ignore
}
return string;
}
public String findID(int id) throws Exception
{
byte[] buffer = new byte[MaxKeyLength];
int freeSpace = free();
for (int ent = firstEntry(); ent < freeSpace; ent = nextEntry(ent))
if (entryID(ent) == id) // found
return restoreKey(ent, buffer);
else
restoreKeyInBuffer(ent, buffer);
throw new Exception("ID not found in block");
}
protected void setBlockNumbers(final int[] blocks)
{
for (int e = firstEntry(); e < free; e = nextEntry(e))
blocks[entryID(e)] = number;
}
/*
protected void doMap(BtreeDict owner, EntryProcessor processor)
throws Exception
{
byte[] buffer = new byte[MaxKeyLength];
final int freeSpace = free();
int entryPtr = firstEntry();
if (isLeaf)
while (entryPtr < freeSpace) {
processor.processEntry(restoreKey(entryPtr, buffer),
entryID(entryPtr));
entryPtr = nextEntry(entryPtr);
}
else
{
owner.lock(this);
int entryIdx = 0;
while (entryPtr < freeSpace) {
owner.accessBlock(getChildIdx(entryIdx)).doMap(owner,processor);
processor.processEntry(restoreKey(entryPtr, buffer),
entryID(entryPtr));
entryPtr = nextEntry(entryPtr);
++entryIdx;
}
owner.accessBlock(getChildIdx(entryIdx)).doMap(owner, processor);
owner.unlock(this);
}
}
*/
}
// end of internal class
protected BlockManager blockManager;
protected int root;
protected int[] blocks;
protected BtreeDict() {/*empty*/}
public BtreeDict(BtreeDictParameters params) throws Exception
{
init(params, false, new BlockFactory() {
public Block makeBlock() { return new DictBlock(); }
});
blocks = new int[params.getFreeID()];
setBlocks(blocks);
}
public int fetch(String key) throws Exception
{
// System.err.println("fetching " + key);
byte[] bytes = key.getBytes("UTF8");
byte[] Key = new byte[bytes.length + 1];
System.arraycopy(bytes, 0, Key, 0, bytes.length);
Key[bytes.length] = 0; // sentinel
return find(accessBlock(root), Key);
}
public String fetch(int conceptID) throws Exception {
return findID(blocks[conceptID], conceptID);
}
public void close() throws Exception {
blockManager.close();
}
protected void init(BtreeDictParameters params, boolean update,
BlockFactory bfactory) throws Exception
{
blockManager = new BlockManager(params, update, bfactory);
root = params.getRootPosition();
}
protected void lock(Block bl) {
blockManager.lockBlock(bl.number);
}
protected void unlock(Block bl) {
blockManager.unlockBlock(bl.number);
}
protected DictBlock accessBlock(int index) throws Exception {
return (DictBlock)blockManager.accessBlock(index);
}
protected DictBlock child(DictBlock bl, int index) throws Exception {
return accessBlock(bl.getChildIdx(index));
}
private String findID(int blNum, int id) throws Exception {
return accessBlock(blNum).findID(id);
}
private int find(DictBlock bl, byte[] key, int index) throws Exception {
return bl.isLeaf ? 0 : find(child(bl, index), key);
}
private int find(DictBlock bl, byte[] key) throws Exception
{
int inputKeyLen = key.length - 1;
int entryPtr = bl.firstEntry();
int freeSpace = bl.free();
int nCharsEqual = 0;
int compression = 0;
for (int entryIdx = 0;;)
{
if (entryPtr == freeSpace)
return find(bl, key, bl.numberOfEntries());
else if (compression == nCharsEqual)
{
int keyLen = bl.entryKeyLength(entryPtr);
int keyPtr = bl.entryKey(entryPtr), i;
for (i = 0;
i < keyLen && key[nCharsEqual] == bl.data[keyPtr + i];
i++)
++nCharsEqual;
if (i == keyLen)
{
if (nCharsEqual == inputKeyLen)
return bl.entryID(entryPtr);
}
else if ((key[nCharsEqual]&0xFF) < (bl.data[keyPtr + i]&0xFF))
return find(bl, key, entryIdx);
}
else if (compression < nCharsEqual) // compression dropped
return find(bl, key, entryPtr == freeSpace
? bl.numberOfEntries() : entryIdx);
do {
entryPtr = bl.nextEntry(entryPtr);
++entryIdx;
}
while (bl.entryCompression(entryPtr) > nCharsEqual);
compression = bl.entryCompression(entryPtr);
}
}
private void setBlocks(final int[] blocks) throws Exception
{
long start = System.currentTimeMillis();
blockManager.mapBlocks(new BlockProcessor() {
public void process(Block block) {
((DictBlock)block).setBlockNumbers(blocks);
}
});
debug((System.currentTimeMillis() - start) + " msec; TMAP");
}
/*
can go to Full
public void map(EntryProcessor processor) throws Exception {
accessBlock(root).doMap(this, processor);
}
*/
/**
* Debug code
*/
private boolean debug=false;
private void debug(String msg) {
if (debug) {
System.err.println("BtreeDict: "+msg);
}
}
public static void main(String[] args)
{
try {
Schema schema = new Schema(null, args[0], false);
BtreeDictParameters params = new BtreeDictParameters(schema, "TMAP");
BtreeDict source = new BtreeDict(params);
/*
source.map(new EntryProcessor() {
public void processEntry(String key, int id) {
System.out.println(key + " " + id);
}
});
*/
}
catch (Exception e) {
System.err.println(e);
e.printStackTrace();
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/LiteMorph.java 0000644 0001750 0001750 00000023353 10661201772 026353 0 ustar varun varun /*
* @(#)LiteMorph.java 1.7 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @(#) LiteMorph.java 1.7 - last change made 10/30/06
*/
package com.sun.java.help.search;
import java.io.*;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.Hashtable;
import java.util.Enumeration;
/**
* This class will generate an array of morphological variants of a word
* to use in search-and-retrieval applications where a user wants to find
* other words morphologically related to words in a query. For example,
* a request such as "electrical fixtures" should also retrieve "electric
* fixtures," "electrical fixture," etc. Given a word of a query, these
* rules generate alternative variations of that word that should also be
* considered. This generation of variant forms of a word fills a role
* similar to that often filled by the use of wild card characters or by
* stemming rules that produce truncated stems in traditional information
* retrieval systems. The approach of generating alternative variations
* has advantages over a truncated stemming approach for many applications,
* because it does not require stemming operations during the indexing
* process, does not require extra indexing space for stems, nor does it
* lose information by storing only stems. Rather, the variation rules
* are applied to the query to produce additional forms to check against
* the index.
*
* Compared to the use of wild card characters, this approach has two
* advantages: first, it does not require the user to think about where
* the wild cards should be placed, and secondly, it deals with irregular
* variations such as irregular verbs (e.g., "break," "broke," "broken"),
* and with stem ending effects such as silent e's and doubling of final
* consonants (e.g., "dig," "digs," "digging"). The rules presented here,
* together with a table of exceptions, provided at the end, deal with
* a wide range of such effects, without requiring any more attention on
* the part of the user than to turn on the facility.
*
* These rules generate regular morphological variants of words using the
* suffixes s, er, ers, est, ed, ing, ly, ful, less, ness, and ment. Rules
* are included for dealing with some words ending in -ize, -ise, -ic and
* -ical, and for some words requiring irregular forms, such as -leaf and
* -man compounds (flyleaf, footman), and Latin words ending in -um and -a,
* such as datum. The rules are supplemented by a list of exceptions for
* words that do not inflect regularly. They are not intended to apply to
* function words or to proper names. When expanding queries, you may not
* want to apply them to capitalized words or to hyphenated words like
* day-to-day and low-level.
*
* The rules treat almost all words as if they were multiply meaningful
* as nouns, verbs, and adjectives. Hence, the rules will often generate
* spurious forms that should never occur in a text -- e.g., fix ->
* fixest, happy -> happied. The rules are suitable for applications
* such as searching text using inverted files, where a quick test
* suffices to determine that a given candidate does not occur in the
* corpus. In such applications, it is preferable to overgenerate
* candidates than to miss possible retrievals.
*
* The program uses rules developed by W. A. Woods and Ellen Hays in 1992.
* An original C program for using them was developed by Jacek Ambroziak
* and was included in Sun's SearchIt product.
*
* @author Roger D. Brinkley
* @author W. A. Woods
* @author Jacek Ambroziak
* @version 1.7 10/30/06
*
* @see Rule
*/
public abstract class LiteMorph {
protected static Vector variants;
protected static Hashtable rulesTable;
protected static Hashtable blockedVariants;
protected static Hashtable exceptions;
public LiteMorph() {
initialize();
}
public static LiteMorph getMorph() {
return null;
}
/**
* Subclasses of this class (generally locale specific)
* need to set up exceptions and rules. At a minium
* implementations
* need to initialize the size of the exceptions HashTable
* and the establish the rules HashTable.
* Implementations have the option of filling exceptions
* directly in this method or calling intialize(String []).
* After initialization the exceptionTable shoudl be garbage
* collected
*/
protected abstract void initialize();
/**
* One time initialization of exceptions Hashtable using an
* array of Strings. Each String is a list of variation groups.
* The words in the groups are space delimited. Any matching
* word in the exceptions will cause all of the words in the
* group to be added to the variant list
*/
protected void initialize (String [] exceptionTable) {
// Firewall
if (exceptions == null || exceptionTable == null) {
return;
}
String tempWord, tempVal;
for (int i = 0; i < exceptionTable.length; i++) {
StringTokenizer tokens = new StringTokenizer(exceptionTable[i], " ");
while (tokens.hasMoreTokens()) {
tempWord = tokens.nextToken();
tempVal = (String)exceptions.get(tempWord);
if (tempVal == null) {
exceptions.put(tempWord, exceptionTable[i]);
} else {
//the same form can occur in several groups that must be appended
exceptions.put(tempWord, tempVal + " " + exceptionTable[i]);
}
}
}
}
/**
* Get the variants of given word. This is locale
* specific variants of a word as supplied by the locale
* implementation of this class
*
* @return String[] an array of words that are variations of word
*/
public synchronized String[] variantsOf(String word) {
// intialize variants and blockedVariants
variants = new Vector();
blockedVariants = new Hashtable ();
// this blocks adding the input word itself
blockedVariants.put(word, word);
// Go get the morphological variantes of the word.
morphWord(word, 0);
// don't need this anymore; release it for gc
blockedVariants = null;
String[] result = new String[variants.size()];
variants.copyInto(result);
//release this for garbage collection
variants = null;
return result;
}
/**
* Morph the word into other words if possible
*/
protected void morphWord(String word, int depth) {
debug(" analyzing: " +word+" at depth "+depth);
if (depth > 2)
return;
// if a word is found among exceptions, don't try rules
String exceptionList = (String)exceptions.get(word);
if (exceptionList == null) {
exceptionList = "";
}
if (exceptionList.length() > 0) {
StringTokenizer tokens = new StringTokenizer(exceptionList, " ");
while (tokens.hasMoreTokens())
addVariant(tokens.nextToken());
debug(" "+word+": found match in exceptions -- "+
exceptionList+", at depth "+depth);
return;
}
if (word.indexOf("-") >= 0)
return;
//don't apply rules to words with internal hyphens (but check exceptions)
Rule[] rules = null;
int skipnum = 0;
// See if the word ends with one of the keys in the rulesTable
Enumeration keys = rulesTable.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
if (word.endsWith(key) && !key.equals("default")) {
rules = (Rule[]) rulesTable.get(key);
skipnum = key.length();
break;
}
}
if (rules == null) {
// no match try to get the "default" rules.
rules = (Rule[]) rulesTable.get("default");
skipnum = 0;
}
for (int i = 0; i < rules.length; i++) {
debug(" "+word+": trying rule: " + rules[i]+
", at depth "+depth);
String [] results = rules[i].match(word, depth, skipnum);
if (results.length > 0) {
debug(" "+word+": found match for: "+rules[i]+
", at depth "+depth);
addVariant(word); //do this here -- i.e., only when a rule matches
for (int j=0; j < results.length; j++) {
addVariant(results[j]);
}
break;
}
}
}
/**
* Add the variant of the word to the list of words
*/
private void addVariant(String word) {
if (blockedVariants.get(word) == null) { // word is not blocked
variants.addElement(word);
blockedVariants.put(word, word); // block it from being added again
}
}
/**
* Convenience method for creating Rules
*/
protected static Rule r(String expression, String expansions, LiteMorph morph) {
return new Rule(expression, expansions, morph);
}
/**
* For printf debugging.
*/
private static final boolean debugFlag = false;
private static void debug(String str) {
if( debugFlag ) {
System.out.println("LiteMorph: " + str);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/MemoryRAFFile.java 0000644 0001750 0001750 00000010234 10661201772 027043 0 ustar varun varun /*
* @(#)MemoryRAFFile.java 1.12 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @(#) MemoryRAFFile.java 1.12 - last change made 10/30/06
*/
package com.sun.java.help.search;
/**
* A DICT (Dictionary) file cached in memory.
*
* @author Roger D. Brinkley
* @version 1.12 10/30/06
*/
import java.net.URL;
import java.net.URLConnection;
import java.io.IOException;
import java.io.InputStream;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.EOFException;
public class MemoryRAFFile extends RAFFile {
private URL url;
private byte[] data;
private int size;
private int filePointer;
public MemoryRAFFile(URLConnection connection) throws IOException {
this.url = connection.getURL();
InputStream in = new BufferedInputStream(connection.getInputStream());
ByteArrayOutputStream data = new ByteArrayOutputStream();
byte[] buf = new byte[512];
int i = 0;
while((i = in.read(buf)) != -1) {
data.write(buf, 0, i);
}
this.data = data.toByteArray();
size = data.size();
filePointer = 0;
}
public long length() {
return size;
}
public void close() throws IOException {
filePointer = 0;
data = null;
size = 0;
}
public long getFilePointer() throws IOException {
return filePointer;
}
public void seek(long pos) throws IOException {
if (pos > size) {
throw new IOException();
}
filePointer = (int)pos;
}
public int read() throws IOException {
if (filePointer >= size) {
return -1;
}
filePointer += 1;
return data[filePointer - 1] & 0xFF;
}
private int readBytes(byte b[], int off, int len) throws IOException {
debug ("readBytes");
if (filePointer + off + len > size) {
throw new IOException();
}
filePointer += off;
System.arraycopy(data, filePointer, b, 0, (int)len);
filePointer += len;
return len;
}
public int read(byte b[], int off, int len) throws IOException {
return readBytes(b, off, len);
}
public int readInt() throws IOException {
debug ("readInt");
int ch1 = this.read();
int ch2 = this.read();
int ch3 = this.read();
int ch4 = this.read();
if ((ch1 | ch2 | ch3 | ch4) < 0)
throw new EOFException();
return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
}
public final void readFully(byte b[]) throws IOException {
readFully(b, 0, b.length);
}
private void readFully (byte b[], int off, int len)
throws IOException {
int n = 0;
do {
int count = this.read(b, off + n, len - n);
if (count < 0)
throw new EOFException();
n += count;
} while (n < len);
}
public void writeInt(int v) throws IOException {
throw new IOException("Unsupported Operation");
}
public void write(byte b[]) throws IOException {
throw new IOException("Unsupported Operation");
}
/**
* For printf debugging.
*/
private static boolean debugFlag = false;
private static void debug(String str) {
if( debugFlag ) {
System.out.println("MemoryRAFFile: " + str);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/LiteMorph_en.java 0000644 0001750 0001750 00000157025 10661201772 027041 0 ustar varun varun /*
* @(#)LiteMorph_en.java 1.6 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @(#) LiteMorph_en.java 1.6 - last change made 10/30/06
*/
package com.sun.java.help.search;
import java.io.*;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.Hashtable;
/**
* This is the English version of LiteMorph
*
* @see LiteMorph
*/
public class LiteMorph_en extends LiteMorph{
private static LiteMorph morph = new LiteMorph_en();
/**
* Make this a singleton class
*/
private LiteMorph_en() {
}
/**
* Return the LiteMorph for this class
*/
public synchronized static LiteMorph getMorph() {
return morph;
}
/**
* This is a locale specific intialization.
* Create the exceptions HashTable for the size needed.
* the call intialize(String []).
*/
protected synchronized void initialize() {
if (exceptions != null) {
return;
}
exceptions = new Hashtable(2800, (float)0.7);
// The exceptions:
// current statistics: approx 700 variation groups
// approx 2800 words)
String[] exceptionTable = {
"a",
//opt//"aardwolf aardwolves",
"abandoner abandon abandons abandoned abandoning abandonings abandoners",
"abdomen abdomens",
"about",
"above",
//opt//"abscissa abscissas abscissae",
"acid acids acidic acidity acidities",
"across",
"act acts acted acting actor actors",
//opt//"acumen",
"ad ads",
"add adds added adding addings addition additions adder adders",
//opt//"addendum addenda addendums",
//opt//"adieu adieux adieus",
"advertise advertises advertised advertising advertiser advertisers "
+"advertisement advertisements advertisings",
"after",
"again",
"against",
"ago",
//opt//"agoutis agouti",
//opt//"alias aliases",
"all",
"almost",
"along",
"already",
"also",
"although",
"alumna alumnae alumnus alumni",
//opt//"alveolus alveoli alveolar",
"always",
"amen amens",
"amidships",
"amid amidst",
"among amongst",
//opt//"ampulla ampullae",
//opt//"amygdala amygdalae",
"an",
"analysis analyses",
"and",
//opt//"annulus annuluses annuli annular",
"another other others",
"antenna antennas antennae",
"antitheses antithesis",
"any",
"anyone anybody",
"anything",
"appendix appendixes appendices",
"apropos",
"aquarium aquariums aquaria",
"argument arguments argue argues argued arguing arguings arguer arguers",
"arise arises arose arisen ariser arisers arising arisings",
"around",
"as",
"asbestos",
"at",
"atlas atlases",
//opt//"atrium atriums atria",
"auger augers augered augering augerings augerer augerers",
"augment augments augmented augmenting augmentings augmentation "
+"augmentations augmenter augmenters",
"automata automaton automatons",
"automation automating automate automates automated automatic",
"avoirdupois",
"awake awakes awoke awaked awoken awaker awakers awaking awakings "
+"awakening awakenings",
"away",
"awful awfully awfulness",
"axis axes axises",
"bacillus bacilli",
"bacterium bacteria",
"bad worse worst badly badness",
//opt//"balladier balladiers",
//opt//"bandolier bandoliers",
"bas",
"bases basis",
"bases base based basing basings basely baseness basenesses basement "
+"basements baseless basic basics",
//opt//"bateau bateaux",
//opt//"bathos",
//opt//"bayou bayous",
"be am are is was were been being",
"bear bears bore borne bearing bearings bearer bearers",
"beat beats beaten beating beatings beater beaters",
//opt//"beau beaux beaus",
"because",
"become becomes became becoming",
//opt//"bedesman bedesmans",
"beef beefs beeves beefed beefing",
"beer beers",
"before",
//opt//"beget begets begat begot begotten begetting begettings begetter begetters",
"begin begins began begun beginning beginnings beginner beginners",
"behalf behalves",
"being beings",
"bend bends bent bending bendings bender benders",
"bereave bereaves bereaved bereft bereaving bereavings bereavement "
+"bereavements",
"beside besides",
"best bests bested besting",
"bet bets betting bettor bettors",
"betimes",
"between",
"beyond",
"bid bids bade bidden bidding biddings bidder bidders",
"bier biers",
"bind binds bound binding bindings binder binders",
"bit bits",
"bite bites bit bitten biting bitings biter biters",
"blackfoot blackfeet",
"bleed bleeds bled bleeding bleedings bleeder bleeders",
"blow blows blew blown blowing blowings blower blowers",
"bookshelf bookshelves",
//opt//"borzois borzoi",
"both",
"bound bounds bounded bounding boundings bounder bounders boundless",
"bourgeois bourgeoisie",
"bra bras",
"brahman brahmans",
"break breaks broke broken breaking breakings breaker breakers",
"breed breeds bred breeding breedings breeder breeders",
"bring brings brought bringing bringings bringer bringers",
//opt//"bronchus bronchi bronchial bronchially",
"build builds built building buildings builder builders",
//opt//"bum bums bummed bumming bummings bummer bummers",
//opt//"bursa bursae bursas bursal",
"bus buses bused bussed busing bussing busings bussings buser busers "
+"busser bussers",
"buss busses bussed bussing bussings busser bussers",
"but",
"buy buys bought buying buyings buyer buyers",
"by",
//opt//"caiman caimans cayman caymans",
//opt//"calculus calculi",
"calf calves calved calving calvings calver calvers",
"can cans canned canning cannings canner canners",
"can could cannot",
//opt//"candelabrum candelabra candelabrums",
"canoes canoe canoed canoeing canoeings canoer canoers",
//opt//"caribou caribous",
"catch catches caught catching catchings catcher catchers",
//opt//"catharsis catharses",
"cement cements cemented cementing cementings cementer cementers",
"cent cents",
"center centers centered centering centerings centerless",
//opt//"chablis",
//opt//"chamois",
//opt//"chapattis chapatti",
//opt//"chateau chateaus chateaux",
//opt//"cherub cherubs cherubim",
"child children childless childish childishly",
"choose chooses chose chosen choosing choosings chooser choosers",
//opt//"cicatrix cicatrices cicatricial cicatricose cicatrize cicatrizes "
//opt//+"cicatrized cicatrizing cicatrizings cicatrization cicatrixes",
//opt//"clement",
//opt//"cliches cliche",
"cling clings clung clinging clingings clinger clingers",
//opt//"codex codices",
//opt//"cognomen",
"colloquium colloquia colloquiums",
//opt//"colossus colossi colossuses",
"come comes came coming comings comer comers",
"comment comments commented commenting commentings commenter commenters",
"compendium compendia compendiums",
"complement complements complemented complementing complementings "
+"complementer complementers complementary",
"compliment compliments complimented complimenting complimentings "
+"complimenter complimenters complimentary",
"concerto concertos concerti",
"condiment condiments",
//opt//"continuum continua continuums",
"corps",
//opt//"corrigendum corrigenda",
"cortex cortices cortexes cortical",
"couscous",
"creep creeps crept creeping creepings creeper creepers creepy",
"crisis crises",
"criterion criteria criterial",
"cryptanalysis cryptanalyses",
"curriculum curricula curriculums curricular",
//opt//"cyclamen cyclamens",
//opt//"czech czechs czechoslovakia czechoslovak czechoslovaks czechoslovakian "
//opt//+"czechoslovakians Czech Czechs Czechoslovakia Czechoslovak Czechoslovaks "
//opt//+"Czechoslovakian Czechoslovakians",
//opt//"dais daises",
"datum data",
"day days daily",
"deal deals dealt dealing dealings dealer dealers",
"decrement decrements decremented decrementing decrementings "
+"decrementer decrementers decremental",
"deer deers",
//opt//"deixis deixes",
"demented dementia",
"desideratum desiderata",
//opt//"desman desmans",
"diagnosis diagnoses diagnose diagnosed diagnosing diagnostic",
"dialysis dialyses",
"dice dices diced dicing dicings dicer dicers",
"die dice",
"die dies died dying dyings",
"dig digs dug digging diggings digger diggers",
"dive dives diver divers dove dived diving divings",
"divest divests divester divesters divested divesting divestings "
+"divestment divestments",
"do does did done doing doings doer doers",
"document documents documented documenting documentings documenter "
+"documenters documentation documentations documentary",
//opt//"dodecahedron dodecahedra dodecahedrons",
"doe does",
//opt//"dormouse dormice",
"dove doves",
"downstairs",
"dozen",
"draw draws drew drawn drawing drawings drawer drawers",
"drink drinks drank drunk drinking drinkings drinker drinkers",
"drive drives drove driven driving drivings driver drivers driverless",
"due dues duly",
"during",
"e",
"each",
"eager eagerer eagerest eagerly eagerness eagernesses",
"early earlier earliest",
"easement easements",
"eat eats ate eaten eating eatings eater eaters",
"effluvium effluvia",
"either",
"element elements elementary",
"elf elves elfen",
"ellipse ellipses elliptic elliptical elliptically",
"ellipsis ellipses elliptic elliptical elliptically",
"else",
"embolus emboli embolic embolism",
"emolument emoluments",
"emphasis emphases",
"employ employs employed employing employer employers employee "
+"employees employment employments employable",
"enough",
"equilibrium equilibria equilibriums",
"erratum errata",
"ever",
"every",
"everything",
//opt//"exegeses exegesis",
"exotic exotically exoticness exotica",
"experiment experiments experimented experimenting experimentings "
+"experimenter experimenters experimentation experimental",
"extra extras",
//opt//"extremum extrema extremums extreme extremely extremeness extremist extremism",
"fall falls fell fallen falling fallings faller fallers",
"far farther farthest",
"fee fees feeless",
"feed feeds fed feeding feedings feeder feeders",
"feel feels felt feeling feelings feeler feelers",
"ferment ferments fermented fermenting fermentings fermentation "
+"fermentations fermenter fermenters",
"few fewer fewest",
//opt//"fez fezzes fezes",
"fight fights fought fighting fightings fighter fighters",
"figment figments",
"filament filaments",
"find finds found finding findings finder finders",
"firmament firmaments",
"flee flees fled fleeing fleeings",
"fling flings flung flinging flingings flinger flingers",
"floe floes",
"fly flies flew flown flying flyings flier fliers flyer flyers",
"focus foci focuses focused focusing focusses focussed focussing focuser focal",
"foment foments fomented fomenting fomentings fomenter fomenters",
"foot feet",
"foot foots footed footing footer footers",
"footing footings footer footers",
"for",
"forbid forbids forbade forbidden forbidding forbiddings forbidder forbidders",
"foresee foresaw foreseen foreseeing foreseeings foreseer foreseers",
"forest forests forester foresting forestation forestations",
"forget forgets forgot forgotten forgetting forgettings forgetter "
+"forgetters forgetful",
"forsake forsakes forsook forsaken forsaking forsakings forsaker forsakers",
"found founds founded founding foundings founder founders",
"fragment fragments fragmented fragmenting fragmentings fragmentation "
+"fragmentations fragmenter fragmenters",
"free frees freer freest freed freeing freely freeness freenesses",
"freeze freezes froze frozen freezing freezings freezer freezers",
"from",
"full fully fuller fullest",
"fuller fullers full fulls fulled fulling fullings",
"fungus fungi funguses fungal",
"gallows",
"ganglion ganglia ganglions ganglionic",
"garment garments",
"gas gasses gassed gassing gassings gasser gassers",
"gas gases gasses gaseous gasless",
"gel gels gelled gelling gellings geller gellers",
//opt//"geneses genesis",
"german germans germanic germany German Germans Germanic Germany",
"get gets got gotten getting gettings getter getters",
"give gives gave given giving givings giver givers",
"gladiolus gladioli gladioluses gladiola gladiolas gladiolae",
"glans glandes",
//opt//"glissando glissandi glissandos",
"gluiness gluey glue glues glued gluing gluings gluer gluers",
//opt//"glum glummer glummest",
"go goes went gone going goings goer goers",
"godchild godchildren",
"good better best goodly goodness goodnesses",
"goods",
"goose geese",
"goose gooses goosed goosing goosings gooser goosers",
"grandchild grandchildren",
"grind grinds ground grinding grindings grinder grinders",
"ground grounds grounded grounding groundings grounder grounders groundless",
"grow grows grew grown growing growings grower growers growth",
"gum gums gummed gumming gummings gummer gummers",
"half halves",
"halve halves halved halving halvings halver halvers",
"hang hangs hung hanged hanging hangings hanger hangers",
//opt//"hanuman hanumans",
"have has had having havings haver havers",
"he him his himself",
"hear hears heard hearing hearings hearer hearers",
"here",
//opt//"herr herren Herr Herren",
//opt//"hiatus hiatuses",
"hide hides hid hidden hiding hidings hider hiders",
//opt//"hie hies hied hieing hying hieings hyings hier hiers",
"hippopotamus hippopotami hippopotamuses",
"hold holds held holding holdings holder holders",
"honorarium honoraria honorariums",
"hoof hoofs hooves hoofed hoofing hoofer hoofers",
"how",
"hum hums hummed humming hummings hummer hummers",
"hymen hymens hymenal",
"hypotheses hypothesis hypothesize hypothesizes hypothesized hypothesizer "
+"hypothesizing hypothetical hypothetically",
"i",
//opt//"icosahedron icosahedra icosahedrons",
"if iffy",
"impediment impediments",
"implement implements implemented implementing implementings implementation "
+"implementations implementer implementers",
"imply implies implied implying implyings implier impliers",
"in inner",
"inclement",
"increment increments incremented incrementing incrementings incrementer "
+"incrementers incremental incrementally",
"index indexes indexed indexing indexings indexer indexers",
"index indexes indices indexical indexicals",
"indoor indoors",
"instrument instruments instrumented instrumenting instrumentings "
+"instrumenter instrumenters instrumentation instrumentations instrumental",
"integument integumentary",
"into",
"it its itself",
"july julys",
"keep keeps kept keeping keepings keeper keepers",
"knife knifes knifed knifing knifings knifer knifers",
"knife knives",
"know knows knew known knowing knowings knower knowers knowledge",
"lament laments lamented lamenting lamentings lamentation lamentations "
+"lamenter lamenters lamentable lamentably",
"larva larvae larvas larval",
"late later latest lately lateness",
"latter latterly",
"lay lays laid laying layer layers",
"layer layers layered layering layerings",
"lead leads led leading leadings leader leaders leaderless",
"leaf leafs leafed leafing leafings leafer leafers",
"leaf leaves leafless",
"leave leaves left leaving leavings leaver leavers",
//opt//"legume legumes",
"lend lends lent lending lendings lender lenders",
"less lesser least",
"let lets letting lettings",
//opt//"libretto librettos libretti",
"lie lies lay lain lying lier liers",
"lie lies lied lying liar liars",
"life lives lifeless",
"light lights lit lighted lighting lightings lightly lighter lighters "
+"lightness lightnesses lightless",
"likely likelier likeliest",
"limen limens",
"lineament lineaments",
"liniment liniments",
"live alive living",
"live lives lived living livings",
"liver livers",
//opt//"llamela llamelae",
"loaf loafs loafed loafing loafings loafer loafers",
"loaf loaves",
//opt//"locus loci",
"logic logics logical logically",
"lose loses lost losing loser losers loss losses",
"louse lice",
"lumen lumens",
"make makes made making makings maker makers",
"man mans manned manning mannings",
"man men",
"manly manlier manliest manliness manful manfulness manhood",
"manic manically",
"manner manners mannered mannerly mannerless mannerful",
//opt//"mantra mantras",
"many",
"matrix matrices matrixes",
"may might",
"maximum maxima maximums maximal maximize maximizes maximized maximizing",
"mean means meant meaning meanings meaningless meaningful",
"mean meaner meanest meanly meanness meannesses",
"median medians medianly medial",
"medium media mediums",
"meet meets met meeting meetings",
"memorandum memoranda memorandums",
"mere merely",
"metal metals metallic",
"might mighty mightily",
//opt//"milieu milieus milieux",
"millenium millennia milleniums millennial",
"mine mines mined mining minings miner miners",
"mine my our ours",
"minimum minima minimums minimal",
"minus minuses",
"miscellaneous miscellanea miscellaneously miscellaneousness miscellany",
//opt//"modulus moduli",
"molest molests molested molesting molestings molester molesters",
"moment moments",
"monument monuments monumental",
//opt//"mooncalf mooncalves",
"more most",
"mouse mice mouseless",
"much",
"multiply multiplies multiplier multipliers multiple multiples "
+"multiplying multiplyings multiplication multiplications",
"mum mums mummed mumming mummings mummer mummers",
"must musts",
"neither",
"nemeses nemesis",
"neurosis neuroses neurotic neurotics",
"nomen",
"none",
"nos no noes",
"not",
"nothing nothings nothingness",
"now",
"nowadays",
"nucleus nuclei nucleuses nuclear",
//opt//"nucleolus nucleoli nucleolar",
"number numbers numbered numbering numberings numberless",
"nutriment nutriments nutrient nutrients nutrition nutritions",
"oasis oases",
//opt//"octahedron octahedra octahedrons",
"octopus octopi octopuses",
"of",
"off",
"offer offers offered offering offerings offerer offerers offeror offerors",
"often",
"oftentimes",
"ointment ointments",
"omen omens",
"on",
"once",
"only",
//opt//"operetta operettas operetti",
"ornament ornaments ornamented ornamenting ornamentings ornamentation "
+"ornamenter ornamenters ornamental",
"outdoor outdoors",
"outlay outlays",
"outlie outlies outlay outlied outlain outlying outlier outliers",
"ovum ova",
"ox oxen",
//opt//"palazzo palazzi palazzos",
"parentheses parenthesis",
"parliament parliaments parliamentary",
"passerby passer-by passersby passers-by",
"past pasts",
//opt//"patois",
"pay pays paid paying payings payer payers payee payees payment payments",
//opt//"pediment pediments",
"per",
"perhaps",
"person persons people",
//opt//"phallus phalli phalluses phallic",
//opt//"phylum phyla phylums",
"phenomenon phenomena phenomenal",
//opt//"phosphorus",
"pi",
"picnic picnics picnicker picnickers picnicked picnicking picnickings",
"pigment pigments pigmented pigmenting pigmentings pigmenter pigmenters "
+"pigmentation pigmentations",
"please pleases pleased pleasing pleasings pleaser pleasers pleasure "
+"pleasures pleasuring pleasurings pleasant pleasantly pleasureless "
+"pleasureful",
"plus pluses plusses",
"polyhedra polyhedron polyhedral",
"priest priests priestly priestlier priestliest priestliness priestless",
"prognosis prognoses",
"prostheses prosthesis",
"prove proves proved proving provings proofs proof prover provers provable",
"psychosis psychoses psychotic psychotics",
//opt//"pupa pupae pupas pupal",
"qed",
"quiz quizzes quizzed quizzing quizzings quizzer quizzers",
"raiment",
"rather",
"re",
"real really",
"redo redoes redid redone redoing redoings redoer redoers",
"regiment regiments regimented regimenting regimenter regimenters "
+"regimentation regimental",
"rendezvous",
"requiz requizzes requizzed requizzing requizzings requizzer requizzers",
"ride rides rode ridden riding ridings rider riders rideless",
"ring rings rang rung ringing ringings ringer ringers ringless",
"rise rises rose risen rising risings riser risers",
//opt//"roof roofs roofed roofing roofings roofer roofers roofless",
"rose roses",
"rudiment rudiments rudimentary",
"rum rums rummed rumming rummings rummer rummers",
"run runs ran running runnings runner runners",
"sacrament sacraments sacramental",
"same sameness",
"sans",
"saw saws sawed sawn sawing sawings sawyer sawyers",
"say says said saying sayings sayer sayers",
"scarf scarfs scarves scarfless",
"schema schemata schemas",
//opt//"scherzo scherzi scherzos",
//opt//"scrotum scrota scrotums",
"sediment sediments sedimentary sedimentation sedimentations",
"see sees saw seen seeing seeings seer seers",
"seek seeks sought seeking seekings seeker seekers",
"segment segments segmented segmenting segmentings segmenter segmenters "
+"segmentation segmentations",
"self selves selfless",
"sell sells sold selling sellings seller sellers",
"semen",
"send sends sent sending sendings sender senders",
"sentiment sentiments sentimental",
//opt//"seraph seraphs seraphim",
"series",
"set sets setting settings",
"several severally",
"sew sews sewed sewn sewing sewings sewer sewers",
"sewer sewers sewerless",
"shake shakes shook shaken shaking shakings shaker shakers",
"shall should",
"shaman shamans",
"shave shaves shaved shaven shaving shavings shaver shavers shaveless",
"she her hers herself",
"sheaf sheaves sheafless",
"sheep",
"shelf shelves shelved shelfing shelvings shelver shelvers shelfless",
"shine shines shined shone shining shinings shiner shiners shineless",
"shoe shoes shoed shod shoeing shoeings shoer shoers shoeless",
"shoot shoots shot shooting shootings shooter shooters",
"shot shots",
"show shows showed shown showing showings shower showers",
"shower showers showery showerless",
"shrink shrinks shrank shrunk shrinking shrinkings shrinker shrinkers "
+"shrinkable",
"sideways",
//opt//"simplex simplexes simplices",
"simply simple simpler simplest",
"since",
"sing sings sang sung singing singings singer singers singable",
"sink sinks sank sunk sinking sinkings sinker sinkers sinkable",
"sit sits sat sitting sittings sitter sitters",
"ski skis skied skiing skiings skier skiers skiless skiable",
"sky skies",
"slay slays slew slain slaying slayings slayer slayers",
"sleep sleeps slept sleeping sleepings sleeper sleepers sleepless",
"so",
"some",
"something",
"sometime sometimes",
"soon",
"spa spas",
"speak speaks spoke spoken speaking speakings speaker speakers",
"species specie",
"spectrum spectra spectrums",
"speed speeds sped speeded speeding speedings speeder speeders",
"spend spends spent spending spendings spender spenders spendable",
"spin spins spun spinning spinnings spinner spinners",
"spoke spokes",
"spring springs sprang sprung springing springings springer springers "
+"springy springiness",
"staff staffs staves staffed staffing staffings staffer staffers",
"stand stands stood standing standings",
"stasis stases",
"steal steals stole stolen stealing stealings stealer stealers",
"stick sticks stuck sticking stickings sticker stickers",
"stigma stigmata stigmas stigmatize stigmatizes stigmatized stigmatizing",
"stimulus stimuli",
"sting stings stung stinging stingings stinger stingers",
"stink stinks stank stunk stinking stinkings stinker stinkers",
"stomach stomachs",
"stratum strata stratums",
"stride strides strode stridden striding stridings strider striders",
"string strings strung stringing stringings stringer stringers stringless",
"strive strives strove striven striving strivings striver strivers",
"strum strums strummed strumming strummings strummer strummers strummable",
//opt//"stylus styli styluses",
//opt//"succubus succubi",
"such",
"suffer suffers suffered suffering sufferings sufferer sufferers sufferable",
"suggest suggests suggested suggesting suggestings suggester suggesters "
+"suggestor suggestors suggestive suggestion suggestions suggestible "
+"suggestable",
"sum sums summed summing summings summer summers",
"summer summers summered summering summerings",
"supplement supplements supplemented supplementing supplementings "
+"supplementation supplementer supplementers supplementary supplemental",
"supply supplies supplied supplying supplyings supplier suppliers",
"swear swears swore sworn swearing swearings swearer swearers",
"sweep sweeps swept sweeping sweepings sweeper sweepers",
"swell swells swelled swollen swelling swellings",
"swim swims swam swum swimming swimmings swimmer swimmers swimable",
"swine",
"swing swings swung swinging swingings swinger swingers",
"syllabus syllabi syllabuses",
"symposium symposia symposiums",
"synapse synapses",
"synapsis synapses",
"synopsis synopses",
"synthesis syntheses",
"tableau tableaux tableaus",
"take takes took taken taking takings taker takers takable",
"teach teaches taught teaching teachings teacher teachers teachable",
"tear tears tore torn tearing tearings tearer tearers tearable",
"tegument teguments",
"tell tells told telling tellings teller tellers tellable",
"temperament temperaments temperamental temperamentally",
"tenement tenements",
//opt//"terminus termini",
//opt//"than thans",
//opt//"that thats",
"the",
"there theres",
"theses thesis",
"they them their theirs themselves",
"thief thieves thieving thievings",
"think thinks thought thinking thinker thinkers thinkable",
"this that these those",
"thought thoughts thougtful thoughtless",
"throw throws threw thrown throwing throwings thrower throwers throwable",
//opt//"thus thuses",
"tic tics",
"tie ties tied tying tyings tier tiers tieable tieless",
"tier tiers tiered tiering tierings tierer tierers",
"to",
"toe toes toed toeing toeings toer toers toeless",
"together togetherness",
"too",
"tooth teeth toothless",
"topaz topazes",
"torment torments tormented tormenting tormentings tormenter tormenters "
+"tormentable",
"toward towards",
"tread treads trod trodden treading treadings treader treaders",
"tread treads treadless retread retreads",
"true truly trueness",
"two twos",
"u",
"under",
"underlay underlays underlaid underlaying underlayings underlayer "
+"underlayers",
"underlie underlies underlay underlain underlying underlier underliers",
"undo undoes undid undone undoing undoings undoer undoers undoable",
"unrest unrestful",
"until",
"unto",
"up",
"upon",
"upstairs",
"use uses user users used using useful useless",
"various variously",
"vehement vehemently vehemence",
"versus",
"very",
"visit visits visited visiting visitings visitor visitors",
"vortex vortexes vortices",
"wake wakes woke waked woken waking wakings waker wakers wakeful "
+"wakefulness wakefulnesses wakeable",
"wear wears wore worn wearing wearings wearer wearers wearable",
"weather weathers weathered weathering weatherly",
"weave weaves wove woven weaving weavings weaver weavers weaveable",
"weep weeps wept weeping weepings weeper weepers",
"wharf wharfs wharves",
//opt//"what whats",
//opt//"when whens",
"where wheres",
"whereas whereases",
"whether whethers",
//opt//"which whiches",
"while whiles whilst whiled whiling",
"whiz whizzes whizzed whizzing whizzings whizzer whizzers",
"who whom whos whose whoses",
"why whys",
"wife wives wifeless",
"will wills willed willing willings willful",
"will would",
"win wins won winning winnings winner winners winnable",
"wind winds wound winding windings winder winders windable",
"wind winds windy windless",
"with",
"within",
"without",
"wolf wolves",
"woman women womanless womanly",
"wound wounds wounded wounding woundings",
"write writes wrote written writing writings writer writers writeable",
"yeses yes",
"yet yets",
"you your yours yourself"};
initialize(exceptionTable);
// The rules:
// For words ending in -s (s-rules):
Rule[] sRules = {
r(".aeiouy bcdfghjklmnpqrstvwxyz + i n e s s",
"y,ies,ier,iers,iest,ied,ying,yings,ily,inesses,iment,iments,iless,iful",
this),
// (e.g., happiness, business)
r(".aeiouy + e l e s s",
"e,es,er,ers,est,ed,ing,ings,eing,eings,ely,eness,enesses,ement,ements,"
+"eness,enesses,eful",
this),
// (e.g., baseless, shoeless)
r("bcdfghjklmnpqrstvwxyz aeiouy bdgklmnprt + l e s s",
"_,s,&er,&ers,&est,&ed,&ing,&ings,ly,ness,nesses,ment,ments,ful",
this),
// (e.g., gutless, hatless, spotless)
r(".aeiouy + l e s s",
"_,s,er,ers,est,ed,ing,ings,ly,ness,nesses,ment,ments,ful",
this),
// (e.g., thoughtless, worthless)
r(".aeiouy + e n e s s",
"e,es,er,ers,est,ed,ing,ings,eing,eings,ely,enesses,ement,ements,"
+"eless,eful",
this),
// (e.g., baseness, toeness)
r(".aeiouy + n e s s",
"_,s,er,ers,est,ed,ing,ings,ly,nesses,ment,ments,less,ful",
this),
// (e.g., bluntness, grayness)
r(".aeiouy s s +",
"es,er,ers,est,ed,ing,ings,ly,ness,nesses,ment,ments,less,ful",
this),
// (e.g., albatross, kiss)
r(".aeiouy o u s +",
"ly,ness",
this),
// (e.g., joyous, fractious, gaseous)
r("+ i e s",
"y,ie,yer,yers,ier,iers,iest,ied,ying,yings,yness,iness,ieness,ynesses,"
+"inesses,ienesses,iment,iement,iments,iements,yless,iless,ieless,yful,"
+"iful,ieful",
this),
// (e.g., tries, unties, jollies, beauties)
r(".aeiouy + s i s",
"ses,sises,sisness,sisment,sisments,sisless,sisful",
this),
// (e.g., crisis, kinesis)
r(".aeiouy i s +",
"es,ness,ment,ments,less,ful",
this),
// (e.g., bronchitis, bursitis)
r(".aeiouy c h + e s",
"_,e,er,ers,est,ed,ing,ings,ly,ely,ness,eness,nesses,enesses,ment,"
+"ement,ments,ements,less,eless,ful,eful",
this),
r(".aeiouy s h + e s",
"_,e,er,ers,est,ed,ing,ings,ly,ely,ness,eness,nesses,enesses,ment,"
+"ement,ments,ements,less,eless,ful,eful",
this),
r(".aeiouy bcdfghjklmnpqrstvwxz + i z e s",
"ize,izer,izers,ized,izing,izings,ization,izations,"
+"ise,ises,iser,isers,ised,ising,isings,isation,isations",
this),
// (e.g., tokenizes) // adds British variations
r(".aeiouy bcdfghjklmnpqrstvwxz + i s e s",
"ize,izes,izer,izers,ized,izing,izings,ization,izations,"
+"ise,iser,isers,ised,ising,isings,isation,isations",
this),
// (e.g., tokenises) // British variant // ~expertise
r(".aeiouy jsxz + e s",
"_,e,er,ers,est,ed,ing,ings,ly,ely,ness,eness,nesses,enesses,ment,"
+"ement,ments,ements,less,eless,ful,eful",
this),
// (e.g., aches, arches)
// v is not in this set because ve words can keep the e before ing
// NB: we are not handling -is plurals like crises
r(".aeiouy d g + e s",
"e,er,ers,est,ed,ing,ings,ely,eness,enesses,ment,ments,ement,ements,"
+"eless,eful",
this),
// (e.g., judges, abridges)
r("e + s",
"*_",
this),
// (e.g., trees, races, likes, agrees)
// covers all other -es words
r("s e g m e n t + s",
"*_",
this),
// (e.g., segments, bisegments, cosegments)
r("p i g m e n t + s",
"*_",
this),
// (e.g., pigments, depigments, repigments)
r(".aeiouy d g + m e n t s",
"ment,*ment",
this),
// (e.g., judgments, abridgments)
r(".aeiouy bcdfghjklmnpqrstvwxyz i m e n t + s",
"*_",
this),
// (e.g., merriments, embodiments)
// -iment in turn will generate y and *y (redo y)
r(".aeiouy m e n t + s",
"*_",
this),
// (e.g., atonements, entrapments)
r(".aeiouy e r + s",
"*_",
this),
// (e.g., viewers, meters, traders, transfers)
r(".aeiouy bcdfghjklmnpqrstvwxyz aeiouy bdglmnprt + s",
"*_",
this),
// (e.g., unflags)
// polysyllables
r("bcdfghjklmnpqrstvwxyz aeiouy bdglmnprt + s",
"*_",
this),
// (e.g., frogs)
// monosyllables
r(".aeiouy i n g + s",
"*_",
this),
// (e.g., killings, muggings)
r(".aeiouy l l + s",
"*_",
this),
// (e.g., hulls, tolls)
r(".bcdfghjklmnpqrstvwxyz + s",
"*_",
this),
// (e.g., beads, toads, zoos)
};
// For words ending in -e (e-rules):
Rule[] eRules = {
r(".aeiouy bcdfghjklmnpqrstvwxyz l + e",
"es,er,ers,est,ed,ing,ings,y,ely,eness,enesses,ement,ements,eless,eful",
this),
// (e.g., able, abominable, fungible, table, enable, idle, subtle)
r("+ i e",
"ies,ier,iers,iest,ied,ying,yings,iely,ieness,ienesses,iement,iements,"
+"ieless,ieful",
this),
// (e.g., bookie, magpie, vie)
r("y e +",
"s,r,rs,st,d,ing,ings,ly,ness,nesses,ment,ments,less,ful",
this),
// (e.g., dye, redye, redeye)
r(".aeiouy d g + e",
"es,er,ers,est,ed,ing,ings,ely,eness,enesses,ment,ments,less,ful,ement,"
+"ements,eless,eful",
this),
// (e.g., judge, abridge)
r("u + e",
"es,er,ers,est,ed,ing,ings,eing,eings,ly,ely,eness,enesses,ment,ments,"
+"less,ful,ement,ements,eless,eful",
this),
// (e.g., true, due, imbue)
r(".aeiouy bcdfghjklmnpqrstvwxz + i z e",
"izes,izer,izers,ized,izing,izings,ization,izations,"
+"ise,ises,iser,isers,ised,ising,isings,isation,isations",
this),
// (e.g., tokenize) // adds British variations
r(".aeiouy bcdfghjklmnpqrstvwxz + i s e",
"ize,izes,izer,izers,ized,izing,izings,ization,izations,"
+"ises,iser,isers,ised,ising,isings,isation,isations",
this),
// (e.g., tokenise) // British variant // ~expertise
r("+ e",
"es,er,ers,est,ed,ing,ings,eing,eings,ely,eness,enesses,ement,ements,"
+"eless,eful",
this),
// (e.g., tree, agree, rage, horse, hoarse)
};
// For words ending in -ed (ed-rules):
Rule[] edRules = {
r("r e e + d",
"ds,der,ders,ded,ding,dings,dly,dness,dnesses,dment,dments,dless,dful,*_",
this),
// (e.g., agreed, freed, decreed, treed)
r("e e + d",
"ds,der,ders,ded,ding,dings,dly,dness,dnesses,dment,dments,dless,dful",
this),
// (e.g., feed, seed, Xweed)
r("bcdfghjklmnpqrstvwxyz + i e d",
"y,ie,ies,ier,iers,iest,ying,yings,ily,yly,iness,yness,inesses,ynesses,"
+"iment,iments,iless,iful,yment,yments,yless,yful",
this),
// (e.g., tried)
r(".aeiouy .bcdfghjklmnpqrstvwxyz l + l e d",
"_,s,er,ers,est,ing,ings,ly,ness,nesses,ment,ments,less,ful,&,&s,"
+"&er,&ers,&est,&ing,&ings,&y,&ness,&nesses,&ment,&ments,&ful",
this),
// (e.g., controlled, fulfilled, rebelled)
// both double and single l forms
r(".aeiouy l + l e d",
"&,&s,&er,&ers,&est,&ing,&ings,&y,&ness,&nesses,&ment,&ments,&ful",
this),
// (e.g., pulled, filled, fulled)
r(".aeiouy s + s e d",
"&,&es,&er,&ers,&est,&ing,&ings,&ly,&ness,&nesses,&ment,&ments,&less,&ful",
this),
// (e.g., hissed, grossed)
r("bcdfghjklmnpqrstvwxyz aeiouy bdgklmnprt + & e d",
"_,s,&er,&ers,&est,&ing,&ings,ly,ness,nesses,ment,ments,less,ful",
this),
// (e.g., hugged, trekked)
r(".aeiouy bcdfghjklmnpqrstvwxz + i z e d",
"izes,izer,izers,ize,izing,izings,ization,izations,"
+"ise,ises,iser,isers,ised,ising,isings,isation,isations",
this),
// (e.g., tokenize) // adds British variations
r(".aeiouy bcdfghjklmnpqrstvwxz + i s e d",
"ize,izes,izer,izers,ized,izing,izings,ization,izations,"
+"ises,iser,isers,ise,ising,isings,isation,isations",
this),
// (e.g., tokenise) // British variant // ~expertise
r(".aeiouy + e d",
"_,e,s,es,er,ers,est,ing,ings,ly,ely,ness,eness,nesses,enesses,"
+"ment,ement,ments,ements,less,eless,ful,eful",
this),
// (e.g., spoiled, tooled, tracked, roasted, atoned, abridged)
r("e d +",
"s,&er,&ers,&est,&ed,&ing,&ings,ly,ness,nesses,ment,ments,less,ful",
this),
// (e.g., bed, sled)
// words with a single e as the only vowel
};
// For words ending in -er (er-rules):
Rule[] erRules = {
r("m e t e r +",
"s,er,ers,ed,ing,ings,ly,ness,nesses,ment,ments,less,ful",
this),
// (e.g., altimeter, ammeter, odometer, perimeter)
r("+ e e r",
"eers,eered,eering,eerings,eerly,eerness,eernesses,eerment,eerments,"
+"eerless,eerful,ee,ees,eest,eed,eeing,eeings,eely,eeness,eenesses,"
+"eement,eements,eeless,eeful,eerer,eerers,eerest",
this),
// (e.g., agreer, beer, budgeteer, engineer, freer)
r("bcdfghjklmnpqrstvwxyz + i e r",
"y,ie,ies,iest,ied,ying,yings,ily,yly,iness,yness,inesses,ynesses,"
+"yment,yments,yless,yful,iment,iments,iless,iful,iers,iered,"
+"iering,ierings,ierly,ierness,iernesses,ierment,ierments,"
+"ierless,ierful,ierer,ierers,ierest",
this),
// (e.g., acidifier, tier)
r(".aeiouy l + l e r",
"&,&s,&est,&ed,&ing,&ings,ly,lely,&ness,&nesses,&ment,&ments,&ful,"
+"&ers,&ered,&ering,&erings,&erly,&erness,&ernesses,&erments,"
+"&erless,&erful",
this),
// (e.g., puller, filler, fuller)
// did not add: &erer, &erest, &errer, &errers, &errest,
// since i think the &er here is always an ending (?)
r(".aeiouy s + s e r",
"&,&es,&est,&ed,&ing,&ings,&ly,&ness,&nesses,&ment,&ments,&less,&ful,"
+"&ers,&ered,&ering,&erings,&erly,&erness,&ernesses,&erment,&erments,"
+"&erless,&erful",
this),
// (e.g., hisser, grosser)
// did not add: &erer, &erest, &errer, &errers, &errest,
// since i think the &er here is always an ending (?)
r("bcdfghjklmnpqrstvwxyz aeiouy bdgkmnprt + & e r",
"_,s,&est,&ed,&ing,&ings,ly,ness,nesses,ment,ments,less,ful,&ers,&ered,"
+"&ering,&erings,&erly,&erness,&ernesses,&erments,&erless,&erful",
this),
// (e.g., bigger, trekker, hitter)
// did not add: &erer, &erest, &errer, &errers, &errest,
// since i think the &er here is always an ending (?)
r(".aeiouy bcdfghjklmnpqrstvwxz + i z e r",
"izes,ize,izers,ized,izing,izings,ization,izations,"
+"ise,ises,iser,isers,ised,ising,isings,isation,isations",
this),
// (e.g., tokenize) // adds British variations
r(".aeiouy bcdfghjklmnpqrstvwxz + i s e r",
"ize,izes,izer,izers,ized,izing,izings,ization,izations,"
+"ises,ise,isers,ised,ising,isings,isation,isations",
this),
// (e.g., tokenise) // British variant // ~expertise
r(".aeiouy + e r",
"_,e,s,es,est,ed,ing,ings,ly,ely,ness,eness,nesses,enesses,ment,ments,"
+"less,ful,ement,ements,eless,eful,ers,ered,erred,ering,erring,erings,"
+"errings,erly,erness,ernesses,erment,erments,erless,erful,erer,erers,"
+"erest,errer,errers,errest",
this),
// (e.g., actioner, atoner, icer, trader, accruer, churchgoer, prefer)
};
// For words ending in -est (est-rules):
Rule[] estRules = {
r("bcdfghjklmnpqrstvwxyz + i e s t",
"y,ies,ier,iers,ied,ying,yings,ily,yly,iness,yness,inesses,ynesses,"
+"iment,iments,iless,iful",
this),
// (e.g., sliest, happiest, wittiest)
r(".aeiouy l + l e s t",
"&,&s,&er,&ers,&ed,&ing,&ings,ly,&ness,&nesses,&ment,&ments,&ful",
this),
// (e.g., fullest)
r(".aeiouy s + s e s t",
"&,&es,&er,&ers,&ed,&ing,&ings,&ly,&ness,&nesses,&ment,&ments,&less,&ful",
this),
// (e.g., grossest)
r("bcdfghjklmnpqrstvwxyz aeiouy bdglmnprst + & e s t",
"_,s,&er,&ers,&ed,&ing,&ings,ly,ness,nesses,ment,ments,less,ful",
this),
// (e.g., biggest)
r(".aeiouy c h + e s t",
"e,es,er,ers,ed,ing,ings,ly,ely,ness,eness,nesses,enesses,ment,ments,"
+"less,ful,ement,ements,eless,eful,ests,ester,esters,ested,"
+"esting,estings,estly,estness,estnesses,estment,estments,estless,estful",
this),
r(".aeiouy s h + e s t",
"e,es,er,ers,ed,ing,ings,ly,ely,ness,eness,nesses,enesses,ment,ments,"
+"less,ful,ement,ements,eless,eful,ests,ester,esters,ested,"
+"esting,estings,estly,estness,estnesses,estment,estments,estless,estful",
this),
r(".aeiouy jxsz + e s t",
"e,es,er,ers,ed,ing,ings,ly,ely,ness,eness,nesses,enesses,ment,ments,"
+"less,ful,ement,ements,eless,eful,ests,ester,esters,ested,"
+"esting,estings,estly,estness,estnesses,estment,estments,estless,estful",
this),
// (e.g., basest, archest, rashest)
r("e r + e s t",
"e,es,er,ers,ed,eing,eings,ely,eness,enesses,ement,ements,eless,eful,"
+"ests,ester,esters,ested,esting,estings,estly,estness,estnesses,"
+"estment,estments,estless,estful",
this),
// (e.g., severest, Xinterest, merest)
r(".aeiouy + e s t",
"_,e,s,es,er,ers,ed,ing,ings,ly,ely,ness,eness,nesses,enesses,ment,ments,"
+"less,ful,ement,ements,eless,eful,ests,ester,esters,ested,esting,estings,"
+"estly,estness,estnesses,estment,estments,estless,estful",
this),
// (e.g., slickest, coolest, ablest, amplest, protest, quest)
// polysyllables - note that this picks up quest because of the
// u but the forms generated are harmless
r("e s t +",
"s,er,ers,ed,ing,ings,ly,ness,nesses,ment,ments,less,ful",
this),
// (e.g., rest, test)
// monosyllables
};
// For words ending in -ful (ful-rules ):
Rule[] fulRules = {
r(".aeiouy bcdfghjklmnpqrstvwxyz + i f u l",
"ifully,ifulness,*y",
this),
// (e.g., beautiful, plentiful)
r(".aeiouy + f u l",
"fully,fulness,*_",
this),
// (e.g., hopeful, sorrowful)
};
// For words ending in -ical:
Rule[] icalRules = {
r(".aeiouy + i c a l",
"ic,ics,ically",
this),
// (e.g., academical, electrical, theatrical)
};
// For words ending in -ic:
Rule[] icRules = {
r(".aeiouy + i c",
"ics,ical,ically",
this),
// (e.g., academic, clinic, mechanic, methodic)
// we're now booting on all redos (w/ or w/out e) as too risky
};
// For words ending in -ing (ing-rules):
Rule[] ingRules = {
r("bcdfghjklmnpqrstvwxyz + y i n g",
"yings,ie,y,ies,ier,iers,iest,ied,iely,yly,ieness,yness,ienesses,ynesses,"
+"iment,iments,iless,iful",
this),
// (e.g., dying, crying, supplying)
// did not add -ing forms (see last 8 ing-rules)
r(".aeiouy l + l i n g",
"*_,&,&s,&er,&ers,&est,&ed,&ings,&ness,&nesses,&ment,&ments,&ful",
this),
// (e.g., pulling, filling, fulling)
// did not add -ing forms (see last 8 ing-rules)
// note that -ly has been dropped from this rule, as i believe
// that only a verb can be the stem here
r(".aeiouy s + s i n g",
"&,&s,&er,&ers,&est,&ed,&ings,&ly,&ness,&nesses,&ment,&ments,&less,&ful",
this),
// (e.g., hissing, grossing, processing)
// did not add -ing forms (see last 8 ing-rules)
r("bcdfghjklmnpqrstvwxyz aeiouy bdgklmnprt + & i n g",
"_,s,&er,&ers,&est,&ed,&ings,ly,ness,nesses,ment,ments,less,ful",
this),
// (e.g., hugging, trekking)
// did not add -ing forms (see last 8 ing-rules)
r("+ e e i n g",
"ee,ees,eer,eers,eest,eed,eeings,eely,eeness,eenesses,eement,eements,"
+"eeless,eeful",
this),
// (e.g., freeing, agreeing)
// did not add -ing forms (see last 8 ing-rules)
r("+ e i n g",
"e,es,er,ers,est,ed,eings,ely,eness,enesses,ement,ements,eless,eful",
this),
// (e.g., ageing, aweing)
// did not add -ing forms (see last 8 ing-rules)
r("aeiou y + i n g",
"_,s,er,ers,est,ed,ings,ly,ingly,ness,nesses,ment,ments,less,ful",
this),
// (e.g., toying, playing)
// did not add -ing forms (see last 8 ing-rules)
r(".aeiou bcdfghjklmnpqrstvwxyz eio t + i n g",
"*_,*e,ings,inger,ingers,ingest,inged,inging,ingings,ingly,"
+"ingness,ingnesses,ingment,ingments,ingless,ingful",
this),
// (e.g., editing, crediting, expediting, siting, exciting
// deleting, completing, coveting, interpreting
// piloting, pivoting, devoting)
r("bcdfghjklmnpqrstvwxyz aeiouy bdgklmt + i n g",
"*e,ings,inger,ingers,ingest,inged,inging,ingings,ingly,"
+"ingness,ingnesses,ingment,ingments,ingless,ingful",
this),
// (e.g., robing, siding, doling, translating, flaking)
// these consonants would double if there were no e in the stem
// removed p from this group: developing, galloping, etc.
// removed r from this group: monitoring, coloring, motoring
// removed n from this group: happening
r(".aeiouy bcdfghjklmnpqrstvwxz + i z i n g",
"izes,izer,izers,ized,ize,izings,ization,izations,"
+"ise,ises,iser,isers,ised,ising,isings,isation,isations",
this),
// (e.g., tokenize) // adds British variations
r(".aeiouy bcdfghjklmnpqrstvwxz + i s i n g",
"ize,izes,izer,izers,ized,izing,izings,ization,izations,"
+"ises,iser,isers,ised,ise,isings,isation,isations",
this),
// (e.g., tokenise) // British variant // ~expertise
r("aeiouy cgsvz + i n g",
"*e,ings,inger,ingers,ingest,inged,inging,ingings,ingly,"
+"ingness,ingnesses,ingment,ingments,ingless,ingful",
this),
// (e.g., icing, aging, achieving, amazing, housing)
// we had k in this list, but that's only right if the vowel
// is single - looking needs to be redone with _
r("bcdfghjklmnpqrstvwxyz clsuv + i n g",
"*e,ings,inger,ingers,ingest,inged,inging,ingings,ingly,"
+"ingness,ingnesses,ingment,ingments,ingless,ingful",
this),
// (e.g., dancing, troubling, arguing, bluing, carving)
r("lr g + i n g",
"*e,ings,inger,ingers,ingest,inged,inging,ingings,ingly,"
+"ingness,ingnesses,ingment,ingments,ingless,ingful",
this),
// (e.g., charging, bulging)
r(".aeiouy bcdfghjklmnpqrstvwxyz bdfjkmnpqrtwxz + i n g",
"*_,ings,inger,ingers,ingest,inged,inging,ingings,ingly,"
+"ingness,ingnesses,ingment,ingments,ingless,ingful",
this),
// (e.g., farming, harping, interesting, bedspring, redwing)
r(".aeiouy + i n g",
"*_,*e,ings,inger,ingers,ingest,inged,inging,ingings,ingly,"
+"ingness,ingnesses,ingment,ingments,ingless,ingful",
this),
// (e.g., spoiling, reviling, autoing, egging, hanging, hingeing,
// judging, breathing, mothing)
// these are the cases where we can't tell if e is needed or not
r("+ i n g",
"ings,inger,ingers,ingest,inged,inging,ingings,ingly,"
+"ingness,ingnesses,ingment,ingments,ingless,ingful",
this),
// (e.g., wing, thing)
// monosyllables
};
// For words ending in -leaf (leaf-rules):
Rule[] leafRules = {
r("+ l e a f",
"leaves",
this),
// (e.g., cloverleaf, flyleaf)
// leaf itself is in the exceptions list
};
// For words ending in -man:
Rule[] manRules = {
r("+ m a n",
"men,mans,maner,manner,manners,maners,manest,maned,manned,maning,"
+"manning,manings,mannings,manly,manness,mannesses,manless,manful",
this),
// (e.g., woman, policeman, cayman, unman)
};
// For words ending in -men:
Rule[] menRules = {
r("+ m e n",
"man,mens,mener,meners,menest,mened,mening,menings,menly,"
+"menness,mennesses,menless,menful",
this),
// (e.g., policewomen, hatchetmen, dolmen)
};
// For words ending in -ment (ment-rules):
Rule[] mentRules = {
r("s e g m e n t +",
"s,ed,ing,ings,er,ers,ly,ness,nesses,less,ful",
this),
// (e.g., segment, bisegment, cosegment)
r("p i g m e n t +",
"s,ed,ing,ings,er,ers,ly,ness,nesses,less,ful",
this),
// (e.g., pigment, depigment, repigment)
r(".aeiouy d g + m e n t",
"*e",
this),
// (e.g., judgment, abridgment)
r(".aeiouy bcdfghjklmnpqrstvwxyz + i m e n t",
"*y",
this),
// (e.g., merriment, embodiment)
r(".aeiouy + m e n t",
"*_",
this),
// (e.g., atonement, entrapment)
};
// For words ending in -o (o-rules):
Rule[] oRules = {
r("aeiou o +",
"s,er,ers,est,ed,ing,ings,ly,ness,nesses,ment,ments,less,ful",
this),
// (e.g., taboo, rodeo)
// no need to generate an es form
r(".aeiouy o +",
"s,es,er,ers,est,ed,ing,ings,ly,ness,nesses,ment,ments,less,ful",
this),
// (e.g., tomato, bonito)
// make both s and es plurals
};
// For words ending in -um (um-rules):
Rule[] umRules = {
r("+ u m",
"a,ums,umer,ummer,umers,ummers,umed,ummed,uming,umming,umings,"
+"ummings,umness,umments,umless,umful",
this),
// (e.g., datum, quantum, tedium, strum, [oil]drum, vacuum)
};
// For words ending in -y (y-rules):
Rule[] yRules = {
r(".aeiouy b + l y",
"le,les,ler,lers,lest,led,ling,lings,leness,lenesses,lement,lements,"
+"leless,leful",
this),
// (e.g., ably, horribly, wobbly)
r(".aeiouy bcdfghjklmnpqrstvwxyz + i l y",
"y,ies,ier,iers,iest,ied,ying,yings,yness,iness,ynesses,inesses,"
+"iment,iments,iless,iful",
this),
// (e.g., happily, dizzily)
r(".aeiouy f u l + l y",
"*_",
this),
// (e.g., peaceful+ly)
r(".aeiouy l + l y",
"*_,lies,lier,liers,liest,lied,lying,lyings,liness,linesses,"
+"liment,liments,liless,liful,*l",
this),
// (e.g., fully, folly, coolly, fatally, dally)
// both -l and -ll words
r("aou + l y",
"lies,lier,liers,liest,lied,lying,lyings,liness,linesses,"
+"liment,liments,liless,liful",
this),
// (e.g., monopoly, Xcephaly, holy)
// i.e., treat ly as part of the stem
r("+ l y",
"*_,lies,lier,liers,liest,lied,lying,lyings,liness,linesses,lyless,lyful",
this),
// (e.g., frequently, comely, deeply, apply, badly)
// i.e., redo stem AND generate all forms with ly as part of stem
r("bcdfghjklmnpqrstvwxyz + y",
"ies,ier,iers,iest,ied,ying,yings,ily,yness,iness,ynesses,inesses,"
+"iment,iments,iless,iful,yment,yments,yless,yful",
this),
// (e.g., happy, spy, cry)
r("aeiou y +",
"s,er,ers,est,ed,ing,ings,ly,ness,nesses,ment,ments,less,ful",
this),
// (e.g., betray, gay, stay)
};
// For other words (root-rules):
Rule[] rootRules = {
r(".aeiouy c h +",
"es,er,ers,est,ed,ing,ings,ly,ness,nesses,ment,ments,less,ful",
this),
r(".aeiouy s h +",
"es,er,ers,est,ed,ing,ings,ly,ness,nesses,ment,ments,less,ful",
this),
r(".aeiouy jxz +",
"es,er,ers,est,ed,ing,ings,ly,ness,nesses,ment,ments,less,ful",
this),
// (e.g., fix, arch, rash)
r(".aeiouy bcdfghjklmnpqrstvwxyz aeiouy bdglmnprt +",
"s,er,ers,est,ed,ing,ings,&er,&ers,&est,&ed,&ing,&ings,ly,"
+"ness,nesses,ment,ments,less,ful",
this),
// (e.g., unflag, open, besot)
// both possibilities for multisyllables
r("bcdfghjklmnpqrstvwxyz aeiouy bdglmnprt +",
"s,&er,&ers,&est,&ed,&ing,&ings,ly,ness,nesses,ment,ments,less,ful",
this),
// (e.g., bed, cop)
r(".aeiouy bcdfghjklmnpqrstvwxyz aeiouy m a + t a",
"_, s,tas,tum,tums,ton,tons,tic,tical",
this),
// (e.g., schemata, automata)
r(".aeiouy t + a",
"as,ae,um,ums,on,ons,ic,ical",
this),
// (e.g., chordata, data, errata, sonata, toccata)
r(".aeiouy .bcdfghjklmnpqrstvwxyz + a",
"as,ae,ata,um,ums,on,ons,al,atic,atical",
this),
// (e.g., schema, ova, polyhedra)
r(".aeiouy l l +",
"s,er,ers,est,ed,ing,ings,y,ness,nesses,ment,ments,-less,ful",
this),
// (e.g., full)
// note: adds a hyphen before less
r(".aeiouy +",
"s,er,ers,est,ed,ing,ings,ly,ness,nesses,ment,ments,less,ful",
this),
// (e.g., spoon, rhythm)
};
rulesTable = new Hashtable();
rulesTable.put("s", sRules);
rulesTable.put("e", eRules);
rulesTable.put("ed", edRules);
rulesTable.put("er", erRules);
rulesTable.put("est", estRules);
rulesTable.put("ful", fulRules);
rulesTable.put("ic", icRules);
rulesTable.put("ical", icalRules);
rulesTable.put("ing", ingRules);
rulesTable.put("man", manRules);
rulesTable.put("men", menRules);
rulesTable.put("ment", mentRules);
rulesTable.put("leaf", leafRules);
rulesTable.put("o", oRules);
rulesTable.put("um", umRules);
rulesTable.put("y", yRules);
rulesTable.put("default", rootRules);
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/ConceptGroupGenerator.java 0000644 0001750 0001750 00000006134 10661201772 030725 0 ustar varun varun /*
* @(#)ConceptGroupGenerator.java 1.6 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 1/13/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
package com.sun.java.help.search;
import java.io.InputStream;
class ConceptGroupGenerator implements CompressorIterator
{
private static final int NConceptsInGroup =
DocumentCompressor.NConceptsInGroup;
private static final int BitsInLabel =
DocumentCompressor.BitsInLabel;
private int _last;
private ConceptData[] _table;
private Decompressor _bits;
private int _k1;
private final int _k2 = BitsInLabel;
private ConceptData _cData;
public ConceptGroupGenerator()
{
_k1 = 0;
_table = new ConceptData[NConceptsInGroup];
_last = 0;
_bits = null;
}
public ConceptGroupGenerator(byte[] bytes, int index, int k)
{
_k1 = k;
_table = new ConceptData[NConceptsInGroup];
_last = 0;
_bits = new ByteArrayDecompressor(bytes, index);
}
public void init(byte[] bytes, int index, int k)
{
_k1 = k;
_bits = new ByteArrayDecompressor(bytes, index);
_last = 0;
for (int i = 0; i < NConceptsInGroup; i++)
_table[i] = null;
}
public void addTerms(int index, ConceptData terms) {
_table[index] = terms;
}
public int decodeConcepts(int k, int shift, int[] concepts) throws Exception {
return _bits.ascendingDecode(k, shift, concepts);
}
public int position() {
return _last;
}
public void value(int value) {
_last += value;
}
boolean next() throws Exception
{
try {
while (_bits.readNext(_k1, this))
if ((_cData = _table[_bits.read(_k2)]) != null)
return true;
return false;
}
catch (Exception e) {
e.printStackTrace();
System.err.println(_bits);
System.err.println(_table);
throw e;
}
}
public void generateFillers(RoleFiller[] array) {
_cData.generateFillers(array, _last);
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/BlockManager.java 0000644 0001750 0001750 00000015532 10661201772 026775 0 ustar varun varun /*
* @(#)BlockManager.java 1.14 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @(#) BlockManager.java 1.5 - last change made 03/20/98
*/
package com.sun.java.help.search;
import java.io.*;
/**
* This class manages Block(s) of information in DictBlock
*
* @author Jacek R. Ambroziak
* @author Roger D. Brinkley
* @version 1.5 03/20/98
*/
class BlockManager
{
/* the Dict file factory. It handles both retrieval and caching.
*/
private static RAFFileFactory factory = RAFFileFactory.create();
//!! not sure if the double list is still correct after many changes
private class BlockDescriptor
{
public Block block = null;
public boolean lock = false;
public boolean modf = false;
public int prev = 0;
public int next = 0;
public void reset()
{
lock = modf = false;
block = null;
}
}
private RAFFile file;
private long blockSize;
private boolean update;
final private int nBlocksLimit = 64;
private int blockTableSize;
private BlockDescriptor[] blockTab;
private int nBlocks = 0;
private int oldest = 0;
private int newest = 0;
private BlockFactory bfactory = null;
private final static int INCR = 256; // size increment
private Block dummy;
public BlockManager(BlockManagerParameters params,
boolean update,
BlockFactory bfactory) throws IOException
{
this.bfactory = bfactory;
this.update = update;
// params.readState();
blockSize = (long)params.getBlockSize();
debug(params.getURL().toString());
file = factory.get(params.getURL(), update);
debug(file.toString());
dummy = bfactory.makeBlock();
if (file.length() == 0 && update) {
dummy.setBlockNumber(0);
writeBlock(dummy);
}
blockTableSize = (int)(file.length()/blockSize);
blockTab = new BlockDescriptor[blockTableSize];
mapBlock(0, new BlockDescriptor(), bfactory.makeBlock());
}
public void lockBlock(int blNum) {
blockTab[blNum].lock = true;
}
public void unlockBlock(int blNum) {
blockTab[blNum].lock = false;
}
public void setModified(int blNum) {
blockTab[blNum].modf = true;
}
public void close() throws IOException
{
if (update)
for (int i = 0; i < blockTableSize; i++)
if (blockTab[i] != null && blockTab[i].modf)
writeBlock(blockTab[i].block);
file.close();
}
public Block accessBlock(int blockNumber) throws Exception
{
if (blockTab[blockNumber] != null)
moveToFront(blockNumber);
else if (nBlocks < nBlocksLimit)
mapBlock(blockNumber, new BlockDescriptor(), bfactory.makeBlock());
else
remapSomeBlock(blockNumber);
return blockTab[blockNumber].block;
}
public Block getNewBlock() throws Exception
{
int number = (int)(file.length()/blockSize);
if (number > blockTableSize - 1)
{
BlockDescriptor[] newArray =
new BlockDescriptor[blockTableSize + INCR];
System.arraycopy(blockTab, 0, newArray, 0, blockTableSize);
blockTab = newArray;
blockTableSize += INCR;
}
if (nBlocks < nBlocksLimit)
{
Block bl = bfactory.makeBlock();
bl.setBlockNumber(number);
writeBlock(bl);
addDescriptor(bl, number, new BlockDescriptor());
}
else
{
dummy.setBlockNumber(number);
writeBlock(dummy);
remapSomeBlock(number);
}
return blockTab[number].block;
}
private void mapBlock(int blockNumber, BlockDescriptor desc, Block block)
throws IOException
{
file.seek(blockSize * blockNumber);
Block.readIn(file, block);
addDescriptor(block, blockNumber, desc);
}
private void addDescriptor(Block block, int blockNumber,
BlockDescriptor desc)
{
blockTab[blockNumber] = desc;
desc.block = block;
blockTab[desc.prev = newest].next = blockNumber;
newest = blockNumber;
nBlocks++;
}
private void remapSomeBlock(int blockNumber) throws Exception
{
int index = oldest;
while (blockTab[index].lock && index != newest)
index = blockTab[index].next;
if (blockTab[index].lock)
throw new Exception("everything locked");
if (blockTab[index].modf)
writeBlock(blockTab[index].block);
nBlocks--;
Block reused = blockTab[index].block;
// delete from double-linked list
if (index == oldest)
oldest = blockTab[index].next;
else if (index == newest)
newest = blockTab[index].prev;
else
{
blockTab[blockTab[index].next].prev = blockTab[index].prev;
blockTab[blockTab[index].prev].next = blockTab[index].next;
}
blockTab[index].reset();
mapBlock(blockNumber, blockTab[index], reused);
// System.err.println("reuse "+index+" --> "+blockNumber+" "+nBlocks);
blockTab[index] = null;
}
private void moveToFront(int index)
{
if (index == oldest)
{
oldest = blockTab[index].next;
blockTab[index].prev = newest;
blockTab[newest].next = index;
newest = index;
}
else if (index != newest)
{
blockTab[blockTab[index].next].prev = blockTab[index].prev;
blockTab[blockTab[index].prev].next = blockTab[index].next;
blockTab[index].prev = newest;
blockTab[newest].next = index;
newest = index;
}
}
public void writeBlock(Block bl) throws IOException
{
file.seek(blockSize * bl.number);
bl.writeOut(file);
}
public void mapBlocks(BlockProcessor processor) throws IOException
{
long nBlocks = file.length()/blockSize;
Block block = bfactory.makeBlock();
file.seek(0);
for (int i = 0; i < nBlocks; i++)
processor.process(Block.readIn(file, block));
}
/**
* Debug code
*/
private boolean debug=false;
private void debug(String msg) {
if (debug) {
System.err.println("Block Manager: "+msg);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/Query.java 0000644 0001750 0001750 00000011160 10661201772 025546 0 ustar varun varun /*
* @(#)Query.java 1.12 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 1/13/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
package com.sun.java.help.search;
import java.util.*;
import javax.help.search.SearchQuery;
import javax.help.search.SearchItem;
class Query
{
private double _currentStandard;
private final int _nColumns;
private double[] _missingPenalty;
private double[] _upperboundTemplate;
private double[] _penalties;
private final SearchEnvironment _env;
private int _hitCounter;
private boolean _vote;
private HitStore _store;
public Query(SearchEnvironment env, int nColumns, double[] missingPenalties)
{
_env = env;
_nColumns = nColumns;
_missingPenalty = new double[nColumns];
_upperboundTemplate = new double[nColumns];
_penalties = missingPenalties;
_hitCounter = 0;
_vote = false;
_currentStandard = (nColumns - 1) * 10.0 + 9.9999;
_store = new HitStore(_currentStandard);
for (int i = 0; i < _nColumns; i++)
_missingPenalty[i] = missingPenalties != null
? missingPenalties[i]
: 10.0;
makePenaltiesTable();
}
public void makeEvent(int n, SearchQuery searchQuery)
{
Vector hits = new Vector(n);
if (n > 0)
{
int N = n;
QueryHit qh = _store.firstBestQueryHit();
n = N;
for ( ; qh != null; qh = --n > 0 ? _store.nextBestQueryHit() : null)
try {
hits.addElement(_env.makeItem(qh));
}
catch (Exception e) {
System.err.println(e + "hit not translated");
}
}
// Params not know at this time
searchQuery.itemsFound(true, hits);
}
public double lookupPenalty(int pattern) {
return _penalties[pattern];
}
public double getOutOufOrderPenalty() {
return 0.25;
}
public double getGapPenalty() {
return 0.005;
}
public int getNColumns() {
return _nColumns;
}
public boolean goodEnough(double penalty) {
return penalty <= _currentStandard;
}
public int[] getConceptArrayOfNewHit(double penalty, Location loc)
{
QueryHit hit = new QueryHit(loc, penalty, _nColumns);
_store.addQueryHit(hit);
_hitCounter++;
return hit.getArray();
}
public void resetForNextDocument()
{
_currentStandard = _store.getCurrentStandard();
// "everything's missing"
for (int i = 0; i < _nColumns; i++)
_upperboundTemplate[i] = _missingPenalty[i];
_vote = false;
}
public boolean vote()
{
double sum = 0.0;
for (int i = 0; i < _nColumns; i++)
sum += _upperboundTemplate[i];
return _vote = (sum <= _currentStandard);
}
public void updateEstimate(int role, double penalty) {
if (penalty < _upperboundTemplate[role])
_upperboundTemplate[role] = penalty;
}
public void printHits(int n)
{
if (n > 0)
{
int N = n;
QueryHit qh = _store.firstBestQueryHit();
n = N;
for ( ; qh != null; qh = --n > 0 ? _store.nextBestQueryHit() : null)
try {
System.out.println(_env.hitToString(qh));
}
catch (Exception e) {
System.err.println(e + "hit not translated");
}
}
}
private void makePenaltiesTable()
{
int nPatterns = 1 << _nColumns;
_penalties = new double[nPatterns];
for (int i = 0; i < nPatterns; i++)
_penalties[i] = computePenalty(i);
}
private double computePenalty(int n)
{
double penalty = 0.0;
for (int i = 0; i < _nColumns; i++)
if ((n & 1 << i) == 0)
penalty += _missingPenalty[i];
return penalty;
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/package.html 0000644 0001750 0001750 00000003422 10661201772 026061 0 ustar varun varun
Implementation classes for the default Search client using in the
reference implementation of JavaHelp.
Note:We have not yet finalized the location for these classes.
Related Documentation
For overviews, tutorials, examples, guides, tool support,
and other documentation,
please see
the JavaHelp home page
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/Compressor.java 0000644 0001750 0001750 00000012221 10661201772 026574 0 ustar varun varun /*
* @(#)Compressor.java 1.9 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 2/17/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
package com.sun.java.help.search;
import java.io.*;
class Compressor
{
private static final int NBits = 32;
private static final int BeginK = 5;
private BitBuffer _buffer = new BitBuffer();
public void write(DataOutput out) throws IOException {
_buffer.write(out);
}
public int byteCount() {
return _buffer.byteCount();
}
public void clear() {
_buffer.clear();
}
public void concatenate(Compressor other) {
_buffer.concatenate(other._buffer);
}
public void encode(IntegerArray pos, int k)
{
int power = 1 << k, n1 = 0;
for (int i = 0; i < pos.cardinality(); i++)
{
int n2 = pos.at(i) >>> k;
int rem = pos.at(i) % power;
if (n2 != n1)
{
int min = n1, a = n1;
int lev = 0, power2 = 1;
if (n2 > n1)
for (int max = n1; max < n2; a >>>= 1, power2 <<= 1, lev++)
if ((a & 1) != 0)
min -= power2;
else
max += power2;
else
for ( ; min > n2; a >>>= 1, power2 <<= 1, lev++)
if ((a & 1) != 0)
min -= power2;
// lev 0s, 1, lev bits of (n2 - min) plus following value
// no 'V' symbol needed here
if (lev*2 + 1 + k <= NBits)
_buffer.append((1<>> k;
int rem = pos.at(i) % power;
if (n2 != n1)
{
int min = n1, a = n1;
int lev = 0, power2 = 1;
if (n2 > n1)
for (int max = n1; max < n2; a >>>= 1, power2 <<= 1, lev++)
if ((a & 1) != 0)
min -= power2;
else
max += power2;
else
for ( ; min > n2; a >>>= 1, power2 <<= 1, lev++)
if ((a & 1) != 0)
min -= power2;
// lev 0s, 1, lev bits of (n2 - min) plus following value
if (lev*2 + 1 + k <= NBits)
_buffer.append((1< 0; k--)
{
_buffer.clear();
encode(array, k);
if (_buffer.bitCount() < min)
{
saved.setFrom(_buffer);
min = _buffer.bitCount();
minK = k;
}
else
break;
}
_buffer.setFrom(saved);
return minK;
}
public int compressAscending(IntegerArray array)
{
IntegerArray differences = new IntegerArray(array.cardinality());
array.toDifferences(differences);
return minimize(differences, BeginK);
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/StreamDecompressor.java 0000644 0001750 0001750 00000005372 10661201772 030272 0 ustar varun varun /*
* @(#)StreamDecompressor.java 1.6 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 1/13/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
package com.sun.java.help.search;
import java.io.*;
class StreamDecompressor extends Decompressor
{
private InputStream _input;
public StreamDecompressor(InputStream input) {
initReading(input);
}
public void initReading(InputStream input)
{
_input = input;
initReading();
}
public int getNextByte() throws java.io.IOException {
return _input.read();
}
public static void main(String[] args)
{
try {
FileInputStream file = new FileInputStream(args[0]);
try {
int k1 = file.read();
long start = System.currentTimeMillis();
System.out.println("k1 = " + k1);
IntegerArray concepts = new IntegerArray();
StreamDecompressor documents = new StreamDecompressor(file);
try {
documents.ascDecode(k1, concepts);
}
catch (Exception e) {
System.err.println(e);
}
System.out.println("index1 = " + concepts.cardinality());
int k2 = file.read();
System.out.println("k2 = " + k2);
IntegerArray offs = new IntegerArray(concepts.cardinality());
StreamDecompressor offsets = new StreamDecompressor(file);
try {
offsets.decode(k2, offs);
}
catch (Exception e) {
System.err.println(e);
}
System.out.println("index2 = " + offs.cardinality());
System.out.println((System.currentTimeMillis() - start) + " msec");
file.close();
}
catch (IOException e) {
System.err.println(e);
}
}
catch (FileNotFoundException e) {
System.err.println(e);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/NextDocGenerator.java 0000644 0001750 0001750 00000005221 10661201772 027655 0 ustar varun varun /*
* @(#)NextDocGenerator.java 1.6 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 1/13/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
package com.sun.java.help.search;
class NextDocGenerator
{
private int _document;
private final int _concept;
private final int _queryMask;
private final ConceptData _terms;
private final NonnegativeIntegerGenerator _iterator;
public NextDocGenerator(ConceptData cd, SearchEnvironment env)
{
_document = 0;
_concept = cd.getConcept();
_queryMask = cd.getQueryMask();
_terms = cd;
_iterator = env.getDocumentIterator(_concept);
}
public int first() throws Exception {
return _document =
_iterator != null ? _iterator.first() : NonnegativeIntegerGenerator.END;
}
public int next() throws Exception {
return _document = _iterator.next();
}
public int getDocument() {
return _document;
}
public int getConcept() {
return _concept;
}
public ConceptData getTerms() {
return _terms;
}
public int getQueryMask() {
return _queryMask;
}
// for sorting
public boolean compareWith(NextDocGenerator other)
{
return _document > other._document
|| _document == other._document && _concept > other._concept;
}
public boolean smallerThan(NextDocGenerator other)
{
return _document < other._document
|| _document == other._document && _concept < other._concept;
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/BlockManagerParameters.java 0000644 0001750 0001750 00000005436 10661201772 031023 0 ustar varun varun /*
* @(#)BlockManagerParameters.java 1.11 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @(#) BlockManagerParameters.java 1.3 - last change made 03/17/98
*/
package com.sun.java.help.search;
import java.net.URL;
/**
* This class contains the parameters necessary for Dict BlockManager
*
* @date 2/3/98
* @author Jacek R. Ambroziak
* @author Roger D. Brinkley
*/
class BlockManagerParameters extends DBPartParameters
{
private URL url;
private int blockSize;
protected int root;
public BlockManagerParameters(Schema schema, String partName)
throws Exception
{
super(schema, partName);
url = schema.getURL(partName);
debug(url.toString());
}
public boolean readState()
{
if (parametersKnown())
{
blockSize = integerParameter("bs");
// System.err.println("blockSize " + blockSize);
root = integerParameter("rt");
return true;
}
else
return false;
}
public void updateSchema(String params) {
super.updateSchema("bs="+blockSize+" rt="+root+" fl=-1 " + params);
}
public BlockManagerParameters(URL url, int blockSize, int root)
{
this.url = url;
this.blockSize = blockSize;
this.root = root;
}
public URL getURL() {
return url;
}
public int getBlockSize() {
return blockSize;
}
public void setBlockSize(int size) {
blockSize = size;
}
public int getRootPosition() {
return root;
}
public void setRoot(int root) {
this.root = root;
}
/**
* Debug code
*/
private boolean debug=false;
private void debug(String msg) {
if (debug) {
System.err.println("Block Manager Parameters: "+msg);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/NextDocGeneratorHeap.java 0000644 0001750 0001750 00000006426 10661201772 030463 0 ustar varun varun /*
* @(#)NextDocGeneratorHeap.java 1.7 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 1/13/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
package com.sun.java.help.search;
class NextDocGeneratorHeap
{
private static final int InitSize = 1024;
private int _heapSize = 0;
private int _size = InitSize;
private NextDocGenerator[] _heap = new NextDocGenerator[InitSize];
private int _free = 0;
private boolean _nonEmpty = false;
public boolean isNonEmpty() {
return _nonEmpty;
}
public void addGenerator(NextDocGenerator gen)
{
if (_free == _size)
{
NextDocGenerator[] newArray = new NextDocGenerator[_size *= 2];
System.arraycopy(_heap, 0, newArray, 0, _free);
_heap = newArray;
}
_heap[_free++] = gen;
}
public void start()
{
if ((_heapSize = _free) > 0)
{
// build heap
for (int i = _heapSize/2; i >= 0; i--)
heapify(i);
_nonEmpty = true;
}
else
_nonEmpty = false;
}
public void step() throws Exception
{
if (_heap[0].next() != NonnegativeIntegerGenerator.END)
heapify(0);
else if (_heapSize > 1)
{
_heap[0] = _heap[--_heapSize];
heapify(0);
}
else
_nonEmpty = false;
}
public int getDocument() {
return _heap[0].getDocument();
}
public int getConcept() {
return _heap[0].getConcept();
}
public ConceptData getTerms() {
return _heap[0].getTerms();
}
public int getQueryMask() {
return _heap[0].getQueryMask();
}
public void reset()
{
_nonEmpty = false;
_free = 0;
}
public boolean atDocument(int document) {
return _nonEmpty && _heap[0].getDocument() == document;
}
private void heapify(int i)
{
int r = (i + 1) << 1, l = r - 1;
int smallest = l < _heapSize && _heap[l].smallerThan(_heap[i]) ? l : i;
if (r < _heapSize && _heap[r].smallerThan(_heap[smallest]))
smallest = r;
if (smallest != i)
{
NextDocGenerator temp = _heap[smallest];
_heap[smallest] = _heap[i];
_heap[i] = temp;
heapify(smallest);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/RAFFile.java 0000644 0001750 0001750 00000006163 10661201772 025660 0 ustar varun varun /*
* @(#)RAFFile.java 1.14 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @(#) RAFFile.java 1.14 - last change made 10/30/06
*/
package com.sun.java.help.search;
import java.io.IOException;
/**
* This class can be used to read/write the contents of a RAF type files
* (i.e. DICT (Dictionary) & POSITIONS (Positions))
* file as part of JavaHelp Search Database. It uses RandamAccessFile for
* quick access to dictionary blocks (DictBlock).
*
* Extension of this class serve include memory resident or unwriteable
* RAFFile.
*
* @author Roger D. Brinkley
* @author Eduardo Pelegri-Llopart
* @version 1.14 10/30/06
*/
import java.net.URL;
import java.io.RandomAccessFile;
import java.io.File;
import java.io.IOException;
public class RAFFile {
private RandomAccessFile raf;
protected RAFFile() {
}
public RAFFile(String name, boolean update) throws IOException {
debug("RAFFile " + name);
raf = new RandomAccessFile(name, update?"rw":"r");
}
public long length() throws IOException {
return raf.length();
}
public long getFilePointer() throws IOException {
return raf.getFilePointer();
}
public void close() throws IOException {
raf.close();
}
public void seek(long pos) throws IOException {
raf.seek(pos);
}
public int readInt() throws IOException {
return raf.readInt();
}
public int read() throws IOException {
return raf.read();
}
public void readFully (byte b[]) throws IOException {
raf.readFully(b);
}
public int read(byte[] b, int off, int len) throws IOException {
return raf.read(b, off, len);
}
public void writeInt(int v) throws IOException {
raf.writeInt(v);
}
public void write(byte b[]) throws IOException {
raf.write(b);
}
/**
* Debug code
*/
private static final boolean debug = false;
private static void debug(String msg) {
if (debug) {
System.err.println("RAFFile: "+msg);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/BtreeDictParameters.java 0000644 0001750 0001750 00000012577 10661201772 030347 0 ustar varun varun /*
* @(#)BtreeDictParameters.java 1.15 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @(#) BtreeDictParameters.java 1.5 - last change made 04/01/98
*/
package com.sun.java.help.search;
import java.net.URL;
import java.net.URLConnection;
import java.util.StringTokenizer;
import java.io.*;
/**
*
* @version 1.5 04/01/98
* @author Jacek R. Ambroziak
* @author Roger D. Brinkley
* @author Eduardo Pelegri-Llopart
*/
class BtreeDictParameters extends BlockManagerParameters
{
private int id1;
private String dirName;
// some form of this is needed for starting new DBs
public BtreeDictParameters(URL fileName, int blockSize, int root,
int freeID)
{
super(fileName, blockSize, root);
id1 = freeID;
}
public BtreeDictParameters(Schema schema, String partName)
throws Exception
{
super(schema, partName);
}
public boolean readState()
{
if (super.readState())
{
setFreeID(integerParameter("id1"));
return true;
}
else
return false;
}
public void writeState() {
}
public int getFreeID() {
return id1;
}
public final void setFreeID(int id) {
id1 = id;
}
private void setDirName(String dirName) {
this.dirName = dirName;
}
public static BtreeDictParameters create(URL dirName)
{
try {
URL url = new URL(dirName, "TMAP");
BtreeDictParameters bdp = null;
// new BtreeDictParameters(url, 2048, 0, 1);
bdp.setDirName(dirName.getFile());
return bdp;
} catch (java.net.MalformedURLException e) {
System.out.println ("Couldn't create " + dirName + File.separator + "TMAP");
}
return null;
}
public static BtreeDictParameters read(String dir, URL hsBase)
throws Exception
{
URL baseURL=null, url, tmapURL=null;
URLConnection connect;
BufferedReader in;
File file;
int blockSize = -1;
int rootPosition = -1;
int freeID = -1;
if (hsBase == null) {
file = new File(dir);
if (file.exists()) {
// On Win32 we need to convert all "\" to "/"
if (File.separatorChar != '/') {
dir = dir.replace(File.separatorChar, '/');
}
// Make sure the last character is a file separator
if (dir.lastIndexOf(File.separatorChar)
!= dir.length() - 1) {
dir = dir.concat(File.separator);
}
debug ("file:" + dir);
// Use a file protocol
baseURL = new URL("file", "", dir);
} else {
// Assume that some protocol was specified and try it
baseURL = new URL(dir);
}
}
// Read the SCHEMA data
if (hsBase != null) {
url = new URL(hsBase, dir + "/SCHEMA");
} else {
url = new URL(baseURL, "SCHEMA");
}
connect = url.openConnection();
in = new BufferedReader
(new InputStreamReader(connect.getInputStream()));
// This needs to be replaced with our XML Parser
String line;
do {
line = in.readLine();
}
while (!line.startsWith("TMAP"));
in.close();
StringTokenizer tokens = new StringTokenizer(line, " =");
tokens.nextToken(); // skip over 'TMAP'
while (tokens.hasMoreTokens())
{
String token = tokens.nextToken();
if (token.equals("bs"))
blockSize = Integer.parseInt(tokens.nextToken());
else if (token.equals("rt"))
rootPosition = Integer.parseInt(tokens.nextToken());
else if (token.equals("id1"))
freeID = Integer.parseInt(tokens.nextToken());
}
if (hsBase != null) {
tmapURL = new URL(hsBase, dir + "/TMAP");
} else {
tmapURL = new URL(baseURL, "TMAP");
}
BtreeDictParameters bdp = null;
// new BtreeDictParameters(tmapURL, blockSize, rootPosition, freeID);
if (hsBase == null) {
bdp.setDirName(Utilities.URLDecoder(baseURL.getFile()));
}
return bdp;
}
public void updateSchema() {
super.updateSchema("id1="+id1+" id2=1");
}
public void write() throws java.io.IOException
{
FileWriter out = new FileWriter(dirName + "/SCHEMA");
out.write("JavaSearch 1.0\n");
out.write("TMAP bs=2048 rt="+root+" fl=-1 id1="+id1+" id2=1\n");
out.close();
}
/**
* For printf debugging.
*/
private static boolean debugFlag = false;
private static void debug(String str) {
if( debugFlag ) {
System.out.println("BtreeDictParamters: " + str);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/TemporaryRAFFile.java 0000644 0001750 0001750 00000006753 10661201772 027570 0 ustar varun varun /*
* @(#)TemporaryRAFFile.java 1.4 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @(#) TemporaryRAFFile.java 1.4 - last change made 10/30/06
*/
package com.sun.java.help.search;
import java.io.IOException;
/**
* This class can be used to read/write the contents of a RAF type files
* (i.e. DICT (Dictionary) & POSITIONS (Positions))
* file as part of JavaHelp Search Database. It uses RandamAccessFile for
* quick access to dictionary blocks (DictBlock).
*
* Extension of this class serve include memory resident or unwriteable
* RAFFile.
*
* @author Roger D. Brinkley
* @author Eduardo Pelegri-Llopart
* @version 1.4 10/30/06
*/
import java.net.URL;
import java.io.RandomAccessFile;
import java.io.File;
import java.io.IOException;
import java.security.Permission;
final public class TemporaryRAFFile extends RAFFile {
private RandomAccessFile raf;
private Permission permission;
// provides only read access.
public TemporaryRAFFile(File file, Permission permission) throws IOException{
debug("TemporaryRAFFile " + file);
raf = new RandomAccessFile(file, "r");
this.permission = permission;
}
public long length() throws IOException {
// check permission
return raf.length();
}
public long getFilePointer() throws IOException {
// check permission
return raf.getFilePointer();
}
public void close() throws IOException {
// check permission
raf.close();
}
public void seek(long pos) throws IOException {
// check permission
raf.seek(pos);
}
public int readInt() throws IOException {
// check permission
return raf.readInt();
}
public int read() throws IOException {
// check permission
return raf.read();
}
public void readFully (byte b[]) throws IOException {
// check permission
raf.readFully(b);
}
public int read(byte[] b, int off, int len) throws IOException {
// check permission
return raf.read(b, off, len);
}
public void writeInt(int v) throws IOException {
// check permission
raf.writeInt(v);
}
public void write(byte b[]) throws IOException {
// check permission
raf.write(b);
}
/**
* Debug code
*/
private static final boolean debug = false;
private static void debug(String msg) {
if (debug) {
System.err.println("TemporaryRAFFile: "+msg);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/IntegerArray.java 0000644 0001750 0001750 00000005500 10661201772 027036 0 ustar varun varun /*
* @(#)IntegerArray.java 1.7 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 1/13/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
package com.sun.java.help.search;
class IntegerArray
{
private int[] _array;
private int _size;
private int _free = 0;
private static final int InitialSize = 128;
public IntegerArray() {
_array = new int[_size = InitialSize];
}
public IntegerArray(int size) {
_array = new int[_size = size];
}
public void clear() {
_free = 0;
}
public int at(int index) {
return _array[index];
}
public void add(int value)
{
if (_free == _size)
growArray(_size * 2);
_array[_free++] = value;
}
private void growArray(int size)
{
int[] newArray = new int[_size = size];
System.arraycopy(_array, 0, newArray, 0, _free);
_array = newArray;
}
public int popLast() {
return _array[--_free];
}
public int cardinality() {
return _free;
}
public void toDifferences(IntegerArray result)
{
if (result._size < _size)
result.growArray(_size);
if ((result._free = _free) > 0)
{
result._array[0] = _array[0];
for (int i = 1; i < _free; i++)
result._array[i] = _array[i] - _array[i - 1];
}
}
public int indexOf(int value)
{
int i = 0, j = _free, k;
while (i <= j)
if (_array[k = (i + j)/2] < value)
i = k + 1;
else if (value < _array[k])
j = k - 1;
else
return k;
return -1;
}
public void print(java.io.PrintStream out)
{
for (int i = 0; i < _free - 1; i++)
{
out.print(_array[i]);
out.print(' ');
}
out.println(_array[_free - 1]);
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/ConceptList.java 0000644 0001750 0001750 00000003660 10661201772 026676 0 ustar varun varun /*
* @(#)ConceptList.java 1.6 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 1/13/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
package com.sun.java.help.search;
class ConceptList implements NonnegativeIntegerGenerator, CompressorIterator
{
private ByteArrayDecompressor _list;
private byte _k;
private int _value = 0;
public ConceptList(byte[] array, int index)
{
_k = array[index];
_list = new ByteArrayDecompressor(array, index + 1);
}
// callback
public void value(int val) {
_value += val;
}
public int first() throws Exception {
_value = 0;
return _list.readNext(_k, this) ? _value : END;
}
public int next() throws Exception {
return _list.readNext(_k, this) ? _value : END;
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/DocumentCompressor.java 0000644 0001750 0001750 00000027430 10661201772 030303 0 ustar varun varun /*
* @(#)DocumentCompressor.java 1.16 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 1/13/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
package com.sun.java.help.search;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
class DocumentCompressor
{
static public final int NConceptsInGroup = 16;
static public final int BitsInLabel = 4;
static public final int DefaultSize = 32;
private int _nGroups;
private int _nExtents;
private int _freeComp;
private int _sizeComp = DefaultSize;
private int _kk;
private Compressor _currentCompressor = null;
private Compressor[] _compressors = new Compressor[DefaultSize];
private Compressor _kCompr = new Compressor();
private Compressor _lCompr = new Compressor();
private Compressor _mCompr = new Compressor();
private Compressor _posCompressor = new Compressor();
private IntegerArray _kTable = new IntegerArray();// k's for the series
private IntegerArray _lTable = new IntegerArray();// lengths of the C/P groups
private IntegerArray _maxConcepts = new IntegerArray();// maximal concepts in CP
private IntegerArray _concepts = new IntegerArray();
private IntegerArray _documents = new IntegerArray();
private IntegerArray _offsets = new IntegerArray();
private IntegerArray _titles = new IntegerArray();
private IntegerArray _positions = new IntegerArray();
private IntegerArray _labels = new IntegerArray();
private RandomAccessFile _posFile;
public DocumentCompressor(URL url) throws Exception
{
URL posURL = new URL(url, "POSITIONS");
if (isFileURL(posURL))
{
// this code should not be repeated
try {
URL offURL = new URL(url, "OFFSETS");
URLConnection connect = offURL.openConnection();
BufferedInputStream in =
new BufferedInputStream(connect.getInputStream());
int k1 = in.read();
StreamDecompressor sddocs = new StreamDecompressor(in);
sddocs.ascDecode(k1, _documents);
int k2 = in.read();
StreamDecompressor sdoffsets = new StreamDecompressor(in);
sdoffsets.ascDecode(k2, _offsets);
// decompress titles' ids table
int k3 = in.read();
StreamDecompressor sdtitles = new StreamDecompressor(in);
sdtitles.decode(k3, _titles);
in.close();
}
catch (java.io.FileNotFoundException e) {;}
_posFile =
new RandomAccessFile(Utilities.URLDecoder(posURL.getFile()),
"rw");
}
else
throw new IOException();
}
private boolean isFileURL(URL url) {
return url.getProtocol().equalsIgnoreCase("file");
}
public void close(String indexFile) throws java.io.IOException
{
_posFile.close();
writeOutOffsets(indexFile);
}
public void compress(int docID, int titleID,
ConceptLocation[] locations, int count,
ConceptLocation[] extents, int extCount)
throws java.io.IOException
{
long start = System.currentTimeMillis();
encode(locations, count, NConceptsInGroup);
if (extCount > 0)
encodeExtents(extents, extCount);
finalizeEncoding();
debug((System.currentTimeMillis() - start) + " msec proc");
int nBytes = byteCount();
start = System.currentTimeMillis();
long currentEnd = _posFile.length();
_documents.add(docID);
_offsets.add((int)currentEnd);
_titles.add(titleID);
_posFile.seek(currentEnd);
writeOut(_posFile);
debug((System.currentTimeMillis() - start) + " msec file");
debug("nGroups = " + _nGroups);
}
private void writeOutOffsets(String indexFile) throws java.io.IOException
{
Compressor documents = new Compressor();
int k1 = documents.compressAscending(_documents);
Compressor offsets = new Compressor();
int k2 = offsets.compressAscending(_offsets);
Compressor titles = new Compressor();
int k3 = titles.minimize(_titles, 8); // the starting k
int nBytes = documents.byteCount();
RandomAccessFile out = new RandomAccessFile(indexFile, "rw");
out.seek(0); // position at beginning
out.write(k1);
documents.write(out);
out.write(k2);
offsets.write(out);
out.write(k3);
titles.write(out);
out.close();
}
private void encode(ConceptLocation[] locations, int count, int nConcepts)
{
final int initK = 4;
// first sort by concept only
ConceptLocation.sortByConcept(locations, 0, count);
// using the fact that concepts are already sorted
// count of groups of 'nConcepts'
// go for differences directly
clear();
int conceptCounter = 0;
int fromIndex = 0;
int prevMax = 0;
int last = locations[0].getConcept(); // init w/ first ID
nextCompressor();
_concepts.add(last);
for (int i = 0;;)
{
for (; i < count && locations[i].getConcept() == last; i++)
locations[i].setConcept(conceptCounter);
if (i == count)
{
if (_concepts.cardinality() > 0)
{
++_nGroups;
_kTable.add(_currentCompressor.minimize(_concepts, initK));
}
encodePositions(locations, fromIndex, i, BitsInLabel);
break;
}
else // new concept (group?)
{
if (++conceptCounter == nConcepts)
{
++_nGroups;
// we are looking at the beginning of a new group
// last is maximal for the group just finished
// it won't be stored in concepts array but maxConcepts
_concepts.popLast();
_maxConcepts.add(last - prevMax);
prevMax = last;
_kTable.add(_currentCompressor.minimize(_concepts, initK));
encodePositions(locations, fromIndex, i, BitsInLabel);
fromIndex = i;
nextCompressor();
_concepts.clear();
conceptCounter = 0;
}
_concepts.add(locations[i].getConcept() - last);
last = locations[i].getConcept();
}
}
}
private void encodePositions(ConceptLocation[] locations, int from, int to,
int cK)
{
final int initK = 3;
int lastPos, k;
// sort in place by positions only
ConceptLocation.sortByPosition(locations, from, to);
_positions.clear();
_labels.clear();
_positions.add(lastPos = locations[from].getBegin());
_labels.add(locations[from].getConcept()); // now: a label
// skip duplicates
for (int i = from, j = from + 1; j < to; j++)
if (locations[i].equals(locations[j]) == false)
{
i = j;
_positions.add(locations[i].getBegin() - lastPos);
lastPos = locations[i].getBegin();
_labels.add(locations[i].getConcept()); // now: a label
}
// first find k by minimizing just positions w/o labels
_kTable.add(k = _posCompressor.minimize(_positions, initK));
_posCompressor.clear();
_posCompressor.encode(_positions, _labels, k, cK);
_currentCompressor.concatenate(_posCompressor);
}
private void encodeExtents(ConceptLocation[] extents, int extCount)
{
// side effects:
// 'k3' added to _kTable
// a number of compressors populated: header + lengths' lists
final int initK = 4;
int c = 0;
IntegerArray concepts = new IntegerArray(extCount); // differences
IntegerArray lengths = new IntegerArray();
IntegerArray kTable = new IntegerArray();
IntegerArray lTable = new IntegerArray();
// reserve a compressor for concatenated tables
nextCompressor();
Compressor extentsHeader = _currentCompressor;
for (int i = 0; i < extCount; i++)
if (extents[i].getConcept() != c)
{
if (c != 0)
{
_nExtents++;
nextCompressor();
kTable.add(_currentCompressor.minimize(lengths, initK));
lTable.add(_currentCompressor.byteCount());
}
concepts.add(extents[i].getConcept() - c);
c = extents[i].getConcept();
lengths.clear();
lengths.add(extents[i].getLength());
}
else
lengths.add(extents[i].getLength());
// last table of lengths
nextCompressor();
kTable.add(_currentCompressor.minimize(lengths, initK));
lTable.add(_currentCompressor.byteCount());
Compressor compressor1 = new Compressor();
kTable.add(compressor1.minimize(lTable, initK));
Compressor compressor2 = new Compressor();
kTable.add(compressor2.minimize(concepts, initK));
_kTable.add(extentsHeader.minimize(kTable, initK)); // k3
extentsHeader.concatenate(compressor1);
extentsHeader.concatenate(compressor2);
}
private void finalizeEncoding()
{
if (_nGroups > 1)
{
// if extents follow C/P groups we need the length of the last group
int limit = _nExtents > 0 ? _freeComp : _freeComp - 1;
for (int j = 0; j < limit; j++) // length of last not saved
_lTable.add(_compressors[j].byteCount());
_kTable.add(_mCompr.minimize(_maxConcepts, 3));
_kTable.add(_lCompr.minimize(_lTable, 3));
_kk = _kCompr.minimize(_kTable, 3);
_kCompr.concatenate(_lCompr);
_kCompr.concatenate(_mCompr);
}
else if (_nGroups == 1 && _nExtents > 0)
{
// length of the single C/P group packed with k-s
_kTable.add(_compressors[0].byteCount());
_kk = _kCompr.minimize(_kTable, 3);
}
debug("compr: "+byteCount()+" bytes");
}
private void writeOut(DataOutput out) throws java.io.IOException
{
if (_nExtents == 0)
if (_nGroups > 1)
{
out.write(0x80 | _kk);
_kCompr.write(out); // concatenated k,l,m
for (int j = 0; j < _freeComp; j++)
_compressors[j].write(out);
}
else // single group, no extents; code: 00
{
out.write(_kTable.at(0)); // k1
out.write(_kTable.at(1)); // k2
_compressors[0].write(out); // C/P
}
else // extents
{
out.write((_nGroups > 1 ? 0xC0 : 0x40) | _kk);
_kCompr.write(out);
for (int j = 0; j < _freeComp; j++)
_compressors[j].write(out);
}
}
private Compressor nextCompressor()
{
if (_freeComp == _sizeComp)
{
Compressor[] newArray = new Compressor[_sizeComp *= 2];
System.arraycopy(_compressors, 0, newArray, 0, _freeComp);
_compressors = newArray;
}
if (_compressors[_freeComp] == null)
_compressors[_freeComp] = new Compressor();
return _currentCompressor = _compressors[_freeComp++];
}
private int byteCount()
{
if (_nGroups == 1 && _nExtents == 0)
return 2 + _compressors[0].byteCount();
else
{
int result = 1; // initial kk
result += _kCompr.byteCount();
for (int j = 0; j < _freeComp; j++)
result += _compressors[j].byteCount();
return result;
}
}
private void clear()
{
_nGroups = 0;
_nExtents = 0;
_kTable.clear();
_lTable.clear();
_concepts.clear();
_maxConcepts.clear();
_kCompr.clear();
_lCompr.clear();
_mCompr.clear();
for (int i = 0; i < _sizeComp; i++)
if (_compressors[i] != null)
_compressors[i].clear();
_freeComp = 0;
_currentCompressor = null;
}
/**
* Debug code
*/
private static boolean debug=false;
private static void debug(String msg) {
if (debug) {
System.err.println("DocumentCompressor: "+msg);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/ByteArrayDecompressor.java 0000644 0001750 0001750 00000003554 10661201772 030741 0 ustar varun varun /*
* @(#)ByteArrayDecompressor.java 1.6 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 1/13/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
package com.sun.java.help.search;
class ByteArrayDecompressor extends Decompressor
{
private byte[] _array;
private int _index;
private int _index0;
public ByteArrayDecompressor(byte[] array, int index) {
initReading(array, index);
}
public void initReading(byte[] array, int index)
{
_array = array;
_index = _index0 = index;
initReading();
}
public int bytesRead() {
return _index - _index0;
}
protected int getNextByte() throws Exception {
return _array[_index++] & 0xFF;
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/Schema.java 0000644 0001750 0001750 00000012424 10661201772 025645 0 ustar varun varun /*
* @(#)Schema.java 1.11 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @version 1.5 03/18/98
* @author Jacek R. Ambroziak
*/
package com.sun.java.help.search;
import java.util.Vector;
import java.util.Hashtable;
import java.util.StringTokenizer;
import java.net.URL;
import java.net.URLConnection;
import java.io.*;
public class Schema
{
private String _dirName;
private URL _hsBase = null;
private boolean _update;
private Vector _lines = new Vector();
public static void main(String[] args)
{
try {
Schema sch = new Schema(null, "/files/resources/lexicon/LIF_ONT", false);
debug(sch.parametersAsString("EDGE"));
debug(sch.parametersAsString("TMAP"));
debug(sch.parameters("EDGE").get("rt").toString());
debug(sch.parameters("EDGE").get("vl").toString());
}
catch (Exception e) {
e.printStackTrace();
}
}
public Schema(URL base, String dirName, boolean update) throws Exception
{
_hsBase = base;
_dirName = dirName;
_update = update;
try {
read();
}
catch (java.io.FileNotFoundException e) {
debug("error creating SCHEMA");
}
for (int i = 0; i < _lines.size(); i++)
debug(_lines.elementAt(i).toString());
}
public void update(String partName, String parameters)
{
for (int i = 0; i < _lines.size(); i++)
if (((String)_lines.elementAt(i)).startsWith(partName))
_lines.removeElementAt(i);
_lines.addElement(partName + " " + parameters);
}
public String parametersAsString(String name)
{
for (int i = 0; i < _lines.size(); i++)
if (((String)_lines.elementAt(i)).startsWith(name))
return ((String)_lines.elementAt(i)).substring(name.length() + 1);
return null;
}
public Hashtable parameters(String name)
{
for (int i = 0; i < _lines.size(); i++)
if (((String)_lines.elementAt(i)).startsWith(name))
{
Hashtable result = new Hashtable();
StringTokenizer tokens =
new StringTokenizer((String)_lines.elementAt(i), " =");
tokens.nextToken(); // skip name
while (tokens.hasMoreTokens())
result.put(tokens.nextToken(), tokens.nextToken());
return result;
}
return null;
}
public URL getURL(String name) throws Exception
{
URL baseURL=null, url, tmapURL=null;
URLConnection connect;
File file;
debug("getURL " + name);
debug("dirName=" + _dirName + " hsBase= " + _hsBase);
if (_hsBase == null) {
file = new File(_dirName);
if (file.exists()) {
// On Win32 we need to convert all "\" to "/"
if (File.separatorChar != '/') {
_dirName = _dirName.replace(File.separatorChar, '/');
}
// Make sure the last character is a file separator
if (_dirName.lastIndexOf('/')
!= _dirName.length() - 1) {
_dirName = _dirName.concat("/");
}
debug ("file:" + _dirName);
// Use a file protocol
baseURL = new URL("file", "", _dirName);
} else {
// Assume that some protocol was specified and try it
baseURL = new URL(_dirName);
}
}
// Read the SCHEMA data
if (_hsBase != null) {
return new URL(_hsBase, _dirName + "/" + name);
} else {
return new URL(baseURL, name);
}
}
public void save()
{
if (_update) {
try {
FileWriter out = new FileWriter(_dirName + "/SCHEMA");
out.write("JavaSearch 1.0\n");
for (int i = 0; i < _lines.size(); i++)
{
out.write((String)_lines.elementAt(i));
out.write('\n');
}
out.close();
}
catch (IOException e) {
System.err.println("SCHEMA save failed " + e);
}
}
}
private void read() throws Exception
{
URL url;
URLConnection connect;
BufferedReader in;
url = getURL("SCHEMA");
connect = url.openConnection();
in = new BufferedReader
(new InputStreamReader(connect.getInputStream()));
// This needs to be replaced with our XML Parser
String line;
while ((line = in.readLine()) != null)
_lines.addElement(line);
in.close();
}
/**
* For printf debugging.
*/
private static boolean debugFlag = false;
private static void debug(String str) {
if( debugFlag ) {
System.out.println("Schema: " + str);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/QueryEngine.java 0000644 0001750 0001750 00000015437 10661201772 026707 0 ustar varun varun /*
* @(#)QueryEngine.java 1.25 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @version 1.25 10/30/06
*/
package com.sun.java.help.search;
import java.text.BreakIterator;
import java.util.Vector;
import java.util.Locale;
import java.util.Enumeration;
import java.lang.reflect.Method;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.File;
import java.net.URL;
import javax.help.search.SearchQuery;
import javax.help.HelpUtilities;
/**
* This class is the initial interface into the search engine. It can be
* run as a standalone search engine or instantiated as a class.
*
* @author Jacek R. Ambroziak
* @author Roger D. Brinkley
* @author Eduardo Pelegri-Llopart
* @version 1.25 10/30/06
*/
public class QueryEngine
{
private SearchEnvironment _env;
public QueryEngine(String indexDir, URL hsBase) throws Exception {
_env = new SearchEnvironment(indexDir, hsBase);
}
public void processQuery(String query, Locale l, SearchQuery searchQuery) throws Exception
{
BreakIterator boundary;
int start;
String term;
Vector ids = new Vector();;
LiteMorph morph = getMorphForLocale(l);
int col=-1;
try {
boundary = BreakIterator.getWordInstance(l);
boundary.setText(query);
start = boundary.first();
for (int end = boundary.next();
end != BreakIterator.DONE;
start = end, end = boundary.next()) {
term = new String(query.substring(start,end));
term = term.trim();
term = term.toLowerCase(l);
if (term.length() > 1) {
col += 1;
int id = _env.fetch(term);
if (id > 0) {
ids.addElement(new SearchIds(col, id, 0.0));
}
if (morph != null) {
String [] morphs = morph.variantsOf(term);
for (int i=0; i < morphs.length ; i++) {
int id2 = _env.fetch(morphs[i]);
if (id2 > 0) {
ids.addElement(new SearchIds(col, id2, 0.1));
}
}
}
} else if (term.length() == 1) {
int charType = Character.getType(term.charAt(0));
if ((charType == Character.DECIMAL_DIGIT_NUMBER) ||
(charType == Character.LETTER_NUMBER) ||
(charType == Character.LOWERCASE_LETTER) ||
(charType == Character.OTHER_LETTER) ||
(charType == Character.OTHER_NUMBER) ||
(charType == Character.TITLECASE_LETTER) ||
(charType == Character.UNASSIGNED) ||
(charType == Character.UPPERCASE_LETTER)) {
col += 1;
int id = _env.fetch(term);
if (id > 0) {
ids.addElement(new SearchIds(col, id, 0.0));
}
if (morph != null) {
String [] morphs = morph.variantsOf(term);
for (int i=0; i < morphs.length ; i++) {
int id2 = _env.fetch(morphs[i]);
if (id2 > 0) {
ids.addElement(new SearchIds(col, id2, 0.1));
}
}
}
}
}
}
}
catch (Exception e) {
e.printStackTrace();
}
int size = ids.size();
Search search = new Search(_env, col + 1);
IntegerArray children = new IntegerArray();
// add the terms and any children of a given term to the list of
// searched items. Penalize the children slightly
for (int i = 0; i < size; i++)
{
SearchIds id = (SearchIds) ids.elementAt(i);
search.addTerm(id.col, id.concept, id.score, 0);
children.clear();
_env.getChildren(id.concept, children);
if (children.cardinality() > 0)
for (int j = 0; j < children.cardinality(); j++)
{
search.addTerm(id.col, children.at(j),
id.score + 0.1, 0);
// appending (grand)+children
//!!! as it is too many duplicates are added
_env.getChildren(children.at(j), children);
}
}
search.startSearch(searchQuery);
}
private LiteMorph getMorphForLocale(Locale l) {
// In the event that nolocale has been defined try English
if (l == null) {
l = Locale.ENGLISH;
}
//Try to find a locale version of LiteMorph
Enumeration enum1 = HelpUtilities.getCandidates(l);
String front = "com.sun.java.help.search.LiteMorph";
ClassLoader cl = QueryEngine.class.getClassLoader();
while (enum1.hasMoreElements()) {
String tail = (String) enum1.nextElement();
String name = new String(front + tail);
try {
Class klass;
if (cl == null) {
klass = Class.forName(name);
} else {
klass = cl.loadClass(name);
}
Method method = klass.getMethod ("getMorph",
(java.lang.Class[]) null);
return (LiteMorph) method.invoke(null,
(java.lang.Object[]) null);
} catch (Exception e) {
continue;
}
}
// couldn't find a match
return null;
}
public static void main(String[] args)
{
try {
// BufferedReader is needed for readLine() method
BufferedReader in =
// but we'll make it a degenerate buffer of 1
// to workaround a problem with some PC implementation
// which wouldn't start to read before a lot of chars
// were typed
new BufferedReader(new InputStreamReader(System.in), 1);
String file = new String (args[0]);
QueryEngine qe = new QueryEngine(file, null);
System.out.println("initialized; enter query");
while(true)
{
String line = in.readLine();
if (line.equals("."))
break;
else
{
long start = System.currentTimeMillis();
qe.processQuery(line, Locale.getDefault(), null);
System.out.println((System.currentTimeMillis()-start)
+" msec search");
}
System.out.println("enter next query or . to quit");
}
}
catch (Exception e) {
e.printStackTrace();
}
}
private class SearchIds {
public int col;
public int concept;
public double score;
public SearchIds (int col, int concept, double score) {
this.col = col;
this.concept = concept;
this.score = score;
}
public String toString() {
return "col=" + col + " concept=" + concept + " score=" + score;
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/ConceptData.java 0000644 0001750 0001750 00000007447 10661201772 026643 0 ustar varun varun /*
* @(#)ConceptData.java 1.6 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 1/13/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
package com.sun.java.help.search;
class ConceptData
{
private final byte _query;
private final byte _nColumns;
private final byte _role;
private final int _concept;
private int _conceptLength;
private final int _proximity;
private final double _penalty;
private ConceptData _next;
private static final int ProxPerTerm = 100;
public ConceptData(int id, int role, double score, int query, int nColumns)
{
_query = (byte)query;
_nColumns = (byte)nColumns;
_concept = id;
_proximity = nColumns * ProxPerTerm;
_role = (byte)role;
_penalty = score;
_next = null;
}
public int getConcept() {
return _concept;
}
public double getPenalty() {
return _penalty;
}
public int getConceptLength() {
return _conceptLength;
}
public byte getRole() {
return _role;
}
public byte getQuery() {
return _query;
}
public byte getNColumns() {
return _nColumns;
}
public double getScore() {
return _penalty;
}
public ConceptData getNext() {
return _next;
}
public int getQueryMask() {
return (_next != null ? _next.getQueryMask() : 0) | (1 << _query);
}
public void setConceptLength(int length)
{
_conceptLength = length;
if (_next != null)
_next.setConceptLength(length);
}
public void setNext(ConceptData next) {
_next = next;
}
boolean cEquals(ConceptData other) {
return _concept == other._concept;
}
boolean crEquals(ConceptData other) {
return _concept == other._concept && _role == other._role;
}
boolean crqEquals(ConceptData other) {
return _concept == other._concept && _role == other._role &&
_query == other._query;
}
void addLast(ConceptData other)
{
if (_next != null)
_next.addLast(other);
else
_next = other;
}
boolean compareWith(ConceptData other) {
return _concept < other._concept
|| cEquals(other) && _role < other._role
|| crEquals(other) && _penalty < other._penalty;
}
public void runBy(Query[] queries)
{
ConceptData cd = this;
do
queries[cd._query].updateEstimate(cd._role, cd._penalty);
while ((cd = cd._next) != null);
}
public void generateFillers(RoleFiller[] array, int pos)
{
if (array[_query] != RoleFiller.STOP) // 'prohibited'
(new RoleFiller(_nColumns, this, _role, pos, pos + _proximity))
.use(array, _query);
if (_next != null)
_next.generateFillers(array, pos);
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/DefaultSearchQuery.java 0000644 0001750 0001750 00000010211 10661201772 030175 0 ustar varun varun /*
* @(#)DefaultSearchQuery.java 1.7 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @(#) DefaultSearchQuery.java 1.7 - last change made 10/30/06
*/
package com.sun.java.help.search;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.Vector;
import java.util.Hashtable;
import java.util.EventListener;
import java.util.Locale;
import javax.help.search.*;
import com.sun.java.help.search.*;
import java.security.InvalidParameterException;
/**
* DefaultSearchQuery is the query using the default search engine.
*
* Search results are returned through SearchEvents to
* listeners that register with this instance.
*
* @author Roger D. Brinkley
* @author Eduardo Pelegri-Llopart
* @version 1.7 10/30/06
*
* @see javax.help.search.SearchEngine
* @see javax.help.search.SearchQuery
* @see javax.help.search.SearchEvent
* @see javax.help.search.SearchListener
*/
public class DefaultSearchQuery extends SearchQuery implements Runnable {
private Thread thread = null;
private DefaultSearchEngine dhs;
/**
* Create a DefaultSearchEngine
*/
public DefaultSearchQuery(SearchEngine hs) {
super(hs);
if (hs instanceof DefaultSearchEngine) {
dhs = (DefaultSearchEngine) hs;
}
}
/**
* Starts the search. The implementation is up to subclasses of SearchEngine.
* This method will invoke searchStarted on SearchListeners.
* @exception IllegalArgumentException The parameters are not
* understood by this engine
* @exception IllegalStateException There is an active search in progress in this instance
*/
public void start(String searchparams, Locale l)
throws IllegalArgumentException, IllegalStateException
{
debug ("Starting Search");
if (isActive()) {
throw new IllegalStateException();
}
// initialization
super.start(searchparams, l);
// Actually do the search
thread = new Thread(this, "QueryThread");
thread.start();
}
/**
* Stops the search. The implementation is up to the subcalsses of
* SearchEngine. This method will invoke searchStopped on
* SearchListeners.
*/
public void stop() throws IllegalArgumentException, IllegalStateException {
debug ("Stop Search");
// Can no longer do a stop
// Let it continue to operate until it's completed
// on it's own. This is due to to the enherent problem
// with thread.stop
}
public boolean isActive() {
if (thread == null) {
return false;
}
return thread.isAlive();
}
public void run() throws IllegalArgumentException{
QueryEngine qe = dhs.getQueryEngine();
try {
qe.processQuery(searchparams, l, this);
} catch (Exception e) {
e.printStackTrace();
throw new IllegalArgumentException();
}
fireSearchFinished();
thread = null;
}
/**
* For printf debugging.
*/
private static final boolean debugFlag = false;
private static void debug(String str) {
if( debugFlag ) {
System.out.println("DefaultSearchQuery: " + str);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/RoleFiller.java 0000644 0001750 0001750 00000013416 10661201772 026506 0 ustar varun varun /*
* @(#)RoleFiller.java 1.6 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 1/13/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
package com.sun.java.help.search;
import java.io.PrintStream;
class RoleFiller
{
static int Threshold = 300;
private ConceptData _conceptData;
private byte _fixedRole;
private short _filled;
private int _begin;
private int _end;
private int _limit;
private RoleFiller _next;
private RoleFiller[] _fillers;
public static final RoleFiller STOP = new RoleFiller();
private RoleFiller() {}
public RoleFiller(int nColumns, ConceptData first, int role,
int pos, int limit)
{
_conceptData = first;
_fixedRole = (byte)role; // primary/constitutive concept/role
_filled = (short)(1 << _fixedRole);
_begin = pos; // offset in file
_end = _begin + first.getConceptLength();
_limit = limit;
_next = null;
_fillers = new RoleFiller[nColumns];
_fillers[role] = this;
}
public void print(PrintStream out) {
out.println(_begin + ", " + _end);
}
void makeQueryHit(Query q, int nColumns, int doc, double penalty)
{
if (q.goodEnough(penalty))
{
int[] array =
q.getConceptArrayOfNewHit(penalty,
new Location(doc, _begin, _end));
for (int i = 0; i < nColumns; i++)
array[i] = (_filled & 1 << i) != 0 ? _fillers[i].getConcept() : 0;
}
}
boolean isHit() {
return _filled > (1 << _fixedRole);
}
double getScore() {
return _conceptData.getScore();
}
int getConcept() {
return _conceptData.getConcept();
}
RoleFiller next() {
return _next;
}
void use(RoleFiller[] place, int index)
{
if (place[index] != null)
{
RoleFiller rf = place[index];
place[index] = this;
_next = rf;
while (rf._limit >= _begin)
{
// check if we can grow/improve a hit
// we don't ever replace filler's fixed role
if (_fixedRole != rf._fixedRole)
{
if ((rf._filled & (1 << _fixedRole)) == 0) // not filled yet
{
rf._filled |= 1 << _fixedRole;
rf._fillers[_fixedRole] = this;
rf._end = _end;
}
else
rf.considerReplacementWith(this);
}
if (rf._next != null)
rf = rf._next;
else
return;
}
}
else
place[index] = this;
}
private void considerReplacementWith(RoleFiller replacement)
{
// !!! simplistic for now
// needs gap and out of order
int role = replacement._fixedRole;
if (replacement.getScore() > _fillers[role].getScore())
_fillers[role] = replacement;
}
private double penalty(Query query, int nColumns)
{
int length = _end - _begin + 1;
double penalty = query.lookupPenalty(_filled);
// !!! here is a chance to check against query if hit worth scoring further
// might not be if query already has lots of good hits
for (int i = 0; i < nColumns; i++)
if ((_filled & (1 << i)) != 0)
{
penalty += _fillers[i]._conceptData.getPenalty();
length -= _fillers[i]._conceptData.getConceptLength() + 1;
if ((_filled >> (i + 1)) != 0)
for (int j = i + 1; j < nColumns; j++)
if ((_filled & 1 << j) != 0 && _fillers[j]._begin < _begin)
penalty += query.getOutOufOrderPenalty();
}
return penalty + length*query.getGapPenalty();
}
public void scoreList(Query query, int document)
{
int nColumns = query.getNColumns();
RoleFiller candidateHit = this; // function called for the head of list
RoleFiller next; // lookahead: if overlap, if so, is it better
// 'candidateHit' always points at the current candidate to be converted to a QueryHit
// 'penalty' is its penalty
// 'next' is used to explore earlier overlapping fillers
// the decision to emit a QueryHit is made when either there's no next
// or next doesn't overlap the current candidate
// the loop's logic makes sure that at emit time there's no better/earlier filler
// to overlap with the candidate
double penalty = candidateHit.penalty(query, nColumns);
for (next = candidateHit._next; next != null; next = next._next)
if (next._end < candidateHit._begin) // no overlap
{
candidateHit.makeQueryHit(query, nColumns, document, penalty);
candidateHit = next;
penalty = candidateHit.penalty(query, nColumns);
}
else
{
// !!! can be computed in two steps
double penalty2 = next.penalty(query, nColumns);
if (penalty2 <= penalty) // prefer next, disregard candidateHit
{
penalty = penalty2;
candidateHit = next;
}
}
candidateHit.makeQueryHit(query, nColumns, document, penalty);
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/RAFFileFactory.java 0000644 0001750 0001750 00000011543 10661201772 027206 0 ustar varun varun /*
* @(#)RAFFileFactory.java 1.27 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @(#) RAFFileFactory.java 1.27 - last change made 10/30/06
*/
package com.sun.java.help.search;
import java.io.*;
import java.net.*;
import java.util.*;
import java.lang.reflect.*;
/**
* A factory for files that can be accessed as Random Access file from a URL.
* RAFFiles can either be an acutall RAF file or a memory version of the
* RAF file. When a URL is it is opened as a RAF file, otherwise it is moved
* to a temporary file if possible or into a memory resident version.
*
*
* @author Roger D. Brinkley
* @version 1.27 10/30/06
*/
class RAFFileFactory {
/**
* Cannot create these, need to go through the factory method
*/
private RAFFileFactory() {
}
static RAFFileFactory theFactory;
public static synchronized RAFFileFactory create() {
if (theFactory == null) {
theFactory = new RAFFileFactory();
}
return theFactory;
}
/* For this connection, when to cache in memory and when to disk */
private int memoryCacheLimit = 10000;
private boolean isFileURL(URL url) {
return url.getProtocol().equalsIgnoreCase("file");
}
public int getMemoryCacheLimit() {
return memoryCacheLimit;
}
public void setMemoryCacheLimit(int limit) {
this.memoryCacheLimit = limit;
}
public synchronized RAFFile get(URL url, boolean update)
throws IOException {
RAFFile result = null;
if (isFileURL(url)) {
try {
String f = url.getFile();
// Normalize the string. This is required because of a
// backwards incompatability change in JDK 1.4.0 and later
// releases.
f = Utilities.URLDecoder(f);
// refactor so it runs with verification on...
// Object o = new FilePermission(f, update ? "write":"read");
// here -- check if AccessController.checkPermission(p);
result = new RAFFile(f, update);
debug ("Opened Dict file with file protocol:" + f);
} catch (SecurityException e) {
// cannot do "it" -- code is not yet in place
}
}
if (result == null) {
result = createLocalRAFFile(url);
}
if (result == null) {
throw new FileNotFoundException(url.toString());
}
return result;
}
/**
* Given a URL, retrieves a DICT file and creates a cached DICT
* file object. If the file is larger than the size limit,
* and if temp files are supported by the Java virtual machine,
* the DICT file is it is cached to disk. Otherwise the DICT file
* is cached in memory.
*/
private static RAFFile createLocalRAFFile(URL url) throws IOException {
RAFFile result = null;
URLConnection connection = url.openConnection();
// We should be able to just do a catch on missing method but
// IE4.0 does not like this
//
// try {
// Object foo = connection.getPermission();
//
// result = RAFFileFactoryOn12.get(connection);
//
// } catch (NoSuchMethodError ex) {
// // on 1.1 all we can do is create a memory file
// result = new MemoryRAFFile(connection);
// debug ("Opening a Dict file in Memory");
// }
//
try {
Class types[] = {};
Method m = URLConnection.class.getMethod("getPermission", types);
result = RAFFileFactoryOn12.get(connection);
} catch (NoSuchMethodError ex) {
// as in JDK1.1
} catch (NoSuchMethodException ex) {
// as in JDK1.1
}
if (result == null) {
// on 1.1 all we can do is create a memory file
result = new MemoryRAFFile(connection);
debug ("Opening a Dict file in Memory");
}
return result;
}
/**
* Debug code
*/
private static final boolean debug = false;
private static void debug(String msg) {
if (debug) {
System.err.println("RAFFileFactory: "+msg);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/BlockFactory.java 0000644 0001750 0001750 00000002476 10661201772 027035 0 ustar varun varun /*
* @(#)BlockFactory.java 1.6 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.java.help.search;
interface BlockFactory
{
public Block makeBlock();
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/Search.java 0000644 0001750 0001750 00000026552 10661201772 025661 0 ustar varun varun /*
* @(#)Search.java 1.17 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 1/13/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
package com.sun.java.help.search;
import java.io.*;
import javax.help.search.SearchQuery;
class Search
{
private static final int InitNConcepts = 128;
private SearchEnvironment _env;
private int _max;
private int _nConcepts;
private int _nQueries;
private ConceptGroupGenerator _firstGenerator = new ConceptGroupGenerator();
private int[] _concepts = new int[DocumentCompressor.NConceptsInGroup];
private int _free2;
private int _size2;
private int _startingIndex = 0;
private int _limit = 0;
private Query[] _query;
private ConceptData[] _conceptData;
private GeneratorHeap _genHeap = new GeneratorHeap();
private int _document;
private byte[] _data = null;
private int _base = 0; // index into _data
private NextDocGeneratorHeap _nextDocGenHeap = new NextDocGeneratorHeap();
private IntegerArray _kTable = new IntegerArray();
private IntegerArray _offsets = new IntegerArray();
private IntegerArray _maxConcepts = new IntegerArray();
private IntegerArray _docConcepts = new IntegerArray();
private IntegerArray _queryMasks = new IntegerArray();
private int _maxHitsToShow = 100;
public Search(SearchEnvironment se, int nColumns)
{
_env = se;
_nQueries = 1;
_query = new Query[_nQueries];
_size2 = InitNConcepts;
_free2 = 0;
_conceptData = new ConceptData[_size2];
_query[0] = new Query(se, nColumns, null);
/*
_query[1] = new Query(se, 3, null);
_query[2] = new Query(se, 3, null);
_query[3] = new Query(se, 3, null);
*/
}
public void addTerm(int col, int concept, double score, int query)
{
if (_env.occursInText(concept))
{
if (_free2 == _size2)
{
ConceptData[] newArray = new ConceptData[_size2 *= 2];
System.arraycopy(_conceptData, 0, newArray, 0, _free2);
_conceptData = newArray;
}
_conceptData[_free2++] =
new ConceptData(concept, col, score, query,
_query[query].getNColumns());
}
}
public void startSearch(SearchQuery searchQuery)
{
// fprintf(stderr, "startSearch: setup\n");
int i, j;
// set up ConceptData lists
// order search terms
quicksort(0, _free2 - 1);
// remove duplicates
for (i = 0; i < _free2 - 1; i = j)
for (j = i + 1; j < _free2; j++)
if (_conceptData[i].crqEquals(_conceptData[j]))
_conceptData[j] = null;
else
i = j;
// create lists
for (i = 0; i < _free2 - 1; i = j)
for (j = i + 1; j < _free2; j++)
if (_conceptData[j] != null)
if (_conceptData[i].cEquals(_conceptData[j]))
{
_conceptData[i].addLast(_conceptData[j]);
_conceptData[j] = null;
}
else
i = j;
// densify
for (i = 0; i < _free2 - 1; i++)
if (_conceptData[i] == null)
for (j = i + 1; j < _free2; j++)
if (_conceptData[j] != null)
{
_conceptData[i] = _conceptData[j];
_conceptData[j] = null;
break;
}
// set up new document generators
_nextDocGenHeap.reset();
for (i = 0; i < _free2 && _conceptData[i] != null; i++)
{
NextDocGenerator gen = new NextDocGenerator(_conceptData[i], _env);
try {
gen.first();
if (gen.getDocument() != NonnegativeIntegerGenerator.END)
{
_conceptData[i].
setConceptLength(_env.
getConceptLength(_conceptData[i].getConcept()));
_nextDocGenHeap.addGenerator(gen);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
_nextDocGenHeap.start();
searchDocument();
if (searchQuery == null) {
printResults(_maxHitsToShow);
} else {
_query[0].makeEvent(_maxHitsToShow, searchQuery);
}
}
private void searchDocument()
{
RoleFiller[] start = new RoleFiller[_nQueries];
do {
try {
switch (nextDocument(start))
{
case 0: // multi group
_genHeap.start(start);
while (_genHeap.next(start))
;
break;
case 1: // single group
if (_firstGenerator.next())
{
_firstGenerator.generateFillers(start);
while (_firstGenerator.next())
_firstGenerator.generateFillers(start);
}
break;
case 2: // reached the end
return;
}
}
catch (Exception e) {
e.printStackTrace(System.err);
continue;
}
for (int i = 0; i < _nQueries; i++)
{
RoleFiller next;
if ((next = start[i]) != null && next != RoleFiller.STOP)
next.scoreList(_query[i], _document);
}
_genHeap.reset();
}
while (_nextDocGenHeap.isNonEmpty());
}
// will be called for increasing values of c
// searches index interval [_startingIndex, _nConcepts]
// saves state in _startingIndex
private int indexOf(int concept) throws Exception
{
int i = _startingIndex, j = _nConcepts, k;
while (i <= j)
if (_concepts[k = (i + j)/2] < concept)
i = k + 1;
else if (concept < _concepts[k])
j = k - 1;
else
{
_startingIndex = k + 1;
return k;
}
throw new Exception("indexOf " + concept + " not found");
}
private void printResults(int nHits)
{
for (int q = 0; q < _nQueries; q++)
{
System.out.println("query " + q);
if (_query[q] != null)
_query[q].printHits(nHits);
}
}
private ConceptGroupGenerator makeGenerator(int group) throws Exception
{
int shift, index;
if (group > 0)
{
index = _base + _offsets.at(group - 1);
shift = _maxConcepts.at(group - 1);
}
else
{
index = _base;
shift = 0;
}
// initialize generator
ConceptGroupGenerator gen =
new ConceptGroupGenerator(_data, index, _kTable.at(2*group + 1));
// decode concept table
_nConcepts = gen.decodeConcepts(_kTable.at(2*group), shift, _concepts);
if (group < _limit)
_max = _concepts[_nConcepts] = _maxConcepts.at(group);
else
_max = _concepts[_nConcepts - 1];
_genHeap.addGenerator(gen);
_startingIndex = 0; // in _concepts; lower search index
return gen;
}
// returns true if multigroup
private boolean openDocumentIndex(int docID) throws Exception
{
// The data is only the data for this document id. Thus the base is set
// to zero.
_data = _env.getPositions(docID);
_base = 0;
_startingIndex = 0;
int kk = _data[_base] & 0xFF, k2;
switch (kk >> 6) // get type
{
case 0: // single group, no extents
k2 = _data[_base + 1];
_firstGenerator.init(_data, _base += 2, k2);
// decode concept table
_nConcepts = _firstGenerator.decodeConcepts(kk & 0x3F, 0, _concepts);
return false;
case 2: // multi group, no extents
_kTable.clear();
_offsets.clear();
_maxConcepts.clear();
ByteArrayDecompressor compr =
new ByteArrayDecompressor(_data, _base + 1);
compr.decode(kk & 0x3F, _kTable);
compr.ascDecode(_kTable.popLast(), _offsets);
compr.ascDecode(_kTable.popLast(), _maxConcepts);
_base += 1 + compr.bytesRead();
_limit = _maxConcepts.cardinality();
return true;
case 1: // single group, extents
case 3: // multi group, extents
throw new Exception("extents not yet implemented\n");
}
return false;
}
private int nextDocument(RoleFiller[] start) throws Exception
{
while (_nextDocGenHeap.isNonEmpty()) // still something to do
{
for (int i = 0; i < _nQueries; i++)
if (_query[i] != null)
_query[i].resetForNextDocument();
// gather all concepts this document has and store associated conceptData
int index = 0;
_document = _nextDocGenHeap.getDocument();
_docConcepts.clear();
_queryMasks.clear();
do {
_docConcepts.add(_nextDocGenHeap.getConcept());
_queryMasks.add(_nextDocGenHeap.getQueryMask());
(_conceptData[index++] = _nextDocGenHeap.getTerms()).runBy(_query);
_nextDocGenHeap.step();
}
while (_nextDocGenHeap.atDocument(_document));
// if there is no saturation model, some query will always vote YES
// and so every document will be opened
// even if this case, however, savings can be achieved by not generating fillers
// for some queries (not scoring, etc)
// and, with more care, creation of some GroupGenerators can be avoided
// saturating queries with lots of good hits will lead to best results
int voteMask = 0;
for (int i = 0; i < _nQueries; i++)
if (_query[i] != null)
if (_query[i].vote())
{
start[i] = null; // normal reset
voteMask |= 1 << i;
}
else
start[i] = RoleFiller.STOP; // prohibit setting
// we may eliminate some ConceptGroupGenerators
// those which would be used only by Queries which voted NO
if (voteMask != 0) // need to open up document
{
ConceptGroupGenerator gen;
// !!! don't gather Fillers for disinterested Queries
if (openDocumentIndex(_document)) // multi group
{
// set up all needed generators
int i = 0;
while ((_queryMasks.at(i) & voteMask) == 0)
++i;
// assert(i < index);
int c = _docConcepts.at(i);
int group = 0;
// find first group
while (c > _maxConcepts.at(group) && ++group < _limit)
;
gen = makeGenerator(group);
gen.addTerms(indexOf(c), _conceptData[i]);
for (++i; i < index; i++)
if ((_queryMasks.at(i) & voteMask) > 0)
{
c = _docConcepts.at(i);
if (c > _max) // need to find another group
{
// assert(group < _limit);
while (c > _maxConcepts.at(group) && ++group < _limit)
;
gen = makeGenerator(group);
}
gen.addTerms(indexOf(c), _conceptData[i]);
}
return 0;
}
else // single group
{
for (int i = 0; i < index; i++)
if ((_queryMasks.at(i) & voteMask) != 0)
_firstGenerator.addTerms(indexOf(_docConcepts.at(i)),
_conceptData[i]);
return 1;
}
}
}
return 2;
}
// part of quicksearch
private int partition(int p, int r)
{
ConceptData x = _conceptData[p];
int i = p - 1, j = r + 1;
while (true)
{
while (x.compareWith(_conceptData[--j]))
;
while (_conceptData[++i].compareWith(x))
;
if (i < j)
{
ConceptData t = _conceptData[i];
_conceptData[i] = _conceptData[j];
_conceptData[j] = t;
}
else
return j;
}
}
private void quicksort(int p, int r)
{
if (p < r)
{
int q = partition(p, r);
quicksort(p, q);
quicksort(q + 1, r);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/Utilities.java 0000644 0001750 0001750 00000003456 10661201772 026425 0 ustar varun varun /*
* @(#)Utilities.java 1.3 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* 1.3 10/30/06
*/
package com.sun.java.help.search;
import java.lang.reflect.Method;
/**
*
* @version 1.3 10/30/06
* @author Roger D. Brinkley
*/
class Utilities
{
public static String URLDecoder (String str) {
String returnStr = str;
try {
Class klass = Class.forName("java.net.URLDecoder");
Class types[] = {String.class};
Method m = klass.getMethod("decode", types);
if (m != null) {
Object args[] = {str};
returnStr = (String)m.invoke(null, args);
}
} catch (Throwable t) {
t.printStackTrace();
}
return returnStr;
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/CompressorIterator.java 0000644 0001750 0001750 00000002664 10661201772 030320 0 ustar varun varun /*
* @(#)CompressorIterator.java 1.6 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 1/13/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
package com.sun.java.help.search;
interface CompressorIterator
{
public void value(int value);
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/Location.java 0000644 0001750 0001750 00000003322 10661201772 026212 0 ustar varun varun /*
* @(#)Location.java 1.6 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 1/13/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
package com.sun.java.help.search;
class Location
{
private final int _docID;
private final int _begin;
private final int _end;
public Location(int doc, int begin, int end)
{
_docID = doc;
_begin = begin;
_end = end;
}
public int getDocument() {
return _docID;
}
public int getBegin() {
return _begin;
}
public int getEnd() {
return _end;
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/QueryHit.java 0000644 0001750 0001750 00000004527 10661201772 026224 0 ustar varun varun /*
* @(#)QueryHit.java 1.6 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 1/13/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
package com.sun.java.help.search;
class QueryHit
{
private int _doc;
private int _begin;
private int _end;
private double _score;
private final int[] _concepts;
public QueryHit(Location loc, double penalty, int nColumns)
{
_score = penalty;
_doc = loc.getDocument();
_begin = loc.getBegin();
_end = loc.getEnd();
_concepts = new int[nColumns];
}
public String toString() {
return "[doc = "+_doc+", "+_begin+", "+_end+", "+_score+"]";
}
public int getDocument() {
return _doc;
}
public int getBegin() {
return _begin;
}
public int getEnd() {
return _end;
}
public double getScore() {
return _score;
}
public int[] getArray() {
return _concepts;
}
public boolean betterThan(QueryHit x)
{
if (_score < x._score) return true;
if (_score > x._score) return false;
if (_begin < x._begin) return true;
if (_begin > x._begin) return false;
if (_end < x._end) return true;
if (_end > x._end) return false;
return false;
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/DBPartParameters.java 0000644 0001750 0001750 00000004067 10661201772 027611 0 ustar varun varun /*
* @(#)DBPartParameters.java 1.6 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @version 1.5 03/18/98
* @author Jacek R. Ambroziak
*/
package com.sun.java.help.search;
import java.util.Hashtable;
import java.net.URL;
public class DBPartParameters
{
protected Schema _schema;
private String _partName;
private Hashtable _parameters;
protected DBPartParameters() {}
public DBPartParameters(Schema schema, String partName)
{
_schema = schema;
_partName = partName;
_parameters = schema.parameters(partName);
}
protected boolean parametersKnown() {
return _parameters != null;
}
protected void updateSchema(String parameters) {
_schema.update(_partName, parameters);
}
public int integerParameter(String name) {
return Integer.parseInt(((String)_parameters.get(name)));
}
public URL getURL() throws Exception {
return _schema.getURL(_partName);
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/RAFFileFactoryOn12.java 0000644 0001750 0001750 00000007155 10661201772 027652 0 ustar varun varun /*
* @(#)RAFFileFactoryOn12.java 1.4 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @(#) RAFFileFactoryOn12.java 1.4 - last change made 10/30/06
*/
package com.sun.java.help.search;
import java.io.*;
import java.net.URLConnection;
import java.security.Permission;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;
import java.security.PrivilegedActionException;
/**
* This Factory assumes we are on JDK 1.2
*/
final public class RAFFileFactoryOn12 {
/**
* Creata a RAFFile from a URLConnection. Try to use a temporary file
* if possible. This is a static public method
*
* @param url The URL with the data to the file
* @return the RAFFile for this data
* @exception IOException if there is problem reading from the file
*/
public static RAFFile get(final URLConnection connection) throws IOException {
RAFFile topBack = null;
debug("get on "+connection);
final Permission permission = connection.getPermission();
/* get the permission after the connection is established */
int dictLength = connection.getContentLength();
try {
topBack = (RAFFile)
AccessController.doPrivileged(new PrivilegedExceptionAction() {
RAFFile back = null;
public Object run() throws IOException {
InputStream in = null;
OutputStream out = null;
try {
File tmpFile = File.createTempFile("dict_cache", null);
tmpFile.deleteOnExit();
if (tmpFile != null) {
in = connection.getInputStream();
out = new FileOutputStream(tmpFile);
int read = 0;
byte[] buf = new byte[BUF_SIZE];
while ((read = in.read(buf)) != -1) {
out.write(buf, 0, read);
}
back = new TemporaryRAFFile(tmpFile, permission);
} else {
back = new MemoryRAFFile(connection);
}
} finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
return back;
}
});
} catch (PrivilegedActionException pae) {
topBack = new MemoryRAFFile(connection);
} catch (SecurityException se) {
topBack = new MemoryRAFFile(connection);
}
return topBack;
}
// The size of the buffer
private static int BUF_SIZE = 2048;
/**
* Debug code
*/
private static final boolean debug = false;
private static void debug(String msg) {
if (debug) {
System.err.println("RAFFileFactoryOn12: "+msg);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/Rule.java 0000644 0001750 0001750 00000017064 10661201772 025361 0 ustar varun varun /*
* @(#)Rule.java 1.3 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @(#) Rule.java 1.3 - last change made 10/30/06
*/
package com.sun.java.help.search;
import java.util.Vector;
import java.util.StringTokenizer;
/**
* A Rule matches a pattern at the right ends of a word, removes an indicated
* number of characters from the end to produce a stem, and generate a list
* of alternative forms of the word by adding each of a specified list of
* endings to the stem.
*
* Each rule specifies an ending pattern and a list
* of endings to be added to the stem to produce different variant forms
* of the input word. The ending pattern consists of a string of letters
* or letter groups separated by spaces to be matched against corresponding
* letters at the end of the word.
*
*
* A letter group (e.g., aeiou) will match any of the letters in the group.
*
* A letter group prefixed with a period (.) may be matched anywhere
* preceding the match of its subsequent letter group. A letter group
* of this type is referred to as "unanchored."
*
* A group that is to be matched at a specified position is "anchored."
*
* A plus sign (+) in the pattern, in place of a letter group, marks the
* point in the pattern after which the matching letters will be removed
* to form the stem. There should be no unanchored letter groups after
* the plus sign, and there should be at most one plus sign in the pattern
* (otherwise only the leftmost will count).
*
* An ampersand (&) in place of
* a letter group in an ending pattern will match a letter that is the same
* as its preceeding letter in the word.
*
* An ampersand in the list of alternative endings indicates a repeat of
* the letter that ends the stem.
*
* An under bar (_) as an alternative ending indicates that nothing is to
* be added to the stem for that alternative.
*
* An ending beginning with an
* asterisk (*) indicates that the rules are to be reapplied recursively to
* the form obtained from using this ending.
*
*
* Rule(s) are grouped in blocks and labeled (usually by a common final
* sequence) and are ordered within each group so that after a matching
* rule is found no further rules are to be tried (except when invoked
* explicitly on a new word by a redo (*) operator in an alternative ending).
*
* @author Roger D. Brinkley
* @author Jacek Ambroziak
* @version 1.3 10/30/06
*
* @see LiteMorph
*/
public class Rule {
private String[] pattern;
private int killnum=0;
private String[] expansions;
private Vector words;
private LiteMorph morph;
/**
* Create a Rule
* @param expression A String representing the ending patern described previously.
* @param expansionString A String of space delimeted expansions as described previously.
*/
public Rule(String expression, String expansionString, LiteMorph morph) {
String chars;
boolean passedPlus = false;
this.morph = morph;
//set up pattern array:
if (expression.length() > 0) {
Vector patternBuffer = new Vector(expression.length());
StringTokenizer temp = new StringTokenizer(expression, " \t\n\r");
while (temp.hasMoreTokens()) {
if (passedPlus) {
// count number of characters after +
killnum++;
}
chars = temp.nextToken();
if (chars.equals("+")) {
passedPlus = true;
} else {
patternBuffer.addElement(chars);
}
}
pattern = new String[patternBuffer.size()];
patternBuffer.copyInto(pattern);
}
else pattern = new String[0];
//set up expansions array:
if (expansionString.length() > 0) {
Vector expansionsBuffer = new Vector(expansionString.length());
StringTokenizer temp = new StringTokenizer(expansionString, ", \t\n\r");
while (temp.hasMoreTokens()) {
expansionsBuffer.addElement(temp.nextToken());
}
expansions = new String[expansionsBuffer.size()];
expansionsBuffer.copyInto(expansions);
}
else {
expansions = new String[0];
}
}
/**
* Determines if a word matches the rule
*/
public String [] match(String word, int depth, int skipnum) {
words = new Vector();
boolean matched = true;
//skipnum positions have already been
//tested by the dispatch method
int position = word.length()-1-skipnum;
int i = pattern.length-1-skipnum;
while (i > -1) {
debug(" trying "+pattern[i]+" at "+position+
" for i = "+i);
// There isn't anything left to test
// the match failed
if (position<0) {
matched = false;
break;
}
//"&" match duplicate of previous letter
if (pattern[i].equals("&")) {
if (position < 1 || word.charAt(position) != word.charAt(position-1)) {
matched = false;
break;
}
else i--;
}
//"." pattern can match anywhere
else if (pattern[i].startsWith(".")) {
if (pattern[i].indexOf(word.charAt(position), 1) >= 0) {
//it matches here, so go to next pattern element
i--;
}
} else if (pattern[i].indexOf(word.charAt(position))<0) {
// doesn't match here
matched = false;
break;
} else {
i--;
}
position--;
}
// All done with the compares. If we've got a match then
// build the list words from the expansion list
if (matched)
{
String stem = word.substring(0, word.length() - killnum);
for (i = 0; i < expansions.length; i++) {
makeForm(stem, expansions[i], depth);
}
}
String[] result = new String[words.size()];
words.copyInto(result);
words = null;
return result;
}
private void makeForm(String stem, String expansion, int depth) {
switch (expansion.charAt(0)) {
case '_':
// just use the stem; nothing to add
words.addElement(stem);
break;
case '&':
// double last letter of stem
words.addElement(stem + stem.charAt(stem.length() - 1) + expansion.substring(1));
break;
case '*':
// redo MorphWord on the resulting form
debug(" starting redo: with "+stem+" + "+expansion+
" from depth "+depth);
if (expansion.charAt(1) == '_')
morph.morphWord(stem, depth + 1);
else
morph.morphWord(stem + expansion.substring(1), depth + 1);
break;
default:
words.addElement(stem + expansion);
break;
}
}
/**
* For printf debugging.
*/
private static final boolean debugFlag = false;
private static void debug(String str) {
if( debugFlag ) {
System.out.println("Rule: " + str);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/GeneratorHeap.java 0000644 0001750 0001750 00000006143 10661201772 027172 0 ustar varun varun /*
* @(#)GeneratorHeap.java 1.6 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 1/13/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
package com.sun.java.help.search;
class GeneratorHeap
{
private static final int InitSize = 128;
private int _heapSize = 0;
private ConceptGroupGenerator[] _heap;
private int _size = InitSize;
private int _free = 0;
public GeneratorHeap() {
_heap = new ConceptGroupGenerator[InitSize];
}
public void reset() {
_free = 0;
}
public void addGenerator(ConceptGroupGenerator gen)
{
if (_free == _size)
{
ConceptGroupGenerator[] newArray =
new ConceptGroupGenerator[_size *= 2];
System.arraycopy(_heap, 0, newArray, 0, _free);
_heap = newArray;
}
_heap[_free++] = gen;
}
private void buildHeap()
{
for (int i = _heapSize/2; i >= 0; i--)
heapify(i);
}
private void heapify(int i)
{
int r = (i + 1) << 1, l = r - 1;
int smallest = l<_heapSize&&_heap[l].position()<_heap[i].position()?l:i;
if (r < _heapSize && _heap[r].position() < _heap[smallest].position())
smallest = r;
if (smallest != i)
{
ConceptGroupGenerator temp = _heap[smallest];
_heap[smallest] = _heap[i];
_heap[i] = temp;
heapify(smallest);
}
}
public boolean start(RoleFiller[] array) throws Exception
{
if ((_heapSize = _free) > 0)
{
for (int i = 0; i < _free; i++)
_heap[i].next();
buildHeap();
_heap[0].generateFillers(array);
return true;
}
else
return false;
}
public boolean next(RoleFiller[] array) throws Exception
{
if (_heapSize > 0)
{
if (!_heap[0].next()) // no more
if (_heapSize > 1)
_heap[0] = _heap[--_heapSize];
else
{
_heapSize = 0;
return false;
}
heapify(0);
_heap[0].generateFillers(array);
return true;
}
else
return false;
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/BlockProcessor.java 0000644 0001750 0001750 00000002512 10661201772 027374 0 ustar varun varun /*
* @(#)BlockProcessor.java 1.6 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.java.help.search;
interface BlockProcessor
{
public void process(Block block);
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/ConceptLocation.java 0000644 0001750 0001750 00000010675 10661201772 027537 0 ustar varun varun /*
* @(#)ConceptLocation.java 1.6 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 3/5/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
package com.sun.java.help.search;
class ConceptLocation
{
private int _concept;
private int _begin;
private int _end;
private abstract class ConceptLocationSorter
{
abstract public boolean smallerThan(ConceptLocation a, ConceptLocation b);
// part of quicksearch
private int partition(ConceptLocation[] array, int p, int r)
{
ConceptLocation x = array[p];
int i = p - 1, j = r + 1;
while (true)
{
while (smallerThan(x, array[--j]))
;
while (smallerThan(array[++i], x))
;
if (i < j)
{
ConceptLocation t = array[i];
array[i] = array[j];
array[j] = t;
}
else
return j;
}
}
public void quicksort(ConceptLocation[] array, int p, int r)
{
if (p < r)
{
int q = partition(array, p, r);
quicksort(array, p, q);
quicksort(array, q + 1, r);
}
}
}
private class ConceptSorter extends ConceptLocationSorter
{
public boolean smallerThan(ConceptLocation a, ConceptLocation b) {
return a._concept < b._concept;
}
}
private class PositionSorter extends ConceptLocationSorter
{
public boolean smallerThan(ConceptLocation a, ConceptLocation b) {
return a._begin < b._begin || a._begin == b._begin && a._end < b._end;
}
}
// sorter by concept ID
private static ConceptLocationSorter _cComp;
// sorter by position
private static ConceptLocationSorter _pComp;
private ConceptLocation()
{
_cComp = new ConceptSorter();
_pComp = new PositionSorter();
}
static { new ConceptLocation(); }
public ConceptLocation(int conceptID, int begin, int end)
{
_concept = conceptID;
_begin = begin;
_end = end;
}
public boolean equals(ConceptLocation other) {
return _concept==other._concept&&_begin==other._begin&&_end==other._end;
}
public void setConcept(int concept) {
_concept = concept;
}
public int getConcept() {
return _concept;
}
public int getBegin() {
return _begin;
}
public int getEnd() {
return _end;
}
public int getLength() {
return _end - _begin;
}
public static void sortByConcept(ConceptLocation[] array, int i1, int i2) {
_cComp.quicksort(array, i1, i2 - 1);
}
public static void sortByPosition(ConceptLocation[] array, int i1, int i2) {
_pComp.quicksort(array, i1, i2 - 1);
}
public void print() {
System.out.println(_concept+"\t"+_begin+"\t"+_end);
}
public static void main(String[] args)
{
int limit = 30, b;
ConceptLocation[] array = new ConceptLocation[limit];
for (int i = 0; i < limit; i++)
array[i] = new ConceptLocation((int)(Math.random()*1000),
b = (int)(Math.random()*1000),
b + (int)(Math.random()*10));
for (int i = 0; i < limit; i++)
array[i].print();
ConceptLocation.sortByConcept(array, 0, limit);
System.out.println("----------------------------------");
for (int i = 0; i < limit; i++)
array[i].print();
ConceptLocation.sortByPosition(array, 0, limit);
System.out.println("----------------------------------");
for (int i = 0; i < limit; i++)
array[i].print();
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/EntryProcessor.java 0000644 0001750 0001750 00000002531 10661201772 027444 0 ustar varun varun /*
* @(#)EntryProcessor.java 1.7 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.java.help.search;
interface EntryProcessor
{
public void processEntry(String string, int id);
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/DefaultSearchEngine.java 0000644 0001750 0001750 00000006157 10661201772 030313 0 ustar varun varun /*
* @(#)DefaultSearchEngine.java 1.21 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @(#) DefaultSearchEngine.java 1.21 - last change made 10/30/06
*/
package com.sun.java.help.search;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.Vector;
import java.util.Hashtable;
import java.util.EventListener;
import java.util.Locale;
import javax.help.search.*;
import com.sun.java.help.search.*;
import java.security.InvalidParameterException;
/**
* DefaultSearchEngine is the default search engine.
*
* Search results are returned through SearchEvents to
* listeners that
* register with a SearchEngine instance through the Search Query.
*
* @author Roger D. Brinkley
* @author Eduardo Pelegri-Llopart
* @version 1.21 10/30/06
*
* @see javax.help.search.SearchEngine
* @see javax.help.search.SearchEvent
* @see javax.help.search.SearchListener
*/
public class DefaultSearchEngine extends SearchEngine {
private String urldata; // just for debugging really
protected QueryEngine qe;
/**
* Create a DefaultSearchEngine
*/
public DefaultSearchEngine(URL base, Hashtable params)
throws InvalidParameterException
{
super(base, params);
debug("Loading Search Database");
debug(" base: "+base);
debug(" params: "+params);
// Load the Query Engine and Search DB here
try {
urldata = (String) params.get("data");
qe = new QueryEngine(urldata, base);
} catch (Exception e) {
if (debugFlag) {
System.err.println(" =========== ");
e.printStackTrace();
}
throw new InvalidParameterException();
}
}
public SearchQuery createQuery() {
return new DefaultSearchQuery(this);
}
protected QueryEngine getQueryEngine() {
return qe;
}
/**
* For printf debugging.
*/
private static final boolean debugFlag = false;
private static void debug(String str) {
if( debugFlag ) {
System.out.println("DefaultSearchEngine: " + str);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/Entry.java 0000644 0001750 0001750 00000003515 10661201772 025547 0 ustar varun varun /*
* @(#)Entry.java 1.7 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.java.help.search;
class Entry
{
public byte[] key;
public int id;
public int block = -1;
public Entry(byte[] key, int length, int id)
{
this.key = new byte[length + 1];
System.arraycopy(key, 0, this.key, 0, length);
this.key[length] = 0;
this.id = id;
}
public byte[] getKey() {
return key;
}
public int getID() {
return id;
}
public boolean smallerThan(Entry other)
{
for (int i = 0; i < Math.min(key.length, other.key.length); i++)
if (key[i] != other.key[i])
return (key[i]&0xFF) - (other.key[i]&0xFF) < 0;
return false;
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/SearchEnvironment.java 0000644 0001750 0001750 00000024651 10661201772 030104 0 ustar varun varun /*
* @(#)SearchEnvironment.java 1.29 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @(#) SearchEnvironment.java 1.11 - last change made 04/19/98
*/
package com.sun.java.help.search;
import javax.help.search.SearchItem;
import java.io.*;
import java.util.Vector; // consider removal
import java.net.URL;
import java.net.URLConnection;
import java.net.MalformedURLException;
import java.util.Locale;
import java.awt.datatransfer.DataFlavor;
import java.lang.reflect.Method;
/**
* This class established a SearchEnvironment for JavaHelp classes
*
* @version 1.11 04/19/98
* @author Jacek R. Ambroziak
* @author Roger D. Brinkley
*/
class SearchEnvironment {
private IntegerArray concepts;
private IntegerArray offsets;
private byte[] allLists;
private IntegerArray concepts3;
private IntegerArray offsets3;
private byte[] allChildren;
private IntegerArray documents;
private IntegerArray offsets2;
private IntegerArray titles;
private RAFFile positionsFile = null;
private byte[] positions;
private ByteArrayDecompressor compr;
private BtreeDict tmap;
private URL base; // the base for all searches
private String indexDir; // the index directory
public SearchEnvironment(String indexDir, URL hsBase) throws Exception {
this.base = hsBase;
this.indexDir = indexDir;
readFromDB();
compr = new ByteArrayDecompressor(null, 0);
}
public int fetch(String conceptName) throws Exception {
return tmap.fetch(conceptName);
}
public String fetch(int conceptID) throws Exception {
return tmap.fetch(conceptID);
}
public SearchItem makeItem(QueryHit hit) throws Exception
{
Vector concepts = new Vector();
int[] conceptIDs = hit.getArray();
for (int i = 0; i < conceptIDs.length; i++) {
if (conceptIDs[i] > 0) {
concepts.addElement(fetch(conceptIDs[i]));
}
}
int begin = hit.getBegin();
int end = hit.getEnd();
return new SearchItem(this.base,
fetch(titles.at(hit.getDocument())),
Locale.getDefault().toString(),
fetch(documents.at(hit.getDocument())),
hit.getScore(),
begin,
end,
concepts);
}
public String hitToString(QueryHit hit) throws Exception
{
StringBuffer result = new StringBuffer();
result.append(hit.getScore());
result.append(" ");
result.append(fetch(documents.at(hit.getDocument())));
if (false) {
result.append(" ");
result.append(fetch(titles.at(hit.getDocument())));
}
result.append(" [");
int begin = hit.getBegin();
int end = hit.getEnd();
result.append(begin);
result.append(", ");
result.append(end);
result.append("], {");
int[] concepts = hit.getArray();
for (int i = 0; i < concepts.length; i++)
{
if (concepts[i] > 0)
result.append(fetch(concepts[i]));
else
result.append("--");
if (i < concepts.length - 1)
result.append(", ");
}
result.append("}");
return result.toString();
}
public byte[] getPositions(int docId) throws java.io.IOException
{
// Later on we should do some caching of this
int offset = offsets2.at(docId);
int upto;
if (docId+1 == offsets2.cardinality()) {
upto = (int)positionsFile.length();
} else {
upto = offsets2.at(docId+1);
}
positions = new byte[upto - offset];
positionsFile.seek(offset);
positionsFile.read(positions, 0, upto - offset);
return positions;
}
public int getDocumentIndex(int docId) {
return offsets2.at(docId);
}
public void close() throws java.io.IOException {
positionsFile.close();
}
public boolean occursInText(int concept) {
return concepts.indexOf(concept) >= 0;
}
public NonnegativeIntegerGenerator getDocumentIterator(int concept)
{
int index = concepts.indexOf(concept);
if (index >= 0)
return new ConceptList(allLists, offsets.at(index));
else
return null;
}
public NonnegativeIntegerGenerator getChildIterator(int concept)
{
int index = concepts3.indexOf(concept);
if (index >= 0)
return new ConceptList(allChildren, offsets3.at(index));
else
return null;
}
public void getChildren(int concept, IntegerArray array) throws Exception
{
int index = concepts3.indexOf(concept);
if (index >= 0)
{
int where = offsets3.at(index);
compr.initReading(allChildren, where + 1);
compr.ascDecode(allChildren[where], array);
}
}
public int getConceptLength(int concept) throws Exception {
return tmap.fetch(concept).length();
}
// A temporary piece of code
// Should be rearranged as soon as possible
private URL getURL(String s) throws MalformedURLException {
URL hsBase = this.base;
String dir = this.indexDir;
URL back;
URL baseURL = null;
File file;
if (hsBase == null) {
file = new File(dir);
if (file.exists()) {
// On Win32 we need to convert all "\" to "/"
if (File.separatorChar != '/') {
dir = dir.replace(File.separatorChar, '/');
}
// Make sure the last character is a file separator
if (dir.lastIndexOf('/')
!= dir.length() - 1) {
dir = dir.concat("/");
}
debug ("file:" + dir);
// Use a file protocol
baseURL = new URL("file", "", dir);
} else {
// Assume that some protocol was specified and try it
baseURL = new URL(dir);
}
}
if (hsBase != null) {
back = new URL(hsBase, dir + "/" + s);
} else {
back = new URL(baseURL, s);
}
return back;
}
private void readChildrenData() throws Exception {
URL url;
URLConnection connect;
BufferedInputStream in;
// Read the Children.Tab data
try {
url = getURL("CHILDREN.TAB");
connect = url.openConnection();
InputStream ois = connect.getInputStream();
if (ois == null) {
concepts3 = new IntegerArray(1);
return;
}
in = new BufferedInputStream(ois);
int k1 = in.read();
concepts3 = new IntegerArray(4096);
StreamDecompressor sddocs = new StreamDecompressor(in);
sddocs.ascDecode(k1, concepts3);
int k2 = in.read();
offsets3 = new IntegerArray(concepts3.cardinality() + 1);
offsets3.add(0);
StreamDecompressor sdoffsets = new StreamDecompressor(in);
sdoffsets.ascDecode(k2, offsets3);
in.close();
// Read the Chilren data
url = getURL("CHILDREN");
connect = url.openConnection();
ois = connect.getInputStream();
if (ois == null) {
concepts3 = new IntegerArray(1);
return;
}
in = new BufferedInputStream(ois);
int length = connect.getContentLength();
allChildren = new byte[length];
in.read(allChildren);
in.close();
} catch (MalformedURLException e) {
concepts3 = new IntegerArray(1);
} catch (FileNotFoundException e2) {
concepts3 = new IntegerArray(1);
} catch (IOException e2) {
concepts3 = new IntegerArray(1);
}
}
private void readFromDB() throws Exception {
URL url;
URLConnection connect;
BufferedInputStream in = null;
Schema schema = new Schema(base, indexDir, false);
BtreeDictParameters params = new BtreeDictParameters(schema, "TMAP");
params.readState();
tmap = new BtreeDict(params);
readChildrenData();
url = getURL("DOCS.TAB");
connect = url.openConnection();
in = new BufferedInputStream(connect.getInputStream());
int k1 = in.read();
concepts = new IntegerArray(4096);
StreamDecompressor sddocs = new StreamDecompressor(in);
sddocs.ascDecode(k1, concepts);
int k2 = in.read();
offsets = new IntegerArray(concepts.cardinality() + 1);
offsets.add(0);
StreamDecompressor sdoffsets = new StreamDecompressor(in);
sdoffsets.ascDecode(k2, offsets);
in.close();
// Read the Lists data
url = getURL("DOCS");
connect = url.openConnection();
in = new BufferedInputStream(connect.getInputStream());
// Note: I'd rather look a the length in the URLConnection
// and read in all the data at once, but it doesn't work on 1.1
ByteArrayOutputStream data = new ByteArrayOutputStream();
byte [] buff = new byte[512];
int i = 0;
while ((i = in.read(buff)) != -1) {
data.write(buff, 0, i);
}
allLists = data.toByteArray();
in.close();
// Read the positions offset data
url = getURL("OFFSETS");
connect = url.openConnection();
in = new BufferedInputStream(connect.getInputStream());
k1 = in.read();
documents = new IntegerArray(4096);
sddocs = new StreamDecompressor(in);
sddocs.ascDecode(k1, documents);
k2 = in.read();
offsets2 = new IntegerArray(documents.cardinality() + 1);
sdoffsets = new StreamDecompressor(in);
sdoffsets.ascDecode(k2, offsets2);
// decompress titles' ids table
int k3 = in.read();
titles = new IntegerArray(documents.cardinality());
StreamDecompressor sdtitles = new StreamDecompressor(in);
sdtitles.decode(k3, titles);
in.close();
// Read in the Positions data
RAFFileFactory factory = RAFFileFactory.create();
url = getURL("POSITIONS");
positionsFile = factory.get(url, false);
}
/**
* For printf debugging.
*/
private static boolean debugFlag = false;
private static void debug(String str) {
if( debugFlag ) {
System.out.println("SearchEnvironment: " + str);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/BitBuffer.java 0000644 0001750 0001750 00000010300 10661201772 026304 0 ustar varun varun /*
* @(#)BitBuffer.java 1.6 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 2/17/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
/*
BitBuffer's client has to stick to a usage protocol:
- start with new or cleared BitBuffer
- do appends for a while
- finish w/ close()
*/
package com.sun.java.help.search;
import java.io.*;
class BitBuffer
{
private static final int InitSize = 256;
private static final int NBits = 32;
private static final int BitsInByte = 8;
private static final int BytesInInt = 4;
private int _avail = NBits;
private int _word = 0;
private int _free = 0;
private int _size = InitSize;
private int[] _array = new int[InitSize];
public void close()
{
if (_avail < NBits)
store(_word << _avail);
else
_avail = 0;
}
public void write(DataOutput out) throws IOException
{
for (int i = 0; i < _free - 1; i++)
out.writeInt(_array[i]);
int word = _array[_free - 1];
int bytes = BytesInInt - _avail/BitsInByte;
int shift = NBits;
while (bytes-- > 0)
out.writeByte((word >>> (shift -= BitsInByte)) & 0xFF);
}
public void clear()
{
_word = 0;
_avail = NBits;
_free = 0;
}
public int byteCount() {
return _free*BytesInInt - _avail/BitsInByte;
}
public int bitCount() {
return NBits*_free - _avail;
}
public void setFrom(BitBuffer rhs)
{
_word = rhs._word;
_avail = rhs._avail;
if ((_free = rhs._free) > _size)
_array = new int[_size = rhs._free];
System.arraycopy(rhs._array, 0, _array, 0, _free);
}
private void growArray(int newSize)
{
int[] newArray = new int[_size = newSize];
System.arraycopy(_array, 0, newArray, 0, _free);
_array = newArray;
}
private void store(int value)
{
if (_free == _size)
growArray(_size * 2);
_array[_free++] = value;
}
public void append(int bit)
{
_word = (_word << 1) | bit;
if (--_avail == 0)
{
store(_word);
_word = 0;
_avail = NBits;
}
}
public void append(int source, int kBits)
{
if (kBits < _avail)
{
_word = (_word << kBits) | source;
_avail -= kBits;
}
else if (kBits > _avail)
{
int leftover = kBits - _avail;
store((_word << _avail) | (source >>> leftover));
_word = source;
_avail = NBits - leftover;
}
else
{
store((_word << kBits) | source);
_word = 0;
_avail = NBits;
}
}
public void concatenate(BitBuffer bb)
{
if (NBits*(_size - _free) + _avail < bb.bitCount())
growArray(_free + bb._free + 1);
if (_avail == 0)
{
System.arraycopy(bb._array, 0, _array, _free, bb._free);
_avail = bb._avail;
_free += bb._free;
}
else
{
int tp = _free - 1; // target
int sp = 0; // source
do {
_array[tp++] |= bb._array[sp] >>> (NBits - _avail);
_array[tp] = bb._array[sp++] << _avail;
}
while (sp < bb._free);
_free += bb._free;
if ((_avail += bb._avail) >= NBits)
{
_avail -= NBits;
_free--;
}
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/Decompressor.java 0000644 0001750 0001750 00000011301 10661201772 027103 0 ustar varun varun /*
* @(#)Decompressor.java 1.7 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 1/13/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
package com.sun.java.help.search;
abstract class Decompressor
{
private static final int BitsInByte = 8;
private static final int NBits = 32;
private int _readByte;
private int _toRead = 0;
private int _path = 0;
abstract protected int getNextByte() throws Exception;
protected void initReading() {
_toRead = 0;
}
private int countZeroes() throws Exception
{
for (int count = 0;; _readByte = getNextByte(), _toRead = BitsInByte)
while (_toRead-- > 0)
if ((_readByte & (1 << _toRead)) != 0)
return count;
else
++count;
}
// reads 1 bit; returns non-0 for bit "1"
private int read() throws Exception
{
if (_toRead-- > 0)
return _readByte & (1 << _toRead);
else
{ // get next word
_toRead = BitsInByte - 1;
return (_readByte = getNextByte()) & 0x80;
}
}
public int read(int kBits) throws Exception
{
int shift = BitsInByte - _toRead;
if (kBits <= _toRead)
return ((_readByte<>> (shift + (_toRead-=kBits));
else
{
int result = _toRead > 0
? ((_readByte << shift) & 0xFF) >>> shift
: 0;
for (kBits -= _toRead; kBits >= BitsInByte; kBits -= BitsInByte)
result = (result << BitsInByte) | getNextByte();
if (kBits > 0)
return (result << kBits)
| ((_readByte = getNextByte()) >>> (_toRead = BitsInByte - kBits));
else
{
_toRead = 0;
return result;
}
}
}
public void beginIteration() {
_path = 0;
}
public boolean readNext(int k, CompressorIterator it) throws Exception
{
if (read() != 0)
{
it.value(_path | read(k));
return true;
}
else
for (int count = 1;; _readByte = getNextByte(), _toRead = BitsInByte)
while (_toRead-- > 0)
if ((_readByte & (1 << _toRead)) != 0)
{
int saved = _path;
_path = ((_path >>> (k + count) << count) | read(count)) << k;
if (_path != saved)
{
it.value(_path | read(k));
return true;
}
else
return false;
}
else
++count;
}
public void decode(int k, IntegerArray array) throws Exception
{
for (int path = 0;;)
if (read() != 0)
array.add(path | read(k));
else
{
int count = countZeroes() + 1;
int saved = path;
path = ((path >>> (k + count) << count) | read(count)) << k;
if (path != saved) // convention for end
array.add(path | read(k));
else
break;
}
}
public void ascDecode(int k, IntegerArray array) throws Exception
{
for (int path = 0, start = 0;;)
if (read() != 0)
array.add(start += path | read(k));
else
{
int count = countZeroes() + 1;
int saved = path;
path = ((path >>> (k + count) << count) | read(count)) << k;
if (path != saved) // convention for end
array.add(start += path | read(k));
else
break;
}
}
public int ascendingDecode(int k, int start, int[] array) throws Exception
{
int path = 0, index = 0;
LOOP:
while (true)
if (read() != 0)
array[index++] = (start += path | read(k));
else
for (int cnt = 0;; _readByte = getNextByte(), _toRead = BitsInByte)
while (_toRead-- > 0)
if ((_readByte & (1 << _toRead)) != 0)
{
++cnt;
int Path = ((path >>> (k + cnt) << cnt) | read(cnt)) << k;
if (Path != path)
{
array[index++] = (start += (path = Path) | read(k));
continue LOOP;
}
else
return index;
}
else
++cnt;
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/HitStore.java 0000644 0001750 0001750 00000014276 10661201772 026215 0 ustar varun varun /*
* @(#)HitStore.java 1.7 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 1/13/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
package com.sun.java.help.search;
import java.util.Vector;
class HitStoreNode
{
private int _free = 0;
private int _size;
private QueryHit[] _array;
private int _hitCount = 0;
private double _divider = 0.0;
private double _min = 10000000.0;
private double _max = 0.0;
private HitStoreNode[] _children = new HitStoreNode[2]; // left & right
private int _index = 0;
public HitStoreNode(int size) {
_array = new QueryHit[_size = size];
}
public QueryHit getNextHit() {
return _index < _free ? _array[_index++] : null;
}
private void fastAdd(QueryHit hit)
{
_hitCount++;
_divider += hit.getScore();
if (hit.getScore() > _max)
_max = hit.getScore();
if (hit.getScore() < _min)
_min = hit.getScore();
_array[_free++] = hit;
}
public boolean add(QueryHit hit)
{
if (_array != null)
{
if (_free < _size)
{
fastAdd(hit);
return false;
}
else if (_min != _max)
{
split();
_hitCount++;
_children[hit.getScore() > _divider ? 1 : 0].fastAdd(hit);
return true;
}
else
{
QueryHit[] newArray = new QueryHit[_size *= 2];
System.arraycopy(_array, 0, newArray, 0, _free);
_array = newArray;
fastAdd(hit);
return true;
}
}
else
{
_hitCount++;
return _children[hit.getScore() > _divider ? 1 : 0].add(hit);
}
}
private void split()
{
_children[0] = new HitStoreNode(_size);
_children[1] = new HitStoreNode(_size);
_divider /= _hitCount; // becomes average
for (int i = 0; i < _free; i++)
_children[_array[i].getScore() > _divider ? 1 : 0].fastAdd(_array[i]);
_array = null; // becomes internal
}
public int getCount() {
return _hitCount;
}
public double getDivider() {
return _divider;
}
public HitStoreNode getLChild() {
return _children[0];
}
public HitStoreNode getRChild() {
return _children[1];
}
public void setLChild(HitStoreNode node) {
_children[0] = node;
}
public void setRChild(HitStoreNode node) {
_children[1] = node;
}
public void decrementCount(int delta) {
_hitCount -= delta;
}
public boolean isLeaf() {
return _array != null;
}
public void sort() {
quicksort(0, _free - 1);
}
public void gatherLeaves(Vector vector)
{
if (isLeaf())
vector.addElement(this);
else
{
getLChild().gatherLeaves(vector);
getRChild().gatherLeaves(vector);
}
}
// part of quicksearch
private int partition(int p, int r)
{
QueryHit x = _array[p];
int i = p - 1, j = r + 1;
while (true)
{
while (x.betterThan(_array[--j]))
;
while (_array[++i].betterThan(x))
;
if (i < j)
{
QueryHit t = _array[i];
_array[i] = _array[j];
_array[j] = t;
}
else
return j;
}
}
private void quicksort(int p, int r)
{
if (p < r)
{
int q = partition(p, r);
quicksort(p, q);
quicksort(q + 1, r);
}
}
}
class HitStore
{
private static final int ArraySize = 128;
private static final int DefaultLimit = 300;
private HitStoreNode _root = new HitStoreNode(ArraySize);
private int _limit;
private double _standard;
private Vector _leaves = null;
private HitStoreNode _current = null;
public HitStore(double initialStandard) {
this(initialStandard, DefaultLimit);
}
public HitStore(double initialStandard, int limit)
{
_limit = limit;
_standard = initialStandard;
}
public void addQueryHit(QueryHit hit) {
if(_root.add(hit))
adapt();
}
private HitStoreNode getNextNode()
{
if (_leaves.size() > 0)
{
HitStoreNode node = (HitStoreNode)_leaves.firstElement();
_leaves.removeElementAt(0);
node.sort();
return node;
}
else
return null;
}
public QueryHit firstBestQueryHit()
{
_leaves = new Vector();
_root.gatherLeaves(_leaves);
_current = getNextNode();
return _current.getNextHit();
}
public QueryHit nextBestQueryHit()
{
QueryHit result = _current.getNextHit();
if (result != null)
return result;
else if ((_current = getNextNode()) != null)
return _current.getNextHit();
else
return null;
}
double getCurrentStandard() {
return _standard;
}
private void adapt()
{
if (_root.getCount() > _limit)
if (!_root.isLeaf())
{
HitStoreNode ptr = _root;
// find rightmost internal
while (!ptr.getRChild().isLeaf())
ptr = ptr.getRChild();
_standard = ptr.getDivider();
if (ptr == _root)
_root = ptr.getLChild();
else
{
int count = ptr.getRChild().getCount();
HitStoreNode ptr2 = _root;
while (ptr2.getRChild() != ptr)
{
ptr2.decrementCount(count);
ptr2 = ptr2.getRChild();
}
ptr2.setRChild(ptr.getLChild());
}
ptr.setLChild(null);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/client/com/sun/java/help/search/NonnegativeIntegerGenerator.java 0000644 0001750 0001750 00000002763 10661201772 032114 0 ustar varun varun /*
* @(#)NonnegativeIntegerGenerator.java 1.6 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 1/13/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
package com.sun.java.help.search;
interface NonnegativeIntegerGenerator
{
int END = -1;
int first() throws Exception;
int next() throws Exception;
}
javahelp2-2.0.05/jhMaster/JSearch/client/GNUmakefile 0000644 0001750 0001750 00000003174 10661201772 021155 0 ustar varun varun #
# @(#)GNUmakefile 1.8 06/10/30
#
# Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun in the LICENSE file that accompanied this code.
#
# This code 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 General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
CLIENT_SRC := $(shell find . -name 'SCCS*' -prune -o -name '*.java' -print)
CLIENT_CLASSES=$(CLIENT_SRC:%.java=classes/%.class)
RM=/bin/rm
jar: ../lib/jsearch-client.jar
../lib/jsearch-client.jar: $(CLIENT_CLASSES)
cd classes ; \
jar cf ../../lib/jsearch-client.jar com
classes/%.class: %.java classes
export CLASSPATH ; CLASSPATH=../lib/jsearch-misc.jar:. ; \
javac -d classes $<
classes:
mkdir classes
clean:
$(RM) -rf classes
javahelp2-2.0.05/jhMaster/JSearch/GNUmakefile 0000644 0001750 0001750 00000004706 10661201772 017701 0 ustar varun varun #
# @(#)GNUmakefile 1.31 06/10/30
#
# Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun in the LICENSE file that accompanied this code.
#
# This code 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 General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
# This is a bare-bones Makefile just to build the engine from scratch.
#
# It should be replaced by a real Makefile.
TOP := $(shell pwd)
ifeq ($(JHHOMEWS),)
TOP=$(shell pwd)
JHHOMEWS=$(TOP)/../JavaHelp
endif
CP=/bin/cp -f
PKG = com/sun/java/help/search
JARS = lib/jsearch-misc.jar \
lib/jsearch-client.jar \
lib/jsearch-indexer.jar \
lib/jsearch.jar
all: lib ${JARS} binaries demos
clean:
rm -rf lib
cd client ; $(MAKE) clean
cd indexer ; $(MAKE) clean
cd misc ; $(MAKE) clean
# simple scripts
binaries: jhindexer jhsearch
- chmod a+x jhindexer
- chmod a+x jhsearch
# a test case
demos: demos/holidays
demos/holidays:
mkdir -p demos/holidays
cd demos/holidays ; export to ; to=`pwd` ; \
cd ${JHHOMEWS}/demos/hs/holidays ; \
tar cFFf - hol | ( cd $${to} ; tar xvf - )
## JAR files
lib/jsearch.jar: lib/jsearch-client.jar lib/jsearch-indexer.jar lib/jsearch-misc.jar
/bin/csh -f jarinto FORCE lib/jsearch.jar \
lib/jsearch-client.jar lib/jsearch-indexer.jar lib/jsearch-misc.jar
lib/jsearch-misc.jar: FORCE
cd misc ; $(MAKE) JHHOMEWS=$(JHHOMEWS) jar
lib/jsearch-client.jar: lib/jsearch-misc.jar FORCE
cd client ; $(MAKE) jar
lib/jsearch-indexer.jar: lib/jsearch-misc.jar FORCE
cd indexer ; $(MAKE) jar
## Directories
lib:
mkdir -p lib
FORCE:
javahelp2-2.0.05/jhMaster/JSearch/jhsearch.bat 0000644 0001750 0001750 00000003103 10661201772 020074 0 ustar varun varun @echo off
REM
REM @(#)jhsearch.bat 1.5 06/10/30
REM
REM Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
REM DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
REM
REM This code is free software; you can redistribute it and/or modify it
REM under the terms of the GNU General Public License version 2 only, as
REM published by the Free Software Foundation. Sun designates this
REM particular file as subject to the "Classpath" exception as provided
REM by Sun in the LICENSE file that accompanied this code.
REM
REM This code is distributed in the hope that it will be useful, but WITHOUT
REM ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
REM FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
REM version 2 for more details (a copy is included in the LICENSE file that
REM accompanied this code).
REM
REM You should have received a copy of the GNU General Public License version
REM 2 along with this work; if not, write to the Free Software Foundation,
REM Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
REM
REM Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
REM CA 95054 USA or visit www.sun.com if you need additional information or
REM have any questions.
REM
rem Run the JHSearch
rem @(#)jhsearch.bat 1.3 07/14/98
if ."%JSHOME%".==."". goto nojhhome
goto runnit
:nojhhome
echo The environment variable JSHOME has not been set
goto done
echo
:runnit
@echo on
set CLASSPATH=%JSHOME%\lib\jsearch.jar
java com.sun.java.help.search.QueryEngine %1
@echo off
:done
javahelp2-2.0.05/jhMaster/JSearch/indexer/ 0000755 0001750 0001750 00000000000 11220022253 017241 5 ustar varun varun javahelp2-2.0.05/jhMaster/JSearch/indexer/com/ 0000755 0001750 0001750 00000000000 11220022253 020017 5 ustar varun varun javahelp2-2.0.05/jhMaster/JSearch/indexer/com/sun/ 0000755 0001750 0001750 00000000000 11220022253 020624 5 ustar varun varun javahelp2-2.0.05/jhMaster/JSearch/indexer/com/sun/java/ 0000755 0001750 0001750 00000000000 11220022253 021545 5 ustar varun varun javahelp2-2.0.05/jhMaster/JSearch/indexer/com/sun/java/help/ 0000755 0001750 0001750 00000000000 11220022253 022475 5 ustar varun varun javahelp2-2.0.05/jhMaster/JSearch/indexer/com/sun/java/help/search/ 0000755 0001750 0001750 00000000000 11220022253 023742 5 ustar varun varun javahelp2-2.0.05/jhMaster/JSearch/indexer/com/sun/java/help/search/DefaultIndexerKit.java 0000644 0001750 0001750 00000013126 10661201770 030176 0 ustar varun varun /*
* @(#)DefaultIndexerKit.java 1.17 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @(#) DefaultIndexerKit.java 1.17 - last change made 10/30/06
*/
package com.sun.java.help.search;
import java.io.*;
import java.util.Locale;
import java.text.*;
import javax.help.search.IndexerKit;
import javax.help.search.IndexBuilder;
import javax.help.search.ConfigFile;
/**
* This is the set of things needed by an indexing object
* to be a reasonably functioning indexer for some type
* of text document. This implementation provides a default
* implementation which treats text as plain text
*
* @author Roger D. Brinkley
* @version %I %G
*/
public class DefaultIndexerKit extends IndexerKit {
protected boolean documentStarted;
public DefaultIndexerKit() {
locale = Locale.getDefault();
}
/**
* Creates a copy of the indexer kit. This
* allows an implementation to serve as a prototype
* for others, so that they can be quickly created.
*
* @return the copy
*/
public Object clone() {
return new DefaultIndexerKit();
}
/**
* Gets the MIME type of the data that this
* kit represents support for. The default
* is text/plain.
*
* @return the type
*/
public String getContentType() {
return "";
}
/**
* Inserts content from the given stream, which will be
* treated as plain text.
*
* @param in The stream to read from
* @param file The file name being parsed
* @param ignoreCharset Ignore the CharacterSet when parsing
* @param builder The IndexBuilder for the full text insertion.
* @param config The indexer configuration information
* @exception IOException on any I/O error
*/
public void parse(Reader in, String file, boolean ignoreCharset,
IndexBuilder builder,
ConfigFile config) throws IOException
{
debug ("parsing " + file);
// Do nothing in the default implementation
}
public int parseIntoTokens (String source, int pos) {
BreakIterator boundary;
int start;
String word;
int currentPos = pos;
try {
boundary = BreakIterator.getWordInstance(locale);
boundary.setText(source);
start = boundary.first();
for (int end = boundary.next();
end != BreakIterator.DONE;
start = end, end = boundary.next()) {
word = new String(source.substring(start,end));
word = word.trim();
word = word.toLowerCase(locale);
if (word.length() > 1) {
storeToken(word, currentPos + start);
} else if (word.length() == 1) {
int charType = Character.getType(word.charAt(0));
if ((charType == Character.DECIMAL_DIGIT_NUMBER) ||
(charType == Character.LETTER_NUMBER) ||
(charType == Character.LOWERCASE_LETTER) ||
(charType == Character.OTHER_LETTER) ||
(charType == Character.OTHER_NUMBER) ||
(charType == Character.TITLECASE_LETTER) ||
(charType == Character.UNASSIGNED) ||
(charType == Character.UPPERCASE_LETTER)) {
storeToken (word, currentPos + start);
}
}
}
currentPos += source.length();
}
catch (Exception e) {
e.printStackTrace();
}
return currentPos;
}
protected void startStoreDocument (String file) throws Exception {
if ((config == null) || (builder == null)) {
throw new Exception("ConfigFile and/or IndexBuilder not set");
}
builder.openDocument(config.getURLString(file));
}
protected void endStoreDocument () throws Exception {
if ((config == null) || (builder == null)) {
throw new Exception("ConfigFile and/or IndexBuilder not set");
}
builder.closeDocument();
}
protected void storeToken (String token, int pos) throws Exception {
if ((config == null) || (builder == null)) {
throw new Exception("ConfigFile and/or IndexBuilder not set");
}
if (!documentStarted) {
try {
startStoreDocument(file);
documentStarted = true;
} catch (Exception e) {
if (debugFlag) e.printStackTrace();
throw new IOException("Can't store Document");
}
}
builder.storeLocation(token, pos);
}
protected void storeTitle (String title) throws Exception {
if ((config == null) || (builder == null)) {
throw new Exception("ConfigFile and/or IndexBuilder not set");
}
builder.storeTitle(title);
}
/**
* Debug code
*/
private boolean debugFlag=false;
private void debug(String msg) {
if (debugFlag) {
System.err.println("DefaultIndexKit: "+msg);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/indexer/com/sun/java/help/search/FullBtreeDict.java 0000644 0001750 0001750 00000032573 10661201770 027322 0 ustar varun varun /*
* @(#)FullBtreeDict.java 1.15 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 2/20/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
package com.sun.java.help.search;
import java.io.*; // debugging in main
import java.util.*; // debugging in main
public class FullBtreeDict extends BtreeDict
{
protected BtreeDictParameters params;
private boolean update = false;
private final class Entry
{
public byte[] key;
public int id;
public int block = -1;
public Entry(byte[] key, int length, int id)
{
this.key = new byte[length + 1];
System.arraycopy(key, 0, this.key, 0, length);
this.key[length] = 0;
this.id = id;
}
public boolean smallerThan(Entry other)
{
for (int i = 0; i < Math.min(key.length, other.key.length); i++)
if (key[i] != other.key[i])
return (key[i]&0xFF) < (other.key[i]&0xFF);
return false;
}
}
// end of internal class
protected class FullDictBlock extends DictBlock
{
public void setFree(int free)
{
this.free = free - firstEntry();
this.data[free] = this.data[free + 1] = 0; // sentinel
}
public void setNumberOfEntries(int n) {
setIntegerAt(0, n);
}
protected void setChildIndex(int index, int value) {
setIntegerAt(4*(lastPtrIndex - index + 1), value);
}
public void setEntryID(int i, int id) {
setIntegerAt(i + 2, id);
}
// finds the place and context
private boolean insert(Entry entry)
{
byte[] inkey = entry.key;
final int inputKeyLen = inkey.length - 1;
final int freeSpace = free();
int entryPtr = firstEntry();
int nCharsEqual = 0;
int prevNCEqual = 0;
int compression = 0;
for (int entryIndex = 0;;)
{
if (entryPtr == freeSpace)
return insert(entry, entryPtr, nCharsEqual, 0, numberOfEntries());
else if (compression == nCharsEqual)
{
int keyLen = entryKeyLength(entryPtr);
int keyPtr = entryKey(entryPtr), i;
prevNCEqual = nCharsEqual;
for (i = 0;
i < keyLen && inkey[nCharsEqual] == data[keyPtr + i];
i++)
++nCharsEqual;
if (i == keyLen)
{
if (nCharsEqual == inputKeyLen)
{
setEntryID(entryPtr, entry.id);
return true;
}
}
else if ((inkey[nCharsEqual]&0xFF) < (data[keyPtr + i]&0xFF))
return insert(entry, entryPtr, prevNCEqual, nCharsEqual,
entryIndex);
}
else if (compression < nCharsEqual) // compression dropped
return insert(entry, entryPtr, nCharsEqual, compression,
entryPtr == freeSpace
? numberOfEntries() : entryIndex);
do {
entryPtr = nextEntry(entryPtr);
++entryIndex;
}
while (entryCompression(entryPtr) > nCharsEqual);
compression = entryCompression(entryPtr);
}
}
public void makeEntry(int entry, byte[] key, int id, int length, int compr)
{
data[entry] = (byte) length;
data[entry + 1] = (byte) compr;
setEntryID(entry, id);
System.arraycopy(key, compr, data, entryKey(entry), length);
}
private boolean insert(Entry ent, final int entryPtr,
final int compr1, final int compr2,
final int index)
{
final byte[] key = ent.key;
final int keyLen = key.length - 1 - compr1;
final int freeSpace = free();
// calculate how much space is needed to add the new entry
// first, how many bytes are needed for just the new entry
final int demand = ENTHEADERLEN + keyLen;
// adding an entry can increase compression in the following entry
int increase = 0;
if (entryPtr < freeSpace)
if (entryCompression(entryPtr) < compr2)
increase = compr2 - entryCompression(entryPtr);
/*
System.err.println("key " + key);
System.err.println("entryPtr " + entryPtr);
System.err.println("compr1 " + compr1);
System.err.println("compr2 " + compr2);
System.err.println("index " + index);
System.err.println("demand " + demand);
System.err.println("increase " + increase);
*/
// check if enough space is available
int limit = isLeaf ? DATALEN-2 : 4*(lastPtrIndex-numberOfEntries()-1);
if (freeSpace + demand - increase <= limit)// 2 for sentinel
{
if (entryPtr < freeSpace)
{
// need to shift extant entries forward
final int toMove = increase > 0
? entryPtr + ENTHEADERLEN + increase
: entryPtr;
// move entries
System.arraycopy(data, toMove,
data, toMove + demand - increase,
freeSpace - toMove);
if (increase > 0)
{
// update header
data[entryPtr] -= increase;
data[entryPtr + 1] += increase;
// shift header
System.arraycopy(data, entryPtr,
data, entryPtr + demand, ENTHEADERLEN);
}
}
// now write the new entry in the space made above
makeEntry(entryPtr, key, ent.id, keyLen, compr1);
if (isLeaf == false)
{
int from = 4*(lastPtrIndex - numberOfEntries() + 1);
System.arraycopy(data, from, data, from - 4,
4*(numberOfEntries() - index));
setChildIndex(index + 1, ent.block);
}
setFree(freeSpace + demand - increase);
setNumberOfEntries(numberOfEntries() + 1);
/*
System.err.println("------------list--------------");
byte[] buffer = new byte[MaxKeyLength];
final int freeSpace2 = free();
int entryPtr2 = firstEntry();
while (entryPtr2 < freeSpace2)
{
System.err.println(entryPtr2);
System.err.println(entryKeyLength(entryPtr2));
System.err.println(entryCompression(entryPtr2));
System.err.println(new String(data,
entryKey(entryPtr2),
entryKeyLength(entryPtr2)));
System.err.println(restoreKey(entryPtr2, buffer)+" "+
entryID(entryPtr2));
entryPtr2 = nextEntry(entryPtr2);
}
System.err.println("------------end--------------");
*/
return true;
}
else
return false;
}
public int insertInternal(Entry entry)
{
byte[] inkey = entry.key;
final int inputKeyLen = inkey.length - 1;
int entryPtr = firstEntry();
final int freeSpace = free();
int nCharsEqual = 0;
int compression = 0;
for (int entryIndex = 0;;)
{
if (entryPtr == freeSpace)
return numberOfEntries();
else if (compression == nCharsEqual)
{
int i;
int keyLen = entryKeyLength(entryPtr);
int keyPtr = entryKey(entryPtr);
for (i = 0;
i < keyLen && inkey[nCharsEqual] == data[keyPtr + i];
i++)
++nCharsEqual;
if (i == keyLen)
{
if (nCharsEqual == inputKeyLen)
{
setEntryID(entryPtr, entry.id);
return -1;
}
}
else if ((inkey[nCharsEqual]&0xFF) < (data[keyPtr + i]&0xFF))
return entryIndex;
}
else if (compression < nCharsEqual) // compression dropped
return entryPtr >= freeSpace ? numberOfEntries() : entryIndex;
do {
entryPtr = nextEntry(entryPtr);
++entryIndex;
}
while (entryCompression(entryPtr) > nCharsEqual);
compression = entryCompression(entryPtr);
}
}
private Entry split(FullDictBlock newbl)
{
byte[] buffer = new byte[MaxKeyLength];
int freeSpace = free();
int half = freeSpace/2;
int index = 0; // of middle entry
newbl.isLeaf = isLeaf;
int ent;
for (ent = firstEntry(); ent < half; ent = nextEntry(ent))
{
restoreKeyInBuffer(ent, buffer);
++index;
}
final int entriesToMove = numberOfEntries() - index - 1;
// middle entry
restoreKeyInBuffer(ent, buffer);
int len = entryKeyLength(ent) + entryCompression(ent);
Entry result = new Entry(buffer, len, entryID(ent));
result.block = newbl.number;
int newFree = ent;
// rest goes to the new block
ent = nextEntry(ent);
restoreKeyInBuffer(ent, buffer);
len = entryKeyLength(ent) + entryCompression(ent);
int nptr = firstEntry();
newbl.makeEntry(nptr, buffer, entryID(ent), len, 0);
ent = nextEntry(ent);
System.arraycopy(data, ent,
newbl.data, newbl.nextEntry(nptr), freeSpace - ent);
newbl.setNumberOfEntries(entriesToMove);
newbl.setFree(newbl.nextEntry(nptr) + freeSpace - ent);
if (isLeaf == false) // need to split pointers
{
int from = 4*(lastPtrIndex - numberOfEntries() + 1);
System.arraycopy(data, from,
newbl.data, from + 4*(index + 1),
4*(entriesToMove + 1));
}
// this entry will end here
setFree(newFree);
setNumberOfEntries(index);
return result;
//!!!remember updating ID -> string association
}
public void initInternal(int leftBlock, Entry entry)
{
isLeaf = false;
setNumberOfEntries(1);
setChildIndex(0, leftBlock);
setChildIndex(1, entry.block);
final int ent = firstEntry();
makeEntry(ent, entry.key, entry.id, entry.key.length - 1, 0);
setFree(nextEntry(ent));
}
}
// end of internal class
protected FullBtreeDict() {/*empty*/}
public FullBtreeDict(BtreeDictParameters params, boolean update)
throws Exception
{
init(params, update, new BlockFactory() {
public Block makeBlock() { return new FullDictBlock(); }
});
blocks = new int[300000]; // !!!
this.params = params;
this.update = update;
}
public void close(int freeID) throws Exception
{
params.setFreeID(freeID);
if (update)
params.updateSchema();
super.close();
}
public void store(String key, int id) throws Exception
{
// System.err.println("storing "+key+" id "+id);
byte[] bytes = key.getBytes("UTF8");
Entry entry = insert((FullDictBlock)accessBlock(root),
new Entry(bytes, bytes.length, id));
if (entry != null)
{
// new root; writing to params needed
FullDictBlock nbl = getNewBlock();
nbl.initInternal(root, entry);
blocks[entry.id] = root = nbl.number;
params.setRoot(root);
}
}
private void setModified(Block bl) {
blockManager.setModified(bl.number);
}
private FullDictBlock getNewBlock() throws Exception
{
FullDictBlock nbl = (FullDictBlock)blockManager.getNewBlock();
setModified(nbl);
return nbl;
}
/*
delegation to powerful primitives at the FullDictBlock level lets us
express the insertion algorithm very succintly here
*/
private Entry insert(FullDictBlock bl, Entry ent) throws Exception
{
if (bl.isLeaf)
return insertHere(bl, ent);
else
{
int index = bl.insertInternal(ent);
if (index != -1)
try {
lock(bl);
ent = insert((FullDictBlock)child(bl, index), ent);
return ent == null ? null : insertHere(bl, ent);
}
finally {
unlock(bl);
}
else
return null;
}
}
private Entry insertHere(FullDictBlock bl, Entry ent) throws Exception
{
setModified(bl); // to be modified in any case
if (bl.insert(ent))
return null;
else
{
FullDictBlock nbl = getNewBlock();
Entry middle = bl.split(nbl);
nbl.setBlockNumbers(blocks);
if ((middle.smallerThan(ent) ? nbl : bl).insert(ent) == false)
throw new Exception("entry didn't fit into a freshly split block");
return middle;
}
}
public static void main(String[] args)
{
try {
Schema schema = new Schema(null, args[0], true);
BtreeDictParameters tmapParams = new BtreeDictParameters(schema, "TMAP");
if (tmapParams.readState() == false)
{
tmapParams.setBlockSize(2048);
tmapParams.setRoot(0);
tmapParams.setFreeID(1);
}
FullBtreeDict dict = new FullBtreeDict(tmapParams, true);
int freeID = tmapParams.getFreeID();
LineNumberReader in = new LineNumberReader(new BufferedReader
(new FileReader(args[1])));
String line;
while ((line = in.readLine()) != null)
{
StringTokenizer tokens = new StringTokenizer(line, " ");
while (tokens.hasMoreTokens())
{
String token = tokens.nextToken();
if (token.equals("storing"))
dict.store(tokens.nextToken(), freeID++);
else if (token.equals("fetching"))
dict.fetch(tokens.nextToken());
}
}
in.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
* Debug code
*/
private boolean debug=false;
private void debug(String msg) {
if (debug) {
System.err.println("FullBtreeDict: "+msg);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/indexer/com/sun/java/help/search/package.html 0000644 0001750 0001750 00000003426 10661201770 026243 0 ustar varun varun
Implementation classes for the default Search builder using in the
reference implementation of JavaHelp.
Note:We have not yet finalized the location for these classes.
Related Documentation
For overviews, tutorials, examples, guides, tool support,
and other documentation,
please see
the JavaHelp home page
javahelp2-2.0.05/jhMaster/JSearch/indexer/com/sun/java/help/search/DocumentLists.java 0000644 0001750 0001750 00000020412 10661201770 027414 0 ustar varun varun /*
* @(#)DocumentLists.java 1.7 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 3/10/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
package com.sun.java.help.search;
import java.io.*;
class DocumentLists
{
private static final int RANGE = 1024;
private static final int NConcepts = 16;
private static final int K = 3;
private final IntegerArray[] _arrays = new IntegerArray[RANGE];
private int _minConcept = 0;
private int _limit = RANGE;
private final IntegerArray _concepts = new IntegerArray();
private final IntegerArray _offsets = new IntegerArray();
private final Compressor _compr = new Compressor();
private final IntegerArray _diffs = new IntegerArray();
private final ByteArrayDecompressor _decmp =
new ByteArrayDecompressor(null, 0);
private DataOutputStream _mainFile;
// heap
private int _heapSize = 0;
private MicroIndex[] _heap;
private class MicroIndex
{
private int _currentRange;
private final int _documentNumber;
private int[] _concepts = new int[NConcepts + 1];
private short _group;
private short _ix;
private IntegerArray _kTable = new IntegerArray();
private IntegerArray _offsets = new IntegerArray();
private IntegerArray _maxConcepts = new IntegerArray();
private byte[] _data;
private int _base;
private int _limit;
private int _nc;
public MicroIndex(int documentNumber, byte[] positions, int index)
throws Exception
{
_documentNumber = documentNumber;
_data = positions;
_base = index;
openDocumentIndex();
}
public boolean smallerThan(MicroIndex other)
{
return _currentRange < other._currentRange ||
_currentRange == other._currentRange &&
_documentNumber < other._documentNumber;
}
private boolean next() throws Exception
{
if (_group <= _limit)
{
int shift, index;
if (_group > 0)
{
index = _base + _offsets.at(_group - 1);
shift = _maxConcepts.at(_group - 1);
}
else
{
index = _base;
shift = 0;
}
_decmp.initReading(_data, index);
_nc = _decmp.ascendingDecode(_kTable.at(_group*2), shift, _concepts);
if (_group < _limit)
_concepts[_nc++] = _maxConcepts.at(_group);
_currentRange = _concepts[_ix = 0]/RANGE;
_group++;
return true;
}
else
return false;
}
private void openDocumentIndex() throws Exception
{
int kk = _data[_base] & 0xFF;
switch (kk >> 6) // get type
{
case 0: // single group, no extents
_decmp.initReading(_data, _base += 2);
_nc = _decmp.ascendingDecode(kk & 0x3F, 0, _concepts);
_currentRange = _concepts[_ix = 0]/RANGE;
_limit = 0;
_group = 1;
break;
case 2: // multi group, no extents
_decmp.initReading(_data, _base + 1);
_decmp.decode(kk & 0x3F, _kTable);
_decmp.ascDecode(_kTable.popLast(), _offsets);
_decmp.ascDecode(_kTable.popLast(), _maxConcepts);
_base += 1 + _decmp.bytesRead();
_limit = _maxConcepts.cardinality();
_group = 0;
next();
break;
case 1: // single group, extents
case 3: // multi group, extents
System.err.println("extents not yet implemented\n");
break;
}
}
public boolean process(DocumentLists lists) throws Exception
{
boolean firstTime = true;
while (true)
{
short stop = lists.process(_documentNumber, _concepts, _nc, _ix,
firstTime);
if (stop < _nc)
{
_currentRange = _concepts[_ix = stop]/RANGE;
return true;
}
else if (next())
firstTime = false;
else
return false;
}
}
}
private DocumentLists(String indexDir) throws Exception
{
for (int i = 0; i < RANGE; i++)
_arrays[i] = new IntegerArray();
_mainFile = new DataOutputStream
(new BufferedOutputStream
(new FileOutputStream(indexDir + "DOCS")));
// main work
InputStream file =
new BufferedInputStream(new FileInputStream(indexDir + "OFFSETS"));
int k1 = file.read();
IntegerArray array = new IntegerArray(4096);
StreamDecompressor documents = new StreamDecompressor(file);
documents.ascDecode(k1, array);
int k2 = file.read();
IntegerArray offsetArray = new IntegerArray(array.cardinality() + 1);
StreamDecompressor offsets = new StreamDecompressor(file);
offsets.ascDecode(k2, offsetArray);
file.close();
File listsFile = new File(indexDir + "POSITIONS");
byte[] positions = new byte[(int)listsFile.length()];
FileInputStream in = new FileInputStream(listsFile);
in.read(positions);
in.close();
// build heap
_heap = new MicroIndex[_heapSize = array.cardinality()];
for (int i = 0; i < array.cardinality(); i++)
_heap[i] = new MicroIndex(i, positions, offsetArray.at(i));
debug(array.cardinality() + " documents");
for (int i = _heapSize/2; i >= 0; i--)
heapify(i);
// process till exhausted
while (true)
if (_heap[0].process(this))
heapify(0);
else if (_heapSize > 1)
{
_heap[0] = _heap[--_heapSize];
heapify(0);
}
else
break;
// closing
flush();
_mainFile.close();
// compress index file
DataOutputStream indexFile = new DataOutputStream
(new BufferedOutputStream
(new FileOutputStream(indexDir + "DOCS.TAB")));
indexFile.write(_compr.compressAscending(_concepts)); // write k
_compr.write(indexFile);
_compr.clear();
indexFile.write(_compr.minimize(_offsets, K)); // write k
_compr.write(indexFile);
indexFile.close();
}
public short process(int documentNumber, int[] concepts, int n, short start,
boolean firstTime)
throws IOException
{
if (firstTime && concepts[start] >= _limit)
flush();
concepts[n] = _limit; // sentinel
while (concepts[start] < _limit)
_arrays[concepts[start++] - _minConcept].add(documentNumber);
return start;
}
private void heapify(int i)
{
int r = (i + 1) << 1, l = r - 1;
int smallest = l < _heapSize && _heap[l].smallerThan(_heap[i]) ? l : i;
if (r < _heapSize && _heap[r].smallerThan(_heap[smallest]))
smallest = r;
if (smallest != i)
{
MicroIndex temp = _heap[smallest];
_heap[smallest] = _heap[i];
_heap[i] = temp;
heapify(smallest);
}
}
private void flush() throws IOException
{
for (int i = 0; i < RANGE; i++)
if (_arrays[i].cardinality() > 0)
{
_arrays[i].toDifferences(_diffs);
_mainFile.write(_compr.minimize(_diffs, K)); // write k
_offsets.add(_compr.byteCount() + 1);
_compr.write(_mainFile);
_concepts.add(_minConcept + i);
_arrays[i].clear();
_diffs.clear();
_compr.clear();
}
_limit += RANGE;
_minConcept += RANGE;
}
public static void invert(String indexDir) throws Exception {
new DocumentLists(indexDir);
}
public static void main(String[] args)
{
String indexDir = args[0];
try {
new DocumentLists(indexDir);
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
* Debug code
*/
private boolean debug=false;
private void debug(String msg) {
if (debug) {
System.err.println("DocumentLists: "+msg);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/indexer/com/sun/java/help/search/PlainTextIndexerKit.java 0000644 0001750 0001750 00000007411 10661201770 030522 0 ustar varun varun /*
* @(#)PlainTextIndexerKit.java 1.3 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @(#) PlainTextIndexerKit.java 1.3 - last change made 10/30/06
*/
package com.sun.java.help.search;
import java.io.*;
import java.util.Locale;
import java.text.*;
import javax.help.search.IndexerKit;
import javax.help.search.IndexBuilder;
import javax.help.search.ConfigFile;
/**
* This is the set of things needed by an indexing object
* to be a reasonably functioning indexer for some type
* of text document. This implementation provides a default
* implementation which treats text as plain text
*
* @author Roger D. Brinkley
* @version %I %G
*/
public class PlainTextIndexerKit extends DefaultIndexerKit {
public PlainTextIndexerKit() {
locale = Locale.getDefault();
}
/**
* Creates a copy of the indexer kit. This
* allows an implementation to serve as a prototype
* for others, so that they can be quickly created.
*
* @return the copy
*/
public Object clone() {
return new PlainTextIndexerKit();
}
/**
* Gets the MIME type of the data that this
* kit represents support for. The default
* is text/plain.
*
* @return the type
*/
public String getContentType() {
return "text/plain";
}
/**
* Inserts content from the given stream, which will be
* treated as plain text.
*
* @param in The stream to read from
* @param file The file name being parsed
* @param ignoreCharset Ignore the CharacterSet when parsing
* @param builder The IndexBuilder for the full text insertion.
* @param config The indexer configuration information
* @exception IOException on any I/O error
*/
public void parse(Reader in, String file, boolean ignoreCharset,
IndexBuilder builder,
ConfigFile config) throws IOException
{
debug ("parsing " + file);
this.builder = builder;
this.config = config;
this.file = file;
documentStarted = false;
int currentPos = 1;
char[] buff = new char[4096];
int nch;
while ((nch = in.read(buff, 0, buff.length)) != -1) {
currentPos = parseIntoTokens(new String(buff), currentPos);
}
try {
storeTitle("No Title");
endStoreDocument();
} catch (Exception e2) {
throw new IOException("Can't store title");
}
this.builder = null;
this.config = null;
}
/**
* Debug code
*/
private boolean debugFlag=false;
private void debug(String msg) {
if (debugFlag) {
System.err.println("PlainTextIndexerKit: "+msg);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/indexer/com/sun/java/help/search/BtreeDictCompactor.java 0000644 0001750 0001750 00000017533 10661201770 030346 0 ustar varun varun /*
* @(#)BtreeDictCompactor.java 1.9 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 5/1/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
package com.sun.java.help.search;
import java.net.URL;
public class BtreeDictCompactor extends FullBtreeDict
{
private CompactorDictBlock _currentLeaf;
private byte[] _lastKey = new byte[MaxKeyLength];
private int _lastKeyLength = 0;
private int _limit;
private int _nEntries = 0;
private int _entry = 0;
private int _counter = 0;
private InternalBlockState _parent = null;
private final class CompactorDictBlock extends FullDictBlock
{
private int restoreKey1(int entry, byte[] buffer)
{
int howMany = entryKeyLength(entry);
int where = entryCompression(entry);
int from = entryKey(entry);
while (howMany-- > 0)
buffer[where++] = data[from++];
return where;
}
protected void doMap1(BtreeDictCompactor owner, BtreeDictCompactor target)
throws Exception
{
byte[] buffer = new byte[MaxKeyLength];
final int freeSpace = free();
int entry = firstEntry();
if (isLeaf)
while (entry < freeSpace) {
target.store(buffer, restoreKey1(entry, buffer), entryID(entry));
entry = nextEntry(entry);
}
else
{
owner.lock(this);
int entryIndex = 0;
while (entry < freeSpace) {
owner.accessBlock1(getChildIdx(entryIndex)).doMap1(owner,target);
target.store(buffer, restoreKey1(entry, buffer), entryID(entry));
entry = nextEntry(entry);
++entryIndex;
}
owner.accessBlock1(getChildIdx(entryIndex)).doMap1(owner, target);
owner.unlock(this);
}
}
} // end of internal class
private final class InternalBlockState
{
private CompactorDictBlock _block;
private byte[] _lastKey = new byte[MaxKeyLength];
private int _lastKeyLength;
private int _entry;
private int _nEntries;
private int _limit;
private InternalBlockState _parent;
public InternalBlockState(int leftChild)
{
debug("NEW ROOT " + _counter);
debug(params.toString());
params.setRoot(_counter);
_block = new CompactorDictBlock();
_block.isLeaf = false;
_block.setBlockNumber(_counter++);
init(leftChild);
}
private void init(int leftChild)
{
_entry = _block.firstEntry();
_nEntries = 0;
_lastKeyLength = 0;
_limit = 4*(lastPtrIndex - 1);
_block.setChildIndex(0, leftChild);
}
public void store(byte[] buffer, int keyLen, int id, int newBlock)
{
// System.out.println(new String(buffer, 0, keyLen) + " " + id);
int cpr = 0;
while (cpr < _lastKeyLength && _lastKey[cpr] == buffer[cpr])
++cpr;
int needed = ENTHEADERLEN + keyLen - cpr;
if (_entry + needed <= _limit)
{
_block.makeEntry(_entry, buffer, id, keyLen - cpr, cpr);
_entry += needed;
_nEntries++;
_block.setChildIndex(_nEntries, newBlock);
_limit -= 4;
_lastKeyLength = keyLen;
System.arraycopy(buffer, cpr, _lastKey, cpr, keyLen - cpr);
}
else
{
debug("NEW: SPLIT INTERNAL");
_block.setFree(_entry);
_block.setNumberOfEntries(_nEntries);
if (_parent == null)
_parent = new InternalBlockState(_block.number);
_parent.store(buffer, keyLen, id, newBlock(_block));
init(newBlock);
}
}
public void close() throws java.io.IOException
{
_block.setFree(_entry);
_block.setNumberOfEntries(_nEntries);
blockManager.writeBlock(_block);
if (_parent == null)
debug("root: " + _block.number);
else
_parent.close();
}
} // end of internal class
public BtreeDictCompactor(BtreeDictParameters params, boolean update)
throws Exception
{
init(params, update, new BlockFactory() {
public Block makeBlock() { return new CompactorDictBlock(); }
});
_currentLeaf = new CompactorDictBlock();
_currentLeaf.setBlockNumber(_counter++);
_limit = DATALEN - 2;
_entry = _currentLeaf.firstEntry();
this.params = params;
}
protected CompactorDictBlock accessBlock1(int index) throws Exception {
return (CompactorDictBlock)blockManager.accessBlock(index);
}
public void store(byte[] buffer, int keyLen, int id)
{
// System.out.println(new String(buffer, 0, keyLen));
if (id > 0)
{
int cpr = 0;
while (cpr < _lastKeyLength && _lastKey[cpr] == buffer[cpr])
++cpr;
int needed = ENTHEADERLEN + keyLen - cpr;
if (_entry + needed <= _limit)
{
_currentLeaf.makeEntry(_entry, buffer, id, keyLen - cpr, cpr);
_entry += needed;
_nEntries++;
_lastKeyLength = keyLen;
System.arraycopy(buffer, cpr, _lastKey, cpr, keyLen - cpr);
}
else
{
_currentLeaf.setFree(_entry);
_currentLeaf.setNumberOfEntries(_nEntries);
if (_parent == null)
_parent = new InternalBlockState(_currentLeaf.number);
_parent.store(buffer, keyLen, id, newBlock(_currentLeaf));
_entry = _currentLeaf.firstEntry();
_nEntries = 0;
_lastKeyLength = 0;
}
}
}
private int newBlock(DictBlock block)
{
int number = _counter++;
try {
blockManager.writeBlock(block); // write out full
block.setBlockNumber(number); // recycle
blockManager.writeBlock(block); // reserve space for new
}
catch (java.io.IOException e) {
e.printStackTrace();
}
return number;
}
public void close() throws java.io.IOException
{
_currentLeaf.setFree(_entry);
_currentLeaf.setNumberOfEntries(_nEntries);
blockManager.writeBlock(_currentLeaf);
if (_parent == null)
debug("root: " + _currentLeaf.number);
else
_parent.close();
blockManager.close();
}
public void compact(BtreeDictParameters params) throws Exception
{
final BtreeDictCompactor target = new BtreeDictCompactor(params, true);
((CompactorDictBlock)blockManager.accessBlock(root)).doMap1(this, target);
target.close();
blockManager.close();
}
public static void main(String[] args)
{
try {
Schema schema = new Schema(null, args[0], false);
BtreeDictParameters params = new BtreeDictParameters(schema, "TMAP");
BtreeDictCompactor source = new BtreeDictCompactor(params, false);
URL url = new URL("file", "", args[1]);
BtreeDictParameters params2 = new BtreeDictParameters(url, 2048, 0, 24);
source.compact(params2);
}
catch (Exception e) {
System.err.println(e);
e.printStackTrace();
}
}
/**
* Debug code
*/
private boolean debug=false;
private void debug(String msg) {
if (debug) {
System.err.println("BtreeDictCompactor: "+msg);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/indexer/com/sun/java/help/search/DefaultIndexBuilder.java 0000644 0001750 0001750 00000015751 10661201770 030514 0 ustar varun varun /*
* @(#)DefaultIndexBuilder.java 1.23 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @date 3/13/98
* @author Jacek R. Ambroziak
* @group Sun Microsystems Laboratories
*/
package com.sun.java.help.search;
import java.net.URL;
import java.io.*;
import java.util.Hashtable;
import java.util.Enumeration;
import javax.help.search.IndexBuilder;
public class DefaultIndexBuilder extends IndexBuilder
{
private static int InitSize = 4096;
private FullBtreeDict dict;
protected Hashtable cache = new Hashtable(15000);
private DocumentCompressor compr;
private int free = 0;
private int size = InitSize;
private ConceptLocation[] locations = new ConceptLocation[size];
private int freeID;
private int currentDocID = 0;
private Schema _schema;
private BtreeDictParameters _tmapParams;
private int _title = 0;
public DefaultIndexBuilder(String indexDir) throws Exception
{
super (indexDir);
// temporary code to disable incremental updates
removeExistingFiles(indexDir);
_schema = new Schema(null, indexDir, true);
_tmapParams = new BtreeDictParameters(_schema, "TMAP");
if (_tmapParams.readState() == false)
{
_tmapParams.setBlockSize(2048);
_tmapParams.setRoot(0);
_tmapParams.setFreeID(1);
}
URL url = new URL("file", "", indexDir);
/*
try {
params = BtreeDictParameters.read(indexDir, null);
} catch (java.io.FileNotFoundException e) {
params = BtreeDictParameters.create(url);
}
*/
dict = new FullBtreeDict(_tmapParams, true);
freeID = _tmapParams.getFreeID();
compr = new DocumentCompressor(url);
}
// temporary until Jacek incorporates stop words into IndexBuilder
private Hashtable tmpstopWords = new Hashtable();
public void storeStopWords(Enumeration stopWords) {
for (; stopWords.hasMoreElements() ;) {
String word = (String) stopWords.nextElement();
// temporarily keep the list here until Jacek finishes adding
// stop words to indexes
tmpstopWords.put(word, word);
}
}
public Enumeration getStopWords() {
// For now the stop words are not stored in the index
// Jacek will change this when he supports stop words in indexes
return null;
}
// temporary code until Jacek provides support for stop words in indexes
private boolean isStopWord(String word) {
return tmpstopWords.get(word) != null;
}
public void close() throws Exception
{
dict.close(freeID);
_tmapParams.setFreeID(freeID);
_tmapParams.updateSchema();
debug("compacting...");
BtreeDictCompactor source = new BtreeDictCompactor(_tmapParams, false);
URL url = new URL("file", "", indexDir + "compacted");
BtreeDictParameters params =
new BtreeDictParameters(url, _tmapParams.getBlockSize(), 0, freeID);
source.compact(params);
URL tmapURL = new URL("file", "", indexDir + "TMAP");
File tmap = new File(Utilities.URLDecoder(tmapURL.getFile()));
tmap.delete();
File compacted = new File(Utilities.URLDecoder(url.getFile()));
compacted.renameTo(tmap);
_tmapParams.setRoot(params.getRootPosition());
_tmapParams.updateSchema();
debug("freeID is " + freeID);
compr.close(indexDir + "OFFSETS");
debug("inverting index");
DocumentLists.invert(indexDir);
_schema.save();
}
public void openDocument(String name) throws Exception
{
if (currentDocID != 0) {
throw new Exception("document already open");
}
currentDocID = intern(name);
}
public void closeDocument() throws Exception
{
if (currentDocID == 0) {
throw new Exception("no document open");
}
compr.compress(currentDocID, _title, locations, free, null, 0);
free = 0;
currentDocID = 0; // state: nothing open
_title = 0;
}
public void storeLocation(String text, int position) throws Exception
{
// next line is temporary until Jacek provides support for stop words in
// indexes
if (isStopWord(text)) return;
if (free == size) {
ConceptLocation[] newArray = new ConceptLocation[size *= 2];
System.arraycopy(locations, 0, newArray, 0, free);
locations = newArray;
}
locations[free++] = new ConceptLocation(intern(text),
position,
position + text.length());
}
public void storeTitle(String title) throws Exception
{
_title = intern(title);
}
private int intern(String name) throws Exception
{
Integer cached = (Integer)cache.get(name);
if (cached != null)
return cached.intValue();
else
{
int id = dict.fetch(name);
if (id == 0) {
dict.store(name, id = freeID++);
}
cache.put(name, new Integer(id));
return id;
}
}
/**
* Temporary code to remove existing files
* remove when updates actually works
*/
private void removeExistingFiles(String indexDir) {
File test = new File(indexDir);
try {
if (test.exists()) {
try {
File tmap = new File(test, "TMAP");
tmap.delete();
} catch (java.lang.NullPointerException te) {
}
try {
File docs = new File(test, "DOCS");
docs.delete();
} catch (java.lang.NullPointerException de) {
}
try {
File docstab = new File(test, "DOCS.TAB");
docstab.delete();
} catch (java.lang.NullPointerException dte) {
}
try {
File offsets = new File(test, "OFFSETS");
offsets.delete();
} catch (java.lang.NullPointerException oe) {
}
try {
File positions = new File(test, "POSITIONS");
positions.delete();
} catch (java.lang.NullPointerException pe) {
}
try {
File schema = new File(test, "SCHEMA");
schema.delete();
} catch (java.lang.NullPointerException se) {
}
}
} catch (java.lang.SecurityException e) {
}
}
/**
* Debug code
*/
private boolean debug = false;
private void debug(String msg) {
if (debug) {
System.err.println("DefaultIndexBuilder: "+msg);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/indexer/com/sun/java/help/search/Indexer.java 0000644 0001750 0001750 00000041206 10661201770 026221 0 ustar varun varun /*
* @(#)Indexer.java 1.46 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @(#) Indexer.java 1.46 - last change made 10/30/06
*/
package com.sun.java.help.search;
import java.io.*;
import java.text.*;
import java.net.*;
import java.util.Vector;
import java.util.Hashtable;
import java.util.Locale;
import javax.help.search.IndexerKit;
import javax.help.search.ConfigFile;
import com.sun.java.help.impl.HeaderParser;
/**
* This class provides ...
*
*
* @version 1.46 10/30/06
* @author Roger D. Brinkley
*/
public class Indexer {
/** The database directory name. */
String dbName = "JavaHelpSearch";
/** The stream for printing syntax errors */
PrintStream verbose=null;
PrintStream logStream=null;
/** The number of documents correctly parsed and compiled. */
short docNumber;
private DefaultIndexBuilder indexBuilder = null;
private ConfigFile config;
private String title;
private String header;
private boolean firstHeader=false;
String lastPCdata;
int currentPos;
boolean openTagSeen = false;
boolean inPre = false;
boolean inTitle = false;
boolean inFirstHeader = false;
boolean inOption = false;
int inBlock = 0;
String sourcepath;
/**
* Starts the application.
* @param args[] the command line arguments
**/
public static void main(String args[]) {
Indexer compiler = new Indexer();
try {
compiler.compile(args);
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
* Creates an initialised compiler.
**/
public Indexer() {
// Make sure the last character is a file separator
if (dbName.lastIndexOf("/")
!= dbName.length() - 1) {
dbName = dbName.concat("/");
}
docNumber = 0;
}
/**
* Parses the .html files, and compiles the search database.
* @param args[] the command line arguments
**/
public void compile(String args[]) throws Exception {
long parseTime, compileTime, startTime = System.currentTimeMillis();
int words;
String configFile = null;
Vector tmpfiles = new Vector();
Vector files = new Vector();
String file;
int size;
sourcepath="";
boolean nostopwords = false;
for (int i=0; i < args.length ; i++) {
if(args[i].equals("-db")) {
if ((i + 1) < args.length) {
dbName = args[++i];
// Make sure the last character is a file separator
if (dbName.lastIndexOf("/")
!= dbName.length() - 1) {
dbName = dbName.concat("/");
}
} else {
System.out.println (args[i] + "-db requires argument");
}
}
else if(args[i].equals("-sourcepath")) {
if ((i + 1) < args.length) {
sourcepath = args[++i];
} else {
System.out.println (args[i] + "-sourcepath requires argument");
}
}
else if(args[i].equals("-locale")) {
if ((i + 1) < args.length) {
defaultLang= args[++i];
} else {
System.out.println (args[i] + "-locale requires argument");
}
}
else if(args[i].equals("-logfile")) {
if ((i + 1) < args.length) {
String logFile= args[++i];
try {
logStream = new PrintStream(new FileOutputStream(logFile)
,true);
System.setErr(logStream);
System.setOut(logStream);
verbose = logStream;
} catch (java.io.FileNotFoundException ex) {
System.out.println("Couldn't create logFile " + logFile);
}
} else {
System.out.println (args[i] + "-logfile requires argument");
}
}
else if(args[i].equals("-verbose")) verbose = System.out;
else if(args[i].equals("-nostopwords")) nostopwords = true;
else if(args[i].equals("-c")) {
if ((i + 1) < args.length) {
configFile = args[++i];
} else {
System.out.println (args[i] + "-c requires argument");
}
}
else if(args[i].startsWith("-")) {
System.out.println("Unknown argument '" + args[i] + "'");
showUsage();
return;
} else {
tmpfiles.addElement(args[i]);
}
}
// read the config file
config = new ConfigFile (configFile, files, nostopwords);
// get the files from the config file
files = config.getFiles();
// adjust the passed with config parameters
size = tmpfiles.size();
for (int i=0; i < size; i++) {
files = loadFiles ((String)tmpfiles.elementAt(i), files);
}
size = files.size();
if (size == 0) {
System.out.println("No files specified to index");
showUsage();
return;
}
indexBuilder= new DefaultIndexBuilder(dbName);
// set the stopwords in the indexBuilder
indexBuilder.storeStopWords(config.getStopWords());
for (int i=0; i < size; i++) {
file = (String) files.elementAt(i);
URL url = new URL("file", "", sourcepath+file);
InputStream in = url.openStream();
URLConnection conn = url.openConnection();
String type = conn.getContentType();
setContentType(type);
if (kit != null) {
try {
if (verbose != null) {
verbose.println(" File: '" + file + "'");
verbose.println(" URL: '" + config.getURLString(file) + "'");
}
parseFile(in, file, false);
in.close();
} catch (UnsupportedEncodingException e1) {
System.out.println("File: '" + file + "' encoding " +
charSetName + " not supported");
in.close();
continue;
} catch (IOException e) {
if (debugFlag) e.printStackTrace();
System.out.println("I/O exception occurred in file '" + sourcepath+file + "'");
in.close();
continue;
}
}
}
parseTime = System.currentTimeMillis() - startTime;
// show some final statistics
compileTime = System.currentTimeMillis() - startTime - parseTime;
if (verbose != null) {
verbose.println(" Parse time: " + (float)parseTime / 1000.0 + " s");
}
indexBuilder.close();
}
/**
* This method invokes the indexerKit to initiate parsing. In the
* case where a ChangedCharSetException is thrown this exception
* will contain the new CharSet. Therefore the parse() operation
* is then restarted after building a new Reader with the new charset.
*
* @param the inputstream to use.
* @param the document to load.
*
*/
void parseFile(InputStream in, String file, boolean ignoreCharset) throws IOException {
try {
kit.parse(new InputStreamReader(in, charSetName), file,
ignoreCharset, indexBuilder, config);
} catch (com.sun.java.help.search.ChangedCharSetException e1) {
String charSetSpec = e1.getCharSetSpec();
if (e1.keyEqualsCharSet()) {
charSetName = charSetSpec;
} else {
setCharsetFromContentTypeParameters(charSetSpec);
}
in.close();
URL url = new URL("file", "", sourcepath+file);
in = url.openStream();
parseFile(in, file, true);
}
}
public Vector loadFiles (String file, Vector files) {
File tstfile = new File (file);
if (tstfile.isDirectory()) {
String list[] = tstfile.list();
for (int i=0; i < list.length; i++) {
files = loadFiles (tstfile.getPath() +
File.separator +
list[i], files);
}
} else {
files.addElement(file);
}
return files;
}
/**
* Shows the usage message.
**/
public void showUsage() {
System.out.println(" Usage: java JavaHelp.Index options file ...");
System.out.println(" Options: -c file config file");
System.out.println(" -db file generated database file name");
System.out.println(" -verbose verbose documentation");
System.out.println(" -nostopwords ignore stop words");
System.out.println(" -locale language_country_variant");
System.out.println(" -logfile log file name");
System.out.println("Note: config file composition:");
System.out.println(" IndexRemove /public_html/JavaHelp/demo");
System.out.println(" IndexPrepend ..");
System.out.println(" StopWords word1 ... wordN");
System.out.println(" StopWordsFile stopWordFileName");
System.out.println(" File /public_html/JavaHelp/demo/first.html");
System.out.println(" File=/public_html/JavaHelp/demo/second.html");
System.out.println(" ...");
}
/**
* Current content binding of the indexer.
*/
private IndexerKit kit;
/**
* Table of registered type handlers for this indexer.
*/
private Hashtable typeHandlers;
private String defaultCharSetName = "ISO8859_1";
private String charSetName;
private String defaultLang = Locale.getDefault().toString();
private String lang;
/*
* Private AppContext keys for this class's static variables.
*/
private static final Hashtable kitRegistry = new Hashtable();
private static final Hashtable kitTypeRegistry = new Hashtable();
private static final Hashtable kitLoaderRegistry = new Hashtable();
static {
// set the default bindings
registerIndexerKitForContentType("text/plain",
"com.sun.java.help.search.PlainTextIndexerKit",
null);
registerIndexerKitForContentType("text/html",
"com.sun.java.help.search.HTMLIndexerKit",
null);
}
/**
* Sets the type of content for the current document that this indexer
* handles. This calls getIndexerKitForContentType.
*
* If there is a charset definition specified as a parameter
* of the content type specification, it will be used when
* loading input streams using the associated IndexerKit.
* For example if the type is specified as
* text/html; charset=EUC-JP the content
* will be loaded using the IndexerKit registered for
* text/html and the Reader provided to
* the IndexerKit to load unicode into the document will
* use the EUC-JP charset for translating
* to unicode.
*
* @param type the non-null mime type for the content editing
* support.
*/
public final void setContentType(String type) {
// Set a charSetName to default incase it isn't defined
charSetName = defaultCharSetName;
// Set the lang to default lang incase it isn't defined
lang = defaultLang;
debug ("type=" + type);
// The type could have optional info is part of it,
// for example some charset info. We need to strip that
// of and save it.
int parm = type.indexOf(";");
if (parm > -1) {
// Save the paramList.
String paramList = type.substring(parm);
// update the content type string.
type = type.substring(0, parm).trim();
// Set the charset name from the paramlist
setCharsetFromContentTypeParameters(paramList);
}
if ((kit == null) || (! type.equals(kit.getContentType()))) {
IndexerKit k = getIndexerKitForContentType(type);
if (k != null) {
kit = k;
}
}
kit.setLocale(lang);
}
/**
* This method get's the charset information specified as part
* of the content type in the http header information.
*/
private void setCharsetFromContentTypeParameters(String paramlist) {
String charset = null;
try {
// paramlist is handed to us with a leading ';', strip it.
int semi = paramlist.indexOf(';');
if (semi > -1 && semi < paramlist.length()-1) {
paramlist = paramlist.substring(semi + 1);
}
if (paramlist.length() > 0) {
// parse the paramlist into attr-value pairs & get the
// charset pair's value
HeaderParser hdrParser = new HeaderParser(paramlist);
charset = hdrParser.findValue("charset");
if (charset != null) {
charSetName = charset;
}
}
}
catch (IndexOutOfBoundsException e) {
// malformed parameter list, use charset we have
}
catch (NullPointerException e) {
// malformed parameter list, use charset we have
}
catch (Exception e) {
// malformed parameter list, use charset we have; but complain
System.err.println("Indexer.getCharsetFromContentTypeParameters failed on: " + paramlist);
e.printStackTrace();
}
}
/**
* Fetches the indexer kit to use for the given type
* of content. This is called when a type is requested
* that doesn't match the currently installed type.
* If the component doesn't have an IndexerKit registered
* for the given type, it will try to create an
* IndexerKit from the default IndexerKit registry.
* If that fails, a PlainIndexerKit is used on the
* assumption that all text documents can be represented
* as plain text.
*
* This method can be reimplemented to use some
* other kind of type registry. This can
* be reimplemented to use the Java Activation
* Framework for example.
*
* @param type the non-null content type
* @return the indexer kit
*/
public IndexerKit getIndexerKitForContentType(String type) {
if (typeHandlers == null) {
typeHandlers = new Hashtable(3);
}
IndexerKit k = (IndexerKit) typeHandlers.get(type);
if (k == null) {
k = createIndexerKitForContentType(type);
if (k != null) {
setIndexerKitForContentType(type, k);
}
}
if (k == null) {
k = new DefaultIndexerKit();
setIndexerKitForContentType(type, k);
}
return k;
}
/**
* Directly set the indexer kit to use for the given type.
*
* @param type the non-null content type
* @param k the indexer kit to be set
*/
public void setIndexerKitForContentType(String type, IndexerKit k) {
if (typeHandlers == null) {
typeHandlers = new Hashtable(3);
}
typeHandlers.put(type, k);
}
/**
* Create a handler for the given type from the default registry
* of indexer kits. The registry is created if necessary. An attempt
* is made to dynamically load the prototype of the given kit. If
* successful it is cloned and returned.
*
* @param type the content type
* @return the indexer kit, or null if one cannot be created
*/
public static IndexerKit createIndexerKitForContentType(String type) {
debug ("Getting IndexerKit for " + type);
IndexerKit k = null;
k = (IndexerKit) kitRegistry.get(type);
if (k == null) {
// try to dynamically load the support
String classname = (String) kitTypeRegistry.get(type);
ClassLoader loader = (ClassLoader) kitLoaderRegistry.get(type);
try {
Class c;
if (loader != null) {
c = loader.loadClass(classname);
} else {
c = Class.forName(classname);
}
k = (IndexerKit) c.newInstance();
kitRegistry.put(type, k);
} catch (Throwable e) {
if (debugFlag) e.printStackTrace();
k = null;
}
}
// create a copy of the prototype or null if there
// is no prototype.
if (k != null) {
return (IndexerKit) k.clone();
}
return null;
}
/**
* Establishes the default bindings of type to name.
* The class will be dynamically loaded later when actually
* needed, and can be safely changed before attempted uses
* to avoid loading unwanted classes.
*
* @param type the non-null content type
* @param classname the class to load later
*/
public static void registerIndexerKitForContentType(String type, String classname, ClassLoader loader) {
kitTypeRegistry.put(type, classname);
if (loader != null) {
kitLoaderRegistry.put(type, loader);
}
}
/**
* For printf debugging.
*/
private static boolean debugFlag = false;
private static void debug(String str) {
if( debugFlag ) {
System.out.println("Indexer: " + str);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/indexer/com/sun/java/help/search/ChangedCharSetException.java 0000644 0001750 0001750 00000003640 10661201770 031305 0 ustar varun varun /*
* @(#)ChangedCharSetException.java 1.6 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @(#) ChangedCharSetException.java 1.6 - last change made 10/30/06
*/
package com.sun.java.help.search;
import java.io.IOException;
/**
* ChangedCharSetException as the name indicates is an exception
* thrown when the charset is changed.
*
* @author Roger Brinkley
* 10/30/06 %V%
*/
public class ChangedCharSetException extends IOException {
String charSetSpec;
boolean charSetKey;
public ChangedCharSetException(String charSetSpec, boolean charSetKey) {
this.charSetSpec = charSetSpec;
this.charSetKey = charSetKey;
}
public String getCharSetSpec() {
return charSetSpec;
}
public boolean keyEqualsCharSet() {
return charSetKey;
}
}
javahelp2-2.0.05/jhMaster/JSearch/indexer/com/sun/java/help/search/HTMLIndexerKit.java 0000644 0001750 0001750 00000100056 10661201770 027355 0 ustar varun varun /*
* @(#)HTMLIndexerKit.java 1.26 06/10/30
*
* Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @(#) HTMLIndexerKit.java 1.26 - last change made 10/30/06
*/
package com.sun.java.help.search;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.text.*;
import javax.swing.text.html.*;
import java.util.*;
import javax.help.search.IndexerKit;
import javax.help.search.IndexBuilder;
import javax.help.search.ConfigFile;
/**
* This is the default implementation of html parsing.
* It can be subclasses to use a different parser and
* receiver.
*
* @author Roger D. Brinkley
* @version %I %G
*/
public class HTMLIndexerKit extends DefaultIndexerKit{
/**
* Constructs an HTMLEditorKit
*/
public HTMLIndexerKit() {
}
/**
* Create a copy of the editor kit. This
* allows an implementation to serve as a prototype
* for others, so that they can be quickly created.
*
* @return the copy
*/
public Object clone() {
return new HTMLIndexerKit();
}
/**
* Get the MIME type of the data that this
* kit represents support for. This kit supports
* the type text/html.
*
* @return the type
*/
public String getContentType() {
return "text/html";
}
/**
* Create and initialize a model from the given
* stream which is expected to be in a format appropriate
* for this kind of kit. This is implemented to read
* html 3.2 text.
*
* @param in The stream to read from
* @param file The file name being parsed
* @param ignoreCharset Ignore the CharacterSet when parsing
* @param builder The IndexBuilder for the full text insertion.
* @param config The indexer configuration information
* @exception IOException on any I/O error
*/
public void parse(Reader in, String file, boolean ignoreCharset,
IndexBuilder builder,
ConfigFile config) throws IOException{
this.builder = builder;
this.config = config;
this.file = file;
documentStarted = false;
HTMLEditorKit.Parser p = getParser();
if (p == null) {
throw new IOException("Can't load parser");
}
if (defaultCallback == null) {
defaultCallback = getParserCallback(this);
}
defaultCallback.initialize();
try {
p.parse(in, defaultCallback, ignoreCharset);
} catch (javax.swing.text.ChangedCharSetException e4) {
throw new com.sun.java.help.search.ChangedCharSetException
(e4.getCharSetSpec(),
e4.keyEqualsCharSet());
}
try {
defaultCallback.flush();
} catch (BadLocationException e3) {
throw new IOException("Can't flush parser");
}
try {
storeTitle(defaultCallback.getTitle());
endStoreDocument();
} catch (Exception e2) {
throw new IOException("Can't store title");
}
this.builder = null;
this.config = null;
}
/**
* Fetch the parser to use for reading html streams.
* This can be reimplemented to provide a different
* parser. The default implementation is loaded dynamically
* to avoid the overhead of loading the default parser if
* it's not used. The default parser is the HotJava parser
* using an html 3.2 dtd.
*/
protected HTMLEditorKit.Parser getParser() {
if (defaultParser == null) {
try {
Class c = Class.forName("javax.swing.text.html.parser.ParserDelegator");
defaultParser = (HTMLEditorKit.Parser) c.newInstance();
} catch (Throwable e) {
e.printStackTrace();
}
}
return defaultParser;
}
/**
* Fetch the parser callback to use to parse the
* html. This is implemented to return an instance of
* HTMLEditorKit.HTMLParserCallback. Subclasses can reimplement this
* method to change how the document gets parsed
*/
public HTMLParserCallback getParserCallback(IndexerKit kit) {
return new HTMLParserCallback(kit);
}
// --- variables ------------------------------------------
private static HTMLEditorKit.Parser defaultParser = null;
private static HTMLParserCallback defaultCallback = null;
private static char[] NEWLINE;
static {
NEWLINE = new char[1];
NEWLINE[0] = '\n';
}
/**
* An html reader to load an html document with an html
* element structure. This is a set of callbacks from
* the parser, implemented to create a set index tokens
*/
public class HTMLParserCallback extends HTMLEditorKit.ParserCallback {
private IndexerKit kit;
private String title;
private String header;
private boolean firstHeader;
private int currentPos;
private boolean receivedEndHTML;
private boolean insertAfterImplied;
private boolean inParagraph;
private boolean impliedP;
private boolean inPre;
private boolean inTextArea;
private boolean inTitle;
private boolean lastWasNewline;
private boolean emptyAnchor;
private boolean inBody;
private boolean foundInsertTag;
private boolean inHead;
private boolean inStyle;
private boolean inOption;
private boolean inFirstHeader;
private boolean startTagType;
private boolean preservesUnknownTags;
Hashtable tagMap;
int inBlock;
Stack tagStack;
String defaultLang;
String lastLang;
// LangElement is a simple little internal class to keep
// track of tags and the langs
private class LangElement {
HTML.Tag tag;
String lang;
public LangElement (HTML.Tag tag, String lang) {
this.tag = tag;
this.lang = lang;
}
public HTML.Tag getTag() {
return tag;
}
public String getLang() {
return lang;
}
}
public HTMLParserCallback(IndexerKit kit) {
this.kit = kit;
tagMap = new Hashtable(57);
TagAction na = new TagAction();
TagAction ba = new BlockAction();
TagAction pa = new ParagraphAction();
TagAction ca = new CharacterAction();
TagAction sa = new SpecialAction();
TagAction fa = new FormAction();
TagAction ha = new HiddenAction();
TagAction conv = new ConvertAction();
// register handlers for the well known tags
tagMap.put(HTML.Tag.A, new AnchorAction());
tagMap.put(HTML.Tag.ADDRESS, ca);
tagMap.put(HTML.Tag.APPLET, ha);
tagMap.put(HTML.Tag.AREA, new AreaAction());
tagMap.put(HTML.Tag.B, ca);
tagMap.put(HTML.Tag.BASE, new BaseAction());
tagMap.put(HTML.Tag.BASEFONT, ca);
tagMap.put(HTML.Tag.BIG, ca);
tagMap.put(HTML.Tag.BLOCKQUOTE, ba);
tagMap.put(HTML.Tag.BODY, ba);
tagMap.put(HTML.Tag.BR, sa);
tagMap.put(HTML.Tag.CAPTION, ba);
tagMap.put(HTML.Tag.CENTER, ba);
tagMap.put(HTML.Tag.CITE, ca);
tagMap.put(HTML.Tag.CODE, ca);
tagMap.put(HTML.Tag.DD, ba);
tagMap.put(HTML.Tag.DFN, ca);
tagMap.put(HTML.Tag.DIR, ba);
tagMap.put(HTML.Tag.DIV, ba);
tagMap.put(HTML.Tag.DL, ba);
tagMap.put(HTML.Tag.DT, pa);
tagMap.put(HTML.Tag.EM, ca);
tagMap.put(HTML.Tag.FONT, conv);
tagMap.put(HTML.Tag.FORM, new FormTagAction());
tagMap.put(HTML.Tag.FRAME, sa);
tagMap.put(HTML.Tag.FRAMESET, ba);
tagMap.put(HTML.Tag.H1, pa);
tagMap.put(HTML.Tag.H2, pa);
tagMap.put(HTML.Tag.H3, pa);
tagMap.put(HTML.Tag.H4, pa);
tagMap.put(HTML.Tag.H5, pa);
tagMap.put(HTML.Tag.H6, pa);
tagMap.put(HTML.Tag.HEAD, new HeadAction());
tagMap.put(HTML.Tag.HR, sa);
tagMap.put(HTML.Tag.HTML, ba);
tagMap.put(HTML.Tag.I, conv);
tagMap.put(HTML.Tag.IMG, sa);
tagMap.put(HTML.Tag.INPUT, fa);
tagMap.put(HTML.Tag.ISINDEX, new IsindexAction());
tagMap.put(HTML.Tag.KBD, ca);
tagMap.put(HTML.Tag.LI, ba);
tagMap.put(HTML.Tag.LINK, new LinkAction());
tagMap.put(HTML.Tag.MAP, new MapAction());
tagMap.put(HTML.Tag.MENU, ba);
tagMap.put(HTML.Tag.META, new MetaAction());
// NOBR isn't publicly available so workaround it.
HTML.Tag tag = HTML.getTag("NOBR");
if (tag != null) {
tagMap.put(tag, ca);
}
tagMap.put(HTML.Tag.NOFRAMES, ba);
tagMap.put(HTML.Tag.OBJECT, sa);
tagMap.put(HTML.Tag.OL, ba);
tagMap.put(HTML.Tag.OPTION, fa);
tagMap.put(HTML.Tag.P, pa);
tagMap.put(HTML.Tag.PARAM, new ObjectAction());
tagMap.put(HTML.Tag.PRE, new PreAction());
tagMap.put(HTML.Tag.SAMP, ca);
tagMap.put(HTML.Tag.SCRIPT, ha);
tagMap.put(HTML.Tag.SELECT, fa);
tagMap.put(HTML.Tag.SMALL, ca);
tagMap.put(HTML.Tag.STRIKE, conv);
tagMap.put(HTML.Tag.S, ca);
tagMap.put(HTML.Tag.STRONG, ca);
tagMap.put(HTML.Tag.STYLE, new StyleAction());
tagMap.put(HTML.Tag.SUB, conv);
tagMap.put(HTML.Tag.SUP, conv);
tagMap.put(HTML.Tag.TABLE, ba);
tagMap.put(HTML.Tag.TD, ba);
tagMap.put(HTML.Tag.TEXTAREA, fa);
tagMap.put(HTML.Tag.TH, ba);
tagMap.put(HTML.Tag.TITLE, new TitleAction());
tagMap.put(HTML.Tag.TR, ba);
tagMap.put(HTML.Tag.TT, ca);
tagMap.put(HTML.Tag.U, conv);
tagMap.put(HTML.Tag.UL, ba);
tagMap.put(HTML.Tag.VAR, ca);
}
public void initialize() {
title = null;
header = null;
firstHeader = true;
currentPos = 0;
receivedEndHTML = false;
insertAfterImplied = false;
inParagraph = false;
impliedP = false;
inPre = false;
inTitle = false;
inOption = false;
inFirstHeader = false;
startTagType = false;
emptyAnchor = false;
inBlock = 0;
tagStack = new Stack();
defaultLang = kit.getLocale().toString();
lastLang = defaultLang;
inTextArea = false;
lastWasNewline = false;
inBody = false;
foundInsertTag = true;
preservesUnknownTags = true;
inHead = false;
inStyle = false;
}
public String getTitle() {
if (title == null || title.length() < 1) {
title = header;
if (title == null || title.length() < 1) {
title = "No Title";
}
}
return title;
}
// -- ParserCallback methods --------------------
/**
* This is the last method called on the reader. It allows
* any pending changes to be flushed into the document.
* Since this is currently loading synchronously, the entire
* set of changes are pushed in at this point.
*/
public void flush() throws BadLocationException {
// Nothing needs to be done here
}
/**
* Called by the parser to indicate a block of text was
* encountered.
*/
public void handleText(char[] data, int pos) {
if (receivedEndHTML) {
return;
}
if (inTextArea) {
// don't do anything
} else if (inPre) {
preContent(data);
} else if (inTitle) {
titleContent(new String(data));
} else if (inOption) {
// Nothing to do here
} else if (inStyle) {
// don't do anything
} else if (inBlock > 0) {
// Added test for first header to set the
// header content
if (inFirstHeader) {
headerContent(new String(data));
}
if (!foundInsertTag && insertAfterImplied) {
// Assume content should be added.
foundInsertTag(false);
foundInsertTag = true;
inParagraph = impliedP = true;
}
if (data.length >= 1) {
addContent(data, 0, data.length);
}
}
}
/**
* Callback from the parser. Route to the appropriate
* handler for the tag.
* This method differes from HTMLDcoument since there
* is not the possibility of doing a mid insert in the
* document and we don't really need to be concerned with
* the construction of the style sheet.
*/
public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos) {
if (receivedEndHTML) {
return;
}
if (!inBody && t == HTML.Tag.BODY) {
inBody = true;
}
TagAction action = (TagAction) tagMap.get(t);
if (action != null) {
action.start(t, a);
}
}
public void handleComment(char[] data, int pos) {
if (receivedEndHTML) {
// don't do anything here
return;
}
if (inStyle) {
// don't do anything here
} else if (preservesUnknownTags) {
if (inBlock == 0) {
// Comment outside of body, will not be able to show it,
// but can add it as a property on the Document.
// In the indexer we don't care though so
// do nothing.
return;
}
SimpleAttributeSet sas = new SimpleAttributeSet();
sas.addAttribute(HTML.Attribute.COMMENT, new String(data));
addSpecialElement(HTML.Tag.COMMENT, sas);
debug ("comment added currentPos=" + currentPos);
}
}
/**
* Callback from the parser. Route to the appropriate
* handler for the tag.
*
* Ignore the midInsert statements in HTMLDocument
*/
public void handleEndTag(HTML.Tag t, int pos) {
if (receivedEndHTML) {
return;
}
if (t == HTML.Tag.HTML) {
receivedEndHTML = true;
}
if (t == HTML.Tag.BODY) {
inBody = false;
}
TagAction action = (TagAction) tagMap.get(t);
if (action != null) {
action.end(t);
}
}
/**
* Callback from the parser. Route to the appropriate
* handler for the tag.
*
* Ignore the midInsert and style statements in HTMLDocument
*/
public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) {
if (receivedEndHTML) {
return;
}
TagAction action = (TagAction) tagMap.get(t);
if (action != null) {
action.start(t, a);
action.end(t);
} else if (preservesUnknownTags) {
addSpecialElement(t, a);
}
}
// ---- tag handling support ------------------------------
/**
* Register a handler for the given tag. By default
* all of the well-known tags will have been registered.
* This can be used to change the handling of a particular
* tag or to add support for custom tags.
*/
protected void registerTag(HTML.Tag t, TagAction a) {
tagMap.put(t, a);
}
/**
* This is an action to be performed in response
* to parsing a tag. This allows customization
* of how each tag is handled and avoids a large
* switch statement.
*/
public class TagAction {
/**
* Called when a start tag is seen for the
* type of tag this action was registered
* to. The tag argument indicates the actual
* tag for those actions that are shared across
* many tags.
*
* Different from HTMLDocument it doesn't ignore
* the tag.
*/
public void start(HTML.Tag t, MutableAttributeSet a) {
String lang = (String) a.getAttribute(HTML.Attribute.LANG);
if (lang == null) {
lang = lastLang;
}
addTag(t, lang);
}
/**
* Called when an end tag is seen for the
* type of tag this action was registered
* to. The tag argument indicates the actual
* tag for those actions that are shared across
* many tags.
*
* Different from HTMLDocument it doesn't ignore
* the tag.
*/
public void end(HTML.Tag t) {
removeTag(t);
}
}
public class BlockAction extends TagAction {
public void start(HTML.Tag t, MutableAttributeSet attr) {
blockOpen(t, attr);
String lang = (String) attr.getAttribute(HTML.Attribute.LANG);
if (lang == null) {
lang = lastLang;
}
addTag(t, lang);
}
public void end(HTML.Tag t) {
blockClose(t);
removeTag(t);
}
}
/**
* Action used for the actual element form tag. This is named such
* as there was already a public class named FormAction.
*
* Unlike HTMLDocument there is no need to setup/destroy
* a ButtonGroup
*/
private class FormTagAction extends BlockAction {
public void start(HTML.Tag t, MutableAttributeSet attr) {
super.start(t, attr);
// do nothing else
}
public void end(HTML.Tag t) {
super.end(t);
// do nothing else
}
}
public class ParagraphAction extends BlockAction {
public void start(HTML.Tag t, MutableAttributeSet a) {
// trap the first header as a substitute title if needed
if (firstHeader &&
((t == HTML.Tag.H1) || (t == HTML.Tag.H2) ||
(t == HTML.Tag.H3) || (t == HTML.Tag.H4) ||
(t == HTML.Tag.H5) || (t == HTML.Tag.H6))) {
inFirstHeader = true;
}
// addTag done in super
super.start(t, a);
inParagraph = true;
}
public void end(HTML.Tag t) {
// trapped the first header as a substitute title if needed
if (firstHeader &&
((t == HTML.Tag.H1) || (t == HTML.Tag.H2) ||
(t == HTML.Tag.H3) || (t == HTML.Tag.H4) ||
(t == HTML.Tag.H5) || (t == HTML.Tag.H6))) {
inFirstHeader = false;
firstHeader = false;
}
// removeTag done in super
super.end(t);
inParagraph = false;
}
}
public class SpecialAction extends TagAction {
public void start(HTML.Tag t, MutableAttributeSet a) {
String lang = (String) a.getAttribute(HTML.Attribute.LANG);
if (lang == null) {
lang = lastLang;
}
addTag(t, lang);
addSpecialElement(t, a);
}
// removeTag is handled in super class
}
public class IsindexAction extends TagAction {
public void start(HTML.Tag t, MutableAttributeSet a) {
blockOpen(HTML.Tag.IMPLIED, new SimpleAttributeSet());
addSpecialElement(t, a);
blockClose(HTML.Tag.IMPLIED);
}
}
public class HiddenAction extends TagAction {
public void start(HTML.Tag t, MutableAttributeSet a) {
String lang = (String) a.getAttribute(HTML.Attribute.LANG);
if (lang == null) {
lang = lastLang;
}
addTag(t, lang);
addSpecialElement(t, a);
}
public void end(HTML.Tag t) {
if (!isEmpty(t)) {
MutableAttributeSet a = new SimpleAttributeSet();
a.addAttribute(HTML.Attribute.ENDTAG, "true");
addSpecialElement(t, a);
}
removeTag(t);
}
private boolean isEmpty(HTML.Tag t) {
if (t == HTML.Tag.APPLET ||
t == HTML.Tag.TITLE ||
t == HTML.Tag.SCRIPT) {
return false;
}
return true;
}
}
/**
* Subclass of HiddenAction to set the content type for style sheets,
* and to set the name of the default style sheet.
*
* None of this method is really needed for the Indexer.
* Don't do anything related tot he style sheet and just
* take the actions of HiddenAction to record the position
*/
class MetaAction extends HiddenAction {
public void start(HTML.Tag t, MutableAttributeSet a) {
// ignore all the style sheet setting code
super.start(t, a);
}
private boolean isEmpty(HTML.Tag t) {
return true;
}
}
/**
* End if overridden to create the necessary stylesheets that
* are referenced via the link tag. It is done in this manner
* as the meta tag can be used to specify an alternate style sheet,
* and is not guaranteed to come before the link tags.
*
* For the indexer we don't care much about the style
* sheets.
*/
class HeadAction extends BlockAction {
public void start(HTML.Tag t, MutableAttributeSet a) {
inHead = true;
super.start(t, a);
}
public void end(HTML.Tag t) {
inHead = inStyle = false;
// ignore the StyleSheet statements
super.end(t);
}
}
/**
* A subclass to add the AttributeSet to styles if the
* attributes contains an attribute for 'rel' with value
* 'stylesheet' or 'alternate stylesheet'.
*
* For the indexer we don't care about style sheets.
*/
class LinkAction extends HiddenAction {
public void start(HTML.Tag t, MutableAttributeSet a) {
// ignore the style sheet statements
super.start(t, a);
}
}
/**
* Don't do anything for Maps in Indexer. It just stores
* the information in a property HashTable.
*/
class MapAction extends TagAction {
}
/**
* Don't do anthing for an Area action for Indexer.
* It's stored locally in HTMLDocument and doesn't
* require an entry as a tag
*/
class AreaAction extends TagAction {
}
/**
* Handle style actions
*
* Ignore the storing the styles as HTMLDocument does
*/
class StyleAction extends TagAction {
public void start(HTML.Tag t, MutableAttributeSet a) {
if (inHead) {
inStyle = true;
}
super.start(t, a);
}
public void end(HTML.Tag t) {
inStyle = false;
super.end(t);
}
}
public class PreAction extends BlockAction {
public void start(HTML.Tag t, MutableAttributeSet attr) {
inPre = true;
blockOpen(t, attr);
attr.addAttribute(CSS.Attribute.WHITE_SPACE, "pre");
blockOpen(HTML.Tag.IMPLIED, attr);
String lang = (String) attr.getAttribute(HTML.Attribute.LANG);
if (lang == null) {
lang = lastLang;
}
addTag(t, lang);
}
public void end(HTML.Tag t) {
blockClose(HTML.Tag.IMPLIED);
// set inPre to false after closing, so that if a newline
// is added it won't generate a blockOpen.
inPre = false;
blockClose(t);
removeTag(t);
}
}
public class CharacterAction extends TagAction {
/**
* In the indexer we don't care about character style
* and the foundInsertTag will always be true so there
* really isn't much to do here
*
*/
public void start(HTML.Tag t, MutableAttributeSet a) {
String lang = (String) a.getAttribute(HTML.Attribute.LANG);
if (lang == null) {
lang = lastLang;
}
addTag(t, lang);
}
public void end(HTML.Tag t) {
removeTag(t);
}
}
/**
* Provides conversion of HTML tag/attribute
* mappings that have a corresponding StyleConstants
* and CSS mapping. The conversion is to CSS attributes.
*
* For the indexer we really don't care much. We'll keep
* the method here for consistency sake, but it really
* isn't needed.
*/
class ConvertAction extends TagAction {
}
class AnchorAction extends CharacterAction {
// This class has a dependancy on the "one[0]" character
// used in javax.swing.text.html.HTMLDocument$AnchorAction
// we need to ensure we use the same character value.
private boolean post4207472 = isPost4207472();
public void start(HTML.Tag t, MutableAttributeSet attr) {
// set flag to catch empty anchors
emptyAnchor = true;
// addTag done in super
super.start(t, attr);
}
public void end(HTML.Tag t) {
if (emptyAnchor) {
// if the anchor was empty it was probably a
// named anchor point and we don't want to throw
// it away.
char[] one = new char[1];
if (post4207472)
one[0] = '\n';
else
one[0] = ' ';
debug ("emptyAnchor currentPos=" + currentPos);
addContent(one, 0, 1);
}
// remove tag done in super
super.end(t);
}
private boolean isPost4207472() {
try {
String ver = System.getProperty("java.version");
int major = Integer.parseInt(ver.substring(2,3));
int minor = 0;
// allow for FCS case - we leave minor as 0 if dealing with FCS
if (ver.length() > 6)
minor = Integer.parseInt(ver.substring(6,8));
if ((major > 5 ) || (major==5 && minor >= 4)) {
return true;
} else {
return false;
}
} catch (Exception e) {
debug ("Exception in isPost4207472 : " + e);
return true; // assume true if we encounter problem
}
}
}
class TitleAction extends HiddenAction {
public void start(HTML.Tag t, MutableAttributeSet attr) {
inTitle = true;
super.start(t, attr);
}
public void end(HTML.Tag t) {
inTitle = false;
super.end(t);
}
}
class BaseAction extends TagAction {
// Nothing here for indexer
}
class ObjectAction extends SpecialAction {
public void start(HTML.Tag t, MutableAttributeSet a) {
if (t == HTML.Tag.PARAM) {
// don't do anything if a parameter
} else {
super.start(t, a);
}
}
public void end(HTML.Tag t) {
if (t != HTML.Tag.PARAM) {
super.end(t);
}
}
}
public class FormAction extends SpecialAction {
/**
* Ignore INPUT and Select. Only be concerned with
* TEXTAREA and OPTION
*/
public void start(HTML.Tag t, MutableAttributeSet attr) {
if (t == HTML.Tag.TEXTAREA) {
inTextArea = true;
}
// Occupy one space for the element, unless this is an option.
if (t == HTML.Tag.OPTION) {
//options don't take any room. They are internal to selects
} else {
super.start(t, attr);
}
}
public void end(HTML.Tag t) {
if (t == HTML.Tag.TEXTAREA) {
inTextArea = false;
}
if (t == HTML.Tag.OPTION) {
// ignore options
} else {
super.end(t);
}
}
}
// --- utility methods used by the reader ------------------
/**
* Set the title for the doc
*/
protected void titleContent(String s) {
if (title == null) {
title = new String(s);
} else {
title.concat(s);
}
}
/**
* Set the first header for the doc
*/
protected void headerContent(String s) {
if (header == null) {
header = new String(s);
} else {
header.concat(s);
}
}
/**
* Add the given content that was encountered in a
* PRE element. This synthesizes lines to hold the
* runs of text, and makes calls to addContent to
* actually add the text.
*/
protected void preContent(char[] data) {
int last = 0;
for (int i = 0; i < data.length; i++) {
if (data[i] == '\n') {
debug ("preContent currentPos=" + currentPos);
addContent(data, last, i - last + 1);
blockClose(HTML.Tag.IMPLIED);
MutableAttributeSet a = new SimpleAttributeSet();
a.addAttribute(CSS.Attribute.WHITE_SPACE, "pre");
blockOpen(HTML.Tag.IMPLIED, a);
last = i + 1;
}
}
if (last < data.length) {
debug ("preContent currentPos=" + currentPos);
addContent(data, last, data.length - last);
}
}
/**
* Add an instruction to the parse buffer to create a
* block element with the given attributes.
*/
protected void blockOpen(HTML.Tag t, MutableAttributeSet attr) {
debug ("blockOpen");
if (impliedP) {
blockClose(HTML.Tag.IMPLIED);
}
inBlock++;
if (!canInsertTag(t, attr, true)) {
return;
}
startTagType = true;
lastWasNewline = false;
// parse buffer code not used in indexer
}
/**
* Add an instruction to the parse buffer to close out
* a block element of the given type.
*/
protected void blockClose(HTML.Tag t) {
debug ("blockClose");
inBlock --;
if (!foundInsertTag) {
return;
}
// Add a new line, if the last character wasn't one. This is
// needed for proper positioning of the cursor.
if(!lastWasNewline) {
debug ("blockClose adding NEWLINE currentPos=" + currentPos);
addContent(NEWLINE, 0, 1, false);
lastWasNewline = true;
}
if (impliedP) {
impliedP = false;
inParagraph = false;
if (t != HTML.Tag.IMPLIED) {
blockClose(HTML.Tag.IMPLIED);
}
}
// This is different from HTMLReader. I don't keep parseBuffer
// so I'll use the boolean startTagType instead.
//
// an open/close with no content will be removed, so we
// add a space of content to keep the element being formed.
if (startTagType) {
char[] one = new char[1];
one[0] = ' ';
debug ("blockclose open/close nocontent currentPos=" + currentPos);
addContent(one, 0, 1);
}
startTagType = false;
}
/**
* Add some text with the current character attributes.
*
* @param embedded the attributes of an embedded object.
*/
protected void addContent(char[] data, int offs, int length) {
addContent(data, offs, length, true);
}
/**
* Add some text with the current character attributes.
*
* @param embedded the attributes of an embedded object.
*/
protected void addContent(char[] data, int offs, int length,
boolean generateImpliedPIfNecessary) {
debug ("addContent");
if (!foundInsertTag) {
return;
}
if (generateImpliedPIfNecessary && (! inParagraph) && (! inPre)) {
blockOpen(HTML.Tag.IMPLIED, new SimpleAttributeSet());
inParagraph = true;
impliedP = true;
}
emptyAnchor = false;
// This is different from HTMLDocument. The indexer doesn't use
// parseBuffer. Instead pass the strings over to IndexerKit to
// parse the string into tokens. Also set startTagType to false
// to simulate that portion of parseBuffer
debug ("Pre parseIntoTokens String=" + new String(data, offs, length) + " currentPos=" + currentPos);
startTagType = false;
currentPos = kit.parseIntoTokens(new String(data, offs, length),
currentPos);
debug ("Post parseIntoTokens currentPos=" + currentPos);
// No flushing like HTMLDocument but set the lastWasNewline
// appropriately
if(length > 0) {
lastWasNewline = (data[offs + length - 1] == '\n');
}
}
/**
* Add content that is basically specified entirely
* in the attribute set.
*/
protected void addSpecialElement(HTML.Tag t, MutableAttributeSet a) {
if ((t != HTML.Tag.FRAME) && (! inParagraph) && (! inPre)) {
blockOpen(HTML.Tag.IMPLIED, new SimpleAttributeSet());
inParagraph = true;
impliedP = true;
}
if (!canInsertTag(t, a, true)) {
return;
}
emptyAnchor = false;
// This is different from HTMLDocument. The indexer doesn't use
// parseBuffer. Just increment to currentPos to simulate the
// addition
currentPos += 1;
debug ("addingSpecialElement tag=" + t + " currentPos=" + currentPos);
startTagType = false;
// Set this to avoid generating a newline for frames, frames
// shouldn't have any content, and shouldn't need a newline.
if (t == HTML.Tag.FRAME) {
lastWasNewline = true;
}
}
/**
* Returns true if can insert starting at t. This
* will return false if the insert tag is set, and hasn't been found
* yet.
*/
private boolean canInsertTag(HTML.Tag t, AttributeSet attr,
boolean isBlockTag) {
if (!foundInsertTag) {
foundInsertTag(isBlockTag);
return false;
}
return true;
}
private boolean isInsertTag(HTML.Tag tag) {
return (false);
}
private void foundInsertTag(boolean isBlockTag) {
foundInsertTag = true;
// The rest of the code is differnt from HTMLDocument since we
// don't need to worry about added to a document we don't care
// about adding a newline or pushing or poping
}
/**
* addTag keeps track of tags and their lang attributes
*/
protected void addTag(HTML.Tag tag, String lang) {
LangElement el = new LangElement(tag, lang);
tagStack.push(el);
if (lastLang.compareTo(lang) != 0) {
kit.setLocale(lang);
lastLang = lang;
}
}
/**
* removeTag removes a tag from the tagStack. The tagStack is
* used to keep track of tags and locales
*/
protected void removeTag(HTML.Tag tag) {
LangElement el;
String name = tag.toString();
String newLang=defaultLang;
for (;;) {
if (tagStack.empty())
break;
el = (LangElement) tagStack.pop();
if (el.getTag().toString().compareTo(name) == 0) {
if (tagStack.empty()) {
newLang = defaultLang;
} else {
el = (LangElement) tagStack.peek();
newLang = el.getLang();
}
break;
}
}
if (lastLang.compareTo(newLang) != 0) {
kit.setLocale(newLang);
lastLang = newLang;
}
}
}
/**
* Debug code
*/
private boolean debugFlag=false;
private void debug(String msg) {
if (debugFlag) {
System.err.println("HTMLIndexerKit: "+msg);
}
}
}
javahelp2-2.0.05/jhMaster/JSearch/indexer/GNUmakefile 0000644 0001750 0001750 00000003237 10661201770 021333 0 ustar varun varun #
# @(#)GNUmakefile 1.9 06/10/30
#
# Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun in the LICENSE file that accompanied this code.
#
# This code 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 General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
SOURCES := $(shell find . -name 'SCCS*' -prune -o -name '*Old*' -prune -o -name '*.java' -print)
CLASSES = $(SOURCES:%.java=classes/%.class)
RM=/bin/rm
jar: ../lib/jsearch-indexer.jar
../lib/jsearch-indexer.jar: $(CLASSES)
cd classes ; \
jar cf ../../lib/jsearch-indexer.jar com
classes/%.class: %.java classes
export CLASSPATH ; CLASSPATH=../lib/jsearch-misc.jar:../lib/jsearch-client.jar:. ; \
javac -d classes $<
classes:
mkdir classes
clean:
$(RM) -rf classes
javahelp2-2.0.05/jhMaster/JavaHelp/ 0000755 0001750 0001750 00000000000 11220022253 015756 5 ustar varun varun javahelp2-2.0.05/jhMaster/JavaHelp/src/ 0000755 0001750 0001750 00000000000 11220022253 016545 5 ustar varun varun javahelp2-2.0.05/jhMaster/JavaHelp/src/impl/ 0000755 0001750 0001750 00000000000 11220022253 017506 5 ustar varun varun javahelp2-2.0.05/jhMaster/JavaHelp/src/impl/com/ 0000755 0001750 0001750 00000000000 11220022253 020264 5 ustar varun varun javahelp2-2.0.05/jhMaster/JavaHelp/src/impl/com/sun/ 0000755 0001750 0001750 00000000000 11220022253 021071 5 ustar varun varun javahelp2-2.0.05/jhMaster/JavaHelp/src/impl/com/sun/java/ 0000755 0001750 0001750 00000000000 11220022253 022012 5 ustar varun varun javahelp2-2.0.05/jhMaster/JavaHelp/src/impl/com/sun/java/help/ 0000755 0001750 0001750 00000000000 11220022253 022742 5 ustar varun varun javahelp2-2.0.05/jhMaster/JavaHelp/src/impl/com/sun/java/help/impl/ 0000755 0001750 0001750 00000000000 11220022253 023703 5 ustar varun varun javahelp2-2.0.05/jhMaster/JavaHelp/src/impl/com/sun/java/help/impl/SwingWorker.java 0000644 0001750 0001750 00000011653 10661201774 027054 0 ustar varun varun /*
* @(#)SwingWorker.java 1.3 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @(#) SwingWorker.java 1.3 - last change made 10/30/06
*/
package com.sun.java.help.impl;
import javax.swing.SwingUtilities;
/**
* This is the 3rd version of SwingWorker (also known as
* SwingWorker 3), an abstract class that you subclass to
* perform GUI-related work in a dedicated thread. For
* instructions on and examples of using this class, see:
*
* http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html
*
* Note that the API changed slightly in the 3rd version:
* You must now invoke start() on the SwingWorker after
* creating it.
*/
public abstract class SwingWorker {
private Object value; // see getValue(), setValue()
/**
* Class to maintain reference to current worker thread
* under separate synchronization control.
*/
private static class ThreadVar {
private Thread thread;
ThreadVar(Thread t) { thread = t; }
synchronized Thread get() { return thread; }
synchronized void clear() { thread = null; }
}
private ThreadVar threadVar;
/**
* Get the value produced by the worker thread, or null if it
* hasn't been constructed yet.
*/
protected synchronized Object getValue() {
return value;
}
/**
* Set the value produced by worker thread
*/
private synchronized void setValue(Object x) {
value = x;
}
/**
* Compute the value to be returned by the get method.
*/
public abstract Object construct();
/**
* Called on the event dispatching thread (not on the worker thread)
* after the construct method has returned.
*/
public void finished() {
}
/**
* A new method that interrupts the worker thread. Call this method
* to force the worker to stop what it's doing.
*/
public void interrupt() {
Thread t = threadVar.get();
if (t != null) {
t.interrupt();
}
threadVar.clear();
}
/**
* Return the value created by the construct method.
* Returns null if either the constructing thread or the current
* thread was interrupted before a value was produced.
*
* @return the value created by the construct method
*/
public Object get() {
while (true) {
Thread t = threadVar.get();
if (t == null) {
return getValue();
}
try {
t.join();
}
catch (InterruptedException e) {
Thread.currentThread().interrupt(); // propagate
return null;
}
}
}
/**
* Start a thread that will call the construct method
* and then exit.
*/
public SwingWorker() {
final Runnable doFinished = new Runnable() {
public void run() { finished(); }
};
Runnable doConstruct = new Runnable() {
public void run() {
try {
setValue(construct());
}
finally {
threadVar.clear();
}
SwingUtilities.invokeLater(doFinished);
}
};
Thread t = new Thread(doConstruct);
threadVar = new ThreadVar(t);
}
/**
* Start the worker thread.
*/
public void start() {
start(Thread.NORM_PRIORITY);
}
/**
* Start the worker thread.
*/
public void start(int priority) {
Thread t = threadVar.get();
if (t != null) {
if (priority < Thread.MAX_PRIORITY && priority > Thread.MIN_PRIORITY) {
t.setPriority(priority);
}
t.start();
}
}
}
javahelp2-2.0.05/jhMaster/JavaHelp/src/impl/com/sun/java/help/impl/CustomKit.java 0000644 0001750 0001750 00000025075 10661201774 026520 0 ustar varun varun /*
* @(#)CustomKit.java 1.15 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.java.help.impl;
import java.util.Enumeration;
import java.util.Vector;
import java.awt.*;
import java.net.*;
import java.io.*;
import javax.swing.*;
import javax.swing.text.*;
import java.beans.*;
import java.lang.reflect.*;
import javax.swing.text.html.*;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseEvent;
/**
* Subclass of HTMLEditorKit from Swing to adds better functionality
* for handing