KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > IZPressHtmlCompressTask


1 /*****************************************************************************
2  * Copyright (C) The Krysalis project. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * This software is published under the terms of the Krysalis Patchy *
5  * Software License version 1.1_01, a copy of which has been included *
6  * at the bottom of this file. *
7  *****************************************************************************/

8
9 import com.izforge.izpress.*;
10
11 import java.io.InputStream JavaDoc;
12 import java.io.FileInputStream JavaDoc;
13 import java.io.BufferedInputStream JavaDoc;
14 import java.io.OutputStream JavaDoc;
15 import java.io.FileOutputStream JavaDoc;
16 import java.io.Writer JavaDoc;
17 import java.io.PrintWriter JavaDoc;
18 import java.io.FileWriter JavaDoc;
19 import java.io.BufferedWriter JavaDoc;
20 import java.io.FileWriter JavaDoc;
21 import java.io.IOException JavaDoc;
22
23 import java.util.ArrayList JavaDoc;
24
25 import org.w3c.dom.NodeList JavaDoc;
26 import org.w3c.dom.Node JavaDoc;
27 import org.w3c.dom.Element JavaDoc;
28 import org.w3c.dom.Attr JavaDoc;
29 import org.w3c.dom.Document JavaDoc;
30 import org.w3c.dom.NamedNodeMap JavaDoc;
31
32 import org.w3c.tidy.Tidy;
33
34 import org.apache.tools.ant.BuildException;
35 import org.apache.tools.ant.taskdefs.Property;
36
37 /**
38  * Task to compress html size.
39  *
40  * @author <a HREF="mailto:barozzi@nicolaken.com">Nicola Ken Barozzi</a>
41  * @created 14 January 2002
42  */

43 public class IZPressHtmlCompressTask extends org.apache.tools.ant.Task {
44
45   private String JavaDoc src;
46   private String JavaDoc dest;
47   private Compressor compressor;
48   private CompressorConfig conf;
49   private String JavaDoc wipeComments = "true";
50   private String JavaDoc wipeBorders = "true";
51   private String JavaDoc wipeReturns = "true";
52   private String JavaDoc wipeSpaces = "true";
53
54    PrintWriter JavaDoc pw;
55   /**
56    * Constructor.
57    */

58   public IZPressHtmlCompressTask() {
59     super();
60   }
61
62   /**
63    * Initializes the task.
64    */

65   public void init() {
66     super.init();
67     // Setup an instance of IZCompressor.
68
conf =
69      new CompressorConfig(false,false,true,true);
70   }
71
72   /**
73    * Run the task.
74    * @exception org.apache.tools.ant.BuildException The exception raised during task execution.
75    */

76   public void execute() throws org.apache.tools.ant.BuildException {
77
78     try{
79
80       FileInputStream JavaDoc in = new FileInputStream JavaDoc(src);
81       FileOutputStream JavaDoc out = new FileOutputStream JavaDoc(dest);
82
83       compressor = new Compressor(in,out,conf);
84       
85       compressor.compress();
86
87       out.flush();
88       in.close();
89       out.close();
90
91     }
92     catch(IOException JavaDoc ioe)
93     {
94       throw new BuildException(ioe);
95     }
96   }
97
98   public void setSrc(String JavaDoc src) {
99     this.src = src;
100   }
101
102   public void setDest(String JavaDoc dest) {
103     this.dest = dest;
104   }
105
106
107   public void setWipeComments(String JavaDoc wipeComments) {
108     this.wipeComments = wipeComments;
109   }
110
111
112   public void setWipeBorders(String JavaDoc wipeBorders) {
113     this.wipeBorders = wipeBorders;
114   }
115   
116     public void setWipeReturns(String JavaDoc wipeReturns) {
117     this.wipeReturns = wipeReturns;
118   }
119
120
121   public void setWipeSpaces(String JavaDoc wipeSpaces) {
122     this.wipeSpaces = wipeSpaces;
123   }
124
125 }
126
127 /*
128 The Krysalis Patchy Software License, Version 1.1_01
129 Copyright (c) 2002 Nicola Ken Barozzi. All rights reserved.
130
131 This Licence is compatible with the BSD licence as described and
132 approved by http://www.opensource.org/, and is based on the
133 Apache Software Licence Version 1.1.
134
135 Redistribution and use in source and binary forms, with or without
136 modification, are permitted provided that the following conditions
137 are met:
138
139  1. Redistributions of source code must retain the above copyright
140     notice, this list of conditions and the following disclaimer.
141
142 2. Redistributions in binary form must reproduce the above copyright
143    notice, this list of conditions and the following disclaimer in
144    the documentation and/or other materials provided with the
145    distribution.
146
147 3. The end-user documentation included with the redistribution,
148    if any, must include the following acknowledgment:
149       "This product includes software developed for project
150        Krysalis (http://www.krysalis.org/)."
151    Alternately, this acknowledgment may appear in the software itself,
152    if and wherever such third-party acknowledgments normally appear.
153
154 4. The names "Krysalis" and "Nicola Ken Barozzi" and
155    "Krysalis Centipede" must not be used to endorse or promote products
156    derived from this software without prior written permission. For
157    written permission, please contact krysalis@nicolaken.org.
158    
159 5. Products derived from this software may not be called "Krysalis",
160    "Krysalis Centipede", nor may "Krysalis" appear in their name,
161    without prior written permission of Nicola Ken Barozzi.
162
163 6. This software may contain voluntary contributions made by many
164    individuals, who decided to donate the code to this project in
165    respect of this licence.
166
167 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
168 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
169 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
170 DISCLAIMED. IN NO EVENT SHALL THE KRYSALIS PROJECT OR
171 ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
172 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
173 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
174 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
175 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
176 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
177 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
178 SUCH DAMAGE.
179 ====================================================================*/

180
Free Books   Free Magazines  
Popular Tags