KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > jsfmeta > util > FacesConfigParserHelper


1 /*
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * "The contents of this file are subject to the Mozilla 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 at
7  * http://www.mozilla.org/MPL/
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 the
11  * License for the specific language governing rights and limitations under
12  * the License.
13  *
14  * The Original Code is ICEfaces 1.5 open source software code, released
15  * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
16  * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
17  * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
18  *
19  * Contributor(s): _____________________.
20  *
21  * Alternatively, the contents of this file may be used under the terms of
22  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
23  * License), in which case the provisions of the LGPL License are
24  * applicable instead of those above. If you wish to allow use of your
25  * version of this file only under the terms of the LGPL License and not to
26  * allow others to use your version of this file under the MPL, indicate
27  * your decision by deleting the provisions above and replace them with
28  * the notice and other provisions required by the LGPL License. If you do
29  * not delete the provisions above, a recipient may use your version of
30  * this file under either the MPL or the LGPL License."
31  *
32  */

33
34 /*
35  * faces-Config.xml Parser Helper
36  *
37  */

38
39 package com.icesoft.jsfmeta.util;
40
41 import java.io.File JavaDoc;
42 import java.io.IOException JavaDoc;
43 import java.net.URL JavaDoc;
44
45 import javax.faces.render.RenderKitFactory;
46 import javax.xml.parsers.DocumentBuilder JavaDoc;
47 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
48 import javax.xml.parsers.ParserConfigurationException JavaDoc;
49
50 import org.xml.sax.ErrorHandler JavaDoc;
51 import org.xml.sax.SAXException JavaDoc;
52 import org.xml.sax.SAXParseException JavaDoc;
53
54 import com.icesoft.jsfmeta.MetadataXmlParser;
55 import com.sun.rave.jsfmeta.beans.FacesConfigBean;
56 import com.sun.rave.jsfmeta.beans.RenderKitBean;
57 import com.sun.rave.jsfmeta.beans.RendererBean;
58
59 public class FacesConfigParserHelper {
60     
61     private String JavaDoc fileName;
62     
63     public FacesConfigParserHelper(String JavaDoc file){
64         fileName = file;
65     }
66     
67     public static void main(String JavaDoc[] args){
68         String JavaDoc tmp = "./src/main/resources/conf/webui-faces-config.xml";
69         FacesConfigParserHelper helper = new FacesConfigParserHelper(tmp);
70         helper.getRendererBeans();
71         
72     }
73     
74     public static void validate(String JavaDoc filePath) {
75         
76         DocumentBuilderFactory JavaDoc documentBuilderFactory = DocumentBuilderFactory
77                 .newInstance();
78         documentBuilderFactory.setValidating(true);
79         
80         DocumentBuilder JavaDoc documentBuilder = null;
81         try {
82             documentBuilder = documentBuilderFactory.newDocumentBuilder();
83         } catch (ParserConfigurationException JavaDoc e) {
84             e.printStackTrace();
85         }
86         
87         documentBuilder.setErrorHandler(new ErrorHandler JavaDoc() {
88             public void error(SAXParseException JavaDoc e) {
89                 e.printStackTrace();
90             }
91             
92             public void fatalError(SAXParseException JavaDoc e) throws SAXException JavaDoc {
93                 e.printStackTrace();
94             }
95             
96             public void warning(SAXParseException JavaDoc e) {
97                 e.printStackTrace();
98             }
99         });
100         
101         try {
102             documentBuilder.parse(new File JavaDoc(filePath));
103         } catch (IOException JavaDoc e) {
104             
105             e.printStackTrace();
106         } catch (SAXException JavaDoc e) {
107             e.printStackTrace();
108             
109         }
110     }
111     
112     
113
114     public RendererBean[] getRendererBeans() {
115         
116         RendererBean[] rd = null;
117         MetadataXmlParser metadataParser = new MetadataXmlParser();
118         metadataParser.setDesign(false);
119         
120         try {
121             
122             File JavaDoc file = new File JavaDoc(fileName);
123             FacesConfigBean facesConfigBean = metadataParser.parse(file);
124             RenderKitBean renderKitBean = facesConfigBean.getRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT);
125             rd = renderKitBean.getRenderers();
126             
127         } catch (IOException JavaDoc e) {
128             e.printStackTrace();
129         } catch (SAXException JavaDoc e) {
130             e.printStackTrace();
131         }
132         
133         return rd;
134     }
135     
136 }
137
Popular Tags