001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Developer of the Enhydra Application Server is Together Austria.
015: * All Rights Reserved.
016: *
017: */
018: package org.enhydra.util.jivan;
019:
020: import java.io.ByteArrayOutputStream;
021: import java.io.IOException;
022:
023: import org.enhydra.util.dom.SimpleXMLObjectImpl;
024: import org.jivan.html.document.DocumentManager;
025: import org.jivan.html.dom.HTMLDocumentCEImpl;
026: import org.w3c.dom.Document;
027:
028: /**
029: * <p>Title: JivanSimpleXMLObjectImpl</p>
030: * <p>Description: This class represents implementation of XMLObject interface.
031: * Its main purpose is to provide the way for creation of XMLObject object by
032: * passed Jivan org.w3c.dom.Document Jivan implementation. The XMLCObject
033: * created by this manner can be used in already existing writeDOM() methods of
034: * ServletHttpPresentationResponse object to perform http response. Note that
035: * this class was tested only in in http response, not in DOM manipulation, and
036: * some methods throw an exception
037: * because they are not implemented.</p>
038: * <p>Copyright: Copyright (c) 2004</p>
039: * <p>Company: Together</p>
040: * @author Vladimir Radisic
041: * @version 1.0
042: */
043: public class JivanSimpleXMLObjectImpl extends SimpleXMLObjectImpl {
044:
045: public JivanSimpleXMLObjectImpl() {
046: super ();
047: }
048:
049: /**
050: * Set the Jivan implemented DOM document associated with this object and
051: * optional encoding. Note that if argument 'document' is not of type
052: * org.jivan.html.dom.HTMLDocumentCEImpl, the ClassCastException will be
053: * thrown.
054: * @param document org.w3c.dom.Document implementation which should be
055: * associated with this object,
056: * @param mimeType The MIME type associated with the document.
057: * @param encoding The encoding associated with the document.
058: */
059: public void setDocument(Document document, String mimeType,
060: String encoding) {
061: if (document != null
062: && document instanceof org.jivan.html.dom.HTMLDocumentCEImpl) {
063: super .setDocument(document, mimeType, encoding);
064: } else
065: throw new java.lang.ClassCastException(
066: "Document must be the org.jivan.html.dom.HTMLDocumentCEImpl implementation!");
067: }
068:
069: /**
070: * Set the Jivan implemented DOM document associated with this object and
071: * optional encoding. The MIME type is set to default value ('text/html').
072: * Note that if argument 'document' is not of type
073: * org.jivan.html.dom.HTMLDocumentCEImpl, the ClassCastException will be
074: * thrown.
075: * @param document org.w3c.dom.Document implementation which should be
076: * associated with this object,
077: * @param encoding The encoding associated with the document.
078: */
079: public void setDocument(Document document, String encoding) {
080: this .setDocument(document, "text/html", encoding);
081: }
082:
083: /**
084: * Set the Jivan implemented DOM document associated with this object and
085: * optional encoding. The MIME type is set to default value ('text/html'),
086: * and encoding is also set to default value ('UTF-8'). Note that if argument
087: * 'document' is not of type org.jivan.html.dom.HTMLDocumentCEImpl, the
088: * ClassCastException will be thrown.
089: * @param document org.w3c.dom.Document implementation which should be
090: * associated with this object,
091: */
092: public void setDocument(Document document) {
093: this .setDocument(document, "text/html", "UTF-8");
094: }
095:
096: /**
097: * Set the Jivan implemented DOM document associated with this object via
098: * corresponding DocumentManager and optional encoding.
099: * @param docMan appropriate DocumentManager object which contains the desired
100: * Jivan Document implementation (org.jivan.html.dom.HTMLDocumentCEImpl).
101: * @param mimeType The MIME type associated with the document.
102: * @param encoding The encoding associated with the document.
103: */
104: public void setDocument(DocumentManager docMan, String mimeType,
105: String encoding) {
106: Document temp = docMan.getDocument();
107: this .setDocument(temp, mimeType, encoding);
108: }
109:
110: /**
111: * Set the Jivan implemented DOM document associated with this object via
112: * corresponding DocumentManager and optional encoding. The MIME type is set
113: * to default value ('text/html').
114: * @param docMan appropriate DocumentManager object which contains the desired
115: * Jivan Document implementation (org.jivan.html.dom.HTMLDocumentCEImpl).
116: * @param encoding The encoding associated with the document.
117: */
118: public void setDocument(DocumentManager docMan, String encoding) {
119: Document temp = docMan.getDocument();
120: this .setDocument(temp, "text/html", encoding);
121: }
122:
123: /**
124: * Set the Jivan implemented DOM document associated with this object via
125: * corresponding DocumentManager and optional encoding. The MIME type is set
126: * to default value ('text/html'), and encoding is also set to default value
127: * ('UTF-8').
128: * @param docMan appropriate DocumentManager object which contains the desired
129: * Jivan Document implementation (org.jivan.html.dom.HTMLDocumentCEImpl).
130: */
131: public void setDocument(DocumentManager docMan) {
132: Document temp = docMan.getDocument();
133: this .setDocument(temp, "text/html", "UTF-8");
134: }
135:
136: /**
137: * Transforms Jivan Document DOM object to byte array. This will be done by
138: * using corresponding DocumentManager and its serialize() method
139: * @return DOM represented as byte array.
140: * @throws IOException
141: */
142: public byte[] toByteDocument() throws IOException {
143: HTMLDocumentCEImpl doc = (HTMLDocumentCEImpl) super
144: .getDocument();
145: DocumentManager dm = doc.getDocman();
146:
147: ByteArrayOutputStream bos = new ByteArrayOutputStream();
148: dm.serialize(bos);
149: bos.flush();
150: byte[] retArray = bos.toByteArray();
151: bos.close();
152:
153: return retArray;
154: }
155:
156: }
|