KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > util > TidyCommandLine


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 /* $Id: TidyCommandLine.java 42598 2004-03-01 16:18:28Z gregor $ */
19
20 package org.apache.lenya.util;
21
22 import java.io.BufferedInputStream JavaDoc;
23 import java.io.File JavaDoc;
24 import java.io.FileOutputStream JavaDoc;
25 import java.io.FileWriter JavaDoc;
26 import java.io.PrintWriter JavaDoc;
27 import java.net.URL JavaDoc;
28
29 import org.w3c.tidy.Tidy;
30
31
32 /**
33  * DOCUMENT ME!
34  */

35 public class TidyCommandLine {
36     /**
37      * DOCUMENT ME!
38      *
39      * @param args DOCUMENT ME!
40      */

41     public static void main(String JavaDoc[] args) {
42         if (args.length != 3) {
43             System.err.println("Usage: java " + new TidyCommandLine().getClass().getName() +
44                 " http://www.lenya.org index.xhtml error.log");
45
46             return;
47         }
48
49         try {
50             new TidyCommandLine().tidy(new URL JavaDoc(args[0]), new File JavaDoc(args[1]), new File JavaDoc(args[2]), true);
51         } catch (Exception JavaDoc e) {
52             System.err.println(e);
53         }
54     }
55
56     /**
57      * DOCUMENT ME!
58      *
59      * @param url DOCUMENT ME!
60      * @param file DOCUMENT ME!
61      * @param err DOCUMENT ME!
62      * @param xhtml DOCUMENT ME!
63      *
64      * @throws Exception DOCUMENT ME!
65      */

66     public void tidy(URL JavaDoc url, File JavaDoc file, File JavaDoc err, boolean xhtml)
67         throws Exception JavaDoc {
68         Tidy tidy = new Tidy();
69         tidy.setXmlOut(xhtml);
70         tidy.setErrout(new PrintWriter JavaDoc(new FileWriter JavaDoc(err.getAbsolutePath()), true));
71
72         BufferedInputStream JavaDoc in = new BufferedInputStream JavaDoc(url.openStream());
73         FileOutputStream JavaDoc out = new FileOutputStream JavaDoc(file.getAbsolutePath());
74         tidy.parse(in, out);
75     }
76 }
77
Popular Tags