001    package edu.nrao.sss.webapp.faces.tag;
002    
003    import javax.faces.webapp.UIComponentTag;
004    import javax.faces.component.UIComponent;
005    import javax.faces.context.FacesContext;
006    import javax.faces.application.Application;
007    import javax.faces.el.ValueBinding;
008    import javax.faces.el.ReferenceSyntaxException;
009    
010    import org.apache.log4j.Logger;
011    
012    import edu.nrao.sss.webapp.faces.component.LongitudeUIComponent;
013    
014    public class LongitudeTag extends UIComponentTag
015    {
016            private static final Logger log = Logger.getLogger(LongitudeTag.class);
017            
018            public String getComponentType() { return "edu.nrao.sss.Longitude"; }
019            public String getRendererType() { return null; }
020            
021            private String value = null, 
022                    enabled = null,
023                    style = null,
024                    styleClass = null;
025            
026            @SuppressWarnings("unchecked")
027            protected void setProperties(UIComponent component)
028            {
029                    super.setProperties(component);
030                    
031                    log.debug("Value is: " + value);
032                    if (value != null) 
033                    { 
034                            if (isValueReference(value))
035                            {
036                                    FacesContext context = FacesContext.getCurrentInstance();
037                                    Application app = context.getApplication();
038                                    ValueBinding vb = app.createValueBinding(value);
039    
040                                    component.setValueBinding("value", vb);
041                            }
042                            
043                            else
044                            {
045                                    throw new ReferenceSyntaxException(value + " is not a valid EL expression");
046                            }
047                    }
048                    
049                    if (enabled != null) 
050                    { 
051                            if (isValueReference(enabled))
052                            {
053                                    FacesContext context = FacesContext.getCurrentInstance();
054                                    Application app = context.getApplication();
055                                    ValueBinding vb = app.createValueBinding(enabled);
056    
057                                    component.setValueBinding("enabled", vb);
058                            }
059                            
060                            else
061                            {
062                                    ((LongitudeUIComponent)component).setEnabled(isTrue(enabled));
063                            }
064                    }
065                    
066                    if (style != null) 
067                    { 
068                            if (isValueReference(style))
069                            {
070                                    FacesContext context = FacesContext.getCurrentInstance();
071                                    Application app = context.getApplication();
072                                    ValueBinding vb = app.createValueBinding(style);
073    
074                                    component.setValueBinding("style", vb);
075                            }
076                            
077                            else
078                            {
079                                    component.getAttributes().put("style", style);
080                            }
081                    }
082                    
083                    if (styleClass != null) 
084                    { 
085                            if (isValueReference(styleClass))
086                            {
087                                    FacesContext context = FacesContext.getCurrentInstance();
088                                    Application app = context.getApplication();
089                                    ValueBinding vb = app.createValueBinding(styleClass);
090    
091                                    component.setValueBinding("styleClass", vb);
092                            }
093                            
094                            else
095                            {
096                                    component.getAttributes().put("styleClass", styleClass);
097                            }
098                    }
099            }
100            
101            public void release()
102            {
103                    super.release();
104                    this.enabled = null;
105                    this.value = null;
106                    this.style = null;
107                    this.styleClass = null;
108            }
109            
110            public void setValue(String v)
111            {
112                    this.value = v;
113            }
114            
115            public void setEnabled(String e)
116            {
117                    this.enabled = e;
118            }
119            
120            public void setStyle(String s)
121            {
122                    this.style = s;
123            }
124            
125            public void setStyleClass(String sc)
126            {
127                    this.styleClass = sc;
128            }
129            
130            public boolean isTrue(String v)
131            {
132                    return ("true".equalsIgnoreCase(v) || "1".equals(v));
133            }
134    }