提交 0ea30d28 authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 6f67c668
......@@ -106,12 +106,12 @@ public class H2Dictionary extends DBDictionary {
buf.append(", ").append(pkStr);
}
Unique[] unqs = table.getUniques();
String unqStr;
for (int i = 0; i < unqs.length; i++) {
unqStr = getUniqueConstraintSQL(unqs[i]);
if (unqStr != null)
buf.append(", ").append(unqStr);
Unique[] uniques = table.getUniques();
String uniqueStr;
for (int i = 0; i < uniques.length; i++) {
uniqueStr = getUniqueConstraintSQL(uniques[i]);
if (uniqueStr != null)
buf.append(", ").append(uniqueStr);
}
buf.append(")");
......@@ -154,12 +154,12 @@ public class H2Dictionary extends DBDictionary {
return cols;
}
public void setDouble(PreparedStatement stmnt, int idx, double val, Column col) throws SQLException {
super.setDouble(stmnt, idx, val, col);
public void setDouble(PreparedStatement stat, int idx, double val, Column col) throws SQLException {
super.setDouble(stat, idx, val, col);
}
public void setBigDecimal(PreparedStatement stmnt, int idx, BigDecimal val, Column col) throws SQLException {
super.setBigDecimal(stmnt, idx, val, col);
public void setBigDecimal(PreparedStatement stat, int idx, BigDecimal val, Column col) throws SQLException {
super.setBigDecimal(stat, idx, val, col);
}
protected void appendSelectRange(SQLBuffer buf, long start, long end) {
......
......@@ -68,8 +68,8 @@ public class CodeSwitch {
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("Use +MODE to switch on code labeled MODE");
System.out.println("Use -MODE to switch off code labeled MODE");
System.out
.println("Path: Any number of path or files may be specified.");
System.out
......@@ -164,7 +164,7 @@ public class CodeSwitch {
private boolean processFile(String name) {
File f = new File(name);
boolean switchoff = false;
boolean off = false;
boolean working = false;
int state = 0;
try {
......@@ -233,11 +233,11 @@ public class CodeSwitch {
}
if (switchedOn) {
working = true;
switchoff = false;
off = false;
} else if (switchedOff) {
working = true;
insertLine(++i, "/*" + endOfLine);
switchoff = true;
off = true;
}
if (switches.indexOf(s) == -1) {
switches.add(s);
......@@ -249,12 +249,12 @@ public class CodeSwitch {
}
state = 2;
if (working) {
if (switchoff) {
if (off) {
insertLine(++i, "*/" + endOfLine);
switchoff = false;
off = false;
} else {
insertLine(++i, "/*" + endOfLine);
switchoff = true;
off = true;
}
}
} else if (lineTrim.startsWith("//#endif")) {
......@@ -263,7 +263,7 @@ public class CodeSwitch {
return false;
}
state = 0;
if (working && switchoff) {
if (working && off) {
insertLine(i++, "*/" + endOfLine);
}
working = false;
......@@ -275,18 +275,18 @@ public class CodeSwitch {
return false;
}
if (changed) {
File fnew = new File(name + ".new");
FileWriter write = new FileWriter(fnew);
File fileNew = new File(name + ".new");
FileWriter write = new FileWriter(fileNew);
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();
File fileBack = new File(name + ".bak");
fileBack.delete();
f.renameTo(fileBack);
File fileCopy = new File(name);
fileNew.renameTo(fileCopy);
fileBack.delete();
System.out.println(name);
}
return true;
......
......@@ -12,13 +12,15 @@ import java.io.OutputStreamWriter;
import java.io.RandomAccessFile;
import org.h2.server.web.PageParser;
import org.h2.tools.indexer.HtmlConverter;
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[] list = new File("bin/org/h2/server/web/res").listFiles();
for(int i=0; list != null && i<list.length; i++) {
File f = list[i];
if(!f.getName().endsWith(".properties")) {
continue;
......@@ -29,13 +31,14 @@ public class PropertiesToUTF8 {
in.close();
String name = f.getName();
if(name.startsWith("utf8")) {
s = PageParser.escapeHtml(s, false);
s = HtmlConverter.convertStringToHtml(s);
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 = HtmlConverter.convertHtmlToString(s);
// s = unescapeHtml(s);
s = StringUtils.javaDecode(s);
FileOutputStream out = new FileOutputStream("utf8" + f.getName());
OutputStreamWriter w = new OutputStreamWriter(out, "UTF-8");
......
......@@ -71,13 +71,13 @@ public class GenerateDoc {
}
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);
FileOutputStream out = new FileOutputStream(outDir + "/"+fileName+".html");
FileInputStream in = new FileInputStream(inDir + "/"+fileName+".jsp");
byte[] bytes = IOUtils.readBytesAndClose(in, 0);
String page = new String(bytes);
page = PageParser.parse(null, page, session);
fout.write(page.getBytes());
fout.close();
out.write(page.getBytes());
out.close();
}
void map(String key, String sql) throws Exception {
......
......@@ -163,7 +163,7 @@ public class LinkChecker {
} else if(type.equals("name")) {
targets.put(path + "#" + ref, "name");
} else {
error(fileName, "unsupported <a xxx: " + html.substring(idx, idx + 100));
error(fileName, "unsupported <a ?: " + html.substring(idx, idx + 100));
}
}
}
......
......@@ -5,6 +5,7 @@ import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
......@@ -18,6 +19,7 @@ public class SpellChecker {
private HashSet used = new HashSet();
private HashMap unknown = new HashMap();
private boolean debug;
private boolean printDictionary;
private boolean addToDictionary;
private static final String[] SUFFIX = new String[]{"java", "sql", "cpp", "txt", "html", "xml", "jsp", "css", "bat", "nsi", "csv", "xml", "js", "def", "dev", "h", "Driver", "properties", "win", "task", "php", "" };
private static final String[] IGNORE = new String[]{"gif", "png", "odg", "ico", "sxd", "zip", "bz2", "rc", "layout", "res", "dll", "jar"};
......@@ -30,22 +32,37 @@ public class SpellChecker {
private void run(String dictionary, String dir) throws IOException {
process(new File(dir + "/" + dictionary));
process(new File(dir));
System.out.println("used words");
for(Iterator it = used.iterator(); it.hasNext();) {
String s = (String) it.next();
System.out.print(s + " ");
}
System.out.println();
System.out.println("ALL UNKNOWN ----------------------------");
for(Iterator it = unknown.keySet().iterator(); it.hasNext();) {
String s = (String) it.next();
int count = ((Integer) unknown.get(s)).intValue();
if(count > 5) {
System.out.print(s + " ");
if(printDictionary) {
System.out.println("USED WORDS");
String[] list = new String[used.size()];
used.toArray(list);
Arrays.sort(list);
StringBuffer buff = new StringBuffer();
for(int i=0; i<list.length; i++) {
String s = list[i];
if(buff.length() > 0) {
if(buff.length() + s.length() > 80) {
System.out.println(buff.toString());
buff.setLength(0);
} else {
buff.append(' ');
}
}
buff.append(s);
}
System.out.println(buff.toString());
}
System.out.println();
if(unknown.size() > 0) {
System.out.println();
System.out.println("UNKNOWN WORDS");
for(Iterator it = unknown.keySet().iterator(); it.hasNext();) {
String s = (String) it.next();
int count = ((Integer) unknown.get(s)).intValue();
if(count > 5) {
System.out.print(s + " ");
}
}
System.out.println();
throw new IOException("spell check failed");
}
}
......@@ -57,9 +74,9 @@ public class SpellChecker {
}
int removeThisLater;
if(name.indexOf("\\test\\") >= 0) {
return;
}
// if(name.indexOf("\\test\\") >= 0) {
// return;
// }
if(file.isDirectory()) {
File[] list = file.listFiles();
......@@ -115,7 +132,7 @@ public class SpellChecker {
}
private void scan(String fileName, String text) {
HashSet notfound = new HashSet();
HashSet notFound = new HashSet();
StringTokenizer tokenizer = new StringTokenizer(text, "\r\n \t+\"*%&/()='[]{},.-;:_<>\\!?$@#|~^`");
while(tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
......@@ -126,17 +143,17 @@ public class SpellChecker {
if(!addToDictionary && debug) {
System.out.print(token + " ");
}
scanCombinedToken(notfound, token);
scanCombinedToken(notFound, token);
if(!addToDictionary && debug) {
System.out.println();
}
}
if(notfound.isEmpty()) {
if(notFound.isEmpty()) {
return;
}
if(notfound.size() > 0) {
if(notFound.size() > 0) {
System.out.println("file: " + fileName);
for(Iterator it = notfound.iterator(); it.hasNext();) {
for(Iterator it = notFound.iterator(); it.hasNext();) {
String s = (String) it.next();
System.out.print(s + " ");
}
......@@ -144,24 +161,24 @@ public class SpellChecker {
}
}
private void scanCombinedToken(HashSet notfound, String token) {
private void scanCombinedToken(HashSet notFound, String token) {
for(int i=1; i<token.length(); i++) {
char cleft = token.charAt(i-1);
char cright = token.charAt(i);
if(Character.isLowerCase(cleft) && Character.isUpperCase(cright)) {
scanToken(notfound, token.substring(0, i));
char charLeft = token.charAt(i-1);
char charRight = token.charAt(i);
if(Character.isLowerCase(charLeft) && Character.isUpperCase(charRight)) {
scanToken(notFound, token.substring(0, i));
token = token.substring(i);
i = 1;
} else if(Character.isUpperCase(cleft) && Character.isLowerCase(cright)) {
scanToken(notfound, token.substring(0, i - 1));
} else if(Character.isUpperCase(charLeft) && Character.isLowerCase(charRight)) {
scanToken(notFound, token.substring(0, i - 1));
token = token.substring(i - 1);
i = 1;
}
}
scanToken(notfound, token);
scanToken(notFound, token);
}
private void scanToken(HashSet notfound, String token) {
private void scanToken(HashSet notFound, String token) {
if(token.length() < 3) {
return;
}
......@@ -188,7 +205,7 @@ public class SpellChecker {
dictionary.add(token);
} else {
if(!dictionary.contains(token)) {
notfound.add(token);
notFound.add(token);
increment(unknown, token);
} else {
used.add(token);
......
......@@ -89,7 +89,7 @@ public class XMLChecker {
private static void checkXML(String xml, boolean html) throws Exception {
String lastElement = null;
String[] noclose = new String[]{
String[] noClose = new String[]{
"li", "link", "meta", "br", "img", "input", "hr", "frame"
};
XMLParser parser = new XMLParser(xml);
......@@ -110,8 +110,8 @@ public class XMLChecker {
if(html && name.equals("table") && lastElement.trim().length() > 0) {
throw new Exception("Test before table: " + lastElement);
}
for(int i=0; html && i<noclose.length; i++) {
if(name.equals(noclose[i])) {
for(int i=0; html && i<noClose.length; i++) {
if(name.equals(noClose[i])) {
name = null;
break;
}
......@@ -121,8 +121,8 @@ public class XMLChecker {
}
} else if(event == XMLParser.END_ELEMENT) {
String name = parser.getName();
for(int i=0; html && i<noclose.length; i++) {
if(name.equals(noclose[i])) {
for(int i=0; html && i<noClose.length; i++) {
if(name.equals(noClose[i])) {
throw new Exception("Unnecessary closing element " + name + " at " + parser.getRemaining());
}
}
......
......@@ -8,6 +8,7 @@ import java.util.HashMap;
public class HtmlConverter {
private static HashMap charMap = new HashMap();
private static HashMap codeMap = new HashMap();
private static final String[] CHARS = {
"quot:34", "amp:38", "lt:60", "gt:62", "nbsp:160", "iexcl:161", "cent:162",
......@@ -58,11 +59,43 @@ public class HtmlConverter {
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));
Character character = new Character((char)ch);
charMap.put(key, character);
codeMap.put(character, key);
}
}
public static String convertHtml(String html) {
public static String convertStringToHtml(String s) {
if(s == null) {
return null;
}
if(s.length() == 0) {
return s;
}
StringBuffer buff = new StringBuffer();
for(int i=0; i<s.length(); i++) {
char ch = s.charAt(i);
Character c = new Character(ch);
String token = (String) codeMap.get(c);
if(token == null) {
if(ch < 128) {
buff.append(ch);
} else {
buff.append('&');
buff.append('#');
buff.append((int)ch);
buff.append(';');
}
} else {
buff.append('&');
buff.append(token);
buff.append(';');
}
}
return buff.toString();
}
public static String convertHtmlToString(String html) {
if(html == null) {
return null;
}
......@@ -110,6 +143,5 @@ public class HtmlConverter {
}
return buff.toString();
}
}
......@@ -31,7 +31,7 @@ public class Indexer {
boolean title;
boolean heading;
private static final int MIN_WORDSIZE = 3;
private static final int MIN_WORD_SIZE = 3;
private static final int MAX_RELATIONS = 20;
public static void main(String[] args) throws Exception {
......@@ -222,7 +222,7 @@ public class Indexer {
// buff.append(weight.value);
}
}
// TODO optimization: could support "a name=" and go to _first_ occurance, or scan page and mark
// TODO optimization: could support "a name=" and go to _first_ occurrence, or scan page and mark
output.println("ref['"+convertUTF(first)+"']='"+buff.toString()+"';");
output.println("// totalRelations: "+totalRelations);
}
......@@ -290,7 +290,7 @@ public class Indexer {
}
void process(String text) {
text = HtmlConverter.convertHtml(text);
text = HtmlConverter.convertHtmlToString(text);
if(title) {
if(page.title == null) {
page.title = text;
......@@ -312,7 +312,7 @@ public class Indexer {
false);
while (t.hasMoreTokens()) {
String token = t.nextToken();
if(token.length()<MIN_WORDSIZE) {
if(token.length()<MIN_WORD_SIZE) {
continue;
}
if(Character.isDigit(token.charAt(0))) {
......
......@@ -47,7 +47,7 @@ class H2Adapter extends DatabaseAdapter
private String schemaName;
/**
* Constructs a H2 adapter based on the given JDBCmetadata.
* Constructs a H2 adapter based on the given JDBC metadata.
* @param dictionary The Dictionary to use
* @param metadata the database metadata.
*/
......@@ -75,7 +75,7 @@ class H2Adapter extends DatabaseAdapter
}
/**
* Accessor for the vendor ID for this adapter.
* Getter for the vendor ID for this adapter.
* @return The vendor ID
*/
public String getVendorID()
......@@ -85,7 +85,7 @@ class H2Adapter extends DatabaseAdapter
/**
* Accessor for a Connection to the datastore.
* @param ds The data source. Possible to have more than one datasource for failover
* @param ds The data source. Possible to have more than one data source for fail over
* @param userName The username for the datastore
* @param password The password for the datastore
* @param isolationLevel The level of transaction isolation
......@@ -149,7 +149,7 @@ class H2Adapter extends DatabaseAdapter
/**
* Method to return the SQL to append to the SELECT clause of a SELECT statement to handle
* restriction of ranges using the LIMUT keyword.
* restriction of ranges using the LIMIT keyword.
* @param offset The offset to return from
* @param count The number of items to return
* @return The SQL to append to allow for ranges using LIMIT.
......@@ -244,8 +244,8 @@ class H2Adapter extends DatabaseAdapter
}
/**
* Whether we support autoincrementing fields.
* @return whether we support autoincrementing fields.
* Whether we support auto incrementing fields.
* @return whether we support auto incrementing fields.
**/
public boolean supportsAutoIncrementFields()
{
......@@ -264,7 +264,7 @@ class H2Adapter extends DatabaseAdapter
}
/**
* Accessor for the auto-increment keyword for generating DDLs (CREATE TABLEs...).
* Accessor for the auto-increment keyword for generating DDLs (CREATE TABLE...).
* @return The keyword for a column using auto-increment
**/
public String getAutoIncrementKeyword()
......@@ -273,7 +273,7 @@ class H2Adapter extends DatabaseAdapter
}
/**
* Method to retutn the INSERT statement to use when inserting into a table that has no
* Method to return the INSERT statement to use when inserting into a table that has no
* columns specified. This is the case when we have a single column in the table and that column
* is autoincrement/identity (and so is assigned automatically in the datastore).
* @param table The table
......@@ -298,7 +298,7 @@ class H2Adapter extends DatabaseAdapter
* Whether this datastore supports the use of CHECK after the column
* definitions in CREATE TABLE statements (DDL).
* e.g.
* CREATE TABLE XXX
* CREATE TABLE XYZ
* (
* COL_A int,
* COL_B char(1),
......
......@@ -28,8 +28,8 @@ public class H2Dialect extends Dialect {
try {
Class constants = ReflectHelper.classForName( "org.h2.engine.Constants" );
Integer build = (Integer)constants.getDeclaredField("BUILD_ID" ).get(null);
int buildid = build.intValue();
if(buildid < 32) {
int buildId = build.intValue();
if(buildId < 32) {
querySequenceString = "select name from information_schema.sequences";
}
} catch(Throwable e) {
......@@ -141,7 +141,7 @@ public class H2Dialect extends Dialect {
// registerFunction("minute", new StandardSQLFunction("minute", Hibernate.INTEGER));
// registerFunction("month", new StandardSQLFunction("month", Hibernate.INTEGER));
registerFunction("monthname", new StandardSQLFunction("monthname", Hibernate.STRING));
registerFunction("quater", new StandardSQLFunction("quater", Hibernate.INTEGER));
registerFunction("quarter", new StandardSQLFunction("quarter", Hibernate.INTEGER));
// registerFunction("second", new StandardSQLFunction("second", Hibernate.INTEGER));
registerFunction("week", new StandardSQLFunction("week", Hibernate.INTEGER));
// registerFunction("year", new StandardSQLFunction("year", Hibernate.INTEGER));
......@@ -246,15 +246,15 @@ public class H2Dialect extends Dialect {
/**
* Extract the name of the violated constraint from the given SQLException.
*
* @param sqle The exception that was the result of the constraint violation.
* @param e The exception that was the result of the constraint violation.
* @return The extracted constraint name.
*/
public String extractConstraintName(SQLException sqle) {
public String extractConstraintName(SQLException e) {
String constraintName = null;
// 23000: Check constraint violation: {0}
// 23001: Unique index or primary key violation: {0}
if(sqle.getSQLState().startsWith("23")) {
String message = sqle.getMessage();
if(e.getSQLState().startsWith("23")) {
String message = e.getMessage();
int idx = message.indexOf("violation: ");
if(idx > 0) {
constraintName = message.substring(idx + "violation: ".length());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论