01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.jetspeed.dbutil;
18:
19: import java.io.BufferedReader;
20: import java.io.File;
21: import java.io.FileReader;
22: import java.io.FileWriter;
23: import java.io.PrintWriter;
24:
25: public class ScriptUtil {
26:
27: public static void main(String[] args) {
28: System.out.println("Running DBUtils " + args[0]);
29: try {
30: if (args.length == 2 && args[0].equals("-drops")) {
31: dropdrops(args[1]);
32: }
33: } catch (Exception e) {
34: e.printStackTrace();
35: }
36: }
37:
38: public static void dropdrops(String filename) throws Exception {
39: System.out.println("dropping drops from " + filename);
40: String outputFileName = filename + ".tmp";
41: FileReader fr = new FileReader(filename);
42: BufferedReader reader = new BufferedReader(fr);
43:
44: FileWriter fw = new FileWriter(outputFileName);
45: PrintWriter writer = new PrintWriter(fw);
46: String line;
47: while ((line = reader.readLine()) != null) {
48: String temp = line.toUpperCase();
49: if (!temp.startsWith("DROP")) {
50: writer.println(line);
51: }
52: }
53: fr.close();
54: fw.close();
55: File original = new File(filename);
56: File modified = new File(outputFileName);
57: original.delete();
58: modified.renameTo(original);
59: }
60:
61: }
|