01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.outerj.daisy.frontend.util;
17:
18: import org.apache.excalibur.xml.sax.XMLizable;
19: import org.apache.xmlbeans.XmlObject;
20: import org.apache.cocoon.xml.IncludeXMLConsumer;
21: import org.xml.sax.ContentHandler;
22: import org.xml.sax.SAXException;
23:
24: /**
25: * An XMLizable wrapper around an XMLBeans XmlObject.
26: */
27: public class XmlObjectXMLizable implements XMLizable {
28: private XmlObject xmlObject;
29: private boolean dropDocumentElement;
30:
31: /**
32: * @param xmlObject null is allowed
33: */
34: public XmlObjectXMLizable(XmlObject xmlObject) {
35: this .xmlObject = xmlObject;
36: }
37:
38: public XmlObjectXMLizable(XmlObject xmlObject,
39: boolean dropDocumentElement) {
40: this .xmlObject = xmlObject;
41: this .dropDocumentElement = dropDocumentElement;
42: }
43:
44: public void toSAX(ContentHandler contentHandler)
45: throws SAXException {
46: if (xmlObject != null) {
47: if (dropDocumentElement) {
48: IncludeXMLConsumer consumer = new IncludeXMLConsumer(
49: contentHandler);
50: consumer.setIgnoreRootElement(true);
51: contentHandler = consumer;
52: }
53: xmlObject.save(contentHandler, null);
54: }
55: }
56: }
|