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.cocoon.serialization;
18:
19: import org.apache.avalon.framework.configuration.Configuration;
20: import org.apache.avalon.framework.configuration.ConfigurationException;
21: import org.apache.cocoon.CascadingIOException;
22: import javax.xml.transform.OutputKeys;
23: import javax.xml.transform.sax.TransformerHandler;
24: import javax.xml.transform.stream.StreamResult;
25: import java.io.IOException;
26: import java.io.OutputStream;
27:
28: /**
29: * @cocoon.sitemap.component.documentation
30: * The html serializer serializes sax events into an html document.
31: *
32: * @cocoon.sitemap.component.name html
33: * @cocoon.sitemap.component.mimetype text/html
34: * @cocoon.sitemap.component.logger sitemap.serializer.html
35: *
36: * @cocoon.sitemap.component.pooling.max 32
37: *
38: * @cocoon.sitemap.component.configuration
39: * <doctype-public>-//W3C//DTD HTML 4.01 Transitional//EN</doctype-public>
40: * <doctype-system>http://www.w3.org/TR/html4/loose.dtd</doctype-system>
41: *
42: *
43: * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
44: * @version CVS $Id: HTMLSerializer.java 433543 2006-08-22 06:22:54Z crossley $
45: */
46:
47: public class HTMLSerializer extends AbstractTextSerializer {
48:
49: /**
50: * Set the configurations for this serializer.
51: */
52: public void configure(Configuration conf)
53: throws ConfigurationException {
54: super .configure(conf);
55: this .format.put(OutputKeys.METHOD, "html");
56: }
57:
58: /**
59: * Set the {@link OutputStream} where the requested resource should
60: * be serialized.
61: */
62: public void setOutputStream(OutputStream out) throws IOException {
63: super .setOutputStream(out);
64: try {
65: TransformerHandler handler = this .getTransformerHandler();
66: handler.getTransformer().setOutputProperties(this .format);
67: handler.setResult(new StreamResult(this .output));
68: this .setContentHandler(handler);
69: this .setLexicalHandler(handler);
70: } catch (Exception e) {
71: final String message = "Cannot set HTMLSerializer outputstream";
72: throw new CascadingIOException(message, e);
73: }
74: }
75: }
|