Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
3da434bd
提交
3da434bd
authored
12月 15, 2006
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
--no commit message
--no commit message
上级
976bc8b3
隐藏空白字符变更
内嵌
并排
正在显示
12 个修改的文件
包含
1707 行增加
和
0 行删除
+1707
-0
CheckTextFiles.java
h2/src/tools/org/h2/tools/code/CheckTextFiles.java
+177
-0
CodeSwitch.java
h2/src/tools/org/h2/tools/code/CodeSwitch.java
+307
-0
PropertiesToUTF8.java
h2/src/tools/org/h2/tools/code/PropertiesToUTF8.java
+60
-0
GenerateDoc.java
h2/src/tools/org/h2/tools/doc/GenerateDoc.java
+101
-0
LinkChecker.java
h2/src/tools/org/h2/tools/doc/LinkChecker.java
+175
-0
MergeDocs.java
h2/src/tools/org/h2/tools/doc/MergeDocs.java
+87
-0
Doclet.java
h2/src/tools/org/h2/tools/doclet/Doclet.java
+265
-0
HtmlConverter.java
h2/src/tools/org/h2/tools/indexer/HtmlConverter.java
+115
-0
Indexer.java
h2/src/tools/org/h2/tools/indexer/Indexer.java
+341
-0
Page.java
h2/src/tools/org/h2/tools/indexer/Page.java
+23
-0
Weight.java
h2/src/tools/org/h2/tools/indexer/Weight.java
+11
-0
Word.java
h2/src/tools/org/h2/tools/indexer/Word.java
+45
-0
没有找到文件。
h2/src/tools/org/h2/tools/code/CheckTextFiles.java
0 → 100644
浏览文件 @
3da434bd
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
tools
.
code
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.RandomAccessFile
;
import
org.h2.util.ByteUtils
;
public
class
CheckTextFiles
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
CheckTextFiles
().
run
();
}
String
[]
suffixCheck
=
new
String
[]{
"html"
,
"jsp"
,
"js"
,
"css"
,
"bat"
,
"nsi"
,
"java"
,
"txt"
,
"properties"
,
"cpp"
,
"def"
,
"h"
,
"rc"
,
"dev"
,
"sql"
,
"xml"
,
"csv"
,
"Driver"
};
String
[]
suffixIgnore
=
new
String
[]{
"gif"
,
"png"
,
"odg"
,
"ico"
,
"sxd"
,
"layout"
,
"res"
,
"win"
,
"dll"
,
"jar"
};
boolean
failOnError
;
boolean
allowTab
,
allowCR
=
true
,
allowTrailingSpaces
=
true
;
int
spacesPerTab
=
4
;
boolean
autoFix
=
true
;
boolean
useCRLF
=
true
;
// must contain "+" otherwise this here counts as well
String
copyrightLicense
=
"Copyright 2004-2006 H2 Group. "
+
"Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html)."
;
String
[]
suffixIgnoreLicense
=
new
String
[]{
"bat"
,
"nsi"
,
"txt"
,
"properties"
,
"def"
,
"rc"
,
"dev"
,
"xml"
,
"_private.h"
,
"java.sql.Driver"
};
boolean
hasError
;
void
run
()
throws
Exception
{
String
baseDir
=
"src"
;
check
(
new
File
(
baseDir
));
if
(
hasError
)
{
throw
new
Exception
(
"Errors found"
);
}
}
private
void
check
(
File
file
)
throws
Exception
{
String
name
=
file
.
getName
();
if
(
file
.
isDirectory
())
{
if
(
name
.
equals
(
"CVS"
)
||
name
.
equals
(
".svn"
))
{
return
;
}
File
[]
list
=
file
.
listFiles
();
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
check
(
list
[
i
]);
}
}
else
{
String
suffix
=
""
;
int
lastDot
=
name
.
lastIndexOf
(
'.'
);
if
(
lastDot
>=
0
)
{
suffix
=
name
.
substring
(
lastDot
+
1
);
}
boolean
check
=
false
,
ignore
=
false
;
for
(
int
i
=
0
;
i
<
suffixCheck
.
length
;
i
++)
{
if
(
suffix
.
equals
(
suffixCheck
[
i
]))
{
check
=
true
;
}
}
for
(
int
i
=
0
;
i
<
suffixIgnore
.
length
;
i
++)
{
if
(
suffix
.
equals
(
suffixIgnore
[
i
]))
{
ignore
=
true
;
}
}
boolean
checkLicense
=
true
;
for
(
int
i
=
0
;
i
<
suffixIgnoreLicense
.
length
;
i
++)
{
String
ig
=
suffixIgnoreLicense
[
i
];
if
(
suffix
.
equals
(
ig
)
||
name
.
endsWith
(
ig
))
{
checkLicense
=
false
;
break
;
}
}
if
(
ignore
==
check
)
{
throw
new
Error
(
"Unknown suffix: "
+
suffix
+
" for file: "
+
name
);
}
if
(
check
)
{
checkOrFixFile
(
file
,
autoFix
,
checkLicense
);
}
}
}
void
checkOrFixFile
(
File
file
,
boolean
fix
,
boolean
checkLicense
)
throws
Exception
{
RandomAccessFile
in
=
new
RandomAccessFile
(
file
,
"r"
);
byte
[]
data
=
new
byte
[(
int
)
file
.
length
()];
ByteArrayOutputStream
out
=
fix
?
new
ByteArrayOutputStream
()
:
null
;
in
.
readFully
(
data
);
in
.
close
();
if
(
checkLicense
)
{
if
(
data
.
length
>
copyrightLicense
.
length
())
{
// don't check tiny files
String
text
=
new
String
(
data
);
if
(
text
.
indexOf
(
copyrightLicense
)
<
0
)
{
fail
(
file
,
"license is missing"
,
0
);
}
}
}
int
line
=
1
;
boolean
lastWasWhitespace
=
false
;
for
(
int
i
=
0
;
i
<
data
.
length
;
i
++)
{
char
ch
=
(
char
)
(
data
[
i
]
&
0xff
);
if
(
ch
>
127
)
{
fail
(
file
,
"contains character "
+
ch
,
line
);
return
;
}
else
if
(
ch
<
32
)
{
if
(
ch
==
'\n'
)
{
if
(
lastWasWhitespace
&&
!
allowTrailingSpaces
)
{
fail
(
file
,
"contains trailing white space"
,
line
);
return
;
}
if
(
fix
)
{
if
(
useCRLF
)
{
out
.
write
(
'\r'
);
}
out
.
write
(
ch
);
}
lastWasWhitespace
=
false
;
line
++;
}
else
if
(
ch
==
'\r'
)
{
if
(!
allowCR
)
{
fail
(
file
,
"contains CR"
,
line
);
return
;
}
if
(
lastWasWhitespace
&&
!
allowTrailingSpaces
)
{
fail
(
file
,
"contains trailing white space"
,
line
);
return
;
}
lastWasWhitespace
=
false
;
// ok
}
else
if
(
ch
==
'\t'
)
{
if
(
fix
)
{
for
(
int
j
=
0
;
j
<
spacesPerTab
;
j
++)
{
out
.
write
(
' '
);
}
}
else
{
if
(!
allowTab
)
{
fail
(
file
,
"contains TAB"
,
line
);
return
;
}
}
lastWasWhitespace
=
true
;
// ok
}
else
{
fail
(
file
,
"contains character "
+(
int
)
ch
,
line
);
return
;
}
}
else
{
if
(
fix
)
{
out
.
write
(
ch
);
}
lastWasWhitespace
=
Character
.
isWhitespace
(
ch
);
}
}
if
(
lastWasWhitespace
&&
!
allowTrailingSpaces
)
{
fail
(
file
,
"contains trailing white space at the very end"
,
line
);
return
;
}
if
(
fix
)
{
byte
[]
changed
=
out
.
toByteArray
();
if
(
ByteUtils
.
compareNotNull
(
data
,
changed
)
!=
0
)
{
RandomAccessFile
f
=
new
RandomAccessFile
(
file
,
"rw"
);
f
.
write
(
changed
);
f
.
setLength
(
changed
.
length
);
f
.
close
();
System
.
out
.
println
(
"CHANGED: File "
+
file
.
getName
());
}
}
}
private
void
fail
(
File
file
,
String
error
,
int
line
)
{
System
.
out
.
println
(
"FAIL: File "
+
file
.
getAbsolutePath
()
+
" "
+
error
+
" at line "
+
line
);
hasError
=
true
;
if
(
failOnError
)
{
throw
new
Error
(
"FAIL"
);
}
}
}
h2/src/tools/org/h2/tools/code/CodeSwitch.java
0 → 100644
浏览文件 @
3da434bd
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
tools
.
code
;
import
java.io.*
;
import
java.util.*
;
/**
* @author Thomas
* TODO codeswitch: replace with ant 'Replace' task is possible
*/
public
class
CodeSwitch
{
private
boolean
recurse
;
private
ArrayList
list
=
new
ArrayList
();
private
ArrayList
switchOn
=
new
ArrayList
();
private
ArrayList
switchOff
=
new
ArrayList
();
private
ArrayList
switches
=
new
ArrayList
();
private
byte
[]
file
;
private
String
endOfLine
;
private
ArrayList
lines
;
private
boolean
changed
;
public
static
void
main
(
String
[]
argv
)
{
(
new
CodeSwitch
()).
run
(
argv
);
}
private
void
run
(
String
[]
a
)
{
if
(
a
.
length
==
0
)
{
showUsage
();
return
;
}
boolean
path
=
false
;
recurse
=
true
;
for
(
int
i
=
0
;
i
<
a
.
length
;
i
++)
{
String
p
=
a
[
i
];
if
(
p
.
startsWith
(
"+"
))
{
switchOn
.
add
(
p
.
substring
(
1
));
}
else
if
(
p
.
startsWith
(
"-r+"
))
{
// (default)
recurse
=
true
;
}
else
if
(
p
.
startsWith
(
"-r-"
))
{
recurse
=
false
;
}
else
if
(
p
.
startsWith
(
"-"
))
{
switchOff
.
add
(
p
.
substring
(
1
));
}
else
{
addDir
(
p
,
true
);
path
=
true
;
}
}
if
(!
path
)
{
printError
(
"no path specified"
);
showUsage
();
}
process
();
if
(
switchOff
.
size
()
==
0
&&
switchOn
.
size
()
==
0
)
{
printSwitches
();
}
}
private
void
showUsage
()
{
String
className
=
getClass
().
getName
();
System
.
out
.
println
(
"Usage: java "
+
className
+
" [-r+] [-r-] paths [+|-][labels]"
);
System
.
out
.
println
(
"If no labels are specified then all used"
);
System
.
out
.
println
(
"labels in the source code are shown."
);
System
.
out
.
println
(
"-r+ recurse subdirectories (default)"
);
System
.
out
.
println
(
"-r- do not recurse subdirectories"
);
System
.
out
.
println
(
"Use +MODE to switch on the things labeld MODE"
);
System
.
out
.
println
(
"Use -MODE to switch off the things labeld MODE"
);
System
.
out
.
println
(
"Path: Any number of path or files may be specified."
);
System
.
out
.
println
(
" Use . for the current directory (including sub-directories)."
);
System
.
out
.
println
(
"Example: java "
+
className
+
" +JAVA2 ."
);
System
.
out
.
println
(
"This example switches on code labeled JAVA2 in all *.java files"
);
System
.
out
.
println
(
"in the current directory and all subdirectories."
);
}
private
void
process
()
{
int
len
=
list
.
size
();
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
String
fileName
=
(
String
)
list
.
get
(
i
);
if
(!
processFile
(
fileName
))
{
System
.
out
.
println
(
"in file "
+
fileName
+
" - this file is skipped"
);
}
}
}
private
void
printSwitches
()
{
System
.
out
.
println
(
"Used labels:"
);
for
(
int
i
=
0
;
i
<
switches
.
size
();
i
++)
{
System
.
out
.
println
((
String
)
(
switches
.
get
(
i
)));
}
}
private
void
addDir
(
String
path
,
boolean
recurseMore
)
{
File
f
=
new
File
(
path
);
if
(
f
.
isFile
()
&&
path
.
endsWith
(
".java"
))
{
list
.
add
(
path
);
}
else
if
(
f
.
isDirectory
())
{
if
(
recurse
||
recurseMore
)
{
// one recursion at least
String
[]
files
=
f
.
list
();
for
(
int
i
=
0
;
i
<
files
.
length
;
i
++)
{
addDir
(
path
+
File
.
separatorChar
+
files
[
i
],
false
);
}
}
}
}
// lines are terminated with \r, \n or \r\n
private
void
breakIntoLines
()
{
lines
=
new
ArrayList
();
int
len
=
file
.
length
;
int
last
=
0
;
int
cr
=
0
,
lf
=
0
,
crlf
=
0
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
byte
c
=
file
[
i
];
if
(
c
==
'\r'
||
c
==
'\n'
)
{
if
(
c
==
'\r'
)
{
if
(
i
<
len
-
1
&&
file
[
i
+
1
]
==
'\n'
)
{
i
++;
crlf
++;
}
else
{
cr
++;
}
}
else
{
lf
++;
}
if
(
i
<
len
)
{
lines
.
add
(
new
String
(
file
,
last
,
i
-
last
+
1
));
last
=
i
+
1
;
}
}
}
if
(
cr
>
lf
&&
cr
>
crlf
)
{
endOfLine
=
"\r"
;
}
else
if
(
lf
>
crlf
)
{
endOfLine
=
"\n"
;
}
else
{
endOfLine
=
"\r\n"
;
}
lines
.
add
(
new
String
(
file
,
last
,
len
-
last
));
}
private
String
getLine
(
int
line
)
{
return
(
String
)
lines
.
get
(
line
);
}
private
void
insertLine
(
int
line
,
String
s
)
{
lines
.
add
(
line
,
s
);
changed
=
true
;
}
private
void
removeLine
(
int
line
)
{
lines
.
remove
(
line
);
changed
=
true
;
}
private
boolean
processFile
(
String
name
)
{
File
f
=
new
File
(
name
);
boolean
switchoff
=
false
;
boolean
working
=
false
;
int
state
=
0
;
try
{
long
rawLen
=
f
.
length
();
if
(
rawLen
>
Integer
.
MAX_VALUE
)
{
printError
(
"Files bigger than Integer.MAX_VALUE are not supported"
);
return
false
;
}
int
len
=
(
int
)
rawLen
;
file
=
new
byte
[
len
];
RandomAccessFile
read
=
new
RandomAccessFile
(
f
,
"r"
);
read
.
readFully
(
file
);
read
.
close
();
breakIntoLines
();
changed
=
false
;
for
(
int
i
=
0
;
i
<
lines
.
size
();
i
++)
{
String
line
=
getLine
(
i
);
String
lineTrim
=
line
.
trim
();
if
(
working
)
{
if
(
lineTrim
.
startsWith
(
"/*"
)
||
lineTrim
.
startsWith
(
"*/"
))
{
removeLine
(
i
);
i
--;
continue
;
}
}
if
(
lineTrim
.
startsWith
(
"//#"
))
{
if
(
lineTrim
.
startsWith
(
"//#ifdef "
))
{
if
(
state
!=
0
)
{
printError
(
"//#ifdef not allowed inside //#ifdef"
);
return
false
;
}
state
=
1
;
String
s
=
lineTrim
.
substring
(
9
);
boolean
switchedOn
=
false
;
boolean
switchedOff
=
false
;
if
(
switchOn
.
indexOf
(
s
)
!=
-
1
)
{
switchedOn
=
true
;
}
if
(
switchOff
.
indexOf
(
s
)
!=
-
1
)
{
switchedOff
=
true
;
}
if
(
s
.
indexOf
(
"&&"
)
!=
-
1
)
{
switchedOn
=
true
;
s
+=
"&&"
;
while
(
s
.
length
()
>
0
)
{
int
id
=
s
.
indexOf
(
"&&"
);
if
(
id
==
-
1
)
{
break
;
}
String
s1
=
s
.
substring
(
0
,
id
).
trim
();
s
=
s
.
substring
(
id
+
2
).
trim
();
if
(
switches
.
indexOf
(
s1
)
==
-
1
)
{
switches
.
add
(
s1
);
switchedOn
=
false
;
}
if
(
switchOn
.
indexOf
(
s1
)
==
-
1
)
{
switchedOff
=
true
;
switchedOn
=
false
;
}
if
(
switchOff
.
indexOf
(
s1
)
!=
-
1
)
{
switchedOff
=
true
;
switchedOn
=
false
;
}
}
}
if
(
switchedOn
)
{
working
=
true
;
switchoff
=
false
;
}
else
if
(
switchedOff
)
{
working
=
true
;
insertLine
(++
i
,
"/*"
+
endOfLine
);
switchoff
=
true
;
}
if
(
switches
.
indexOf
(
s
)
==
-
1
)
{
switches
.
add
(
s
);
}
}
else
if
(
lineTrim
.
startsWith
(
"//#else"
))
{
if
(
state
!=
1
)
{
printError
(
"//#else without //#ifdef"
);
return
false
;
}
state
=
2
;
if
(
working
)
{
if
(
switchoff
)
{
insertLine
(++
i
,
"*/"
+
endOfLine
);
switchoff
=
false
;
}
else
{
insertLine
(++
i
,
"/*"
+
endOfLine
);
switchoff
=
true
;
}
}
}
else
if
(
lineTrim
.
startsWith
(
"//#endif"
))
{
if
(
state
==
0
)
{
printError
(
"//#endif without //#ifdef"
);
return
false
;
}
state
=
0
;
if
(
working
&&
switchoff
)
{
insertLine
(
i
++,
"*/"
+
endOfLine
);
}
working
=
false
;
}
}
}
if
(
state
!=
0
)
{
printError
(
"//#endif missing"
);
return
false
;
}
if
(
changed
)
{
File
fnew
=
new
File
(
name
+
".new"
);
FileWriter
write
=
new
FileWriter
(
fnew
);
for
(
int
i
=
0
;
i
<
lines
.
size
();
i
++)
{
write
.
write
(
getLine
(
i
));
}
write
.
close
();
File
fbak
=
new
File
(
name
+
".bak"
);
fbak
.
delete
();
f
.
renameTo
(
fbak
);
File
fcopy
=
new
File
(
name
);
fnew
.
renameTo
(
fcopy
);
fbak
.
delete
();
System
.
out
.
println
(
name
);
}
return
true
;
}
catch
(
Exception
e
)
{
printError
(
e
);
return
false
;
}
}
private
static
void
printError
(
Exception
e
)
{
e
.
printStackTrace
();
}
private
static
void
printError
(
String
s
)
{
System
.
out
.
println
(
"ERROR: "
+
s
);
}
}
h2/src/tools/org/h2/tools/code/PropertiesToUTF8.java
0 → 100644
浏览文件 @
3da434bd
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
tools
.
code
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.InputStreamReader
;
import
java.io.OutputStreamWriter
;
import
java.io.RandomAccessFile
;
import
org.h2.server.web.PageParser
;
import
org.h2.util.IOUtils
;
import
org.h2.util.StringUtils
;
public
class
PropertiesToUTF8
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
File
[]
list
=
new
File
(
"bin/org/h2/web/res"
).
listFiles
();
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
File
f
=
list
[
i
];
if
(!
f
.
getName
().
endsWith
(
".properties"
))
{
continue
;
}
FileInputStream
in
=
new
FileInputStream
(
f
);
InputStreamReader
r
=
new
InputStreamReader
(
in
,
"UTF-8"
);
String
s
=
IOUtils
.
readStringAndClose
(
r
,
-
1
);
in
.
close
();
String
name
=
f
.
getName
();
if
(
name
.
startsWith
(
"utf8"
))
{
s
=
PageParser
.
escapeHtml
(
s
,
false
);
RandomAccessFile
out
=
new
RandomAccessFile
(
name
.
substring
(
4
),
"rw"
);
out
.
write
(
s
.
getBytes
());
out
.
close
();
}
else
{
new
CheckTextFiles
().
checkOrFixFile
(
f
,
false
,
false
);
s
=
unescapeHtml
(
s
);
s
=
StringUtils
.
javaDecode
(
s
);
FileOutputStream
out
=
new
FileOutputStream
(
"utf8"
+
f
.
getName
());
OutputStreamWriter
w
=
new
OutputStreamWriter
(
out
,
"UTF-8"
);
w
.
write
(
s
);
w
.
close
();
out
.
close
();
}
}
}
private
static
String
unescapeHtml
(
String
s
)
{
String
codes
=
"< < & & > > Ä \u00c4 Ö \u00d6 Ü \u00dc ä \u00e4 ö \u00f6 ü \u00fc ñ \u00f1 ó \u00f3 Í \u00cd ç \u00e7 &eagrave; \u00e8 ê \u00ea Ú \u00da á \u00e1 ú \u00fa é \u00e9 è \u00e8 î \u00ee"
;
String
[]
list
=
StringUtils
.
arraySplit
(
codes
,
' '
,
false
);
for
(
int
i
=
0
;
i
<
list
.
length
;
i
+=
2
)
{
s
=
StringUtils
.
replaceAll
(
s
,
list
[
i
],
list
[
i
+
1
]);
}
if
(
s
.
indexOf
(
"&"
)
>=
0
)
{
throw
new
Error
(
"??? "
+
s
);
}
return
s
;
}
}
h2/src/tools/org/h2/tools/doc/GenerateDoc.java
0 → 100644
浏览文件 @
3da434bd
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
tools
.
doc
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.ResultSet
;
import
java.sql.ResultSetMetaData
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
org.h2.bnf.Bnf
;
import
org.h2.server.web.PageParser
;
import
org.h2.tools.indexer.Indexer
;
import
org.h2.util.IOUtils
;
import
org.h2.util.StringUtils
;
public
class
GenerateDoc
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
GenerateDoc
().
run
(
args
);
}
String
inDir
=
"src/docsrc/html"
;
String
outDir
=
"docs/html"
;
Connection
conn
;
HashMap
session
=
new
HashMap
();
Bnf
bnf
;
void
run
(
String
[]
args
)
throws
Exception
{
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
if
(
args
[
i
].
equals
(
"-in"
))
{
inDir
=
args
[++
i
];
}
else
if
(
args
[
i
].
equals
(
"-out"
))
{
outDir
=
args
[++
i
];
}
}
Class
.
forName
(
"org.h2.Driver"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:."
);
new
File
(
outDir
).
mkdirs
();
bnf
=
Bnf
.
getInstance
(
null
);
map
(
"commands"
,
"SELECT * FROM INFORMATION_SCHEMA.HELP WHERE SECTION LIKE 'Commands%' ORDER BY ID"
);
map
(
"commandsDML"
,
"SELECT * FROM INFORMATION_SCHEMA.HELP WHERE SECTION='Commands (DML)' ORDER BY ID"
);
map
(
"commandsDDL"
,
"SELECT * FROM INFORMATION_SCHEMA.HELP WHERE SECTION='Commands (DDL)' ORDER BY ID"
);
map
(
"commandsOther"
,
"SELECT * FROM INFORMATION_SCHEMA.HELP WHERE SECTION='Commands (Other)' ORDER BY ID"
);
map
(
"otherGrammar"
,
"SELECT * FROM INFORMATION_SCHEMA.HELP WHERE SECTION='Other Grammar' ORDER BY ID"
);
map
(
"functionsAggregate"
,
"SELECT * FROM INFORMATION_SCHEMA.HELP WHERE SECTION = 'Functions (Aggregate)' ORDER BY ID"
);
map
(
"functionsNumeric"
,
"SELECT * FROM INFORMATION_SCHEMA.HELP WHERE SECTION = 'Functions (Numeric)' ORDER BY ID"
);
map
(
"functionsString"
,
"SELECT * FROM INFORMATION_SCHEMA.HELP WHERE SECTION = 'Functions (String)' ORDER BY ID"
);
map
(
"functionsTimeDate"
,
"SELECT * FROM INFORMATION_SCHEMA.HELP WHERE SECTION = 'Functions (Time and Date)' ORDER BY ID"
);
map
(
"functionsSystem"
,
"SELECT * FROM INFORMATION_SCHEMA.HELP WHERE SECTION = 'Functions (System)' ORDER BY ID"
);
map
(
"functionsAll"
,
"SELECT * FROM INFORMATION_SCHEMA.HELP WHERE SECTION LIKE 'Functions%' ORDER BY SECTION, ID"
);
map
(
"dataTypes"
,
"SELECT * FROM INFORMATION_SCHEMA.HELP WHERE SECTION LIKE 'Data Types%' ORDER BY SECTION, ID"
);
process
(
"grammar"
);
process
(
"functions"
);
process
(
"datatypes"
);
conn
.
close
();
Indexer
.
main
(
new
String
[
0
]);
}
void
process
(
String
fileName
)
throws
Exception
{
FileOutputStream
fout
=
new
FileOutputStream
(
outDir
+
"/"
+
fileName
+
".html"
);
FileInputStream
fin
=
new
FileInputStream
(
inDir
+
"/"
+
fileName
+
".jsp"
);
byte
[]
bytes
=
IOUtils
.
readBytesAndClose
(
fin
,
0
);
String
page
=
new
String
(
bytes
);
page
=
PageParser
.
parse
(
null
,
page
,
session
);
fout
.
write
(
page
.
getBytes
());
fout
.
close
();
}
void
map
(
String
key
,
String
sql
)
throws
Exception
{
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
sql
);
ArrayList
list
=
new
ArrayList
();
while
(
rs
.
next
())
{
HashMap
map
=
new
HashMap
();
ResultSetMetaData
meta
=
rs
.
getMetaData
();
for
(
int
i
=
0
;
i
<
meta
.
getColumnCount
();
i
++)
{
String
k
=
StringUtils
.
toLowerEnglish
(
meta
.
getColumnLabel
(
i
+
1
));
String
value
=
rs
.
getString
(
i
+
1
);
map
.
put
(
k
,
PageParser
.
escapeHtml
(
value
));
}
String
topic
=
rs
.
getString
(
"TOPIC"
);
String
syntax
=
rs
.
getString
(
"SYNTAX"
);
syntax
=
bnf
.
getSyntax
(
topic
,
syntax
);
map
.
put
(
"syntax"
,
syntax
);
list
.
add
(
map
);
}
session
.
put
(
key
,
list
);
}
}
h2/src/tools/org/h2/tools/doc/LinkChecker.java
0 → 100644
浏览文件 @
3da434bd
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
tools
.
doc
;
import
java.io.File
;
import
java.io.FileReader
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
org.h2.util.IOUtils
;
import
org.h2.util.StartBrowser
;
import
org.h2.util.StringUtils
;
public
class
LinkChecker
{
private
static
final
boolean
OPEN_EXTERNAL_LINKS
=
false
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
LinkChecker
().
run
(
args
);
}
private
HashMap
targets
=
new
HashMap
();
private
HashMap
links
=
new
HashMap
();
private
void
run
(
String
[]
args
)
throws
Exception
{
String
dir
=
"src/docsrc"
;
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
if
(
"-dir"
.
equals
(
args
[
i
]))
{
dir
=
args
[++
i
];
}
}
process
(
dir
);
listExternalLinks
();
listBadLinks
();
}
void
listExternalLinks
()
{
for
(
Iterator
it
=
links
.
keySet
().
iterator
();
it
.
hasNext
();
)
{
String
link
=
(
String
)
it
.
next
();
if
(
link
.
startsWith
(
"http"
))
{
if
(
link
.
indexOf
(
"//localhost"
)>
0
)
{
continue
;
}
if
(
OPEN_EXTERNAL_LINKS
)
{
StartBrowser
.
openURL
(
link
);
}
System
.
out
.
println
(
"External Link: "
+
link
);
}
}
}
void
listBadLinks
()
throws
Exception
{
ArrayList
errors
=
new
ArrayList
();
for
(
Iterator
it
=
links
.
keySet
().
iterator
();
it
.
hasNext
();
)
{
String
link
=
(
String
)
it
.
next
();
if
(!
link
.
startsWith
(
"http"
)
&&
!
link
.
endsWith
(
"h2.pdf"
))
{
if
(
targets
.
get
(
link
)
==
null
)
{
errors
.
add
(
links
.
get
(
link
)
+
": missing link "
+
link
);
}
}
}
for
(
Iterator
it
=
links
.
keySet
().
iterator
();
it
.
hasNext
();
)
{
String
link
=
(
String
)
it
.
next
();
if
(!
link
.
startsWith
(
"http"
))
{
targets
.
remove
(
link
);
}
}
for
(
Iterator
it
=
targets
.
keySet
().
iterator
();
it
.
hasNext
();
)
{
String
name
=
(
String
)
it
.
next
();
if
(
targets
.
get
(
name
).
equals
(
"name"
))
{
errors
.
add
(
"No link to "
+
name
);
}
}
Collections
.
sort
(
errors
);
for
(
int
i
=
0
;
i
<
errors
.
size
();
i
++)
{
System
.
out
.
println
(
errors
.
get
(
i
));
}
if
(
errors
.
size
()
>
0
)
{
throw
new
Exception
(
"Problems where found by the Link Checker"
);
}
}
void
process
(
String
path
)
throws
Exception
{
if
(
path
.
endsWith
(
"/CVS"
))
{
return
;
}
File
file
=
new
File
(
path
);
if
(
file
.
isDirectory
())
{
String
[]
list
=
file
.
list
();
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
process
(
path
+
"/"
+
list
[
i
]);
}
}
else
{
processFile
(
path
);
}
}
void
processFile
(
String
path
)
throws
Exception
{
targets
.
put
(
path
,
"file"
);
String
lower
=
StringUtils
.
toLowerEnglish
(
path
);
if
(!
lower
.
endsWith
(
".html"
)
&&
!
lower
.
endsWith
(
".htm"
))
{
return
;
}
String
fileName
=
new
File
(
path
).
getName
();
String
parent
=
path
.
substring
(
0
,
path
.
lastIndexOf
(
'/'
));
String
html
=
IOUtils
.
readStringAndClose
(
new
FileReader
(
path
),
-
1
);
int
idx
=
-
1
;
while
(
true
)
{
idx
=
html
.
indexOf
(
" id=\""
,
idx
+
1
);
if
(
idx
<
0
)
{
break
;
}
int
start
=
idx
+
4
;
int
end
=
html
.
indexOf
(
"\""
,
start
+
1
);
if
(
end
<
0
)
{
error
(
fileName
,
"expected \" after id= "
+
html
.
substring
(
idx
,
idx
+
100
));
}
String
ref
=
html
.
substring
(
start
+
1
,
end
);
targets
.
put
(
path
+
"#"
+
ref
,
"id"
);
}
idx
=
-
1
;
while
(
true
)
{
idx
=
html
.
indexOf
(
"<a "
,
idx
+
1
);
if
(
idx
<
0
)
{
break
;
}
int
equals
=
html
.
indexOf
(
"="
,
idx
);
if
(
equals
<
0
)
{
error
(
fileName
,
"expected = after <a at "
+
html
.
substring
(
idx
,
idx
+
100
));
}
String
type
=
html
.
substring
(
idx
+
2
,
equals
).
trim
();
int
start
=
html
.
indexOf
(
"\""
,
idx
);
if
(
start
<
0
)
{
error
(
fileName
,
"expected \" after <a at "
+
html
.
substring
(
idx
,
idx
+
100
));
}
int
end
=
html
.
indexOf
(
"\""
,
start
+
1
);
if
(
end
<
0
)
{
error
(
fileName
,
"expected \" after <a at "
+
html
.
substring
(
idx
,
idx
+
100
));
}
String
ref
=
html
.
substring
(
start
+
1
,
end
);
if
(
type
.
equals
(
"href"
))
{
if
(
ref
.
startsWith
(
"http:"
)
||
ref
.
startsWith
(
"https:"
))
{
// ok
}
else
if
(
ref
.
startsWith
(
"#"
))
{
ref
=
path
+
ref
;
}
else
{
String
p
=
parent
;
while
(
ref
.
startsWith
(
"."
))
{
if
(
ref
.
startsWith
(
"./"
))
{
ref
=
ref
.
substring
(
2
);
}
else
if
(
ref
.
startsWith
(
"../"
))
{
ref
=
ref
.
substring
(
3
);
p
=
p
.
substring
(
0
,
p
.
lastIndexOf
(
'/'
));
}
}
ref
=
p
+
"/"
+
ref
;
}
links
.
put
(
ref
,
path
);
}
else
if
(
type
.
equals
(
"name"
))
{
targets
.
put
(
path
+
"#"
+
ref
,
"name"
);
}
else
{
error
(
fileName
,
"unsupported <a xxx: "
+
html
.
substring
(
idx
,
idx
+
100
));
}
}
}
private
void
error
(
String
fileName
,
String
string
)
{
System
.
out
.
println
(
"ERROR with "
+
fileName
+
": "
+
string
);
}
}
h2/src/tools/org/h2/tools/doc/MergeDocs.java
0 → 100644
浏览文件 @
3da434bd
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
tools
.
doc
;
import
java.io.File
;
import
java.io.FileReader
;
import
java.io.FileWriter
;
import
java.io.PrintWriter
;
import
org.h2.util.StringUtils
;
public
class
MergeDocs
{
String
baseDir
=
"docs/html"
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
MergeDocs
().
run
(
args
);
}
private
void
run
(
String
[]
args
)
throws
Exception
{
String
[]
pages
=
{
"quickstartText.html"
,
"installation.html"
,
"tutorial.html"
,
"features.html"
,
"performance.html"
,
"advanced.html"
,
"grammar.html"
,
"functions.html"
,
"datatypes.html"
,
"build.html"
,
"history.html"
,
"faq.html"
,
"license.html"
};
String
finalText
=
""
;
for
(
int
i
=
0
;
i
<
pages
.
length
;
i
++)
{
String
text
=
getContent
(
pages
[
i
]);
for
(
int
j
=
0
;
j
<
pages
.
length
;
j
++)
{
text
=
StringUtils
.
replaceAll
(
text
,
pages
[
j
]
+
"#"
,
"#"
);
}
text
=
removeHeaderFooter
(
text
);
finalText
+=
text
;
}
File
output
=
new
File
(
baseDir
,
"onePage.html"
);
PrintWriter
writer
=
new
PrintWriter
(
new
FileWriter
(
output
));
writer
.
println
(
"<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"><title>"
);
writer
.
println
(
"H2 Documentation"
);
writer
.
println
(
"</title><link rel=\"stylesheet\" type=\"text/css\" href=\"stylesheetPdf.css\"></head><body>"
);
writer
.
println
(
finalText
);
writer
.
println
(
"</body></html>"
);
writer
.
close
();
}
private
String
removeHeaderFooter
(
String
text
)
{
// String start = "<body";
// String end = "</body>";
String
start
=
"<div class=\"contentDiv\""
;
String
end
=
"</div></td></tr></table></body></html>"
;
int
idx
=
text
.
indexOf
(
end
);
text
=
text
.
substring
(
0
,
idx
);
idx
=
text
.
indexOf
(
start
);
idx
=
text
.
indexOf
(
'>'
,
idx
);
text
=
text
.
substring
(
idx
+
1
);
return
text
;
}
String
getContent
(
String
fileName
)
throws
Exception
{
File
file
=
new
File
(
baseDir
,
fileName
);
int
length
=
(
int
)
file
.
length
();
char
[]
data
=
new
char
[
length
];
FileReader
reader
=
new
FileReader
(
file
);
int
off
=
0
;
while
(
length
>
0
)
{
int
len
=
reader
.
read
(
data
,
off
,
length
);
off
+=
len
;
length
-=
len
;
}
reader
.
close
();
String
s
=
new
String
(
data
);
return
s
;
}
}
h2/src/tools/org/h2/tools/doclet/Doclet.java
0 → 100644
浏览文件 @
3da434bd
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
tools
.
doclet
;
import
java.io.BufferedWriter
;
import
java.io.File
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.util.Arrays
;
import
java.util.Comparator
;
import
com.sun.javadoc.ClassDoc
;
import
com.sun.javadoc.FieldDoc
;
import
com.sun.javadoc.MethodDoc
;
import
com.sun.javadoc.ParamTag
;
import
com.sun.javadoc.Parameter
;
import
com.sun.javadoc.RootDoc
;
import
com.sun.javadoc.Tag
;
import
com.sun.javadoc.ThrowsTag
;
import
com.sun.javadoc.Type
;
public
class
Doclet
{
public
static
boolean
start
(
RootDoc
root
)
throws
IOException
{
ClassDoc
[]
classes
=
root
.
classes
();
String
[][]
options
=
root
.
options
();
String
destDir
=
"docs/javadoc"
;
for
(
int
i
=
0
;
i
<
options
.
length
;
i
++)
{
if
(
options
[
i
][
0
].
equals
(
"destdir"
))
{
destDir
=
options
[
i
][
1
];
}
}
for
(
int
i
=
0
;
i
<
classes
.
length
;
++
i
)
{
ClassDoc
clazz
=
classes
[
i
];
processClass
(
destDir
,
clazz
);
}
return
true
;
}
private
static
String
getClass
(
String
name
)
{
if
(
name
.
startsWith
(
"Jdbc"
))
{
return
name
.
substring
(
4
);
}
return
name
;
}
private
static
void
processClass
(
String
destDir
,
ClassDoc
clazz
)
throws
IOException
{
String
packageName
=
clazz
.
containingPackage
().
name
();
String
dir
=
destDir
+
"/"
+
packageName
.
replace
(
'.'
,
'/'
);
(
new
File
(
dir
)).
mkdirs
();
String
fileName
=
dir
+
"/"
+
clazz
.
name
()
+
".html"
;
String
className
=
getClass
(
clazz
.
name
());
FileWriter
out
=
new
FileWriter
(
fileName
);
PrintWriter
writer
=
new
PrintWriter
(
new
BufferedWriter
(
out
));
writer
.
println
(
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"
);
writer
.
println
(
"<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"><title>"
);
writer
.
println
(
className
);
writer
.
println
(
"</title><link rel=\"stylesheet\" type=\"text/css\" href=\"../../../stylesheet.css\"></head><body>"
);
writer
.
println
(
"<table class=\"content\"><tr class=\"content\"><td class=\"content\"><div class=\"contentDiv\">"
);
writer
.
println
(
"<h1>"
+
className
+
"</h1>"
);
writer
.
println
(
clazz
.
commentText
()+
"<br /><br />"
);
MethodDoc
[]
methods
=
clazz
.
methods
();
Arrays
.
sort
(
methods
,
new
Comparator
()
{
public
int
compare
(
Object
a
,
Object
b
)
{
return
((
MethodDoc
)
a
).
name
().
compareTo
(((
MethodDoc
)
b
).
name
());
}
});
writer
.
println
(
"<table><tr><th colspan=\"2\">Methods</th></tr>"
);
for
(
int
i
=
0
;
i
<
methods
.
length
;
i
++)
{
MethodDoc
method
=
methods
[
i
];
String
name
=
method
.
name
();
if
(
skipMethod
(
method
))
{
continue
;
}
String
type
=
getTypeName
(
method
.
isStatic
(),
method
.
returnType
());
writer
.
println
(
"<tr><td class=\"return\">"
+
type
+
"</td><td class=\"method\">"
);
Parameter
[]
params
=
method
.
parameters
();
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
'('
);
for
(
int
j
=
0
;
j
<
params
.
length
;
j
++)
{
if
(
j
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
getTypeName
(
false
,
params
[
j
].
type
()));
buff
.
append
(
' '
);
buff
.
append
(
params
[
j
].
name
());
}
buff
.
append
(
')'
);
if
(
isDeprecated
(
method
))
{
name
=
"<span class=\"deprecated\">"
+
name
+
"</span>"
;
}
writer
.
println
(
"<a href=\"#r"
+
i
+
"\">"
+
name
+
"</a>"
+
buff
.
toString
());
String
firstSentence
=
getFirstSentence
(
method
.
firstSentenceTags
());
if
(
firstSentence
!=
null
)
{
writer
.
println
(
"<div class=\"methodText\">"
+
firstSentence
+
"</div>"
);
}
writer
.
println
(
"</td></tr>"
);
}
writer
.
println
(
"</table>"
);
FieldDoc
[]
fields
=
clazz
.
fields
();
if
(
clazz
.
interfaces
().
length
>
0
)
{
fields
=
clazz
.
interfaces
()[
0
].
fields
();
}
Arrays
.
sort
(
fields
,
new
Comparator
()
{
public
int
compare
(
Object
a
,
Object
b
)
{
return
((
FieldDoc
)
a
).
name
().
compareTo
(((
FieldDoc
)
b
).
name
());
}
});
int
fieldId
=
0
;
for
(
int
i
=
0
;
i
<
fields
.
length
;
i
++)
{
FieldDoc
field
=
fields
[
i
];
if
(!
field
.
isFinal
()
||
!
field
.
isStatic
()
||
!
field
.
isPublic
())
{
continue
;
}
if
(
fieldId
==
0
)
{
writer
.
println
(
"<br /><table><tr><th colspan=\"2\">Fields</th></tr>"
);
}
String
name
=
field
.
name
();
String
type
=
getTypeName
(
true
,
field
.
type
());
writer
.
println
(
"<tr><td class=\"return\">"
+
type
+
"</td><td class=\"method\">"
);
//writer.println("<a href=\"#f" + fieldId + "\">" + name + "</a>");
writer
.
println
(
name
+
" = "
+
field
.
constantValueExpression
());
String
firstSentence
=
getFirstSentence
(
field
.
firstSentenceTags
());
if
(
firstSentence
!=
null
)
{
writer
.
println
(
"<div class=\"methodText\">"
+
firstSentence
+
"</div>"
);
}
writer
.
println
(
"</td></tr>"
);
fieldId
++;
}
if
(
fieldId
>
0
)
{
writer
.
println
(
"</table>"
);
}
for
(
int
i
=
0
;
i
<
methods
.
length
;
i
++)
{
MethodDoc
method
=
methods
[
i
];
String
name
=
method
.
name
();
if
(
skipMethod
(
method
))
{
continue
;
}
String
type
=
getTypeName
(
method
.
isStatic
(),
method
.
returnType
());
writer
.
println
(
"<a name=\"r"
+
i
+
"\"></a>"
);
Parameter
[]
params
=
method
.
parameters
();
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
'('
);
for
(
int
j
=
0
;
j
<
params
.
length
;
j
++)
{
if
(
j
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
getTypeName
(
false
,
params
[
j
].
type
()));
buff
.
append
(
' '
);
buff
.
append
(
params
[
j
].
name
());
}
buff
.
append
(
')'
);
ClassDoc
[]
exceptions
=
method
.
thrownExceptions
();
if
(
exceptions
.
length
>
0
)
{
buff
.
append
(
" throws "
);
for
(
int
k
=
0
;
k
<
exceptions
.
length
;
k
++)
{
if
(
k
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
exceptions
[
k
].
typeName
());
}
}
if
(
isDeprecated
(
method
))
{
name
=
"<span class=\"deprecated\">"
+
name
+
"</span>"
;
}
writer
.
println
(
"<h4>"
+
type
+
" <span class=\"methodName\">"
+
name
+
"</span>"
+
buff
.
toString
()+
"</h4>"
);
writer
.
println
(
method
.
commentText
());
ParamTag
[]
paramTags
=
method
.
paramTags
();
boolean
space
=
false
;
for
(
int
j
=
0
;
j
<
paramTags
.
length
;
j
++)
{
if
(!
space
)
{
writer
.
println
(
"<br /><br >"
);
space
=
true
;
}
String
p
=
paramTags
[
j
].
parameterName
()
+
" - "
+
paramTags
[
j
].
parameterComment
();
if
(
j
==
0
)
{
writer
.
println
(
"<div class=\"itemTitle\">Parameters:</div>"
);
}
writer
.
println
(
"<div class=\"item\">"
+
p
+
"</div>"
);
}
Tag
[]
returnTags
=
method
.
tags
(
"return"
);
if
(
returnTags
!=
null
&&
returnTags
.
length
>
0
)
{
if
(!
space
)
{
writer
.
println
(
"<br /><br >"
);
space
=
true
;
}
writer
.
println
(
"<div class=\"itemTitle\">Returns:</div>"
);
writer
.
println
(
"<div class=\"item\">"
+
returnTags
[
0
].
text
()+
"</div>"
);
}
ThrowsTag
[]
throwsTags
=
method
.
throwsTags
();
if
(
throwsTags
!=
null
&&
throwsTags
.
length
>
0
)
{
if
(!
space
)
{
writer
.
println
(
"<br /><br >"
);
space
=
true
;
}
writer
.
println
(
"<div class=\"itemTitle\">Throws:</div>"
);
for
(
int
j
=
0
;
j
<
throwsTags
.
length
;
j
++)
{
String
p
=
throwsTags
[
j
].
exceptionName
();
String
c
=
throwsTags
[
j
].
exceptionComment
();
if
(
c
.
length
()
>
0
)
{
p
+=
" - "
+
c
;
}
writer
.
println
(
"<div class=\"item\">"
+
p
+
"</div>"
);
}
}
writer
.
println
(
"<hr>"
);
}
writer
.
println
(
"</div></td></tr></table></body></html>"
);
writer
.
close
();
out
.
close
();
}
private
static
boolean
skipMethod
(
MethodDoc
method
)
{
String
name
=
method
.
name
();
if
(!
method
.
isPublic
()
||
name
.
equals
(
"finalize"
))
{
return
true
;
}
if
(
method
.
getRawCommentText
().
startsWith
(
"@deprecated INTERNAL"
))
{
return
true
;
}
String
firstSentence
=
getFirstSentence
(
method
.
firstSentenceTags
());
if
(
firstSentence
==
null
||
firstSentence
.
trim
().
length
()==
0
)
{
throw
new
Error
(
"undocumented method? "
+
name
+
" "
+
method
.
containingClass
().
name
()+
" "
+
method
.
getRawCommentText
());
}
if
(
firstSentence
.
startsWith
(
"INTERNAL"
))
{
return
true
;
}
return
false
;
}
private
static
String
getFirstSentence
(
Tag
[]
tags
)
{
String
firstSentence
=
null
;
if
(
tags
.
length
>
0
)
{
Tag
first
=
tags
[
0
];
firstSentence
=
first
.
text
();
}
return
firstSentence
;
}
private
static
String
getTypeName
(
boolean
isStatic
,
Type
type
)
{
String
s
=
type
.
typeName
()
+
type
.
dimension
();
if
(
isStatic
)
{
s
=
"static "
+
s
;
}
return
s
;
}
private
static
boolean
isDeprecated
(
MethodDoc
method
)
{
Tag
[]
tags
=
method
.
tags
();
boolean
deprecated
=
false
;
for
(
int
j
=
0
;
j
<
tags
.
length
;
j
++)
{
Tag
t
=
tags
[
j
];
if
(
t
.
kind
().
equals
(
"@deprecated"
))
{
deprecated
=
true
;
}
}
return
deprecated
;
}
}
h2/src/tools/org/h2/tools/indexer/HtmlConverter.java
0 → 100644
浏览文件 @
3da434bd
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
tools
.
indexer
;
import
java.util.HashMap
;
public
class
HtmlConverter
{
private
static
HashMap
charMap
=
new
HashMap
();
private
static
final
String
[]
CHARS
=
{
"quot:34"
,
"amp:38"
,
"lt:60"
,
"gt:62"
,
"nbsp:160"
,
"iexcl:161"
,
"cent:162"
,
"pound:163"
,
"curren:164"
,
"yen:165"
,
"brvbar:166"
,
"sect:167"
,
"uml:168"
,
"copy:169"
,
"ordf:170"
,
"laquo:171"
,
"not:172"
,
"shy:173"
,
"reg:174"
,
"macr:175"
,
"deg:176"
,
"plusmn:177"
,
"sup2:178"
,
"sup3:179"
,
"acute:180"
,
"micro:181"
,
"para:182"
,
"middot:183"
,
"cedil:184"
,
"sup1:185"
,
"ordm:186"
,
"raquo:187"
,
"frac14:188"
,
"frac12:189"
,
"frac34:190"
,
"iquest:191"
,
"Agrave:192"
,
"Aacute:193"
,
"Acirc:194"
,
"Atilde:195"
,
"Auml:196"
,
"Aring:197"
,
"AElig:198"
,
"Ccedil:199"
,
"Egrave:200"
,
"Eacute:201"
,
"Ecirc:202"
,
"Euml:203"
,
"Igrave:204"
,
"Iacute:205"
,
"Icirc:206"
,
"Iuml:207"
,
"ETH:208"
,
"Ntilde:209"
,
"Ograve:210"
,
"Oacute:211"
,
"Ocirc:212"
,
"Otilde:213"
,
"Ouml:214"
,
"times:215"
,
"Oslash:216"
,
"Ugrave:217"
,
"Uacute:218"
,
"Ucirc:219"
,
"Uuml:220"
,
"Yacute:221"
,
"THORN:222"
,
"szlig:223"
,
"agrave:224"
,
"aacute:225"
,
"acirc:226"
,
"atilde:227"
,
"auml:228"
,
"aring:229"
,
"aelig:230"
,
"ccedil:231"
,
"egrave:232"
,
"eacute:233"
,
"ecirc:234"
,
"euml:235"
,
"igrave:236"
,
"iacute:237"
,
"icirc:238"
,
"iuml:239"
,
"eth:240"
,
"ntilde:241"
,
"ograve:242"
,
"oacute:243"
,
"ocirc:244"
,
"otilde:245"
,
"ouml:246"
,
"divide:247"
,
"oslash:248"
,
"ugrave:249"
,
"uacute:250"
,
"ucirc:251"
,
"uuml:252"
,
"yacute:253"
,
"thorn:254"
,
"yuml:255"
,
"Alpha:913"
,
"alpha:945"
,
"Beta:914"
,
"beta:946"
,
"Gamma:915"
,
"gamma:947"
,
"Delta:916"
,
"delta:948"
,
"Epsilon:917"
,
"epsilon:949"
,
"Zeta:918"
,
"zeta:950"
,
"Eta:919"
,
"eta:951"
,
"Theta:920"
,
"theta:952"
,
"Iota:921"
,
"iota:953"
,
"Kappa:922"
,
"kappa:954"
,
"Lambda:923"
,
"lambda:955"
,
"Mu:924"
,
"mu:956"
,
"Nu:925"
,
"nu:957"
,
"Xi:926"
,
"xi:958"
,
"Omicron:927"
,
"omicron:959"
,
"Pi:928"
,
"pi:960"
,
"Rho:929"
,
"rho:961"
,
"Sigma:931"
,
"sigmaf:962"
,
"sigma:963"
,
"Tau:932"
,
"tau:964"
,
"Upsilon:933"
,
"upsilon:965"
,
"Phi:934"
,
"phi:966"
,
"Chi:935"
,
"chi:967"
,
"Psi:936"
,
"psi:968"
,
"Omega:937"
,
"omega:969"
,
"thetasym:977"
,
"upsih:978"
,
"piv:982"
,
"forall:8704"
,
"part:8706"
,
"exist:8707"
,
"empty:8709"
,
"nabla:8711"
,
"isin:8712"
,
"notin:8713"
,
"ni:8715"
,
"prod:8719"
,
"sum:8721"
,
"minus:8722"
,
"lowast:8727"
,
"radic:8730"
,
"prop:8733"
,
"infin:8734"
,
"ang:8736"
,
"and:8743"
,
"or:8744"
,
"cap:8745"
,
"cup:8746"
,
"int:8747"
,
"there4:8756"
,
"sim:8764"
,
"cong:8773"
,
"asymp:8776"
,
"ne:8800"
,
"equiv:8801"
,
"le:8804"
,
"ge:8805"
,
"sub:8834"
,
"sup:8835"
,
"nsub:8836"
,
"sube:8838"
,
"supe:8839"
,
"oplus:8853"
,
"otimes:8855"
,
"perp:8869"
,
"sdot:8901"
,
"loz:9674"
,
"lceil:8968"
,
"rceil:8969"
,
"lfloor:8970"
,
"rfloor:8971"
,
"lang:9001"
,
"rang:9002"
,
"larr:8592"
,
"uarr:8593"
,
"rarr:8594"
,
"darr:8595"
,
"harr:8596"
,
"crarr:8629"
,
"lArr:8656"
,
"uArr:8657"
,
"rArr:8658"
,
"dArr:8659"
,
"hArr:8660"
,
"bull:8226"
,
"prime:8242"
,
"oline:8254"
,
"frasl:8260"
,
"weierp:8472"
,
"image:8465"
,
"real:8476"
,
"trade:8482"
,
"euro:8364"
,
"alefsym:8501"
,
"spades:9824"
,
"clubs:9827"
,
"hearts:9829"
,
"diams:9830"
,
"ensp:8194"
,
"emsp:8195"
,
"thinsp:8201"
,
"zwnj:8204"
,
"zwj:8205"
,
"lrm:8206"
,
"rlm:8207"
,
"ndash:8211"
,
"mdash:8212"
,
"lsquo:8216"
,
"rsquo:8217"
,
"sbquo:8218"
,
"ldquo:8220"
,
"rdquo:8221"
,
"bdquo:8222"
,
"dagger:8224"
,
"Dagger:8225"
,
"hellip:8230"
,
"permil:8240"
,
"lsaquo:8249"
,
"rsaquo:8250"
};
static
{
for
(
int
i
=
0
;
i
<
CHARS
.
length
;
i
++)
{
String
token
=
CHARS
[
i
];
int
idx
=
token
.
indexOf
(
':'
);
String
key
=
token
.
substring
(
0
,
idx
);
int
ch
=
Integer
.
parseInt
(
token
.
substring
(
idx
+
1
));
charMap
.
put
(
key
,
new
Character
((
char
)
ch
));
}
}
public
static
String
convertHtml
(
String
html
)
{
if
(
html
==
null
)
{
return
null
;
}
if
(
html
.
length
()
==
0
)
{
return
html
;
}
if
(
html
.
indexOf
(
'&'
)
<
0
)
{
return
html
;
}
StringBuffer
buff
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
html
.
length
();
i
++)
{
char
ch
=
html
.
charAt
(
i
);
if
(
ch
!=
'&'
)
{
buff
.
append
(
ch
);
continue
;
}
int
idx
=
html
.
indexOf
(
';'
,
i
+
1
);
if
(
idx
<
0
)
{
buff
.
append
(
"???"
);
continue
;
}
String
key
=
html
.
substring
(
i
+
1
,
idx
);
Character
repl
;
if
(
key
.
startsWith
(
"#"
))
{
try
{
int
code
=
Integer
.
parseInt
(
key
.
substring
(
1
));
if
(
code
<
0
||
code
>
0xffff
)
{
repl
=
null
;
}
else
{
repl
=
new
Character
((
char
)
code
);
}
}
catch
(
NumberFormatException
e
)
{
repl
=
null
;
}
}
else
{
repl
=
(
Character
)
charMap
.
get
(
key
);
}
if
(
repl
==
null
)
{
buff
.
append
(
"???"
+
key
+
"???"
);
continue
;
}
else
{
buff
.
append
(
repl
.
charValue
());
}
i
=
idx
;
}
return
buff
.
toString
();
}
}
h2/src/tools/org/h2/tools/indexer/Indexer.java
0 → 100644
浏览文件 @
3da434bd
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
tools
.
indexer
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileWriter
;
import
java.io.PrintWriter
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.StringTokenizer
;
import
org.h2.util.IOUtils
;
import
org.h2.util.StringUtils
;
public
class
Indexer
{
ArrayList
pages
=
new
ArrayList
();
HashMap
words
=
new
HashMap
();
HashSet
noIndex
=
new
HashSet
();
ArrayList
wordList
;
int
totalAllWeights
;
PrintWriter
output
;
Page
page
;
boolean
title
;
boolean
heading
;
private
static
final
int
MIN_WORDSIZE
=
3
;
private
static
final
int
MAX_RELATIONS
=
20
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
String
dir
=
"docs"
;
String
destDir
=
"docs/html"
;
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
if
(
args
[
i
].
equals
(
"-dir"
))
{
dir
=
args
[++
i
];
}
else
if
(
args
[
i
].
equals
(
"-destDir"
))
{
destDir
=
args
[++
i
];
}
}
Indexer
app
=
new
Indexer
();
File
file
=
new
File
(
dir
);
System
.
out
.
println
(
"indexing "
+
file
.
getCanonicalPath
());
// File file = new File("C:\\Programs\\selfhtml81");
// File file = new File("C:\\Programme\\selfhtml81");
app
.
setNoIndex
(
new
String
[]
{
"index.html"
,
"html/header.html"
,
"html/search.html"
,
"html/frame.html"
,
"javadoc/index.html"
,
"javadoc/classes.html"
,
"javadoc/allclasses-frame.html"
,
"javadoc/allclasses-noframe.html"
,
"javadoc/constant-values.html"
,
"javadoc/overview-frame.html"
,
"javadoc/overview-summary.html"
,
"javadoc/serialized-form.html"
});
app
.
output
=
new
PrintWriter
(
new
FileWriter
(
destDir
+
"/index.js"
));
app
.
readPages
(
""
,
file
,
0
);
app
.
output
.
println
(
"var pages=new Array();"
);
app
.
output
.
println
(
"var ref=new Array();"
);
app
.
output
.
println
(
"function Page(title, file) { this.title=title; this.file=file; }"
);
app
.
output
.
println
(
"function load() {"
);
app
.
sortWords
();
app
.
removeOverflowRelations
();
app
.
sortPages
();
app
.
listPages
();
app
.
listWords
();
app
.
output
.
println
(
"}"
);
app
.
output
.
close
();
}
private
void
setNoIndex
(
String
[]
strings
)
{
for
(
int
i
=
0
;
i
<
strings
.
length
;
i
++)
{
noIndex
.
add
(
strings
[
i
]);
}
}
void
sortWords
()
{
wordList
=
new
ArrayList
(
words
.
values
());
// TODO support ignored keywords (to shrink the index)
// String ignored = "";
// for(int i=0; i<wordList.size(); i++) {
// Word word = (Word) wordList.get(i);
// if(word.pages.size() >= pages.size()/4) {
// wordList.remove(i);
// if(ignored.length()==0) {
// ignored += ",";
// }
// ignored += word.name;
// i--;
// }
// }
// output.println("var ignored = '" + convertUTF(ignored) + "'");
// TODO support A, B, C,... class links in the index file and use them for combined AND searches
Collections
.
sort
(
wordList
,
new
Comparator
()
{
public
int
compare
(
Object
o0
,
Object
o1
)
{
Word
w0
=
(
Word
)
o0
;
Word
w1
=
(
Word
)
o1
;
return
w0
.
name
.
compareToIgnoreCase
(
w1
.
name
);
}
});
}
void
removeOverflowRelations
()
{
for
(
int
i
=
0
;
i
<
wordList
.
size
();
i
++)
{
Word
word
=
(
Word
)
wordList
.
get
(
i
);
ArrayList
weights
=
word
.
getSortedWeights
();
int
max
=
MAX_RELATIONS
;
if
(
weights
.
size
()
>
max
)
{
while
(
max
<
weights
.
size
())
{
Weight
weight
=
(
Weight
)
weights
.
get
(
max
);
if
(
weight
.
value
<
Weight
.
HEADER
)
{
break
;
}
max
++;
}
}
while
(
max
<
weights
.
size
())
{
Weight
weight
=
(
Weight
)
weights
.
get
(
max
);
weights
.
remove
(
max
);
weight
.
page
.
relations
--;
}
}
}
void
sortPages
()
{
Collections
.
sort
(
pages
,
new
Comparator
()
{
public
int
compare
(
Object
o0
,
Object
o1
)
{
Page
p0
=
(
Page
)
o0
;
Page
p1
=
(
Page
)
o1
;
return
p0
.
relations
==
p1
.
relations
?
0
:
p0
.
relations
<
p1
.
relations
?
1
:
-
1
;
}
});
for
(
int
i
=
0
;
i
<
pages
.
size
();
i
++)
{
Page
page
=
(
Page
)
pages
.
get
(
i
);
page
.
id
=
i
;
}
}
void
listPages
()
{
for
(
int
i
=
0
;
i
<
pages
.
size
();
i
++)
{
Page
page
=
(
Page
)
pages
.
get
(
i
);
output
.
println
(
"pages["
+
page
.
id
+
"]=new Page('"
+
convertUTF
(
page
.
title
)+
"', '"
+
page
.
fileName
+
"');"
);
}
}
void
readPages
(
String
dir
,
File
file
,
int
level
)
throws
Exception
{
String
name
=
file
.
getName
();
String
fileName
=
dir
.
length
()
>
0
?
dir
+
"/"
+
name
:
level
>
0
?
name
:
""
;
if
(
file
.
isDirectory
())
{
File
[]
list
=
file
.
listFiles
();
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
readPages
(
fileName
,
list
[
i
],
level
+
1
);
}
return
;
}
String
lower
=
StringUtils
.
toLowerEnglish
(
name
);
if
(!
lower
.
endsWith
(
".html"
)
&&
!
lower
.
endsWith
(
".htm"
))
{
return
;
}
if
(!
noIndex
.
contains
(
fileName
))
{
page
=
new
Page
(
pages
.
size
(),
fileName
,
name
);
pages
.
add
(
page
);
readPage
(
file
);
}
}
void
listWords
()
{
output
.
println
(
"// words: "
+
wordList
.
size
());
StringBuffer
buff
=
new
StringBuffer
();
String
first
=
""
;
int
firstLen
=
1
;
int
totalRelations
=
0
;
for
(
int
i
=
0
;
i
<
wordList
.
size
();
i
++)
{
Word
word
=
(
Word
)
wordList
.
get
(
i
);
ArrayList
weights
=
word
.
getSortedWeights
();
String
lower
=
StringUtils
.
toLowerEnglish
(
word
.
name
);
if
(!
first
.
equals
(
lower
.
substring
(
0
,
firstLen
)))
{
if
(
buff
.
length
()>
0
)
{
output
.
println
(
"ref['"
+
convertUTF
(
first
)+
"']='"
+
buff
.
toString
()+
"';"
);
buff
=
new
StringBuffer
();
}
first
=
lower
.
substring
(
0
,
firstLen
);
}
if
(
buff
.
length
()>
0
)
{
buff
.
append
(
';'
);
}
buff
.
append
(
convertUTF
(
word
.
name
));
buff
.
append
(
'='
);
String
weightString
=
"r"
;
totalRelations
+=
weights
.
size
();
for
(
int
j
=
0
;
j
<
weights
.
size
();
j
++)
{
Weight
weight
=
(
Weight
)
weights
.
get
(
j
);
Page
page
=
weight
.
page
;
if
(
j
>
0
)
{
buff
.
append
(
","
);
}
String
ws
;
if
(
weight
.
value
>=
Weight
.
TITLE
)
{
ws
=
"t"
;
}
else
if
(
weight
.
value
>=
Weight
.
HEADER
)
{
ws
=
"h"
;
}
else
{
ws
=
"r"
;
}
if
(
ws
!=
weightString
)
{
weightString
=
ws
;
buff
.
append
(
ws
);
}
buff
.
append
(
page
.
id
);
// TODO compress weight
// buff.append(",");
// buff.append(weight.value);
}
}
// TODO optimization: could support "a name=" and go to _first_ occurance, or scan page and mark
output
.
println
(
"ref['"
+
convertUTF
(
first
)+
"']='"
+
buff
.
toString
()+
"';"
);
output
.
println
(
"// totalRelations: "
+
totalRelations
);
}
private
void
readPage
(
File
file
)
throws
Exception
{
byte
[]
data
=
IOUtils
.
readBytesAndClose
(
new
FileInputStream
(
file
),
0
);
String
text
=
new
String
(
data
,
"UTF-8"
);
StringTokenizer
t
=
new
StringTokenizer
(
text
,
"<> \r\n"
,
true
);
boolean
inTag
=
false
;
title
=
false
;
heading
=
false
;
while
(
t
.
hasMoreTokens
())
{
String
token
=
t
.
nextToken
();
if
(
token
.
length
()==
1
)
{
char
c
=
token
.
charAt
(
0
);
switch
(
c
)
{
case
'<'
:
{
if
(
inTag
)
{
process
(
"???"
);
}
inTag
=
true
;
if
(!
t
.
hasMoreTokens
())
{
break
;
}
token
=
t
.
nextToken
();
if
(
token
.
startsWith
(
"/"
))
{
title
=
false
;
heading
=
false
;
}
else
if
(
token
.
equalsIgnoreCase
(
"title"
))
{
title
=
true
;
}
else
if
(
token
.
length
()
==
2
&&
Character
.
toLowerCase
(
token
.
charAt
(
0
))==
'h'
&&
Character
.
isDigit
(
token
.
charAt
(
1
)))
{
heading
=
true
;
}
// TODO maybe skip script tags?
break
;
}
case
'>'
:
{
if
(!
inTag
)
{
process
(
"???"
);
}
inTag
=
false
;
break
;
}
case
'\r'
:
case
'\n'
:
case
' '
:
break
;
default
:
if
(!
inTag
)
{
process
(
token
);
}
}
}
else
{
if
(!
inTag
)
{
process
(
token
);
}
}
}
if
(
page
.
title
==
null
||
page
.
title
.
trim
().
length
()
==
0
)
{
System
.
out
.
println
(
"Error: not title found in "
+
file
.
getName
());
page
.
title
=
file
.
getName
();
}
page
.
title
=
page
.
title
.
trim
();
}
void
process
(
String
text
)
{
text
=
HtmlConverter
.
convertHtml
(
text
);
if
(
title
)
{
if
(
page
.
title
==
null
)
{
page
.
title
=
text
;
}
else
{
page
.
title
=
page
.
title
+
" "
+
text
;
}
}
int
weight
;
if
(
title
)
{
weight
=
Weight
.
TITLE
;
}
else
if
(
heading
)
{
weight
=
Weight
.
HEADER
;
}
else
{
weight
=
Weight
.
PARAGRAPH
;
}
// this list of constants needs to be the same in search.js
StringTokenizer
t
=
new
StringTokenizer
(
text
,
" \t\r\n\"'.,:;!&/\\?%@`[]{}()+-=<>|*^~#$"
+
(
char
)
160
,
// nbsp
false
);
while
(
t
.
hasMoreTokens
())
{
String
token
=
t
.
nextToken
();
if
(
token
.
length
()<
MIN_WORDSIZE
)
{
continue
;
}
if
(
Character
.
isDigit
(
token
.
charAt
(
0
)))
{
continue
;
}
String
lower
=
StringUtils
.
toLowerEnglish
(
token
);
Word
word
=
(
Word
)
words
.
get
(
lower
);
if
(
word
==
null
)
{
word
=
new
Word
(
token
);
words
.
put
(
lower
,
word
);
}
else
if
(!
word
.
name
.
equals
(
token
))
{
word
.
name
=
token
.
compareTo
(
word
.
name
)
>
0
?
token
:
word
.
name
;
}
page
.
totalWeight
+=
weight
;
totalAllWeights
+=
weight
;
word
.
addPage
(
page
,
weight
);
}
}
String
convertUTF
(
String
s
)
{
s
=
StringUtils
.
quoteJavaString
(
s
);
s
=
s
.
substring
(
1
,
s
.
length
()-
1
);
return
s
;
}
}
h2/src/tools/org/h2/tools/indexer/Page.java
0 → 100644
浏览文件 @
3da434bd
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
tools
.
indexer
;
public
class
Page
{
int
id
;
String
fileName
;
String
name
;
String
title
;
// TODO page.totalWeight is currently not used
int
totalWeight
;
int
relations
;
Page
(
int
id
,
String
fileName
,
String
name
)
{
this
.
id
=
id
;
this
.
fileName
=
fileName
;
this
.
name
=
name
;
}
}
h2/src/tools/org/h2/tools/indexer/Weight.java
0 → 100644
浏览文件 @
3da434bd
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
tools
.
indexer
;
public
class
Weight
{
static
final
int
TITLE
=
10000
,
HEADER
=
100
,
PARAGRAPH
=
1
;
Page
page
;
int
value
;
}
h2/src/tools/org/h2/tools/indexer/Word.java
0 → 100644
浏览文件 @
3da434bd
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
tools
.
indexer
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.HashMap
;
public
class
Word
{
String
name
;
HashMap
pages
=
new
HashMap
();
ArrayList
weightList
;
Word
(
String
name
)
{
this
.
name
=
name
;
}
void
addPage
(
Page
page
,
int
weight
)
{
Weight
w
=
(
Weight
)
pages
.
get
(
page
);
if
(
w
==
null
)
{
w
=
new
Weight
();
w
.
page
=
page
;
pages
.
put
(
page
,
w
);
}
w
.
value
+=
weight
;
page
.
relations
++;
}
ArrayList
getSortedWeights
()
{
if
(
weightList
==
null
)
{
weightList
=
new
ArrayList
(
pages
.
values
());
Collections
.
sort
(
weightList
,
new
Comparator
()
{
public
int
compare
(
Object
o0
,
Object
o1
)
{
Weight
w0
=
(
Weight
)
o0
;
Weight
w1
=
(
Weight
)
o1
;
return
w0
.
value
<
w1
.
value
?
1
:
w0
.
value
==
w1
.
value
?
0
:
-
1
;
}
});
}
return
weightList
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论