appl = appl.substring(1);
File helpTextFile = File.createTempFile("helptext", ".ht");
helpTextFile.deleteOnExit();
String helpTextFileName = helpTextFile.getAbsolutePath();
Db helpText = new Db(null, 0);
helpText.open(null,helpTextFileName, null, Db.DB_BTREE, Db.DB_TRUNCATE, 0644);
File dbBaseFile = File.createTempFile("database", "db");
dbBaseFile.deleteOnExit();
String dbBaseFileName = dbBaseFile.getAbsolutePath();
Db dbBase = new Db(null, 0);
dbBase.open(null,dbBaseFileName, null, Db.DB_BTREE, Db.DB_TRUNCATE, 0644);
File keyWordFile = File.createTempFile("keybase", "key");
keyWordFile.deleteOnExit();
String keyWordFileName = keyWordFile.getAbsolutePath();
Db keyWord = new Db(null, 0);
keyWord.open(null,keyWordFileName, null, Db.DB_BTREE, Db.DB_TRUNCATE, 0644);
HelpKeyword helpKeyword = new HelpKeyword();
// now input the hid.lst and store it into a hashmap
FileReader fileReader = new FileReader(hid);
StringBuffer strBuf = new StringBuffer();
int n = 0;
char[] c = new char[1024];
while ((n = fileReader.read(c, 0, 1024)) != -1)
strBuf.append(c, 0, n);
String str = strBuf.toString();
StringTokenizer strTokenizer = new StringTokenizer(str);
while (strTokenizer.hasMoreTokens()) {
String key = strTokenizer.nextToken();
String data = strTokenizer.nextToken();
hidlistTranslation.put(
key.toUpperCase().replace(':', '_'),
data.trim());
}
// lastly, initialize the indexBuilder
if (!helpFiles.isEmpty())
initXMLIndexBuilder();
// here we start our loop over the hzip files.
Iterator iter = helpFiles.iterator();
while (iter.hasNext()) {
// process one file
// streamTable contains the streams in the hzip file
//Hashtable streamTable = new Hashtable();
Hashtable streamTable1 = new Hashtable();
String xhpFileName = (String) iter.next();
if (!xhpFileName.endsWith(".xhp")) {
// only work on .xhp - files
System.err.println(
"ERROR: input list entry '"
+ xhpFileName
+ "' has the wrong extension (only files with extension .xhp "
+ "are accepted)");
continue;
}
HelpCompiler hc =
new HelpCompiler(
streamTable1,
xhpFileName,
sourceRoot + File.separator + lang + File.separator,
embeddStylesheet,
module,
lang);
try {
boolean success = hc.compile();
if (!success) {
System.err.println(
"\nERROR: compiling help particle '"
+ xhpFileName
+ "' for language '"
+ lang
+ "' failed!");
System.exit(1);
}
} catch (UnsupportedEncodingException e) {
System.err.println(
"\nERROR: unsupported Encoding Exception'"
+ "': "
+ e.getMessage());
System.exit(1);
}
// Read the document core data
byte[] byStr = (byte[]) streamTable1.get("document/id");
String documentBaseId = null;
if (byStr != null) {
documentBaseId = new String(byStr, "UTF8");
} else {
System.err.println("corrupt compileroutput");
System.exit(1);
}
String documentPath =
new String(
((byte[]) streamTable1.get("document/path")),
"UTF8");
if (documentPath.startsWith("/"))
documentPath = documentPath.substring(1);
String documentJarfile =
new String(
((byte[]) streamTable1.get("document/module")),
"UTF8")
+ ".jar";
byte[] byteStream = (byte[]) streamTable1.get("document/title");
String documentTitle = null;
if (byteStream != null)
documentTitle = new String(byteStream, "UTF8");
else
documentTitle = "<notitle>";
byte[] fileB = documentPath.getBytes("UTF8");
byte[] jarfileB = documentJarfile.getBytes("UTF8");
byte[] titleB = documentTitle.getBytes("UTF8");
// add once this as its own id.
addBookmark(dbBase, documentPath, fileB, null, jarfileB, titleB);
if (init) {
FileInputStream indexXSLFile =
new FileInputStream(indexStylesheet);
int read = 0;
byte[] bytes = new byte[2048];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while ((read = indexXSLFile.read(bytes, 0, 2048)) != -1)
baos.write(bytes, 0, read);
createFileFromBytes("index.xsl", baos.toByteArray());
xmlIndexBuilder.init("index");
init = false;
}
// first the database *.db
// ByteArrayInputStream bais = null;
// ObjectInputStream ois = null;
Object baos = streamTable1.get(appl + "/hidlist");
if (baos == null)
baos = streamTable1.get("default/hidlist");
if (baos != null) {
HashSet hidlist = (HashSet) baos;
// now iterate over all elements of the hidlist
Iterator hidListIter = hidlist.iterator();
while (hidListIter.hasNext()) {
String hid = (String) hidListIter.next();
byte[] anchorB = null;
int index = hid.lastIndexOf('#');
if (index != -1) {
anchorB = hid.substring(1 + index).getBytes("UTF8");
hid = hid.substring(0, index);
}
addBookmark(dbBase, hid, fileB, anchorB, jarfileB, titleB);
}
}
// now the keywords
baos = streamTable1.get(appl + "/keywords");
if (baos == null)
baos = streamTable1.get("default/keywords");
if (baos != null) {
Hashtable anchorToLL = (Hashtable) baos;
Enumeration enumer = anchorToLL.keys();
String fakedHid = URLEncoder.encode(documentPath);
while (enumer.hasMoreElements()) {
String anchor = (String) enumer.nextElement();
addBookmark(
dbBase,
documentPath,
fileB,
anchor.getBytes("UTF8"),
jarfileB,
titleB);
String totalId = fakedHid + "#" + anchor;
// System.err.println(hzipFileName);
LinkedList ll = (LinkedList) anchorToLL.get(anchor);
Iterator llIter = ll.iterator();
while (llIter.hasNext())
helpKeyword.insert((String) llIter.next(), totalId);
}
}
// and last the helptexts
baos = streamTable1.get(appl + "/helptexts");
if (baos == null)
baos = streamTable1.get("default/helptexts");
if (baos != null) {
Hashtable helpTextHash = (Hashtable) baos;
Enumeration helpTextIter = helpTextHash.keys();
while (helpTextIter.hasMoreElements()) {
String helpTextId = (String) helpTextIter.nextElement();
String helpTextText = (String) helpTextHash.get(helpTextId);
String tHid =
(String) hidlistTranslation.get(
helpTextId.toUpperCase().replace(':', '_'));
if (tHid != null)
helpTextId = tHid;
helpTextId = URLEncoder.encode(helpTextId);
Dbt keyDbt = new Dbt(helpTextId.getBytes("UTF8"));
Dbt textDbt = new Dbt(helpTextText.getBytes("UTF8"));
helpText.put(null, keyDbt, textDbt, 0);
}
}
// now the indexing
// and last the helptexts
baos = (byte[]) streamTable1.get(appl + "/text");
if (baos == null)
baos = (byte[]) streamTable1.get("default/text");
if (baos != null) {
byte[] bytes = (byte[]) baos;
HelpURLStreamHandlerFactory.setMode(bytes);
xmlIndexBuilder.indexDocument(
new URL(
"vnd.sun.star.help://"
+ module.toLowerCase()
+ "/"
+ URLEncoder.encode(documentPath)),
"");
}
} // while loop over hzip files ending
helpText.close(0);
dbBase.close(0);
helpKeyword.dump(keyWord);
keyWord.close(0);
if (!helpFiles.isEmpty())
closeXMLIndexBuilder();
// now copy the databases into memory, so we will be able to add it to the outputfile
String mod = module.toLowerCase();