KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > sax > XMLByteStreamFragment


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.components.sax;
17
18 import org.apache.cocoon.xml.AbstractSAXFragment;
19 import org.apache.cocoon.xml.EmbeddedXMLPipe;
20 import org.xml.sax.ContentHandler JavaDoc;
21 import org.xml.sax.SAXException JavaDoc;
22
23 /**
24  * An XMLByteStream wrapped by an XMLFragment implementation. This allows to
25  * store SAX events and insert them in an XSP result using <xsp:expr>.
26  *
27  * @author <a HREF="mailto:sylvain@apache.org">Sylvain Wallez</a>
28  * @version CVS $Id: XMLByteStreamFragment.java 105790 2004-11-19 07:37:46Z antonio $
29  */

30 public class XMLByteStreamFragment extends AbstractSAXFragment {
31
32     /** The XML byte stream */
33     private Object JavaDoc xmlBytes;
34
35     /**
36      * Creates a new <code>XMLByteStreamFragment</code> defined by the given
37      * XML byte stream.
38      *
39      * @param bytes the XML byte stream representing the document fragment
40      */

41     public XMLByteStreamFragment(Object JavaDoc bytes) {
42         this.xmlBytes = bytes;
43     }
44
45     /**
46      * Output the fragment. If the fragment is a document, start/endDocument
47      * events are discarded.
48      */

49     public void toSAX(ContentHandler JavaDoc ch) throws SAXException JavaDoc {
50         // Stream bytes and discard start/endDocument
51
XMLByteStreamInterpreter deserializer = new XMLByteStreamInterpreter();
52         deserializer.setContentHandler(new EmbeddedXMLPipe(ch));
53         deserializer.deserialize(this.xmlBytes);
54     }
55 }
56
Popular Tags