KickJava   Java API By Example, From Geeks To Geeks.

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


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 package com.icesoft.jsfmeta.util;
35
36 import java.io.IOException JavaDoc;
37 import java.net.URL JavaDoc;
38
39 import org.xml.sax.SAXException JavaDoc;
40
41 import com.icesoft.jsfmeta.MetadataXmlParser;
42 import com.sun.rave.jsfmeta.beans.ComponentBean;
43 import com.sun.rave.jsfmeta.beans.FacesConfigBean;
44 import com.sun.rave.jsfmeta.beans.PropertyBean;
45
46 /*
47  * filter to reset category for component beans
48  *
49  * TODO: remove me
50  */

51
52 public class FilterComponentBeanProperties {
53     
54     
55     public FilterComponentBeanProperties(){
56         
57     }
58     
59     public void init(){
60         
61     }
62     
63     public static void main(String JavaDoc[] args) {
64         
65         FilterComponentBeanProperties status = new FilterComponentBeanProperties();
66         status.getFilterComponentProperty();
67     }
68     
69         /*
70          * return Javascript attribute property for example: onclick
71          */

72     public PropertyBean[] getFilterComponentProperty() {
73         
74         PropertyBean[] pb = null;
75         String JavaDoc[] cb = null;
76         MetadataXmlParser metadataParser = new MetadataXmlParser();
77         metadataParser.setDesign(true);
78         
79         try {
80             ClassLoader JavaDoc classLoader = Thread.currentThread()
81             .getContextClassLoader();
82             URL JavaDoc localUrl = classLoader.getResource(".");
83             String JavaDoc newPath = "file:" + localUrl.getPath()
84             + "./../conf/filter.properties/filter-faces-config.xml";
85             URL JavaDoc url = new URL JavaDoc(newPath);
86             
87             FacesConfigBean facesConfigBean = metadataParser.parse(url);
88             ComponentBean[] componentbeans = facesConfigBean.getComponents();
89             cb = new String JavaDoc[componentbeans.length];
90             
91             for (int i = 0; i < componentbeans.length; i++) {
92                 cb[i] = componentbeans[i].getComponentClass();
93                 PropertyBean[] descriptions = componentbeans[i].getProperties();
94                 
95                 String JavaDoc one = "";
96                 pb = descriptions;
97                 for (int j = 0; j < pb.length; j++) {
98                     
99                     one = one + "\n property name=" + pb[j].getPropertyName()+ " property category="+ pb[j].getCategory();
100                 }
101             }
102         } catch (IOException JavaDoc e) {
103             e.printStackTrace();
104         } catch (SAXException JavaDoc e) {
105             e.printStackTrace();
106         }
107         
108         return pb;
109     }
110     
111     
112     private void filterCategory(PropertyBean propertyBean){
113         
114         PropertyBean[] filterPropertyBeans = getFilterComponentProperty();
115         
116         for(int i=0 ; i< filterPropertyBeans.length; i++){
117             
118             boolean condition = filterPropertyBeans[i].getPropertyName().equalsIgnoreCase(propertyBean.getPropertyName());
119             if(condition){
120                 propertyBean.setCategory(filterPropertyBeans[i].getCategory());
121             }
122         }
123     }
124     
125     
126         /*
127          * filter with category name (hiding JAVASCRIPT category related properties)getEffect
128          */

129     public void filter(ComponentBean componentBean) {
130         
131         PropertyBean[] propertyBeans = null;
132         propertyBeans = componentBean.getProperties();
133         for (int j = 0; j < propertyBeans.length; j++) {
134                         
135             String JavaDoc propertyName = propertyBeans[j].getPropertyName();
136             String JavaDoc categoryName = propertyBeans[j].getCategory();
137             
138             if (categoryName != null
139                     && categoryName.equalsIgnoreCase("javascript")) {
140                 PropertyBean temp = propertyBeans[j];
141                 temp.setHidden(true);
142             }
143         }
144     }
145     
146         /*
147          * filter
148          */

149     public void filter(ComponentBean[] componentBeans) {
150         
151         PropertyBean[] propertyBeans = null;
152         
153         for (int i = 0; i < componentBeans.length; i++) {
154             
155             componentBeans[i].getProperties();
156             propertyBeans = componentBeans[i].getProperties();
157             
158             for (int j = 0; j < propertyBeans.length; j++) {
159                 String JavaDoc propertyName = propertyBeans[j].getPropertyName();
160                 String JavaDoc categoryName = propertyBeans[j].getCategory();
161                 System.out.println("propertyName=" + propertyName
162                         + " categoryName=" + categoryName);
163             }
164         }
165     }
166     
167         /*
168          * filter
169          */

170     public void filter(ComponentBean[] componentBeans,
171             PropertyBean[] propertyBeans) {
172         
173         for (int i = 0; i < componentBeans.length; i++) {
174             componentBeans[i].getProperties();
175         }
176         
177         for (int i = 0; i < propertyBeans.length; i++) {
178             String JavaDoc propertyName = propertyBeans[i].getPropertyName();
179             String JavaDoc categoryName = propertyBeans[i].getCategory();
180         }
181     }
182     
183 }
184
Popular Tags