KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.xml.transform.OutputKeys JavaDoc;
19 import javax.xml.transform.sax.TransformerHandler JavaDoc;
20 import javax.xml.transform.stream.StreamResult JavaDoc;
21
22 import org.apache.avalon.framework.configuration.Configuration;
23 import org.apache.avalon.framework.configuration.ConfigurationException;
24 import org.apache.cocoon.CascadingIOException;
25
26 import java.io.IOException JavaDoc;
27 import java.io.OutputStream JavaDoc;
28
29 /**
30  * @author <a HREF="mailto:stefano@apache.org">Stefano Mazzocchi</a>
31  * @version CVS $Id: XMLSerializer.java 30932 2004-07-29 17:35:38Z vgritsenko $
32  */

33
34 public class XMLSerializer extends AbstractTextSerializer {
35
36     /**
37      * Set the configurations for this serializer.
38      */

39     public void configure(Configuration conf)
40     throws ConfigurationException {
41         super.configure( conf );
42         this.format.put(OutputKeys.METHOD,"xml");
43     }
44
45     /**
46      * Set the {@link OutputStream} where the requested resource should
47      * be serialized.
48      */

49     public void setOutputStream(OutputStream JavaDoc out) throws IOException {
50         super.setOutputStream(out);
51         try {
52             TransformerHandler JavaDoc handler = this.getTransformerHandler();
53             handler.getTransformer().setOutputProperties(this.format);
54             handler.setResult(new StreamResult JavaDoc(this.output));
55             this.setContentHandler(handler);
56             this.setLexicalHandler(handler);
57         } catch (Exception JavaDoc e) {
58             final String JavaDoc message = "Cannot set XMLSerializer outputstream";
59             throw new CascadingIOException(message, e);
60         }
61     }
62
63 }
64
Popular Tags