KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > admingui > taglib > DataSheetModel


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.tools.admingui.taglib;
25
26 import com.iplanet.jato.*;
27 import com.iplanet.jato.model.*;
28 import com.iplanet.jato.view.*;
29 import com.iplanet.jato.view.html.*;
30
31 import com.sun.web.ui.common.CCDebug;
32 import com.sun.web.ui.model.CCPropertySheetModel;
33
34 import org.w3c.dom.*;
35 import org.xml.sax.*;
36 import org.xml.sax.helpers.*;
37
38 import java.io.*;
39 import java.util.*;
40 import javax.servlet.*;
41 import javax.xml.parsers.*;
42
43
44 public class DataSheetModel extends CCPropertySheetModel
45                             implements DataSheetModelInterface {
46     /**
47      * Default constructor.
48      */

49     public DataSheetModel() {
50     super();
51     }
52
53     /**
54      * Construct an instance from the given string containing XML data.
55      *
56      * @param value The string containing XML data.
57      */

58     public DataSheetModel(String JavaDoc value) {
59         super(value);
60     }
61     
62     /**
63      * Construct an instance from an XML file, identified by path name
64      * the the servlet context.
65      *
66      * @param sc The servlet context used to retrieve file.
67      * @param value The path to a file, relative to the application
68      * base directory (e.g., /WEB-INF/table.xml).
69      */

70     public DataSheetModel(ServletContext sc, String JavaDoc file) {
71         super(sc, file);
72     }
73     
74     /**
75      * Construct an instance from the given InputStream containing XML data.
76      *
77      * NOTE: You must call the setDocument(is) after deserialize the object
78      * when you using this constructor. Otheriwese the xml document would
79      * be null.
80      *
81      *
82      * @param is The InputStream containing XML schema.
83      */

84     public DataSheetModel(InputStream is) {
85         super(is);
86     }
87     
88     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
89
// XML document methods
90
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
91

92     transient private EntityResolver entityResolver = null;
93     
94     public void setEntityResolver(EntityResolver er) {
95         this.entityResolver = er;
96     }
97     
98     public EntityResolver getEntityResolver() {
99         return entityResolver;
100     }
101     
102     protected void createDocument(InputStream is)
103         throws IllegalArgumentException JavaDoc {
104         if (is == null) {
105             throw new IllegalArgumentException JavaDoc("Invalid parameter: "+
106                 "The InputStream is null in CCPropertySheetModel.");
107         }
108         EntityResolver er = getEntityResolver();
109         if (er == null)
110             super.createDocument(is);
111         else
112             this.createDocument(is, er);
113     }
114     
115     protected void createDocument(InputStream is, EntityResolver er)
116         throws IllegalArgumentException JavaDoc {
117     if (is == null) {
118         throw new IllegalArgumentException JavaDoc("Invalid parameter.");
119         }
120         if (er == null) {
121             super.createDocument(is);
122             return;
123         }
124
125     // validate the given stream of xml and return the Document produced
126
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
127     factory.setIgnoringElementContentWhitespace(true);
128     factory.setValidating(true);
129
130     try {
131         DocumentBuilder documentBuilder = factory.newDocumentBuilder();
132         documentBuilder.setEntityResolver(er);
133         documentBuilder.setErrorHandler(new DefaultHandler() {
134         public void error(SAXParseException e) {
135             throw new IllegalArgumentException JavaDoc(e.getMessage());
136         }
137         public void fatalError(SAXParseException e) {
138             throw new IllegalArgumentException JavaDoc(e.getMessage());
139         }
140         public void warning(SAXParseException e) {
141             CCDebug.trace3(e.getMessage());
142         }
143         });
144         document = documentBuilder.parse(is);
145     } catch (IOException e) {
146         throw new IllegalArgumentException JavaDoc(e.getMessage());
147     } catch (SAXException e) {
148         throw new IllegalArgumentException JavaDoc(e.getMessage());
149     } catch (ParserConfigurationException e) {
150         throw new IllegalArgumentException JavaDoc(e.getMessage());
151     }
152     }
153 }
154
Popular Tags