KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > util > jivan > JivanSimpleXMLObjectImpl


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Developer of the Enhydra Application Server is Together Austria.
15  * All Rights Reserved.
16  *
17  */

18 package org.enhydra.util.jivan;
19
20 import java.io.ByteArrayOutputStream JavaDoc;
21 import java.io.IOException JavaDoc;
22
23 import org.enhydra.util.dom.SimpleXMLObjectImpl;
24 import org.jivan.html.document.DocumentManager;
25 import org.jivan.html.dom.HTMLDocumentCEImpl;
26 import org.w3c.dom.Document JavaDoc;
27
28
29 /**
30  * <p>Title: JivanSimpleXMLObjectImpl</p>
31  * <p>Description: This class represents implementation of XMLObject interface.
32  * Its main purpose is to provide the way for creation of XMLObject object by
33  * passed Jivan org.w3c.dom.Document Jivan implementation. The XMLCObject
34  * created by this manner can be used in already existing writeDOM() methods of
35  * ServletHttpPresentationResponse object to perform http response. Note that
36  * this class was tested only in in http response, not in DOM manipulation, and
37  * some methods throw an exception
38  * because they are not implemented.</p>
39  * <p>Copyright: Copyright (c) 2004</p>
40  * <p>Company: Together</p>
41  * @author Vladimir Radisic
42  * @version 1.0
43  */

44 public class JivanSimpleXMLObjectImpl
45     extends SimpleXMLObjectImpl {
46
47   public JivanSimpleXMLObjectImpl() {
48     super();
49   }
50
51   /**
52    * Set the Jivan implemented DOM document associated with this object and
53    * optional encoding. Note that if argument 'document' is not of type
54    * org.jivan.html.dom.HTMLDocumentCEImpl, the ClassCastException will be
55    * thrown.
56    * @param document org.w3c.dom.Document implementation which should be
57    * associated with this object,
58    * @param mimeType The MIME type associated with the document.
59    * @param encoding The encoding associated with the document.
60    */

61   public void setDocument(Document JavaDoc document, String JavaDoc mimeType, String JavaDoc encoding) {
62     if (document != null && document instanceof org.jivan.html.dom.HTMLDocumentCEImpl) {
63       super.setDocument(document, mimeType, encoding);
64     }
65     else
66       throw new java.lang.ClassCastException JavaDoc(
67           "Document must be the org.jivan.html.dom.HTMLDocumentCEImpl implementation!");
68   }
69
70   /**
71    * Set the Jivan implemented DOM document associated with this object and
72    * optional encoding. The MIME type is set to default value ('text/html').
73    * Note that if argument 'document' is not of type
74    * org.jivan.html.dom.HTMLDocumentCEImpl, the ClassCastException will be
75    * thrown.
76    * @param document org.w3c.dom.Document implementation which should be
77    * associated with this object,
78    * @param encoding The encoding associated with the document.
79    */

80   public void setDocument(Document JavaDoc document, String JavaDoc encoding) {
81     this.setDocument(document, "text/html", encoding);
82   }
83
84   /**
85    * Set the Jivan implemented DOM document associated with this object and
86    * optional encoding. The MIME type is set to default value ('text/html'),
87    * and encoding is also set to default value ('UTF-8'). Note that if argument
88    * 'document' is not of type org.jivan.html.dom.HTMLDocumentCEImpl, the
89    * ClassCastException will be thrown.
90    * @param document org.w3c.dom.Document implementation which should be
91    * associated with this object,
92    */

93   public void setDocument(Document JavaDoc document) {
94     this.setDocument(document, "text/html", "UTF-8");
95   }
96
97   /**
98    * Set the Jivan implemented DOM document associated with this object via
99    * corresponding DocumentManager and optional encoding.
100    * @param docMan appropriate DocumentManager object which contains the desired
101    * Jivan Document implementation (org.jivan.html.dom.HTMLDocumentCEImpl).
102    * @param mimeType The MIME type associated with the document.
103    * @param encoding The encoding associated with the document.
104    */

105   public void setDocument(DocumentManager docMan, String JavaDoc mimeType, String JavaDoc encoding) {
106     Document JavaDoc 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 JavaDoc encoding) {
119     Document JavaDoc 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 JavaDoc 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 JavaDoc {
143     HTMLDocumentCEImpl doc = (HTMLDocumentCEImpl)super.getDocument();
144     DocumentManager dm = doc.getDocman();
145
146     ByteArrayOutputStream JavaDoc bos = new ByteArrayOutputStream JavaDoc();
147     dm.serialize(bos);
148     bos.flush();
149     byte[] retArray = bos.toByteArray();
150     bos.close();
151
152     return retArray;
153   }
154
155 }
Popular Tags