001: /*
002: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
003: *
004: * "The contents of this file are subject to the Mozilla 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 at
007: * http://www.mozilla.org/MPL/
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 the
011: * License for the specific language governing rights and limitations under
012: * the License.
013: *
014: * The Original Code is ICEfaces 1.5 open source software code, released
015: * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
016: * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
017: * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
018: *
019: * Contributor(s): _____________________.
020: *
021: * Alternatively, the contents of this file may be used under the terms of
022: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
023: * License), in which case the provisions of the LGPL License are
024: * applicable instead of those above. If you wish to allow use of your
025: * version of this file only under the terms of the LGPL License and not to
026: * allow others to use your version of this file under the MPL, indicate
027: * your decision by deleting the provisions above and replace them with
028: * the notice and other provisions required by the LGPL License. If you do
029: * not delete the provisions above, a recipient may use your version of
030: * this file under either the MPL or the LGPL License."
031: *
032: */
033:
034: /*
035: * faces-Config.xml Parser Helper
036: *
037: */
038:
039: package com.icesoft.jsfmeta.util;
040:
041: import java.io.File;
042: import java.io.IOException;
043: import java.net.URL;
044:
045: import javax.faces.render.RenderKitFactory;
046: import javax.xml.parsers.DocumentBuilder;
047: import javax.xml.parsers.DocumentBuilderFactory;
048: import javax.xml.parsers.ParserConfigurationException;
049:
050: import org.xml.sax.ErrorHandler;
051: import org.xml.sax.SAXException;
052: import org.xml.sax.SAXParseException;
053:
054: import com.icesoft.jsfmeta.MetadataXmlParser;
055: import com.sun.rave.jsfmeta.beans.FacesConfigBean;
056: import com.sun.rave.jsfmeta.beans.RenderKitBean;
057: import com.sun.rave.jsfmeta.beans.RendererBean;
058:
059: public class FacesConfigParserHelper {
060:
061: private String fileName;
062:
063: public FacesConfigParserHelper(String file) {
064: fileName = file;
065: }
066:
067: public static void main(String[] args) {
068: String tmp = "./src/main/resources/conf/webui-faces-config.xml";
069: FacesConfigParserHelper helper = new FacesConfigParserHelper(
070: tmp);
071: helper.getRendererBeans();
072:
073: }
074:
075: public static void validate(String filePath) {
076:
077: DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
078: .newInstance();
079: documentBuilderFactory.setValidating(true);
080:
081: DocumentBuilder documentBuilder = null;
082: try {
083: documentBuilder = documentBuilderFactory
084: .newDocumentBuilder();
085: } catch (ParserConfigurationException e) {
086: e.printStackTrace();
087: }
088:
089: documentBuilder.setErrorHandler(new ErrorHandler() {
090: public void error(SAXParseException e) {
091: e.printStackTrace();
092: }
093:
094: public void fatalError(SAXParseException e)
095: throws SAXException {
096: e.printStackTrace();
097: }
098:
099: public void warning(SAXParseException e) {
100: e.printStackTrace();
101: }
102: });
103:
104: try {
105: documentBuilder.parse(new File(filePath));
106: } catch (IOException e) {
107:
108: e.printStackTrace();
109: } catch (SAXException e) {
110: e.printStackTrace();
111:
112: }
113: }
114:
115: public RendererBean[] getRendererBeans() {
116:
117: RendererBean[] rd = null;
118: MetadataXmlParser metadataParser = new MetadataXmlParser();
119: metadataParser.setDesign(false);
120:
121: try {
122:
123: File file = new File(fileName);
124: FacesConfigBean facesConfigBean = metadataParser
125: .parse(file);
126: RenderKitBean renderKitBean = facesConfigBean
127: .getRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT);
128: rd = renderKitBean.getRenderers();
129:
130: } catch (IOException e) {
131: e.printStackTrace();
132: } catch (SAXException e) {
133: e.printStackTrace();
134: }
135:
136: return rd;
137: }
138:
139: }
|