KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > serialization > HTMLSerializer


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 package org.apache.cocoon.serialization;
17
18 import org.apache.avalon.framework.configuration.Configuration;
19 import org.apache.avalon.framework.configuration.ConfigurationException;
20 import org.apache.cocoon.CascadingIOException;
21 import javax.xml.transform.OutputKeys JavaDoc;
22 import javax.xml.transform.sax.TransformerHandler JavaDoc;
23 import javax.xml.transform.stream.StreamResult JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.io.OutputStream JavaDoc;
26
27 /**
28  * @cocoon.sitemap.component.documentation
29  * The html serializer serializes sax events into an html document.
30  *
31  * @cocoon.sitemap.component.name html
32  * @cocoon.sitemap.component.mimetype text/html
33  * @cocoon.sitemap.component.logger sitemap.serializer.html
34  *
35  * @cocoon.sitemap.component.pooling.max 32
36  *
37  * @cocoon.sitemap.component.configuration
38  * <doctype-public>-//W3C//DTD HTML 4.01 Transitional//EN</doctype-public>
39  * <doctype-system>http://www.w3.org/TR/html4/loose.dtd</doctype-system>
40  *
41  *
42  * @author <a HREF="mailto:stefano@apache.org">Stefano Mazzocchi</a>
43  * @version CVS $Id: HTMLSerializer.java 180021 2005-06-04 20:59:57Z antonio $
44  */

45
46 public class HTMLSerializer extends AbstractTextSerializer {
47
48     /**
49      * Set the configurations for this serializer.
50      */

51     public void configure(Configuration conf)
52     throws ConfigurationException {
53         super.configure(conf);
54         this.format.put(OutputKeys.METHOD,"html");
55     }
56
57     /**
58      * Set the {@link OutputStream} where the requested resource should
59      * be serialized.
60      */

61     public void setOutputStream(OutputStream JavaDoc out)
62     throws IOException {
63         super.setOutputStream(out);
64         try {
65             TransformerHandler JavaDoc handler = this.getTransformerHandler();
66             handler.getTransformer().setOutputProperties(this.format);
67             handler.setResult(new StreamResult JavaDoc(this.output));
68             this.setContentHandler(handler);
69             this.setLexicalHandler(handler);
70         } catch (Exception JavaDoc e) {
71             final String JavaDoc message = "Cannot set HTMLSerializer outputstream";
72             throw new CascadingIOException(message, e);
73         }
74     }
75 }
76
Popular Tags