01: /******************************************************************************
02: * JBoss, a division of Red Hat *
03: * Copyright 2006, Red Hat Middleware, LLC, and individual *
04: * contributors as indicated by the @authors tag. See the *
05: * copyright.txt in the distribution for a full listing of *
06: * individual contributors. *
07: * *
08: * This is free software; you can redistribute it and/or modify it *
09: * under the terms of the GNU Lesser General Public License as *
10: * published by the Free Software Foundation; either version 2.1 of *
11: * the License, or (at your option) any later version. *
12: * *
13: * This software is distributed in the hope that it will be useful, *
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16: * Lesser General Public License for more details. *
17: * *
18: * You should have received a copy of the GNU Lesser General Public *
19: * License along with this software; if not, write to the Free *
20: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
21: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
22: ******************************************************************************/package org.jboss.portal.faces.component.portlet;
23:
24: import com.sun.facelets.FaceletContext;
25: import com.sun.facelets.tag.MetaRule;
26: import com.sun.facelets.tag.MetaRuleset;
27: import com.sun.facelets.tag.Metadata;
28: import com.sun.facelets.tag.MetadataTarget;
29: import com.sun.facelets.tag.TagAttribute;
30: import com.sun.facelets.tag.jsf.ComponentConfig;
31: import com.sun.facelets.tag.jsf.ComponentHandler;
32: import org.jboss.portal.common.util.Tools;
33:
34: import java.beans.PropertyEditor;
35: import java.beans.PropertyEditorManager;
36: import java.util.Set;
37:
38: /**
39: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
40: * @version $Revision: 8784 $
41: */
42: public class PortletHandler extends ComponentHandler {
43: public PortletHandler(ComponentConfig config) {
44: super (config);
45: }
46:
47: protected MetaRuleset createMetaRuleset(Class type) {
48: MetaRuleset mr = super .createMetaRuleset(type);
49:
50: //
51: mr.addRule(new MetaRule() {
52: public Metadata applyRule(String name,
53: TagAttribute attribute, MetadataTarget meta) {
54: if ("supportedModes".equals(name)) {
55: if (attribute.isLiteral()) {
56: String s = attribute.getValue();
57: PropertyEditor editor = PropertyEditorManager
58: .findEditor(String[].class);
59: editor.setAsText(s);
60: String[] values = (String[]) editor.getValue();
61: final Set set = Tools.toSet(values);
62: return new Metadata() {
63: public void applyMetadata(
64: FaceletContext ctx, Object instance) {
65: UIPortlet portlet = (UIPortlet) instance;
66: portlet.setSupportedModes(set);
67: }
68: };
69: }
70: }
71: if ("supportedWindowStates".equals(name)) {
72: if (attribute.isLiteral()) {
73: String s = attribute.getValue();
74: PropertyEditor editor = PropertyEditorManager
75: .findEditor(String[].class);
76: editor.setAsText(s);
77: String[] values = (String[]) editor.getValue();
78: final Set set = Tools.toSet(values);
79: return new Metadata() {
80: public void applyMetadata(
81: FaceletContext ctx, Object instance) {
82: UIPortlet portlet = (UIPortlet) instance;
83: portlet.setSupportedWindowStates(set);
84: }
85: };
86: }
87: }
88: return null;
89: }
90: });
91:
92: return mr;
93: }
94: }
|